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.145 by root, Mon Aug 16 12:04:57 2004 UTC vs.
Revision 1.192 by root, Fri Feb 4 11:41:23 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#ifdef KEYSYM_RESOURCE
54# include "keyboard.h"
55#endif
56
53#include <wchar.h> 57#include <cwchar>
58#include <csignal>
54 59
55/*----------------------------------------------------------------------*/ 60/*----------------------------------------------------------------------*/
56 61
57#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 62#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
58 63
133 { 138 {
134 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x]; 139 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x];
135 140
136 if (t != NOCHAR || !x) 141 if (t != NOCHAR || !x)
137 { 142 {
138 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x]); 143 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x],
144 screen.rend[y + TermWin.saveLines - TermWin.view_start][x]);
139 iso14755buf = ISO_14755_54; 145 iso14755buf = ISO_14755_54;
140 break; 146 break;
141 } 147 }
142 148
143 x--; 149 x--;
146} 152}
147#endif 153#endif
148 154
149#if ENABLE_OVERLAY 155#if ENABLE_OVERLAY
150void 156void
151rxvt_term::iso14755_51 (wchar_t ch) 157rxvt_term::iso14755_51 (unicode_t ch, rend_t r)
152{ 158{
159 rxvt_fontset *fs = FONTSET (r);
160 rxvt_font *f = (*fs)[fs->find_font (ch)];
153 wchar_t *chr, *alloc; 161 wchar_t *chr, *alloc, ch2;
154 int len; 162 int len;
155 163
156#if ENABLE_COMBINING 164#if ENABLE_COMBINING
157 if (IS_COMPOSE (ch)) 165 if (IS_COMPOSE (ch))
158 { 166 {
161 rxvt_composite.expand (ch, chr); 169 rxvt_composite.expand (ch, chr);
162 } 170 }
163 else 171 else
164#endif 172#endif
165 { 173 {
174 ch2 = ch;
175
166 alloc = 0; 176 alloc = 0;
167 chr = &ch; 177 chr = &ch2;
168 len = 1; 178 len = 1;
169 } 179 }
170 180
171 scr_overlay_new (0, -1, 8 + 5, len); 181 int width = strlen (f->name);
182
183 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1);
184
185 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
172 186
173 for (int y = 0; y < len; y++) 187 for (int y = 0; y < len; y++)
174 { 188 {
175 char buf[9]; 189 char buf[9];
176 190
181 scr_overlay_set (9, y, '='); 195 scr_overlay_set (9, y, '=');
182#if !UNICODE3 196#if !UNICODE3
183 if (ch >= 0x10000) 197 if (ch >= 0x10000)
184 ch = 0xfffd; 198 ch = 0xfffd;
185#endif 199#endif
186 scr_overlay_set (11, y, ch); 200 scr_overlay_set (11, y, ch, r);
187 scr_overlay_set (12, y, NOCHAR); 201 scr_overlay_set (12, y, NOCHAR, r);
188 } 202 }
203
204 scr_overlay_set (0, len, f->name);
189 205
190#if ENABLE_COMBINING 206#if ENABLE_COMBINING
191 if (alloc) 207 if (alloc)
192 delete [] alloc; 208 delete [] alloc;
193#endif 209#endif
332 valid_keysym = keysym != NoSymbol; 348 valid_keysym = keysym != NoSymbol;
333 } 349 }
334 350
335 if (valid_keysym) 351 if (valid_keysym)
336 { 352 {
353#ifdef KEYSYM_RESOURCE
354 if (keyboard->dispatch (this, keysym, ev.state))
355 return;
356#endif
357
337 if (TermWin.saveLines) 358 if (TermWin.saveLines)
338 { 359 {
339#ifdef UNSHIFTED_SCROLLKEYS 360#ifdef UNSHIFTED_SCROLLKEYS
340 if (!ctrl && !meta) 361 if (!ctrl && !meta)
341#else 362#else
406 { 427 {
407 /* normal XTerm key bindings */ 428 /* normal XTerm key bindings */
408 case XK_Insert: /* Shift+Insert = paste mouse selection */ 429 case XK_Insert: /* Shift+Insert = paste mouse selection */
409 selection_request (ev.time, 0, 0); 430 selection_request (ev.time, 0, 0);
410 return; 431 return;
411#if TODO // TODO 432#if TODO
412 /* rxvt extras */ 433 /* rxvt extras */
413 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 434 case XK_KP_Add: /* Shift+KP_Add = bigger font */
414 change_font (FONT_UP); 435 change_font (FONT_UP);
415 return; 436 return;
416 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 437 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
475 } 496 }
476#endif 497#endif
477 498
478 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 499 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
479 { 500 {
480#ifdef KEYSYM_RESOURCE
481 if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL)
482 {
483 unsigned int l;
484 const unsigned char *kbuf0;
485
486 kbuf0 = (Keysym_map[keysym & 0xFF]);
487 l = (unsigned int)*kbuf0++;
488
489 /* escape prefix */
490 if (meta
491# ifdef META8_OPTION
492 && meta_char == C0_ESC
493# endif
494 )
495 {
496 const unsigned char ch = C0_ESC;
497 tt_write (&ch, 1);
498 }
499
500 tt_write (kbuf0, l);
501 return;
502 }
503 else
504#endif
505 { 501 {
506 newlen = 1; 502 newlen = 1;
507 switch (keysym) 503 switch (keysym)
508 { 504 {
509#ifndef NO_BACKSPACE_KEY 505#ifndef NO_BACKSPACE_KEY
776#undef FKEY 772#undef FKEY
777 default: 773 default:
778 newlen = 0; 774 newlen = 0;
779 break; 775 break;
780 } 776 }
777
781 if (newlen) 778 if (newlen)
782 len = strlen (kbuf); 779 len = strlen (kbuf);
783 } 780 }
784 781
785 /* 782 /*
793 } 790 }
794 else if (ctrl && keysym == XK_minus) 791 else if (ctrl && keysym == XK_minus)
795 { 792 {
796 len = 1; 793 len = 1;
797 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 794 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
795 }
796 else if (keysym == XK_ISO_Left_Tab)
797 {
798 strcpy (kbuf, "\033[Z");
799 len = 3;
798 } 800 }
799 else 801 else
800 { 802 {
801#ifdef META8_OPTION 803#ifdef META8_OPTION
802 /* set 8-bit on */ 804 /* set 8-bit on */
861#endif /* DEBUG_CMD */ 863#endif /* DEBUG_CMD */
862 tt_write (kbuf, (unsigned int)len); 864 tt_write (kbuf, (unsigned int)len);
863} 865}
864/*}}} */ 866/*}}} */
865 867
866#if (MENUBAR_MAX) 868#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
867/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 869/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
868/* attempt to `write' count to the input buffer */ 870/* attempt to `write' count to the input buffer */
869unsigned int 871unsigned int
870rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 872rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
871{ 873{
894 896
895 cmd_parse (); 897 cmd_parse ();
896 898
897 return 0; 899 return 0;
898} 900}
899#endif /* MENUBAR_MAX */ 901#endif
900 902
901void 903void
902rxvt_term::flush () 904rxvt_term::flush ()
903{ 905{
906 flush_ev.stop ();
907
904#ifdef TRANSPARENT 908#ifdef TRANSPARENT
905 if (want_full_refresh) 909 if (want_full_refresh)
906 { 910 {
907 want_full_refresh = 0; 911 want_full_refresh = 0;
908 scr_clear (); 912 scr_clear ();
918 IMSendSpot (); 922 IMSendSpot ();
919#endif 923#endif
920 } 924 }
921 925
922 display->flush (); 926 display->flush ();
923
924 flush_ev.stop ();
925} 927}
926 928
927void 929void
928rxvt_term::check_cb (check_watcher &w) 930rxvt_term::check_cb (check_watcher &w)
929{ 931{
1005{ 1007{
1006 if (mouse_slip_wheel_speed == 0 1008 if (mouse_slip_wheel_speed == 0
1007 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1009 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1008 : scr_page (UP, mouse_slip_wheel_speed)) 1010 : scr_page (UP, mouse_slip_wheel_speed))
1009 { 1011 {
1012 if (TermWin.view_start == TermWin.nscrolled ||
1013 TermWin.view_start == 0)
1014 mouse_slip_wheel_speed = 0;
1015
1010 refresh_type |= SMOOTH_REFRESH; 1016 refresh_type |= SMOOTH_REFRESH;
1011 want_refresh = 1; 1017 want_refresh = 1;
1012 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1018 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1013 } 1019 }
1014} 1020}
1046rxvt_term::pty_cb (io_watcher &w, short revents) 1052rxvt_term::pty_cb (io_watcher &w, short revents)
1047{ 1053{
1048 SET_R (this); 1054 SET_R (this);
1049 SET_LOCALE (locale); 1055 SET_LOCALE (locale);
1050 1056
1051 if (revents & EVENT_WRITE)
1052 tt_write (0, 0);
1053 else if (revents & EVENT_READ) 1057 if (revents & EVENT_READ)
1054 // loop, but don't allow a single term to monopolize us 1058 // loop, but don't allow a single term to monopolize us
1055 while (pty_fill ()) 1059 while (pty_fill ())
1056 if (cmd_parse ()) 1060 if (cmd_parse ())
1057 break; 1061 break;
1062
1063 if (revents & EVENT_WRITE)
1064 pty_write ();
1058} 1065}
1059 1066
1060void 1067void
1061rxvt_term::pointer_unblank () 1068rxvt_term::pointer_unblank ()
1062{ 1069{
1076rxvt_term::pointer_blank () 1083rxvt_term::pointer_blank ()
1077{ 1084{
1078 if (! (options & Opt_pointerBlank)) 1085 if (! (options & Opt_pointerBlank))
1079 return; 1086 return;
1080 1087
1081 XDefineCursor (display->display, TermWin.vt, blank_cursor); 1088 XDefineCursor (display->display, TermWin.vt, display->blank_cursor);
1082 XFlush (display->display); 1089 XFlush (display->display);
1083 1090
1084 hidden_pointer = 1; 1091 hidden_pointer = 1;
1085} 1092}
1086 1093
1137 + ((MEvent.state & ModMetaMask) ? 8 : 0) 1144 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1138 + ((MEvent.state & ControlMask) ? 16 : 0); 1145 + ((MEvent.state & ControlMask) ? 16 : 0);
1139#ifdef MOUSE_REPORT_DOUBLECLICK 1146#ifdef MOUSE_REPORT_DOUBLECLICK
1140 key_state += ((MEvent.clicks > 1) ? 32 : 0); 1147 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1141#endif 1148#endif
1142
1143 } 1149 }
1144 1150
1145#ifdef DEBUG_MOUSEREPORT 1151#if DEBUG_MOUSEREPORT
1146 fprintf (stderr, "Mouse ["); 1152 fprintf (stderr, "Mouse [");
1147 if (key_state & 16) 1153 if (key_state & 16)
1148 fputc ('C', stderr); 1154 fputc ('C', stderr);
1149 if (key_state & 4) 1155 if (key_state & 4)
1150 fputc ('S', stderr); 1156 fputc ('S', stderr);
1154 fputc ('2', stderr); 1160 fputc ('2', stderr);
1155 fprintf (stderr, "]: <%d>, %d/%d\n", 1161 fprintf (stderr, "]: <%d>, %d/%d\n",
1156 button_number, 1162 button_number,
1157 x + 1, 1163 x + 1,
1158 y + 1); 1164 y + 1);
1159#else 1165#endif
1166
1160 tt_printf ("\033[M%c%c%c", 1167 tt_printf ("\033[M%c%c%c",
1161 (32 + button_number + key_state), 1168 (32 + button_number + key_state),
1162 (32 + x + 1), 1169 (32 + x + 1),
1163 (32 + y + 1)); 1170 (32 + y + 1));
1164#endif
1165} 1171}
1166 1172
1167#ifdef USING_W11LIB 1173#ifdef USING_W11LIB
1168void 1174void
1169rxvt_W11_process_x_event (XEvent *ev) 1175rxvt_W11_process_x_event (XEvent *ev)
1176 1182
1177/*{{{ process an X event */ 1183/*{{{ process an X event */
1178void 1184void
1179rxvt_term::x_cb (XEvent &ev) 1185rxvt_term::x_cb (XEvent &ev)
1180{ 1186{
1187 dDisp;
1188
1181 SET_R (this); 1189 SET_R (this);
1182 SET_LOCALE (locale); 1190 SET_LOCALE (locale);
1183 1191
1184#if defined(CURSOR_BLINK) 1192#if defined(CURSOR_BLINK)
1185 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1193 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1206 if (ev.type == KeyPress && hidden_pointer == 0) 1214 if (ev.type == KeyPress && hidden_pointer == 0)
1207 pointer_blank (); 1215 pointer_blank ();
1208 } 1216 }
1209#endif 1217#endif
1210 1218
1211#ifdef USE_XIM
1212 if (XFilterEvent (&ev, None))
1213 return;
1214#endif
1215
1216 Window unused_root, unused_child; 1219 Window unused_root, unused_child;
1217 int unused_root_x, unused_root_y; 1220 int unused_root_x, unused_root_y;
1218 unsigned int unused_mask; 1221 unsigned int unused_mask;
1219 1222
1220 switch (ev.type) 1223 switch (ev.type)
1221 { 1224 {
1222 case KeyPress: 1225 case KeyPress:
1223#if ISO_14755 1226#if ISO_14755
1227 1230
1228 break; 1231 break;
1229 1232
1230 case KeyRelease: 1233 case KeyRelease:
1231 { 1234 {
1232#if (defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)) || defined (ENABLE_FRILLS) 1235#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1233 KeySym ks; 1236 KeySym ks;
1234 1237
1235 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ 1238 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1236#endif 1239#endif
1237 1240
1321 Atom ActualType; 1324 Atom ActualType;
1322 int ActualFormat; 1325 int ActualFormat;
1323 unsigned char *data; 1326 unsigned char *data;
1324 unsigned long Size, RemainingBytes; 1327 unsigned long Size, RemainingBytes;
1325 1328
1326 XGetWindowProperty (display->display, display->root, 1329 XGetWindowProperty (disp, display->root,
1327 xa[XA_DNDSELECTION], 1330 xa[XA_DNDSELECTION],
1328 0L, 1000000L, 1331 0L, 1000000L,
1329 False, AnyPropertyType, 1332 False, AnyPropertyType,
1330 &ActualType, &ActualFormat, 1333 &ActualType, &ActualFormat,
1331 &Size, &RemainingBytes, 1334 &Size, &RemainingBytes,
1332 &data); 1335 &data);
1333 XChangeProperty (display->display, display->root, 1336 set_string_property (XA_CUT_BUFFER0, data);
1334 XA_CUT_BUFFER0, XA_STRING,
1335 8, PropModeReplace,
1336 data, strlen (data));
1337 XFree (data); 1337 XFree (data);
1338 selection_paste (display->root, XA_CUT_BUFFER0, True); 1338 selection_paste (display->root, XA_CUT_BUFFER0, true);
1339 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1339 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1340 } 1340 }
1341#endif /* OFFIX_DND */ 1341#endif /* OFFIX_DND */
1342 break; 1342 break;
1343 1343
1344 case MappingNotify: 1344 case MappingNotify:
1388#endif 1388#endif
1389#ifdef OFF_FOCUS_FADING 1389#ifdef OFF_FOCUS_FADING
1390 if (rs[Rs_fade]) 1390 if (rs[Rs_fade])
1391 { 1391 {
1392 pix_colors = pix_colors_focused; 1392 pix_colors = pix_colors_focused;
1393 set_colorfgbg ();
1394 scr_clear (); 1393 scr_recolour ();
1395 scr_touch (true);
1396 } 1394 }
1397#endif 1395#endif
1398 1396
1399 } 1397 }
1400 break; 1398 break;
1402 case FocusOut: 1400 case FocusOut:
1403 if (TermWin.focus) 1401 if (TermWin.focus)
1404 { 1402 {
1405 TermWin.focus = 0; 1403 TermWin.focus = 0;
1406 want_refresh = 1; 1404 want_refresh = 1;
1405
1406#if ENABLE_FRILLS || ISO_14755
1407 iso14755buf = 0;
1408#endif
1409#if ENABLE_OVERLAY
1410 scr_overlay_off ();
1411#endif
1407#ifdef USE_XIM 1412#ifdef USE_XIM
1408 if (Input_Context != NULL) 1413 if (Input_Context != NULL)
1409 XUnsetICFocus (Input_Context); 1414 XUnsetICFocus (Input_Context);
1410#endif 1415#endif
1411#ifdef CURSOR_BLINK 1416#ifdef CURSOR_BLINK
1415#endif 1420#endif
1416#ifdef OFF_FOCUS_FADING 1421#ifdef OFF_FOCUS_FADING
1417 if (rs[Rs_fade]) 1422 if (rs[Rs_fade])
1418 { 1423 {
1419 pix_colors = pix_colors_unfocused; 1424 pix_colors = pix_colors_unfocused;
1420 set_colorfgbg ();
1421 scr_clear (); 1425 scr_recolour ();
1422 scr_touch (true);
1423 } 1426 }
1424#endif 1427#endif
1425
1426 } 1428 }
1427 break; 1429 break;
1428 1430
1429 case ConfigureNotify: 1431 case ConfigureNotify:
1430 if (ev.xconfigure.window == TermWin.parent[0]) 1432 if (ev.xconfigure.window == TermWin.parent[0])
1435 { /* Wrap lots of configures into one */ 1437 { /* Wrap lots of configures into one */
1436 width = ev.xconfigure.width; 1438 width = ev.xconfigure.width;
1437 height = ev.xconfigure.height; 1439 height = ev.xconfigure.height;
1438 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); 1440 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1439 } 1441 }
1440 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev)); 1442 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev));
1441 1443
1442 if (szHint.width != width || szHint.height != height) 1444 if (szHint.width != width || szHint.height != height)
1445 {
1446 seen_resize = 1;
1443 resize_all_windows (width, height, 1); 1447 resize_all_windows (width, height, 1);
1448 }
1444 1449
1445#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1450#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1446 if (options & Opt_transparent) 1451 if (options & Opt_transparent)
1447 {
1448 check_our_parents (); 1452 check_our_parents ();
1449 if (am_transparent)
1450 want_refresh = want_full_refresh = 1;
1451 }
1452#endif 1453#endif
1453 } 1454 }
1454 break; 1455 break;
1455 1456
1456 case PropertyNotify: 1457 case PropertyNotify:
1464 selection_clear (); 1465 selection_clear ();
1465 break; 1466 break;
1466 1467
1467 case SelectionNotify: 1468 case SelectionNotify:
1468 if (selection_wait == Sel_normal) 1469 if (selection_wait == Sel_normal)
1469 selection_paste (ev.xselection.requestor, 1470 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1470 ev.xselection.property, True);
1471 break; 1471 break;
1472 1472
1473 case SelectionRequest: 1473 case SelectionRequest:
1474 selection_send (ev.xselectionrequest); 1474 selection_send (ev.xselectionrequest);
1475 break; 1475 break;
1499 if (ev.xany.window == TermWin.vt) 1499 if (ev.xany.window == TermWin.vt)
1500 { 1500 {
1501 do 1501 do
1502 scr_expose (ev.xexpose.x, ev.xexpose.y, 1502 scr_expose (ev.xexpose.x, ev.xexpose.y,
1503 ev.xexpose.width, ev.xexpose.height, False); 1503 ev.xexpose.width, ev.xexpose.height, False);
1504 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); 1504 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev));
1505 1505
1506 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1506 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1507 1507
1508 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) 1508 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev))
1509 scr_expose (ev.xexpose.x, ev.xexpose.y, 1509 scr_expose (ev.xexpose.x, ev.xexpose.y,
1510 ev.xexpose.width, ev.xexpose.height, False); 1510 ev.xexpose.width, ev.xexpose.height, False);
1511 1511
1512 scr_refresh (refresh_type); 1512 scr_refresh (refresh_type);
1513 } 1513 }
1514 else 1514 else
1515 { 1515 {
1516 XEvent unused_event; 1516 XEvent unused_event;
1517 1517
1518 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) 1518 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1519 ; 1519 ;
1520 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) 1520 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1521 ; 1521 ;
1522 1522
1523 if (isScrollbarWindow (ev.xany.window)) 1523 if (isScrollbarWindow (ev.xany.window))
1524 { 1524 {
1525 scrollBar.setIdle (); 1525 scrollBar.setIdle ();
1530 menubar_expose (); 1530 menubar_expose ();
1531#endif 1531#endif
1532 1532
1533#ifdef TRANSPARENT 1533#ifdef TRANSPARENT
1534 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1534 if (am_transparent && ev.xany.window == TermWin.parent[0])
1535 XClearWindow (display->display, ev.xany.window); 1535 XClearWindow (disp, ev.xany.window);
1536#endif 1536#endif
1537 } 1537 }
1538 break; 1538 break;
1539 1539
1540 case MotionNotify: 1540 case MotionNotify:
1547 { 1547 {
1548 menubar_control (ev.xbutton); 1548 menubar_control (ev.xbutton);
1549 break; 1549 break;
1550 } 1550 }
1551#endif 1551#endif
1552 if ((priv_modes & PrivMode_mouse_report) && ! (bypass_keystate)) 1552 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1553 break; 1553 break;
1554 1554
1555 if (ev.xany.window == TermWin.vt) 1555 if (ev.xany.window == TermWin.vt)
1556 { 1556 {
1557 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1557 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1558 { 1558 {
1559 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) 1559 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev))
1560 ; 1560 ;
1561 1561
1562 XQueryPointer (display->display, TermWin.vt, 1562 XQueryPointer (disp, TermWin.vt,
1563 &unused_root, &unused_child, 1563 &unused_root, &unused_child,
1564 &unused_root_x, &unused_root_y, 1564 &unused_root_x, &unused_root_y,
1565 & (ev.xbutton.x), & (ev.xbutton.y), 1565 &ev.xbutton.x, &ev.xbutton.y,
1566 &unused_mask); 1566 &ev.xbutton.state);
1567#ifdef MOUSE_THRESHOLD 1567#ifdef MOUSE_THRESHOLD
1568 /* deal with a `jumpy' mouse */ 1568 /* deal with a `jumpy' mouse */
1569 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) 1569 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1570 { 1570 {
1571#endif 1571#endif
1576 iso14755_54 (ev.xbutton.x, ev.xbutton.y); 1576 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1577 break; 1577 break;
1578 } 1578 }
1579#endif 1579#endif
1580 selection_extend (ev.xbutton.x, ev.xbutton.y, 1580 selection_extend (ev.xbutton.x, ev.xbutton.y,
1581 (ev.xbutton.state & Button3Mask) ? 2 : 0); 1581 ev.xbutton.state & Button3Mask ? 2 : 0);
1582
1582#ifdef SELECTION_SCROLLING 1583#ifdef SELECTION_SCROLLING
1583 if (ev.xbutton.y < TermWin.int_bwidth 1584 if (ev.xbutton.y < TermWin.int_bwidth
1584 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1585 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1))
1585 { 1586 {
1586 int dist; 1587 int dist;
1597 selection_save_x = ev.xbutton.x; 1598 selection_save_x = ev.xbutton.x;
1598 selection_save_y = ev.xbutton.y; 1599 selection_save_y = ev.xbutton.y;
1599 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1600 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1600 1601
1601 /* calc number of lines to scroll */ 1602 /* calc number of lines to scroll */
1602 if (ev.xbutton.y<TermWin.int_bwidth) 1603 if (ev.xbutton.y < TermWin.int_bwidth)
1603 { 1604 {
1604 scroll_selection_dir = UP; 1605 scroll_selection_dir = UP;
1605 dist = TermWin.int_bwidth - ev.xbutton.y; 1606 dist = TermWin.int_bwidth - ev.xbutton.y;
1606 } 1607 }
1607 else 1608 else
1630#endif 1631#endif
1631 } 1632 }
1632 } 1633 }
1633 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1634 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1634 { 1635 {
1635 while (XCheckTypedWindowEvent (display->display, scrollBar.win, 1636 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1636 MotionNotify, &ev)) ; 1637 MotionNotify, &ev))
1638 ;
1639
1637 XQueryPointer (display->display, scrollBar.win, 1640 XQueryPointer (disp, scrollBar.win,
1638 &unused_root, &unused_child, 1641 &unused_root, &unused_child,
1639 &unused_root_x, &unused_root_y, 1642 &unused_root_x, &unused_root_y,
1640 & (ev.xbutton.x), & (ev.xbutton.y), 1643 &ev.xbutton.x, &ev.xbutton.y,
1641 &unused_mask); 1644 &unused_mask);
1642 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1645 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1643 scrollbar_size ()); 1646 scrollbar_size ());
1644 scr_refresh (refresh_type); 1647 scr_refresh (refresh_type);
1645 refresh_limit = 0; 1648 refresh_limit = 0;
1661 case PropertyNotify: 1664 case PropertyNotify:
1662 /* 1665 /*
1663 * if user used some Esetroot compatible prog to set the root bg, 1666 * if user used some Esetroot compatible prog to set the root bg,
1664 * use the property to determine the pixmap. We use it later on. 1667 * use the property to determine the pixmap. We use it later on.
1665 */ 1668 */
1666 if (xa[XA_XROOTPMAPID] == 0)
1667 xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False);
1668
1669 if (ev.xproperty.atom != xa[XA_XROOTPMAPID]) 1669 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1670 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1670 return; 1671 return;
1671 1672
1672 /* FALLTHROUGH */ 1673 /* FALLTHROUGH */
1673 case ReparentNotify: 1674 case ReparentNotify:
1674 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1675 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1700 return; 1701 return;
1701 } 1702 }
1702#endif 1703#endif
1703 1704
1704 clickintime = ev.time - MEvent.time < MULTICLICK_TIME; 1705 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1706
1705 if (reportmode) 1707 if (reportmode)
1706 { 1708 {
1707 /* mouse report from vt window */ 1709 /* mouse report from vt window */
1708 /* save the xbutton state (for ButtonRelease) */ 1710 /* save the xbutton state (for ButtonRelease) */
1709 MEvent.state = ev.state; 1711 MEvent.state = ev.state;
1738 } 1740 }
1739 else 1741 else
1740 { 1742 {
1741 if (ev.button != MEvent.button) 1743 if (ev.button != MEvent.button)
1742 MEvent.clicks = 0; 1744 MEvent.clicks = 0;
1745
1743 switch (ev.button) 1746 switch (ev.button)
1744 { 1747 {
1745 case Button1: 1748 case Button1:
1749 /* allow meta + click to select rectangular areas */
1750 /* should be done in screen.C */
1751#if ENABLE_FRILLS
1752 selection.rect = !!(ev.state & ModMetaMask);
1753#else
1754 selection.rect = false;
1755#endif
1756
1746 /* allow shift+left click to extend selection */ 1757 /* allow shift+left click to extend selection */
1747 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1758 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1748 { 1759 {
1749 if (MEvent.button == Button1 && clickintime) 1760 if (MEvent.button == Button1 && clickintime)
1750 selection_rotate (ev.x, ev.y); 1761 selection_rotate (ev.x, ev.y);
2072 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2083 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2073 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2084 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2074 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2085 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2075 int i; 2086 int i;
2076 2087
2077 Visual* visual = display->visual; 2088 Visual *visual = display->visual;
2078 2089
2079 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2090 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2080 2091
2081 /* for convenience */ 2092 /* for convenience */
2082 mask_r = visual->red_mask; 2093 mask_r = visual->red_mask;
2303 Atom atype; 2314 Atom atype;
2304 unsigned char *prop = NULL; 2315 unsigned char *prop = NULL;
2305 Window root, oldp, *list; 2316 Window root, oldp, *list;
2306 Pixmap rootpixmap = None; 2317 Pixmap rootpixmap = None;
2307 XWindowAttributes wattr, wrootattr; 2318 XWindowAttributes wattr, wrootattr;
2319 dDisp;
2308 2320
2309 pchanged = 0; 2321 pchanged = 0;
2310 2322
2311 if (!(options & Opt_transparent)) 2323 if (!(options & Opt_transparent))
2312 return pchanged; /* Don't try any more */ 2324 return pchanged; /* Don't try any more */
2313 2325
2314 XGetWindowAttributes (display->display, display->root, &wrootattr); 2326 XGetWindowAttributes (disp, display->root, &wrootattr);
2315 rootdepth = wrootattr.depth; 2327 rootdepth = wrootattr.depth;
2316 2328
2317 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2329 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2318 2330
2319 if (rootdepth != wattr.depth) 2331 if (rootdepth != wattr.depth)
2320 { 2332 {
2321 if (am_transparent) 2333 if (am_transparent)
2322 { 2334 {
2323 pchanged = 1; 2335 pchanged = 1;
2324 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2336 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2325 am_transparent = am_pixmap_trans = 0; 2337 am_transparent = am_pixmap_trans = 0;
2326 } 2338 }
2327 2339
2328 return pchanged; /* Don't try any more */ 2340 return pchanged; /* Don't try any more */
2329 } 2341 }
2330 2342
2331 /* Get all X ops out of the queue so that our information is up-to-date. */ 2343 /* Get all X ops out of the queue so that our information is up-to-date. */
2332 XSync (display->display, False); 2344 XSync (disp, False);
2333 2345
2334 /* 2346 /*
2335 * Make the frame window set by the window manager have 2347 * Make the frame window set by the window manager have
2336 * the root background. Some window managers put multiple nested frame 2348 * the root background. Some window managers put multiple nested frame
2337 * windows for each client, so we have to take care about that. 2349 * windows for each client, so we have to take care about that.
2338 */ 2350 */
2339 i = (xa[XA_XROOTPMAPID] 2351 i = (xa[XA_XROOTPMAP_ID]
2340 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2352 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2341 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2353 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2342 &nitems, &bytes_after, &prop) == Success); 2354 &nitems, &bytes_after, &prop) == Success);
2343 2355
2344 if (!i || prop == NULL) 2356 if (!i || prop == NULL)
2345 i = (xa[XA_XSETROOTID] 2357 i = (xa[XA_ESETROOT_PMAP_ID]
2346 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2358 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2347 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2359 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2348 &nitems, &bytes_after, &prop) == Success); 2360 &nitems, &bytes_after, &prop) == Success);
2349 2361
2350 if (!i || prop == NULL 2362 if (!i || prop == NULL
2351#if TINTING 2363#if TINTING
2370 Window cr; 2382 Window cr;
2371 XImage *image; 2383 XImage *image;
2372 GC gc; 2384 GC gc;
2373 XGCValues gcvalue; 2385 XGCValues gcvalue;
2374 2386
2375 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2387 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2376 0, 0, &sx, &sy, &cr); 2388 0, 0, &sx, &sy, &cr);
2377 nw = (unsigned int)szHint.width; 2389 nw = (unsigned int)szHint.width;
2378 nh = (unsigned int)szHint.height; 2390 nh = (unsigned int)szHint.height;
2379 nx = ny = 0; 2391 nx = ny = 0;
2380 2392
2392 sy = 0; 2404 sy = 0;
2393 } 2405 }
2394 2406
2395 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2407 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2396 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2408 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2409
2410 XSync (disp, False);
2397 allowedxerror = -1; 2411 allowedxerror = -1;
2398 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2412 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2399 2413
2400 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2414 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2401 /* XXX: may need a delay here? */ 2415 /* XXX: may need a delay here? */
2402 allowedxerror = 0; 2416 allowedxerror = 0;
2403 2417
2406 if (am_transparent && am_pixmap_trans) 2420 if (am_transparent && am_pixmap_trans)
2407 { 2421 {
2408 pchanged = 1; 2422 pchanged = 1;
2409 if (TermWin.pixmap != None) 2423 if (TermWin.pixmap != None)
2410 { 2424 {
2411 XFreePixmap (display->display, TermWin.pixmap); 2425 XFreePixmap (disp, TermWin.pixmap);
2412 TermWin.pixmap = None; 2426 TermWin.pixmap = None;
2413 } 2427 }
2414 } 2428 }
2415 2429
2416 am_pixmap_trans = 0; 2430 am_pixmap_trans = 0;
2417 } 2431 }
2418 else 2432 else
2419 { 2433 {
2420 if (TermWin.pixmap != None) 2434 if (TermWin.pixmap != None)
2421 XFreePixmap (display->display, TermWin.pixmap); 2435 XFreePixmap (disp, TermWin.pixmap);
2422 2436
2423#if TINTING 2437#if TINTING
2424 if (ISSET_PIXCOLOR (Color_tint)) 2438 if (ISSET_PIXCOLOR (Color_tint))
2425 { 2439 {
2426 unsigned short rm, gm, bm; 2440 unsigned short rm, gm, bm;
2430 2444
2431 ShadeXImage (display, image, shade, rm, gm, bm); 2445 ShadeXImage (display, image, shade, rm, gm, bm);
2432 } 2446 }
2433#endif 2447#endif
2434 2448
2435 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2449 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2436 szHint.width, szHint.height, image->depth); 2450 szHint.width, szHint.height, image->depth);
2437 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2451 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2438 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2452 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2439 nx, ny, image->width, image->height); 2453 nx, ny, image->width, image->height);
2440 XFreeGC (display->display, gc); 2454 XFreeGC (disp, gc);
2441 XDestroyImage (image); 2455 XDestroyImage (image);
2442 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); 2456 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2443 XClearWindow (display->display, TermWin.parent[0]); 2457 XClearWindow (disp, TermWin.parent[0]);
2444 2458
2445 if (!am_transparent || !am_pixmap_trans) 2459 if (!am_transparent || !am_pixmap_trans)
2446 pchanged = 1; 2460 pchanged = 1;
2447 2461
2448 am_transparent = am_pixmap_trans = 1; 2462 am_transparent = am_pixmap_trans = 1;
2449 } 2463 }
2450 } 2464 }
2451 2465
2452 if (!am_pixmap_trans) 2466 if (am_pixmap_trans)
2467 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2468 else
2453 { 2469 {
2454 unsigned int n; 2470 unsigned int n;
2455 /* 2471 /*
2456 * InheritPixmap transparency 2472 * InheritPixmap transparency
2457 */ 2473 */
2458 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2474 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2459 { 2475 {
2460 oldp = TermWin.parent[i]; 2476 oldp = TermWin.parent[i];
2461 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2477 XQueryTree (disp, TermWin.parent[i - 1], &root,
2462 &TermWin.parent[i], &list, &n); 2478 &TermWin.parent[i], &list, &n);
2463 XFree (list); 2479 XFree (list);
2464 2480
2465 if (TermWin.parent[i] == display->root) 2481 if (TermWin.parent[i] == display->root)
2466 { 2482 {
2478 2494
2479 if (pchanged) 2495 if (pchanged)
2480 { 2496 {
2481 for (; n < (unsigned int)i; n++) 2497 for (; n < (unsigned int)i; n++)
2482 { 2498 {
2483 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 2499 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2484 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2500 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2485 { 2501 {
2486 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2502 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2487 break; 2503 break;
2488 } 2504 }
2489 } 2505 }
2490 } 2506 }
2491 2507
2492 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) 2508 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2493 { 2509 {
2494 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); 2510 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2495 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2511 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2496 am_transparent = 0; 2512 am_transparent = 0;
2497 /* XXX: also turn off Opt_transparent? */ 2513 /* XXX: also turn off Opt_transparent? */
2498 } 2514 }
2499 else 2515 else
2500 { 2516 {
2503 * needed for fvwm2.2.2 (and before?) */ 2519 * needed for fvwm2.2.2 (and before?) */
2504 sleep (1); 2520 sleep (1);
2505#endif 2521#endif
2506 for (n = 0; n < (unsigned int)i; n++) 2522 for (n = 0; n < (unsigned int)i; n++)
2507 { 2523 {
2508 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); 2524 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2509 XClearWindow (display->display, TermWin.parent[n]); 2525 XClearWindow (disp, TermWin.parent[n]);
2510 } 2526 }
2511 2527
2512 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); 2528 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2513 am_transparent = 1; 2529 am_transparent = 1;
2514 } 2530 }
2515 2531
2516 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2532 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2517 TermWin.parent[i] = None; 2533 TermWin.parent[i] = None;
2518 } 2534 }
2519 2535
2520 // this is experimental
2521 if (scrollBar.win) 2536 if (scrollBar.win)
2522 { 2537 {
2523 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2538 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2524 XClearWindow (display->display, scrollBar.win);
2525 scrollBar.setIdle (); 2539 scrollBar.setIdle ();
2526 scrollbar_show (0); 2540 scrollbar_show (0);
2541 }
2542
2543 if (am_transparent)
2544 {
2545 want_refresh = want_full_refresh = 1;
2546 if (am_pixmap_trans)
2547 flush ();
2527 } 2548 }
2528 2549
2529 return pchanged; 2550 return pchanged;
2530} 2551}
2531#endif 2552#endif
2557 seen_input = 1; 2578 seen_input = 1;
2558 // many badly-written programs (e.g. jed) contain a race condition: 2579 // many badly-written programs (e.g. jed) contain a race condition:
2559 // they first read the screensize and then install a SIGWINCH handler. 2580 // they first read the screensize and then install a SIGWINCH handler.
2560 // some window managers resize the window early, and these programs 2581 // some window managers resize the window early, and these programs
2561 // then sometimes get the size wrong. 2582 // then sometimes get the size wrong.
2583 // unfortunately other programs are even more buggy and dislike
2584 // being sent SIGWINCH, so only do it when we were in fact being
2585 // resized.
2586 if (seen_resize)
2562 kill (-cmd_pid, SIGWINCH); 2587 kill (-cmd_pid, SIGWINCH);
2563 } 2588 }
2564 2589
2565 /* Read a text string from the input buffer */ 2590 /* Read a text string from the input buffer */
2566 unicode_t buf[UBUFSIZ]; 2591 unicode_t buf[UBUFSIZ];
2567 bool refreshnow = false; 2592 bool refreshnow = false;
2679 if (len == (size_t)-1) 2704 if (len == (size_t)-1)
2680 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2705 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2681 2706
2682 // assume wchar == unicode 2707 // assume wchar == unicode
2683 cmdbuf_ptr += len; 2708 cmdbuf_ptr += len;
2684 return wc; 2709 return wc & UNICODE_MASK;
2685 } 2710 }
2686 2711
2687 return NOCHAR; 2712 return NOCHAR;
2688} 2713}
2689 2714
3391rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3416rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3392{ 3417{
3393 int x, y; 3418 int x, y;
3394 XWindowAttributes wattr; 3419 XWindowAttributes wattr;
3395 Window wdummy; 3420 Window wdummy;
3421 dDisp;
3396 3422
3397 if (nargs == 0) 3423 if (nargs == 0)
3398 return; 3424 return;
3399 3425
3400 switch (args[0]) 3426 switch (args[0])
3401 { 3427 {
3402 /* 3428 /*
3403 * commands 3429 * commands
3404 */ 3430 */
3405 case 1: /* deiconify window */ 3431 case 1: /* deiconify window */
3406 XMapWindow (display->display, TermWin.parent[0]); 3432 XMapWindow (disp, TermWin.parent[0]);
3407 break; 3433 break;
3408 case 2: /* iconify window */ 3434 case 2: /* iconify window */
3409 XIconifyWindow (display->display, TermWin.parent[0], 3435 XIconifyWindow (disp, TermWin.parent[0], display->screen);
3410 DefaultScreen (display->display));
3411 break; 3436 break;
3412 case 3: /* set position (pixels) */ 3437 case 3: /* set position (pixels) */
3413 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); 3438 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]);
3414 break; 3439 break;
3415 case 4: /* set size (pixels) */ 3440 case 4: /* set size (pixels) */
3416 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3441 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3417 break; 3442 break;
3418 case 5: /* raise window */ 3443 case 5: /* raise window */
3419 XRaiseWindow (display->display, TermWin.parent[0]); 3444 XRaiseWindow (disp, TermWin.parent[0]);
3420 break; 3445 break;
3421 case 6: /* lower window */ 3446 case 6: /* lower window */
3422 XLowerWindow (display->display, TermWin.parent[0]); 3447 XLowerWindow (disp, TermWin.parent[0]);
3423 break; 3448 break;
3424 case 7: /* refresh window */ 3449 case 7: /* refresh window */
3425 scr_touch (true); 3450 scr_touch (true);
3426 break; 3451 break;
3427 case 8: /* set size (chars) */ 3452 case 8: /* set size (chars) */
3439 3464
3440 /* 3465 /*
3441 * reports - some output format copied from XTerm 3466 * reports - some output format copied from XTerm
3442 */ 3467 */
3443 case 11: /* report window state */ 3468 case 11: /* report window state */
3444 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3469 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3445 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3470 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3446 break; 3471 break;
3447 case 13: /* report window position */ 3472 case 13: /* report window position */
3448 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3473 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3449 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3474 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root,
3450 -wattr.border_width, -wattr.border_width, 3475 -wattr.border_width, -wattr.border_width,
3451 &x, &y, &wdummy); 3476 &x, &y, &wdummy);
3452 tt_printf ("\033[3;%d;%dt", x, y); 3477 tt_printf ("\033[3;%d;%dt", x, y);
3453 break; 3478 break;
3454 case 14: /* report window size (pixels) */ 3479 case 14: /* report window size (pixels) */
3455 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3480 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
3456 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3481 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3457 break; 3482 break;
3458 case 18: /* report text area size (chars) */ 3483 case 18: /* report text area size (chars) */
3459 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3484 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol);
3460 break; 3485 break;
3462 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3487 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol);
3463 break; 3488 break;
3464 case 20: /* report icon label */ 3489 case 20: /* report icon label */
3465 { 3490 {
3466 char *s; 3491 char *s;
3467 XGetIconName (display->display, TermWin.parent[0], &s); 3492 XGetIconName (disp, TermWin.parent[0], &s);
3468 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3493 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3469 XFree (s); 3494 XFree (s);
3470 } 3495 }
3471 break; 3496 break;
3472 case 21: /* report window title */ 3497 case 21: /* report window title */
3473 { 3498 {
3474 char *s; 3499 char *s;
3475 XFetchName (display->display, TermWin.parent[0], &s); 3500 XFetchName (disp, TermWin.parent[0], &s);
3476 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3501 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3477 XFree (s); 3502 XFree (s);
3478 } 3503 }
3479 break; 3504 break;
3480 } 3505 }
3487 * ends_how is terminator used. returned input must be free()'d 3512 * ends_how is terminator used. returned input must be free()'d
3488 */ 3513 */
3489unsigned char * 3514unsigned char *
3490rxvt_term::get_to_st (unicode_t &ends_how) 3515rxvt_term::get_to_st (unicode_t &ends_how)
3491{ 3516{
3492 unicode_t prev = 0, ch; 3517 unicode_t ch;
3518 bool seen_esc = false;
3493 unsigned int n = 0; 3519 unsigned int n = 0;
3494 unsigned char *s;
3495 unsigned char string[STRING_MAX]; 3520 wchar_t string[STRING_MAX];
3496 3521
3497 while ((ch = cmd_getc ()) != NOCHAR) 3522 while ((ch = cmd_getc ()) != NOCHAR)
3498 { 3523 {
3499 if (prev == C0_ESC) 3524 if (seen_esc)
3500 { 3525 {
3501 if (ch == 0x5c) /* 7bit ST */ 3526 if (ch == 0x5c) /* 7bit ST */
3502 break; 3527 break;
3503 else 3528 else
3504 return NULL; 3529 return NULL;
3505 } 3530 }
3531 else if (ch == C0_ESC)
3532 {
3533 seen_esc = true;
3534 continue;
3535 }
3506 else if (ch == C0_BEL || ch == CHAR_ST) 3536 else if (ch == C0_BEL || ch == CHAR_ST)
3507 break; 3537 break;
3508 else if (ch < 0x20) 3538 else if (ch < 0x20)
3509 return NULL; /* other control character - exit */ 3539 return NULL; /* other control character - exit */
3540
3541 seen_esc = false;
3510 3542
3511 if (n >= sizeof (string) - 1) 3543 if (n >= sizeof (string) - 1)
3512 // stop at some sane length 3544 // stop at some sane length
3513 return NULL; 3545 return NULL;
3514 3546
3515 if (ch == C0_SYN) 3547 if (ch == C0_SYN)
3516 {
3517 string[n++] = cmd_get8 (); 3548 string[n++] = cmd_get8 ();
3518 prev = 0;
3519 }
3520 else 3549 else
3521 string[n++] = prev = ch; 3550 string[n++] = ch;
3522 } 3551 }
3523 3552
3524 string[n++] = '\0'; 3553 string[n++] = '\0';
3525 3554
3526 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3527 return NULL;
3528
3529 ends_how = (ch == 0x5c ? C0_ESC : ch); 3555 ends_how = (ch == 0x5c ? C0_ESC : ch);
3530 strncpy (s, string, n); 3556
3531 return s; 3557 return (unsigned char *)rxvt_wcstombs (string);
3532} 3558}
3533 3559
3534/*----------------------------------------------------------------------*/ 3560/*----------------------------------------------------------------------*/
3535/* 3561/*
3536 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3562 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3620{ 3646{
3621 int changed = 0; 3647 int changed = 0;
3622 int color; 3648 int color;
3623 char *buf, *name; 3649 char *buf, *name;
3624 bool query = str[0] == '?' && !str[1]; 3650 bool query = str[0] == '?' && !str[1];
3651 int saveop = op;
3652 dDisp;
3625 3653
3626 assert (str != NULL); 3654 assert (str != NULL);
3627 switch (op) 3655 switch (op)
3628 { 3656 {
3629 case XTerm_name: 3657 case XTerm_name:
3636 set_title (str); 3664 set_title (str);
3637 break; 3665 break;
3638 case XTerm_property: 3666 case XTerm_property:
3639 if (str[0] == '?') 3667 if (str[0] == '?')
3640 { 3668 {
3641 Atom prop = XInternAtom (display->display, str + 1, True); 3669 Atom prop = display->atom (str + 1);
3642 Atom actual_type; 3670 Atom actual_type;
3643 int actual_format; 3671 int actual_format;
3644 unsigned long nitems; 3672 unsigned long nitems;
3645 unsigned long bytes_after; 3673 unsigned long bytes_after;
3646 unsigned char *value = 0; 3674 unsigned char *value = 0;
3647 const char *str = ""; 3675 const char *str = "";
3648 3676
3649 if (prop 3677 if (prop
3650 && XGetWindowProperty (display->display, TermWin.parent[0], 3678 && XGetWindowProperty (disp, TermWin.parent[0],
3651 prop, 0, 1<<16, 0, AnyPropertyType, 3679 prop, 0, 1<<16, 0, AnyPropertyType,
3652 &actual_type, &actual_format, 3680 &actual_type, &actual_format,
3653 &nitems, &bytes_after, &value) == Success 3681 &nitems, &bytes_after, &value) == Success
3654 && actual_type != None 3682 && actual_type != None
3655 && actual_format == 8) 3683 && actual_format == 8)
3664 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3692 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3665 3693
3666 if (eq) 3694 if (eq)
3667 { 3695 {
3668 *eq = 0; 3696 *eq = 0;
3669 XChangeProperty (display->display, TermWin.parent[0], 3697 set_utf8_property (display->atom (str), eq + 1);
3670 display->atom (str), XA_STRING, 8,
3671 PropModeReplace, (unsigned char *)eq + 1,
3672 strlen (eq + 1));
3673 } 3698 }
3674 else 3699 else
3675 XDeleteProperty (display->display, TermWin.parent[0], 3700 XDeleteProperty (disp, TermWin.parent[0],
3676 display->atom (str)); 3701 display->atom (str));
3677 } 3702 }
3678 break; 3703 break;
3679 3704
3680 case XTerm_Color: 3705 case XTerm_Color:
3721 break; 3746 break;
3722#ifndef NO_BOLD_UNDERLINE_REVERSE 3747#ifndef NO_BOLD_UNDERLINE_REVERSE
3723 case XTerm_Color_BD: 3748 case XTerm_Color_BD:
3724 process_color_seq (XTerm_Color_BD, Color_BD, str, resp); 3749 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3725 break; 3750 break;
3751 case XTerm_Color_IT:
3752 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3753 break;
3726 case XTerm_Color_UL: 3754 case XTerm_Color_UL:
3727 process_color_seq (XTerm_Color_UL, Color_UL, str, resp); 3755 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3728 break; 3756 break;
3729 case XTerm_Color_RV: 3757 case XTerm_Color_RV:
3730 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3758 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3759 break;
3760#endif
3761#if TRANSPARENT && TINTING
3762 case XTerm_Color_tint:
3763 process_color_seq (XTerm_Color_tint, Color_tint, str, resp);
3764 check_our_parents ();
3765 if (am_transparent)
3766 want_full_refresh = want_refresh = 1;
3731 break; 3767 break;
3732#endif 3768#endif
3733 3769
3734 case XTerm_Pixmap: 3770 case XTerm_Pixmap:
3735 if (*str != ';') 3771 if (*str != ';')
3744 { 3780 {
3745 str++; 3781 str++;
3746#if XPM_BACKGROUND 3782#if XPM_BACKGROUND
3747 changed += scale_pixmap (str); 3783 changed += scale_pixmap (str);
3748#endif 3784#endif
3749
3750 } 3785 }
3786
3751 if (changed) 3787 if (changed)
3752 { 3788 {
3753#ifdef XPM_BACKGROUND 3789#ifdef XPM_BACKGROUND
3754 resize_pixmap (); 3790 resize_pixmap ();
3755#endif 3791#endif
3767 case XTerm_logfile: 3803 case XTerm_logfile:
3768 // TODO, when secure mode? 3804 // TODO, when secure mode?
3769 break; 3805 break;
3770 3806
3771 case XTerm_font: 3807 case XTerm_font:
3808 op = URxvt_font;
3809 case URxvt_font:
3810#if ENABLE_STYLES
3811 case URxvt_boldFont:
3812 case URxvt_italicFont:
3813 case URxvt_boldItalicFont:
3814#endif
3772 if (query) 3815 if (query)
3773 tt_printf ("\33]%d;%-.250s%c", XTerm_font, 3816 tt_printf ("\33]%d;%-.250s%c", saveop,
3774 (options & Opt_insecure) && TermWin.fontset->fontdesc 3817 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc
3775 ? TermWin.fontset->fontdesc : "", 3818 ? TermWin.fontset[op - URxvt_font]->fontdesc : "",
3776 resp); 3819 resp);
3777 else 3820 else
3821 {
3822 const char *&res = rs[Rs_font + (op - URxvt_font)];
3823
3824 res = strdup (str);
3825 allocated.push_back ((void *)res);
3778 change_font (str); 3826 set_fonts ();
3827 }
3779 break; 3828 break;
3780 3829
3781#if ENABLE_FRILLS 3830#if ENABLE_FRILLS
3782 case XTerm_locale: 3831 case XTerm_locale:
3783 if (query) 3832 if (query)
3784 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3833 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3785 else 3834 else
3786 { 3835 {
3787 set_locale (str); 3836 set_locale (str);
3837 pty.set_utf8_mode (enc_utf8);
3788# ifdef USE_XIM 3838# ifdef USE_XIM
3789 im_cb (); 3839 im_cb ();
3790# endif 3840# endif
3791 } 3841 }
3792 break;
3793
3794 case XTerm_findfont:
3795 {
3796 int fid = TermWin.fontset->find_font (atoi (str));
3797 tt_printf ("\33]%d;%d;%-.250s%c", XTerm_findfont,
3798 fid,
3799 (options & Opt_insecure) ? (*TermWin.fontset)[fid]->name : "",
3800 resp);
3801 }
3802 break; 3842 break;
3803#endif 3843#endif
3804 3844
3805#ifdef MENUBAR 3845#ifdef MENUBAR
3806 case XTerm_Menu: 3846 case XTerm_Menu:
3935 3975
3936 /* extra handling for values with state unkept */ 3976 /* extra handling for values with state unkept */
3937 switch (arg[i]) 3977 switch (arg[i])
3938 { 3978 {
3939 case 1048: /* alternative cursor save */ 3979 case 1048: /* alternative cursor save */
3980 case 1049:
3940 if (options & Opt_secondaryScreen) 3981 if (options & Opt_secondaryScreen)
3941 if (mode == 0) 3982 if (mode == 0)
3942 scr_cursor (RESTORE); 3983 scr_cursor (RESTORE);
3943 else if (mode == 1) 3984 else if (mode == 1)
3944 scr_cursor (SAVE); 3985 scr_cursor (SAVE);
4069 rendset = 0, rendstyle = ~RS_None; 4110 rendset = 0, rendstyle = ~RS_None;
4070 break; 4111 break;
4071 case 1: 4112 case 1:
4072 rendset = 1, rendstyle = RS_Bold; 4113 rendset = 1, rendstyle = RS_Bold;
4073 break; 4114 break;
4074 //case 2: // faint or second colour 4115 //case 2: // low intensity
4075 //case 3: // italic 4116 case 3:
4117 rendset = 1, rendstyle = RS_Italic;
4118 break;
4076 case 4: 4119 case 4:
4077 rendset = 1, rendstyle = RS_Uline; 4120 rendset = 1, rendstyle = RS_Uline;
4078 break; 4121 break;
4079 case 5: // slowly blinking 4122 case 5: // slowly blinking
4080 case 6: // rapidly blinking 4123 case 6: // rapidly blinking
4092 //case 11: // scoansi acs on, first alt font 4135 //case 11: // scoansi acs on, first alt font
4093 //case 12: // scoansi acs on, |0x80, second alt font 4136 //case 12: // scoansi acs on, |0x80, second alt font
4094 //... 4137 //...
4095 //case 19: // ninth alt font 4138 //case 19: // ninth alt font
4096 //case 20: // gothic 4139 //case 20: // gothic
4097 case 21: // disable bold, faint 4140 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4098 rendset = 0, rendstyle = RS_Bold; 4141 rendset = 0, rendstyle = RS_Bold;
4099 break; 4142 break;
4100 case 22: 4143 case 22: // normal intensity
4101 rendset = 0, rendstyle = RS_Bold; 4144 rendset = 0, rendstyle = RS_Bold;
4102 break; 4145 break;
4103 //case 23: disable italic 4146 case 23: // disable italic
4147 rendset = 0, rendstyle = RS_Italic;
4148 break;
4104 case 24: 4149 case 24:
4105 rendset = 0, rendstyle = RS_Uline; 4150 rendset = 0, rendstyle = RS_Uline;
4106 break; 4151 break;
4107 case 25: 4152 case 25:
4108 rendset = 0, rendstyle = RS_Blink; 4153 rendset = 0, rendstyle = RS_Blink;
4109 break; 4154 break;
4110 case 26: 4155 case 26: // variable spacing (iso 8613)
4111 rendset = 0, rendstyle = RS_Blink; 4156 rendset = 0, rendstyle = RS_Blink;
4112 break; 4157 break;
4113 case 27: 4158 case 27:
4114 rendset = 0, rendstyle = RS_RVid; 4159 rendset = 0, rendstyle = RS_RVid;
4115 break; 4160 break;
4133 case 35: 4178 case 35:
4134 case 36: 4179 case 36:
4135 case 37: 4180 case 37:
4136 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); 4181 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4137 break; 4182 break;
4138#ifdef TTY_256COLOR 4183 case 38: // set fg color, ISO 8613-6
4139 case 38:
4140 if (nargs > i + 2 && arg[i + 1] == 5) 4184 if (nargs > i + 2 && arg[i + 1] == 5)
4141 { 4185 {
4142 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); 4186 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4143 i += 2; 4187 i += 2;
4144 } 4188 }
4145 break; 4189 break;
4146#endif
4147 case 39: /* default fg */ 4190 case 39: /* default fg */
4148 scr_color (Color_fg, Color_fg); 4191 scr_color (Color_fg, Color_fg);
4149 break; 4192 break;
4150 4193
4151 case 40: 4194 case 40:
4156 case 45: 4199 case 45:
4157 case 46: 4200 case 46:
4158 case 47: 4201 case 47:
4159 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); 4202 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4160 break; 4203 break;
4161#ifdef TTY_256COLOR 4204 case 48: // set bg color, ISO 8613-6
4162 case 48:
4163 if (nargs > i + 2 && arg[i + 1] == 5) 4205 if (nargs > i + 2 && arg[i + 1] == 5)
4164 { 4206 {
4165 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); 4207 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4166 i += 2; 4208 i += 2;
4167 } 4209 }
4168 break; 4210 break;
4169#endif
4170 case 49: /* default bg */ 4211 case 49: /* default bg */
4171 scr_color (Color_bg, Color_bg); 4212 scr_color (Color_bg, Color_bg);
4172 break; 4213 break;
4214
4215 //case 50: // not variable spacing
4173 4216
4174#ifndef NO_BRIGHTCOLOR 4217#ifndef NO_BRIGHTCOLOR
4175 case 90: 4218 case 90:
4176 case 91: /* set bright fg color */ 4219 case 91: /* set bright fg color */
4177 case 92: 4220 case 92:
4178 case 93: 4221 case 93:
4179 case 94: 4222 case 94:
4180 case 95: 4223 case 95:
4181 case 96: 4224 case 96:
4182 case 97: 4225 case 97:
4183 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), 4226 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4184 Color_fg);
4185 break; 4227 break;
4186 case 100: 4228 case 100:
4187 case 101: /* set bright bg color */ 4229 case 101: /* set bright bg color */
4188 case 102: 4230 case 102:
4189 case 103: 4231 case 103:
4190 case 104: 4232 case 104:
4191 case 105: 4233 case 105:
4192 case 106: 4234 case 106:
4193 case 107: 4235 case 107:
4194 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), 4236 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4195 Color_bg);
4196 break; 4237 break;
4197#endif 4238#endif
4198 4239
4199 } 4240 }
4200 } 4241 }
4239 4280
4240/* ---------------------------------------------------------------------- */ 4281/* ---------------------------------------------------------------------- */
4241/* Write data to the pty as typed by the user, pasted with the mouse, 4282/* Write data to the pty as typed by the user, pasted with the mouse,
4242 * or generated by us in response to a query ESC sequence. 4283 * or generated by us in response to a query ESC sequence.
4243 */ 4284 */
4285const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4286
4244void 4287void
4245rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4288rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4246{ 4289{
4247 enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT 4290 if (v_buflen == 0)
4291 {
4292 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4248 4293
4249 if (len) 4294 if ((unsigned int)written == len)
4295 return;
4296
4297 data += written;
4298 len -= written;
4250 { 4299 }
4300
4301 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4302
4303 memcpy (v_buffer + v_buflen, data, len);
4304 v_buflen += len;
4305
4306 pty_ev.set (EVENT_READ | EVENT_WRITE);
4307}
4308
4309void rxvt_term::pty_write ()
4310{
4311 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4312
4313 if (written > 0)
4314 {
4315 v_buflen -= written;
4316
4251 if (v_buflen == 0) 4317 if (v_buflen == 0)
4252 { 4318 {
4253 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4254
4255 if ((unsigned int)written == len)
4256 return;
4257
4258 data += written;
4259 len -= written;
4260 }
4261
4262
4263 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4264
4265 memcpy (v_buffer + v_buflen, data, len);
4266 v_buflen += len;
4267 }
4268
4269 for (;;)
4270 {
4271 int written = write (pty.pty, v_buffer, min (MAX_PTY_WRITE, v_buflen));
4272
4273 if (written > 0)
4274 {
4275 v_buflen -= written;
4276
4277 if (v_buflen == 0)
4278 {
4279 free (v_buffer); 4319 free (v_buffer);
4280 v_buffer = 0; 4320 v_buffer = 0;
4281 v_buflen = 0; 4321 v_buflen = 0;
4282 4322
4283 pty_ev.set (EVENT_READ); 4323 pty_ev.set (EVENT_READ);
4284 return;
4285 }
4286
4287 memmove (v_buffer, v_buffer + written, v_buflen);
4288 }
4289 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4290 // original code just ignores this...
4291 destroy ();
4292 else
4293 {
4294 pty_ev.set (EVENT_READ | EVENT_WRITE);
4295 return; 4324 return;
4296 } 4325 }
4326
4327 memmove (v_buffer, v_buffer + written, v_buflen);
4297 } 4328 }
4329 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4330 // original code just ignores this...
4331 destroy ();
4298} 4332}
4299 4333
4300/*----------------------- end-of-file (C source) -----------------------*/ 4334/*----------------------- end-of-file (C source) -----------------------*/
4301 4335

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines