ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.170 by root, Sun Nov 21 20:19:24 2004 UTC vs.
Revision 1.183 by root, Tue Dec 21 06:43:00 2004 UTC

48#include "../config.h" /* NECESSARY */ 48#include "../config.h" /* NECESSARY */
49#include "rxvt.h" /* NECESSARY */ 49#include "rxvt.h" /* NECESSARY */
50#include "version.h" 50#include "version.h"
51#include "command.h" 51#include "command.h"
52 52
53#include <wchar.h> 53#include <cwchar>
54#include <csignal>
54 55
55/*----------------------------------------------------------------------*/ 56/*----------------------------------------------------------------------*/
56 57
57#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 58#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
58 59
487#endif 488#endif
488 489
489 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 490 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
490 { 491 {
491#ifdef KEYSYM_RESOURCE 492#ifdef KEYSYM_RESOURCE
492 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL) 493 if (!(shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
493 { 494 {
494 unsigned int l; 495 unsigned int l;
495 const unsigned char *kbuf0; 496 const unsigned char *kbuf0;
496 497
497 kbuf0 = (Keysym_map[keysym & 0xFF]); 498 kbuf0 = (Keysym_map[keysym & 0xFF]);
784 case XK_F35: /* "\033[49~" */ 785 case XK_F35: /* "\033[49~" */
785 FKEY (31, XK_F17); 786 FKEY (31, XK_F17);
786 break; 787 break;
787#undef FKEY 788#undef FKEY
788 default: 789 default:
789 newlen = 0; 790 if (len == 0
790 break; 791 && (keysym & 0xfff0) != 0xff70
792 && (keysym & 0xfff0) != 0xffe0)
793 /* generate a keycode for every remaining keypress */
794 sprintf ((char *)kbuf, "\033[%x;%xA", (unsigned char)ev.state, (unsigned short)keysym);
791 } 795 }
796
792 if (newlen) 797 if (newlen)
793 len = strlen (kbuf); 798 len = strlen (kbuf);
794 } 799 }
795 800
796 /* 801 /*
804 } 809 }
805 else if (ctrl && keysym == XK_minus) 810 else if (ctrl && keysym == XK_minus)
806 { 811 {
807 len = 1; 812 len = 1;
808 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 813 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
814 }
815 else if (keysym == XK_ISO_Left_Tab)
816 {
817 strcpy (kbuf, "\033[Z");
818 len = 3;
819 }
820 else if (len == 0
821 && (keysym & 0xffe0) != 0xfe00
822 && (keysym < 0xfe50 || keysym > 0xfe6f))
823 {
824 /* generate a keycode for every remaining keypress */
825 len = sprintf ((char *)kbuf, "\033[%x;%xA", (unsigned char)ev.state, (unsigned short)keysym);
809 } 826 }
810 else 827 else
811 { 828 {
812#ifdef META8_OPTION 829#ifdef META8_OPTION
813 /* set 8-bit on */ 830 /* set 8-bit on */
1057rxvt_term::pty_cb (io_watcher &w, short revents) 1074rxvt_term::pty_cb (io_watcher &w, short revents)
1058{ 1075{
1059 SET_R (this); 1076 SET_R (this);
1060 SET_LOCALE (locale); 1077 SET_LOCALE (locale);
1061 1078
1062 if (revents & EVENT_WRITE)
1063 tt_write (0, 0);
1064 else if (revents & EVENT_READ) 1079 if (revents & EVENT_READ)
1065 // loop, but don't allow a single term to monopolize us 1080 // loop, but don't allow a single term to monopolize us
1066 while (pty_fill ()) 1081 while (pty_fill ())
1067 if (cmd_parse ()) 1082 if (cmd_parse ())
1068 break; 1083 break;
1084
1085 if (revents & EVENT_WRITE)
1086 pty_write ();
1069} 1087}
1070 1088
1071void 1089void
1072rxvt_term::pointer_unblank () 1090rxvt_term::pointer_unblank ()
1073{ 1091{
1216 if (ev.type == KeyPress && hidden_pointer == 0) 1234 if (ev.type == KeyPress && hidden_pointer == 0)
1217 pointer_blank (); 1235 pointer_blank ();
1218 } 1236 }
1219#endif 1237#endif
1220 1238
1221 Window unused_root, unused_child; 1239 Window unused_root, unused_child;
1222 int unused_root_x, unused_root_y; 1240 int unused_root_x, unused_root_y;
1223 unsigned int unused_mask; 1241 unsigned int unused_mask;
1224 1242
1225 switch (ev.type) 1243 switch (ev.type)
1226 { 1244 {
1227 case KeyPress: 1245 case KeyPress:
1228#if ISO_14755 1246#if ISO_14755
1333 0L, 1000000L, 1351 0L, 1000000L,
1334 False, AnyPropertyType, 1352 False, AnyPropertyType,
1335 &ActualType, &ActualFormat, 1353 &ActualType, &ActualFormat,
1336 &Size, &RemainingBytes, 1354 &Size, &RemainingBytes,
1337 &data); 1355 &data);
1338 XChangeProperty (display->display, display->root, 1356 set_string_property (XA_CUT_BUFFER0, data);
1339 XA_CUT_BUFFER0, XA_STRING,
1340 8, PropModeReplace,
1341 data, strlen (data));
1342 XFree (data); 1357 XFree (data);
1343 selection_paste (display->root, XA_CUT_BUFFER0, True); 1358 selection_paste (display->root, XA_CUT_BUFFER0, true);
1344 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1359 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime);
1345 } 1360 }
1346#endif /* OFFIX_DND */ 1361#endif /* OFFIX_DND */
1347 break; 1362 break;
1348 1363
1452 resize_all_windows (width, height, 1); 1467 resize_all_windows (width, height, 1);
1453 } 1468 }
1454 1469
1455#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1470#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1456 if (options & Opt_transparent) 1471 if (options & Opt_transparent)
1457 {
1458 check_our_parents (); 1472 check_our_parents ();
1459 if (am_transparent)
1460 want_refresh = want_full_refresh = 1;
1461 }
1462#endif 1473#endif
1463 } 1474 }
1464 break; 1475 break;
1465 1476
1466 case PropertyNotify: 1477 case PropertyNotify:
1474 selection_clear (); 1485 selection_clear ();
1475 break; 1486 break;
1476 1487
1477 case SelectionNotify: 1488 case SelectionNotify:
1478 if (selection_wait == Sel_normal) 1489 if (selection_wait == Sel_normal)
1479 selection_paste (ev.xselection.requestor, 1490 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1480 ev.xselection.property, True);
1481 break; 1491 break;
1482 1492
1483 case SelectionRequest: 1493 case SelectionRequest:
1484 selection_send (ev.xselectionrequest); 1494 selection_send (ev.xselectionrequest);
1485 break; 1495 break;
1674 case PropertyNotify: 1684 case PropertyNotify:
1675 /* 1685 /*
1676 * if user used some Esetroot compatible prog to set the root bg, 1686 * if user used some Esetroot compatible prog to set the root bg,
1677 * use the property to determine the pixmap. We use it later on. 1687 * use the property to determine the pixmap. We use it later on.
1678 */ 1688 */
1679 if (xa[XA_XROOTPMAPID] == 0)
1680 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1681
1682 if (ev.xproperty.atom != xa[XA_XROOTPMAPID]) 1689 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1690 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1683 return; 1691 return;
1684 1692
1685 /* FALLTHROUGH */ 1693 /* FALLTHROUGH */
1686 case ReparentNotify: 1694 case ReparentNotify:
1687 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1695 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
2357 /* 2365 /*
2358 * Make the frame window set by the window manager have 2366 * Make the frame window set by the window manager have
2359 * the root background. Some window managers put multiple nested frame 2367 * the root background. Some window managers put multiple nested frame
2360 * windows for each client, so we have to take care about that. 2368 * windows for each client, so we have to take care about that.
2361 */ 2369 */
2362 i = (xa[XA_XROOTPMAPID] 2370 i = (xa[XA_XROOTPMAP_ID]
2363 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2371 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAP_ID],
2364 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2372 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2365 &nitems, &bytes_after, &prop) == Success); 2373 &nitems, &bytes_after, &prop) == Success);
2366 2374
2367 if (!i || prop == NULL) 2375 if (!i || prop == NULL)
2368 i = (xa[XA_XSETROOTID] 2376 i = (xa[XA_ESETROOT_PMAP_ID]
2369 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2377 && XGetWindowProperty (display->display, display->root, xa[XA_ESETROOT_PMAP_ID],
2370 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2378 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2371 &nitems, &bytes_after, &prop) == Success); 2379 &nitems, &bytes_after, &prop) == Success);
2372 2380
2373 if (!i || prop == NULL 2381 if (!i || prop == NULL
2374#if TINTING 2382#if TINTING
2415 sy = 0; 2423 sy = 0;
2416 } 2424 }
2417 2425
2418 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2426 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2419 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2427 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2428
2429 XSync (display->display, False);
2420 allowedxerror = -1; 2430 allowedxerror = -1;
2421 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2431 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2422 2432
2423 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2433 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2424 /* XXX: may need a delay here? */ 2434 /* XXX: may need a delay here? */
2470 2480
2471 am_transparent = am_pixmap_trans = 1; 2481 am_transparent = am_pixmap_trans = 1;
2472 } 2482 }
2473 } 2483 }
2474 2484
2475 if (!am_pixmap_trans) 2485 if (am_pixmap_trans)
2486 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative);
2487 else
2476 { 2488 {
2477 unsigned int n; 2489 unsigned int n;
2478 /* 2490 /*
2479 * InheritPixmap transparency 2491 * InheritPixmap transparency
2480 */ 2492 */
2543 if (scrollBar.win) 2555 if (scrollBar.win)
2544 { 2556 {
2545 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2557 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative);
2546 scrollBar.setIdle (); 2558 scrollBar.setIdle ();
2547 scrollbar_show (0); 2559 scrollbar_show (0);
2560 }
2561
2562 if (am_transparent)
2563 {
2564 want_refresh = want_full_refresh = 1;
2565 if (am_pixmap_trans)
2566 flush ();
2548 } 2567 }
2549 2568
2550 return pchanged; 2569 return pchanged;
2551} 2570}
2552#endif 2571#endif
2704 if (len == (size_t)-1) 2723 if (len == (size_t)-1)
2705 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2724 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2706 2725
2707 // assume wchar == unicode 2726 // assume wchar == unicode
2708 cmdbuf_ptr += len; 2727 cmdbuf_ptr += len;
2709 return wc; 2728 return wc & UNICODE_MASK;
2710 } 2729 }
2711 2730
2712 return NOCHAR; 2731 return NOCHAR;
2713} 2732}
2714 2733
3512 * ends_how is terminator used. returned input must be free()'d 3531 * ends_how is terminator used. returned input must be free()'d
3513 */ 3532 */
3514unsigned char * 3533unsigned char *
3515rxvt_term::get_to_st (unicode_t &ends_how) 3534rxvt_term::get_to_st (unicode_t &ends_how)
3516{ 3535{
3517 unicode_t seen_esc = 0, ch; 3536 unicode_t ch;
3537 bool seen_esc = false;
3518 unsigned int n = 0; 3538 unsigned int n = 0;
3519 unsigned char *s;
3520 unsigned char string[STRING_MAX]; 3539 wchar_t string[STRING_MAX];
3521 3540
3522 while ((ch = cmd_getc ()) != NOCHAR) 3541 while ((ch = cmd_getc ()) != NOCHAR)
3523 { 3542 {
3524 if (seen_esc) 3543 if (seen_esc)
3525 { 3544 {
3528 else 3547 else
3529 return NULL; 3548 return NULL;
3530 } 3549 }
3531 else if (ch == C0_ESC) 3550 else if (ch == C0_ESC)
3532 { 3551 {
3533 seen_esc = 1; 3552 seen_esc = true;
3534 continue; 3553 continue;
3535 } 3554 }
3536 else if (ch == C0_BEL || ch == CHAR_ST) 3555 else if (ch == C0_BEL || ch == CHAR_ST)
3537 break; 3556 break;
3538 else if (ch < 0x20) 3557 else if (ch < 0x20)
3539 return NULL; /* other control character - exit */ 3558 return NULL; /* other control character - exit */
3540 3559
3541 seen_esc = 0; 3560 seen_esc = false;
3542 3561
3543 if (n >= sizeof (string) - 1) 3562 if (n >= sizeof (string) - 1)
3544 // stop at some sane length 3563 // stop at some sane length
3545 return NULL; 3564 return NULL;
3546 3565
3550 string[n++] = ch; 3569 string[n++] = ch;
3551 } 3570 }
3552 3571
3553 string[n++] = '\0'; 3572 string[n++] = '\0';
3554 3573
3555 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3556 return NULL;
3557
3558 ends_how = (ch == 0x5c ? C0_ESC : ch); 3574 ends_how = (ch == 0x5c ? C0_ESC : ch);
3559 strncpy (s, string, n); 3575
3560 return s; 3576 return (unsigned char *)rxvt_wcstombs (string);
3561} 3577}
3562 3578
3563/*----------------------------------------------------------------------*/ 3579/*----------------------------------------------------------------------*/
3564/* 3580/*
3565 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3581 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3666 set_title (str); 3682 set_title (str);
3667 break; 3683 break;
3668 case XTerm_property: 3684 case XTerm_property:
3669 if (str[0] == '?') 3685 if (str[0] == '?')
3670 { 3686 {
3671 Atom prop = XInternAtom (display->display, str + 1, True); 3687 Atom prop = display->atom (str + 1);
3672 Atom actual_type; 3688 Atom actual_type;
3673 int actual_format; 3689 int actual_format;
3674 unsigned long nitems; 3690 unsigned long nitems;
3675 unsigned long bytes_after; 3691 unsigned long bytes_after;
3676 unsigned char *value = 0; 3692 unsigned char *value = 0;
3694 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3710 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3695 3711
3696 if (eq) 3712 if (eq)
3697 { 3713 {
3698 *eq = 0; 3714 *eq = 0;
3699 XChangeProperty (display->display, TermWin.parent[0], 3715 set_utf8_property (display->atom (str), eq + 1);
3700 display->atom (str), XA_STRING, 8,
3701 PropModeReplace, (unsigned char *)eq + 1,
3702 strlen (eq + 1));
3703 } 3716 }
3704 else 3717 else
3705 XDeleteProperty (display->display, TermWin.parent[0], 3718 XDeleteProperty (display->display, TermWin.parent[0],
3706 display->atom (str)); 3719 display->atom (str));
3707 } 3720 }
4284 4297
4285/* ---------------------------------------------------------------------- */ 4298/* ---------------------------------------------------------------------- */
4286/* Write data to the pty as typed by the user, pasted with the mouse, 4299/* Write data to the pty as typed by the user, pasted with the mouse,
4287 * or generated by us in response to a query ESC sequence. 4300 * or generated by us in response to a query ESC sequence.
4288 */ 4301 */
4302const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4303
4289void 4304void
4290rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4305rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4291{ 4306{
4292 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4307 if (v_buflen == 0)
4308 {
4309 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4293 4310
4294 if (len) 4311 if ((unsigned int)written == len)
4312 return;
4313
4314 data += written;
4315 len -= written;
4295 { 4316 }
4317
4318 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4319
4320 memcpy (v_buffer + v_buflen, data, len);
4321 v_buflen += len;
4322
4323 pty_ev.set (EVENT_READ | EVENT_WRITE);
4324}
4325
4326void rxvt_term::pty_write ()
4327{
4328 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4329
4330 if (written > 0)
4331 {
4332 v_buflen -= written;
4333
4296 if (v_buflen == 0) 4334 if (v_buflen == 0)
4297 { 4335 {
4298 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4299
4300 if ((unsigned int)written == len)
4301 return;
4302
4303 data += written;
4304 len -= written;
4305 }
4306
4307
4308 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4309
4310 memcpy (v_buffer + v_buflen, data, len);
4311 v_buflen += len;
4312 }
4313
4314 for (;;)
4315 {
4316 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4317
4318 if (written > 0)
4319 {
4320 v_buflen -= written;
4321
4322 if (v_buflen == 0)
4323 {
4324 free (v_buffer); 4336 free (v_buffer);
4325 v_buffer = 0; 4337 v_buffer = 0;
4326 v_buflen = 0; 4338 v_buflen = 0;
4327 4339
4328 pty_ev.set (EVENT_READ); 4340 pty_ev.set (EVENT_READ);
4329 return;
4330 }
4331
4332 memmove (v_buffer, v_buffer + written, v_buflen);
4333 }
4334 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4335 // original code just ignores this...
4336 destroy ();
4337 else
4338 {
4339 pty_ev.set (EVENT_READ | EVENT_WRITE);
4340 return; 4341 return;
4341 } 4342 }
4343
4344 memmove (v_buffer, v_buffer + written, v_buflen);
4342 } 4345 }
4346 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4347 // original code just ignores this...
4348 destroy ();
4343} 4349}
4344 4350
4345/*----------------------- end-of-file (C source) -----------------------*/ 4351/*----------------------- end-of-file (C source) -----------------------*/
4346 4352

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines