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.223 by root, Sun Jan 1 05:28:28 2006 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#ifdef KEYSYM_RESOURCE
54# include "keyboard.h"
55#endif
56
57#include <csignal>
58
59#define HAVE_SCHED_YIELD 1 //D//TODO//FIXME
60#if HAVE_SCHED_YIELD
53#include <wchar.h> 61# include <sched.h>
62#endif
54 63
55/*----------------------------------------------------------------------*/ 64/*----------------------------------------------------------------------*/
56 65
57#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 66#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
58 67
113 XK_Escape, 0x238b, 122 XK_Escape, 0x238b,
114 XK_Undo, 0x238c, 123 XK_Undo, 0x238c,
115 XK_Print, 0x2399, 124 XK_Print, 0x2399,
116 125
117 XK_space, 0x2423, 126 XK_space, 0x2423,
127
128#ifdef XK_KP_Begin
129 XK_KP_Prior, 0x21de,
130 XK_KP_Next, 0x21df,
131 XK_KP_Begin, 0x2320,
132 XK_KP_Insert, 0x2380,
133 XK_KP_Delete, 0x2326,
118 XK_KP_Space, 0x2422, 134 XK_KP_Space, 0x2422,
135#endif
119 0, 136 0,
120}; 137};
121 138
122void 139void
123rxvt_term::iso14755_54 (int x, int y) 140rxvt_term::iso14755_54 (int x, int y)
124{ 141{
125 x = Pixel2Col (x); 142 x = Pixel2Col (x);
126 y = Pixel2Row (y); 143 y = Pixel2Row (y);
127 144
128 if (x < 0 || x >= TermWin.ncol 145 if (!IN_RANGE_EXC (x, 0, ncol)
129 || y < 0 || y >= TermWin.nrow) 146 || !IN_RANGE_EXC (y, 0, nrow))
130 return; 147 return;
131 148
132 for (;;) 149 for (;;)
133 { 150 {
134 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x]; 151 const line_t &l = ROW(y - view_start);
152
153 text_t t = l.t[x];
135 154
136 if (t != NOCHAR || !x) 155 if (t != NOCHAR || !x)
137 { 156 {
138 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x]); 157 iso14755_51 (l.t[x], l.r[x], x, y);
139 iso14755buf = ISO_14755_54; 158 iso14755buf = ISO_14755_54;
140 break; 159 break;
141 } 160 }
142 161
143 x--; 162 x--;
144 } 163 }
145
146} 164}
147#endif
148 165
149#if ENABLE_OVERLAY
150void 166void
151rxvt_term::iso14755_51 (wchar_t ch) 167rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
152{ 168{
169 rxvt_fontset *fs = FONTSET (r);
170 rxvt_font *f = (*fs)[fs->find_font (ch)];
153 wchar_t *chr, *alloc; 171 wchar_t *chr, *alloc, ch2, *fname;
154 int len; 172 int len;
155 173
174 fname = rxvt_utf8towcs (f->name);
175
156#if ENABLE_COMBINING 176# if ENABLE_COMBINING
157 if (IS_COMPOSE (ch)) 177 if (IS_COMPOSE (ch))
158 { 178 {
159 len = rxvt_composite.expand (ch, 0); 179 len = rxvt_composite.expand (ch, 0);
160 alloc = chr = new wchar_t[len]; 180 alloc = chr = new wchar_t[len];
161 rxvt_composite.expand (ch, chr); 181 rxvt_composite.expand (ch, chr);
162 } 182 }
163 else 183 else
164#endif 184# endif
165 { 185 {
186 ch2 = ch;
187
166 alloc = 0; 188 alloc = 0;
167 chr = &ch; 189 chr = &ch2;
168 len = 1; 190 len = 1;
169 } 191 }
170 192
193 char attr[80]; // plenty
194
195 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
196 (int)r,
197 fgcolor_of (r), bgcolor_of (r),
198 r & RS_Bold ? " bold" : "",
199 r & RS_Italic ? " italic" : "",
200 r & RS_Blink ? " blink" : "",
201 r & RS_RVid ? " rvid" : "",
202 r & RS_Uline ? " uline" : "",
203 r & RS_Careful ? " careful" : "");
204
205 int width = wcswidth (fname, wcslen (fname));
206
207 max_it (width, 8+5); // for char + hey
208 max_it (width, strlen (attr));
209
210 if (y >= 0)
211 {
212 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
213 x = 0;
214 }
215
171 scr_overlay_new (0, -1, 8 + 5, len); 216 scr_overlay_new (x, y, width, len + 2);
217
218 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
172 219
173 for (int y = 0; y < len; y++) 220 for (int y = 0; y < len; y++)
174 { 221 {
175 char buf[9]; 222 char buf[9];
176 223
177 ch = *chr++; 224 ch = *chr++;
178 225
179 sprintf (buf, "%8x", ch); 226 sprintf (buf, "%8x", ch);
180 scr_overlay_set (0, y, buf); 227 scr_overlay_set (0, y, buf);
181 scr_overlay_set (9, y, '='); 228 scr_overlay_set (9, y, '=');
182#if !UNICODE3 229# if !UNICODE3
183 if (ch >= 0x10000) 230 if (ch >= 0x10000)
184 ch = 0xfffd; 231 ch = 0xfffd;
185#endif 232# endif
186 scr_overlay_set (11, y, ch); 233 scr_overlay_set (11, y, ch, r);
187 scr_overlay_set (12, y, NOCHAR); 234 scr_overlay_set (12, y, NOCHAR, r);
188 } 235 }
189 236
237 scr_overlay_set (0, len , attr);
238 scr_overlay_set (0, len + 1, fname);
239
240 free (fname);
241
190#if ENABLE_COMBINING 242# if ENABLE_COMBINING
191 if (alloc) 243 if (alloc)
192 delete [] alloc; 244 delete [] alloc;
193#endif 245# endif
194} 246}
195#endif 247#endif
196 248
197void 249void
198rxvt_term::commit_iso14755 () 250rxvt_term::commit_iso14755 ()
261 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 313 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
262 * escape sequence to toggle the Keypad. 314 * escape sequence to toggle the Keypad.
263 * 315 *
264 * Always permit `shift' to override the current setting 316 * Always permit `shift' to override the current setting
265 */ 317 */
266 shft = (ev.state & ShiftMask); 318 shft = ev.state & ShiftMask;
267 ctrl = (ev.state & ControlMask); 319 ctrl = ev.state & ControlMask;
268 meta = (ev.state & ModMetaMask); 320 meta = ev.state & ModMetaMask;
269 321
270 if (numlock_state || (ev.state & ModNumLockMask)) 322 if (numlock_state || (ev.state & ModNumLockMask))
271 { 323 {
272 numlock_state = (ev.state & ModNumLockMask); 324 numlock_state = (ev.state & ModNumLockMask);
273 PrivMode ((!numlock_state), PrivMode_aplKP); 325 PrivMode ((!numlock_state), PrivMode_aplKP);
293 345
294 // the XOpenIM manpage lies about hardcoding the locale 346 // the XOpenIM manpage lies about hardcoding the locale
295 // at the point of XOpenIM, so temporarily switch locales 347 // at the point of XOpenIM, so temporarily switch locales
296 if (rs[Rs_imLocale]) 348 if (rs[Rs_imLocale])
297 SET_LOCALE (rs[Rs_imLocale]); 349 SET_LOCALE (rs[Rs_imLocale]);
350
298 // assume wchar_t == unicode or better 351 // assume wchar_t == unicode or better
299 len = XwcLookupString (Input_Context, &ev, wkbuf, 352 len = XwcLookupString (Input_Context, &ev, wkbuf,
300 KBUFSZ, &keysym, &status_return); 353 KBUFSZ, &keysym, &status_return);
354
301 if (rs[Rs_imLocale]) 355 if (rs[Rs_imLocale])
302 SET_LOCALE (locale); 356 SET_LOCALE (locale);
303 357
304 if (status_return == XLookupChars 358 if (status_return == XLookupChars
305 || status_return == XLookupBoth) 359 || status_return == XLookupBoth)
332 valid_keysym = keysym != NoSymbol; 386 valid_keysym = keysym != NoSymbol;
333 } 387 }
334 388
335 if (valid_keysym) 389 if (valid_keysym)
336 { 390 {
391#ifdef KEYSYM_RESOURCE
392 if (keyboard->dispatch (this, keysym, ev.state))
393 return;
394#endif
395
337 if (TermWin.saveLines) 396 if (saveLines)
338 { 397 {
339#ifdef UNSHIFTED_SCROLLKEYS 398#ifdef UNSHIFTED_SCROLLKEYS
340 if (!ctrl && !meta) 399 if (!ctrl && !meta)
341#else 400#else
342 if (IS_SCROLL_MOD) 401 if (IS_SCROLL_MOD)
343#endif 402#endif
344 { 403 {
345 int lnsppg; 404 int lnsppg;
346 405
347#ifdef PAGING_CONTEXT_LINES 406#ifdef PAGING_CONTEXT_LINES
348 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; 407 lnsppg = nrow - PAGING_CONTEXT_LINES;
349#else 408#else
350 lnsppg = TermWin.nrow * 4 / 5; 409 lnsppg = nrow * 4 / 5;
351#endif 410#endif
352 if (keysym == XK_Prior) 411 if (keysym == XK_Prior)
353 { 412 {
354 scr_page (UP, lnsppg); 413 scr_page (UP, lnsppg);
355 return; 414 return;
406 { 465 {
407 /* normal XTerm key bindings */ 466 /* normal XTerm key bindings */
408 case XK_Insert: /* Shift+Insert = paste mouse selection */ 467 case XK_Insert: /* Shift+Insert = paste mouse selection */
409 selection_request (ev.time, 0, 0); 468 selection_request (ev.time, 0, 0);
410 return; 469 return;
411#if TODO // TODO 470#if TODO
412 /* rxvt extras */ 471 /* rxvt extras */
413 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 472 case XK_KP_Add: /* Shift+KP_Add = bigger font */
414 change_font (FONT_UP); 473 change_font (FONT_UP);
415 return; 474 return;
416 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 475 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
475 } 534 }
476#endif 535#endif
477 536
478 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 537 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
479 { 538 {
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 { 539 {
506 newlen = 1; 540 newlen = 1;
507 switch (keysym) 541 switch (keysym)
508 { 542 {
509#ifndef NO_BACKSPACE_KEY 543#ifndef NO_BACKSPACE_KEY
517 else 551 else
518 strcpy (kbuf, key_backspace); 552 strcpy (kbuf, key_backspace);
519 break; 553 break;
520#endif 554#endif
521#ifndef NO_DELETE_KEY 555#ifndef NO_DELETE_KEY
556# ifdef XK_KP_Prior
557 case XK_KP_Delete:
558 /* allow shift to override */
559 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
560 {
561 strcpy (kbuf, "\033On");
562 break;
563 }
564 /* FALLTHROUGH */
565# endif
522 case XK_Delete: 566 case XK_Delete:
523 strcpy (kbuf, key_delete); 567 strcpy (kbuf, key_delete);
524 break; 568 break;
525#endif 569#endif
526 case XK_Tab: 570 case XK_Tab:
629#ifdef XK_KP_Begin 673#ifdef XK_KP_Begin
630 case XK_KP_Begin: 674 case XK_KP_Begin:
631 strcpy (kbuf, "\033Ou"); 675 strcpy (kbuf, "\033Ou");
632 break; 676 break;
633 677
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 678#endif
642 case XK_KP_F1: /* "\033OP" */ 679 case XK_KP_F1: /* "\033OP" */
643 case XK_KP_F2: /* "\033OQ" */ 680 case XK_KP_F2: /* "\033OQ" */
644 case XK_KP_F3: /* "\033OR" */ 681 case XK_KP_F3: /* "\033OR" */
645 case XK_KP_F4: /* "\033OS" */ 682 case XK_KP_F4: /* "\033OS" */
677 break; 714 break;
678 715
679 case XK_Find: 716 case XK_Find:
680 strcpy (kbuf, "\033[1~"); 717 strcpy (kbuf, "\033[1~");
681 break; 718 break;
719
720#ifdef XK_KP_End
721 case XK_KP_Insert:
722 /* allow shift to override */
723 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
724 {
725 strcpy (kbuf, "\033Op");
726 break;
727 }
728 /* FALLTHROUGH */
729#endif
682 case XK_Insert: 730 case XK_Insert:
683 strcpy (kbuf, "\033[2~"); 731 strcpy (kbuf, "\033[2~");
684 break; 732 break;
685#ifdef DXK_Remove /* support for DEC remove like key */ 733#ifdef DXK_Remove /* support for DEC remove like key */
686 case DXK_Remove: 734 case DXK_Remove:
776#undef FKEY 824#undef FKEY
777 default: 825 default:
778 newlen = 0; 826 newlen = 0;
779 break; 827 break;
780 } 828 }
829
781 if (newlen) 830 if (newlen)
782 len = strlen (kbuf); 831 len = strlen (kbuf);
783 } 832 }
784 833
785 /* 834 /*
794 else if (ctrl && keysym == XK_minus) 843 else if (ctrl && keysym == XK_minus)
795 { 844 {
796 len = 1; 845 len = 1;
797 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 846 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
798 } 847 }
848 else if (keysym == XK_ISO_Left_Tab)
849 {
850 strcpy (kbuf, "\033[Z");
851 len = 3;
852 }
799 else 853 else
800 { 854 {
801#ifdef META8_OPTION 855#ifdef META8_OPTION
802 /* set 8-bit on */ 856 /* set 8-bit on */
803 if (meta && (meta_char == 0x80)) 857 if (meta && (meta_char == 0x80))
815 } 869 }
816 870
817 if (len <= 0) 871 if (len <= 0)
818 return; /* not mapped */ 872 return; /* not mapped */
819 873
820 if (options & Opt_scrollTtyKeypress) 874 if (OPTION (Opt_scrollTtyKeypress))
821 if (TermWin.view_start) 875 if (view_start)
822 { 876 {
823 TermWin.view_start = 0; 877 view_start = 0;
824 want_refresh = 1; 878 want_refresh = 1;
825 } 879 }
826 880
827 /* 881 /*
828 * these modifications only affect the static keybuffer 882 * these modifications only affect the static keybuffer
861#endif /* DEBUG_CMD */ 915#endif /* DEBUG_CMD */
862 tt_write (kbuf, (unsigned int)len); 916 tt_write (kbuf, (unsigned int)len);
863} 917}
864/*}}} */ 918/*}}} */
865 919
866#if (MENUBAR_MAX) 920#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
867/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 921/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
868/* attempt to `write' count to the input buffer */ 922/* attempt to `write' count to the input buffer */
869unsigned int 923unsigned int
870rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 924rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
871{ 925{
894 948
895 cmd_parse (); 949 cmd_parse ();
896 950
897 return 0; 951 return 0;
898} 952}
899#endif /* MENUBAR_MAX */ 953#endif
900 954
901void 955void
902rxvt_term::flush () 956rxvt_term::flush ()
903{ 957{
958 flush_ev.stop ();
959
904#ifdef TRANSPARENT 960#ifdef TRANSPARENT
905 if (want_full_refresh) 961 if (want_full_refresh)
906 { 962 {
907 want_full_refresh = 0; 963 want_full_refresh = 0;
908 scr_clear (); 964 scr_clear ();
918 IMSendSpot (); 974 IMSendSpot ();
919#endif 975#endif
920 } 976 }
921 977
922 display->flush (); 978 display->flush ();
923
924 flush_ev.stop ();
925} 979}
926 980
927void 981void
928rxvt_term::check_cb (check_watcher &w) 982rxvt_term::check_cb (check_watcher &w)
929{ 983{
1005{ 1059{
1006 if (mouse_slip_wheel_speed == 0 1060 if (mouse_slip_wheel_speed == 0
1007 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1061 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1008 : scr_page (UP, mouse_slip_wheel_speed)) 1062 : scr_page (UP, mouse_slip_wheel_speed))
1009 { 1063 {
1064 if (view_start == nsaved ||
1065 view_start == 0)
1066 mouse_slip_wheel_speed = 0;
1067
1010 refresh_type |= SMOOTH_REFRESH; 1068 refresh_type |= SMOOTH_REFRESH;
1011 want_refresh = 1; 1069 want_refresh = 1;
1012 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1070 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1013 } 1071 }
1014} 1072}
1027 1085
1028 memmove (cmdbuf_base, cmdbuf_ptr, n); 1086 memmove (cmdbuf_base, cmdbuf_ptr, n);
1029 cmdbuf_ptr = cmdbuf_base; 1087 cmdbuf_ptr = cmdbuf_base;
1030 cmdbuf_endp = cmdbuf_ptr + n; 1088 cmdbuf_endp = cmdbuf_ptr + n;
1031 1089
1032 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1090 ssize_t r = read (pty.pty, cmdbuf_endp, CBUFSIZ - n);
1033 1091
1034 if (n > 0) 1092 if (r > 0)
1035 { 1093 {
1036 cmdbuf_endp += n; 1094 cmdbuf_endp += r;
1037 return true; 1095 return true;
1038 } 1096 }
1039 else if (n < 0 && errno != EAGAIN) 1097 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1098 {
1099#if HAVE_SCHED_YIELD
1100 sched_yield ();
1101#endif
1102 }
1103 else
1104 {
1105 pty_ev.stop ();
1106
1107 if (!OPTION (Opt_hold))
1040 destroy (); 1108 destroy ();
1109 }
1041 1110
1042 return false; 1111 return false;
1043} 1112}
1044 1113
1045void 1114void
1046rxvt_term::pty_cb (io_watcher &w, short revents) 1115rxvt_term::pty_cb (io_watcher &w, short revents)
1047{ 1116{
1048 SET_R (this); 1117 SET_R (this);
1049 SET_LOCALE (locale); 1118 SET_LOCALE (locale);
1050 1119
1051 if (revents & EVENT_WRITE)
1052 tt_write (0, 0);
1053 else if (revents & EVENT_READ) 1120 if (revents & EVENT_READ)
1054 // loop, but don't allow a single term to monopolize us 1121 // loop, but don't allow a single term to monopolize us
1055 while (pty_fill ()) 1122 while (pty_fill ())
1056 if (cmd_parse ()) 1123 if (cmd_parse ())
1057 break; 1124 break;
1125
1126 if (revents & EVENT_WRITE)
1127 pty_write ();
1058} 1128}
1059 1129
1060void 1130void
1061rxvt_term::pointer_unblank () 1131rxvt_term::pointer_unblank ()
1062{ 1132{
1063 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1133 XDefineCursor (display->display, vt, TermWin_cursor);
1064 recolour_cursor (); 1134 recolour_cursor ();
1065 1135
1066#ifdef POINTER_BLANK 1136#ifdef POINTER_BLANK
1067 hidden_pointer = 0; 1137 hidden_pointer = 0;
1068 1138
1069 if (options & Opt_pointerBlank) 1139 if (OPTION (Opt_pointerBlank))
1070 pointer_ev.start (NOW + pointerBlankDelay); 1140 pointer_ev.start (NOW + pointerBlankDelay);
1071#endif 1141#endif
1072} 1142}
1073 1143
1074#ifdef POINTER_BLANK 1144#ifdef POINTER_BLANK
1075void 1145void
1076rxvt_term::pointer_blank () 1146rxvt_term::pointer_blank ()
1077{ 1147{
1078 if (! (options & Opt_pointerBlank)) 1148 if (! OPTION (Opt_pointerBlank))
1079 return; 1149 return;
1080 1150
1081 XDefineCursor (display->display, TermWin.vt, blank_cursor); 1151 XDefineCursor (display->display, vt, display->blank_cursor);
1082 XFlush (display->display); 1152 XFlush (display->display);
1083 1153
1084 hidden_pointer = 1; 1154 hidden_pointer = 1;
1085} 1155}
1086 1156
1137 + ((MEvent.state & ModMetaMask) ? 8 : 0) 1207 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1138 + ((MEvent.state & ControlMask) ? 16 : 0); 1208 + ((MEvent.state & ControlMask) ? 16 : 0);
1139#ifdef MOUSE_REPORT_DOUBLECLICK 1209#ifdef MOUSE_REPORT_DOUBLECLICK
1140 key_state += ((MEvent.clicks > 1) ? 32 : 0); 1210 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1141#endif 1211#endif
1142
1143 } 1212 }
1144 1213
1145#ifdef DEBUG_MOUSEREPORT 1214#if DEBUG_MOUSEREPORT
1146 fprintf (stderr, "Mouse ["); 1215 fprintf (stderr, "Mouse [");
1147 if (key_state & 16) 1216 if (key_state & 16)
1148 fputc ('C', stderr); 1217 fputc ('C', stderr);
1149 if (key_state & 4) 1218 if (key_state & 4)
1150 fputc ('S', stderr); 1219 fputc ('S', stderr);
1154 fputc ('2', stderr); 1223 fputc ('2', stderr);
1155 fprintf (stderr, "]: <%d>, %d/%d\n", 1224 fprintf (stderr, "]: <%d>, %d/%d\n",
1156 button_number, 1225 button_number,
1157 x + 1, 1226 x + 1,
1158 y + 1); 1227 y + 1);
1159#else 1228#endif
1229
1160 tt_printf ("\033[M%c%c%c", 1230 tt_printf ("\033[M%c%c%c",
1161 (32 + button_number + key_state), 1231 (32 + button_number + key_state),
1162 (32 + x + 1), 1232 (32 + x + 1),
1163 (32 + y + 1)); 1233 (32 + y + 1));
1164#endif
1165} 1234}
1166 1235
1167#ifdef USING_W11LIB 1236#ifdef USING_W11LIB
1168void 1237void
1169rxvt_W11_process_x_event (XEvent *ev) 1238rxvt_W11_process_x_event (XEvent *ev)
1176 1245
1177/*{{{ process an X event */ 1246/*{{{ process an X event */
1178void 1247void
1179rxvt_term::x_cb (XEvent &ev) 1248rxvt_term::x_cb (XEvent &ev)
1180{ 1249{
1250 dDisp;
1251
1181 SET_R (this); 1252 SET_R (this);
1182 SET_LOCALE (locale); 1253 SET_LOCALE (locale);
1183 1254
1184#if defined(CURSOR_BLINK) 1255#if defined(CURSOR_BLINK)
1185 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1256 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress)
1186 { 1257 {
1187 if (hidden_cursor) 1258 if (hidden_cursor)
1188 { 1259 {
1189 hidden_cursor = 0; 1260 hidden_cursor = 0;
1190 want_refresh = 1; 1261 want_refresh = 1;
1193 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1264 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1194 } 1265 }
1195#endif 1266#endif
1196 1267
1197#if defined(POINTER_BLANK) 1268#if defined(POINTER_BLANK)
1198 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0) 1269 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0)
1199 { 1270 {
1200 if (ev.type == MotionNotify 1271 if (ev.type == MotionNotify
1201 || ev.type == ButtonPress 1272 || ev.type == ButtonPress
1202 || ev.type == ButtonRelease) 1273 || ev.type == ButtonRelease)
1203 if (hidden_pointer) 1274 if (hidden_pointer)
1206 if (ev.type == KeyPress && hidden_pointer == 0) 1277 if (ev.type == KeyPress && hidden_pointer == 0)
1207 pointer_blank (); 1278 pointer_blank ();
1208 } 1279 }
1209#endif 1280#endif
1210 1281
1211#ifdef USE_XIM
1212 if (XFilterEvent (&ev, None))
1213 return;
1214#endif
1215
1216 Window unused_root, unused_child; 1282 Window unused_root, unused_child;
1217 int unused_root_x, unused_root_y; 1283 int unused_root_x, unused_root_y;
1218 unsigned int unused_mask; 1284 unsigned int unused_mask;
1219 1285
1220 switch (ev.type) 1286 switch (ev.type)
1221 { 1287 {
1222 case KeyPress: 1288 case KeyPress:
1223#if ISO_14755 1289#if ISO_14755
1227 1293
1228 break; 1294 break;
1229 1295
1230 case KeyRelease: 1296 case KeyRelease:
1231 { 1297 {
1232#if (defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)) || defined (ENABLE_FRILLS) 1298#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1233 KeySym ks; 1299 KeySym ks;
1234 1300
1235 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ 1301 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1236#endif 1302#endif
1237 1303
1306 button_release (ev.xbutton); 1372 button_release (ev.xbutton);
1307 break; 1373 break;
1308 1374
1309 case ClientMessage: 1375 case ClientMessage:
1310 if (ev.xclient.format == 32 1376 if (ev.xclient.format == 32
1377 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1378 {
1311 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) 1379 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1312 destroy (); 1380 destroy ();
1381#if ENABLE_EWMH
1382 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1383 XSendEvent (disp, ev.xclient.window = display->root,
1384 False, SubstructureRedirectMask | SubstructureNotifyMask,
1385 &ev);
1386#endif
1387 }
1388#if ENABLE_XEMBED
1389 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1390 {
1391 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1392 focus_in ();
1393 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1394 focus_out ();
1395 }
1396#endif
1313#ifdef OFFIX_DND 1397#ifdef OFFIX_DND
1314 /* OffiX Dnd (drag 'n' drop) protocol */ 1398 /* OffiX Dnd (drag 'n' drop) protocol */
1315 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] 1399 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1316 && (ev.xclient.data.l[0] == DndFile 1400 && (ev.xclient.data.l[0] == DndFile
1317 || ev.xclient.data.l[0] == DndDir 1401 || ev.xclient.data.l[0] == DndDir
1318 || ev.xclient.data.l[0] == DndLink)) 1402 || ev.xclient.data.l[0] == DndLink))
1319 { 1403 {
1320 /* Get Dnd data */ 1404 /* Get Dnd data */
1321 Atom ActualType; 1405 Atom ActualType;
1322 int ActualFormat; 1406 int ActualFormat;
1323 unsigned char *data; 1407 unsigned char *data;
1324 unsigned long Size, RemainingBytes; 1408 unsigned long Size, RemainingBytes;
1325 1409
1326 XGetWindowProperty (display->display, display->root, 1410 XGetWindowProperty (disp, display->root,
1327 xa[XA_DNDSELECTION], 1411 xa[XA_DNDSELECTION],
1328 0L, 1000000L, 1412 0L, 1000000L,
1329 False, AnyPropertyType, 1413 False, AnyPropertyType,
1330 &ActualType, &ActualFormat, 1414 &ActualType, &ActualFormat,
1331 &Size, &RemainingBytes, 1415 &Size, &RemainingBytes,
1332 &data); 1416 &data);
1333 XChangeProperty (display->display, display->root, 1417 set_string_property (XA_CUT_BUFFER0, data);
1334 XA_CUT_BUFFER0, XA_STRING,
1335 8, PropModeReplace,
1336 data, strlen (data));
1337 XFree (data); 1418 XFree (data);
1338 selection_paste (display->root, XA_CUT_BUFFER0, True); 1419 selection_paste (display->root, XA_CUT_BUFFER0, true);
1339 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1420 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1340 } 1421 }
1341#endif /* OFFIX_DND */ 1422#endif /* OFFIX_DND */
1342 break; 1423 break;
1343 1424
1344 case MappingNotify: 1425 case MappingNotify:
1369 break; 1450 break;
1370 } 1451 }
1371 break; 1452 break;
1372 1453
1373 case FocusIn: 1454 case FocusIn:
1374 if (!TermWin.focus) 1455 focus_in ();
1456 break;
1457
1458 case FocusOut:
1459 focus_out ();
1460 break;
1461
1462 case ConfigureNotify:
1463 if (ev.xconfigure.window == parent[0])
1375 { 1464 {
1376 TermWin.focus = 1; 1465 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev))
1377 want_refresh = 1; 1466 ;
1378#ifdef USE_XIM 1467
1379 if (Input_Context != NULL) 1468 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1380 { 1469 {
1381 IMSetStatusPosition (); 1470 seen_resize = 1;
1382 XSetICFocus (Input_Context); 1471 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1383 } 1472 }
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 1473
1445#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1474#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1446 if (options & Opt_transparent) 1475 if (OPTION (Opt_transparent))
1447 {
1448 check_our_parents (); 1476 check_our_parents ();
1449 if (am_transparent)
1450 want_refresh = want_full_refresh = 1;
1451 }
1452#endif 1477#endif
1453 } 1478 }
1454 break; 1479 break;
1455 1480
1456 case PropertyNotify: 1481 case PropertyNotify:
1464 selection_clear (); 1489 selection_clear ();
1465 break; 1490 break;
1466 1491
1467 case SelectionNotify: 1492 case SelectionNotify:
1468 if (selection_wait == Sel_normal) 1493 if (selection_wait == Sel_normal)
1469 selection_paste (ev.xselection.requestor, 1494 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1470 ev.xselection.property, True);
1471 break; 1495 break;
1472 1496
1473 case SelectionRequest: 1497 case SelectionRequest:
1474 selection_send (ev.xselectionrequest); 1498 selection_send (ev.xselectionrequest);
1475 break; 1499 break;
1476 1500
1477 case UnmapNotify: 1501 case UnmapNotify:
1478 TermWin.mapped = 0; 1502 mapped = 0;
1479#ifdef TEXT_BLINK 1503#ifdef TEXT_BLINK
1480 text_blink_ev.stop (); 1504 text_blink_ev.stop ();
1481#endif 1505#endif
1482 break; 1506 break;
1483 1507
1484 case MapNotify: 1508 case MapNotify:
1485 TermWin.mapped = 1; 1509 mapped = 1;
1486#ifdef TEXT_BLINK 1510#ifdef TEXT_BLINK
1487 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 1511 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1488#endif 1512#endif
1489 break; 1513 break;
1490 1514
1494 break; 1518 break;
1495#endif /* TRANSPARENT */ 1519#endif /* TRANSPARENT */
1496 1520
1497 case GraphicsExpose: 1521 case GraphicsExpose:
1498 case Expose: 1522 case Expose:
1499 if (ev.xany.window == TermWin.vt) 1523 if (ev.xany.window == vt)
1500 { 1524 {
1501 do 1525 do
1502 scr_expose (ev.xexpose.x, ev.xexpose.y, 1526 scr_expose (ev.xexpose.x, ev.xexpose.y,
1503 ev.xexpose.width, ev.xexpose.height, False); 1527 ev.xexpose.width, ev.xexpose.height, False);
1504 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); 1528 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev));
1505 1529
1506 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1530 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1507 1531
1508 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) 1532 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1509 scr_expose (ev.xexpose.x, ev.xexpose.y, 1533 scr_expose (ev.xexpose.x, ev.xexpose.y,
1510 ev.xexpose.width, ev.xexpose.height, False); 1534 ev.xexpose.width, ev.xexpose.height, False);
1511 1535
1512 scr_refresh (refresh_type); 1536 scr_refresh (refresh_type);
1513 } 1537 }
1514 else 1538 else
1515 { 1539 {
1516 XEvent unused_event; 1540 XEvent unused_event;
1517 1541
1518 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) 1542 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1519 ; 1543 ;
1520 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) 1544 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1521 ; 1545 ;
1522 1546
1523 if (isScrollbarWindow (ev.xany.window)) 1547 if (isScrollbarWindow (ev.xany.window))
1524 { 1548 {
1525 scrollBar.setIdle (); 1549 scrollBar.setIdle ();
1529 if (menubar_visible () && isMenuBarWindow (ev.xany.window)) 1553 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1530 menubar_expose (); 1554 menubar_expose ();
1531#endif 1555#endif
1532 1556
1533#ifdef TRANSPARENT 1557#ifdef TRANSPARENT
1534 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1558 if (am_transparent && ev.xany.window == parent[0])
1535 XClearWindow (display->display, ev.xany.window); 1559 XClearWindow (disp, ev.xany.window);
1536#endif 1560#endif
1537 } 1561 }
1538 break; 1562 break;
1539 1563
1540 case MotionNotify: 1564 case MotionNotify:
1547 { 1571 {
1548 menubar_control (ev.xbutton); 1572 menubar_control (ev.xbutton);
1549 break; 1573 break;
1550 } 1574 }
1551#endif 1575#endif
1552 if ((priv_modes & PrivMode_mouse_report) && ! (bypass_keystate)) 1576 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1553 break; 1577 break;
1554 1578
1555 if (ev.xany.window == TermWin.vt) 1579 if (ev.xany.window == vt)
1556 { 1580 {
1557 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1581 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1558 { 1582 {
1559 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) 1583 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1560 ; 1584 ;
1561 1585
1562 XQueryPointer (display->display, TermWin.vt, 1586 XQueryPointer (disp, vt,
1563 &unused_root, &unused_child, 1587 &unused_root, &unused_child,
1564 &unused_root_x, &unused_root_y, 1588 &unused_root_x, &unused_root_y,
1565 & (ev.xbutton.x), & (ev.xbutton.y), 1589 &ev.xbutton.x, &ev.xbutton.y,
1566 &unused_mask); 1590 &ev.xbutton.state);
1567#ifdef MOUSE_THRESHOLD 1591#ifdef MOUSE_THRESHOLD
1568 /* deal with a `jumpy' mouse */ 1592 /* deal with a `jumpy' mouse */
1569 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) 1593 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1570 { 1594 {
1571#endif 1595#endif
1576 iso14755_54 (ev.xbutton.x, ev.xbutton.y); 1600 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1577 break; 1601 break;
1578 } 1602 }
1579#endif 1603#endif
1580 selection_extend (ev.xbutton.x, ev.xbutton.y, 1604 selection_extend (ev.xbutton.x, ev.xbutton.y,
1581 (ev.xbutton.state & Button3Mask) ? 2 : 0); 1605 ev.xbutton.state & Button3Mask ? 2 : 0);
1606
1582#ifdef SELECTION_SCROLLING 1607#ifdef SELECTION_SCROLLING
1583 if (ev.xbutton.y < TermWin.int_bwidth 1608 if (ev.xbutton.y < int_bwidth
1584 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1609 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1585 { 1610 {
1586 int dist; 1611 int dist;
1587 1612
1588 /* don't clobber the current delay if we are 1613 /* don't clobber the current delay if we are
1589 * already in the middle of scrolling. 1614 * already in the middle of scrolling.
1597 selection_save_x = ev.xbutton.x; 1622 selection_save_x = ev.xbutton.x;
1598 selection_save_y = ev.xbutton.y; 1623 selection_save_y = ev.xbutton.y;
1599 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1624 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1600 1625
1601 /* calc number of lines to scroll */ 1626 /* calc number of lines to scroll */
1602 if (ev.xbutton.y<TermWin.int_bwidth) 1627 if (ev.xbutton.y < int_bwidth)
1603 { 1628 {
1604 scroll_selection_dir = UP; 1629 scroll_selection_dir = UP;
1605 dist = TermWin.int_bwidth - ev.xbutton.y; 1630 dist = int_bwidth - ev.xbutton.y;
1606 } 1631 }
1607 else 1632 else
1608 { 1633 {
1609 scroll_selection_dir = DN; 1634 scroll_selection_dir = DN;
1610 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1635 dist = ev.xbutton.y - (int_bwidth + height);
1611 } 1636 }
1612 1637
1613 scroll_selection_lines = Pixel2Height (dist) 1638 scroll_selection_lines = Pixel2Height (dist)
1614 / SELECTION_SCROLL_LINE_SPEEDUP 1639 / SELECTION_SCROLL_LINE_SPEEDUP
1615 + 1; 1640 + 1;
1616 MIN_IT (scroll_selection_lines, 1641 min_it (scroll_selection_lines,
1617 SELECTION_SCROLL_MAX_LINES); 1642 SELECTION_SCROLL_MAX_LINES);
1618 } 1643 }
1619 else 1644 else
1620 { 1645 {
1621 /* we are within the text window, so we 1646 /* we are within the text window, so we
1630#endif 1655#endif
1631 } 1656 }
1632 } 1657 }
1633 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1658 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1634 { 1659 {
1635 while (XCheckTypedWindowEvent (display->display, scrollBar.win, 1660 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1636 MotionNotify, &ev)) ; 1661 MotionNotify, &ev))
1662 ;
1663
1637 XQueryPointer (display->display, scrollBar.win, 1664 XQueryPointer (disp, scrollBar.win,
1638 &unused_root, &unused_child, 1665 &unused_root, &unused_child,
1639 &unused_root_x, &unused_root_y, 1666 &unused_root_x, &unused_root_y,
1640 & (ev.xbutton.x), & (ev.xbutton.y), 1667 &ev.xbutton.x, &ev.xbutton.y,
1641 &unused_mask); 1668 &unused_mask);
1642 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1669 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1643 scrollbar_size ()); 1670 scrollbar_size ());
1644 scr_refresh (refresh_type); 1671 scr_refresh (refresh_type);
1645 refresh_limit = 0; 1672 refresh_limit = 0;
1647 } 1674 }
1648 break; 1675 break;
1649 } 1676 }
1650} 1677}
1651 1678
1679void
1680rxvt_term::focus_in ()
1681{
1682 if (!focus)
1683 {
1684 focus = 1;
1685 want_refresh = 1;
1686#if USE_XIM
1687 if (Input_Context != NULL)
1688 {
1689 IMSetStatusPosition ();
1690 XSetICFocus (Input_Context);
1691 }
1692#endif
1693#if CURSOR_BLINK
1694 if (OPTION (Opt_cursorBlink))
1695 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1696#endif
1697#if OFF_FOCUS_FADING
1698 if (rs[Rs_fade])
1699 {
1700 pix_colors = pix_colors_focused;
1701 scr_recolour ();
1702 }
1703#endif
1704 }
1705}
1706
1707void
1708rxvt_term::focus_out ()
1709{
1710 if (focus)
1711 {
1712 focus = 0;
1713 want_refresh = 1;
1714
1715#if ENABLE_FRILLS || ISO_14755
1716 iso14755buf = 0;
1717#endif
1718#if ENABLE_OVERLAY
1719 scr_overlay_off ();
1720#endif
1721#if USE_XIM
1722 if (Input_Context != NULL)
1723 XUnsetICFocus (Input_Context);
1724#endif
1725#if CURSOR_BLINK
1726 if (OPTION (Opt_cursorBlink))
1727 cursor_blink_ev.stop ();
1728 hidden_cursor = 0;
1729#endif
1730#if OFF_FOCUS_FADING
1731 if (rs[Rs_fade])
1732 {
1733 pix_colors = pix_colors_unfocused;
1734 scr_recolour ();
1735 }
1736#endif
1737 }
1738}
1739
1652#if TRANSPARENT 1740#if TRANSPARENT
1653void 1741void
1654rxvt_term::rootwin_cb (XEvent &ev) 1742rxvt_term::rootwin_cb (XEvent &ev)
1655{ 1743{
1656 SET_R (this); 1744 SET_R (this);
1661 case PropertyNotify: 1749 case PropertyNotify:
1662 /* 1750 /*
1663 * if user used some Esetroot compatible prog to set the root bg, 1751 * 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. 1752 * use the property to determine the pixmap. We use it later on.
1665 */ 1753 */
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]) 1754 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1755 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1670 return; 1756 return;
1671 1757
1672 /* FALLTHROUGH */ 1758 /* FALLTHROUGH */
1673 case ReparentNotify: 1759 case ReparentNotify:
1674 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1760 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1675 want_refresh = want_full_refresh = 1; 1761 want_refresh = want_full_refresh = 1;
1676 break; 1762 break;
1677 } 1763 }
1678} 1764}
1679#endif 1765#endif
1688 reportmode = !! (priv_modes & PrivMode_mouse_report); 1774 reportmode = !! (priv_modes & PrivMode_mouse_report);
1689 1775
1690 /* 1776 /*
1691 * VT window processing of button press 1777 * VT window processing of button press
1692 */ 1778 */
1693 if (ev.window == TermWin.vt) 1779 if (ev.window == vt)
1694 { 1780 {
1695#if ISO_14755 1781#if ISO_14755
1696 // 5.4 1782 // 5.4
1697 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1783 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1698 { 1784 {
1700 return; 1786 return;
1701 } 1787 }
1702#endif 1788#endif
1703 1789
1704 clickintime = ev.time - MEvent.time < MULTICLICK_TIME; 1790 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1791
1705 if (reportmode) 1792 if (reportmode)
1706 { 1793 {
1707 /* mouse report from vt window */ 1794 /* mouse report from vt window */
1708 /* save the xbutton state (for ButtonRelease) */ 1795 /* save the xbutton state (for ButtonRelease) */
1709 MEvent.state = ev.state; 1796 MEvent.state = ev.state;
1738 } 1825 }
1739 else 1826 else
1740 { 1827 {
1741 if (ev.button != MEvent.button) 1828 if (ev.button != MEvent.button)
1742 MEvent.clicks = 0; 1829 MEvent.clicks = 0;
1830
1743 switch (ev.button) 1831 switch (ev.button)
1744 { 1832 {
1745 case Button1: 1833 case Button1:
1834 /* allow meta + click to select rectangular areas */
1835 /* should be done in screen.C */
1836#if ENABLE_FRILLS
1837 selection.rect = !!(ev.state & ModMetaMask);
1838#else
1839 selection.rect = false;
1840#endif
1841
1746 /* allow shift+left click to extend selection */ 1842 /* allow shift+left click to extend selection */
1747 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1843 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1748 { 1844 {
1749 if (MEvent.button == Button1 && clickintime) 1845 if (MEvent.button == Button1 && clickintime)
1750 selection_rotate (ev.x, ev.y); 1846 selection_rotate (ev.x, ev.y);
1893 case Button3: 1989 case Button3:
1894 if (scrollBar.style != R_SB_XTERM) 1990 if (scrollBar.style != R_SB_XTERM)
1895 { 1991 {
1896 if (scrollbar_above_slider (ev.y)) 1992 if (scrollbar_above_slider (ev.y))
1897# ifdef RXVT_SCROLL_FULL 1993# ifdef RXVT_SCROLL_FULL
1898 scr_page (UP, TermWin.nrow - 1); 1994 scr_page (UP, nrow - 1);
1899# else 1995# else
1900 scr_page (UP, TermWin.nrow / 4); 1996 scr_page (UP, nrow / 4);
1901# endif 1997# endif
1902 else if (scrollbar_below_slider (ev.y)) 1998 else if (scrollbar_below_slider (ev.y))
1903# ifdef RXVT_SCROLL_FULL 1999# ifdef RXVT_SCROLL_FULL
1904 scr_page (DN, TermWin.nrow - 1); 2000 scr_page (DN, nrow - 1);
1905# else 2001# else
1906 scr_page (DN, TermWin.nrow / 4); 2002 scr_page (DN, nrow / 4);
1907# endif 2003# endif
1908 else 2004 else
1909 scrollBar.setMotion (); 2005 scrollBar.setMotion ();
1910 } 2006 }
1911 else 2007 else
1912 { 2008 {
1913 scr_page ((ev.button == Button1 ? DN : UP), 2009 scr_page ((ev.button == Button1 ? DN : UP),
1914 (TermWin.nrow 2010 (nrow
1915 * scrollbar_position (ev.y) 2011 * scrollbar_position (ev.y)
1916 / scrollbar_size ())); 2012 / scrollbar_size ()));
1917 } 2013 }
1918 2014
1919 break; 2015 break;
1951#ifdef SELECTION_SCROLLING 2047#ifdef SELECTION_SCROLLING
1952 if (sel_scroll_ev.active) 2048 if (sel_scroll_ev.active)
1953 sel_scroll_ev.stop(); 2049 sel_scroll_ev.stop();
1954#endif 2050#endif
1955 2051
1956 if (ev.window == TermWin.vt) 2052 if (ev.window == vt)
1957 { 2053 {
1958#if ISO_14755 2054#if ISO_14755
1959 // 5.4 2055 // 5.4
1960 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2056 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1961 return; 2057 return;
2011 2107
2012 v = ev.button == Button4 ? UP : DN; 2108 v = ev.button == Button4 ? UP : DN;
2013 2109
2014 if (ev.state & ShiftMask) 2110 if (ev.state & ShiftMask)
2015 i = 1; 2111 i = 1;
2016 else if (options & Opt_mouseWheelScrollPage) 2112 else if (OPTION (Opt_mouseWheelScrollPage))
2017 i = TermWin.nrow - 1; 2113 i = nrow - 1;
2018 else 2114 else
2019 i = 5; 2115 i = 5;
2020 2116
2021# ifdef MOUSE_SLIP_WHEELING 2117# ifdef MOUSE_SLIP_WHEELING
2022 if (ev.state & ControlMask) 2118 if (ev.state & ControlMask)
2023 { 2119 {
2024 mouse_slip_wheel_speed += v ? -1 : 1; 2120 mouse_slip_wheel_speed += v ? -1 : 1;
2025 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2121 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; 2122 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2027 2123
2028 if (slip_wheel_ev.at < NOW) 2124 if (slip_wheel_ev.at < NOW)
2029 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2125 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2030 2126
2031 slip_wheel_ev.start (); 2127 slip_wheel_ev.start ();
2072 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2168 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2073 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2169 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2074 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2170 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2075 int i; 2171 int i;
2076 2172
2077 Visual* visual = display->visual; 2173 Visual *visual = display->visual;
2078 2174
2079 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2175 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2080 2176
2081 /* for convenience */ 2177 /* for convenience */
2082 mask_r = visual->red_mask; 2178 mask_r = visual->red_mask;
2303 Atom atype; 2399 Atom atype;
2304 unsigned char *prop = NULL; 2400 unsigned char *prop = NULL;
2305 Window root, oldp, *list; 2401 Window root, oldp, *list;
2306 Pixmap rootpixmap = None; 2402 Pixmap rootpixmap = None;
2307 XWindowAttributes wattr, wrootattr; 2403 XWindowAttributes wattr, wrootattr;
2404 dDisp;
2308 2405
2309 pchanged = 0; 2406 pchanged = 0;
2310 2407
2311 if (!(options & Opt_transparent)) 2408 if (!OPTION (Opt_transparent))
2312 return pchanged; /* Don't try any more */ 2409 return pchanged; /* Don't try any more */
2313 2410
2314 XGetWindowAttributes (display->display, display->root, &wrootattr); 2411 XGetWindowAttributes (disp, display->root, &wrootattr);
2315 rootdepth = wrootattr.depth; 2412 rootdepth = wrootattr.depth;
2316 2413
2317 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2414 XGetWindowAttributes (disp, parent[0], &wattr);
2318 2415
2319 if (rootdepth != wattr.depth) 2416 if (rootdepth != wattr.depth)
2320 { 2417 {
2321 if (am_transparent) 2418 if (am_transparent)
2322 { 2419 {
2323 pchanged = 1; 2420 pchanged = 1;
2324 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2421 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2325 am_transparent = am_pixmap_trans = 0; 2422 am_transparent = am_pixmap_trans = 0;
2326 } 2423 }
2327 2424
2328 return pchanged; /* Don't try any more */ 2425 return pchanged; /* Don't try any more */
2329 } 2426 }
2330 2427
2331 /* Get all X ops out of the queue so that our information is up-to-date. */ 2428 /* Get all X ops out of the queue so that our information is up-to-date. */
2332 XSync (display->display, False); 2429 XSync (disp, False);
2333 2430
2334 /* 2431 /*
2335 * Make the frame window set by the window manager have 2432 * Make the frame window set by the window manager have
2336 * the root background. Some window managers put multiple nested frame 2433 * the root background. Some window managers put multiple nested frame
2337 * windows for each client, so we have to take care about that. 2434 * windows for each client, so we have to take care about that.
2338 */ 2435 */
2339 i = (xa[XA_XROOTPMAPID] 2436 i = (xa[XA_XROOTPMAP_ID]
2340 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2437 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2341 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2438 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2342 &nitems, &bytes_after, &prop) == Success); 2439 &nitems, &bytes_after, &prop) == Success);
2343 2440
2344 if (!i || prop == NULL) 2441 if (!i || prop == NULL)
2345 i = (xa[XA_XSETROOTID] 2442 i = (xa[XA_ESETROOT_PMAP_ID]
2346 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2443 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2347 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2444 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2348 &nitems, &bytes_after, &prop) == Success); 2445 &nitems, &bytes_after, &prop) == Success);
2349 2446
2350 if (!i || prop == NULL 2447 if (!i || prop == NULL
2351#if TINTING 2448#if TINTING
2370 Window cr; 2467 Window cr;
2371 XImage *image; 2468 XImage *image;
2372 GC gc; 2469 GC gc;
2373 XGCValues gcvalue; 2470 XGCValues gcvalue;
2374 2471
2375 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2472 XTranslateCoordinates (disp, parent[0], display->root,
2376 0, 0, &sx, &sy, &cr); 2473 0, 0, &sx, &sy, &cr);
2377 nw = (unsigned int)szHint.width; 2474 nw = (unsigned int)szHint.width;
2378 nh = (unsigned int)szHint.height; 2475 nh = (unsigned int)szHint.height;
2379 nx = ny = 0; 2476 nx = ny = 0;
2380 2477
2390 nh += sy; 2487 nh += sy;
2391 ny = -sy; 2488 ny = -sy;
2392 sy = 0; 2489 sy = 0;
2393 } 2490 }
2394 2491
2395 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2492 min_it (nw, (unsigned int) (wrootattr.width - sx));
2396 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2493 min_it (nh, (unsigned int) (wrootattr.height - sy));
2494
2495 XSync (disp, False);
2397 allowedxerror = -1; 2496 allowedxerror = -1;
2398 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2497 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2399 2498
2400 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2499 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2401 /* XXX: may need a delay here? */ 2500 /* XXX: may need a delay here? */
2402 allowedxerror = 0; 2501 allowedxerror = 0;
2403 2502
2404 if (image == NULL) 2503 if (image == NULL)
2405 { 2504 {
2406 if (am_transparent && am_pixmap_trans) 2505 if (am_transparent && am_pixmap_trans)
2407 { 2506 {
2408 pchanged = 1; 2507 pchanged = 1;
2409 if (TermWin.pixmap != None) 2508 if (pixmap != None)
2410 { 2509 {
2411 XFreePixmap (display->display, TermWin.pixmap); 2510 XFreePixmap (disp, pixmap);
2412 TermWin.pixmap = None; 2511 pixmap = None;
2413 } 2512 }
2414 } 2513 }
2415 2514
2416 am_pixmap_trans = 0; 2515 am_pixmap_trans = 0;
2417 } 2516 }
2418 else 2517 else
2419 { 2518 {
2420 if (TermWin.pixmap != None) 2519 if (pixmap != None)
2421 XFreePixmap (display->display, TermWin.pixmap); 2520 XFreePixmap (disp, pixmap);
2422 2521
2423#if TINTING 2522#if TINTING
2424 if (ISSET_PIXCOLOR (Color_tint)) 2523 if (ISSET_PIXCOLOR (Color_tint))
2425 { 2524 {
2426 unsigned short rm, gm, bm; 2525 unsigned short rm, gm, bm;
2430 2529
2431 ShadeXImage (display, image, shade, rm, gm, bm); 2530 ShadeXImage (display, image, shade, rm, gm, bm);
2432 } 2531 }
2433#endif 2532#endif
2434 2533
2435 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2534 pixmap = XCreatePixmap (disp, vt,
2436 szHint.width, szHint.height, image->depth); 2535 szHint.width, szHint.height, image->depth);
2437 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2536 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2438 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2537 XPutImage (disp, pixmap, gc, image, 0, 0,
2439 nx, ny, image->width, image->height); 2538 nx, ny, image->width, image->height);
2440 XFreeGC (display->display, gc); 2539 XFreeGC (disp, gc);
2441 XDestroyImage (image); 2540 XDestroyImage (image);
2442 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); 2541 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2443 XClearWindow (display->display, TermWin.parent[0]); 2542 XClearWindow (disp, parent[0]);
2444 2543
2445 if (!am_transparent || !am_pixmap_trans) 2544 if (!am_transparent || !am_pixmap_trans)
2446 pchanged = 1; 2545 pchanged = 1;
2447 2546
2448 am_transparent = am_pixmap_trans = 1; 2547 am_transparent = am_pixmap_trans = 1;
2449 } 2548 }
2450 } 2549 }
2451 2550
2452 if (!am_pixmap_trans) 2551 if (am_pixmap_trans)
2552 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2553 else
2453 { 2554 {
2454 unsigned int n; 2555 unsigned int n;
2455 /* 2556 /*
2456 * InheritPixmap transparency 2557 * InheritPixmap transparency
2457 */ 2558 */
2458 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2559 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2459 { 2560 {
2460 oldp = TermWin.parent[i]; 2561 oldp = parent[i];
2461 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2562 XQueryTree (disp, parent[i - 1], &root,
2462 &TermWin.parent[i], &list, &n); 2563 &parent[i], &list, &n);
2463 XFree (list); 2564 XFree (list);
2464 2565
2465 if (TermWin.parent[i] == display->root) 2566 if (parent[i] == display->root)
2466 { 2567 {
2467 if (oldp != None) 2568 if (oldp != None)
2468 pchanged = 1; 2569 pchanged = 1;
2469 2570
2470 break; 2571 break;
2471 } 2572 }
2472 2573
2473 if (oldp != TermWin.parent[i]) 2574 if (oldp != parent[i])
2474 pchanged = 1; 2575 pchanged = 1;
2475 } 2576 }
2476 2577
2477 n = 0; 2578 n = 0;
2478 2579
2479 if (pchanged) 2580 if (pchanged)
2480 { 2581 {
2481 for (; n < (unsigned int)i; n++) 2582 for (; n < (unsigned int)i; n++)
2482 { 2583 {
2483 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 2584 XGetWindowAttributes (disp, parent[n], &wattr);
2484 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2585 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2485 { 2586 {
2486 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2587 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2487 break; 2588 break;
2488 } 2589 }
2489 } 2590 }
2490 } 2591 }
2491 2592
2492 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) 2593 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2493 { 2594 {
2494 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); 2595 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2495 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2596 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2496 am_transparent = 0; 2597 am_transparent = 0;
2497 /* XXX: also turn off Opt_transparent? */ 2598 /* XXX: also turn off Opt_transparent? */
2498 } 2599 }
2499 else 2600 else
2500 { 2601 {
2503 * needed for fvwm2.2.2 (and before?) */ 2604 * needed for fvwm2.2.2 (and before?) */
2504 sleep (1); 2605 sleep (1);
2505#endif 2606#endif
2506 for (n = 0; n < (unsigned int)i; n++) 2607 for (n = 0; n < (unsigned int)i; n++)
2507 { 2608 {
2508 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); 2609 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2509 XClearWindow (display->display, TermWin.parent[n]); 2610 XClearWindow (disp, parent[n]);
2510 } 2611 }
2511 2612
2512 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); 2613 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2513 am_transparent = 1; 2614 am_transparent = 1;
2514 } 2615 }
2515 2616
2516 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2617 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2517 TermWin.parent[i] = None; 2618 parent[i] = None;
2518 } 2619 }
2519 2620
2520 // this is experimental
2521 if (scrollBar.win) 2621 if (scrollBar.win)
2522 { 2622 {
2523 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2623 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2524 XClearWindow (display->display, scrollBar.win);
2525 scrollBar.setIdle (); 2624 scrollBar.setIdle ();
2526 scrollbar_show (0); 2625 scrollbar_show (0);
2626 }
2627
2628 if (am_transparent)
2629 {
2630 want_refresh = want_full_refresh = 1;
2631 if (am_pixmap_trans)
2632 flush ();
2527 } 2633 }
2528 2634
2529 return pchanged; 2635 return pchanged;
2530} 2636}
2531#endif 2637#endif
2557 seen_input = 1; 2663 seen_input = 1;
2558 // many badly-written programs (e.g. jed) contain a race condition: 2664 // many badly-written programs (e.g. jed) contain a race condition:
2559 // they first read the screensize and then install a SIGWINCH handler. 2665 // they first read the screensize and then install a SIGWINCH handler.
2560 // some window managers resize the window early, and these programs 2666 // some window managers resize the window early, and these programs
2561 // then sometimes get the size wrong. 2667 // then sometimes get the size wrong.
2668 // unfortunately other programs are even more buggy and dislike
2669 // being sent SIGWINCH, so only do it when we were in fact being
2670 // resized.
2671 if (seen_resize && cmd_pid)
2562 kill (-cmd_pid, SIGWINCH); 2672 kill (-cmd_pid, SIGWINCH);
2563 } 2673 }
2564 2674
2565 /* Read a text string from the input buffer */ 2675 /* Read a text string from the input buffer */
2566 unicode_t buf[UBUFSIZ]; 2676 unicode_t buf[UBUFSIZ];
2567 bool refreshnow = false; 2677 bool refreshnow = false;
2568 int nlines = 0; 2678 int nlines = 0;
2569 unicode_t *str = buf; 2679 unicode_t *str = buf;
2680 unicode_t *eol = str + min (ncol, UBUFSIZ);
2570 2681
2571 for (;;) 2682 for (;;)
2572 { 2683 {
2573 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2684 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2574 break; 2685 break;
2575 2686
2576 *str++ = ch; 2687 *str++ = ch;
2577 2688
2578 if (ch == C0_LF) 2689 if (ch == C0_LF || str >= eol)
2579 { 2690 {
2691 if (ch == C0_LF)
2580 nlines++; 2692 nlines++;
2693
2581 refresh_count++; 2694 refresh_count++;
2582 2695
2583 if (!(options & Opt_jumpScroll) 2696 if (!OPTION (Opt_jumpScroll)
2584 || (refresh_count >= refresh_limit * (TermWin.nrow - 1))) 2697 || (refresh_count >= refresh_limit * (nrow - 1)))
2585 { 2698 {
2586 refreshnow = true; 2699 refreshnow = true;
2587 ch = NOCHAR; 2700 ch = NOCHAR;
2588 break; 2701 break;
2589 } 2702 }
2590 2703
2591 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2704 // scr_add_lines only works for nlines <= nrow - 1.
2592 if (nlines >= TermWin.nrow - 1) 2705 if (nlines >= nrow - 1)
2593 { 2706 {
2594 scr_add_lines (buf, nlines, str - buf); 2707 scr_add_lines (buf, nlines, str - buf);
2595 nlines = 0; 2708 nlines = 0;
2596 str = buf; 2709 str = buf;
2710 eol = str + min (ncol, UBUFSIZ);
2597 } 2711 }
2598 }
2599 2712
2600 if (str >= buf + UBUFSIZ) 2713 if (str >= eol)
2601 { 2714 {
2715 if (eol >= buf + UBUFSIZ)
2716 {
2602 ch = NOCHAR; 2717 ch = NOCHAR;
2603 break; 2718 break;
2719 }
2720 else
2721 eol = min (eol + ncol, buf + UBUFSIZ);
2722 }
2723
2604 } 2724 }
2605 2725
2606 seq_begin = cmdbuf_ptr; 2726 seq_begin = cmdbuf_ptr;
2607 ch = next_char (); 2727 ch = next_char ();
2608 } 2728 }
2615 * the number of pages between refreshes is refresh_limit, which 2735 * the number of pages between refreshes is refresh_limit, which
2616 * is incremented here because we must be doing flat-out scrolling. 2736 * is incremented here because we must be doing flat-out scrolling.
2617 */ 2737 */
2618 if (refreshnow) 2738 if (refreshnow)
2619 { 2739 {
2620 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 2740 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2621 refresh_limit++; 2741 refresh_limit++;
2622 else 2742 else
2623 { 2743 {
2624 flag = true; 2744 flag = true;
2625 scr_refresh (refresh_type); 2745 scr_refresh (refresh_type);
2679 if (len == (size_t)-1) 2799 if (len == (size_t)-1)
2680 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2800 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2681 2801
2682 // assume wchar == unicode 2802 // assume wchar == unicode
2683 cmdbuf_ptr += len; 2803 cmdbuf_ptr += len;
2684 return wc; 2804 return wc & UNICODE_MASK;
2685 } 2805 }
2686 2806
2687 return NOCHAR; 2807 return NOCHAR;
2688} 2808}
2689 2809
3152 { 3272 {
3153 switch (priv) 3273 switch (priv)
3154 { 3274 {
3155 case '>': 3275 case '>':
3156 if (ch == CSI_DA) /* secondary device attributes */ 3276 if (ch == CSI_DA) /* secondary device attributes */
3157 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING); 3277 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]);
3158 break; 3278 break;
3159 case '?': 3279 case '?':
3160 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3280 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3161 process_terminal_mode (ch, priv, nargs, arg); 3281 process_terminal_mode (ch, priv, nargs, arg);
3162 break; 3282 break;
3267 3387
3268 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 3388 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3269 arg[0] = -arg[0]; 3389 arg[0] = -arg[0];
3270 /* FALLTHROUGH */ 3390 /* FALLTHROUGH */
3271 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3391 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3272 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 3392 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3273 break; 3393 break;
3274 3394
3275 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3395 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3276 tt_write ((const unsigned char *)VT100_ANS, 3396 tt_write ((const unsigned char *)VT100_ANS,
3277 (unsigned int) (sizeof (VT100_ANS) - 1)); 3397 (unsigned int) (sizeof (VT100_ANS) - 1));
3289 break; 3409 break;
3290 case 6: /* CPR requested */ 3410 case 6: /* CPR requested */
3291 scr_report_position (); 3411 scr_report_position ();
3292 break; 3412 break;
3293 case 7: /* unofficial extension */ 3413 case 7: /* unofficial extension */
3294 if (options & Opt_insecure) 3414 if (OPTION (Opt_insecure))
3295 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3415 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3296 break; 3416 break;
3297 case 8: /* unofficial extension */ 3417 case 8: /* unofficial extension */
3298 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3418 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3299 break; 3419 break;
3391rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3511rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3392{ 3512{
3393 int x, y; 3513 int x, y;
3394 XWindowAttributes wattr; 3514 XWindowAttributes wattr;
3395 Window wdummy; 3515 Window wdummy;
3516 dDisp;
3396 3517
3397 if (nargs == 0) 3518 if (nargs == 0)
3398 return; 3519 return;
3399 3520
3400 switch (args[0]) 3521 switch (args[0])
3401 { 3522 {
3402 /* 3523 /*
3403 * commands 3524 * commands
3404 */ 3525 */
3405 case 1: /* deiconify window */ 3526 case 1: /* deiconify window */
3406 XMapWindow (display->display, TermWin.parent[0]); 3527 XMapWindow (disp, parent[0]);
3407 break; 3528 break;
3408 case 2: /* iconify window */ 3529 case 2: /* iconify window */
3409 XIconifyWindow (display->display, TermWin.parent[0], 3530 XIconifyWindow (disp, parent[0], display->screen);
3410 DefaultScreen (display->display));
3411 break; 3531 break;
3412 case 3: /* set position (pixels) */ 3532 case 3: /* set position (pixels) */
3413 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); 3533 XMoveWindow (disp, parent[0], args[1], args[2]);
3414 break; 3534 break;
3415 case 4: /* set size (pixels) */ 3535 case 4: /* set size (pixels) */
3416 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3536 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3417 break; 3537 break;
3418 case 5: /* raise window */ 3538 case 5: /* raise window */
3419 XRaiseWindow (display->display, TermWin.parent[0]); 3539 XRaiseWindow (disp, parent[0]);
3420 break; 3540 break;
3421 case 6: /* lower window */ 3541 case 6: /* lower window */
3422 XLowerWindow (display->display, TermWin.parent[0]); 3542 XLowerWindow (disp, parent[0]);
3423 break; 3543 break;
3424 case 7: /* refresh window */ 3544 case 7: /* refresh window */
3425 scr_touch (true); 3545 scr_touch (true);
3426 break; 3546 break;
3427 case 8: /* set size (chars) */ 3547 case 8: /* set size (chars) */
3428 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3548 set_widthheight ((unsigned int) (args[2] * fwidth),
3429 (unsigned int) (args[1] * TermWin.fheight)); 3549 (unsigned int) (args[1] * fheight));
3430 break; 3550 break;
3431 3551
3432 //case 9: NYI, TODO, restore maximized window or maximize window 3552 //case 9: NYI, TODO, restore maximized window or maximize window
3433 default: 3553 default:
3434 if (args[0] >= 24) /* set height (chars) */ 3554 if (args[0] >= 24) /* set height (chars) */
3435 set_widthheight ((unsigned int)TermWin.width, 3555 set_widthheight ((unsigned int)width,
3436 (unsigned int) (args[1] * TermWin.fheight)); 3556 (unsigned int) (args[1] * fheight));
3437 break; 3557 break;
3438 3558
3439 3559
3440 /* 3560 /*
3441 * reports - some output format copied from XTerm 3561 * reports - some output format copied from XTerm
3442 */ 3562 */
3443 case 11: /* report window state */ 3563 case 11: /* report window state */
3444 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3564 XGetWindowAttributes (disp, parent[0], &wattr);
3445 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3565 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3446 break; 3566 break;
3447 case 13: /* report window position */ 3567 case 13: /* report window position */
3448 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3568 XGetWindowAttributes (disp, parent[0], &wattr);
3449 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3569 XTranslateCoordinates (disp, parent[0], wattr.root,
3450 -wattr.border_width, -wattr.border_width, 3570 -wattr.border_width, -wattr.border_width,
3451 &x, &y, &wdummy); 3571 &x, &y, &wdummy);
3452 tt_printf ("\033[3;%d;%dt", x, y); 3572 tt_printf ("\033[3;%d;%dt", x, y);
3453 break; 3573 break;
3454 case 14: /* report window size (pixels) */ 3574 case 14: /* report window size (pixels) */
3455 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3575 XGetWindowAttributes (disp, parent[0], &wattr);
3456 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3576 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3457 break; 3577 break;
3458 case 18: /* report text area size (chars) */ 3578 case 18: /* report text area size (chars) */
3459 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3579 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3460 break; 3580 break;
3461 case 19: /* report window size (chars) */ 3581 case 19: /* report window size (chars) */
3462 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3582 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3463 break; 3583 break;
3464 case 20: /* report icon label */ 3584 case 20: /* report icon label */
3465 { 3585 {
3466 char *s; 3586 char *s;
3467 XGetIconName (display->display, TermWin.parent[0], &s); 3587 XGetIconName (disp, parent[0], &s);
3468 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3588 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3469 XFree (s); 3589 XFree (s);
3470 } 3590 }
3471 break; 3591 break;
3472 case 21: /* report window title */ 3592 case 21: /* report window title */
3473 { 3593 {
3474 char *s; 3594 char *s;
3475 XFetchName (display->display, TermWin.parent[0], &s); 3595 XFetchName (disp, parent[0], &s);
3476 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3596 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3477 XFree (s); 3597 XFree (s);
3478 } 3598 }
3479 break; 3599 break;
3480 } 3600 }
3481} 3601}
3487 * ends_how is terminator used. returned input must be free()'d 3607 * ends_how is terminator used. returned input must be free()'d
3488 */ 3608 */
3489unsigned char * 3609unsigned char *
3490rxvt_term::get_to_st (unicode_t &ends_how) 3610rxvt_term::get_to_st (unicode_t &ends_how)
3491{ 3611{
3492 unicode_t prev = 0, ch; 3612 unicode_t ch;
3613 bool seen_esc = false;
3493 unsigned int n = 0; 3614 unsigned int n = 0;
3494 unsigned char *s;
3495 unsigned char string[STRING_MAX]; 3615 wchar_t string[STRING_MAX];
3496 3616
3497 while ((ch = cmd_getc ()) != NOCHAR) 3617 while ((ch = cmd_getc ()) != NOCHAR)
3498 { 3618 {
3499 if (prev == C0_ESC) 3619 if (seen_esc)
3500 { 3620 {
3501 if (ch == 0x5c) /* 7bit ST */ 3621 if (ch == 0x5c) /* 7bit ST */
3502 break; 3622 break;
3503 else 3623 else
3504 return NULL; 3624 return NULL;
3505 } 3625 }
3626 else if (ch == C0_ESC)
3627 {
3628 seen_esc = true;
3629 continue;
3630 }
3506 else if (ch == C0_BEL || ch == CHAR_ST) 3631 else if (ch == C0_BEL || ch == CHAR_ST)
3507 break; 3632 break;
3508 else if (ch < 0x20) 3633 else if (ch < 0x20)
3509 return NULL; /* other control character - exit */ 3634 return NULL; /* other control character - exit */
3510 3635
3511 if (n >= sizeof (string) - 1) 3636 seen_esc = false;
3637
3638 if (n >= STRING_MAX - 1)
3512 // stop at some sane length 3639 // stop at some sane length
3513 return NULL; 3640 return NULL;
3514 3641
3515 if (ch == C0_SYN) 3642 if (ch == C0_SYN)
3516 {
3517 string[n++] = cmd_get8 (); 3643 string[n++] = cmd_get8 ();
3518 prev = 0;
3519 }
3520 else 3644 else
3521 string[n++] = prev = ch; 3645 string[n++] = ch;
3522 } 3646 }
3523 3647
3524 string[n++] = '\0'; 3648 string[n++] = '\0';
3525 3649
3526 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3527 return NULL;
3528
3529 ends_how = (ch == 0x5c ? C0_ESC : ch); 3650 ends_how = (ch == 0x5c ? C0_ESC : ch);
3530 strncpy (s, string, n); 3651
3531 return s; 3652 return (unsigned char *)rxvt_wcstombs (string);
3532} 3653}
3533 3654
3534/*----------------------------------------------------------------------*/ 3655/*----------------------------------------------------------------------*/
3535/* 3656/*
3536 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3657 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3590 set_window_color (color, str); 3711 set_window_color (color, str);
3591} 3712}
3592 3713
3593/* 3714/*
3594 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3715 * 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 */ 3716 */
3618void 3717void
3619rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3718rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3620{ 3719{
3621 int changed = 0; 3720 int changed = 0;
3622 int color; 3721 int color;
3623 char *buf, *name; 3722 char *buf, *name;
3624 bool query = str[0] == '?' && !str[1]; 3723 bool query = str[0] == '?' && !str[1];
3724 int saveop = op;
3725 dDisp;
3625 3726
3626 assert (str != NULL); 3727 assert (str != NULL);
3627 switch (op) 3728 switch (op)
3628 { 3729 {
3629 case XTerm_name: 3730 case XTerm_name:
3636 set_title (str); 3737 set_title (str);
3637 break; 3738 break;
3638 case XTerm_property: 3739 case XTerm_property:
3639 if (str[0] == '?') 3740 if (str[0] == '?')
3640 { 3741 {
3641 Atom prop = XInternAtom (display->display, str + 1, True); 3742 Atom prop = display->atom (str + 1);
3642 Atom actual_type; 3743 Atom actual_type;
3643 int actual_format; 3744 int actual_format;
3644 unsigned long nitems; 3745 unsigned long nitems;
3645 unsigned long bytes_after; 3746 unsigned long bytes_after;
3646 unsigned char *value = 0; 3747 unsigned char *value = 0;
3647 const char *str = ""; 3748 const char *str = "";
3648 3749
3649 if (prop 3750 if (prop
3650 && XGetWindowProperty (display->display, TermWin.parent[0], 3751 && XGetWindowProperty (disp, parent[0],
3651 prop, 0, 1<<16, 0, AnyPropertyType, 3752 prop, 0, 1<<16, 0, AnyPropertyType,
3652 &actual_type, &actual_format, 3753 &actual_type, &actual_format,
3653 &nitems, &bytes_after, &value) == Success 3754 &nitems, &bytes_after, &value) == Success
3654 && actual_type != None 3755 && actual_type != None
3655 && actual_format == 8) 3756 && actual_format == 8)
3664 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3765 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3665 3766
3666 if (eq) 3767 if (eq)
3667 { 3768 {
3668 *eq = 0; 3769 *eq = 0;
3669 XChangeProperty (display->display, TermWin.parent[0], 3770 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 } 3771 }
3674 else 3772 else
3675 XDeleteProperty (display->display, TermWin.parent[0], 3773 XDeleteProperty (disp, parent[0],
3676 display->atom (str)); 3774 display->atom (str));
3677 } 3775 }
3678 break; 3776 break;
3679 3777
3680 case XTerm_Color: 3778 case XTerm_Color:
3727 process_color_seq (XTerm_Color_UL, Color_UL, str, resp); 3825 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3728 break; 3826 break;
3729 case XTerm_Color_RV: 3827 case XTerm_Color_RV:
3730 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3828 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3731 break; 3829 break;
3830 case URxvt_Color_IT:
3831 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3832 break;
3833#endif
3834#if TRANSPARENT && TINTING
3835 case URxvt_Color_tint:
3836 process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3837 check_our_parents ();
3838 if (am_transparent)
3839 want_full_refresh = want_refresh = 1;
3840 break;
3732#endif 3841#endif
3733 3842
3734 case XTerm_Pixmap: 3843 case XTerm_Pixmap:
3735 if (*str != ';') 3844 if (*str != ';')
3736 { 3845 {
3744 { 3853 {
3745 str++; 3854 str++;
3746#if XPM_BACKGROUND 3855#if XPM_BACKGROUND
3747 changed += scale_pixmap (str); 3856 changed += scale_pixmap (str);
3748#endif 3857#endif
3749
3750 } 3858 }
3859
3751 if (changed) 3860 if (changed)
3752 { 3861 {
3753#ifdef XPM_BACKGROUND 3862#ifdef XPM_BACKGROUND
3754 resize_pixmap (); 3863 resize_pixmap ();
3755#endif 3864#endif
3766 3875
3767 case XTerm_logfile: 3876 case XTerm_logfile:
3768 // TODO, when secure mode? 3877 // TODO, when secure mode?
3769 break; 3878 break;
3770 3879
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 3880#ifdef MENUBAR
3806 case XTerm_Menu: 3881 case URxvt_Menu:
3807 if (options & Opt_insecure) 3882 if (OPTION (Opt_insecure))
3808 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3883 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3809 break; 3884 break;
3810#endif 3885#endif
3811#if 0 3886#if 0
3812 case XTerm_dumpscreen: /* no error notices */ 3887 case XTerm_dumpscreen: /* no error notices */
3816 { 3891 {
3817 scr_dump (fd); 3892 scr_dump (fd);
3818 close (fd); 3893 close (fd);
3819 } 3894 }
3820 } 3895 }
3896 break;
3897#endif
3898 case XTerm_font:
3899 op = URxvt_font;
3900 case URxvt_font:
3901#if ENABLE_STYLES
3902 case URxvt_boldFont:
3903 case URxvt_italicFont:
3904 case URxvt_boldItalicFont:
3905#endif
3906 if (query)
3907 tt_printf ("\33]%d;%-.250s%c", saveop,
3908 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3909 ? fontset[op - URxvt_font]->fontdesc : "",
3910 resp);
3911 else
3912 {
3913 const char *&res = rs[Rs_font + (op - URxvt_font)];
3914
3915 res = strdup (str);
3916 allocated.push_back ((void *)res);
3917 set_fonts ();
3918 }
3919 break;
3920
3921#if ENABLE_FRILLS
3922 case URxvt_locale:
3923 if (query)
3924 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp);
3925 else
3926 {
3927 set_locale (str);
3928 pty.set_utf8_mode (enc_utf8);
3929 init_xlocale ();
3930 }
3931 break;
3932
3933 case URxvt_view_up:
3934 case URxvt_view_down:
3935 int lines = atoi (str);
3936
3937 if (lines)
3938 scr_page (op == URxvt_view_up ? UP : DN, lines);
3939 else
3940 {
3941 scr_erase_savelines ();
3942 }
3943
3821 break; 3944 break;
3822#endif 3945#endif
3823 } 3946 }
3824} 3947}
3825/*----------------------------------------------------------------------*/ 3948/*----------------------------------------------------------------------*/
3934 } 4057 }
3935 4058
3936 /* extra handling for values with state unkept */ 4059 /* extra handling for values with state unkept */
3937 switch (arg[i]) 4060 switch (arg[i])
3938 { 4061 {
4062#if ENABLE_STYLES
4063 case 1021:
4064 if (mode)
4065 SET_OPTION (Opt_intensityStyles);
4066 else
4067 CLR_OPTION (Opt_intensityStyles);
4068
4069 want_refresh = 1;
4070 want_full_refresh = 1;
4071 break;
4072#endif
3939 case 1048: /* alternative cursor save */ 4073 case 1048: /* alternative cursor save */
4074 case 1049:
3940 if (options & Opt_secondaryScreen) 4075 if (OPTION (Opt_secondaryScreen))
3941 if (mode == 0) 4076 if (mode == 0)
3942 scr_cursor (RESTORE); 4077 scr_cursor (RESTORE);
3943 else if (mode == 1) 4078 else if (mode == 1)
3944 scr_cursor (SAVE); 4079 scr_cursor (SAVE);
3945 break; 4080 break;
3957 */ 4092 */
3958 PrivMode (1, PrivMode_vt52); 4093 PrivMode (1, PrivMode_vt52);
3959 break; 4094 break;
3960 case 3: /* 80/132 */ 4095 case 3: /* 80/132 */
3961 if (priv_modes & PrivMode_132OK) 4096 if (priv_modes & PrivMode_132OK)
3962 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 4097 set_widthheight (((state ? 132 : 80) * fwidth), height);
3963 break; 4098 break;
3964 case 4: /* smooth scrolling */ 4099 case 4: /* smooth scrolling */
3965 if (state) 4100 if (!state)
3966 options &= ~Opt_jumpScroll; 4101 SET_OPTION (Opt_jumpScroll);
3967 else 4102 else
3968 options |= Opt_jumpScroll; 4103 CLR_OPTION (Opt_jumpScroll);
3969 break; 4104 break;
3970 case 5: /* reverse video */ 4105 case 5: /* reverse video */
3971 scr_rvideo_mode (state); 4106 scr_rvideo_mode (state);
3972 break; 4107 break;
3973 case 6: /* relative/absolute origins */ 4108 case 6: /* relative/absolute origins */
4014#if 0 4149#if 0
4015 case 1001: 4150 case 1001:
4016 break; /* X11 mouse highlighting */ 4151 break; /* X11 mouse highlighting */
4017#endif 4152#endif
4018 case 1010: /* scroll to bottom on TTY output inhibit */ 4153 case 1010: /* scroll to bottom on TTY output inhibit */
4019 if (state) 4154 if (!state)
4020 options &= ~Opt_scrollTtyOutput; 4155 SET_OPTION (Opt_scrollTtyOutput);
4021 else 4156 else
4022 options |= Opt_scrollTtyOutput; 4157 CLR_OPTION (Opt_scrollTtyOutput);
4023 break; 4158 break;
4024 case 1011: /* scroll to bottom on key press */ 4159 case 1011: /* scroll to bottom on key press */
4025 if (state) 4160 if (state)
4026 options |= Opt_scrollTtyKeypress; 4161 SET_OPTION (Opt_scrollTtyKeypress);
4027 else 4162 else
4028 options &= ~Opt_scrollTtyKeypress; 4163 CLR_OPTION (Opt_scrollTtyKeypress);
4029 break; 4164 break;
4030 case 1047: /* secondary screen w/ clearing last */ 4165 case 1047: /* secondary screen w/ clearing last */
4031 if (options & Opt_secondaryScreen) 4166 if (OPTION (Opt_secondaryScreen))
4032 if (current_screen != PRIMARY) 4167 if (current_screen != PRIMARY)
4033 scr_erase_screen (2); 4168 scr_erase_screen (2);
4034 scr_change_screen (state); 4169 scr_change_screen (state);
4035 break; 4170 break;
4036 case 1049: /* secondary screen w/ clearing first */ 4171 case 1049: /* secondary screen w/ clearing first */
4037 scr_change_screen (state); 4172 scr_change_screen (state);
4038 if (options & Opt_secondaryScreen) 4173 if (OPTION (Opt_secondaryScreen))
4039 if (current_screen != PRIMARY) 4174 if (current_screen != PRIMARY)
4040 scr_erase_screen (2); 4175 scr_erase_screen (2);
4041 break; 4176 break;
4042 default: 4177 default:
4043 break; 4178 break;
4069 rendset = 0, rendstyle = ~RS_None; 4204 rendset = 0, rendstyle = ~RS_None;
4070 break; 4205 break;
4071 case 1: 4206 case 1:
4072 rendset = 1, rendstyle = RS_Bold; 4207 rendset = 1, rendstyle = RS_Bold;
4073 break; 4208 break;
4074 //case 2: // faint or second colour 4209 //case 2: // low intensity
4075 //case 3: // italic 4210 case 3:
4211 rendset = 1, rendstyle = RS_Italic;
4212 break;
4076 case 4: 4213 case 4:
4077 rendset = 1, rendstyle = RS_Uline; 4214 rendset = 1, rendstyle = RS_Uline;
4078 break; 4215 break;
4079 case 5: // slowly blinking 4216 case 5: // slowly blinking
4080 case 6: // rapidly blinking 4217 case 6: // rapidly blinking
4092 //case 11: // scoansi acs on, first alt font 4229 //case 11: // scoansi acs on, first alt font
4093 //case 12: // scoansi acs on, |0x80, second alt font 4230 //case 12: // scoansi acs on, |0x80, second alt font
4094 //... 4231 //...
4095 //case 19: // ninth alt font 4232 //case 19: // ninth alt font
4096 //case 20: // gothic 4233 //case 20: // gothic
4097 case 21: // disable bold, faint 4234 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4098 rendset = 0, rendstyle = RS_Bold; 4235 rendset = 0, rendstyle = RS_Bold;
4099 break; 4236 break;
4100 case 22: 4237 case 22: // normal intensity
4101 rendset = 0, rendstyle = RS_Bold; 4238 rendset = 0, rendstyle = RS_Bold;
4102 break; 4239 break;
4103 //case 23: disable italic 4240 case 23: // disable italic
4241 rendset = 0, rendstyle = RS_Italic;
4242 break;
4104 case 24: 4243 case 24:
4105 rendset = 0, rendstyle = RS_Uline; 4244 rendset = 0, rendstyle = RS_Uline;
4106 break; 4245 break;
4107 case 25: 4246 case 25:
4108 rendset = 0, rendstyle = RS_Blink; 4247 rendset = 0, rendstyle = RS_Blink;
4109 break; 4248 break;
4110 case 26: 4249 case 26: // variable spacing (iso 8613)
4111 rendset = 0, rendstyle = RS_Blink; 4250 rendset = 0, rendstyle = RS_Blink;
4112 break; 4251 break;
4113 case 27: 4252 case 27:
4114 rendset = 0, rendstyle = RS_RVid; 4253 rendset = 0, rendstyle = RS_RVid;
4115 break; 4254 break;
4133 case 35: 4272 case 35:
4134 case 36: 4273 case 36:
4135 case 37: 4274 case 37:
4136 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); 4275 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4137 break; 4276 break;
4138#ifdef TTY_256COLOR 4277 case 38: // set fg color, ISO 8613-6
4139 case 38:
4140 if (nargs > i + 2 && arg[i + 1] == 5) 4278 if (nargs > i + 2 && arg[i + 1] == 5)
4141 { 4279 {
4142 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); 4280 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4143 i += 2; 4281 i += 2;
4144 } 4282 }
4145 break; 4283 break;
4146#endif
4147 case 39: /* default fg */ 4284 case 39: /* default fg */
4148 scr_color (Color_fg, Color_fg); 4285 scr_color (Color_fg, Color_fg);
4149 break; 4286 break;
4150 4287
4151 case 40: 4288 case 40:
4156 case 45: 4293 case 45:
4157 case 46: 4294 case 46:
4158 case 47: 4295 case 47:
4159 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); 4296 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4160 break; 4297 break;
4161#ifdef TTY_256COLOR 4298 case 48: // set bg color, ISO 8613-6
4162 case 48:
4163 if (nargs > i + 2 && arg[i + 1] == 5) 4299 if (nargs > i + 2 && arg[i + 1] == 5)
4164 { 4300 {
4165 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); 4301 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4166 i += 2; 4302 i += 2;
4167 } 4303 }
4168 break; 4304 break;
4169#endif
4170 case 49: /* default bg */ 4305 case 49: /* default bg */
4171 scr_color (Color_bg, Color_bg); 4306 scr_color (Color_bg, Color_bg);
4172 break; 4307 break;
4308
4309 //case 50: // not variable spacing
4173 4310
4174#ifndef NO_BRIGHTCOLOR 4311#ifndef NO_BRIGHTCOLOR
4175 case 90: 4312 case 90:
4176 case 91: /* set bright fg color */ 4313 case 91: /* set bright fg color */
4177 case 92: 4314 case 92:
4178 case 93: 4315 case 93:
4179 case 94: 4316 case 94:
4180 case 95: 4317 case 95:
4181 case 96: 4318 case 96:
4182 case 97: 4319 case 97:
4183 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), 4320 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4184 Color_fg);
4185 break; 4321 break;
4186 case 100: 4322 case 100:
4187 case 101: /* set bright bg color */ 4323 case 101: /* set bright bg color */
4188 case 102: 4324 case 102:
4189 case 103: 4325 case 103:
4190 case 104: 4326 case 104:
4191 case 105: 4327 case 105:
4192 case 106: 4328 case 106:
4193 case 107: 4329 case 107:
4194 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), 4330 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4195 Color_bg);
4196 break; 4331 break;
4197#endif 4332#endif
4198
4199 } 4333 }
4200 } 4334 }
4201} 4335}
4202/*}}} */ 4336/*}}} */
4203 4337
4239 4373
4240/* ---------------------------------------------------------------------- */ 4374/* ---------------------------------------------------------------------- */
4241/* Write data to the pty as typed by the user, pasted with the mouse, 4375/* 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. 4376 * or generated by us in response to a query ESC sequence.
4243 */ 4377 */
4378const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4379
4244void 4380void
4245rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4381rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4246{ 4382{
4247 enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT 4383 if (v_buflen == 0)
4384 {
4385 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4248 4386
4249 if (len) 4387 if ((unsigned int)written == len)
4388 return;
4389
4390 data += written;
4391 len -= written;
4250 { 4392 }
4393
4394 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4395
4396 memcpy (v_buffer + v_buflen, data, len);
4397 v_buflen += len;
4398
4399 pty_ev.set (EVENT_READ | EVENT_WRITE);
4400}
4401
4402void rxvt_term::pty_write ()
4403{
4404 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4405
4406 if (written > 0)
4407 {
4408 v_buflen -= written;
4409
4251 if (v_buflen == 0) 4410 if (v_buflen == 0)
4252 { 4411 {
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); 4412 free (v_buffer);
4280 v_buffer = 0; 4413 v_buffer = 0;
4281 v_buflen = 0; 4414 v_buflen = 0;
4282 4415
4283 pty_ev.set (EVENT_READ); 4416 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; 4417 return;
4296 } 4418 }
4419
4420 memmove (v_buffer, v_buffer + written, v_buflen);
4297 } 4421 }
4422 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4423 pty_ev.set (EVENT_READ);
4298} 4424}
4299 4425
4300/*----------------------- end-of-file (C source) -----------------------*/ 4426/*----------------------- end-of-file (C source) -----------------------*/
4301 4427

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines