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.171 by root, Wed Dec 1 02:12:18 2004 UTC vs.
Revision 1.193 by root, Sun Feb 13 08:56:27 2005 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#ifdef KEYSYM_RESOURCE
54# include "keyboard.h"
55#endif
56
54#include <signal.h> 57#include <csignal>
55 58
56/*----------------------------------------------------------------------*/ 59/*----------------------------------------------------------------------*/
57 60
58#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
59 62
344 valid_keysym = keysym != NoSymbol; 347 valid_keysym = keysym != NoSymbol;
345 } 348 }
346 349
347 if (valid_keysym) 350 if (valid_keysym)
348 { 351 {
352#ifdef KEYSYM_RESOURCE
353 if (keyboard->dispatch (this, keysym, ev.state))
354 return;
355#endif
356
349 if (TermWin.saveLines) 357 if (TermWin.saveLines)
350 { 358 {
351#ifdef UNSHIFTED_SCROLLKEYS 359#ifdef UNSHIFTED_SCROLLKEYS
352 if (!ctrl && !meta) 360 if (!ctrl && !meta)
353#else 361#else
487 } 495 }
488#endif 496#endif
489 497
490 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 498 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
491 { 499 {
492#ifdef KEYSYM_RESOURCE
493 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
494 {
495 unsigned int l;
496 const unsigned char *kbuf0;
497
498 kbuf0 = (Keysym_map[keysym & 0xFF]);
499 l = (unsigned int)*kbuf0++;
500
501 /* escape prefix */
502 if (meta
503# ifdef META8_OPTION
504 && meta_char == C0_ESC
505# endif
506 )
507 {
508 const unsigned char ch = C0_ESC;
509 tt_write (&ch, 1);
510 }
511
512 tt_write (kbuf0, l);
513 return;
514 }
515 else
516#endif
517 { 500 {
518 newlen = 1; 501 newlen = 1;
519 switch (keysym) 502 switch (keysym)
520 { 503 {
521#ifndef NO_BACKSPACE_KEY 504#ifndef NO_BACKSPACE_KEY
788#undef FKEY 771#undef FKEY
789 default: 772 default:
790 newlen = 0; 773 newlen = 0;
791 break; 774 break;
792 } 775 }
776
793 if (newlen) 777 if (newlen)
794 len = strlen (kbuf); 778 len = strlen (kbuf);
795 } 779 }
796 780
797 /* 781 /*
805 } 789 }
806 else if (ctrl && keysym == XK_minus) 790 else if (ctrl && keysym == XK_minus)
807 { 791 {
808 len = 1; 792 len = 1;
809 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 793 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
794 }
795 else if (keysym == XK_ISO_Left_Tab)
796 {
797 strcpy (kbuf, "\033[Z");
798 len = 3;
810 } 799 }
811 else 800 else
812 { 801 {
813#ifdef META8_OPTION 802#ifdef META8_OPTION
814 /* set 8-bit on */ 803 /* set 8-bit on */
873#endif /* DEBUG_CMD */ 862#endif /* DEBUG_CMD */
874 tt_write (kbuf, (unsigned int)len); 863 tt_write (kbuf, (unsigned int)len);
875} 864}
876/*}}} */ 865/*}}} */
877 866
878#if (MENUBAR_MAX) 867#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
879/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 868/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
880/* attempt to `write' count to the input buffer */ 869/* attempt to `write' count to the input buffer */
881unsigned int 870unsigned int
882rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 871rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
883{ 872{
906 895
907 cmd_parse (); 896 cmd_parse ();
908 897
909 return 0; 898 return 0;
910} 899}
911#endif /* MENUBAR_MAX */ 900#endif
912 901
913void 902void
914rxvt_term::flush () 903rxvt_term::flush ()
915{ 904{
916 flush_ev.stop (); 905 flush_ev.stop ();
1017{ 1006{
1018 if (mouse_slip_wheel_speed == 0 1007 if (mouse_slip_wheel_speed == 0
1019 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1008 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1020 : scr_page (UP, mouse_slip_wheel_speed)) 1009 : scr_page (UP, mouse_slip_wheel_speed))
1021 { 1010 {
1011 if (TermWin.view_start == TermWin.nscrolled ||
1012 TermWin.view_start == 0)
1013 mouse_slip_wheel_speed = 0;
1014
1022 refresh_type |= SMOOTH_REFRESH; 1015 refresh_type |= SMOOTH_REFRESH;
1023 want_refresh = 1; 1016 want_refresh = 1;
1024 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1017 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1025 } 1018 }
1026} 1019}
1058rxvt_term::pty_cb (io_watcher &w, short revents) 1051rxvt_term::pty_cb (io_watcher &w, short revents)
1059{ 1052{
1060 SET_R (this); 1053 SET_R (this);
1061 SET_LOCALE (locale); 1054 SET_LOCALE (locale);
1062 1055
1063 if (revents & EVENT_WRITE)
1064 tt_write (0, 0);
1065 else if (revents & EVENT_READ) 1056 if (revents & EVENT_READ)
1066 // loop, but don't allow a single term to monopolize us 1057 // loop, but don't allow a single term to monopolize us
1067 while (pty_fill ()) 1058 while (pty_fill ())
1068 if (cmd_parse ()) 1059 if (cmd_parse ())
1069 break; 1060 break;
1061
1062 if (revents & EVENT_WRITE)
1063 pty_write ();
1070} 1064}
1071 1065
1072void 1066void
1073rxvt_term::pointer_unblank () 1067rxvt_term::pointer_unblank ()
1074{ 1068{
1088rxvt_term::pointer_blank () 1082rxvt_term::pointer_blank ()
1089{ 1083{
1090 if (! (options & Opt_pointerBlank)) 1084 if (! (options & Opt_pointerBlank))
1091 return; 1085 return;
1092 1086
1093 XDefineCursor (display->display, TermWin.vt, blank_cursor); 1087 XDefineCursor (display->display, TermWin.vt, display->blank_cursor);
1094 XFlush (display->display); 1088 XFlush (display->display);
1095 1089
1096 hidden_pointer = 1; 1090 hidden_pointer = 1;
1097} 1091}
1098 1092
1187 1181
1188/*{{{ process an X event */ 1182/*{{{ process an X event */
1189void 1183void
1190rxvt_term::x_cb (XEvent &ev) 1184rxvt_term::x_cb (XEvent &ev)
1191{ 1185{
1186 dDisp;
1187
1192 SET_R (this); 1188 SET_R (this);
1193 SET_LOCALE (locale); 1189 SET_LOCALE (locale);
1194 1190
1195#if defined(CURSOR_BLINK) 1191#if defined(CURSOR_BLINK)
1196 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1192 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1217 if (ev.type == KeyPress && hidden_pointer == 0) 1213 if (ev.type == KeyPress && hidden_pointer == 0)
1218 pointer_blank (); 1214 pointer_blank ();
1219 } 1215 }
1220#endif 1216#endif
1221 1217
1222 Window unused_root, unused_child; 1218 Window unused_root, unused_child;
1223 int unused_root_x, unused_root_y; 1219 int unused_root_x, unused_root_y;
1224 unsigned int unused_mask; 1220 unsigned int unused_mask;
1225 1221
1226 switch (ev.type) 1222 switch (ev.type)
1227 { 1223 {
1228 case KeyPress: 1224 case KeyPress:
1229#if ISO_14755 1225#if ISO_14755
1327 Atom ActualType; 1323 Atom ActualType;
1328 int ActualFormat; 1324 int ActualFormat;
1329 unsigned char *data; 1325 unsigned char *data;
1330 unsigned long Size, RemainingBytes; 1326 unsigned long Size, RemainingBytes;
1331 1327
1332 XGetWindowProperty (display->display, display->root, 1328 XGetWindowProperty (disp, display->root,
1333 xa[XA_DNDSELECTION], 1329 xa[XA_DNDSELECTION],
1334 0L, 1000000L, 1330 0L, 1000000L,
1335 False, AnyPropertyType, 1331 False, AnyPropertyType,
1336 &ActualType, &ActualFormat, 1332 &ActualType, &ActualFormat,
1337 &Size, &RemainingBytes, 1333 &Size, &RemainingBytes,
1338 &data); 1334 &data);
1339 XChangeProperty (display->display, display->root, 1335 set_string_property (XA_CUT_BUFFER0, data);
1340 XA_CUT_BUFFER0, XA_STRING,
1341 8, PropModeReplace,
1342 data, strlen (data));
1343 XFree (data); 1336 XFree (data);
1344 selection_paste (display->root, XA_CUT_BUFFER0, True); 1337 selection_paste (display->root, XA_CUT_BUFFER0, true);
1345 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1338 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1346 } 1339 }
1347#endif /* OFFIX_DND */ 1340#endif /* OFFIX_DND */
1348 break; 1341 break;
1349 1342
1350 case MappingNotify: 1343 case MappingNotify:
1443 { /* Wrap lots of configures into one */ 1436 { /* Wrap lots of configures into one */
1444 width = ev.xconfigure.width; 1437 width = ev.xconfigure.width;
1445 height = ev.xconfigure.height; 1438 height = ev.xconfigure.height;
1446 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); 1439 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1447 } 1440 }
1448 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev)); 1441 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev));
1449 1442
1450 if (szHint.width != width || szHint.height != height) 1443 if (szHint.width != width || szHint.height != height)
1451 { 1444 {
1452 seen_resize = 1; 1445 seen_resize = 1;
1453 resize_all_windows (width, height, 1); 1446 resize_all_windows (width, height, 1);
1454 } 1447 }
1455 1448
1456#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1449#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1457 if (options & Opt_transparent) 1450 if (options & Opt_transparent)
1458 {
1459 check_our_parents (); 1451 check_our_parents ();
1460 if (am_transparent)
1461 want_refresh = want_full_refresh = 1;
1462 }
1463#endif 1452#endif
1464 } 1453 }
1465 break; 1454 break;
1466 1455
1467 case PropertyNotify: 1456 case PropertyNotify:
1475 selection_clear (); 1464 selection_clear ();
1476 break; 1465 break;
1477 1466
1478 case SelectionNotify: 1467 case SelectionNotify:
1479 if (selection_wait == Sel_normal) 1468 if (selection_wait == Sel_normal)
1480 selection_paste (ev.xselection.requestor, 1469 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1481 ev.xselection.property, True);
1482 break; 1470 break;
1483 1471
1484 case SelectionRequest: 1472 case SelectionRequest:
1485 selection_send (ev.xselectionrequest); 1473 selection_send (ev.xselectionrequest);
1486 break; 1474 break;
1510 if (ev.xany.window == TermWin.vt) 1498 if (ev.xany.window == TermWin.vt)
1511 { 1499 {
1512 do 1500 do
1513 scr_expose (ev.xexpose.x, ev.xexpose.y, 1501 scr_expose (ev.xexpose.x, ev.xexpose.y,
1514 ev.xexpose.width, ev.xexpose.height, False); 1502 ev.xexpose.width, ev.xexpose.height, False);
1515 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); 1503 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev));
1516 1504
1517 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1505 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1518 1506
1519 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) 1507 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev))
1520 scr_expose (ev.xexpose.x, ev.xexpose.y, 1508 scr_expose (ev.xexpose.x, ev.xexpose.y,
1521 ev.xexpose.width, ev.xexpose.height, False); 1509 ev.xexpose.width, ev.xexpose.height, False);
1522 1510
1523 scr_refresh (refresh_type); 1511 scr_refresh (refresh_type);
1524 } 1512 }
1525 else 1513 else
1526 { 1514 {
1527 XEvent unused_event; 1515 XEvent unused_event;
1528 1516
1529 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) 1517 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1530 ; 1518 ;
1531 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) 1519 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1532 ; 1520 ;
1533 1521
1534 if (isScrollbarWindow (ev.xany.window)) 1522 if (isScrollbarWindow (ev.xany.window))
1535 { 1523 {
1536 scrollBar.setIdle (); 1524 scrollBar.setIdle ();
1541 menubar_expose (); 1529 menubar_expose ();
1542#endif 1530#endif
1543 1531
1544#ifdef TRANSPARENT 1532#ifdef TRANSPARENT
1545 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1533 if (am_transparent && ev.xany.window == TermWin.parent[0])
1546 XClearWindow (display->display, ev.xany.window); 1534 XClearWindow (disp, ev.xany.window);
1547#endif 1535#endif
1548 } 1536 }
1549 break; 1537 break;
1550 1538
1551 case MotionNotify: 1539 case MotionNotify:
1565 1553
1566 if (ev.xany.window == TermWin.vt) 1554 if (ev.xany.window == TermWin.vt)
1567 { 1555 {
1568 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1556 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1569 { 1557 {
1570 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) 1558 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev))
1571 ; 1559 ;
1572 1560
1573 XQueryPointer (display->display, TermWin.vt, 1561 XQueryPointer (disp, TermWin.vt,
1574 &unused_root, &unused_child, 1562 &unused_root, &unused_child,
1575 &unused_root_x, &unused_root_y, 1563 &unused_root_x, &unused_root_y,
1576 &ev.xbutton.x, &ev.xbutton.y, 1564 &ev.xbutton.x, &ev.xbutton.y,
1577 &ev.xbutton.state); 1565 &ev.xbutton.state);
1578#ifdef MOUSE_THRESHOLD 1566#ifdef MOUSE_THRESHOLD
1642#endif 1630#endif
1643 } 1631 }
1644 } 1632 }
1645 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1633 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1646 { 1634 {
1647 while (XCheckTypedWindowEvent (display->display, scrollBar.win, 1635 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1648 MotionNotify, &ev)) 1636 MotionNotify, &ev))
1649 ; 1637 ;
1650 1638
1651 XQueryPointer (display->display, scrollBar.win, 1639 XQueryPointer (disp, scrollBar.win,
1652 &unused_root, &unused_child, 1640 &unused_root, &unused_child,
1653 &unused_root_x, &unused_root_y, 1641 &unused_root_x, &unused_root_y,
1654 &ev.xbutton.x, &ev.xbutton.y, 1642 &ev.xbutton.x, &ev.xbutton.y,
1655 &unused_mask); 1643 &unused_mask);
1656 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1644 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1675 case PropertyNotify: 1663 case PropertyNotify:
1676 /* 1664 /*
1677 * if user used some Esetroot compatible prog to set the root bg, 1665 * if user used some Esetroot compatible prog to set the root bg,
1678 * use the property to determine the pixmap. We use it later on. 1666 * use the property to determine the pixmap. We use it later on.
1679 */ 1667 */
1680 if (xa[XA_XROOTPMAPID] == 0)
1681 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1682
1683 if (ev.xproperty.atom != xa[XA_XROOTPMAPID]) 1668 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1669 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1684 return; 1670 return;
1685 1671
1686 /* FALLTHROUGH */ 1672 /* FALLTHROUGH */
1687 case ReparentNotify: 1673 case ReparentNotify:
1688 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1674 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1760 { 1746 {
1761 case Button1: 1747 case Button1:
1762 /* allow meta + click to select rectangular areas */ 1748 /* allow meta + click to select rectangular areas */
1763 /* should be done in screen.C */ 1749 /* should be done in screen.C */
1764#if ENABLE_FRILLS 1750#if ENABLE_FRILLS
1765 selection.rect = !! (ev.state & ModMetaMask); 1751 selection.rect = !!(ev.state & ModMetaMask);
1766#else 1752#else
1767 selection.rect = false; 1753 selection.rect = false;
1768#endif 1754#endif
1769 1755
1770 /* allow shift+left click to extend selection */ 1756 /* allow shift+left click to extend selection */
2096 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2082 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2097 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2083 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2098 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2084 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2099 int i; 2085 int i;
2100 2086
2101 Visual* visual = display->visual; 2087 Visual *visual = display->visual;
2102 2088
2103 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2089 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2104 2090
2105 /* for convenience */ 2091 /* for convenience */
2106 mask_r = visual->red_mask; 2092 mask_r = visual->red_mask;
2327 Atom atype; 2313 Atom atype;
2328 unsigned char *prop = NULL; 2314 unsigned char *prop = NULL;
2329 Window root, oldp, *list; 2315 Window root, oldp, *list;
2330 Pixmap rootpixmap = None; 2316 Pixmap rootpixmap = None;
2331 XWindowAttributes wattr, wrootattr; 2317 XWindowAttributes wattr, wrootattr;
2318 dDisp;
2332 2319
2333 pchanged = 0; 2320 pchanged = 0;
2334 2321
2335 if (!(options & Opt_transparent)) 2322 if (!(options & Opt_transparent))
2336 return pchanged; /* Don't try any more */ 2323 return pchanged; /* Don't try any more */
2337 2324
2338 XGetWindowAttributes (display->display, display->root, &wrootattr); 2325 XGetWindowAttributes (disp, display->root, &wrootattr);
2339 rootdepth = wrootattr.depth; 2326 rootdepth = wrootattr.depth;
2340 2327
2341 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2328 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2342 2329
2343 if (rootdepth != wattr.depth) 2330 if (rootdepth != wattr.depth)
2344 { 2331 {
2345 if (am_transparent) 2332 if (am_transparent)
2346 { 2333 {
2347 pchanged = 1; 2334 pchanged = 1;
2348 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2335 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2349 am_transparent = am_pixmap_trans = 0; 2336 am_transparent = am_pixmap_trans = 0;
2350 } 2337 }
2351 2338
2352 return pchanged; /* Don't try any more */ 2339 return pchanged; /* Don't try any more */
2353 } 2340 }
2354 2341
2355 /* Get all X ops out of the queue so that our information is up-to-date. */ 2342 /* Get all X ops out of the queue so that our information is up-to-date. */
2356 XSync (display->display, False); 2343 XSync (disp, False);
2357 2344
2358 /* 2345 /*
2359 * Make the frame window set by the window manager have 2346 * Make the frame window set by the window manager have
2360 * the root background. Some window managers put multiple nested frame 2347 * the root background. Some window managers put multiple nested frame
2361 * windows for each client, so we have to take care about that. 2348 * windows for each client, so we have to take care about that.
2362 */ 2349 */
2363 i = (xa[XA_XROOTPMAPID] 2350 i = (xa[XA_XROOTPMAP_ID]
2364 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2351 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2365 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2352 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2366 &nitems, &bytes_after, &prop) == Success); 2353 &nitems, &bytes_after, &prop) == Success);
2367 2354
2368 if (!i || prop == NULL) 2355 if (!i || prop == NULL)
2369 i = (xa[XA_XSETROOTID] 2356 i = (xa[XA_ESETROOT_PMAP_ID]
2370 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2357 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2371 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2358 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2372 &nitems, &bytes_after, &prop) == Success); 2359 &nitems, &bytes_after, &prop) == Success);
2373 2360
2374 if (!i || prop == NULL 2361 if (!i || prop == NULL
2375#if TINTING 2362#if TINTING
2394 Window cr; 2381 Window cr;
2395 XImage *image; 2382 XImage *image;
2396 GC gc; 2383 GC gc;
2397 XGCValues gcvalue; 2384 XGCValues gcvalue;
2398 2385
2399 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2386 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2400 0, 0, &sx, &sy, &cr); 2387 0, 0, &sx, &sy, &cr);
2401 nw = (unsigned int)szHint.width; 2388 nw = (unsigned int)szHint.width;
2402 nh = (unsigned int)szHint.height; 2389 nh = (unsigned int)szHint.height;
2403 nx = ny = 0; 2390 nx = ny = 0;
2404 2391
2416 sy = 0; 2403 sy = 0;
2417 } 2404 }
2418 2405
2419 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2406 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2420 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2407 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2408
2409 XSync (disp, False);
2421 allowedxerror = -1; 2410 allowedxerror = -1;
2422 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2411 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2423 2412
2424 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2413 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2425 /* XXX: may need a delay here? */ 2414 /* XXX: may need a delay here? */
2426 allowedxerror = 0; 2415 allowedxerror = 0;
2427 2416
2430 if (am_transparent && am_pixmap_trans) 2419 if (am_transparent && am_pixmap_trans)
2431 { 2420 {
2432 pchanged = 1; 2421 pchanged = 1;
2433 if (TermWin.pixmap != None) 2422 if (TermWin.pixmap != None)
2434 { 2423 {
2435 XFreePixmap (display->display, TermWin.pixmap); 2424 XFreePixmap (disp, TermWin.pixmap);
2436 TermWin.pixmap = None; 2425 TermWin.pixmap = None;
2437 } 2426 }
2438 } 2427 }
2439 2428
2440 am_pixmap_trans = 0; 2429 am_pixmap_trans = 0;
2441 } 2430 }
2442 else 2431 else
2443 { 2432 {
2444 if (TermWin.pixmap != None) 2433 if (TermWin.pixmap != None)
2445 XFreePixmap (display->display, TermWin.pixmap); 2434 XFreePixmap (disp, TermWin.pixmap);
2446 2435
2447#if TINTING 2436#if TINTING
2448 if (ISSET_PIXCOLOR (Color_tint)) 2437 if (ISSET_PIXCOLOR (Color_tint))
2449 { 2438 {
2450 unsigned short rm, gm, bm; 2439 unsigned short rm, gm, bm;
2454 2443
2455 ShadeXImage (display, image, shade, rm, gm, bm); 2444 ShadeXImage (display, image, shade, rm, gm, bm);
2456 } 2445 }
2457#endif 2446#endif
2458 2447
2459 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2448 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2460 szHint.width, szHint.height, image->depth); 2449 szHint.width, szHint.height, image->depth);
2461 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2450 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2462 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2451 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2463 nx, ny, image->width, image->height); 2452 nx, ny, image->width, image->height);
2464 XFreeGC (display->display, gc); 2453 XFreeGC (disp, gc);
2465 XDestroyImage (image); 2454 XDestroyImage (image);
2466 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); 2455 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2467 XClearWindow (display->display, TermWin.parent[0]); 2456 XClearWindow (disp, TermWin.parent[0]);
2468 2457
2469 if (!am_transparent || !am_pixmap_trans) 2458 if (!am_transparent || !am_pixmap_trans)
2470 pchanged = 1; 2459 pchanged = 1;
2471 2460
2472 am_transparent = am_pixmap_trans = 1; 2461 am_transparent = am_pixmap_trans = 1;
2473 } 2462 }
2474 } 2463 }
2475 2464
2476 if (!am_pixmap_trans) 2465 if (am_pixmap_trans)
2466 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2467 else
2477 { 2468 {
2478 unsigned int n; 2469 unsigned int n;
2479 /* 2470 /*
2480 * InheritPixmap transparency 2471 * InheritPixmap transparency
2481 */ 2472 */
2482 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2473 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2483 { 2474 {
2484 oldp = TermWin.parent[i]; 2475 oldp = TermWin.parent[i];
2485 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2476 XQueryTree (disp, TermWin.parent[i - 1], &root,
2486 &TermWin.parent[i], &list, &n); 2477 &TermWin.parent[i], &list, &n);
2487 XFree (list); 2478 XFree (list);
2488 2479
2489 if (TermWin.parent[i] == display->root) 2480 if (TermWin.parent[i] == display->root)
2490 { 2481 {
2502 2493
2503 if (pchanged) 2494 if (pchanged)
2504 { 2495 {
2505 for (; n < (unsigned int)i; n++) 2496 for (; n < (unsigned int)i; n++)
2506 { 2497 {
2507 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 2498 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2508 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2499 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2509 { 2500 {
2510 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2501 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2511 break; 2502 break;
2512 } 2503 }
2513 } 2504 }
2514 } 2505 }
2515 2506
2516 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) 2507 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2517 { 2508 {
2518 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); 2509 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2519 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2510 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2520 am_transparent = 0; 2511 am_transparent = 0;
2521 /* XXX: also turn off Opt_transparent? */ 2512 /* XXX: also turn off Opt_transparent? */
2522 } 2513 }
2523 else 2514 else
2524 { 2515 {
2527 * needed for fvwm2.2.2 (and before?) */ 2518 * needed for fvwm2.2.2 (and before?) */
2528 sleep (1); 2519 sleep (1);
2529#endif 2520#endif
2530 for (n = 0; n < (unsigned int)i; n++) 2521 for (n = 0; n < (unsigned int)i; n++)
2531 { 2522 {
2532 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); 2523 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2533 XClearWindow (display->display, TermWin.parent[n]); 2524 XClearWindow (disp, TermWin.parent[n]);
2534 } 2525 }
2535 2526
2536 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); 2527 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2537 am_transparent = 1; 2528 am_transparent = 1;
2538 } 2529 }
2539 2530
2540 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2531 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2541 TermWin.parent[i] = None; 2532 TermWin.parent[i] = None;
2542 } 2533 }
2543 2534
2544 if (scrollBar.win) 2535 if (scrollBar.win)
2545 { 2536 {
2546 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2537 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2547 scrollBar.setIdle (); 2538 scrollBar.setIdle ();
2548 scrollbar_show (0); 2539 scrollbar_show (0);
2540 }
2541
2542 if (am_transparent)
2543 {
2544 want_refresh = want_full_refresh = 1;
2545 if (am_pixmap_trans)
2546 flush ();
2549 } 2547 }
2550 2548
2551 return pchanged; 2549 return pchanged;
2552} 2550}
2553#endif 2551#endif
2705 if (len == (size_t)-1) 2703 if (len == (size_t)-1)
2706 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2704 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2707 2705
2708 // assume wchar == unicode 2706 // assume wchar == unicode
2709 cmdbuf_ptr += len; 2707 cmdbuf_ptr += len;
2710 return wc; 2708 return wc & UNICODE_MASK;
2711 } 2709 }
2712 2710
2713 return NOCHAR; 2711 return NOCHAR;
2714} 2712}
2715 2713
3417rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3415rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3418{ 3416{
3419 int x, y; 3417 int x, y;
3420 XWindowAttributes wattr; 3418 XWindowAttributes wattr;
3421 Window wdummy; 3419 Window wdummy;
3420 dDisp;
3422 3421
3423 if (nargs == 0) 3422 if (nargs == 0)
3424 return; 3423 return;
3425 3424
3426 switch (args[0]) 3425 switch (args[0])
3427 { 3426 {
3428 /* 3427 /*
3429 * commands 3428 * commands
3430 */ 3429 */
3431 case 1: /* deiconify window */ 3430 case 1: /* deiconify window */
3432 XMapWindow (display->display, TermWin.parent[0]); 3431 XMapWindow (disp, TermWin.parent[0]);
3433 break; 3432 break;
3434 case 2: /* iconify window */ 3433 case 2: /* iconify window */
3435 XIconifyWindow (display->display, TermWin.parent[0], 3434 XIconifyWindow (disp, TermWin.parent[0], display->screen);
3436 DefaultScreen (display->display));
3437 break; 3435 break;
3438 case 3: /* set position (pixels) */ 3436 case 3: /* set position (pixels) */
3439 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); 3437 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]);
3440 break; 3438 break;
3441 case 4: /* set size (pixels) */ 3439 case 4: /* set size (pixels) */
3442 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3440 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3443 break; 3441 break;
3444 case 5: /* raise window */ 3442 case 5: /* raise window */
3445 XRaiseWindow (display->display, TermWin.parent[0]); 3443 XRaiseWindow (disp, TermWin.parent[0]);
3446 break; 3444 break;
3447 case 6: /* lower window */ 3445 case 6: /* lower window */
3448 XLowerWindow (display->display, TermWin.parent[0]); 3446 XLowerWindow (disp, TermWin.parent[0]);
3449 break; 3447 break;
3450 case 7: /* refresh window */ 3448 case 7: /* refresh window */
3451 scr_touch (true); 3449 scr_touch (true);
3452 break; 3450 break;
3453 case 8: /* set size (chars) */ 3451 case 8: /* set size (chars) */
3465 3463
3466 /* 3464 /*
3467 * reports - some output format copied from XTerm 3465 * reports - some output format copied from XTerm
3468 */ 3466 */
3469 case 11: /* report window state */ 3467 case 11: /* report window state */
3470 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3468 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3471 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3469 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3472 break; 3470 break;
3473 case 13: /* report window position */ 3471 case 13: /* report window position */
3474 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3472 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3475 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3473 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root,
3476 -wattr.border_width, -wattr.border_width, 3474 -wattr.border_width, -wattr.border_width,
3477 &x, &y, &wdummy); 3475 &x, &y, &wdummy);
3478 tt_printf ("\033[3;%d;%dt", x, y); 3476 tt_printf ("\033[3;%d;%dt", x, y);
3479 break; 3477 break;
3480 case 14: /* report window size (pixels) */ 3478 case 14: /* report window size (pixels) */
3481 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3479 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3482 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3480 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3483 break; 3481 break;
3484 case 18: /* report text area size (chars) */ 3482 case 18: /* report text area size (chars) */
3485 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3483 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3486 break; 3484 break;
3488 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3486 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3489 break; 3487 break;
3490 case 20: /* report icon label */ 3488 case 20: /* report icon label */
3491 { 3489 {
3492 char *s; 3490 char *s;
3493 XGetIconName (display->display, TermWin.parent[0], &s); 3491 XGetIconName (disp, TermWin.parent[0], &s);
3494 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3492 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3495 XFree (s); 3493 XFree (s);
3496 } 3494 }
3497 break; 3495 break;
3498 case 21: /* report window title */ 3496 case 21: /* report window title */
3499 { 3497 {
3500 char *s; 3498 char *s;
3501 XFetchName (display->display, TermWin.parent[0], &s); 3499 XFetchName (disp, TermWin.parent[0], &s);
3502 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3500 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3503 XFree (s); 3501 XFree (s);
3504 } 3502 }
3505 break; 3503 break;
3506 } 3504 }
3513 * ends_how is terminator used. returned input must be free()'d 3511 * ends_how is terminator used. returned input must be free()'d
3514 */ 3512 */
3515unsigned char * 3513unsigned char *
3516rxvt_term::get_to_st (unicode_t &ends_how) 3514rxvt_term::get_to_st (unicode_t &ends_how)
3517{ 3515{
3518 unicode_t seen_esc = 0, ch; 3516 unicode_t ch;
3517 bool seen_esc = false;
3519 unsigned int n = 0; 3518 unsigned int n = 0;
3520 unsigned char *s;
3521 unsigned char string[STRING_MAX]; 3519 wchar_t string[STRING_MAX];
3522 3520
3523 while ((ch = cmd_getc ()) != NOCHAR) 3521 while ((ch = cmd_getc ()) != NOCHAR)
3524 { 3522 {
3525 if (seen_esc) 3523 if (seen_esc)
3526 { 3524 {
3529 else 3527 else
3530 return NULL; 3528 return NULL;
3531 } 3529 }
3532 else if (ch == C0_ESC) 3530 else if (ch == C0_ESC)
3533 { 3531 {
3534 seen_esc = 1; 3532 seen_esc = true;
3535 continue; 3533 continue;
3536 } 3534 }
3537 else if (ch == C0_BEL || ch == CHAR_ST) 3535 else if (ch == C0_BEL || ch == CHAR_ST)
3538 break; 3536 break;
3539 else if (ch < 0x20) 3537 else if (ch < 0x20)
3540 return NULL; /* other control character - exit */ 3538 return NULL; /* other control character - exit */
3541 3539
3542 seen_esc = 0; 3540 seen_esc = false;
3543 3541
3544 if (n >= sizeof (string) - 1) 3542 if (n >= sizeof (string) - 1)
3545 // stop at some sane length 3543 // stop at some sane length
3546 return NULL; 3544 return NULL;
3547 3545
3551 string[n++] = ch; 3549 string[n++] = ch;
3552 } 3550 }
3553 3551
3554 string[n++] = '\0'; 3552 string[n++] = '\0';
3555 3553
3556 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3557 return NULL;
3558
3559 ends_how = (ch == 0x5c ? C0_ESC : ch); 3554 ends_how = (ch == 0x5c ? C0_ESC : ch);
3560 strncpy (s, string, n); 3555
3561 return s; 3556 return (unsigned char *)rxvt_wcstombs (string);
3562} 3557}
3563 3558
3564/*----------------------------------------------------------------------*/ 3559/*----------------------------------------------------------------------*/
3565/* 3560/*
3566 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3561 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3651 int changed = 0; 3646 int changed = 0;
3652 int color; 3647 int color;
3653 char *buf, *name; 3648 char *buf, *name;
3654 bool query = str[0] == '?' && !str[1]; 3649 bool query = str[0] == '?' && !str[1];
3655 int saveop = op; 3650 int saveop = op;
3651 dDisp;
3656 3652
3657 assert (str != NULL); 3653 assert (str != NULL);
3658 switch (op) 3654 switch (op)
3659 { 3655 {
3660 case XTerm_name: 3656 case XTerm_name:
3667 set_title (str); 3663 set_title (str);
3668 break; 3664 break;
3669 case XTerm_property: 3665 case XTerm_property:
3670 if (str[0] == '?') 3666 if (str[0] == '?')
3671 { 3667 {
3672 Atom prop = XInternAtom (display->display, str + 1, True); 3668 Atom prop = display->atom (str + 1);
3673 Atom actual_type; 3669 Atom actual_type;
3674 int actual_format; 3670 int actual_format;
3675 unsigned long nitems; 3671 unsigned long nitems;
3676 unsigned long bytes_after; 3672 unsigned long bytes_after;
3677 unsigned char *value = 0; 3673 unsigned char *value = 0;
3678 const char *str = ""; 3674 const char *str = "";
3679 3675
3680 if (prop 3676 if (prop
3681 && XGetWindowProperty (display->display, TermWin.parent[0], 3677 && XGetWindowProperty (disp, TermWin.parent[0],
3682 prop, 0, 1<<16, 0, AnyPropertyType, 3678 prop, 0, 1<<16, 0, AnyPropertyType,
3683 &actual_type, &actual_format, 3679 &actual_type, &actual_format,
3684 &nitems, &bytes_after, &value) == Success 3680 &nitems, &bytes_after, &value) == Success
3685 && actual_type != None 3681 && actual_type != None
3686 && actual_format == 8) 3682 && actual_format == 8)
3695 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3691 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3696 3692
3697 if (eq) 3693 if (eq)
3698 { 3694 {
3699 *eq = 0; 3695 *eq = 0;
3700 XChangeProperty (display->display, TermWin.parent[0], 3696 set_utf8_property (display->atom (str), eq + 1);
3701 display->atom (str), XA_STRING, 8,
3702 PropModeReplace, (unsigned char *)eq + 1,
3703 strlen (eq + 1));
3704 } 3697 }
3705 else 3698 else
3706 XDeleteProperty (display->display, TermWin.parent[0], 3699 XDeleteProperty (disp, TermWin.parent[0],
3707 display->atom (str)); 3700 display->atom (str));
3708 } 3701 }
3709 break; 3702 break;
3710 3703
3711 case XTerm_Color: 3704 case XTerm_Color:
3786 { 3779 {
3787 str++; 3780 str++;
3788#if XPM_BACKGROUND 3781#if XPM_BACKGROUND
3789 changed += scale_pixmap (str); 3782 changed += scale_pixmap (str);
3790#endif 3783#endif
3791
3792 } 3784 }
3785
3793 if (changed) 3786 if (changed)
3794 { 3787 {
3795#ifdef XPM_BACKGROUND 3788#ifdef XPM_BACKGROUND
3796 resize_pixmap (); 3789 resize_pixmap ();
3797#endif 3790#endif
3838 if (query) 3831 if (query)
3839 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3832 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3840 else 3833 else
3841 { 3834 {
3842 set_locale (str); 3835 set_locale (str);
3836 pty.set_utf8_mode (enc_utf8);
3843# ifdef USE_XIM 3837# ifdef USE_XIM
3844 im_cb (); 3838 im_cb ();
3845# endif 3839# endif
3846 } 3840 }
3847 break; 3841 break;
4285 4279
4286/* ---------------------------------------------------------------------- */ 4280/* ---------------------------------------------------------------------- */
4287/* Write data to the pty as typed by the user, pasted with the mouse, 4281/* Write data to the pty as typed by the user, pasted with the mouse,
4288 * or generated by us in response to a query ESC sequence. 4282 * or generated by us in response to a query ESC sequence.
4289 */ 4283 */
4284const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4285
4290void 4286void
4291rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4287rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4292{ 4288{
4293 const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4289 if (v_buflen == 0)
4290 {
4291 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4294 4292
4295 if (len) 4293 if ((unsigned int)written == len)
4294 return;
4295
4296 data += written;
4297 len -= written;
4296 { 4298 }
4299
4300 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4301
4302 memcpy (v_buffer + v_buflen, data, len);
4303 v_buflen += len;
4304
4305 pty_ev.set (EVENT_READ | EVENT_WRITE);
4306}
4307
4308void rxvt_term::pty_write ()
4309{
4310 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4311
4312 if (written > 0)
4313 {
4314 v_buflen -= written;
4315
4297 if (v_buflen == 0) 4316 if (v_buflen == 0)
4298 { 4317 {
4299 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4300
4301 if ((unsigned int)written == len)
4302 return;
4303
4304 data += written;
4305 len -= written;
4306 }
4307
4308
4309 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4310
4311 memcpy (v_buffer + v_buflen, data, len);
4312 v_buflen += len;
4313 }
4314
4315 for (;;)
4316 {
4317 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4318
4319 if (written > 0)
4320 {
4321 v_buflen -= written;
4322
4323 if (v_buflen == 0)
4324 {
4325 free (v_buffer); 4318 free (v_buffer);
4326 v_buffer = 0; 4319 v_buffer = 0;
4327 v_buflen = 0; 4320 v_buflen = 0;
4328 4321
4329 pty_ev.set (EVENT_READ); 4322 pty_ev.set (EVENT_READ);
4330 return;
4331 }
4332
4333 memmove (v_buffer, v_buffer + written, v_buflen);
4334 }
4335 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4336 // original code just ignores this...
4337 destroy ();
4338 else
4339 {
4340 pty_ev.set (EVENT_READ | EVENT_WRITE);
4341 return; 4323 return;
4342 } 4324 }
4325
4326 memmove (v_buffer, v_buffer + written, v_buflen);
4343 } 4327 }
4328 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4329 // original code just ignores this...
4330 destroy ();
4344} 4331}
4345 4332
4346/*----------------------- end-of-file (C source) -----------------------*/ 4333/*----------------------- end-of-file (C source) -----------------------*/
4347 4334

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines