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.215 by root, Fri Dec 23 14:46:34 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
171 scr_overlay_new (0, -1, 8 + 5, len); 190 int width = wcswidth (fname, wcslen (fname));
191
192 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1);
193
194 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
172 195
173 for (int y = 0; y < len; y++) 196 for (int y = 0; y < len; y++)
174 { 197 {
175 char buf[9]; 198 char buf[9];
176 199
181 scr_overlay_set (9, y, '='); 204 scr_overlay_set (9, y, '=');
182#if !UNICODE3 205#if !UNICODE3
183 if (ch >= 0x10000) 206 if (ch >= 0x10000)
184 ch = 0xfffd; 207 ch = 0xfffd;
185#endif 208#endif
186 scr_overlay_set (11, y, ch); 209 scr_overlay_set (11, y, ch, r);
187 scr_overlay_set (12, y, NOCHAR); 210 scr_overlay_set (12, y, NOCHAR, r);
188 } 211 }
212
213 scr_overlay_set (0, len, fname);
214
215 free (fname);
189 216
190#if ENABLE_COMBINING 217#if ENABLE_COMBINING
191 if (alloc) 218 if (alloc)
192 delete [] alloc; 219 delete [] alloc;
193#endif 220#endif
261 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 288 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
262 * escape sequence to toggle the Keypad. 289 * escape sequence to toggle the Keypad.
263 * 290 *
264 * Always permit `shift' to override the current setting 291 * Always permit `shift' to override the current setting
265 */ 292 */
266 shft = (ev.state & ShiftMask); 293 shft = ev.state & ShiftMask;
267 ctrl = (ev.state & ControlMask); 294 ctrl = ev.state & ControlMask;
268 meta = (ev.state & ModMetaMask); 295 meta = ev.state & ModMetaMask;
269 296
270 if (numlock_state || (ev.state & ModNumLockMask)) 297 if (numlock_state || (ev.state & ModNumLockMask))
271 { 298 {
272 numlock_state = (ev.state & ModNumLockMask); 299 numlock_state = (ev.state & ModNumLockMask);
273 PrivMode ((!numlock_state), PrivMode_aplKP); 300 PrivMode ((!numlock_state), PrivMode_aplKP);
293 320
294 // the XOpenIM manpage lies about hardcoding the locale 321 // the XOpenIM manpage lies about hardcoding the locale
295 // at the point of XOpenIM, so temporarily switch locales 322 // at the point of XOpenIM, so temporarily switch locales
296 if (rs[Rs_imLocale]) 323 if (rs[Rs_imLocale])
297 SET_LOCALE (rs[Rs_imLocale]); 324 SET_LOCALE (rs[Rs_imLocale]);
325
298 // assume wchar_t == unicode or better 326 // assume wchar_t == unicode or better
299 len = XwcLookupString (Input_Context, &ev, wkbuf, 327 len = XwcLookupString (Input_Context, &ev, wkbuf,
300 KBUFSZ, &keysym, &status_return); 328 KBUFSZ, &keysym, &status_return);
329
301 if (rs[Rs_imLocale]) 330 if (rs[Rs_imLocale])
302 SET_LOCALE (locale); 331 SET_LOCALE (locale);
303 332
304 if (status_return == XLookupChars 333 if (status_return == XLookupChars
305 || status_return == XLookupBoth) 334 || status_return == XLookupBoth)
332 valid_keysym = keysym != NoSymbol; 361 valid_keysym = keysym != NoSymbol;
333 } 362 }
334 363
335 if (valid_keysym) 364 if (valid_keysym)
336 { 365 {
366#ifdef KEYSYM_RESOURCE
367 if (keyboard->dispatch (this, keysym, ev.state))
368 return;
369#endif
370
337 if (TermWin.saveLines) 371 if (saveLines)
338 { 372 {
339#ifdef UNSHIFTED_SCROLLKEYS 373#ifdef UNSHIFTED_SCROLLKEYS
340 if (!ctrl && !meta) 374 if (!ctrl && !meta)
341#else 375#else
342 if (IS_SCROLL_MOD) 376 if (IS_SCROLL_MOD)
343#endif 377#endif
344 { 378 {
345 int lnsppg; 379 int lnsppg;
346 380
347#ifdef PAGING_CONTEXT_LINES 381#ifdef PAGING_CONTEXT_LINES
348 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; 382 lnsppg = nrow - PAGING_CONTEXT_LINES;
349#else 383#else
350 lnsppg = TermWin.nrow * 4 / 5; 384 lnsppg = nrow * 4 / 5;
351#endif 385#endif
352 if (keysym == XK_Prior) 386 if (keysym == XK_Prior)
353 { 387 {
354 scr_page (UP, lnsppg); 388 scr_page (UP, lnsppg);
355 return; 389 return;
406 { 440 {
407 /* normal XTerm key bindings */ 441 /* normal XTerm key bindings */
408 case XK_Insert: /* Shift+Insert = paste mouse selection */ 442 case XK_Insert: /* Shift+Insert = paste mouse selection */
409 selection_request (ev.time, 0, 0); 443 selection_request (ev.time, 0, 0);
410 return; 444 return;
411#if TODO // TODO 445#if TODO
412 /* rxvt extras */ 446 /* rxvt extras */
413 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 447 case XK_KP_Add: /* Shift+KP_Add = bigger font */
414 change_font (FONT_UP); 448 change_font (FONT_UP);
415 return; 449 return;
416 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 450 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
475 } 509 }
476#endif 510#endif
477 511
478 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 512 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
479 { 513 {
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 { 514 {
506 newlen = 1; 515 newlen = 1;
507 switch (keysym) 516 switch (keysym)
508 { 517 {
509#ifndef NO_BACKSPACE_KEY 518#ifndef NO_BACKSPACE_KEY
517 else 526 else
518 strcpy (kbuf, key_backspace); 527 strcpy (kbuf, key_backspace);
519 break; 528 break;
520#endif 529#endif
521#ifndef NO_DELETE_KEY 530#ifndef NO_DELETE_KEY
531# ifdef XK_KP_Prior
532 case XK_KP_Delete:
533 /* allow shift to override */
534 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
535 {
536 strcpy (kbuf, "\033On");
537 break;
538 }
539 /* FALLTHROUGH */
540# endif
522 case XK_Delete: 541 case XK_Delete:
523 strcpy (kbuf, key_delete); 542 strcpy (kbuf, key_delete);
524 break; 543 break;
525#endif 544#endif
526 case XK_Tab: 545 case XK_Tab:
629#ifdef XK_KP_Begin 648#ifdef XK_KP_Begin
630 case XK_KP_Begin: 649 case XK_KP_Begin:
631 strcpy (kbuf, "\033Ou"); 650 strcpy (kbuf, "\033Ou");
632 break; 651 break;
633 652
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 653#endif
642 case XK_KP_F1: /* "\033OP" */ 654 case XK_KP_F1: /* "\033OP" */
643 case XK_KP_F2: /* "\033OQ" */ 655 case XK_KP_F2: /* "\033OQ" */
644 case XK_KP_F3: /* "\033OR" */ 656 case XK_KP_F3: /* "\033OR" */
645 case XK_KP_F4: /* "\033OS" */ 657 case XK_KP_F4: /* "\033OS" */
677 break; 689 break;
678 690
679 case XK_Find: 691 case XK_Find:
680 strcpy (kbuf, "\033[1~"); 692 strcpy (kbuf, "\033[1~");
681 break; 693 break;
694
695#ifdef XK_KP_End
696 case XK_KP_Insert:
697 /* allow shift to override */
698 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
699 {
700 strcpy (kbuf, "\033Op");
701 break;
702 }
703 /* FALLTHROUGH */
704#endif
682 case XK_Insert: 705 case XK_Insert:
683 strcpy (kbuf, "\033[2~"); 706 strcpy (kbuf, "\033[2~");
684 break; 707 break;
685#ifdef DXK_Remove /* support for DEC remove like key */ 708#ifdef DXK_Remove /* support for DEC remove like key */
686 case DXK_Remove: 709 case DXK_Remove:
776#undef FKEY 799#undef FKEY
777 default: 800 default:
778 newlen = 0; 801 newlen = 0;
779 break; 802 break;
780 } 803 }
804
781 if (newlen) 805 if (newlen)
782 len = strlen (kbuf); 806 len = strlen (kbuf);
783 } 807 }
784 808
785 /* 809 /*
794 else if (ctrl && keysym == XK_minus) 818 else if (ctrl && keysym == XK_minus)
795 { 819 {
796 len = 1; 820 len = 1;
797 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ 821 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
798 } 822 }
823 else if (keysym == XK_ISO_Left_Tab)
824 {
825 strcpy (kbuf, "\033[Z");
826 len = 3;
827 }
799 else 828 else
800 { 829 {
801#ifdef META8_OPTION 830#ifdef META8_OPTION
802 /* set 8-bit on */ 831 /* set 8-bit on */
803 if (meta && (meta_char == 0x80)) 832 if (meta && (meta_char == 0x80))
816 845
817 if (len <= 0) 846 if (len <= 0)
818 return; /* not mapped */ 847 return; /* not mapped */
819 848
820 if (options & Opt_scrollTtyKeypress) 849 if (options & Opt_scrollTtyKeypress)
821 if (TermWin.view_start) 850 if (view_start)
822 { 851 {
823 TermWin.view_start = 0; 852 view_start = 0;
824 want_refresh = 1; 853 want_refresh = 1;
825 } 854 }
826 855
827 /* 856 /*
828 * these modifications only affect the static keybuffer 857 * these modifications only affect the static keybuffer
861#endif /* DEBUG_CMD */ 890#endif /* DEBUG_CMD */
862 tt_write (kbuf, (unsigned int)len); 891 tt_write (kbuf, (unsigned int)len);
863} 892}
864/*}}} */ 893/*}}} */
865 894
866#if (MENUBAR_MAX) 895#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
867/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ 896/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
868/* attempt to `write' count to the input buffer */ 897/* attempt to `write' count to the input buffer */
869unsigned int 898unsigned int
870rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 899rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
871{ 900{
894 923
895 cmd_parse (); 924 cmd_parse ();
896 925
897 return 0; 926 return 0;
898} 927}
899#endif /* MENUBAR_MAX */ 928#endif
900 929
901void 930void
902rxvt_term::flush () 931rxvt_term::flush ()
903{ 932{
933 flush_ev.stop ();
934
904#ifdef TRANSPARENT 935#ifdef TRANSPARENT
905 if (want_full_refresh) 936 if (want_full_refresh)
906 { 937 {
907 want_full_refresh = 0; 938 want_full_refresh = 0;
908 scr_clear (); 939 scr_clear ();
918 IMSendSpot (); 949 IMSendSpot ();
919#endif 950#endif
920 } 951 }
921 952
922 display->flush (); 953 display->flush ();
923
924 flush_ev.stop ();
925} 954}
926 955
927void 956void
928rxvt_term::check_cb (check_watcher &w) 957rxvt_term::check_cb (check_watcher &w)
929{ 958{
1005{ 1034{
1006 if (mouse_slip_wheel_speed == 0 1035 if (mouse_slip_wheel_speed == 0
1007 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1036 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1008 : scr_page (UP, mouse_slip_wheel_speed)) 1037 : scr_page (UP, mouse_slip_wheel_speed))
1009 { 1038 {
1039 if (view_start == nsaved ||
1040 view_start == 0)
1041 mouse_slip_wheel_speed = 0;
1042
1010 refresh_type |= SMOOTH_REFRESH; 1043 refresh_type |= SMOOTH_REFRESH;
1011 want_refresh = 1; 1044 want_refresh = 1;
1012 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1045 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1013 } 1046 }
1014} 1047}
1034 if (n > 0) 1067 if (n > 0)
1035 { 1068 {
1036 cmdbuf_endp += n; 1069 cmdbuf_endp += n;
1037 return true; 1070 return true;
1038 } 1071 }
1039 else if (n < 0 && errno != EAGAIN) 1072 else if ((n < 0 && errno != EAGAIN && errno != EINTR) || n == 0)
1073 {
1074 pty_ev.stop ();
1075
1076 if (!(options & Opt_hold))
1040 destroy (); 1077 destroy ();
1078 }
1041 1079
1042 return false; 1080 return false;
1043} 1081}
1044 1082
1045void 1083void
1046rxvt_term::pty_cb (io_watcher &w, short revents) 1084rxvt_term::pty_cb (io_watcher &w, short revents)
1047{ 1085{
1048 SET_R (this); 1086 SET_R (this);
1049 SET_LOCALE (locale); 1087 SET_LOCALE (locale);
1050 1088
1051 if (revents & EVENT_WRITE)
1052 tt_write (0, 0);
1053 else if (revents & EVENT_READ) 1089 if (revents & EVENT_READ)
1054 // loop, but don't allow a single term to monopolize us 1090 // loop, but don't allow a single term to monopolize us
1055 while (pty_fill ()) 1091 while (pty_fill ())
1056 if (cmd_parse ()) 1092 if (cmd_parse ())
1057 break; 1093 break;
1094
1095 if (revents & EVENT_WRITE)
1096 pty_write ();
1058} 1097}
1059 1098
1060void 1099void
1061rxvt_term::pointer_unblank () 1100rxvt_term::pointer_unblank ()
1062{ 1101{
1063 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1102 XDefineCursor (display->display, vt, TermWin_cursor);
1064 recolour_cursor (); 1103 recolour_cursor ();
1065 1104
1066#ifdef POINTER_BLANK 1105#ifdef POINTER_BLANK
1067 hidden_pointer = 0; 1106 hidden_pointer = 0;
1068 1107
1076rxvt_term::pointer_blank () 1115rxvt_term::pointer_blank ()
1077{ 1116{
1078 if (! (options & Opt_pointerBlank)) 1117 if (! (options & Opt_pointerBlank))
1079 return; 1118 return;
1080 1119
1081 XDefineCursor (display->display, TermWin.vt, blank_cursor); 1120 XDefineCursor (display->display, vt, display->blank_cursor);
1082 XFlush (display->display); 1121 XFlush (display->display);
1083 1122
1084 hidden_pointer = 1; 1123 hidden_pointer = 1;
1085} 1124}
1086 1125
1137 + ((MEvent.state & ModMetaMask) ? 8 : 0) 1176 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1138 + ((MEvent.state & ControlMask) ? 16 : 0); 1177 + ((MEvent.state & ControlMask) ? 16 : 0);
1139#ifdef MOUSE_REPORT_DOUBLECLICK 1178#ifdef MOUSE_REPORT_DOUBLECLICK
1140 key_state += ((MEvent.clicks > 1) ? 32 : 0); 1179 key_state += ((MEvent.clicks > 1) ? 32 : 0);
1141#endif 1180#endif
1142
1143 } 1181 }
1144 1182
1145#ifdef DEBUG_MOUSEREPORT 1183#if DEBUG_MOUSEREPORT
1146 fprintf (stderr, "Mouse ["); 1184 fprintf (stderr, "Mouse [");
1147 if (key_state & 16) 1185 if (key_state & 16)
1148 fputc ('C', stderr); 1186 fputc ('C', stderr);
1149 if (key_state & 4) 1187 if (key_state & 4)
1150 fputc ('S', stderr); 1188 fputc ('S', stderr);
1154 fputc ('2', stderr); 1192 fputc ('2', stderr);
1155 fprintf (stderr, "]: <%d>, %d/%d\n", 1193 fprintf (stderr, "]: <%d>, %d/%d\n",
1156 button_number, 1194 button_number,
1157 x + 1, 1195 x + 1,
1158 y + 1); 1196 y + 1);
1159#else 1197#endif
1198
1160 tt_printf ("\033[M%c%c%c", 1199 tt_printf ("\033[M%c%c%c",
1161 (32 + button_number + key_state), 1200 (32 + button_number + key_state),
1162 (32 + x + 1), 1201 (32 + x + 1),
1163 (32 + y + 1)); 1202 (32 + y + 1));
1164#endif
1165} 1203}
1166 1204
1167#ifdef USING_W11LIB 1205#ifdef USING_W11LIB
1168void 1206void
1169rxvt_W11_process_x_event (XEvent *ev) 1207rxvt_W11_process_x_event (XEvent *ev)
1176 1214
1177/*{{{ process an X event */ 1215/*{{{ process an X event */
1178void 1216void
1179rxvt_term::x_cb (XEvent &ev) 1217rxvt_term::x_cb (XEvent &ev)
1180{ 1218{
1219 dDisp;
1220
1181 SET_R (this); 1221 SET_R (this);
1182 SET_LOCALE (locale); 1222 SET_LOCALE (locale);
1183 1223
1184#if defined(CURSOR_BLINK) 1224#if defined(CURSOR_BLINK)
1185 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1225 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1206 if (ev.type == KeyPress && hidden_pointer == 0) 1246 if (ev.type == KeyPress && hidden_pointer == 0)
1207 pointer_blank (); 1247 pointer_blank ();
1208 } 1248 }
1209#endif 1249#endif
1210 1250
1211#ifdef USE_XIM
1212 if (XFilterEvent (&ev, None))
1213 return;
1214#endif
1215
1216 Window unused_root, unused_child; 1251 Window unused_root, unused_child;
1217 int unused_root_x, unused_root_y; 1252 int unused_root_x, unused_root_y;
1218 unsigned int unused_mask; 1253 unsigned int unused_mask;
1219 1254
1220 switch (ev.type) 1255 switch (ev.type)
1221 { 1256 {
1222 case KeyPress: 1257 case KeyPress:
1223#if ISO_14755 1258#if ISO_14755
1227 1262
1228 break; 1263 break;
1229 1264
1230 case KeyRelease: 1265 case KeyRelease:
1231 { 1266 {
1232#if (defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)) || defined (ENABLE_FRILLS) 1267#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1233 KeySym ks; 1268 KeySym ks;
1234 1269
1235 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ 1270 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1236#endif 1271#endif
1237 1272
1306 button_release (ev.xbutton); 1341 button_release (ev.xbutton);
1307 break; 1342 break;
1308 1343
1309 case ClientMessage: 1344 case ClientMessage:
1310 if (ev.xclient.format == 32 1345 if (ev.xclient.format == 32
1346 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1347 {
1311 && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) 1348 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1312 destroy (); 1349 destroy ();
1350#if ENABLE_EWMH
1351 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1352 XSendEvent (disp, ev.xclient.window = display->root,
1353 False, SubstructureRedirectMask | SubstructureNotifyMask,
1354 &ev);
1355#endif
1356 }
1357#if ENABLE_XEMBED
1358 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1359 {
1360 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1361 focus_in ();
1362 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1363 focus_out ();
1364 }
1365#endif
1313#ifdef OFFIX_DND 1366#ifdef OFFIX_DND
1314 /* OffiX Dnd (drag 'n' drop) protocol */ 1367 /* OffiX Dnd (drag 'n' drop) protocol */
1315 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] 1368 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1316 && (ev.xclient.data.l[0] == DndFile 1369 && (ev.xclient.data.l[0] == DndFile
1317 || ev.xclient.data.l[0] == DndDir 1370 || ev.xclient.data.l[0] == DndDir
1318 || ev.xclient.data.l[0] == DndLink)) 1371 || ev.xclient.data.l[0] == DndLink))
1319 { 1372 {
1320 /* Get Dnd data */ 1373 /* Get Dnd data */
1321 Atom ActualType; 1374 Atom ActualType;
1322 int ActualFormat; 1375 int ActualFormat;
1323 unsigned char *data; 1376 unsigned char *data;
1324 unsigned long Size, RemainingBytes; 1377 unsigned long Size, RemainingBytes;
1325 1378
1326 XGetWindowProperty (display->display, display->root, 1379 XGetWindowProperty (disp, display->root,
1327 xa[XA_DNDSELECTION], 1380 xa[XA_DNDSELECTION],
1328 0L, 1000000L, 1381 0L, 1000000L,
1329 False, AnyPropertyType, 1382 False, AnyPropertyType,
1330 &ActualType, &ActualFormat, 1383 &ActualType, &ActualFormat,
1331 &Size, &RemainingBytes, 1384 &Size, &RemainingBytes,
1332 &data); 1385 &data);
1333 XChangeProperty (display->display, display->root, 1386 set_string_property (XA_CUT_BUFFER0, data);
1334 XA_CUT_BUFFER0, XA_STRING,
1335 8, PropModeReplace,
1336 data, strlen (data));
1337 XFree (data); 1387 XFree (data);
1338 selection_paste (display->root, XA_CUT_BUFFER0, True); 1388 selection_paste (display->root, XA_CUT_BUFFER0, true);
1339 XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); 1389 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1340 } 1390 }
1341#endif /* OFFIX_DND */ 1391#endif /* OFFIX_DND */
1342 break; 1392 break;
1343 1393
1344 case MappingNotify: 1394 case MappingNotify:
1369 break; 1419 break;
1370 } 1420 }
1371 break; 1421 break;
1372 1422
1373 case FocusIn: 1423 case FocusIn:
1374 if (!TermWin.focus) 1424 focus_in ();
1425 break;
1426
1427 case FocusOut:
1428 focus_out ();
1429 break;
1430
1431 case ConfigureNotify:
1432 if (ev.xconfigure.window == parent[0])
1375 { 1433 {
1376 TermWin.focus = 1; 1434 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev))
1377 want_refresh = 1; 1435 ;
1378#ifdef USE_XIM 1436
1379 if (Input_Context != NULL) 1437 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1380 { 1438 {
1381 IMSetStatusPosition (); 1439 seen_resize = 1;
1382 XSetICFocus (Input_Context); 1440 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1383 } 1441 }
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 1442
1445#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1443#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1446 if (options & Opt_transparent) 1444 if (options & Opt_transparent)
1447 {
1448 check_our_parents (); 1445 check_our_parents ();
1449 if (am_transparent)
1450 want_refresh = want_full_refresh = 1;
1451 }
1452#endif 1446#endif
1453 } 1447 }
1454 break; 1448 break;
1455 1449
1456 case PropertyNotify: 1450 case PropertyNotify:
1464 selection_clear (); 1458 selection_clear ();
1465 break; 1459 break;
1466 1460
1467 case SelectionNotify: 1461 case SelectionNotify:
1468 if (selection_wait == Sel_normal) 1462 if (selection_wait == Sel_normal)
1469 selection_paste (ev.xselection.requestor, 1463 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1470 ev.xselection.property, True);
1471 break; 1464 break;
1472 1465
1473 case SelectionRequest: 1466 case SelectionRequest:
1474 selection_send (ev.xselectionrequest); 1467 selection_send (ev.xselectionrequest);
1475 break; 1468 break;
1476 1469
1477 case UnmapNotify: 1470 case UnmapNotify:
1478 TermWin.mapped = 0; 1471 mapped = 0;
1479#ifdef TEXT_BLINK 1472#ifdef TEXT_BLINK
1480 text_blink_ev.stop (); 1473 text_blink_ev.stop ();
1481#endif 1474#endif
1482 break; 1475 break;
1483 1476
1484 case MapNotify: 1477 case MapNotify:
1485 TermWin.mapped = 1; 1478 mapped = 1;
1486#ifdef TEXT_BLINK 1479#ifdef TEXT_BLINK
1487 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 1480 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1488#endif 1481#endif
1489 break; 1482 break;
1490 1483
1494 break; 1487 break;
1495#endif /* TRANSPARENT */ 1488#endif /* TRANSPARENT */
1496 1489
1497 case GraphicsExpose: 1490 case GraphicsExpose:
1498 case Expose: 1491 case Expose:
1499 if (ev.xany.window == TermWin.vt) 1492 if (ev.xany.window == vt)
1500 { 1493 {
1501 do 1494 do
1502 scr_expose (ev.xexpose.x, ev.xexpose.y, 1495 scr_expose (ev.xexpose.x, ev.xexpose.y,
1503 ev.xexpose.width, ev.xexpose.height, False); 1496 ev.xexpose.width, ev.xexpose.height, False);
1504 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); 1497 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev));
1505 1498
1506 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1499 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1507 1500
1508 while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) 1501 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1509 scr_expose (ev.xexpose.x, ev.xexpose.y, 1502 scr_expose (ev.xexpose.x, ev.xexpose.y,
1510 ev.xexpose.width, ev.xexpose.height, False); 1503 ev.xexpose.width, ev.xexpose.height, False);
1511 1504
1512 scr_refresh (refresh_type); 1505 scr_refresh (refresh_type);
1513 } 1506 }
1514 else 1507 else
1515 { 1508 {
1516 XEvent unused_event; 1509 XEvent unused_event;
1517 1510
1518 while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) 1511 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event))
1519 ; 1512 ;
1520 while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) 1513 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event))
1521 ; 1514 ;
1522 1515
1523 if (isScrollbarWindow (ev.xany.window)) 1516 if (isScrollbarWindow (ev.xany.window))
1524 { 1517 {
1525 scrollBar.setIdle (); 1518 scrollBar.setIdle ();
1529 if (menubar_visible () && isMenuBarWindow (ev.xany.window)) 1522 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1530 menubar_expose (); 1523 menubar_expose ();
1531#endif 1524#endif
1532 1525
1533#ifdef TRANSPARENT 1526#ifdef TRANSPARENT
1534 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1527 if (am_transparent && ev.xany.window == parent[0])
1535 XClearWindow (display->display, ev.xany.window); 1528 XClearWindow (disp, ev.xany.window);
1536#endif 1529#endif
1537 } 1530 }
1538 break; 1531 break;
1539 1532
1540 case MotionNotify: 1533 case MotionNotify:
1547 { 1540 {
1548 menubar_control (ev.xbutton); 1541 menubar_control (ev.xbutton);
1549 break; 1542 break;
1550 } 1543 }
1551#endif 1544#endif
1552 if ((priv_modes & PrivMode_mouse_report) && ! (bypass_keystate)) 1545 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1553 break; 1546 break;
1554 1547
1555 if (ev.xany.window == TermWin.vt) 1548 if (ev.xany.window == vt)
1556 { 1549 {
1557 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1550 if (ev.xbutton.state & (Button1Mask | Button3Mask))
1558 { 1551 {
1559 while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) 1552 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1560 ; 1553 ;
1561 1554
1562 XQueryPointer (display->display, TermWin.vt, 1555 XQueryPointer (disp, vt,
1563 &unused_root, &unused_child, 1556 &unused_root, &unused_child,
1564 &unused_root_x, &unused_root_y, 1557 &unused_root_x, &unused_root_y,
1565 & (ev.xbutton.x), & (ev.xbutton.y), 1558 &ev.xbutton.x, &ev.xbutton.y,
1566 &unused_mask); 1559 &ev.xbutton.state);
1567#ifdef MOUSE_THRESHOLD 1560#ifdef MOUSE_THRESHOLD
1568 /* deal with a `jumpy' mouse */ 1561 /* deal with a `jumpy' mouse */
1569 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) 1562 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD)
1570 { 1563 {
1571#endif 1564#endif
1576 iso14755_54 (ev.xbutton.x, ev.xbutton.y); 1569 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1577 break; 1570 break;
1578 } 1571 }
1579#endif 1572#endif
1580 selection_extend (ev.xbutton.x, ev.xbutton.y, 1573 selection_extend (ev.xbutton.x, ev.xbutton.y,
1581 (ev.xbutton.state & Button3Mask) ? 2 : 0); 1574 ev.xbutton.state & Button3Mask ? 2 : 0);
1575
1582#ifdef SELECTION_SCROLLING 1576#ifdef SELECTION_SCROLLING
1583 if (ev.xbutton.y < TermWin.int_bwidth 1577 if (ev.xbutton.y < int_bwidth
1584 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1578 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1585 { 1579 {
1586 int dist; 1580 int dist;
1587 1581
1588 /* don't clobber the current delay if we are 1582 /* don't clobber the current delay if we are
1589 * already in the middle of scrolling. 1583 * already in the middle of scrolling.
1597 selection_save_x = ev.xbutton.x; 1591 selection_save_x = ev.xbutton.x;
1598 selection_save_y = ev.xbutton.y; 1592 selection_save_y = ev.xbutton.y;
1599 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1593 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1600 1594
1601 /* calc number of lines to scroll */ 1595 /* calc number of lines to scroll */
1602 if (ev.xbutton.y<TermWin.int_bwidth) 1596 if (ev.xbutton.y < int_bwidth)
1603 { 1597 {
1604 scroll_selection_dir = UP; 1598 scroll_selection_dir = UP;
1605 dist = TermWin.int_bwidth - ev.xbutton.y; 1599 dist = int_bwidth - ev.xbutton.y;
1606 } 1600 }
1607 else 1601 else
1608 { 1602 {
1609 scroll_selection_dir = DN; 1603 scroll_selection_dir = DN;
1610 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1604 dist = ev.xbutton.y - (int_bwidth + height);
1611 } 1605 }
1612 1606
1613 scroll_selection_lines = Pixel2Height (dist) 1607 scroll_selection_lines = Pixel2Height (dist)
1614 / SELECTION_SCROLL_LINE_SPEEDUP 1608 / SELECTION_SCROLL_LINE_SPEEDUP
1615 + 1; 1609 + 1;
1616 MIN_IT (scroll_selection_lines, 1610 min_it (scroll_selection_lines,
1617 SELECTION_SCROLL_MAX_LINES); 1611 SELECTION_SCROLL_MAX_LINES);
1618 } 1612 }
1619 else 1613 else
1620 { 1614 {
1621 /* we are within the text window, so we 1615 /* we are within the text window, so we
1630#endif 1624#endif
1631 } 1625 }
1632 } 1626 }
1633 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1627 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1634 { 1628 {
1635 while (XCheckTypedWindowEvent (display->display, scrollBar.win, 1629 while (XCheckTypedWindowEvent (disp, scrollBar.win,
1636 MotionNotify, &ev)) ; 1630 MotionNotify, &ev))
1631 ;
1632
1637 XQueryPointer (display->display, scrollBar.win, 1633 XQueryPointer (disp, scrollBar.win,
1638 &unused_root, &unused_child, 1634 &unused_root, &unused_child,
1639 &unused_root_x, &unused_root_y, 1635 &unused_root_x, &unused_root_y,
1640 & (ev.xbutton.x), & (ev.xbutton.y), 1636 &ev.xbutton.x, &ev.xbutton.y,
1641 &unused_mask); 1637 &unused_mask);
1642 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1638 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1643 scrollbar_size ()); 1639 scrollbar_size ());
1644 scr_refresh (refresh_type); 1640 scr_refresh (refresh_type);
1645 refresh_limit = 0; 1641 refresh_limit = 0;
1647 } 1643 }
1648 break; 1644 break;
1649 } 1645 }
1650} 1646}
1651 1647
1648void
1649rxvt_term::focus_in ()
1650{
1651 if (!focus)
1652 {
1653 focus = 1;
1654 want_refresh = 1;
1655#if USE_XIM
1656 if (Input_Context != NULL)
1657 {
1658 IMSetStatusPosition ();
1659 XSetICFocus (Input_Context);
1660 }
1661#endif
1662#if CURSOR_BLINK
1663 if (options & Opt_cursorBlink)
1664 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1665#endif
1666#if OFF_FOCUS_FADING
1667 if (rs[Rs_fade])
1668 {
1669 pix_colors = pix_colors_focused;
1670 scr_recolour ();
1671 }
1672#endif
1673 }
1674}
1675
1676void
1677rxvt_term::focus_out ()
1678{
1679 if (focus)
1680 {
1681 focus = 0;
1682 want_refresh = 1;
1683
1684#if ENABLE_FRILLS || ISO_14755
1685 iso14755buf = 0;
1686#endif
1687#if ENABLE_OVERLAY
1688 scr_overlay_off ();
1689#endif
1690#if USE_XIM
1691 if (Input_Context != NULL)
1692 XUnsetICFocus (Input_Context);
1693#endif
1694#if CURSOR_BLINK
1695 if (options & Opt_cursorBlink)
1696 cursor_blink_ev.stop ();
1697 hidden_cursor = 0;
1698#endif
1699#if OFF_FOCUS_FADING
1700 if (rs[Rs_fade])
1701 {
1702 pix_colors = pix_colors_unfocused;
1703 scr_recolour ();
1704 }
1705#endif
1706 }
1707}
1708
1652#if TRANSPARENT 1709#if TRANSPARENT
1653void 1710void
1654rxvt_term::rootwin_cb (XEvent &ev) 1711rxvt_term::rootwin_cb (XEvent &ev)
1655{ 1712{
1656 SET_R (this); 1713 SET_R (this);
1661 case PropertyNotify: 1718 case PropertyNotify:
1662 /* 1719 /*
1663 * if user used some Esetroot compatible prog to set the root bg, 1720 * 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. 1721 * use the property to determine the pixmap. We use it later on.
1665 */ 1722 */
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]) 1723 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID]
1724 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1670 return; 1725 return;
1671 1726
1672 /* FALLTHROUGH */ 1727 /* FALLTHROUGH */
1673 case ReparentNotify: 1728 case ReparentNotify:
1674 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1729 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1688 reportmode = !! (priv_modes & PrivMode_mouse_report); 1743 reportmode = !! (priv_modes & PrivMode_mouse_report);
1689 1744
1690 /* 1745 /*
1691 * VT window processing of button press 1746 * VT window processing of button press
1692 */ 1747 */
1693 if (ev.window == TermWin.vt) 1748 if (ev.window == vt)
1694 { 1749 {
1695#if ISO_14755 1750#if ISO_14755
1696 // 5.4 1751 // 5.4
1697 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1752 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1698 { 1753 {
1700 return; 1755 return;
1701 } 1756 }
1702#endif 1757#endif
1703 1758
1704 clickintime = ev.time - MEvent.time < MULTICLICK_TIME; 1759 clickintime = ev.time - MEvent.time < MULTICLICK_TIME;
1760
1705 if (reportmode) 1761 if (reportmode)
1706 { 1762 {
1707 /* mouse report from vt window */ 1763 /* mouse report from vt window */
1708 /* save the xbutton state (for ButtonRelease) */ 1764 /* save the xbutton state (for ButtonRelease) */
1709 MEvent.state = ev.state; 1765 MEvent.state = ev.state;
1738 } 1794 }
1739 else 1795 else
1740 { 1796 {
1741 if (ev.button != MEvent.button) 1797 if (ev.button != MEvent.button)
1742 MEvent.clicks = 0; 1798 MEvent.clicks = 0;
1799
1743 switch (ev.button) 1800 switch (ev.button)
1744 { 1801 {
1745 case Button1: 1802 case Button1:
1803 /* allow meta + click to select rectangular areas */
1804 /* should be done in screen.C */
1805#if ENABLE_FRILLS
1806 selection.rect = !!(ev.state & ModMetaMask);
1807#else
1808 selection.rect = false;
1809#endif
1810
1746 /* allow shift+left click to extend selection */ 1811 /* allow shift+left click to extend selection */
1747 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1812 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report))
1748 { 1813 {
1749 if (MEvent.button == Button1 && clickintime) 1814 if (MEvent.button == Button1 && clickintime)
1750 selection_rotate (ev.x, ev.y); 1815 selection_rotate (ev.x, ev.y);
1893 case Button3: 1958 case Button3:
1894 if (scrollBar.style != R_SB_XTERM) 1959 if (scrollBar.style != R_SB_XTERM)
1895 { 1960 {
1896 if (scrollbar_above_slider (ev.y)) 1961 if (scrollbar_above_slider (ev.y))
1897# ifdef RXVT_SCROLL_FULL 1962# ifdef RXVT_SCROLL_FULL
1898 scr_page (UP, TermWin.nrow - 1); 1963 scr_page (UP, nrow - 1);
1899# else 1964# else
1900 scr_page (UP, TermWin.nrow / 4); 1965 scr_page (UP, nrow / 4);
1901# endif 1966# endif
1902 else if (scrollbar_below_slider (ev.y)) 1967 else if (scrollbar_below_slider (ev.y))
1903# ifdef RXVT_SCROLL_FULL 1968# ifdef RXVT_SCROLL_FULL
1904 scr_page (DN, TermWin.nrow - 1); 1969 scr_page (DN, nrow - 1);
1905# else 1970# else
1906 scr_page (DN, TermWin.nrow / 4); 1971 scr_page (DN, nrow / 4);
1907# endif 1972# endif
1908 else 1973 else
1909 scrollBar.setMotion (); 1974 scrollBar.setMotion ();
1910 } 1975 }
1911 else 1976 else
1912 { 1977 {
1913 scr_page ((ev.button == Button1 ? DN : UP), 1978 scr_page ((ev.button == Button1 ? DN : UP),
1914 (TermWin.nrow 1979 (nrow
1915 * scrollbar_position (ev.y) 1980 * scrollbar_position (ev.y)
1916 / scrollbar_size ())); 1981 / scrollbar_size ()));
1917 } 1982 }
1918 1983
1919 break; 1984 break;
1951#ifdef SELECTION_SCROLLING 2016#ifdef SELECTION_SCROLLING
1952 if (sel_scroll_ev.active) 2017 if (sel_scroll_ev.active)
1953 sel_scroll_ev.stop(); 2018 sel_scroll_ev.stop();
1954#endif 2019#endif
1955 2020
1956 if (ev.window == TermWin.vt) 2021 if (ev.window == vt)
1957 { 2022 {
1958#if ISO_14755 2023#if ISO_14755
1959 // 5.4 2024 // 5.4
1960 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2025 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1961 return; 2026 return;
2012 v = ev.button == Button4 ? UP : DN; 2077 v = ev.button == Button4 ? UP : DN;
2013 2078
2014 if (ev.state & ShiftMask) 2079 if (ev.state & ShiftMask)
2015 i = 1; 2080 i = 1;
2016 else if (options & Opt_mouseWheelScrollPage) 2081 else if (options & Opt_mouseWheelScrollPage)
2017 i = TermWin.nrow - 1; 2082 i = nrow - 1;
2018 else 2083 else
2019 i = 5; 2084 i = 5;
2020 2085
2021# ifdef MOUSE_SLIP_WHEELING 2086# ifdef MOUSE_SLIP_WHEELING
2022 if (ev.state & ControlMask) 2087 if (ev.state & ControlMask)
2023 { 2088 {
2024 mouse_slip_wheel_speed += v ? -1 : 1; 2089 mouse_slip_wheel_speed += v ? -1 : 1;
2025 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2090 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; 2091 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2027 2092
2028 if (slip_wheel_ev.at < NOW) 2093 if (slip_wheel_ev.at < NOW)
2029 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2094 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2030 2095
2031 slip_wheel_ev.start (); 2096 slip_wheel_ev.start ();
2072 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2137 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2073 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2138 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2074 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2139 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2075 int i; 2140 int i;
2076 2141
2077 Visual* visual = display->visual; 2142 Visual *visual = display->visual;
2078 2143
2079 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2144 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2080 2145
2081 /* for convenience */ 2146 /* for convenience */
2082 mask_r = visual->red_mask; 2147 mask_r = visual->red_mask;
2303 Atom atype; 2368 Atom atype;
2304 unsigned char *prop = NULL; 2369 unsigned char *prop = NULL;
2305 Window root, oldp, *list; 2370 Window root, oldp, *list;
2306 Pixmap rootpixmap = None; 2371 Pixmap rootpixmap = None;
2307 XWindowAttributes wattr, wrootattr; 2372 XWindowAttributes wattr, wrootattr;
2373 dDisp;
2308 2374
2309 pchanged = 0; 2375 pchanged = 0;
2310 2376
2311 if (!(options & Opt_transparent)) 2377 if (!(options & Opt_transparent))
2312 return pchanged; /* Don't try any more */ 2378 return pchanged; /* Don't try any more */
2313 2379
2314 XGetWindowAttributes (display->display, display->root, &wrootattr); 2380 XGetWindowAttributes (disp, display->root, &wrootattr);
2315 rootdepth = wrootattr.depth; 2381 rootdepth = wrootattr.depth;
2316 2382
2317 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 2383 XGetWindowAttributes (disp, parent[0], &wattr);
2318 2384
2319 if (rootdepth != wattr.depth) 2385 if (rootdepth != wattr.depth)
2320 { 2386 {
2321 if (am_transparent) 2387 if (am_transparent)
2322 { 2388 {
2323 pchanged = 1; 2389 pchanged = 1;
2324 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2390 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2325 am_transparent = am_pixmap_trans = 0; 2391 am_transparent = am_pixmap_trans = 0;
2326 } 2392 }
2327 2393
2328 return pchanged; /* Don't try any more */ 2394 return pchanged; /* Don't try any more */
2329 } 2395 }
2330 2396
2331 /* Get all X ops out of the queue so that our information is up-to-date. */ 2397 /* Get all X ops out of the queue so that our information is up-to-date. */
2332 XSync (display->display, False); 2398 XSync (disp, False);
2333 2399
2334 /* 2400 /*
2335 * Make the frame window set by the window manager have 2401 * Make the frame window set by the window manager have
2336 * the root background. Some window managers put multiple nested frame 2402 * the root background. Some window managers put multiple nested frame
2337 * windows for each client, so we have to take care about that. 2403 * windows for each client, so we have to take care about that.
2338 */ 2404 */
2339 i = (xa[XA_XROOTPMAPID] 2405 i = (xa[XA_XROOTPMAP_ID]
2340 && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 2406 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2341 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2407 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2342 &nitems, &bytes_after, &prop) == Success); 2408 &nitems, &bytes_after, &prop) == Success);
2343 2409
2344 if (!i || prop == NULL) 2410 if (!i || prop == NULL)
2345 i = (xa[XA_XSETROOTID] 2411 i = (xa[XA_ESETROOT_PMAP_ID]
2346 && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], 2412 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2347 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2413 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2348 &nitems, &bytes_after, &prop) == Success); 2414 &nitems, &bytes_after, &prop) == Success);
2349 2415
2350 if (!i || prop == NULL 2416 if (!i || prop == NULL
2351#if TINTING 2417#if TINTING
2370 Window cr; 2436 Window cr;
2371 XImage *image; 2437 XImage *image;
2372 GC gc; 2438 GC gc;
2373 XGCValues gcvalue; 2439 XGCValues gcvalue;
2374 2440
2375 XTranslateCoordinates (display->display, TermWin.parent[0], display->root, 2441 XTranslateCoordinates (disp, parent[0], display->root,
2376 0, 0, &sx, &sy, &cr); 2442 0, 0, &sx, &sy, &cr);
2377 nw = (unsigned int)szHint.width; 2443 nw = (unsigned int)szHint.width;
2378 nh = (unsigned int)szHint.height; 2444 nh = (unsigned int)szHint.height;
2379 nx = ny = 0; 2445 nx = ny = 0;
2380 2446
2390 nh += sy; 2456 nh += sy;
2391 ny = -sy; 2457 ny = -sy;
2392 sy = 0; 2458 sy = 0;
2393 } 2459 }
2394 2460
2395 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2461 min_it (nw, (unsigned int) (wrootattr.width - sx));
2396 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2462 min_it (nh, (unsigned int) (wrootattr.height - sy));
2463
2464 XSync (disp, False);
2397 allowedxerror = -1; 2465 allowedxerror = -1;
2398 image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2466 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2399 2467
2400 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2468 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2401 /* XXX: may need a delay here? */ 2469 /* XXX: may need a delay here? */
2402 allowedxerror = 0; 2470 allowedxerror = 0;
2403 2471
2404 if (image == NULL) 2472 if (image == NULL)
2405 { 2473 {
2406 if (am_transparent && am_pixmap_trans) 2474 if (am_transparent && am_pixmap_trans)
2407 { 2475 {
2408 pchanged = 1; 2476 pchanged = 1;
2409 if (TermWin.pixmap != None) 2477 if (pixmap != None)
2410 { 2478 {
2411 XFreePixmap (display->display, TermWin.pixmap); 2479 XFreePixmap (disp, pixmap);
2412 TermWin.pixmap = None; 2480 pixmap = None;
2413 } 2481 }
2414 } 2482 }
2415 2483
2416 am_pixmap_trans = 0; 2484 am_pixmap_trans = 0;
2417 } 2485 }
2418 else 2486 else
2419 { 2487 {
2420 if (TermWin.pixmap != None) 2488 if (pixmap != None)
2421 XFreePixmap (display->display, TermWin.pixmap); 2489 XFreePixmap (disp, pixmap);
2422 2490
2423#if TINTING 2491#if TINTING
2424 if (ISSET_PIXCOLOR (Color_tint)) 2492 if (ISSET_PIXCOLOR (Color_tint))
2425 { 2493 {
2426 unsigned short rm, gm, bm; 2494 unsigned short rm, gm, bm;
2430 2498
2431 ShadeXImage (display, image, shade, rm, gm, bm); 2499 ShadeXImage (display, image, shade, rm, gm, bm);
2432 } 2500 }
2433#endif 2501#endif
2434 2502
2435 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 2503 pixmap = XCreatePixmap (disp, vt,
2436 szHint.width, szHint.height, image->depth); 2504 szHint.width, szHint.height, image->depth);
2437 gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); 2505 gc = XCreateGC (disp, vt, 0UL, &gcvalue);
2438 XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, 2506 XPutImage (disp, pixmap, gc, image, 0, 0,
2439 nx, ny, image->width, image->height); 2507 nx, ny, image->width, image->height);
2440 XFreeGC (display->display, gc); 2508 XFreeGC (disp, gc);
2441 XDestroyImage (image); 2509 XDestroyImage (image);
2442 XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); 2510 XSetWindowBackgroundPixmap (disp, parent[0], pixmap);
2443 XClearWindow (display->display, TermWin.parent[0]); 2511 XClearWindow (disp, parent[0]);
2444 2512
2445 if (!am_transparent || !am_pixmap_trans) 2513 if (!am_transparent || !am_pixmap_trans)
2446 pchanged = 1; 2514 pchanged = 1;
2447 2515
2448 am_transparent = am_pixmap_trans = 1; 2516 am_transparent = am_pixmap_trans = 1;
2449 } 2517 }
2450 } 2518 }
2451 2519
2452 if (!am_pixmap_trans) 2520 if (am_pixmap_trans)
2521 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2522 else
2453 { 2523 {
2454 unsigned int n; 2524 unsigned int n;
2455 /* 2525 /*
2456 * InheritPixmap transparency 2526 * InheritPixmap transparency
2457 */ 2527 */
2458 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2528 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2459 { 2529 {
2460 oldp = TermWin.parent[i]; 2530 oldp = parent[i];
2461 XQueryTree (display->display, TermWin.parent[i - 1], &root, 2531 XQueryTree (disp, parent[i - 1], &root,
2462 &TermWin.parent[i], &list, &n); 2532 &parent[i], &list, &n);
2463 XFree (list); 2533 XFree (list);
2464 2534
2465 if (TermWin.parent[i] == display->root) 2535 if (parent[i] == display->root)
2466 { 2536 {
2467 if (oldp != None) 2537 if (oldp != None)
2468 pchanged = 1; 2538 pchanged = 1;
2469 2539
2470 break; 2540 break;
2471 } 2541 }
2472 2542
2473 if (oldp != TermWin.parent[i]) 2543 if (oldp != parent[i])
2474 pchanged = 1; 2544 pchanged = 1;
2475 } 2545 }
2476 2546
2477 n = 0; 2547 n = 0;
2478 2548
2479 if (pchanged) 2549 if (pchanged)
2480 { 2550 {
2481 for (; n < (unsigned int)i; n++) 2551 for (; n < (unsigned int)i; n++)
2482 { 2552 {
2483 XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); 2553 XGetWindowAttributes (disp, parent[n], &wattr);
2484 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2554 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2485 { 2555 {
2486 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2556 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2487 break; 2557 break;
2488 } 2558 }
2489 } 2559 }
2490 } 2560 }
2491 2561
2492 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) 2562 if (n > (int) (sizeof (parent) / sizeof (parent[0])))
2493 { 2563 {
2494 XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); 2564 XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]);
2495 XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); 2565 XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]);
2496 am_transparent = 0; 2566 am_transparent = 0;
2497 /* XXX: also turn off Opt_transparent? */ 2567 /* XXX: also turn off Opt_transparent? */
2498 } 2568 }
2499 else 2569 else
2500 { 2570 {
2503 * needed for fvwm2.2.2 (and before?) */ 2573 * needed for fvwm2.2.2 (and before?) */
2504 sleep (1); 2574 sleep (1);
2505#endif 2575#endif
2506 for (n = 0; n < (unsigned int)i; n++) 2576 for (n = 0; n < (unsigned int)i; n++)
2507 { 2577 {
2508 XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); 2578 XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative);
2509 XClearWindow (display->display, TermWin.parent[n]); 2579 XClearWindow (disp, parent[n]);
2510 } 2580 }
2511 2581
2512 XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); 2582 XSetWindowBackgroundPixmap (disp, vt, ParentRelative);
2513 am_transparent = 1; 2583 am_transparent = 1;
2514 } 2584 }
2515 2585
2516 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2586 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2517 TermWin.parent[i] = None; 2587 parent[i] = None;
2518 } 2588 }
2519 2589
2520 // this is experimental
2521 if (scrollBar.win) 2590 if (scrollBar.win)
2522 { 2591 {
2523 XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); 2592 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2524 XClearWindow (display->display, scrollBar.win);
2525 scrollBar.setIdle (); 2593 scrollBar.setIdle ();
2526 scrollbar_show (0); 2594 scrollbar_show (0);
2595 }
2596
2597 if (am_transparent)
2598 {
2599 want_refresh = want_full_refresh = 1;
2600 if (am_pixmap_trans)
2601 flush ();
2527 } 2602 }
2528 2603
2529 return pchanged; 2604 return pchanged;
2530} 2605}
2531#endif 2606#endif
2557 seen_input = 1; 2632 seen_input = 1;
2558 // many badly-written programs (e.g. jed) contain a race condition: 2633 // many badly-written programs (e.g. jed) contain a race condition:
2559 // they first read the screensize and then install a SIGWINCH handler. 2634 // they first read the screensize and then install a SIGWINCH handler.
2560 // some window managers resize the window early, and these programs 2635 // some window managers resize the window early, and these programs
2561 // then sometimes get the size wrong. 2636 // then sometimes get the size wrong.
2637 // unfortunately other programs are even more buggy and dislike
2638 // being sent SIGWINCH, so only do it when we were in fact being
2639 // resized.
2640 if (seen_resize && cmd_pid)
2562 kill (-cmd_pid, SIGWINCH); 2641 kill (-cmd_pid, SIGWINCH);
2563 } 2642 }
2564 2643
2565 /* Read a text string from the input buffer */ 2644 /* Read a text string from the input buffer */
2566 unicode_t buf[UBUFSIZ]; 2645 unicode_t buf[UBUFSIZ];
2567 bool refreshnow = false; 2646 bool refreshnow = false;
2568 int nlines = 0; 2647 int nlines = 0;
2569 unicode_t *str = buf; 2648 unicode_t *str = buf;
2649 unicode_t *eol = str + min (ncol, UBUFSIZ);
2570 2650
2571 for (;;) 2651 for (;;)
2572 { 2652 {
2573 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2653 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2574 break; 2654 break;
2575 2655
2576 *str++ = ch; 2656 *str++ = ch;
2577 2657
2578 if (ch == C0_LF) 2658 if (ch == C0_LF || str >= eol)
2579 { 2659 {
2660 if (ch == C0_LF)
2580 nlines++; 2661 nlines++;
2662
2581 refresh_count++; 2663 refresh_count++;
2582 2664
2583 if (!(options & Opt_jumpScroll) 2665 if (!(options & Opt_jumpScroll)
2584 || (refresh_count >= refresh_limit * (TermWin.nrow - 1))) 2666 || (refresh_count >= refresh_limit * (nrow - 1)))
2585 { 2667 {
2586 refreshnow = true; 2668 refreshnow = true;
2587 ch = NOCHAR; 2669 ch = NOCHAR;
2588 break; 2670 break;
2589 } 2671 }
2590 2672
2591 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2673 // scr_add_lines only works for nlines <= nrow - 1.
2592 if (nlines >= TermWin.nrow - 1) 2674 if (nlines >= nrow - 1)
2593 { 2675 {
2594 scr_add_lines (buf, nlines, str - buf); 2676 scr_add_lines (buf, nlines, str - buf);
2595 nlines = 0; 2677 nlines = 0;
2596 str = buf; 2678 str = buf;
2679 eol = str + min (ncol, UBUFSIZ);
2597 } 2680 }
2598 }
2599 2681
2600 if (str >= buf + UBUFSIZ) 2682 if (str >= eol)
2601 { 2683 {
2684 if (eol >= buf + UBUFSIZ)
2685 {
2602 ch = NOCHAR; 2686 ch = NOCHAR;
2603 break; 2687 break;
2688 }
2689 else
2690 eol = min (eol + ncol, buf + UBUFSIZ);
2691 }
2692
2604 } 2693 }
2605 2694
2606 seq_begin = cmdbuf_ptr; 2695 seq_begin = cmdbuf_ptr;
2607 ch = next_char (); 2696 ch = next_char ();
2608 } 2697 }
2679 if (len == (size_t)-1) 2768 if (len == (size_t)-1)
2680 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2769 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2681 2770
2682 // assume wchar == unicode 2771 // assume wchar == unicode
2683 cmdbuf_ptr += len; 2772 cmdbuf_ptr += len;
2684 return wc; 2773 return wc & UNICODE_MASK;
2685 } 2774 }
2686 2775
2687 return NOCHAR; 2776 return NOCHAR;
2688} 2777}
2689 2778
3152 { 3241 {
3153 switch (priv) 3242 switch (priv)
3154 { 3243 {
3155 case '>': 3244 case '>':
3156 if (ch == CSI_DA) /* secondary device attributes */ 3245 if (ch == CSI_DA) /* secondary device attributes */
3157 tt_printf ("\033[>%d;%-.8s;0c", 'R', VSTRING); 3246 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]);
3158 break; 3247 break;
3159 case '?': 3248 case '?':
3160 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3249 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3161 process_terminal_mode (ch, priv, nargs, arg); 3250 process_terminal_mode (ch, priv, nargs, arg);
3162 break; 3251 break;
3267 3356
3268 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 3357 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3269 arg[0] = -arg[0]; 3358 arg[0] = -arg[0];
3270 /* FALLTHROUGH */ 3359 /* FALLTHROUGH */
3271 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3360 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3272 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 3361 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3273 break; 3362 break;
3274 3363
3275 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3364 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3276 tt_write ((const unsigned char *)VT100_ANS, 3365 tt_write ((const unsigned char *)VT100_ANS,
3277 (unsigned int) (sizeof (VT100_ANS) - 1)); 3366 (unsigned int) (sizeof (VT100_ANS) - 1));
3391rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3480rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3392{ 3481{
3393 int x, y; 3482 int x, y;
3394 XWindowAttributes wattr; 3483 XWindowAttributes wattr;
3395 Window wdummy; 3484 Window wdummy;
3485 dDisp;
3396 3486
3397 if (nargs == 0) 3487 if (nargs == 0)
3398 return; 3488 return;
3399 3489
3400 switch (args[0]) 3490 switch (args[0])
3401 { 3491 {
3402 /* 3492 /*
3403 * commands 3493 * commands
3404 */ 3494 */
3405 case 1: /* deiconify window */ 3495 case 1: /* deiconify window */
3406 XMapWindow (display->display, TermWin.parent[0]); 3496 XMapWindow (disp, parent[0]);
3407 break; 3497 break;
3408 case 2: /* iconify window */ 3498 case 2: /* iconify window */
3409 XIconifyWindow (display->display, TermWin.parent[0], 3499 XIconifyWindow (disp, parent[0], display->screen);
3410 DefaultScreen (display->display));
3411 break; 3500 break;
3412 case 3: /* set position (pixels) */ 3501 case 3: /* set position (pixels) */
3413 XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); 3502 XMoveWindow (disp, parent[0], args[1], args[2]);
3414 break; 3503 break;
3415 case 4: /* set size (pixels) */ 3504 case 4: /* set size (pixels) */
3416 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3505 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3417 break; 3506 break;
3418 case 5: /* raise window */ 3507 case 5: /* raise window */
3419 XRaiseWindow (display->display, TermWin.parent[0]); 3508 XRaiseWindow (disp, parent[0]);
3420 break; 3509 break;
3421 case 6: /* lower window */ 3510 case 6: /* lower window */
3422 XLowerWindow (display->display, TermWin.parent[0]); 3511 XLowerWindow (disp, parent[0]);
3423 break; 3512 break;
3424 case 7: /* refresh window */ 3513 case 7: /* refresh window */
3425 scr_touch (true); 3514 scr_touch (true);
3426 break; 3515 break;
3427 case 8: /* set size (chars) */ 3516 case 8: /* set size (chars) */
3428 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3517 set_widthheight ((unsigned int) (args[2] * fwidth),
3429 (unsigned int) (args[1] * TermWin.fheight)); 3518 (unsigned int) (args[1] * fheight));
3430 break; 3519 break;
3431 3520
3432 //case 9: NYI, TODO, restore maximized window or maximize window 3521 //case 9: NYI, TODO, restore maximized window or maximize window
3433 default: 3522 default:
3434 if (args[0] >= 24) /* set height (chars) */ 3523 if (args[0] >= 24) /* set height (chars) */
3435 set_widthheight ((unsigned int)TermWin.width, 3524 set_widthheight ((unsigned int)width,
3436 (unsigned int) (args[1] * TermWin.fheight)); 3525 (unsigned int) (args[1] * fheight));
3437 break; 3526 break;
3438 3527
3439 3528
3440 /* 3529 /*
3441 * reports - some output format copied from XTerm 3530 * reports - some output format copied from XTerm
3442 */ 3531 */
3443 case 11: /* report window state */ 3532 case 11: /* report window state */
3444 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3533 XGetWindowAttributes (disp, parent[0], &wattr);
3445 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3534 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3446 break; 3535 break;
3447 case 13: /* report window position */ 3536 case 13: /* report window position */
3448 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3537 XGetWindowAttributes (disp, parent[0], &wattr);
3449 XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, 3538 XTranslateCoordinates (disp, parent[0], wattr.root,
3450 -wattr.border_width, -wattr.border_width, 3539 -wattr.border_width, -wattr.border_width,
3451 &x, &y, &wdummy); 3540 &x, &y, &wdummy);
3452 tt_printf ("\033[3;%d;%dt", x, y); 3541 tt_printf ("\033[3;%d;%dt", x, y);
3453 break; 3542 break;
3454 case 14: /* report window size (pixels) */ 3543 case 14: /* report window size (pixels) */
3455 XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); 3544 XGetWindowAttributes (disp, parent[0], &wattr);
3456 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3545 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3457 break; 3546 break;
3458 case 18: /* report text area size (chars) */ 3547 case 18: /* report text area size (chars) */
3459 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3548 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3460 break; 3549 break;
3461 case 19: /* report window size (chars) */ 3550 case 19: /* report window size (chars) */
3462 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3551 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3463 break; 3552 break;
3464 case 20: /* report icon label */ 3553 case 20: /* report icon label */
3465 { 3554 {
3466 char *s; 3555 char *s;
3467 XGetIconName (display->display, TermWin.parent[0], &s); 3556 XGetIconName (disp, parent[0], &s);
3468 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3557 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3469 XFree (s); 3558 XFree (s);
3470 } 3559 }
3471 break; 3560 break;
3472 case 21: /* report window title */ 3561 case 21: /* report window title */
3473 { 3562 {
3474 char *s; 3563 char *s;
3475 XFetchName (display->display, TermWin.parent[0], &s); 3564 XFetchName (disp, parent[0], &s);
3476 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3565 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */
3477 XFree (s); 3566 XFree (s);
3478 } 3567 }
3479 break; 3568 break;
3480 } 3569 }
3487 * ends_how is terminator used. returned input must be free()'d 3576 * ends_how is terminator used. returned input must be free()'d
3488 */ 3577 */
3489unsigned char * 3578unsigned char *
3490rxvt_term::get_to_st (unicode_t &ends_how) 3579rxvt_term::get_to_st (unicode_t &ends_how)
3491{ 3580{
3492 unicode_t prev = 0, ch; 3581 unicode_t ch;
3582 bool seen_esc = false;
3493 unsigned int n = 0; 3583 unsigned int n = 0;
3494 unsigned char *s;
3495 unsigned char string[STRING_MAX]; 3584 wchar_t string[STRING_MAX];
3496 3585
3497 while ((ch = cmd_getc ()) != NOCHAR) 3586 while ((ch = cmd_getc ()) != NOCHAR)
3498 { 3587 {
3499 if (prev == C0_ESC) 3588 if (seen_esc)
3500 { 3589 {
3501 if (ch == 0x5c) /* 7bit ST */ 3590 if (ch == 0x5c) /* 7bit ST */
3502 break; 3591 break;
3503 else 3592 else
3504 return NULL; 3593 return NULL;
3505 } 3594 }
3595 else if (ch == C0_ESC)
3596 {
3597 seen_esc = true;
3598 continue;
3599 }
3506 else if (ch == C0_BEL || ch == CHAR_ST) 3600 else if (ch == C0_BEL || ch == CHAR_ST)
3507 break; 3601 break;
3508 else if (ch < 0x20) 3602 else if (ch < 0x20)
3509 return NULL; /* other control character - exit */ 3603 return NULL; /* other control character - exit */
3510 3604
3511 if (n >= sizeof (string) - 1) 3605 seen_esc = false;
3606
3607 if (n >= STRING_MAX - 1)
3512 // stop at some sane length 3608 // stop at some sane length
3513 return NULL; 3609 return NULL;
3514 3610
3515 if (ch == C0_SYN) 3611 if (ch == C0_SYN)
3516 {
3517 string[n++] = cmd_get8 (); 3612 string[n++] = cmd_get8 ();
3518 prev = 0;
3519 }
3520 else 3613 else
3521 string[n++] = prev = ch; 3614 string[n++] = ch;
3522 } 3615 }
3523 3616
3524 string[n++] = '\0'; 3617 string[n++] = '\0';
3525 3618
3526 if ((s = (unsigned char *)rxvt_malloc (n)) == NULL)
3527 return NULL;
3528
3529 ends_how = (ch == 0x5c ? C0_ESC : ch); 3619 ends_how = (ch == 0x5c ? C0_ESC : ch);
3530 strncpy (s, string, n); 3620
3531 return s; 3621 return (unsigned char *)rxvt_wcstombs (string);
3532} 3622}
3533 3623
3534/*----------------------------------------------------------------------*/ 3624/*----------------------------------------------------------------------*/
3535/* 3625/*
3536 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3626 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3590 set_window_color (color, str); 3680 set_window_color (color, str);
3591} 3681}
3592 3682
3593/* 3683/*
3594 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3684 * 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 */ 3685 */
3618void 3686void
3619rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3687rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp)
3620{ 3688{
3621 int changed = 0; 3689 int changed = 0;
3622 int color; 3690 int color;
3623 char *buf, *name; 3691 char *buf, *name;
3624 bool query = str[0] == '?' && !str[1]; 3692 bool query = str[0] == '?' && !str[1];
3693 int saveop = op;
3694 dDisp;
3625 3695
3626 assert (str != NULL); 3696 assert (str != NULL);
3627 switch (op) 3697 switch (op)
3628 { 3698 {
3629 case XTerm_name: 3699 case XTerm_name:
3636 set_title (str); 3706 set_title (str);
3637 break; 3707 break;
3638 case XTerm_property: 3708 case XTerm_property:
3639 if (str[0] == '?') 3709 if (str[0] == '?')
3640 { 3710 {
3641 Atom prop = XInternAtom (display->display, str + 1, True); 3711 Atom prop = display->atom (str + 1);
3642 Atom actual_type; 3712 Atom actual_type;
3643 int actual_format; 3713 int actual_format;
3644 unsigned long nitems; 3714 unsigned long nitems;
3645 unsigned long bytes_after; 3715 unsigned long bytes_after;
3646 unsigned char *value = 0; 3716 unsigned char *value = 0;
3647 const char *str = ""; 3717 const char *str = "";
3648 3718
3649 if (prop 3719 if (prop
3650 && XGetWindowProperty (display->display, TermWin.parent[0], 3720 && XGetWindowProperty (disp, parent[0],
3651 prop, 0, 1<<16, 0, AnyPropertyType, 3721 prop, 0, 1<<16, 0, AnyPropertyType,
3652 &actual_type, &actual_format, 3722 &actual_type, &actual_format,
3653 &nitems, &bytes_after, &value) == Success 3723 &nitems, &bytes_after, &value) == Success
3654 && actual_type != None 3724 && actual_type != None
3655 && actual_format == 8) 3725 && actual_format == 8)
3664 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3734 char *eq = strchr (str, '='); // constness lost, but verified to be ok
3665 3735
3666 if (eq) 3736 if (eq)
3667 { 3737 {
3668 *eq = 0; 3738 *eq = 0;
3669 XChangeProperty (display->display, TermWin.parent[0], 3739 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 } 3740 }
3674 else 3741 else
3675 XDeleteProperty (display->display, TermWin.parent[0], 3742 XDeleteProperty (disp, parent[0],
3676 display->atom (str)); 3743 display->atom (str));
3677 } 3744 }
3678 break; 3745 break;
3679 3746
3680 case XTerm_Color: 3747 case XTerm_Color:
3727 process_color_seq (XTerm_Color_UL, Color_UL, str, resp); 3794 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3728 break; 3795 break;
3729 case XTerm_Color_RV: 3796 case XTerm_Color_RV:
3730 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3797 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3731 break; 3798 break;
3799 case URxvt_Color_IT:
3800 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3801 break;
3802#endif
3803#if TRANSPARENT && TINTING
3804 case URxvt_Color_tint:
3805 process_color_seq (URxvt_Color_tint, Color_tint, str, resp);
3806 check_our_parents ();
3807 if (am_transparent)
3808 want_full_refresh = want_refresh = 1;
3809 break;
3732#endif 3810#endif
3733 3811
3734 case XTerm_Pixmap: 3812 case XTerm_Pixmap:
3735 if (*str != ';') 3813 if (*str != ';')
3736 { 3814 {
3744 { 3822 {
3745 str++; 3823 str++;
3746#if XPM_BACKGROUND 3824#if XPM_BACKGROUND
3747 changed += scale_pixmap (str); 3825 changed += scale_pixmap (str);
3748#endif 3826#endif
3749
3750 } 3827 }
3828
3751 if (changed) 3829 if (changed)
3752 { 3830 {
3753#ifdef XPM_BACKGROUND 3831#ifdef XPM_BACKGROUND
3754 resize_pixmap (); 3832 resize_pixmap ();
3755#endif 3833#endif
3766 3844
3767 case XTerm_logfile: 3845 case XTerm_logfile:
3768 // TODO, when secure mode? 3846 // TODO, when secure mode?
3769 break; 3847 break;
3770 3848
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 3849#ifdef MENUBAR
3806 case XTerm_Menu: 3850 case URxvt_Menu:
3807 if (options & Opt_insecure) 3851 if (options & Opt_insecure)
3808 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3852 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3809 break; 3853 break;
3810#endif 3854#endif
3811#if 0 3855#if 0
3816 { 3860 {
3817 scr_dump (fd); 3861 scr_dump (fd);
3818 close (fd); 3862 close (fd);
3819 } 3863 }
3820 } 3864 }
3865 break;
3866#endif
3867 case XTerm_font:
3868 op = URxvt_font;
3869 case URxvt_font:
3870#if ENABLE_STYLES
3871 case URxvt_boldFont:
3872 case URxvt_italicFont:
3873 case URxvt_boldItalicFont:
3874#endif
3875 if (query)
3876 tt_printf ("\33]%d;%-.250s%c", saveop,
3877 (options & Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3878 ? fontset[op - URxvt_font]->fontdesc : "",
3879 resp);
3880 else
3881 {
3882 const char *&res = rs[Rs_font + (op - URxvt_font)];
3883
3884 res = strdup (str);
3885 allocated.push_back ((void *)res);
3886 set_fonts ();
3887 }
3888 break;
3889
3890#if ENABLE_FRILLS
3891 case URxvt_locale:
3892 if (query)
3893 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp);
3894 else
3895 {
3896 set_locale (str);
3897 pty.set_utf8_mode (enc_utf8);
3898 init_xlocale ();
3899 }
3900 break;
3901
3902 case URxvt_view_up:
3903 case URxvt_view_down:
3904 int lines = atoi (str);
3905
3906 if (lines)
3907 scr_page (op == URxvt_view_up ? UP : DN, lines);
3908 else
3909 {
3910 scr_erase_savelines ();
3911 }
3912
3821 break; 3913 break;
3822#endif 3914#endif
3823 } 3915 }
3824} 3916}
3825/*----------------------------------------------------------------------*/ 3917/*----------------------------------------------------------------------*/
3935 4027
3936 /* extra handling for values with state unkept */ 4028 /* extra handling for values with state unkept */
3937 switch (arg[i]) 4029 switch (arg[i])
3938 { 4030 {
3939 case 1048: /* alternative cursor save */ 4031 case 1048: /* alternative cursor save */
4032 case 1049:
3940 if (options & Opt_secondaryScreen) 4033 if (options & Opt_secondaryScreen)
3941 if (mode == 0) 4034 if (mode == 0)
3942 scr_cursor (RESTORE); 4035 scr_cursor (RESTORE);
3943 else if (mode == 1) 4036 else if (mode == 1)
3944 scr_cursor (SAVE); 4037 scr_cursor (SAVE);
3957 */ 4050 */
3958 PrivMode (1, PrivMode_vt52); 4051 PrivMode (1, PrivMode_vt52);
3959 break; 4052 break;
3960 case 3: /* 80/132 */ 4053 case 3: /* 80/132 */
3961 if (priv_modes & PrivMode_132OK) 4054 if (priv_modes & PrivMode_132OK)
3962 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 4055 set_widthheight (((state ? 132 : 80) * fwidth), height);
3963 break; 4056 break;
3964 case 4: /* smooth scrolling */ 4057 case 4: /* smooth scrolling */
3965 if (state) 4058 if (state)
3966 options &= ~Opt_jumpScroll; 4059 options &= ~Opt_jumpScroll;
3967 else 4060 else
4069 rendset = 0, rendstyle = ~RS_None; 4162 rendset = 0, rendstyle = ~RS_None;
4070 break; 4163 break;
4071 case 1: 4164 case 1:
4072 rendset = 1, rendstyle = RS_Bold; 4165 rendset = 1, rendstyle = RS_Bold;
4073 break; 4166 break;
4074 //case 2: // faint or second colour 4167 //case 2: // low intensity
4075 //case 3: // italic 4168 case 3:
4169 rendset = 1, rendstyle = RS_Italic;
4170 break;
4076 case 4: 4171 case 4:
4077 rendset = 1, rendstyle = RS_Uline; 4172 rendset = 1, rendstyle = RS_Uline;
4078 break; 4173 break;
4079 case 5: // slowly blinking 4174 case 5: // slowly blinking
4080 case 6: // rapidly blinking 4175 case 6: // rapidly blinking
4092 //case 11: // scoansi acs on, first alt font 4187 //case 11: // scoansi acs on, first alt font
4093 //case 12: // scoansi acs on, |0x80, second alt font 4188 //case 12: // scoansi acs on, |0x80, second alt font
4094 //... 4189 //...
4095 //case 19: // ninth alt font 4190 //case 19: // ninth alt font
4096 //case 20: // gothic 4191 //case 20: // gothic
4097 case 21: // disable bold, faint 4192 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4098 rendset = 0, rendstyle = RS_Bold; 4193 rendset = 0, rendstyle = RS_Bold;
4099 break; 4194 break;
4100 case 22: 4195 case 22: // normal intensity
4101 rendset = 0, rendstyle = RS_Bold; 4196 rendset = 0, rendstyle = RS_Bold;
4102 break; 4197 break;
4103 //case 23: disable italic 4198 case 23: // disable italic
4199 rendset = 0, rendstyle = RS_Italic;
4200 break;
4104 case 24: 4201 case 24:
4105 rendset = 0, rendstyle = RS_Uline; 4202 rendset = 0, rendstyle = RS_Uline;
4106 break; 4203 break;
4107 case 25: 4204 case 25:
4108 rendset = 0, rendstyle = RS_Blink; 4205 rendset = 0, rendstyle = RS_Blink;
4109 break; 4206 break;
4110 case 26: 4207 case 26: // variable spacing (iso 8613)
4111 rendset = 0, rendstyle = RS_Blink; 4208 rendset = 0, rendstyle = RS_Blink;
4112 break; 4209 break;
4113 case 27: 4210 case 27:
4114 rendset = 0, rendstyle = RS_RVid; 4211 rendset = 0, rendstyle = RS_RVid;
4115 break; 4212 break;
4133 case 35: 4230 case 35:
4134 case 36: 4231 case 36:
4135 case 37: 4232 case 37:
4136 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); 4233 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4137 break; 4234 break;
4138#ifdef TTY_256COLOR 4235 case 38: // set fg color, ISO 8613-6
4139 case 38:
4140 if (nargs > i + 2 && arg[i + 1] == 5) 4236 if (nargs > i + 2 && arg[i + 1] == 5)
4141 { 4237 {
4142 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg); 4238 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4143 i += 2; 4239 i += 2;
4144 } 4240 }
4145 break; 4241 break;
4146#endif
4147 case 39: /* default fg */ 4242 case 39: /* default fg */
4148 scr_color (Color_fg, Color_fg); 4243 scr_color (Color_fg, Color_fg);
4149 break; 4244 break;
4150 4245
4151 case 40: 4246 case 40:
4156 case 45: 4251 case 45:
4157 case 46: 4252 case 46:
4158 case 47: 4253 case 47:
4159 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); 4254 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4160 break; 4255 break;
4161#ifdef TTY_256COLOR 4256 case 48: // set bg color, ISO 8613-6
4162 case 48:
4163 if (nargs > i + 2 && arg[i + 1] == 5) 4257 if (nargs > i + 2 && arg[i + 1] == 5)
4164 { 4258 {
4165 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg); 4259 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4166 i += 2; 4260 i += 2;
4167 } 4261 }
4168 break; 4262 break;
4169#endif
4170 case 49: /* default bg */ 4263 case 49: /* default bg */
4171 scr_color (Color_bg, Color_bg); 4264 scr_color (Color_bg, Color_bg);
4172 break; 4265 break;
4266
4267 //case 50: // not variable spacing
4173 4268
4174#ifndef NO_BRIGHTCOLOR 4269#ifndef NO_BRIGHTCOLOR
4175 case 90: 4270 case 90:
4176 case 91: /* set bright fg color */ 4271 case 91: /* set bright fg color */
4177 case 92: 4272 case 92:
4178 case 93: 4273 case 93:
4179 case 94: 4274 case 94:
4180 case 95: 4275 case 95:
4181 case 96: 4276 case 96:
4182 case 97: 4277 case 97:
4183 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), 4278 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 90)), Color_fg);
4184 Color_fg);
4185 break; 4279 break;
4186 case 100: 4280 case 100:
4187 case 101: /* set bright bg color */ 4281 case 101: /* set bright bg color */
4188 case 102: 4282 case 102:
4189 case 103: 4283 case 103:
4190 case 104: 4284 case 104:
4191 case 105: 4285 case 105:
4192 case 106: 4286 case 106:
4193 case 107: 4287 case 107:
4194 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), 4288 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4195 Color_bg);
4196 break; 4289 break;
4197#endif 4290#endif
4198 4291
4199 } 4292 }
4200 } 4293 }
4239 4332
4240/* ---------------------------------------------------------------------- */ 4333/* ---------------------------------------------------------------------- */
4241/* Write data to the pty as typed by the user, pasted with the mouse, 4334/* 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. 4335 * or generated by us in response to a query ESC sequence.
4243 */ 4336 */
4337const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4338
4244void 4339void
4245rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4340rxvt_term::tt_write (const unsigned char *data, unsigned int len)
4246{ 4341{
4247 enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT 4342 if (v_buflen == 0)
4343 {
4344 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE));
4248 4345
4249 if (len) 4346 if ((unsigned int)written == len)
4347 return;
4348
4349 data += written;
4350 len -= written;
4250 { 4351 }
4352
4353 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len);
4354
4355 memcpy (v_buffer + v_buflen, data, len);
4356 v_buflen += len;
4357
4358 pty_ev.set (EVENT_READ | EVENT_WRITE);
4359}
4360
4361void rxvt_term::pty_write ()
4362{
4363 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4364
4365 if (written > 0)
4366 {
4367 v_buflen -= written;
4368
4251 if (v_buflen == 0) 4369 if (v_buflen == 0)
4252 { 4370 {
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); 4371 free (v_buffer);
4280 v_buffer = 0; 4372 v_buffer = 0;
4281 v_buflen = 0; 4373 v_buflen = 0;
4282 4374
4283 pty_ev.set (EVENT_READ); 4375 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; 4376 return;
4296 } 4377 }
4378
4379 memmove (v_buffer, v_buffer + written, v_buflen);
4297 } 4380 }
4381 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4382 pty_ev.set (EVENT_READ);
4298} 4383}
4299 4384
4300/*----------------------- end-of-file (C source) -----------------------*/ 4385/*----------------------- end-of-file (C source) -----------------------*/
4301 4386

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines