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.216 by root, Tue Dec 27 01:25:42 2005 UTC

25 * - extensive modifications 25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> 26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas 27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options) 28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org> 29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-2004 Marc Lehmann <pcg@goof.com> 30 * Copyright (c) 2003-2005 Marc Lehmann <pcg@goof.com>
31 * 31 *
32 * This program is free software; you can redistribute it and/or modify 32 * This program is free software; you can redistribute it and/or modify
33 * it under the terms of the GNU General Public License as published by 33 * it under the terms of the GNU General Public License as published by
34 * the Free Software Foundation; either version 2 of the License, or 34 * the Free Software Foundation; either version 2 of the License, or
35 * (at your option) any later version. 35 * (at your option) any later version.
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
57#include <csignal>
54 58
55/*----------------------------------------------------------------------*/ 59/*----------------------------------------------------------------------*/
56 60
57#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
58 62
113 XK_Escape, 0x238b, 117 XK_Escape, 0x238b,
114 XK_Undo, 0x238c, 118 XK_Undo, 0x238c,
115 XK_Print, 0x2399, 119 XK_Print, 0x2399,
116 120
117 XK_space, 0x2423, 121 XK_space, 0x2423,
122
123#ifdef XK_KP_Begin
124 XK_KP_Prior, 0x21de,
125 XK_KP_Next, 0x21df,
126 XK_KP_Begin, 0x2320,
127 XK_KP_Insert, 0x2380,
128 XK_KP_Delete, 0x2326,
118 XK_KP_Space, 0x2422, 129 XK_KP_Space, 0x2422,
130#endif
119 0, 131 0,
120}; 132};
121 133
122void 134void
123rxvt_term::iso14755_54 (int x, int y) 135rxvt_term::iso14755_54 (int x, int y)
124{ 136{
125 x = Pixel2Col (x); 137 x = Pixel2Col (x);
126 y = Pixel2Row (y); 138 y = Pixel2Row (y);
127 139
128 if (x < 0 || x >= TermWin.ncol 140 if (!IN_RANGE_EXC (x, 0, ncol)
129 || y < 0 || y >= TermWin.nrow) 141 || !IN_RANGE_EXC (y, 0, nrow))
130 return; 142 return;
131 143
132 for (;;) 144 for (;;)
133 { 145 {
134 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x]; 146 const line_t &l = ROW(y - view_start);
147
148 text_t t = l.t[x];
135 149
136 if (t != NOCHAR || !x) 150 if (t != NOCHAR || !x)
137 { 151 {
138 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x]); 152 iso14755_51 (l.t[x], l.r[x]);
139 iso14755buf = ISO_14755_54; 153 iso14755buf = ISO_14755_54;
140 break; 154 break;
141 } 155 }
142 156
143 x--; 157 x--;
144 } 158 }
145
146} 159}
147#endif 160#endif
148 161
149#if ENABLE_OVERLAY 162#if ENABLE_OVERLAY
150void 163void
151rxvt_term::iso14755_51 (wchar_t ch) 164rxvt_term::iso14755_51 (unicode_t ch, rend_t r)
152{ 165{
166 rxvt_fontset *fs = FONTSET (r);
167 rxvt_font *f = (*fs)[fs->find_font (ch)];
153 wchar_t *chr, *alloc; 168 wchar_t *chr, *alloc, ch2, *fname;
154 int len; 169 int len;
170
171 fname = rxvt_utf8towcs (f->name);
155 172
156#if ENABLE_COMBINING 173#if ENABLE_COMBINING
157 if (IS_COMPOSE (ch)) 174 if (IS_COMPOSE (ch))
158 { 175 {
159 len = rxvt_composite.expand (ch, 0); 176 len = rxvt_composite.expand (ch, 0);
161 rxvt_composite.expand (ch, chr); 178 rxvt_composite.expand (ch, chr);
162 } 179 }
163 else 180 else
164#endif 181#endif
165 { 182 {
183 ch2 = ch;
184
166 alloc = 0; 185 alloc = 0;
167 chr = &ch; 186 chr = &ch2;
168 len = 1; 187 len = 1;
169 } 188 }
170 189
190 char attr[80]; // plenty
191
192 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
193 (int)r,
194 GET_FGCOLOR (r), GET_BGCOLOR (r),
195 r & RS_Bold ? " bold" : "",
196 r & RS_Italic ? " italic" : "",
197 r & RS_Blink ? " blink" : "",
198 r & RS_RVid ? " rvid" : "",
199 r & RS_Uline ? " uline" : "",
200 r & RS_Careful ? " careful" : "");
201
202 int width = wcswidth (fname, wcslen (fname));
203
204 max_it (width, 8+5); // for char + hey
205 max_it (width, strlen (attr));
206
171 scr_overlay_new (0, -1, 8 + 5, len); 207 scr_overlay_new (0, -1, width, len + 2);
208
209 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
172 210
173 for (int y = 0; y < len; y++) 211 for (int y = 0; y < len; y++)
174 { 212 {
175 char buf[9]; 213 char buf[9];
176 214
181 scr_overlay_set (9, y, '='); 219 scr_overlay_set (9, y, '=');
182#if !UNICODE3 220#if !UNICODE3
183 if (ch >= 0x10000) 221 if (ch >= 0x10000)
184 ch = 0xfffd; 222 ch = 0xfffd;
185#endif 223#endif
186 scr_overlay_set (11, y, ch); 224 scr_overlay_set (11, y, ch, r);
187 scr_overlay_set (12, y, NOCHAR); 225 scr_overlay_set (12, y, NOCHAR, r);
188 } 226 }
227
228 scr_overlay_set (0, len , attr);
229 scr_overlay_set (0, len + 1, fname);
230
231 free (fname);
189 232
190#if ENABLE_COMBINING 233#if ENABLE_COMBINING
191 if (alloc) 234 if (alloc)
192 delete [] alloc; 235 delete [] alloc;
193#endif 236#endif
261 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 304 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
262 * escape sequence to toggle the Keypad. 305 * escape sequence to toggle the Keypad.
263 * 306 *
264 * Always permit `shift' to override the current setting 307 * Always permit `shift' to override the current setting
265 */ 308 */
266 shft = (ev.state & ShiftMask); 309 shft = ev.state & ShiftMask;
267 ctrl = (ev.state & ControlMask); 310 ctrl = ev.state & ControlMask;
268 meta = (ev.state & ModMetaMask); 311 meta = ev.state & ModMetaMask;
269 312
270 if (numlock_state || (ev.state & ModNumLockMask)) 313 if (numlock_state || (ev.state & ModNumLockMask))
271 { 314 {
272 numlock_state = (ev.state & ModNumLockMask); 315 numlock_state = (ev.state & ModNumLockMask);
273 PrivMode ((!numlock_state), PrivMode_aplKP); 316 PrivMode ((!numlock_state), PrivMode_aplKP);
293 336
294 // the XOpenIM manpage lies about hardcoding the locale 337 // the XOpenIM manpage lies about hardcoding the locale
295 // at the point of XOpenIM, so temporarily switch locales 338 // at the point of XOpenIM, so temporarily switch locales
296 if (rs[Rs_imLocale]) 339 if (rs[Rs_imLocale])
297 SET_LOCALE (rs[Rs_imLocale]); 340 SET_LOCALE (rs[Rs_imLocale]);
341
298 // assume wchar_t == unicode or better 342 // assume wchar_t == unicode or better
299 len = XwcLookupString (Input_Context, &ev, wkbuf, 343 len = XwcLookupString (Input_Context, &ev, wkbuf,
300 KBUFSZ, &keysym, &status_return); 344 KBUFSZ, &keysym, &status_return);
345
301 if (rs[Rs_imLocale]) 346 if (rs[Rs_imLocale])
302 SET_LOCALE (locale); 347 SET_LOCALE (locale);
303 348
304 if (status_return == XLookupChars 349 if (status_return == XLookupChars
305 || status_return == XLookupBoth) 350 || status_return == XLookupBoth)
332 valid_keysym = keysym != NoSymbol; 377 valid_keysym = keysym != NoSymbol;
333 } 378 }
334 379
335 if (valid_keysym) 380 if (valid_keysym)
336 { 381 {
382#ifdef KEYSYM_RESOURCE
383 if (keyboard->dispatch (this, keysym, ev.state))
384 return;
385#endif
386
337 if (TermWin.saveLines) 387 if (saveLines)
338 { 388 {
339#ifdef UNSHIFTED_SCROLLKEYS 389#ifdef UNSHIFTED_SCROLLKEYS
340 if (!ctrl && !meta) 390 if (!ctrl && !meta)
341#else 391#else
342 if (IS_SCROLL_MOD) 392 if (IS_SCROLL_MOD)
343#endif 393#endif
344 { 394 {
345 int lnsppg; 395 int lnsppg;
346 396
347#ifdef PAGING_CONTEXT_LINES 397#ifdef PAGING_CONTEXT_LINES
348 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; 398 lnsppg = nrow - PAGING_CONTEXT_LINES;
349#else 399#else
350 lnsppg = TermWin.nrow * 4 / 5; 400 lnsppg = nrow * 4 / 5;
351#endif 401#endif
352 if (keysym == XK_Prior) 402 if (keysym == XK_Prior)
353 { 403 {
354 scr_page (UP, lnsppg); 404 scr_page (UP, lnsppg);
355 return; 405 return;
406 { 456 {
407 /* normal XTerm key bindings */ 457 /* normal XTerm key bindings */
408 case XK_Insert: /* Shift+Insert = paste mouse selection */ 458 case XK_Insert: /* Shift+Insert = paste mouse selection */
409 selection_request (ev.time, 0, 0); 459 selection_request (ev.time, 0, 0);
410 return; 460 return;
411#if TODO // TODO 461#if TODO
412 /* rxvt extras */ 462 /* rxvt extras */
413 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 463 case XK_KP_Add: /* Shift+KP_Add = bigger font */
414 change_font (FONT_UP); 464 change_font (FONT_UP);
415 return; 465 return;
416 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 466 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
475 } 525 }
476#endif 526#endif
477 527
478 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 528 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
479 { 529 {
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 { 530 {
506 newlen = 1; 531 newlen = 1;
507 switch (keysym) 532 switch (keysym)
508 { 533 {
509#ifndef NO_BACKSPACE_KEY 534#ifndef NO_BACKSPACE_KEY
517 else 542 else
518 strcpy (kbuf, key_backspace); 543 strcpy (kbuf, key_backspace);
519 break; 544 break;
520#endif 545#endif
521#ifndef NO_DELETE_KEY 546#ifndef NO_DELETE_KEY
547# ifdef XK_KP_Prior
548 case XK_KP_Delete:
549 /* allow shift to override */
550 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
551 {
552 strcpy (kbuf, "\033On");
553 break;
554 }
555 /* FALLTHROUGH */
556# endif
522 case XK_Delete: 557 case XK_Delete:
523 strcpy (kbuf, key_delete); 558 strcpy (kbuf, key_delete);
524 break; 559 break;
525#endif 560#endif
526 case XK_Tab: 561 case XK_Tab:
629#ifdef XK_KP_Begin 664#ifdef XK_KP_Begin
630 case XK_KP_Begin: 665 case XK_KP_Begin:
631 strcpy (kbuf, "\033Ou"); 666 strcpy (kbuf, "\033Ou");
632 break; 667 break;
633 668
634 case XK_KP_Insert:
635 strcpy (kbuf, "\033Op");
636 break;
637
638 case XK_KP_Delete:
639 strcpy (kbuf, "\033On");
640 break;
641#endif 669#endif
642 case XK_KP_F1: /* "\033OP" */ 670 case XK_KP_F1: /* "\033OP" */
643 case XK_KP_F2: /* "\033OQ" */ 671 case XK_KP_F2: /* "\033OQ" */
644 case XK_KP_F3: /* "\033OR" */ 672 case XK_KP_F3: /* "\033OR" */
645 case XK_KP_F4: /* "\033OS" */ 673 case XK_KP_F4: /* "\033OS" */
677 break; 705 break;
678 706
679 case XK_Find: 707 case XK_Find:
680 strcpy (kbuf, "\033[1~"); 708 strcpy (kbuf, "\033[1~");
681 break; 709 break;
710
711#ifdef XK_KP_End
712 case XK_KP_Insert:
713 /* allow shift to override */
714 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
715 {
716 strcpy (kbuf, "\033Op");
717 break;
718 }
719 /* FALLTHROUGH */
720#endif
682 case XK_Insert: 721 case XK_Insert:
683 strcpy (kbuf, "\033[2~"); 722 strcpy (kbuf, "\033[2~");
684 break; 723 break;
685#ifdef DXK_Remove /* support for DEC remove like key */ 724#ifdef DXK_Remove /* support for DEC remove like key */
686 case DXK_Remove: 725 case DXK_Remove:
776#undef FKEY 815#undef FKEY
777 default: 816 default:
778 newlen = 0; 817 newlen = 0;
779 break; 818 break;
780 } 819 }
820
781 if (newlen) 821 if (newlen)
782 len = strlen (kbuf); 822 len = strlen (kbuf);
783 } 823 }
784 824
785 /* 825 /*
794 else if (ctrl && keysym == XK_minus) 834 else if (ctrl && keysym == XK_minus)
795 { 835 {
796 len = 1; 836 len = 1;
797 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 837 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
798 } 838 }
839 else if (keysym == XK_ISO_Left_Tab)
840 {
841 strcpy (kbuf, "\033[Z");
842 len = 3;
843 }
799 else 844 else
800 { 845 {
801#ifdef META8_OPTION 846#ifdef META8_OPTION
802 /* set 8-bit on */ 847 /* set 8-bit on */
803 if (meta && (meta_char == 0x80)) 848 if (meta && (meta_char == 0x80))
816 861
817 if (len <= 0) 862 if (len <= 0)
818 return; /* not mapped */ 863 return; /* not mapped */
819 864
820 if (options & Opt_scrollTtyKeypress) 865 if (options & Opt_scrollTtyKeypress)
821 if (TermWin.view_start) 866 if (view_start)
822 { 867 {
823 TermWin.view_start = 0; 868 view_start = 0;
824 want_refresh = 1; 869 want_refresh = 1;
825 } 870 }
826 871
827 /* 872 /*
828 * these modifications only affect the static keybuffer 873 * these modifications only affect the static keybuffer
861#endif /* DEBUG_CMD */ 906#endif /* DEBUG_CMD */
862 tt_write (kbuf, (unsigned int)len); 907 tt_write (kbuf, (unsigned int)len);
863} 908}
864/*}}} */ 909/*}}} */
865 910
866#if (MENUBAR_MAX) 911#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
867/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 912/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
868/* attempt to `write' count to the input buffer */ 913/* attempt to `write' count to the input buffer */
869unsigned int 914unsigned int
870rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 915rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
871{ 916{
894 939
895 cmd_parse (); 940 cmd_parse ();
896 941
897 return 0; 942 return 0;
898} 943}
899#endif /* MENUBAR_MAX */ 944#endif
900 945
901void 946void
902rxvt_term::flush () 947rxvt_term::flush ()
903{ 948{
949 flush_ev.stop ();
950
904#ifdef TRANSPARENT 951#ifdef TRANSPARENT
905 if (want_full_refresh) 952 if (want_full_refresh)
906 { 953 {
907 want_full_refresh = 0; 954 want_full_refresh = 0;
908 scr_clear (); 955 scr_clear ();
918 IMSendSpot (); 965 IMSendSpot ();
919#endif 966#endif
920 } 967 }
921 968
922 display->flush (); 969 display->flush ();
923
924 flush_ev.stop ();
925} 970}
926 971
927void 972void
928rxvt_term::check_cb (check_watcher &w) 973rxvt_term::check_cb (check_watcher &w)
929{ 974{
1005{ 1050{
1006 if (mouse_slip_wheel_speed == 0 1051 if (mouse_slip_wheel_speed == 0
1007 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1052 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1008 : scr_page (UP, mouse_slip_wheel_speed)) 1053 : scr_page (UP, mouse_slip_wheel_speed))
1009 { 1054 {
1055 if (view_start == nsaved ||
1056 view_start == 0)
1057 mouse_slip_wheel_speed = 0;
1058
1010 refresh_type |= SMOOTH_REFRESH; 1059 refresh_type |= SMOOTH_REFRESH;
1011 want_refresh = 1; 1060 want_refresh = 1;
1012 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1061 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1013 } 1062 }
1014} 1063}
1034 if (n > 0) 1083 if (n > 0)
1035 { 1084 {
1036 cmdbuf_endp += n; 1085 cmdbuf_endp += n;
1037 return true; 1086 return true;
1038 } 1087 }
1039 else if (n < 0 && errno != EAGAIN) 1088 else if ((n < 0 && errno != EAGAIN && errno != EINTR) || n == 0)
1089 {
1090 pty_ev.stop ();
1091
1092 if (!(options & Opt_hold))
1040 destroy (); 1093 destroy ();
1094 }
1041 1095
1042 return false; 1096 return false;
1043} 1097}
1044 1098
1045void 1099void
1046rxvt_term::pty_cb (io_watcher &w, short revents) 1100rxvt_term::pty_cb (io_watcher &w, short revents)
1047{ 1101{
1048 SET_R (this); 1102 SET_R (this);
1049 SET_LOCALE (locale); 1103 SET_LOCALE (locale);
1050 1104
1051 if (revents & EVENT_WRITE)
1052 tt_write (0, 0);
1053 else if (revents & EVENT_READ) 1105 if (revents & EVENT_READ)
1054 // loop, but don't allow a single term to monopolize us 1106 // loop, but don't allow a single term to monopolize us
1055 while (pty_fill ()) 1107 while (pty_fill ())
1056 if (cmd_parse ()) 1108 if (cmd_parse ())
1057 break; 1109 break;
1110
1111 if (revents & EVENT_WRITE)
1112 pty_write ();
1058} 1113}
1059 1114
1060void 1115void
1061rxvt_term::pointer_unblank () 1116rxvt_term::pointer_unblank ()
1062{ 1117{
1063 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1118 XDefineCursor (display->display, vt, TermWin_cursor);
1064 recolour_cursor (); 1119 recolour_cursor ();
1065 1120
1066#ifdef POINTER_BLANK 1121#ifdef POINTER_BLANK
1067 hidden_pointer = 0; 1122 hidden_pointer = 0;
1068 1123
1076rxvt_term::pointer_blank () 1131rxvt_term::pointer_blank ()
1077{ 1132{
1078 if (! (options & Opt_pointerBlank)) 1133 if (! (options & Opt_pointerBlank))
1079 return; 1134 return;
1080 1135
1081 XDefineCursor (display->display, TermWin.vt, blank_cursor); 1136 XDefineCursor (display->display, vt, display->blank_cursor);
1082 XFlush (display->display); 1137 XFlush (display->display);
1083 1138
1084 hidden_pointer = 1; 1139 hidden_pointer = 1;
1085} 1140}
1086 1141
1137 + ((MEvent.state & ModMetaMask) ? 8 : 0) 1192 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1138 + ((MEvent.state & ControlMask) ? 16 : 0); 1193 + ((MEvent.state & ControlMask) ? 16 : 0);
1139#ifdef MOUSE_REPORT_DOUBLECLICK 1194#ifdef MOUSE_REPORT_DOUBLECLICK
1140 key_state += ((MEvent.clicks > 1) ? 32 : 0); 1195 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1141#endif 1196#endif
1142
1143 } 1197 }
1144 1198
1145#ifdef DEBUG_MOUSEREPORT 1199#if DEBUG_MOUSEREPORT
1146 fprintf (stderr, "Mouse ["); 1200 fprintf (stderr, "Mouse [");
1147 if (key_state & 16) 1201 if (key_state & 16)
1148 fputc ('C', stderr); 1202 fputc ('C', stderr);
1149 if (key_state & 4) 1203 if (key_state & 4)
1150 fputc ('S', stderr); 1204 fputc ('S', stderr);
1154 fputc ('2', stderr); 1208 fputc ('2', stderr);
1155 fprintf (stderr, "]: <%d>, %d/%d\n", 1209 fprintf (stderr, "]: <%d>, %d/%d\n",
1156 button_number, 1210 button_number,
1157 x + 1, 1211 x + 1,
1158 y + 1); 1212 y + 1);
1159#else 1213#endif
1214
1160 tt_printf ("\033[M%c%c%c", 1215 tt_printf ("\033[M%c%c%c",
1161 (32 + button_number + key_state), 1216 (32 + button_number + key_state),
1162 (32 + x + 1), 1217 (32 + x + 1),
1163 (32 + y + 1)); 1218 (32 + y + 1));
1164#endif
1165} 1219}
1166 1220
1167#ifdef USING_W11LIB 1221#ifdef USING_W11LIB
1168void 1222void
1169rxvt_W11_process_x_event (XEvent *ev) 1223rxvt_W11_process_x_event (XEvent *ev)
1176 1230
1177/*{{{ process an X event */ 1231/*{{{ process an X event */
1178void 1232void
1179rxvt_term::x_cb (XEvent &ev) 1233rxvt_term::x_cb (XEvent &ev)
1180{ 1234{
1235 dDisp;
1236
1181 SET_R (this); 1237 SET_R (this);
1182 SET_LOCALE (locale); 1238 SET_LOCALE (locale);
1183 1239
1184#if defined(CURSOR_BLINK) 1240#if defined(CURSOR_BLINK)
1185 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1241 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1206 if (ev.type == KeyPress && hidden_pointer == 0) 1262 if (ev.type == KeyPress && hidden_pointer == 0)
1207 pointer_blank (); 1263 pointer_blank ();
1208 } 1264 }
1209#endif 1265#endif
1210 1266
1211#ifdef USE_XIM
1212 if (XFilterEvent (&ev, None))
1213 return;
1214#endif
1215
1216 Window unused_root, unused_child; 1267 Window unused_root, unused_child;
1217 int unused_root_x, unused_root_y; 1268 int unused_root_x, unused_root_y;
1218 unsigned int unused_mask; 1269 unsigned int unused_mask;
1219 1270
1220 switch (ev.type) 1271 switch (ev.type)
1221 { 1272 {
1222 case KeyPress: 1273 case KeyPress:
1223#if ISO_14755 1274#if ISO_14755
1227 1278
1228 break; 1279 break;
1229 1280
1230 case KeyRelease: 1281 case KeyRelease:
1231 { 1282 {
1232#if (defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)) || defined (ENABLE_FRILLS) 1283#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1233 KeySym ks; 1284 KeySym ks;
1234 1285
1235 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ 1286 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1236#endif 1287#endif
1237 1288
1306 button_release (ev.xbutton); 1357 button_release (ev.xbutton);
1307 break; 1358 break;
1308 1359
1309 case ClientMessage: 1360 case ClientMessage:
1310 if (ev.xclient.format == 32 1361 if (ev.xclient.format == 32
1362 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1363 {
1311 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) 1364 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1312 destroy (); 1365 destroy ();
1366#if ENABLE_EWMH
1367 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1368 XSendEvent (disp, ev.xclient.window = display->root,
1369 False, SubstructureRedirectMask | SubstructureNotifyMask,
1370 &ev);
1371#endif
1372 }
1373#if ENABLE_XEMBED
1374 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1375 {
1376 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1377 focus_in ();
1378 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1379 focus_out ();
1380 }
1381#endif
1313#ifdef OFFIX_DND 1382#ifdef OFFIX_DND
1314 /* OffiX Dnd (drag 'n' drop) protocol */ 1383 /* OffiX Dnd (drag 'n' drop) protocol */
1315 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] 1384 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1316 && (ev.xclient.data.l[0] == DndFile 1385 && (ev.xclient.data.l[0] == DndFile
1317 || ev.xclient.data.l[0] == DndDir 1386 || ev.xclient.data.l[0] == DndDir
1318 || ev.xclient.data.l[0] == DndLink)) 1387 || ev.xclient.data.l[0] == DndLink))
1319 { 1388 {
1320 /* Get Dnd data */ 1389 /* Get Dnd data */
1321 Atom ActualType; 1390 Atom ActualType;
1322 int ActualFormat; 1391 int ActualFormat;
1323 unsigned char *data; 1392 unsigned char *data;
1324 unsigned long Size, RemainingBytes; 1393 unsigned long Size, RemainingBytes;
1325 1394
1326 XGetWindowProperty (display->display, display->root, 1395 XGetWindowProperty (disp, display->root,
1327 xa[XA_DNDSELECTION], 1396 xa[XA_DNDSELECTION],
1328 0L, 1000000L, 1397 0L, 1000000L,
1329 False, AnyPropertyType, 1398 False, AnyPropertyType,
1330 &ActualType, &ActualFormat, 1399 &ActualType, &ActualFormat,
1331 &Size, &RemainingBytes, 1400 &Size, &RemainingBytes,
1332 &data); 1401 &data);
1333 XChangeProperty (display->display, display->root, 1402 set_string_property (XA_CUT_BUFFER0, data);
1334 XA_CUT_BUFFER0, XA_STRING,
1335 8, PropModeReplace,
1336 data, strlen (data));
1337 XFree (data); 1403 XFree (data);
1338 selection_paste (display->root, XA_CUT_BUFFER0, True); 1404 selection_paste (display->root, XA_CUT_BUFFER0, true);
1339 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1405 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1340 } 1406 }
1341#endif /* OFFIX_DND */ 1407#endif /* OFFIX_DND */
1342 break; 1408 break;
1343 1409
1344 case MappingNotify: 1410 case MappingNotify:
1369 break; 1435 break;
1370 } 1436 }
1371 break; 1437 break;
1372 1438
1373 case FocusIn: 1439 case FocusIn:
1374 if (!TermWin.focus) 1440 focus_in ();
1441 break;
1442
1443 case FocusOut:
1444 focus_out ();
1445 break;
1446
1447 case ConfigureNotify:
1448 if (ev.xconfigure.window == parent[0])
1375 { 1449 {
1376 TermWin.focus = 1; 1450 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev))
1377 want_refresh = 1; 1451 ;
1378#ifdef USE_XIM 1452
1379 if (Input_Context != NULL) 1453 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1380 { 1454 {
1381 IMSetStatusPosition (); 1455 seen_resize = 1;
1382 XSetICFocus (Input_Context); 1456 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1383 } 1457 }
1384#endif
1385#ifdef CURSOR_BLINK
1386 if (options & Opt_cursorBlink)
1387 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1388#endif
1389#ifdef OFF_FOCUS_FADING
1390 if (rs[Rs_fade])
1391 {
1392 pix_colors = pix_colors_focused;
1393 set_colorfgbg ();
1394 scr_clear ();
1395 scr_touch (true);
1396 }
1397#endif
1398
1399 }
1400 break;
1401
1402 case FocusOut:
1403 if (TermWin.focus)
1404 {
1405 TermWin.focus = 0;
1406 want_refresh = 1;
1407#ifdef USE_XIM
1408 if (Input_Context != NULL)
1409 XUnsetICFocus (Input_Context);
1410#endif
1411#ifdef CURSOR_BLINK
1412 if (options & Opt_cursorBlink)
1413 cursor_blink_ev.stop ();
1414 hidden_cursor = 0;
1415#endif
1416#ifdef OFF_FOCUS_FADING
1417 if (rs[Rs_fade])
1418 {
1419 pix_colors = pix_colors_unfocused;
1420 set_colorfgbg ();
1421 scr_clear ();
1422 scr_touch (true);
1423 }
1424#endif
1425
1426 }
1427 break;
1428
1429 case ConfigureNotify:
1430 if (ev.xconfigure.window == TermWin.parent[0])
1431 {
1432 int height, width;
1433
1434 do
1435 { /* Wrap lots of configures into one */
1436 width = ev.xconfigure.width;
1437 height = ev.xconfigure.height;
1438 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1439 }
1440 while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev));
1441
1442 if (szHint.width != width || szHint.height != height)
1443 resize_all_windows (width, height, 1);
1444 1458
1445#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1459#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1446 if (options & Opt_transparent) 1460 if (options & Opt_transparent)
1447 {
1448 check_our_parents (); 1461 check_our_parents ();
1449 if (am_transparent)
1450 want_refresh = want_full_refresh = 1;
1451 }
1452#endif 1462#endif
1453 } 1463 }
1454 break; 1464 break;
1455 1465
1456 case PropertyNotify: 1466 case PropertyNotify:
1464 selection_clear (); 1474 selection_clear ();
1465 break; 1475 break;
1466 1476
1467 case SelectionNotify: 1477 case SelectionNotify:
1468 if (selection_wait == Sel_normal) 1478 if (selection_wait == Sel_normal)
1469 selection_paste (ev.xselection.requestor, 1479 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1470 ev.xselection.property, True);
1471 break; 1480 break;
1472 1481
1473 case SelectionRequest: 1482 case SelectionRequest:
1474 selection_send (ev.xselectionrequest); 1483 selection_send (ev.xselectionrequest);
1475 break; 1484 break;
1476 1485
1477 case UnmapNotify: 1486 case UnmapNotify:
1478 TermWin.mapped = 0; 1487 mapped = 0;
1479#ifdef TEXT_BLINK 1488#ifdef TEXT_BLINK
1480 text_blink_ev.stop (); 1489 text_blink_ev.stop ();
1481#endif 1490#endif
1482 break; 1491 break;
1483 1492
1484 case MapNotify: 1493 case MapNotify:
1485 TermWin.mapped = 1; 1494 mapped = 1;
1486#ifdef TEXT_BLINK 1495#ifdef TEXT_BLINK
1487 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 1496 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1488#endif 1497#endif
1489 break; 1498 break;
1490 1499
1494 break; 1503 break;
1495#endif /* TRANSPARENT */ 1504#endif /* TRANSPARENT */
1496 1505
1497 case GraphicsExpose: 1506 case GraphicsExpose:
1498 case Expose: 1507 case Expose:
1499 if (ev.xany.window == TermWin.vt) 1508 if (ev.xany.window == vt)
1500 { 1509 {
1501 do 1510 do
1502 scr_expose (ev.xexpose.x, ev.xexpose.y, 1511 scr_expose (ev.xexpose.x, ev.xexpose.y,
1503 ev.xexpose.width, ev.xexpose.height, False); 1512 ev.xexpose.width, ev.xexpose.height, False);
1504 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); 1513 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev));
1505 1514
1506 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1515 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1507 1516
1508 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) 1517 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1509 scr_expose (ev.xexpose.x, ev.xexpose.y, 1518 scr_expose (ev.xexpose.x, ev.xexpose.y,
1510 ev.xexpose.width, ev.xexpose.height, False); 1519 ev.xexpose.width, ev.xexpose.height, False);
1511 1520
1512 scr_refresh (refresh_type); 1521 scr_refresh (refresh_type);
1513 } 1522 }
1514 else 1523 else
1515 { 1524 {
1516 XEvent unused_event; 1525 XEvent unused_event;
1517 1526
1518 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) 1527 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1519 ; 1528 ;
1520 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) 1529 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1521 ; 1530 ;
1522 1531
1523 if (isScrollbarWindow (ev.xany.window)) 1532 if (isScrollbarWindow (ev.xany.window))
1524 { 1533 {
1525 scrollBar.setIdle (); 1534 scrollBar.setIdle ();
1529 if (menubar_visible () && isMenuBarWindow (ev.xany.window)) 1538 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1530 menubar_expose (); 1539 menubar_expose ();
1531#endif 1540#endif
1532 1541
1533#ifdef TRANSPARENT 1542#ifdef TRANSPARENT
1534 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1543 if (am_transparent && ev.xany.window == parent[0])
1535 XClearWindow (display->display, ev.xany.window); 1544 XClearWindow (disp, ev.xany.window);
1536#endif 1545#endif
1537 } 1546 }
1538 break; 1547 break;
1539 1548
1540 case MotionNotify: 1549 case MotionNotify:
1547 { 1556 {
1548 menubar_control (ev.xbutton); 1557 menubar_control (ev.xbutton);
1549 break; 1558 break;
1550 } 1559 }
1551#endif 1560#endif
1552 if ((priv_modes & PrivMode_mouse_report) && ! (bypass_keystate)) 1561 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1553 break; 1562 break;
1554 1563
1555 if (ev.xany.window == TermWin.vt) 1564 if (ev.xany.window == vt)
1556 { 1565 {
1557 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1566 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1558 { 1567 {
1559 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) 1568 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1560 ; 1569 ;
1561 1570
1562 XQueryPointer (display->display, TermWin.vt, 1571 XQueryPointer (disp, vt,
1563 &unused_root, &unused_child, 1572 &unused_root, &unused_child,
1564 &unused_root_x, &unused_root_y, 1573 &unused_root_x, &unused_root_y,
1565 & (ev.xbutton.x), & (ev.xbutton.y), 1574 &ev.xbutton.x, &ev.xbutton.y,
1566 &unused_mask); 1575 &ev.xbutton.state);
1567#ifdef MOUSE_THRESHOLD 1576#ifdef MOUSE_THRESHOLD
1568 /* deal with a `jumpy' mouse */ 1577 /* deal with a `jumpy' mouse */
1569 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) 1578 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1570 { 1579 {
1571#endif 1580#endif
1576 iso14755_54 (ev.xbutton.x, ev.xbutton.y); 1585 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1577 break; 1586 break;
1578 } 1587 }
1579#endif 1588#endif
1580 selection_extend (ev.xbutton.x, ev.xbutton.y, 1589 selection_extend (ev.xbutton.x, ev.xbutton.y,
1581 (ev.xbutton.state & Button3Mask) ? 2 : 0); 1590 ev.xbutton.state & Button3Mask ? 2 : 0);
1591
1582#ifdef SELECTION_SCROLLING 1592#ifdef SELECTION_SCROLLING
1583 if (ev.xbutton.y < TermWin.int_bwidth 1593 if (ev.xbutton.y < int_bwidth
1584 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1594 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1585 { 1595 {
1586 int dist; 1596 int dist;
1587 1597
1588 /* don't clobber the current delay if we are 1598 /* don't clobber the current delay if we are
1589 * already in the middle of scrolling. 1599 * already in the middle of scrolling.
1597 selection_save_x = ev.xbutton.x; 1607 selection_save_x = ev.xbutton.x;
1598 selection_save_y = ev.xbutton.y; 1608 selection_save_y = ev.xbutton.y;
1599 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1609 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1600 1610
1601 /* calc number of lines to scroll */ 1611 /* calc number of lines to scroll */
1602 if (ev.xbutton.y<TermWin.int_bwidth) 1612 if (ev.xbutton.y < int_bwidth)
1603 { 1613 {
1604 scroll_selection_dir = UP; 1614 scroll_selection_dir = UP;
1605 dist = TermWin.int_bwidth - ev.xbutton.y; 1615 dist = int_bwidth - ev.xbutton.y;
1606 } 1616 }
1607 else 1617 else
1608 { 1618 {
1609 scroll_selection_dir = DN; 1619 scroll_selection_dir = DN;
1610 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1620 dist = ev.xbutton.y - (int_bwidth + height);
1611 } 1621 }
1612 1622
1613 scroll_selection_lines = Pixel2Height (dist) 1623 scroll_selection_lines = Pixel2Height (dist)
1614 / SELECTION_SCROLL_LINE_SPEEDUP 1624 / SELECTION_SCROLL_LINE_SPEEDUP
1615 + 1; 1625 + 1;
1616 MIN_IT (scroll_selection_lines, 1626 min_it (scroll_selection_lines,
1617 SELECTION_SCROLL_MAX_LINES); 1627 SELECTION_SCROLL_MAX_LINES);
1618 } 1628 }
1619 else 1629 else
1620 { 1630 {
1621 /* we are within the text window, so we 1631 /* we are within the text window, so we
1630#endif 1640#endif
1631 } 1641 }
1632 } 1642 }
1633 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1643 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1634 { 1644 {
1635 while (XCheckTypedWindowEvent (display->display, scrollBar.win, 1645 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1636 MotionNotify, &ev)) ; 1646 MotionNotify, &ev))
1647 ;
1648
1637 XQueryPointer (display->display, scrollBar.win, 1649 XQueryPointer (disp, scrollBar.win,
1638 &unused_root, &unused_child, 1650 &unused_root, &unused_child,
1639 &unused_root_x, &unused_root_y, 1651 &unused_root_x, &unused_root_y,
1640 & (ev.xbutton.x), & (ev.xbutton.y), 1652 &ev.xbutton.x, &ev.xbutton.y,
1641 &unused_mask); 1653 &unused_mask);
1642 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1654 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1643 scrollbar_size ()); 1655 scrollbar_size ());
1644 scr_refresh (refresh_type); 1656 scr_refresh (refresh_type);
1645 refresh_limit = 0; 1657 refresh_limit = 0;
1647 } 1659 }
1648 break; 1660 break;
1649 } 1661 }
1650} 1662}
1651 1663
1664void
1665rxvt_term::focus_in ()
1666{
1667 if (!focus)
1668 {
1669 focus = 1;
1670 want_refresh = 1;
1671#if USE_XIM
1672 if (Input_Context != NULL)
1673 {
1674 IMSetStatusPosition ();
1675 XSetICFocus (Input_Context);
1676 }
1677#endif
1678#if CURSOR_BLINK
1679 if (options & Opt_cursorBlink)
1680 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1681#endif
1682#if OFF_FOCUS_FADING
1683 if (rs[Rs_fade])
1684 {
1685 pix_colors = pix_colors_focused;
1686 scr_recolour ();
1687 }
1688#endif
1689 }
1690}
1691
1692void
1693rxvt_term::focus_out ()
1694{
1695 if (focus)
1696 {
1697 focus = 0;
1698 want_refresh = 1;
1699
1700#if ENABLE_FRILLS || ISO_14755
1701 iso14755buf = 0;
1702#endif
1703#if ENABLE_OVERLAY
1704 scr_overlay_off ();
1705#endif
1706#if USE_XIM
1707 if (Input_Context != NULL)
1708 XUnsetICFocus (Input_Context);
1709#endif
1710#if CURSOR_BLINK
1711 if (options & Opt_cursorBlink)
1712 cursor_blink_ev.stop ();
1713 hidden_cursor = 0;
1714#endif
1715#if OFF_FOCUS_FADING
1716 if (rs[Rs_fade])
1717 {
1718 pix_colors = pix_colors_unfocused;
1719 scr_recolour ();
1720 }
1721#endif
1722 }
1723}
1724
1652#if TRANSPARENT 1725#if TRANSPARENT
1653void 1726void
1654rxvt_term::rootwin_cb (XEvent &ev) 1727rxvt_term::rootwin_cb (XEvent &ev)
1655{ 1728{
1656 SET_R (this); 1729 SET_R (this);
1661 case PropertyNotify: 1734 case PropertyNotify:
1662 /* 1735 /*
1663 * if user used some Esetroot compatible prog to set the root bg, 1736 * 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. 1737 * use the property to determine the pixmap. We use it later on.
1665 */ 1738 */
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]) 1739 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1740 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1670 return; 1741 return;
1671 1742
1672 /* FALLTHROUGH */ 1743 /* FALLTHROUGH */
1673 case ReparentNotify: 1744 case ReparentNotify:
1674 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1745 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1688 reportmode = !! (priv_modes & PrivMode_mouse_report); 1759 reportmode = !! (priv_modes & PrivMode_mouse_report);
1689 1760
1690 /* 1761 /*
1691 * VT window processing of button press 1762 * VT window processing of button press
1692 */ 1763 */
1693 if (ev.window == TermWin.vt) 1764 if (ev.window == vt)
1694 { 1765 {
1695#if ISO_14755 1766#if ISO_14755
1696 // 5.4 1767 // 5.4
1697 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1768 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1698 { 1769 {
1700 return; 1771 return;
1701 } 1772 }
1702#endif 1773#endif
1703 1774
1704 clickintime = ev.time - MEvent.time < MULTICLICK_TIME; 1775 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1776
1705 if (reportmode) 1777 if (reportmode)
1706 { 1778 {
1707 /* mouse report from vt window */ 1779 /* mouse report from vt window */
1708 /* save the xbutton state (for ButtonRelease) */ 1780 /* save the xbutton state (for ButtonRelease) */
1709 MEvent.state = ev.state; 1781 MEvent.state = ev.state;
1738 } 1810 }
1739 else 1811 else
1740 { 1812 {
1741 if (ev.button != MEvent.button) 1813 if (ev.button != MEvent.button)
1742 MEvent.clicks = 0; 1814 MEvent.clicks = 0;
1815
1743 switch (ev.button) 1816 switch (ev.button)
1744 { 1817 {
1745 case Button1: 1818 case Button1:
1819 /* allow meta + click to select rectangular areas */
1820 /* should be done in screen.C */
1821#if ENABLE_FRILLS
1822 selection.rect = !!(ev.state & ModMetaMask);
1823#else
1824 selection.rect = false;
1825#endif
1826
1746 /* allow shift+left click to extend selection */ 1827 /* allow shift+left click to extend selection */
1747 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1828 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1748 { 1829 {
1749 if (MEvent.button == Button1 && clickintime) 1830 if (MEvent.button == Button1 && clickintime)
1750 selection_rotate (ev.x, ev.y); 1831 selection_rotate (ev.x, ev.y);
1893 case Button3: 1974 case Button3:
1894 if (scrollBar.style != R_SB_XTERM) 1975 if (scrollBar.style != R_SB_XTERM)
1895 { 1976 {
1896 if (scrollbar_above_slider (ev.y)) 1977 if (scrollbar_above_slider (ev.y))
1897# ifdef RXVT_SCROLL_FULL 1978# ifdef RXVT_SCROLL_FULL
1898 scr_page (UP, TermWin.nrow - 1); 1979 scr_page (UP, nrow - 1);
1899# else 1980# else
1900 scr_page (UP, TermWin.nrow / 4); 1981 scr_page (UP, nrow / 4);
1901# endif 1982# endif
1902 else if (scrollbar_below_slider (ev.y)) 1983 else if (scrollbar_below_slider (ev.y))
1903# ifdef RXVT_SCROLL_FULL 1984# ifdef RXVT_SCROLL_FULL
1904 scr_page (DN, TermWin.nrow - 1); 1985 scr_page (DN, nrow - 1);
1905# else 1986# else
1906 scr_page (DN, TermWin.nrow / 4); 1987 scr_page (DN, nrow / 4);
1907# endif 1988# endif
1908 else 1989 else
1909 scrollBar.setMotion (); 1990 scrollBar.setMotion ();
1910 } 1991 }
1911 else 1992 else
1912 { 1993 {
1913 scr_page ((ev.button == Button1 ? DN : UP), 1994 scr_page ((ev.button == Button1 ? DN : UP),
1914 (TermWin.nrow 1995 (nrow
1915 * scrollbar_position (ev.y) 1996 * scrollbar_position (ev.y)
1916 / scrollbar_size ())); 1997 / scrollbar_size ()));
1917 } 1998 }
1918 1999
1919 break; 2000 break;
1951#ifdef SELECTION_SCROLLING 2032#ifdef SELECTION_SCROLLING
1952 if (sel_scroll_ev.active) 2033 if (sel_scroll_ev.active)
1953 sel_scroll_ev.stop(); 2034 sel_scroll_ev.stop();
1954#endif 2035#endif
1955 2036
1956 if (ev.window == TermWin.vt) 2037 if (ev.window == vt)
1957 { 2038 {
1958#if ISO_14755 2039#if ISO_14755
1959 // 5.4 2040 // 5.4
1960 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2041 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1961 return; 2042 return;
2012 v = ev.button == Button4 ? UP : DN; 2093 v = ev.button == Button4 ? UP : DN;
2013 2094
2014 if (ev.state & ShiftMask) 2095 if (ev.state & ShiftMask)
2015 i = 1; 2096 i = 1;
2016 else if (options & Opt_mouseWheelScrollPage) 2097 else if (options & Opt_mouseWheelScrollPage)
2017 i = TermWin.nrow - 1; 2098 i = nrow - 1;
2018 else 2099 else
2019 i = 5; 2100 i = 5;
2020 2101
2021# ifdef MOUSE_SLIP_WHEELING 2102# ifdef MOUSE_SLIP_WHEELING
2022 if (ev.state & ControlMask) 2103 if (ev.state & ControlMask)
2023 { 2104 {
2024 mouse_slip_wheel_speed += v ? -1 : 1; 2105 mouse_slip_wheel_speed += v ? -1 : 1;
2025 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2106 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2026 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow; 2107 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2027 2108
2028 if (slip_wheel_ev.at < NOW) 2109 if (slip_wheel_ev.at < NOW)
2029 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2110 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2030 2111
2031 slip_wheel_ev.start (); 2112 slip_wheel_ev.start ();
2072 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2153 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2073 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2154 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2074 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2155 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2075 int i; 2156 int i;
2076 2157
2077 Visual* visual = display->visual; 2158 Visual *visual = display->visual;
2078 2159
2079 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2160 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2080 2161
2081 /* for convenience */ 2162 /* for convenience */
2082 mask_r = visual->red_mask; 2163 mask_r = visual->red_mask;
2303 Atom atype; 2384 Atom atype;
2304 unsigned char *prop = NULL; 2385 unsigned char *prop = NULL;
2305 Window root, oldp, *list; 2386 Window root, oldp, *list;
2306 Pixmap rootpixmap = None; 2387 Pixmap rootpixmap = None;
2307 XWindowAttributes wattr, wrootattr; 2388 XWindowAttributes wattr, wrootattr;
2389 dDisp;
2308 2390
2309 pchanged = 0; 2391 pchanged = 0;
2310 2392
2311 if (!(options & Opt_transparent)) 2393 if (!(options & Opt_transparent))
2312 return pchanged; /* Don't try any more */ 2394 return pchanged; /* Don't try any more */
2313 2395
2314 XGetWindowAttributes (display->display, display->root, &wrootattr); 2396 XGetWindowAttributes (disp, display->root, &wrootattr);
2315 rootdepth = wrootattr.depth; 2397 rootdepth = wrootattr.depth;
2316 2398
2317 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2399 XGetWindowAttributes (disp, parent[0], &wattr);
2318 2400
2319 if (rootdepth != wattr.depth) 2401 if (rootdepth != wattr.depth)
2320 { 2402 {
2321 if (am_transparent) 2403 if (am_transparent)
2322 { 2404 {
2323 pchanged = 1; 2405 pchanged = 1;
2324 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2406 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2325 am_transparent = am_pixmap_trans = 0; 2407 am_transparent = am_pixmap_trans = 0;
2326 } 2408 }
2327 2409
2328 return pchanged; /* Don't try any more */ 2410 return pchanged; /* Don't try any more */
2329 } 2411 }
2330 2412
2331 /* Get all X ops out of the queue so that our information is up-to-date. */ 2413 /* Get all X ops out of the queue so that our information is up-to-date. */
2332 XSync (display->display, False); 2414 XSync (disp, False);
2333 2415
2334 /* 2416 /*
2335 * Make the frame window set by the window manager have 2417 * Make the frame window set by the window manager have
2336 * the root background. Some window managers put multiple nested frame 2418 * the root background. Some window managers put multiple nested frame
2337 * windows for each client, so we have to take care about that. 2419 * windows for each client, so we have to take care about that.
2338 */ 2420 */
2339 i = (xa[XA_XROOTPMAPID] 2421 i = (xa[XA_XROOTPMAP_ID]
2340 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2422 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2341 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2423 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2342 &nitems, &bytes_after, &prop) == Success); 2424 &nitems, &bytes_after, &prop) == Success);
2343 2425
2344 if (!i || prop == NULL) 2426 if (!i || prop == NULL)
2345 i = (xa[XA_XSETROOTID] 2427 i = (xa[XA_ESETROOT_PMAP_ID]
2346 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2428 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2347 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2429 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2348 &nitems, &bytes_after, &prop) == Success); 2430 &nitems, &bytes_after, &prop) == Success);
2349 2431
2350 if (!i || prop == NULL 2432 if (!i || prop == NULL
2351#if TINTING 2433#if TINTING
2370 Window cr; 2452 Window cr;
2371 XImage *image; 2453 XImage *image;
2372 GC gc; 2454 GC gc;
2373 XGCValues gcvalue; 2455 XGCValues gcvalue;
2374 2456
2375 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2457 XTranslateCoordinates (disp, parent[0], display->root,
2376 0, 0, &sx, &sy, &cr); 2458 0, 0, &sx, &sy, &cr);
2377 nw = (unsigned int)szHint.width; 2459 nw = (unsigned int)szHint.width;
2378 nh = (unsigned int)szHint.height; 2460 nh = (unsigned int)szHint.height;
2379 nx = ny = 0; 2461 nx = ny = 0;
2380 2462
2390 nh += sy; 2472 nh += sy;
2391 ny = -sy; 2473 ny = -sy;
2392 sy = 0; 2474 sy = 0;
2393 } 2475 }
2394 2476
2395 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2477 min_it (nw, (unsigned int) (wrootattr.width - sx));
2396 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2478 min_it (nh, (unsigned int) (wrootattr.height - sy));
2479
2480 XSync (disp, False);
2397 allowedxerror = -1; 2481 allowedxerror = -1;
2398 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2482 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2399 2483
2400 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2484 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2401 /* XXX: may need a delay here? */ 2485 /* XXX: may need a delay here? */
2402 allowedxerror = 0; 2486 allowedxerror = 0;
2403 2487
2404 if (image == NULL) 2488 if (image == NULL)
2405 { 2489 {
2406 if (am_transparent && am_pixmap_trans) 2490 if (am_transparent && am_pixmap_trans)
2407 { 2491 {
2408 pchanged = 1; 2492 pchanged = 1;
2409 if (TermWin.pixmap != None) 2493 if (pixmap != None)
2410 { 2494 {
2411 XFreePixmap (display->display, TermWin.pixmap); 2495 XFreePixmap (disp, pixmap);
2412 TermWin.pixmap = None; 2496 pixmap = None;
2413 } 2497 }
2414 } 2498 }
2415 2499
2416 am_pixmap_trans = 0; 2500 am_pixmap_trans = 0;
2417 } 2501 }
2418 else 2502 else
2419 { 2503 {
2420 if (TermWin.pixmap != None) 2504 if (pixmap != None)
2421 XFreePixmap (display->display, TermWin.pixmap); 2505 XFreePixmap (disp, pixmap);
2422 2506
2423#if TINTING 2507#if TINTING
2424 if (ISSET_PIXCOLOR (Color_tint)) 2508 if (ISSET_PIXCOLOR (Color_tint))
2425 { 2509 {
2426 unsigned short rm, gm, bm; 2510 unsigned short rm, gm, bm;
2430 2514
2431 ShadeXImage (display, image, shade, rm, gm, bm); 2515 ShadeXImage (display, image, shade, rm, gm, bm);
2432 } 2516 }
2433#endif 2517#endif
2434 2518
2435 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2519 pixmap = XCreatePixmap (disp, vt,
2436 szHint.width, szHint.height, image->depth); 2520 szHint.width, szHint.height, image->depth);
2437 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2521 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2438 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2522 XPutImage (disp, pixmap, gc, image, 0, 0,
2439 nx, ny, image->width, image->height); 2523 nx, ny, image->width, image->height);
2440 XFreeGC (display->display, gc); 2524 XFreeGC (disp, gc);
2441 XDestroyImage (image); 2525 XDestroyImage (image);
2442 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); 2526 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2443 XClearWindow (display->display, TermWin.parent[0]); 2527 XClearWindow (disp, parent[0]);
2444 2528
2445 if (!am_transparent || !am_pixmap_trans) 2529 if (!am_transparent || !am_pixmap_trans)
2446 pchanged = 1; 2530 pchanged = 1;
2447 2531
2448 am_transparent = am_pixmap_trans = 1; 2532 am_transparent = am_pixmap_trans = 1;
2449 } 2533 }
2450 } 2534 }
2451 2535
2452 if (!am_pixmap_trans) 2536 if (am_pixmap_trans)
2537 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2538 else
2453 { 2539 {
2454 unsigned int n; 2540 unsigned int n;
2455 /* 2541 /*
2456 * InheritPixmap transparency 2542 * InheritPixmap transparency
2457 */ 2543 */
2458 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2544 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2459 { 2545 {
2460 oldp = TermWin.parent[i]; 2546 oldp = parent[i];
2461 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2547 XQueryTree (disp, parent[i - 1], &root,
2462 &TermWin.parent[i], &list, &n); 2548 &parent[i], &list, &n);
2463 XFree (list); 2549 XFree (list);
2464 2550
2465 if (TermWin.parent[i] == display->root) 2551 if (parent[i] == display->root)
2466 { 2552 {
2467 if (oldp != None) 2553 if (oldp != None)
2468 pchanged = 1; 2554 pchanged = 1;
2469 2555
2470 break; 2556 break;
2471 } 2557 }
2472 2558
2473 if (oldp != TermWin.parent[i]) 2559 if (oldp != parent[i])
2474 pchanged = 1; 2560 pchanged = 1;
2475 } 2561 }
2476 2562
2477 n = 0; 2563 n = 0;
2478 2564
2479 if (pchanged) 2565 if (pchanged)
2480 { 2566 {
2481 for (; n < (unsigned int)i; n++) 2567 for (; n < (unsigned int)i; n++)
2482 { 2568 {
2483 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 2569 XGetWindowAttributes (disp, parent[n], &wattr);
2484 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2570 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2485 { 2571 {
2486 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2572 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2487 break; 2573 break;
2488 } 2574 }
2489 } 2575 }
2490 } 2576 }
2491 2577
2492 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) 2578 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2493 { 2579 {
2494 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); 2580 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2495 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2581 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2496 am_transparent = 0; 2582 am_transparent = 0;
2497 /* XXX: also turn off Opt_transparent? */ 2583 /* XXX: also turn off Opt_transparent? */
2498 } 2584 }
2499 else 2585 else
2500 { 2586 {
2503 * needed for fvwm2.2.2 (and before?) */ 2589 * needed for fvwm2.2.2 (and before?) */
2504 sleep (1); 2590 sleep (1);
2505#endif 2591#endif
2506 for (n = 0; n < (unsigned int)i; n++) 2592 for (n = 0; n < (unsigned int)i; n++)
2507 { 2593 {
2508 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); 2594 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2509 XClearWindow (display->display, TermWin.parent[n]); 2595 XClearWindow (disp, parent[n]);
2510 } 2596 }
2511 2597
2512 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); 2598 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2513 am_transparent = 1; 2599 am_transparent = 1;
2514 } 2600 }
2515 2601
2516 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2602 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2517 TermWin.parent[i] = None; 2603 parent[i] = None;
2518 } 2604 }
2519 2605
2520 // this is experimental
2521 if (scrollBar.win) 2606 if (scrollBar.win)
2522 { 2607 {
2523 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2608 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2524 XClearWindow (display->display, scrollBar.win);
2525 scrollBar.setIdle (); 2609 scrollBar.setIdle ();
2526 scrollbar_show (0); 2610 scrollbar_show (0);
2611 }
2612
2613 if (am_transparent)
2614 {
2615 want_refresh = want_full_refresh = 1;
2616 if (am_pixmap_trans)
2617 flush ();
2527 } 2618 }
2528 2619
2529 return pchanged; 2620 return pchanged;
2530} 2621}
2531#endif 2622#endif
2557 seen_input = 1; 2648 seen_input = 1;
2558 // many badly-written programs (e.g. jed) contain a race condition: 2649 // many badly-written programs (e.g. jed) contain a race condition:
2559 // they first read the screensize and then install a SIGWINCH handler. 2650 // they first read the screensize and then install a SIGWINCH handler.
2560 // some window managers resize the window early, and these programs 2651 // some window managers resize the window early, and these programs
2561 // then sometimes get the size wrong. 2652 // then sometimes get the size wrong.
2653 // unfortunately other programs are even more buggy and dislike
2654 // being sent SIGWINCH, so only do it when we were in fact being
2655 // resized.
2656 if (seen_resize && cmd_pid)
2562 kill (-cmd_pid, SIGWINCH); 2657 kill (-cmd_pid, SIGWINCH);
2563 } 2658 }
2564 2659
2565 /* Read a text string from the input buffer */ 2660 /* Read a text string from the input buffer */
2566 unicode_t buf[UBUFSIZ]; 2661 unicode_t buf[UBUFSIZ];
2567 bool refreshnow = false; 2662 bool refreshnow = false;
2568 int nlines = 0; 2663 int nlines = 0;
2569 unicode_t *str = buf; 2664 unicode_t *str = buf;
2665 unicode_t *eol = str + min (ncol, UBUFSIZ);
2570 2666
2571 for (;;) 2667 for (;;)
2572 { 2668 {
2573 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2669 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2574 break; 2670 break;
2575 2671
2576 *str++ = ch; 2672 *str++ = ch;
2577 2673
2578 if (ch == C0_LF) 2674 if (ch == C0_LF || str >= eol)
2579 { 2675 {
2676 if (ch == C0_LF)
2580 nlines++; 2677 nlines++;
2678
2581 refresh_count++; 2679 refresh_count++;
2582 2680
2583 if (!(options & Opt_jumpScroll) 2681 if (!(options & Opt_jumpScroll)
2584 || (refresh_count >= refresh_limit * (TermWin.nrow - 1))) 2682 || (refresh_count >= refresh_limit * (nrow - 1)))
2585 { 2683 {
2586 refreshnow = true; 2684 refreshnow = true;
2587 ch = NOCHAR; 2685 ch = NOCHAR;
2588 break; 2686 break;
2589 } 2687 }
2590 2688
2591 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2689 // scr_add_lines only works for nlines <= nrow - 1.
2592 if (nlines >= TermWin.nrow - 1) 2690 if (nlines >= nrow - 1)
2593 { 2691 {
2594 scr_add_lines (buf, nlines, str - buf); 2692 scr_add_lines (buf, nlines, str - buf);
2595 nlines = 0; 2693 nlines = 0;
2596 str = buf; 2694 str = buf;
2695 eol = str + min (ncol, UBUFSIZ);
2597 } 2696 }
2598 }
2599 2697
2600 if (str >= buf + UBUFSIZ) 2698 if (str >= eol)
2601 { 2699 {
2700 if (eol >= buf + UBUFSIZ)
2701 {
2602 ch = NOCHAR; 2702 ch = NOCHAR;
2603 break; 2703 break;
2704 }
2705 else
2706 eol = min (eol + ncol, buf + UBUFSIZ);
2707 }
2708
2604 } 2709 }
2605 2710
2606 seq_begin = cmdbuf_ptr; 2711 seq_begin = cmdbuf_ptr;
2607 ch = next_char (); 2712 ch = next_char ();
2608 } 2713 }
2679 if (len == (size_t)-1) 2784 if (len == (size_t)-1)
2680 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2785 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2681 2786
2682 // assume wchar == unicode 2787 // assume wchar == unicode
2683 cmdbuf_ptr += len; 2788 cmdbuf_ptr += len;
2684 return wc; 2789 return wc & UNICODE_MASK;
2685 } 2790 }
2686 2791
2687 return NOCHAR; 2792 return NOCHAR;
2688} 2793}
2689 2794
3152 { 3257 {
3153 switch (priv) 3258 switch (priv)
3154 { 3259 {
3155 case '>': 3260 case '>':
3156 if (ch == CSI_DA) /* secondary device attributes */ 3261 if (ch == CSI_DA) /* secondary device attributes */
3157 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING); 3262 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]);
3158 break; 3263 break;
3159 case '?': 3264 case '?':
3160 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3265 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3161 process_terminal_mode (ch, priv, nargs, arg); 3266 process_terminal_mode (ch, priv, nargs, arg);
3162 break; 3267 break;
3267 3372
3268 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 3373 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3269 arg[0] = -arg[0]; 3374 arg[0] = -arg[0];
3270 /* FALLTHROUGH */ 3375 /* FALLTHROUGH */
3271 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3376 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3272 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 3377 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3273 break; 3378 break;
3274 3379
3275 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3380 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3276 tt_write ((const unsigned char *)VT100_ANS, 3381 tt_write ((const unsigned char *)VT100_ANS,
3277 (unsigned int) (sizeof (VT100_ANS) - 1)); 3382 (unsigned int) (sizeof (VT100_ANS) - 1));
3391rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3496rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3392{ 3497{
3393 int x, y; 3498 int x, y;
3394 XWindowAttributes wattr; 3499 XWindowAttributes wattr;
3395 Window wdummy; 3500 Window wdummy;
3501 dDisp;
3396 3502
3397 if (nargs == 0) 3503 if (nargs == 0)
3398 return; 3504 return;
3399 3505
3400 switch (args[0]) 3506 switch (args[0])
3401 { 3507 {
3402 /* 3508 /*
3403 * commands 3509 * commands
3404 */ 3510 */
3405 case 1: /* deiconify window */ 3511 case 1: /* deiconify window */
3406 XMapWindow (display->display, TermWin.parent[0]); 3512 XMapWindow (disp, parent[0]);
3407 break; 3513 break;
3408 case 2: /* iconify window */ 3514 case 2: /* iconify window */
3409 XIconifyWindow (display->display, TermWin.parent[0], 3515 XIconifyWindow (disp, parent[0], display->screen);
3410 DefaultScreen (display->display));
3411 break; 3516 break;
3412 case 3: /* set position (pixels) */ 3517 case 3: /* set position (pixels) */
3413 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); 3518 XMoveWindow (disp, parent[0], args[1], args[2]);
3414 break; 3519 break;
3415 case 4: /* set size (pixels) */ 3520 case 4: /* set size (pixels) */
3416 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3521 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3417 break; 3522 break;
3418 case 5: /* raise window */ 3523 case 5: /* raise window */
3419 XRaiseWindow (display->display, TermWin.parent[0]); 3524 XRaiseWindow (disp, parent[0]);
3420 break; 3525 break;
3421 case 6: /* lower window */ 3526 case 6: /* lower window */
3422 XLowerWindow (display->display, TermWin.parent[0]); 3527 XLowerWindow (disp, parent[0]);
3423 break; 3528 break;
3424 case 7: /* refresh window */ 3529 case 7: /* refresh window */
3425 scr_touch (true); 3530 scr_touch (true);
3426 break; 3531 break;
3427 case 8: /* set size (chars) */ 3532 case 8: /* set size (chars) */
3428 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3533 set_widthheight ((unsigned int) (args[2] * fwidth),
3429 (unsigned int) (args[1] * TermWin.fheight)); 3534 (unsigned int) (args[1] * fheight));
3430 break; 3535 break;
3431 3536
3432 //case 9: NYI, TODO, restore maximized window or maximize window 3537 //case 9: NYI, TODO, restore maximized window or maximize window
3433 default: 3538 default:
3434 if (args[0] >= 24) /* set height (chars) */ 3539 if (args[0] >= 24) /* set height (chars) */
3435 set_widthheight ((unsigned int)TermWin.width, 3540 set_widthheight ((unsigned int)width,
3436 (unsigned int) (args[1] * TermWin.fheight)); 3541 (unsigned int) (args[1] * fheight));
3437 break; 3542 break;
3438 3543
3439 3544
3440 /* 3545 /*
3441 * reports - some output format copied from XTerm 3546 * reports - some output format copied from XTerm
3442 */ 3547 */
3443 case 11: /* report window state */ 3548 case 11: /* report window state */
3444 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3549 XGetWindowAttributes (disp, parent[0], &wattr);
3445 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3550 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3446 break; 3551 break;
3447 case 13: /* report window position */ 3552 case 13: /* report window position */
3448 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3553 XGetWindowAttributes (disp, parent[0], &wattr);
3449 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3554 XTranslateCoordinates (disp, parent[0], wattr.root,
3450 -wattr.border_width, -wattr.border_width, 3555 -wattr.border_width, -wattr.border_width,
3451 &x, &y, &wdummy); 3556 &x, &y, &wdummy);
3452 tt_printf ("\033[3;%d;%dt", x, y); 3557 tt_printf ("\033[3;%d;%dt", x, y);
3453 break; 3558 break;
3454 case 14: /* report window size (pixels) */ 3559 case 14: /* report window size (pixels) */
3455 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3560 XGetWindowAttributes (disp, parent[0], &wattr);
3456 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3561 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3457 break; 3562 break;
3458 case 18: /* report text area size (chars) */ 3563 case 18: /* report text area size (chars) */
3459 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3564 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3460 break; 3565 break;
3461 case 19: /* report window size (chars) */ 3566 case 19: /* report window size (chars) */
3462 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3567 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3463 break; 3568 break;
3464 case 20: /* report icon label */ 3569 case 20: /* report icon label */
3465 { 3570 {
3466 char *s; 3571 char *s;
3467 XGetIconName (display->display, TermWin.parent[0], &s); 3572 XGetIconName (disp, parent[0], &s);
3468 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3573 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3469 XFree (s); 3574 XFree (s);
3470 } 3575 }
3471 break; 3576 break;
3472 case 21: /* report window title */ 3577 case 21: /* report window title */
3473 { 3578 {
3474 char *s; 3579 char *s;
3475 XFetchName (display->display, TermWin.parent[0], &s); 3580 XFetchName (disp, parent[0], &s);
3476 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3581 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3477 XFree (s); 3582 XFree (s);
3478 } 3583 }
3479 break; 3584 break;
3480 } 3585 }
3487 * ends_how is terminator used. returned input must be free()'d 3592 * ends_how is terminator used. returned input must be free()'d
3488 */ 3593 */
3489unsigned char * 3594unsigned char *
3490rxvt_term::get_to_st (unicode_t &ends_how) 3595rxvt_term::get_to_st (unicode_t &ends_how)
3491{ 3596{
3492 unicode_t prev = 0, ch; 3597 unicode_t ch;
3598 bool seen_esc = false;
3493 unsigned int n = 0; 3599 unsigned int n = 0;
3494 unsigned char *s;
3495 unsigned char string[STRING_MAX]; 3600 wchar_t string[STRING_MAX];
3496 3601
3497 while ((ch = cmd_getc ()) != NOCHAR) 3602 while ((ch = cmd_getc ()) != NOCHAR)
3498 { 3603 {
3499 if (prev == C0_ESC) 3604 if (seen_esc)
3500 { 3605 {
3501 if (ch == 0x5c) /* 7bit ST */ 3606 if (ch == 0x5c) /* 7bit ST */
3502 break; 3607 break;
3503 else 3608 else
3504 return NULL; 3609 return NULL;
3505 } 3610 }
3611 else if (ch == C0_ESC)
3612 {
3613 seen_esc = true;
3614 continue;
3615 }
3506 else if (ch == C0_BEL || ch == CHAR_ST) 3616 else if (ch == C0_BEL || ch == CHAR_ST)
3507 break; 3617 break;
3508 else if (ch < 0x20) 3618 else if (ch < 0x20)
3509 return NULL; /* other control character - exit */ 3619 return NULL; /* other control character - exit */
3510 3620
3511 if (n >= sizeof (string) - 1) 3621 seen_esc = false;
3622
3623 if (n >= STRING_MAX - 1)
3512 // stop at some sane length 3624 // stop at some sane length
3513 return NULL; 3625 return NULL;
3514 3626
3515 if (ch == C0_SYN) 3627 if (ch == C0_SYN)
3516 {
3517 string[n++] = cmd_get8 (); 3628 string[n++] = cmd_get8 ();
3518 prev = 0;
3519 }
3520 else 3629 else
3521 string[n++] = prev = ch; 3630 string[n++] = ch;
3522 } 3631 }
3523 3632
3524 string[n++] = '\0'; 3633 string[n++] = '\0';
3525 3634
3526 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3527 return NULL;
3528
3529 ends_how = (ch == 0x5c ? C0_ESC : ch); 3635 ends_how = (ch == 0x5c ? C0_ESC : ch);
3530 strncpy (s, string, n); 3636
3531 return s; 3637 return (unsigned char *)rxvt_wcstombs (string);
3532} 3638}
3533 3639
3534/*----------------------------------------------------------------------*/ 3640/*----------------------------------------------------------------------*/
3535/* 3641/*
3536 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3642 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3590 set_window_color (color, str); 3696 set_window_color (color, str);
3591} 3697}
3592 3698
3593/* 3699/*
3594 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3700 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3595 * 0 = change iconName/title
3596 * 1 = change iconName
3597 * 2 = change title
3598 * 4 = change color
3599 * 10 = change fg color
3600 * 11 = change bg color
3601 * 12 = change text color
3602 * 13 = change mouse foreground color
3603 * 17 = change highlight character colour
3604 * 18 = change bold character color
3605 * 19 = change underlined character color
3606 * 46 = change logfile (not implemented)
3607 * 50 = change font
3608 *
3609 * rxvt extensions:
3610 * 20 = bg pixmap
3611 * 39 = change default fg color
3612 * 49 = change default bg color
3613 * 55 = dump scrollback buffer and all of screen
3614 * 701 = change locale
3615 * 702 = find font
3616 * 703 = menu
3617 */ 3701 */
3618void 3702void
3619rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3703rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3620{ 3704{
3621 int changed = 0; 3705 int changed = 0;
3622 int color; 3706 int color;
3623 char *buf, *name; 3707 char *buf, *name;
3624 bool query = str[0] == '?' && !str[1]; 3708 bool query = str[0] == '?' && !str[1];
3709 int saveop = op;
3710 dDisp;
3625 3711
3626 assert (str != NULL); 3712 assert (str != NULL);
3627 switch (op) 3713 switch (op)
3628 { 3714 {
3629 case XTerm_name: 3715 case XTerm_name:
3636 set_title (str); 3722 set_title (str);
3637 break; 3723 break;
3638 case XTerm_property: 3724 case XTerm_property:
3639 if (str[0] == '?') 3725 if (str[0] == '?')
3640 { 3726 {
3641 Atom prop = XInternAtom (display->display, str + 1, True); 3727 Atom prop = display->atom (str + 1);
3642 Atom actual_type; 3728 Atom actual_type;
3643 int actual_format; 3729 int actual_format;
3644 unsigned long nitems; 3730 unsigned long nitems;
3645 unsigned long bytes_after; 3731 unsigned long bytes_after;
3646 unsigned char *value = 0; 3732 unsigned char *value = 0;
3647 const char *str = ""; 3733 const char *str = "";
3648 3734
3649 if (prop 3735 if (prop
3650 && XGetWindowProperty (display->display, TermWin.parent[0], 3736 && XGetWindowProperty (disp, parent[0],
3651 prop, 0, 1<<16, 0, AnyPropertyType, 3737 prop, 0, 1<<16, 0, AnyPropertyType,
3652 &actual_type, &actual_format, 3738 &actual_type, &actual_format,
3653 &nitems, &bytes_after, &value) == Success 3739 &nitems, &bytes_after, &value) == Success
3654 && actual_type != None 3740 && actual_type != None
3655 && actual_format == 8) 3741 && actual_format == 8)
3664 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3750 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3665 3751
3666 if (eq) 3752 if (eq)
3667 { 3753 {
3668 *eq = 0; 3754 *eq = 0;
3669 XChangeProperty (display->display, TermWin.parent[0], 3755 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 } 3756 }
3674 else 3757 else
3675 XDeleteProperty (display->display, TermWin.parent[0], 3758 XDeleteProperty (disp, parent[0],
3676 display->atom (str)); 3759 display->atom (str));
3677 } 3760 }
3678 break; 3761 break;
3679 3762
3680 case XTerm_Color: 3763 case XTerm_Color:
3727 process_color_seq (XTerm_Color_UL, Color_UL, str, resp); 3810 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3728 break; 3811 break;
3729 case XTerm_Color_RV: 3812 case XTerm_Color_RV:
3730 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3813 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3731 break; 3814 break;
3815 case URxvt_Color_IT:
3816 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3817 break;
3818#endif
3819#if TRANSPARENT && TINTING
3820 case URxvt_Color_tint:
3821 process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3822 check_our_parents ();
3823 if (am_transparent)
3824 want_full_refresh = want_refresh = 1;
3825 break;
3732#endif 3826#endif
3733 3827
3734 case XTerm_Pixmap: 3828 case XTerm_Pixmap:
3735 if (*str != ';') 3829 if (*str != ';')
3736 { 3830 {
3744 { 3838 {
3745 str++; 3839 str++;
3746#if XPM_BACKGROUND 3840#if XPM_BACKGROUND
3747 changed += scale_pixmap (str); 3841 changed += scale_pixmap (str);
3748#endif 3842#endif
3749
3750 } 3843 }
3844
3751 if (changed) 3845 if (changed)
3752 { 3846 {
3753#ifdef XPM_BACKGROUND 3847#ifdef XPM_BACKGROUND
3754 resize_pixmap (); 3848 resize_pixmap ();
3755#endif 3849#endif
3766 3860
3767 case XTerm_logfile: 3861 case XTerm_logfile:
3768 // TODO, when secure mode? 3862 // TODO, when secure mode?
3769 break; 3863 break;
3770 3864
3771 case XTerm_font:
3772 if (query)
3773 tt_printf ("\33]%d;%-.250s%c", XTerm_font,
3774 (options & Opt_insecure) && TermWin.fontset->fontdesc
3775 ? TermWin.fontset->fontdesc : "",
3776 resp);
3777 else
3778 change_font (str);
3779 break;
3780
3781#if ENABLE_FRILLS
3782 case XTerm_locale:
3783 if (query)
3784 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp);
3785 else
3786 {
3787 set_locale (str);
3788# ifdef USE_XIM
3789 im_cb ();
3790# endif
3791 }
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;
3803#endif
3804
3805#ifdef MENUBAR 3865#ifdef MENUBAR
3806 case XTerm_Menu: 3866 case URxvt_Menu:
3807 if (options & Opt_insecure) 3867 if (options & Opt_insecure)
3808 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3868 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3809 break; 3869 break;
3810#endif 3870#endif
3811#if 0 3871#if 0
3816 { 3876 {
3817 scr_dump (fd); 3877 scr_dump (fd);
3818 close (fd); 3878 close (fd);
3819 } 3879 }
3820 } 3880 }
3881 break;
3882#endif
3883 case XTerm_font:
3884 op = URxvt_font;
3885 case URxvt_font:
3886#if ENABLE_STYLES
3887 case URxvt_boldFont:
3888 case URxvt_italicFont:
3889 case URxvt_boldItalicFont:
3890#endif
3891 if (query)
3892 tt_printf ("\33]%d;%-.250s%c", saveop,
3893 (options & Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3894 ? fontset[op - URxvt_font]->fontdesc : "",
3895 resp);
3896 else
3897 {
3898 const char *&res = rs[Rs_font + (op - URxvt_font)];
3899
3900 res = strdup (str);
3901 allocated.push_back ((void *)res);
3902 set_fonts ();
3903 }
3904 break;
3905
3906#if ENABLE_FRILLS
3907 case URxvt_locale:
3908 if (query)
3909 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp);
3910 else
3911 {
3912 set_locale (str);
3913 pty.set_utf8_mode (enc_utf8);
3914 init_xlocale ();
3915 }
3916 break;
3917
3918 case URxvt_view_up:
3919 case URxvt_view_down:
3920 int lines = atoi (str);
3921
3922 if (lines)
3923 scr_page (op == URxvt_view_up ? UP : DN, lines);
3924 else
3925 {
3926 scr_erase_savelines ();
3927 }
3928
3821 break; 3929 break;
3822#endif 3930#endif
3823 } 3931 }
3824} 3932}
3825/*----------------------------------------------------------------------*/ 3933/*----------------------------------------------------------------------*/
3935 4043
3936 /* extra handling for values with state unkept */ 4044 /* extra handling for values with state unkept */
3937 switch (arg[i]) 4045 switch (arg[i])
3938 { 4046 {
3939 case 1048: /* alternative cursor save */ 4047 case 1048: /* alternative cursor save */
4048 case 1049:
3940 if (options & Opt_secondaryScreen) 4049 if (options & Opt_secondaryScreen)
3941 if (mode == 0) 4050 if (mode == 0)
3942 scr_cursor (RESTORE); 4051 scr_cursor (RESTORE);
3943 else if (mode == 1) 4052 else if (mode == 1)
3944 scr_cursor (SAVE); 4053 scr_cursor (SAVE);
3957 */ 4066 */
3958 PrivMode (1, PrivMode_vt52); 4067 PrivMode (1, PrivMode_vt52);
3959 break; 4068 break;
3960 case 3: /* 80/132 */ 4069 case 3: /* 80/132 */
3961 if (priv_modes & PrivMode_132OK) 4070 if (priv_modes & PrivMode_132OK)
3962 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 4071 set_widthheight (((state ? 132 : 80) * fwidth), height);
3963 break; 4072 break;
3964 case 4: /* smooth scrolling */ 4073 case 4: /* smooth scrolling */
3965 if (state) 4074 if (state)
3966 options &= ~Opt_jumpScroll; 4075 options &= ~Opt_jumpScroll;
3967 else 4076 else
4069 rendset = 0, rendstyle = ~RS_None; 4178 rendset = 0, rendstyle = ~RS_None;
4070 break; 4179 break;
4071 case 1: 4180 case 1:
4072 rendset = 1, rendstyle = RS_Bold; 4181 rendset = 1, rendstyle = RS_Bold;
4073 break; 4182 break;
4074 //case 2: // faint or second colour 4183 //case 2: // low intensity
4075 //case 3: // italic 4184 case 3:
4185 rendset = 1, rendstyle = RS_Italic;
4186 break;
4076 case 4: 4187 case 4:
4077 rendset = 1, rendstyle = RS_Uline; 4188 rendset = 1, rendstyle = RS_Uline;
4078 break; 4189 break;
4079 case 5: // slowly blinking 4190 case 5: // slowly blinking
4080 case 6: // rapidly blinking 4191 case 6: // rapidly blinking
4092 //case 11: // scoansi acs on, first alt font 4203 //case 11: // scoansi acs on, first alt font
4093 //case 12: // scoansi acs on, |0x80, second alt font 4204 //case 12: // scoansi acs on, |0x80, second alt font
4094 //... 4205 //...
4095 //case 19: // ninth alt font 4206 //case 19: // ninth alt font
4096 //case 20: // gothic 4207 //case 20: // gothic
4097 case 21: // disable bold, faint 4208 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4098 rendset = 0, rendstyle = RS_Bold; 4209 rendset = 0, rendstyle = RS_Bold;
4099 break; 4210 break;
4100 case 22: 4211 case 22: // normal intensity
4101 rendset = 0, rendstyle = RS_Bold; 4212 rendset = 0, rendstyle = RS_Bold;
4102 break; 4213 break;
4103 //case 23: disable italic 4214 case 23: // disable italic
4215 rendset = 0, rendstyle = RS_Italic;
4216 break;
4104 case 24: 4217 case 24:
4105 rendset = 0, rendstyle = RS_Uline; 4218 rendset = 0, rendstyle = RS_Uline;
4106 break; 4219 break;
4107 case 25: 4220 case 25:
4108 rendset = 0, rendstyle = RS_Blink; 4221 rendset = 0, rendstyle = RS_Blink;
4109 break; 4222 break;
4110 case 26: 4223 case 26: // variable spacing (iso 8613)
4111 rendset = 0, rendstyle = RS_Blink; 4224 rendset = 0, rendstyle = RS_Blink;
4112 break; 4225 break;
4113 case 27: 4226 case 27:
4114 rendset = 0, rendstyle = RS_RVid; 4227 rendset = 0, rendstyle = RS_RVid;
4115 break; 4228 break;
4133 case 35: 4246 case 35:
4134 case 36: 4247 case 36:
4135 case 37: 4248 case 37:
4136 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); 4249 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4137 break; 4250 break;
4138#ifdef TTY_256COLOR 4251 case 38: // set fg color, ISO 8613-6
4139 case 38:
4140 if (nargs > i + 2 && arg[i + 1] == 5) 4252 if (nargs > i + 2 && arg[i + 1] == 5)
4141 { 4253 {
4142 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); 4254 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4143 i += 2; 4255 i += 2;
4144 } 4256 }
4145 break; 4257 break;
4146#endif
4147 case 39: /* default fg */ 4258 case 39: /* default fg */
4148 scr_color (Color_fg, Color_fg); 4259 scr_color (Color_fg, Color_fg);
4149 break; 4260 break;
4150 4261
4151 case 40: 4262 case 40:
4156 case 45: 4267 case 45:
4157 case 46: 4268 case 46:
4158 case 47: 4269 case 47:
4159 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); 4270 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4160 break; 4271 break;
4161#ifdef TTY_256COLOR 4272 case 48: // set bg color, ISO 8613-6
4162 case 48:
4163 if (nargs > i + 2 && arg[i + 1] == 5) 4273 if (nargs > i + 2 && arg[i + 1] == 5)
4164 { 4274 {
4165 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); 4275 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4166 i += 2; 4276 i += 2;
4167 } 4277 }
4168 break; 4278 break;
4169#endif
4170 case 49: /* default bg */ 4279 case 49: /* default bg */
4171 scr_color (Color_bg, Color_bg); 4280 scr_color (Color_bg, Color_bg);
4172 break; 4281 break;
4282
4283 //case 50: // not variable spacing
4173 4284
4174#ifndef NO_BRIGHTCOLOR 4285#ifndef NO_BRIGHTCOLOR
4175 case 90: 4286 case 90:
4176 case 91: /* set bright fg color */ 4287 case 91: /* set bright fg color */
4177 case 92: 4288 case 92:
4178 case 93: 4289 case 93:
4179 case 94: 4290 case 94:
4180 case 95: 4291 case 95:
4181 case 96: 4292 case 96:
4182 case 97: 4293 case 97:
4183 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), 4294 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4184 Color_fg);
4185 break; 4295 break;
4186 case 100: 4296 case 100:
4187 case 101: /* set bright bg color */ 4297 case 101: /* set bright bg color */
4188 case 102: 4298 case 102:
4189 case 103: 4299 case 103:
4190 case 104: 4300 case 104:
4191 case 105: 4301 case 105:
4192 case 106: 4302 case 106:
4193 case 107: 4303 case 107:
4194 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), 4304 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4195 Color_bg);
4196 break; 4305 break;
4197#endif 4306#endif
4198 4307
4199 } 4308 }
4200 } 4309 }
4239 4348
4240/* ---------------------------------------------------------------------- */ 4349/* ---------------------------------------------------------------------- */
4241/* Write data to the pty as typed by the user, pasted with the mouse, 4350/* 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. 4351 * or generated by us in response to a query ESC sequence.
4243 */ 4352 */
4353const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4354
4244void 4355void
4245rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4356rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4246{ 4357{
4247 enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT 4358 if (v_buflen == 0)
4359 {
4360 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4248 4361
4249 if (len) 4362 if ((unsigned int)written == len)
4363 return;
4364
4365 data += written;
4366 len -= written;
4250 { 4367 }
4368
4369 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4370
4371 memcpy (v_buffer + v_buflen, data, len);
4372 v_buflen += len;
4373
4374 pty_ev.set (EVENT_READ | EVENT_WRITE);
4375}
4376
4377void rxvt_term::pty_write ()
4378{
4379 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4380
4381 if (written > 0)
4382 {
4383 v_buflen -= written;
4384
4251 if (v_buflen == 0) 4385 if (v_buflen == 0)
4252 { 4386 {
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); 4387 free (v_buffer);
4280 v_buffer = 0; 4388 v_buffer = 0;
4281 v_buflen = 0; 4389 v_buflen = 0;
4282 4390
4283 pty_ev.set (EVENT_READ); 4391 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; 4392 return;
4296 } 4393 }
4394
4395 memmove (v_buffer, v_buffer + written, v_buflen);
4297 } 4396 }
4397 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4398 pty_ev.set (EVENT_READ);
4298} 4399}
4299 4400
4300/*----------------------- end-of-file (C source) -----------------------*/ 4401/*----------------------- end-of-file (C source) -----------------------*/
4301 4402

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines