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.198 by root, Sat Feb 19 01:07:58 2005 UTC vs.
Revision 1.304 by root, Tue Jan 31 22:01:25 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-2005 Marc Lehmann <pcg@goof.com> 30 * Copyright (c) 2003-2006 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.
43 * along with this program; if not, write to the Free Software 43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *----------------------------------------------------------------------*/ 45 *----------------------------------------------------------------------*/
46 46
47/*{{{ includes: */ 47/*{{{ includes: */
48#include "../config.h" /* NECESSARY */ 48#include "../config.h"
49#include "rxvt.h" /* NECESSARY */ 49#include "rxvt.h"
50#include "rxvtperl.h"
50#include "version.h" 51#include "version.h"
51#include "command.h" 52#include "command.h"
52 53
53#ifdef KEYSYM_RESOURCE 54#ifdef KEYSYM_RESOURCE
54# include "keyboard.h" 55# include "keyboard.h"
55#endif 56#endif
56 57
57#include <csignal> 58#include <csignal>
58 59
60#if LINUX_YIELD_HACK
61# include <ctime>
62#endif
63
59/*----------------------------------------------------------------------*/ 64/*----------------------------------------------------------------------*/
60 65
61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 66#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
62
63// exception thrown when the command parser runs out of input data
64class out_of_input { } out_of_input;
65 67
66#if ENABLE_FRILLS || ISO_14755 68#if ENABLE_FRILLS || ISO_14755
67 69
68#define ISO_14755_STARTED 0x80000000UL 70#define ISO_14755_STARTED 0x80000000UL
69#define ISO_14755_51 0x40000000UL // basic (section 5.1) 71#define ISO_14755_51 0x40000000UL // basic (section 5.1)
135rxvt_term::iso14755_54 (int x, int y) 137rxvt_term::iso14755_54 (int x, int y)
136{ 138{
137 x = Pixel2Col (x); 139 x = Pixel2Col (x);
138 y = Pixel2Row (y); 140 y = Pixel2Row (y);
139 141
140 if (x < 0 || x >= TermWin.ncol 142 if (!IN_RANGE_EXC (x, 0, ncol)
141 || y < 0 || y >= TermWin.nrow) 143 || !IN_RANGE_EXC (y, 0, nrow))
142 return; 144 return;
143 145
144 for (;;) 146 for (;;)
145 { 147 {
146 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x]; 148 const line_t &l = ROW(y + view_start);
149
150 text_t t = l.t[x];
147 151
148 if (t != NOCHAR || !x) 152 if (t != NOCHAR || !x)
149 { 153 {
150 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x], 154 iso14755_51 (l.t[x], l.r[x], x, y);
151 screen.rend[y + TermWin.saveLines - TermWin.view_start][x]);
152 iso14755buf = ISO_14755_54; 155 iso14755buf = ISO_14755_54;
153 break; 156 break;
154 } 157 }
155 158
156 x--; 159 x--;
157 } 160 }
158
159} 161}
160#endif
161 162
162#if ENABLE_OVERLAY
163void 163void
164rxvt_term::iso14755_51 (unicode_t ch, rend_t r) 164rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
165{ 165{
166 rxvt_fontset *fs = FONTSET (r); 166 rxvt_fontset *fs = FONTSET (r);
167 rxvt_font *f = (*fs)[fs->find_font (ch)]; 167 rxvt_font *f = (*fs)[fs->find_font (ch)];
168 wchar_t *chr, *alloc, ch2; 168 wchar_t *chr, *alloc, ch2, *fname;
169 int len; 169 int len;
170 170
171 fname = rxvt_utf8towcs (f->name);
172
171#if ENABLE_COMBINING 173# if ENABLE_COMBINING
172 if (IS_COMPOSE (ch)) 174 if (IS_COMPOSE (ch))
173 { 175 {
174 len = rxvt_composite.expand (ch, 0); 176 len = rxvt_composite.expand (ch, 0);
175 alloc = chr = new wchar_t[len]; 177 alloc = chr = new wchar_t[len];
176 rxvt_composite.expand (ch, chr); 178 rxvt_composite.expand (ch, chr);
177 } 179 }
178 else 180 else
179#endif 181# endif
180 { 182 {
181 ch2 = ch; 183 ch2 = ch;
182 184
183 alloc = 0; 185 alloc = 0;
184 chr = &ch2; 186 chr = &ch2;
185 len = 1; 187 len = 1;
186 } 188 }
187 189
188 int width = strlen (f->name); 190 char attr[80]; // plenty
189 191
190 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1); 192 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
193 (int)r,
194 fgcolor_of (r), bgcolor_of (r),
195 r & RS_Bold ? " bold" : "",
196 r & RS_Italic ? " italic" : "",
197 r & RS_Blink ? " blink" : "",
198 r & RS_RVid ? " rvid" : "",
199 r & RS_Uline ? " uline" : "",
200 r & RS_Careful ? " careful" : "");
201
202 int width = wcswidth (fname, wcslen (fname));
203
204 max_it (width, 8+5); // for char + hey
205 max_it (width, strlen (attr));
206
207 if (y >= 0)
208 {
209 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
210 x = 0;
211 }
212
213 scr_overlay_new (x, y, width, len + 2);
191 214
192 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 215 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
193 216
194 for (int y = 0; y < len; y++) 217 for (int y = 0; y < len; y++)
195 { 218 {
198 ch = *chr++; 221 ch = *chr++;
199 222
200 sprintf (buf, "%8x", ch); 223 sprintf (buf, "%8x", ch);
201 scr_overlay_set (0, y, buf); 224 scr_overlay_set (0, y, buf);
202 scr_overlay_set (9, y, '='); 225 scr_overlay_set (9, y, '=');
203#if !UNICODE3 226# if !UNICODE3
204 if (ch >= 0x10000) 227 if (ch >= 0x10000)
205 ch = 0xfffd; 228 ch = 0xfffd;
206#endif 229# endif
207 scr_overlay_set (11, y, ch, r); 230 scr_overlay_set (11, y, ch, r);
231
232 if (WCWIDTH (ch) >= 2)
208 scr_overlay_set (12, y, NOCHAR, r); 233 scr_overlay_set (12, y, NOCHAR, r);
209 } 234 }
210 235
236// {
237// char buf[4+4+3+1];
238// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y);
239// scr_overlay_set (0, 0, buf);
240// }
241 scr_overlay_set (0, len , attr);
211 scr_overlay_set (0, len, f->name); 242 scr_overlay_set (0, len + 1, fname);
212 243
244 free (fname);
245
213#if ENABLE_COMBINING 246# if ENABLE_COMBINING
214 if (alloc) 247 if (alloc)
215 delete [] alloc; 248 delete [] alloc;
216#endif 249# endif
217} 250}
218#endif 251#endif
219 252
220void 253void
221rxvt_term::commit_iso14755 () 254rxvt_term::commit_iso14755 ()
238 mb[0] = ch[0]; 271 mb[0] = ch[0];
239 len = 1; 272 len = 1;
240 } 273 }
241 274
242 if (len > 0) 275 if (len > 0)
243 tt_write ((unsigned char *)mb, len); 276 tt_write (mb, len);
244 else 277 else
245 scr_bell (); 278 scr_bell ();
246 } 279 }
247 280
248 iso14755buf = 0; 281 iso14755buf = 0;
272rxvt_term::lookup_key (XKeyEvent &ev) 305rxvt_term::lookup_key (XKeyEvent &ev)
273{ 306{
274 int ctrl, meta, shft, len; 307 int ctrl, meta, shft, len;
275 unsigned int newlen; 308 unsigned int newlen;
276 KeySym keysym; 309 KeySym keysym;
277#ifdef DEBUG_CMD
278 static int debug_key = 1; /* accessible by a debugger only */
279#endif
280 int valid_keysym; 310 int valid_keysym;
281 unsigned char kbuf[KBUFSZ]; 311 char kbuf[KBUFSZ];
282 312
283 /* 313 /*
284 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 314 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
285 * escape sequence to toggle the Keypad. 315 * escape sequence to toggle the Keypad.
286 * 316 *
304 Status status_return; 334 Status status_return;
305 335
306#if 0 336#if 0
307#ifdef X_HAVE_UTF8_STRING 337#ifdef X_HAVE_UTF8_STRING
308 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful 338 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
309 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 339 len = Xutf8LookupString (Input_Context, &ev, kbuf,
310 KBUFSZ, &keysym, &status_return); 340 KBUFSZ, &keysym, &status_return);
311 else 341 else
312#endif 342#endif
313#endif 343#endif
314 { 344 {
316 346
317 // the XOpenIM manpage lies about hardcoding the locale 347 // the XOpenIM manpage lies about hardcoding the locale
318 // at the point of XOpenIM, so temporarily switch locales 348 // at the point of XOpenIM, so temporarily switch locales
319 if (rs[Rs_imLocale]) 349 if (rs[Rs_imLocale])
320 SET_LOCALE (rs[Rs_imLocale]); 350 SET_LOCALE (rs[Rs_imLocale]);
351
321 // assume wchar_t == unicode or better 352 // assume wchar_t == unicode or better
322 len = XwcLookupString (Input_Context, &ev, wkbuf, 353 len = XwcLookupString (Input_Context, &ev, wkbuf,
323 KBUFSZ, &keysym, &status_return); 354 KBUFSZ, &keysym, &status_return);
355
324 if (rs[Rs_imLocale]) 356 if (rs[Rs_imLocale])
325 SET_LOCALE (locale); 357 SET_LOCALE (locale);
326 358
327 if (status_return == XLookupChars 359 if (status_return == XLookupChars
328 || status_return == XLookupBoth) 360 || status_return == XLookupBoth)
349 || status_return == XLookupBoth; 381 || status_return == XLookupBoth;
350 } 382 }
351 else 383 else
352#endif 384#endif
353 { 385 {
354 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); 386 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
355 valid_keysym = keysym != NoSymbol; 387 valid_keysym = keysym != NoSymbol;
356 } 388 }
357 389
358 if (valid_keysym) 390 if (valid_keysym)
359 { 391 {
360#ifdef KEYSYM_RESOURCE 392#ifdef KEYSYM_RESOURCE
361 if (keyboard->dispatch (this, keysym, ev.state)) 393 if (keyboard->dispatch (this, keysym, ev.state))
362 return; 394 return;
363#endif 395#endif
364 396
365 if (TermWin.saveLines) 397 if (saveLines)
366 { 398 {
367#ifdef UNSHIFTED_SCROLLKEYS 399#ifdef UNSHIFTED_SCROLLKEYS
368 if (!ctrl && !meta) 400 if (!ctrl && !meta)
369#else 401#else
370 if (IS_SCROLL_MOD) 402 if (IS_SCROLL_MOD)
371#endif 403#endif
372 { 404 {
373 int lnsppg; 405 int lnsppg;
374 406
375#ifdef PAGING_CONTEXT_LINES 407#ifdef PAGING_CONTEXT_LINES
376 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; 408 lnsppg = nrow - PAGING_CONTEXT_LINES;
377#else 409#else
378 lnsppg = TermWin.nrow * 4 / 5; 410 lnsppg = nrow * 4 / 5;
379#endif 411#endif
380 if (keysym == XK_Prior) 412 if (keysym == XK_Prior)
381 { 413 {
382 scr_page (UP, lnsppg); 414 scr_page (UP, lnsppg);
383 return; 415 return;
411 scr_move_to (0, 1); 443 scr_move_to (0, 1);
412 return; 444 return;
413 } 445 }
414 else if (keysym == XK_End) 446 else if (keysym == XK_End)
415 { 447 {
416 scr_move_to (1, 0); 448 scr_move_to (1, 1);
417 return; 449 return;
418 } 450 }
419 } 451 }
420#endif 452#endif
421 } 453 }
432 { 464 {
433 switch (keysym) 465 switch (keysym)
434 { 466 {
435 /* normal XTerm key bindings */ 467 /* normal XTerm key bindings */
436 case XK_Insert: /* Shift+Insert = paste mouse selection */ 468 case XK_Insert: /* Shift+Insert = paste mouse selection */
437 selection_request (ev.time, 0, 0); 469 selection_request (ev.time);
438 return; 470 return;
439#if TODO 471#if TODO
440 /* rxvt extras */ 472 /* rxvt extras */
441 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 473 case XK_KP_Add: /* Shift+KP_Add = bigger font */
442 change_font (FONT_UP); 474 change_font (FONT_UP);
823 { 855 {
824#ifdef META8_OPTION 856#ifdef META8_OPTION
825 /* set 8-bit on */ 857 /* set 8-bit on */
826 if (meta && (meta_char == 0x80)) 858 if (meta && (meta_char == 0x80))
827 { 859 {
828 unsigned char *ch; 860 char *ch;
829 861
830 for (ch = kbuf; ch < kbuf + len; ch++) 862 for (ch = kbuf; ch < kbuf + len; ch++)
831 *ch |= 0x80; 863 *ch |= 0x80;
832 864
833 meta = 0; 865 meta = 0;
835#endif 867#endif
836 /* nil */ ; 868 /* nil */ ;
837 } 869 }
838 } 870 }
839 871
872 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
873 return;
874
840 if (len <= 0) 875 if (len <= 0)
841 return; /* not mapped */ 876 return; /* not mapped */
842 877
843 if (options & Opt_scrollTtyKeypress) 878 if (OPTION (Opt_scrollTtyKeypress))
844 if (TermWin.view_start) 879 if (view_start)
845 { 880 {
846 TermWin.view_start = 0; 881 view_start = 0;
847 want_refresh = 1; 882 want_refresh = 1;
848 } 883 }
849 884
850 /* 885 /*
851 * these modifications only affect the static keybuffer 886 * these modifications only affect the static keybuffer
866#ifdef META8_OPTION 901#ifdef META8_OPTION
867 && meta_char == C0_ESC 902 && meta_char == C0_ESC
868#endif 903#endif
869 ) 904 )
870 { 905 {
871 const unsigned char ch = C0_ESC; 906 const char ch = C0_ESC;
872 tt_write (&ch, 1); 907 tt_write (&ch, 1);
873 } 908 }
874 909
875#if defined(DEBUG_CMD)
876 /* Display keyboard buffer contents */
877 unsigned char *p;
878 int i;
879
880 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
881 for (i = 0, p = kbuf; i < len; i++, p++)
882 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
883 fprintf (stderr, "'\n");
884#endif /* DEBUG_CMD */
885 tt_write (kbuf, (unsigned int)len); 910 tt_write (kbuf, (unsigned int)len);
886} 911}
887/*}}} */ 912/*}}} */
888 913
889#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) 914#if defined (KEYSYM_RESOURCE)
890/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
891/* attempt to `write' count to the input buffer */
892unsigned int 915unsigned int
893rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 916rxvt_term::cmd_write (const char *str, unsigned int count)
894{ 917{
895 unsigned int n, s; 918 unsigned int n, s;
896 919
897 n = cmdbuf_ptr - cmdbuf_base; 920 n = cmdbuf_ptr - cmdbuf_base;
898 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; 921 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
935 } 958 }
936#endif 959#endif
937 960
938 if (want_refresh) 961 if (want_refresh)
939 { 962 {
963 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
964 {
965 int row = view_start;
966 int end_row = row + nrow;
967
968 while (row > top_row && ROW (row - 1).is_longer ())
969 --row;
970
971 do
972 {
973 int start_row = row;
974 line_t *l;
975
976 do
977 {
978 l = &ROW (row++);
979
980 if (!(l->f & LINE_FILTERED))
981 {
982 // line not filtered, mark it as filtered
983 l->f |= LINE_FILTERED;
984 while (l->is_longer ())
985 {
986 l = &ROW (row++);
987 l->f |= LINE_FILTERED;
988 }
989
990 // and filter it
991 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
992
993 break;
994 }
995 }
996 while (l->is_longer () && row < end_row);
997 }
998 while (row < end_row);
999 }
1000
940 scr_refresh (refresh_type); 1001 scr_refresh ();
941 scrollbar_show (1); 1002 scrollbar_show (1);
942#ifdef USE_XIM 1003#ifdef USE_XIM
943 IMSendSpot (); 1004 IMSendSpot ();
944#endif 1005#endif
945 } 1006 }
948} 1009}
949 1010
950void 1011void
951rxvt_term::check_cb (check_watcher &w) 1012rxvt_term::check_cb (check_watcher &w)
952{ 1013{
953 SET_R (this); 1014 make_current ();
954 SET_LOCALE (locale);
955 1015
956 display->flush (); 1016 display->flush ();
957 1017
958 if (want_refresh && !flush_ev.active) 1018 if (want_refresh && !flush_ev.active)
959 flush_ev.start (NOW + 0.01); 1019 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
960} 1020}
961 1021
962void 1022void
963rxvt_term::flush_cb (time_watcher &w) 1023rxvt_term::flush_cb (time_watcher &w)
964{ 1024{
965 SET_R (this); 1025 make_current ();
966 SET_LOCALE (locale);
967 1026
968 refresh_limit = 1; 1027 refresh_limit = 1;
969 refresh_count = 0; 1028 refresh_count = 0;
970 flush (); 1029 flush ();
971} 1030}
975rxvt_term::cursor_blink_cb (time_watcher &w) 1034rxvt_term::cursor_blink_cb (time_watcher &w)
976{ 1035{
977 hidden_cursor = !hidden_cursor; 1036 hidden_cursor = !hidden_cursor;
978 want_refresh = 1; 1037 want_refresh = 1;
979 1038
980 w.start (w.at + BLINK_INTERVAL); 1039 w.start (w.at + CURSOR_BLINK_INTERVAL);
981} 1040}
982#endif 1041#endif
983 1042
984#ifdef TEXT_BLINK 1043#ifdef TEXT_BLINK
985void 1044void
999rxvt_term::cont_scroll_cb (time_watcher &w) 1058rxvt_term::cont_scroll_cb (time_watcher &w)
1000{ 1059{
1001 if ((scrollbar_isUp() || scrollbar_isDn()) && 1060 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1002 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1061 scr_page (scrollbar_isUp() ? UP : DN, 1))
1003 { 1062 {
1004 refresh_type |= SMOOTH_REFRESH;
1005 want_refresh = 1; 1063 want_refresh = 1;
1006 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1064 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1007 } 1065 }
1008} 1066}
1009#endif 1067#endif
1013rxvt_term::sel_scroll_cb (time_watcher &w) 1071rxvt_term::sel_scroll_cb (time_watcher &w)
1014{ 1072{
1015 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1073 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1016 { 1074 {
1017 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1075 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1018 refresh_type |= SMOOTH_REFRESH;
1019 want_refresh = 1; 1076 want_refresh = 1;
1020 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1077 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1021 } 1078 }
1022} 1079}
1023#endif 1080#endif
1028{ 1085{
1029 if (mouse_slip_wheel_speed == 0 1086 if (mouse_slip_wheel_speed == 0
1030 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1087 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1031 : scr_page (UP, mouse_slip_wheel_speed)) 1088 : scr_page (UP, mouse_slip_wheel_speed))
1032 { 1089 {
1033 if (TermWin.view_start == TermWin.nscrolled || 1090 if (view_start == top_row || view_start == 0)
1034 TermWin.view_start == 0)
1035 mouse_slip_wheel_speed = 0; 1091 mouse_slip_wheel_speed = 0;
1036 1092
1037 refresh_type |= SMOOTH_REFRESH;
1038 want_refresh = 1; 1093 want_refresh = 1;
1039 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1094 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1040 } 1095 }
1041} 1096}
1042#endif 1097#endif
1043 1098
1099#if LINUX_YIELD_HACK
1100static struct event_handler
1101{
1102 check_watcher yield_ev;
1103
1104 void yield_cb (check_watcher &w)
1105 {
1106 // this should really be sched_yield(), but the linux guys thought
1107 // that giving a process calling sched_yield () less cpu time than
1108 // ones with high nice levels is a useful thing to do. It surely is is
1109 // allowed by the sus... as is returning ENOSYS.
1110
1111 struct timespec ts = { 0, 0 };
1112 nanosleep (&ts, 0);
1113
1114 w.stop ();
1115 }
1116
1117 event_handler ()
1118 : yield_ev (this, &event_handler::yield_cb)
1119 {
1120 }
1121} event_handler;
1122#endif
1123
1044bool 1124bool
1045rxvt_term::pty_fill () 1125rxvt_term::pty_fill ()
1046{ 1126{
1047 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1127 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1048 1128
1049 if (CBUFSIZ == n) 1129 if (CBUFSIZ == n)
1050 { 1130 {
1051 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); 1131 rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n");
1052 n = 0; 1132 n = 0;
1053 } 1133 }
1054 1134
1055 memmove (cmdbuf_base, cmdbuf_ptr, n); 1135 memmove (cmdbuf_base, cmdbuf_ptr, n);
1056 cmdbuf_ptr = cmdbuf_base; 1136 cmdbuf_ptr = cmdbuf_base;
1057 cmdbuf_endp = cmdbuf_ptr + n; 1137 cmdbuf_endp = cmdbuf_ptr + n;
1058 1138
1059 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1139 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1060 1140
1061 if (n > 0) 1141 if (r > 0)
1062 { 1142 {
1063 cmdbuf_endp += n; 1143 cmdbuf_endp += r;
1064 return true; 1144 return true;
1065 } 1145 }
1066 else if (n < 0 && errno != EAGAIN) 1146 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1147 {
1148#if LINUX_YIELD_HACK
1149 if (display->is_local)
1150 event_handler.yield_ev.start ();
1151#endif
1152 }
1153 else
1154 {
1155 pty_ev.stop ();
1156
1157 if (!OPTION (Opt_hold))
1067 destroy (); 1158 destroy ();
1159 }
1068 1160
1069 return false; 1161 return false;
1070} 1162}
1071 1163
1072void 1164void
1073rxvt_term::pty_cb (io_watcher &w, short revents) 1165rxvt_term::pty_cb (io_watcher &w, short revents)
1074{ 1166{
1075 SET_R (this); 1167 make_current ();
1076 SET_LOCALE (locale);
1077 1168
1078 if (revents & EVENT_READ) 1169 if (revents & EVENT_READ)
1079 // loop, but don't allow a single term to monopolize us 1170 // loop, but don't allow a single term to monopolize us
1080 while (pty_fill ()) 1171 while (pty_fill ())
1081 if (cmd_parse ()) 1172 if (cmd_parse ())
1086} 1177}
1087 1178
1088void 1179void
1089rxvt_term::pointer_unblank () 1180rxvt_term::pointer_unblank ()
1090{ 1181{
1091 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1182 XDefineCursor (xdisp, vt, TermWin_cursor);
1092 recolour_cursor (); 1183 recolour_cursor ();
1093 1184
1094#ifdef POINTER_BLANK 1185#ifdef POINTER_BLANK
1095 hidden_pointer = 0; 1186 hidden_pointer = 0;
1096 1187
1097 if (options & Opt_pointerBlank) 1188 if (OPTION (Opt_pointerBlank))
1098 pointer_ev.start (NOW + pointerBlankDelay); 1189 pointer_ev.start (NOW + pointerBlankDelay);
1099#endif 1190#endif
1100} 1191}
1101 1192
1102#ifdef POINTER_BLANK 1193#ifdef POINTER_BLANK
1103void 1194void
1104rxvt_term::pointer_blank () 1195rxvt_term::pointer_blank ()
1105{ 1196{
1106 if (! (options & Opt_pointerBlank)) 1197 if (!OPTION (Opt_pointerBlank))
1107 return; 1198 return;
1108 1199
1109 XDefineCursor (display->display, TermWin.vt, display->blank_cursor); 1200 XDefineCursor (xdisp, vt, display->blank_cursor);
1110 XFlush (display->display); 1201 XFlush (xdisp);
1111 1202
1112 hidden_pointer = 1; 1203 hidden_pointer = 1;
1113} 1204}
1114 1205
1115void 1206void
1116rxvt_term::pointer_cb (time_watcher &w) 1207rxvt_term::pointer_cb (time_watcher &w)
1117{ 1208{
1118 SET_R (this); 1209 make_current ();
1119 SET_LOCALE (locale);
1120 1210
1121 pointer_blank (); 1211 pointer_blank ();
1122} 1212}
1123#endif 1213#endif
1124 1214
1189 (32 + button_number + key_state), 1279 (32 + button_number + key_state),
1190 (32 + x + 1), 1280 (32 + x + 1),
1191 (32 + y + 1)); 1281 (32 + y + 1));
1192} 1282}
1193 1283
1194#ifdef USING_W11LIB
1195void
1196rxvt_W11_process_x_event (XEvent *ev)
1197{
1198 rxvt_t *r = rxvt_get_r ();
1199
1200 x_cb (*ev);
1201}
1202#endif
1203
1204/*{{{ process an X event */ 1284/*{{{ process an X event */
1205void 1285void
1206rxvt_term::x_cb (XEvent &ev) 1286rxvt_term::x_cb (XEvent &ev)
1207{ 1287{
1208 dDisp; 1288 make_current ();
1209 1289
1210 SET_R (this); 1290 dLocal (Display *, xdisp);
1211 SET_LOCALE (locale);
1212 1291
1213#if defined(CURSOR_BLINK) 1292 if (ev.xany.window == vt
1214 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1293 && SHOULD_INVOKE (HOOK_X_EVENT)
1215 { 1294 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1216 if (hidden_cursor) 1295 return;
1217 {
1218 hidden_cursor = 0;
1219 want_refresh = 1;
1220 }
1221 1296
1222 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1297 // for XQueryPointer
1223 }
1224#endif
1225
1226#if defined(POINTER_BLANK)
1227 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1228 {
1229 if (ev.type == MotionNotify
1230 || ev.type == ButtonPress
1231 || ev.type == ButtonRelease)
1232 if (hidden_pointer)
1233 pointer_unblank ();
1234
1235 if (ev.type == KeyPress && hidden_pointer == 0)
1236 pointer_blank ();
1237 }
1238#endif
1239
1240 Window unused_root, unused_child; 1298 Window unused_root, unused_child;
1241 int unused_root_x, unused_root_y; 1299 int unused_root_x, unused_root_y;
1242 unsigned int unused_mask; 1300 unsigned int unused_mask;
1243 1301
1244 switch (ev.type) 1302 switch (ev.type)
1251 1309
1252 break; 1310 break;
1253 1311
1254 case KeyRelease: 1312 case KeyRelease:
1255 { 1313 {
1256#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 1314#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1257 KeySym ks; 1315 KeySym keysym;
1258 1316
1259 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ 1317 keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1260#endif 1318#endif
1261 1319
1262#if ENABLE_FRILLS || ISO_14755 1320#if ENABLE_FRILLS || ISO_14755
1263 // ISO 14755 support 1321 // ISO 14755 support
1264 if (iso14755buf) 1322 if (iso14755buf)
1269# endif 1327# endif
1270# if ISO_14755 1328# if ISO_14755
1271 // iso14755 part 5.2 handling: release time 1329 // iso14755 part 5.2 handling: release time
1272 // first: controls 1330 // first: controls
1273 if ((ev.xkey.state & ControlMask) 1331 if ((ev.xkey.state & ControlMask)
1274 && ((ks >= 0x40 && ks <= 0x5f) 1332 && ((keysym >= 0x40 && keysym <= 0x5f)
1275 || (ks >= 0x61 && ks <= 0x7f))) 1333 || (keysym >= 0x61 && keysym <= 0x7f)))
1276 { 1334 {
1277 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f); 1335 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1278 commit_iso14755 (); 1336 commit_iso14755 ();
1279 return; // case-break; 1337 goto skip_switch;
1280 } 1338 }
1281 1339
1282 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) 1340 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1283 if (i[0] == ks) 1341 if (i[0] == keysym)
1284 { 1342 {
1285 iso14755buf = ISO_14755_51 | i[1]; 1343 iso14755buf = ISO_14755_51 | i[1];
1286 commit_iso14755 (); 1344 commit_iso14755 ();
1287 return; // case-break; 1345 goto skip_switch;
1288 } 1346 }
1289 1347
1290 scr_bell (); 1348 scr_bell ();
1291# endif 1349# endif
1292 iso14755buf = 0; 1350 iso14755buf = 0;
1311 else 1369 else
1312 iso14755buf = 0; 1370 iso14755buf = 0;
1313 } 1371 }
1314#endif 1372#endif
1315 1373
1374 if (ev.xany.window == vt
1375 && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
1376 break;
1377
1316#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1378#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1317 if (!(ev.xkey.state & ControlMask)) 1379 if (!(ev.xkey.state & ControlMask))
1318 slip_wheel_ev.stop (); 1380 slip_wheel_ev.stop ();
1319 else if (ks == XK_Control_L || ks == XK_Control_R) 1381 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1320 mouse_slip_wheel_speed = 0; 1382 mouse_slip_wheel_speed = 0;
1321#endif 1383#endif
1322 break; 1384 break;
1323 } 1385 }
1324 1386
1330 button_release (ev.xbutton); 1392 button_release (ev.xbutton);
1331 break; 1393 break;
1332 1394
1333 case ClientMessage: 1395 case ClientMessage:
1334 if (ev.xclient.format == 32 1396 if (ev.xclient.format == 32
1397 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1398 {
1335 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS] 1399 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1400 {
1401 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1402 {
1336 && ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1403 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1337 destroy (); 1404 {
1405 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1406 destroy ();
1407 }
1408#if ENABLE_EWMH
1409 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1410 XSendEvent (xdisp, ev.xclient.window = display->root,
1411 False, SubstructureRedirectMask | SubstructureNotifyMask,
1412 &ev);
1413#endif
1414 }
1415 }
1338#if ENABLE_XEMBED 1416#if ENABLE_XEMBED
1339 else if (ev.xclient.format == 32
1340 && ev.xclient.message_type == xa[XA_XEMBED]) 1417 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1341 { 1418 {
1342 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) 1419 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1343 focus_in (); 1420 focus_in ();
1344 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1421 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1345 focus_out (); 1422 focus_out ();
1423 }
1424#endif
1346 } 1425 }
1347#endif
1348#ifdef OFFIX_DND
1349 /* OffiX Dnd (drag 'n' drop) protocol */
1350 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1351 && (ev.xclient.data.l[0] == DndFile
1352 || ev.xclient.data.l[0] == DndDir
1353 || ev.xclient.data.l[0] == DndLink))
1354 {
1355 /* Get Dnd data */
1356 Atom ActualType;
1357 int ActualFormat;
1358 unsigned char *data;
1359 unsigned long Size, RemainingBytes;
1360
1361 XGetWindowProperty (disp, display->root,
1362 xa[XA_DNDSELECTION],
1363 0L, 1000000L,
1364 False, AnyPropertyType,
1365 &ActualType, &ActualFormat,
1366 &Size, &RemainingBytes,
1367 &data);
1368 set_string_property (XA_CUT_BUFFER0, data);
1369 XFree (data);
1370 selection_paste (display->root, XA_CUT_BUFFER0, true);
1371 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1372 }
1373#endif /* OFFIX_DND */
1374 break; 1426 break;
1375 1427
1376 case MappingNotify: 1428 case MappingNotify:
1377 XRefreshKeyboardMapping (&ev.xmapping); 1429 XRefreshKeyboardMapping (&ev.xmapping);
1378 break; 1430 break;
1409 case FocusOut: 1461 case FocusOut:
1410 focus_out (); 1462 focus_out ();
1411 break; 1463 break;
1412 1464
1413 case ConfigureNotify: 1465 case ConfigureNotify:
1414 if (ev.xconfigure.window == TermWin.parent[0]) 1466 if (ev.xconfigure.window == parent[0])
1415 { 1467 {
1416 int height, width;
1417
1418 do
1419 { /* Wrap lots of configures into one */
1420 width = ev.xconfigure.width;
1421 height = ev.xconfigure.height;
1422 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1423 }
1424 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)); 1468 while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev))
1469 ;
1425 1470
1426 if (szHint.width != width || szHint.height != height) 1471 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1427 { 1472 {
1428 seen_resize = 1; 1473 seen_resize = 1;
1429 resize_all_windows (width, height, 1); 1474 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1430 } 1475 }
1431 1476
1477 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1478
1432#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1479#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1433 if (options & Opt_transparent) 1480 if (OPTION (Opt_transparent))
1434 check_our_parents (); 1481 check_our_parents ();
1435#endif 1482#endif
1436 } 1483 }
1437 break; 1484 break;
1438 1485
1439 case PropertyNotify: 1486 case PropertyNotify:
1487 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1440 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1488 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1441 && ev.xproperty.state == PropertyNewValue) 1489 && ev.xproperty.state == PropertyNewValue)
1442 selection_property (ev.xproperty.window, ev.xproperty.atom); 1490 selection_property (ev.xproperty.window, ev.xproperty.atom);
1443 1491
1444 break; 1492 break;
1445 1493
1446 case SelectionClear: 1494 case SelectionClear:
1447 selection_clear (); 1495 selection_clear ();
1454 1502
1455 case SelectionRequest: 1503 case SelectionRequest:
1456 selection_send (ev.xselectionrequest); 1504 selection_send (ev.xselectionrequest);
1457 break; 1505 break;
1458 1506
1507 case MapNotify:
1508 mapped = 1;
1509#ifdef TEXT_BLINK
1510 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1511#endif
1512 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1513 break;
1514
1459 case UnmapNotify: 1515 case UnmapNotify:
1460 TermWin.mapped = 0; 1516 mapped = 0;
1461#ifdef TEXT_BLINK 1517#ifdef TEXT_BLINK
1462 text_blink_ev.stop (); 1518 text_blink_ev.stop ();
1463#endif 1519#endif
1464 break; 1520 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1465
1466 case MapNotify:
1467 TermWin.mapped = 1;
1468#ifdef TEXT_BLINK
1469 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1470#endif
1471 break; 1521 break;
1472 1522
1473#ifdef TRANSPARENT 1523#ifdef TRANSPARENT
1474 case ReparentNotify: 1524 case ReparentNotify:
1475 rootwin_cb (ev); 1525 rootwin_cb (ev);
1476 break; 1526 break;
1477#endif /* TRANSPARENT */ 1527#endif /* TRANSPARENT */
1478 1528
1479 case GraphicsExpose: 1529 case GraphicsExpose:
1480 case Expose: 1530 case Expose:
1481 if (ev.xany.window == TermWin.vt) 1531 if (ev.xany.window == vt)
1482 { 1532 {
1483 do 1533 do
1484 scr_expose (ev.xexpose.x, ev.xexpose.y, 1534 scr_expose (ev.xexpose.x, ev.xexpose.y,
1485 ev.xexpose.width, ev.xexpose.height, False); 1535 ev.xexpose.width, ev.xexpose.height, False);
1486 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); 1536 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev));
1487 1537
1488 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1538 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1489 1539
1490 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) 1540 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev))
1491 scr_expose (ev.xexpose.x, ev.xexpose.y, 1541 scr_expose (ev.xexpose.x, ev.xexpose.y,
1492 ev.xexpose.width, ev.xexpose.height, False); 1542 ev.xexpose.width, ev.xexpose.height, False);
1493 1543
1494 scr_refresh (refresh_type); 1544 want_refresh = 1;
1495 } 1545 }
1496 else 1546 else
1497 { 1547 {
1498 XEvent unused_event; 1548 XEvent unused_event;
1499 1549
1500 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1550 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event))
1501 ; 1551 ;
1502 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1552 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event))
1503 ; 1553 ;
1504 1554
1505 if (isScrollbarWindow (ev.xany.window)) 1555 if (isScrollbarWindow (ev.xany.window))
1506 { 1556 {
1507 scrollBar.setIdle (); 1557 scrollBar.setIdle ();
1508 scrollbar_show (0); 1558 scrollbar_show (0);
1509 } 1559 }
1510#ifdef MENUBAR
1511 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1512 menubar_expose ();
1513#endif
1514 1560
1515#ifdef TRANSPARENT 1561#ifdef TRANSPARENT
1516 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1562 if (am_transparent && ev.xany.window == parent[0])
1517 XClearWindow (disp, ev.xany.window); 1563 XClearWindow (xdisp, ev.xany.window);
1518#endif 1564#endif
1519 } 1565 }
1520 break; 1566 break;
1521 1567
1522 case MotionNotify: 1568 case MotionNotify:
1523#ifdef POINTER_BLANK 1569#ifdef POINTER_BLANK
1524 if (hidden_pointer) 1570 if (hidden_pointer)
1525 pointer_unblank (); 1571 pointer_unblank ();
1526#endif 1572#endif
1527#if MENUBAR
1528 if (isMenuBarWindow (ev.xany.window))
1529 {
1530 menubar_control (ev.xbutton);
1531 break;
1532 }
1533#endif
1534 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1573 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1535 break; 1574 break;
1536 1575
1537 if (ev.xany.window == TermWin.vt) 1576 if (ev.xany.window == vt)
1538 { 1577 {
1578 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1579 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1580 ; // nop
1539 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1581 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1540 { 1582 {
1541 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) 1583 while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev))
1542 ; 1584 ;
1543 1585
1544 XQueryPointer (disp, TermWin.vt, 1586 XQueryPointer (xdisp, vt,
1545 &unused_root, &unused_child, 1587 &unused_root, &unused_child,
1546 &unused_root_x, &unused_root_y, 1588 &unused_root_x, &unused_root_y,
1547 &ev.xbutton.x, &ev.xbutton.y, 1589 &ev.xbutton.x, &ev.xbutton.y,
1548 &ev.xbutton.state); 1590 &ev.xbutton.state);
1549#ifdef MOUSE_THRESHOLD 1591#ifdef MOUSE_THRESHOLD
1561#endif 1603#endif
1562 selection_extend (ev.xbutton.x, ev.xbutton.y, 1604 selection_extend (ev.xbutton.x, ev.xbutton.y,
1563 ev.xbutton.state & Button3Mask ? 2 : 0); 1605 ev.xbutton.state & Button3Mask ? 2 : 0);
1564 1606
1565#ifdef SELECTION_SCROLLING 1607#ifdef SELECTION_SCROLLING
1566 if (ev.xbutton.y < TermWin.int_bwidth 1608 if (ev.xbutton.y < int_bwidth
1567 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1609 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1568 { 1610 {
1569 int dist; 1611 int dist;
1570 1612
1571 /* don't clobber the current delay if we are 1613 /* don't clobber the current delay if we are
1572 * already in the middle of scrolling. 1614 * already in the middle of scrolling.
1580 selection_save_x = ev.xbutton.x; 1622 selection_save_x = ev.xbutton.x;
1581 selection_save_y = ev.xbutton.y; 1623 selection_save_y = ev.xbutton.y;
1582 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1624 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1583 1625
1584 /* calc number of lines to scroll */ 1626 /* calc number of lines to scroll */
1585 if (ev.xbutton.y < TermWin.int_bwidth) 1627 if (ev.xbutton.y < int_bwidth)
1586 { 1628 {
1587 scroll_selection_dir = UP; 1629 scroll_selection_dir = UP;
1588 dist = TermWin.int_bwidth - ev.xbutton.y; 1630 dist = int_bwidth - ev.xbutton.y;
1589 } 1631 }
1590 else 1632 else
1591 { 1633 {
1592 scroll_selection_dir = DN; 1634 scroll_selection_dir = DN;
1593 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1635 dist = ev.xbutton.y - (int_bwidth + height);
1594 } 1636 }
1595 1637
1596 scroll_selection_lines = Pixel2Height (dist) 1638 scroll_selection_lines = Pixel2Height (dist)
1597 / SELECTION_SCROLL_LINE_SPEEDUP 1639 / SELECTION_SCROLL_LINE_SPEEDUP
1598 + 1; 1640 + 1;
1599 MIN_IT (scroll_selection_lines, 1641 min_it (scroll_selection_lines,
1600 SELECTION_SCROLL_MAX_LINES); 1642 SELECTION_SCROLL_MAX_LINES);
1601 } 1643 }
1602 else 1644 else
1603 { 1645 {
1604 /* we are within the text window, so we 1646 /* we are within the text window, so we
1613#endif 1655#endif
1614 } 1656 }
1615 } 1657 }
1616 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1658 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1617 { 1659 {
1618 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1660 while (XCheckTypedWindowEvent (xdisp, scrollBar.win,
1619 MotionNotify, &ev)) 1661 MotionNotify, &ev))
1620 ; 1662 ;
1621 1663
1622 XQueryPointer (disp, scrollBar.win, 1664 XQueryPointer (xdisp, scrollBar.win,
1623 &unused_root, &unused_child, 1665 &unused_root, &unused_child,
1624 &unused_root_x, &unused_root_y, 1666 &unused_root_x, &unused_root_y,
1625 &ev.xbutton.x, &ev.xbutton.y, 1667 &ev.xbutton.x, &ev.xbutton.y,
1626 &unused_mask); 1668 &unused_mask);
1627 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1669 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1628 scrollbar_size ()); 1670 scrollbar_size ());
1629 scr_refresh (refresh_type); 1671 want_refresh = 1;
1630 refresh_limit = 0; 1672 refresh_limit = 0;
1631 scrollbar_show (1); 1673 scrollbar_show (1);
1632 } 1674 }
1633 break; 1675 break;
1634 } 1676 }
1677
1678skip_switch: ;
1679
1680#if defined(CURSOR_BLINK)
1681 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress)
1682 {
1683 if (hidden_cursor)
1684 {
1685 hidden_cursor = 0;
1686 want_refresh = 1;
1687 }
1688
1689 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1690 }
1691#endif
1692
1693#if defined(POINTER_BLANK)
1694 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0)
1695 {
1696 if (ev.type == MotionNotify
1697 || ev.type == ButtonPress
1698 || ev.type == ButtonRelease)
1699 if (hidden_pointer)
1700 pointer_unblank ();
1701
1702 if (ev.type == KeyPress && hidden_pointer == 0)
1703 pointer_blank ();
1704 }
1705#endif
1635} 1706}
1636 1707
1637void 1708void
1638rxvt_term::focus_in () 1709rxvt_term::focus_in ()
1639{ 1710{
1640 if (!TermWin.focus) 1711 if (!focus)
1641 { 1712 {
1642 TermWin.focus = 1; 1713 focus = 1;
1643 want_refresh = 1; 1714 want_refresh = 1;
1715
1716 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1717
1644#ifdef USE_XIM 1718#if USE_XIM
1645 if (Input_Context != NULL) 1719 if (Input_Context != NULL)
1646 { 1720 {
1647 IMSetStatusPosition (); 1721 IMSetStatusPosition ();
1648 XSetICFocus (Input_Context); 1722 XSetICFocus (Input_Context);
1649 } 1723 }
1650#endif 1724#endif
1651#ifdef CURSOR_BLINK 1725#if CURSOR_BLINK
1652 if (options & Opt_cursorBlink) 1726 if (OPTION (Opt_cursorBlink))
1653 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1727 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1654#endif 1728#endif
1655#ifdef OFF_FOCUS_FADING 1729#if OFF_FOCUS_FADING
1656 if (rs[Rs_fade]) 1730 if (rs[Rs_fade])
1657 { 1731 {
1658 pix_colors = pix_colors_focused; 1732 pix_colors = pix_colors_focused;
1659 scr_recolour (); 1733 scr_recolour ();
1660 } 1734 }
1663} 1737}
1664 1738
1665void 1739void
1666rxvt_term::focus_out () 1740rxvt_term::focus_out ()
1667{ 1741{
1668 if (TermWin.focus) 1742 if (focus)
1669 { 1743 {
1670 TermWin.focus = 0; 1744 focus = 0;
1671 want_refresh = 1; 1745 want_refresh = 1;
1672 1746
1747 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1748
1673#if ENABLE_FRILLS || ISO_14755 1749#if ENABLE_FRILLS || ISO_14755
1750 if (iso14755buf)
1751 {
1674 iso14755buf = 0; 1752 iso14755buf = 0;
1675#endif
1676#if ENABLE_OVERLAY 1753# if ENABLE_OVERLAY
1677 scr_overlay_off (); 1754 scr_overlay_off ();
1678#endif 1755# endif
1756 }
1757#endif
1679#ifdef USE_XIM 1758#if USE_XIM
1680 if (Input_Context != NULL) 1759 if (Input_Context != NULL)
1681 XUnsetICFocus (Input_Context); 1760 XUnsetICFocus (Input_Context);
1682#endif 1761#endif
1683#ifdef CURSOR_BLINK 1762#if CURSOR_BLINK
1684 if (options & Opt_cursorBlink) 1763 if (OPTION (Opt_cursorBlink))
1685 cursor_blink_ev.stop (); 1764 cursor_blink_ev.stop ();
1686 hidden_cursor = 0; 1765 hidden_cursor = 0;
1687#endif 1766#endif
1688#ifdef OFF_FOCUS_FADING 1767#if OFF_FOCUS_FADING
1689 if (rs[Rs_fade]) 1768 if (rs[Rs_fade])
1690 { 1769 {
1691 pix_colors = pix_colors_unfocused; 1770 pix_colors = pix_colors_unfocused;
1692 scr_recolour (); 1771 scr_recolour ();
1693 } 1772 }
1697 1776
1698#if TRANSPARENT 1777#if TRANSPARENT
1699void 1778void
1700rxvt_term::rootwin_cb (XEvent &ev) 1779rxvt_term::rootwin_cb (XEvent &ev)
1701{ 1780{
1702 SET_R (this); 1781 make_current ();
1703 SET_LOCALE (locale);
1704 1782
1705 switch (ev.type) 1783 switch (ev.type)
1706 { 1784 {
1707 case PropertyNotify: 1785 case PropertyNotify:
1708 /* 1786 /*
1713 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1791 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1714 return; 1792 return;
1715 1793
1716 /* FALLTHROUGH */ 1794 /* FALLTHROUGH */
1717 case ReparentNotify: 1795 case ReparentNotify:
1718 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1796 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1719 want_refresh = want_full_refresh = 1; 1797 want_refresh = want_full_refresh = 1;
1720 break; 1798 break;
1721 } 1799 }
1722} 1800}
1723#endif 1801#endif
1726rxvt_term::button_press (XButtonEvent &ev) 1804rxvt_term::button_press (XButtonEvent &ev)
1727{ 1805{
1728 int reportmode = 0, clickintime; 1806 int reportmode = 0, clickintime;
1729 1807
1730 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1808 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1809
1731 if (!bypass_keystate) 1810 if (!bypass_keystate)
1732 reportmode = !! (priv_modes & PrivMode_mouse_report); 1811 reportmode = !! (priv_modes & PrivMode_mouse_report);
1733 1812
1734 /* 1813 /*
1735 * VT window processing of button press 1814 * VT window processing of button press
1736 */ 1815 */
1737 if (ev.window == TermWin.vt) 1816 if (ev.window == vt)
1738 { 1817 {
1818 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1819 return;
1820
1739#if ISO_14755 1821#if ISO_14755
1740 // 5.4 1822 // 5.4
1741 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1823 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1742 { 1824 {
1743 iso14755_54 (ev.x, ev.y); 1825 iso14755_54 (ev.x, ev.y);
1755#ifdef MOUSE_REPORT_DOUBLECLICK 1837#ifdef MOUSE_REPORT_DOUBLECLICK
1756 if (ev.button == MEvent.button && clickintime) 1838 if (ev.button == MEvent.button && clickintime)
1757 { 1839 {
1758 /* same button, within alloted time */ 1840 /* same button, within alloted time */
1759 MEvent.clicks++; 1841 MEvent.clicks++;
1842
1760 if (MEvent.clicks > 1) 1843 if (MEvent.clicks > 1)
1761 { 1844 {
1762 /* only report double clicks */ 1845 /* only report double clicks */
1763 MEvent.clicks = 2; 1846 MEvent.clicks = 2;
1764 mouse_report (ev); 1847 mouse_report (ev);
1796#else 1879#else
1797 selection.rect = false; 1880 selection.rect = false;
1798#endif 1881#endif
1799 1882
1800 /* allow shift+left click to extend selection */ 1883 /* allow shift+left click to extend selection */
1801 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1884 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1802 { 1885 {
1803 if (MEvent.button == Button1 && clickintime) 1886 if (MEvent.button == Button1 && clickintime)
1804 selection_rotate (ev.x, ev.y); 1887 selection_rotate (ev.x, ev.y);
1805 else 1888 else
1806 selection_extend (ev.x, ev.y, 1); 1889 selection_extend (ev.x, ev.y, 1);
1947 case Button3: 2030 case Button3:
1948 if (scrollBar.style != R_SB_XTERM) 2031 if (scrollBar.style != R_SB_XTERM)
1949 { 2032 {
1950 if (scrollbar_above_slider (ev.y)) 2033 if (scrollbar_above_slider (ev.y))
1951# ifdef RXVT_SCROLL_FULL 2034# ifdef RXVT_SCROLL_FULL
1952 scr_page (UP, TermWin.nrow - 1); 2035 scr_page (UP, nrow - 1);
1953# else 2036# else
1954 scr_page (UP, TermWin.nrow / 4); 2037 scr_page (UP, nrow / 4);
1955# endif 2038# endif
1956 else if (scrollbar_below_slider (ev.y)) 2039 else if (scrollbar_below_slider (ev.y))
1957# ifdef RXVT_SCROLL_FULL 2040# ifdef RXVT_SCROLL_FULL
1958 scr_page (DN, TermWin.nrow - 1); 2041 scr_page (DN, nrow - 1);
1959# else 2042# else
1960 scr_page (DN, TermWin.nrow / 4); 2043 scr_page (DN, nrow / 4);
1961# endif 2044# endif
1962 else 2045 else
1963 scrollBar.setMotion (); 2046 scrollBar.setMotion ();
1964 } 2047 }
1965 else 2048 else
1966 { 2049 {
1967 scr_page ((ev.button == Button1 ? DN : UP), 2050 scr_page ((ev.button == Button1 ? DN : UP),
1968 (TermWin.nrow 2051 (nrow
1969 * scrollbar_position (ev.y) 2052 * scrollbar_position (ev.y)
1970 / scrollbar_size ())); 2053 / scrollbar_size ()));
1971 } 2054 }
1972 2055
1973 break; 2056 break;
1974 } 2057 }
1975 } 2058 }
2059
1976 return; 2060 return;
1977 } 2061 }
1978#if MENUBAR
1979 /*
1980 * Menubar window processing of button press
1981 */
1982 if (isMenuBarWindow (ev.window))
1983 menubar_control (ev);
1984#endif
1985} 2062}
1986 2063
1987void 2064void
1988rxvt_term::button_release (XButtonEvent &ev) 2065rxvt_term::button_release (XButtonEvent &ev)
1989{ 2066{
1995 2072
1996 if (scrollbar_isUpDn ()) 2073 if (scrollbar_isUpDn ())
1997 { 2074 {
1998 scrollBar.setIdle (); 2075 scrollBar.setIdle ();
1999 scrollbar_show (0); 2076 scrollbar_show (0);
2000#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2001 refresh_type &= ~SMOOTH_REFRESH;
2002#endif
2003 } 2077 }
2004 2078
2005#ifdef SELECTION_SCROLLING 2079#ifdef SELECTION_SCROLLING
2006 if (sel_scroll_ev.active) 2080 if (sel_scroll_ev.active)
2007 sel_scroll_ev.stop(); 2081 sel_scroll_ev.stop();
2008#endif 2082#endif
2009 2083
2010 if (ev.window == TermWin.vt) 2084 if (ev.window == vt)
2011 { 2085 {
2086 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2087 return;
2088
2012#if ISO_14755 2089#if ISO_14755
2013 // 5.4 2090 // 5.4
2014 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2091 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2015 return; 2092 return;
2016#endif 2093#endif
2094
2017 if (reportmode) 2095 if (reportmode)
2018 { 2096 {
2019 /* mouse report from vt window */ 2097 /* mouse report from vt window */
2020 /* don't report release of wheel "buttons" */ 2098 /* don't report release of wheel "buttons" */
2021 if (ev.button >= 4) 2099 if (ev.button >= 4)
2051 { 2129 {
2052 case Button1: 2130 case Button1:
2053 case Button3: 2131 case Button3:
2054 selection_make (ev.time); 2132 selection_make (ev.time);
2055 break; 2133 break;
2134
2056 case Button2: 2135 case Button2:
2057 selection_request (ev.time, ev.x, ev.y); 2136 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2137 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary);
2058 break; 2138 break;
2139
2059#ifdef MOUSE_WHEEL 2140#ifdef MOUSE_WHEEL
2060 case Button4: 2141 case Button4:
2061 case Button5: 2142 case Button5:
2062 { 2143 {
2063 int i; 2144 int i;
2065 2146
2066 v = ev.button == Button4 ? UP : DN; 2147 v = ev.button == Button4 ? UP : DN;
2067 2148
2068 if (ev.state & ShiftMask) 2149 if (ev.state & ShiftMask)
2069 i = 1; 2150 i = 1;
2070 else if (options & Opt_mouseWheelScrollPage) 2151 else if (OPTION (Opt_mouseWheelScrollPage))
2071 i = TermWin.nrow - 1; 2152 i = nrow - 1;
2072 else 2153 else
2073 i = 5; 2154 i = 5;
2074 2155
2075# ifdef MOUSE_SLIP_WHEELING 2156# ifdef MOUSE_SLIP_WHEELING
2076 if (ev.state & ControlMask) 2157 if (ev.state & ControlMask)
2077 { 2158 {
2078 mouse_slip_wheel_speed += v ? -1 : 1; 2159 mouse_slip_wheel_speed += v ? -1 : 1;
2079 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2160 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2080 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow; 2161 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2081 2162
2082 if (slip_wheel_ev.at < NOW) 2163 if (slip_wheel_ev.at < NOW)
2083 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2164 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2084 2165
2085 slip_wheel_ev.start (); 2166 slip_wheel_ev.start ();
2086 } 2167 }
2087 else 2168 else
2088 { 2169 {
2089# endif 2170# endif
2090# ifdef JUMP_MOUSE_WHEEL
2091 scr_page (v, i); 2171 scr_page (v, i);
2092 scr_refresh (SMOOTH_REFRESH);
2093 scrollbar_show (1); 2172 scrollbar_show (1);
2094# else
2095 while (i--)
2096 {
2097 scr_page (v, 1);
2098 scr_refresh (SMOOTH_REFRESH);
2099 scrollbar_show (1);
2100 }
2101# endif
2102# ifdef MOUSE_SLIP_WHEELING 2173# ifdef MOUSE_SLIP_WHEELING
2103 } 2174 }
2104#endif 2175# endif
2105 } 2176 }
2106 break; 2177 break;
2107#endif 2178#endif
2108 } 2179 }
2109 } 2180 }
2110#ifdef MENUBAR
2111 else if (isMenuBarWindow (ev.window))
2112 menubar_control (ev);
2113#endif
2114} 2181}
2115 2182
2116#ifdef TRANSPARENT 2183#ifdef TRANSPARENT
2117#if TINTING 2184#if TINTING
2118/* taken from aterm-0.4.2 */ 2185/* taken from aterm-0.4.2 */
2119 2186
2120typedef uint32_t RUINT32T; 2187typedef uint32_t RUINT32T;
2121 2188
2122void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm) 2189void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
2123{ 2190{
2124 int sh_r, sh_g, sh_b; 2191 int sh_r, sh_g, sh_b;
2125 RUINT32T mask_r, mask_g, mask_b; 2192 RUINT32T mask_r, mask_g, mask_b;
2126 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2193 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2127 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2194 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2128 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2195 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2129 int i; 2196 int i;
2130 2197
2131 Visual *visual = display->visual; 2198 Visual *visual = term->visual;
2132 2199
2133 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2200 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2134 2201
2135 /* for convenience */ 2202 /* for convenience */
2136 mask_r = visual->red_mask; 2203 mask_r = visual->red_mask;
2357 Atom atype; 2424 Atom atype;
2358 unsigned char *prop = NULL; 2425 unsigned char *prop = NULL;
2359 Window root, oldp, *list; 2426 Window root, oldp, *list;
2360 Pixmap rootpixmap = None; 2427 Pixmap rootpixmap = None;
2361 XWindowAttributes wattr, wrootattr; 2428 XWindowAttributes wattr, wrootattr;
2362 dDisp;
2363 2429
2364 pchanged = 0; 2430 pchanged = 0;
2365 2431
2366 if (!(options & Opt_transparent)) 2432 if (!OPTION (Opt_transparent))
2367 return pchanged; /* Don't try any more */ 2433 return pchanged; /* Don't try any more */
2368 2434
2369 XGetWindowAttributes (disp, display->root, &wrootattr); 2435 XGetWindowAttributes (xdisp, display->root, &wrootattr);
2370 rootdepth = wrootattr.depth; 2436 rootdepth = wrootattr.depth;
2371 2437
2372 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 2438 XGetWindowAttributes (xdisp, parent[0], &wattr);
2373 2439
2374 if (rootdepth != wattr.depth) 2440 if (rootdepth != wattr.depth)
2375 { 2441 {
2376 if (am_transparent) 2442 if (am_transparent)
2377 { 2443 {
2378 pchanged = 1; 2444 pchanged = 1;
2379 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); 2445 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2380 am_transparent = am_pixmap_trans = 0; 2446 am_transparent = am_pixmap_trans = 0;
2381 } 2447 }
2382 2448
2383 return pchanged; /* Don't try any more */ 2449 return pchanged; /* Don't try any more */
2384 } 2450 }
2385 2451
2386 /* Get all X ops out of the queue so that our information is up-to-date. */ 2452 /* Get all X ops out of the queue so that our information is up-to-date. */
2387 XSync (disp, False); 2453 XSync (xdisp, False);
2388 2454
2389 /* 2455 /*
2390 * Make the frame window set by the window manager have 2456 * Make the frame window set by the window manager have
2391 * the root background. Some window managers put multiple nested frame 2457 * the root background. Some window managers put multiple nested frame
2392 * windows for each client, so we have to take care about that. 2458 * windows for each client, so we have to take care about that.
2393 */ 2459 */
2394 i = (xa[XA_XROOTPMAP_ID] 2460 i = (xa[XA_XROOTPMAP_ID]
2395 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID], 2461 && XGetWindowProperty (xdisp, display->root, xa[XA_XROOTPMAP_ID],
2396 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2462 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2397 &nitems, &bytes_after, &prop) == Success); 2463 &nitems, &bytes_after, &prop) == Success);
2398 2464
2399 if (!i || prop == NULL) 2465 if (!i || prop == NULL)
2400 i = (xa[XA_ESETROOT_PMAP_ID] 2466 i = (xa[XA_ESETROOT_PMAP_ID]
2401 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID], 2467 && XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID],
2402 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2468 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2403 &nitems, &bytes_after, &prop) == Success); 2469 &nitems, &bytes_after, &prop) == Success);
2404 2470
2405 if (!i || prop == NULL 2471 if (!i || prop == NULL
2406#if TINTING 2472#if TINTING
2407 || !rs[Rs_color + Color_tint] 2473 || !ISSET_PIXCOLOR (Color_tint)
2408#endif 2474#endif
2409 ) 2475 )
2410 have_pixmap = 0; 2476 have_pixmap = 0;
2411 else 2477 else
2412 { 2478 {
2425 Window cr; 2491 Window cr;
2426 XImage *image; 2492 XImage *image;
2427 GC gc; 2493 GC gc;
2428 XGCValues gcvalue; 2494 XGCValues gcvalue;
2429 2495
2430 XTranslateCoordinates (disp, TermWin.parent[0], display->root, 2496 XTranslateCoordinates (xdisp, parent[0], display->root,
2431 0, 0, &sx, &sy, &cr); 2497 0, 0, &sx, &sy, &cr);
2432 nw = (unsigned int)szHint.width; 2498 nw = (unsigned int)szHint.width;
2433 nh = (unsigned int)szHint.height; 2499 nh = (unsigned int)szHint.height;
2434 nx = ny = 0; 2500 nx = ny = 0;
2435 2501
2445 nh += sy; 2511 nh += sy;
2446 ny = -sy; 2512 ny = -sy;
2447 sy = 0; 2513 sy = 0;
2448 } 2514 }
2449 2515
2450 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2516 min_it (nw, (unsigned int) (wrootattr.width - sx));
2451 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2517 min_it (nh, (unsigned int) (wrootattr.height - sy));
2452 2518
2453 XSync (disp, False); 2519 XSync (xdisp, False);
2454 allowedxerror = -1; 2520 allowedxerror = -1;
2455 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2521 image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2456 2522
2457 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2523 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2458 /* XXX: may need a delay here? */ 2524 /* XXX: may need a delay here? */
2459 allowedxerror = 0; 2525 allowedxerror = 0;
2460 2526
2461 if (image == NULL) 2527 if (image == NULL)
2462 { 2528 {
2463 if (am_transparent && am_pixmap_trans) 2529 if (am_transparent && am_pixmap_trans)
2464 { 2530 {
2465 pchanged = 1; 2531 pchanged = 1;
2466 if (TermWin.pixmap != None) 2532 if (pixmap != None)
2467 { 2533 {
2468 XFreePixmap (disp, TermWin.pixmap); 2534 XFreePixmap (xdisp, pixmap);
2469 TermWin.pixmap = None; 2535 pixmap = None;
2470 } 2536 }
2471 } 2537 }
2472 2538
2473 am_pixmap_trans = 0; 2539 am_pixmap_trans = 0;
2474 } 2540 }
2475 else 2541 else
2476 { 2542 {
2477 if (TermWin.pixmap != None) 2543 if (pixmap != None)
2478 XFreePixmap (disp, TermWin.pixmap); 2544 XFreePixmap (xdisp, pixmap);
2479 2545
2480#if TINTING 2546#if TINTING
2481 if (ISSET_PIXCOLOR (Color_tint)) 2547 if (ISSET_PIXCOLOR (Color_tint))
2482 { 2548 {
2483 unsigned short rm, gm, bm;
2484 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; 2549 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2485 2550
2551 rgba c;
2486 pix_colors_focused[Color_tint].get (display, rm, gm, bm); 2552 pix_colors_focused [Color_tint].get (c);
2487 2553
2488 ShadeXImage (display, image, shade, rm, gm, bm); 2554 ShadeXImage (this, image, shade, c.r, c.g, c.b);
2489 } 2555 }
2490#endif 2556#endif
2491 2557
2492 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt, 2558 pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth);
2493 szHint.width, szHint.height, image->depth);
2494 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue); 2559 gc = XCreateGC (xdisp, vt, 0UL, &gcvalue);
2495 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0, 2560 XPutImage (xdisp, pixmap, gc, image, 0, 0,
2496 nx, ny, image->width, image->height); 2561 nx, ny, image->width, image->height);
2497 XFreeGC (disp, gc); 2562 XFreeGC (xdisp, gc);
2498 XDestroyImage (image); 2563 XDestroyImage (image);
2499 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap); 2564 XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap);
2500 XClearWindow (disp, TermWin.parent[0]); 2565 XClearWindow (xdisp, parent[0]);
2501 2566
2502 if (!am_transparent || !am_pixmap_trans) 2567 if (!am_transparent || !am_pixmap_trans)
2503 pchanged = 1; 2568 pchanged = 1;
2504 2569
2505 am_transparent = am_pixmap_trans = 1; 2570 am_transparent = am_pixmap_trans = 1;
2506 } 2571 }
2507 } 2572 }
2508 2573
2509 if (am_pixmap_trans) 2574 if (am_pixmap_trans)
2510 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); 2575 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2511 else 2576 else
2512 { 2577 {
2513 unsigned int n; 2578 unsigned int n;
2514 /* 2579 /*
2515 * InheritPixmap transparency 2580 * InheritPixmap transparency
2516 */ 2581 */
2517 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2582 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2518 { 2583 {
2519 oldp = TermWin.parent[i]; 2584 oldp = parent[i];
2520 XQueryTree (disp, TermWin.parent[i - 1], &root, 2585 XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n);
2521 &TermWin.parent[i], &list, &n);
2522 XFree (list); 2586 XFree (list);
2523 2587
2524 if (TermWin.parent[i] == display->root) 2588 if (parent[i] == display->root)
2525 { 2589 {
2526 if (oldp != None) 2590 if (oldp != None)
2527 pchanged = 1; 2591 pchanged = 1;
2528 2592
2529 break; 2593 break;
2530 } 2594 }
2531 2595
2532 if (oldp != TermWin.parent[i]) 2596 if (oldp != parent[i])
2533 pchanged = 1; 2597 pchanged = 1;
2534 } 2598 }
2535 2599
2536 n = 0; 2600 n = 0;
2537 2601
2538 if (pchanged) 2602 if (pchanged)
2539 {
2540 for (; n < (unsigned int)i; n++) 2603 for (; n < (unsigned int)i; n++)
2541 { 2604 {
2542 XGetWindowAttributes (disp, TermWin.parent[n], &wattr); 2605 XGetWindowAttributes (xdisp, parent[n], &wattr);
2606
2543 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2607 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2544 { 2608 {
2545 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2609 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2546 break; 2610 break;
2547 } 2611 }
2548 } 2612 }
2613
2614 if (n > (sizeof (parent) / sizeof (parent[0])))
2549 } 2615 {
2550
2551 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2552 {
2553 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]); 2616 XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]);
2554 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); 2617 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2555 am_transparent = 0; 2618 am_transparent = 0;
2556 /* XXX: also turn off Opt_transparent? */ 2619 /* XXX: also turn off Opt_transparent? */
2557 } 2620 }
2558 else 2621 else
2559 { 2622 {
2560#if WAIT_FOR_WM
2561 /* wait (an arbitrary period) for the WM to do its thing
2562 * needed for fvwm2.2.2 (and before?) */
2563 sleep (1);
2564#endif
2565 for (n = 0; n < (unsigned int)i; n++) 2623 for (n = 0; n < (unsigned int)i; n++)
2566 { 2624 {
2567 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative); 2625 XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative);
2568 XClearWindow (disp, TermWin.parent[n]); 2626 XClearWindow (xdisp, parent[n]);
2569 } 2627 }
2570 2628
2571 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); 2629 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2572 am_transparent = 1; 2630 am_transparent = 1;
2573 } 2631 }
2574 2632
2575 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2633 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2576 TermWin.parent[i] = None; 2634 parent[i] = None;
2577 } 2635 }
2578 2636
2579 if (scrollBar.win) 2637 if (scrollBar.win)
2580 { 2638 {
2581 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative); 2639 XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative);
2582 scrollBar.setIdle (); 2640 scrollBar.setIdle ();
2583 scrollbar_show (0); 2641 scrollbar_show (0);
2584 } 2642 }
2585 2643
2586 if (am_transparent) 2644 if (am_transparent)
2598 2656
2599bool 2657bool
2600rxvt_term::cmd_parse () 2658rxvt_term::cmd_parse ()
2601{ 2659{
2602 bool flag = false; 2660 bool flag = false;
2603 unicode_t ch = NOCHAR; 2661 wchar_t ch = NOCHAR;
2604 unsigned char *seq_begin; // remember start of esc-sequence here 2662 char *seq_begin; // remember start of esc-sequence here
2605 2663
2606 for (;;) 2664 for (;;)
2607 { 2665 {
2608 if (ch == NOCHAR) 2666 if (ch == NOCHAR)
2609 { 2667 {
2610 seq_begin = cmdbuf_ptr; 2668 seq_begin = cmdbuf_ptr;
2611 ch = next_char (); 2669 ch = next_char ();
2612 }
2613 2670
2614 if (ch == NOCHAR) // TODO: improve 2671 if (ch == NOCHAR)
2615 break; 2672 break;
2673 }
2616 2674
2617 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2675 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2618 { 2676 {
2619 if (!seen_input) 2677 if (!seen_input)
2620 { 2678 {
2629 if (seen_resize && cmd_pid) 2687 if (seen_resize && cmd_pid)
2630 kill (-cmd_pid, SIGWINCH); 2688 kill (-cmd_pid, SIGWINCH);
2631 } 2689 }
2632 2690
2633 /* Read a text string from the input buffer */ 2691 /* Read a text string from the input buffer */
2634 unicode_t buf[UBUFSIZ]; 2692 wchar_t buf[UBUFSIZ];
2635 bool refreshnow = false; 2693 bool refreshnow = false;
2636 int nlines = 0; 2694 int nlines = 0;
2637 unicode_t *str = buf; 2695 wchar_t *str = buf;
2696 wchar_t *eol = str + min (ncol, UBUFSIZ);
2638 2697
2639 for (;;) 2698 for (;;)
2640 { 2699 {
2641 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2700 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2642 break; 2701 break;
2643 2702
2644 *str++ = ch; 2703 *str++ = ch;
2645 2704
2646 if (ch == C0_LF) 2705 if (ch == C0_LF || str >= eol)
2647 { 2706 {
2707 if (ch == C0_LF)
2648 nlines++; 2708 nlines++;
2709
2649 refresh_count++; 2710 refresh_count++;
2650 2711
2651 if (!(options & Opt_jumpScroll) 2712 if (!OPTION (Opt_jumpScroll)
2652 || (refresh_count >= refresh_limit * (TermWin.nrow - 1))) 2713 || (refresh_count >= refresh_limit * (nrow - 1)))
2653 { 2714 {
2654 refreshnow = true; 2715 refreshnow = true;
2716 refresh_count = 0;
2655 ch = NOCHAR; 2717 ch = NOCHAR;
2656 break; 2718 break;
2657 } 2719 }
2658 2720
2659 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2721 // scr_add_lines only works for nlines <= nrow - 1.
2660 if (nlines >= TermWin.nrow - 1) 2722 if (nlines >= nrow - 1)
2661 { 2723 {
2724 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2725 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2662 scr_add_lines (buf, nlines, str - buf); 2726 scr_add_lines (buf, str - buf, nlines);
2727
2663 nlines = 0; 2728 nlines = 0;
2664 str = buf; 2729 str = buf;
2730 eol = str + min (ncol, UBUFSIZ);
2665 } 2731 }
2666 }
2667 2732
2668 if (str >= buf + UBUFSIZ) 2733 if (str >= eol)
2669 { 2734 {
2735 if (eol >= buf + UBUFSIZ)
2736 {
2670 ch = NOCHAR; 2737 ch = NOCHAR;
2671 break; 2738 break;
2739 }
2740 else
2741 eol = min (eol + ncol, buf + UBUFSIZ);
2742 }
2743
2672 } 2744 }
2673 2745
2674 seq_begin = cmdbuf_ptr; 2746 seq_begin = cmdbuf_ptr;
2675 ch = next_char (); 2747 ch = next_char ();
2676 } 2748 }
2677 2749
2750 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2751 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2678 scr_add_lines (buf, nlines, str - buf); 2752 scr_add_lines (buf, str - buf, nlines);
2679 2753
2680 /* 2754 /*
2681 * If there have been a lot of new lines, then update the screen 2755 * If there have been a lot of new lines, then update the screen
2682 * What the heck I'll cheat and only refresh less than every page-full. 2756 * What the heck I'll cheat and only refresh less than every page-full.
2683 * the number of pages between refreshes is refresh_limit, which 2757 * the number of pages between refreshes is refresh_limit, which
2684 * is incremented here because we must be doing flat-out scrolling. 2758 * is incremented here because we must be doing flat-out scrolling.
2685 */ 2759 */
2686 if (refreshnow) 2760 if (refreshnow)
2687 { 2761 {
2688 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 2762 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2689 refresh_limit++; 2763 refresh_limit++;
2690 else 2764 else
2691 { 2765 {
2692 flag = true; 2766 flag = true;
2693 scr_refresh (refresh_type); 2767 scr_refresh ();
2768 want_refresh = 1;
2694 } 2769 }
2695 } 2770 }
2696 2771
2697 } 2772 }
2698 else 2773 else
2713 } 2788 }
2714 2789
2715 return flag; 2790 return flag;
2716} 2791}
2717 2792
2718// read the next octet
2719unicode_t
2720rxvt_term::next_octet ()
2721{
2722 return cmdbuf_ptr < cmdbuf_endp
2723 ? *cmdbuf_ptr++
2724 : NOCHAR;
2725}
2726
2727// read the next character 2793// read the next character
2728unicode_t 2794wchar_t
2729rxvt_term::next_char () 2795rxvt_term::next_char () NOTHROW
2730{ 2796{
2731 while (cmdbuf_ptr < cmdbuf_endp) 2797 while (cmdbuf_ptr < cmdbuf_endp)
2732 { 2798 {
2733 // assume 7-bit to be ascii ALWAYS 2799 // assume 7-bit to be ascii ALWAYS
2734 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2800 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2735 return *cmdbuf_ptr++; 2801 return *cmdbuf_ptr++;
2736 2802
2737 wchar_t wc; 2803 wchar_t wc;
2738 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2804 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2739 2805
2740 if (len == (size_t)-2) 2806 if (len == (size_t)-2)
2741 { 2807 {
2742 // the mbstate stores incomplete sequences. didn't know this :/ 2808 // the mbstate stores incomplete sequences. didn't know this :/
2743 cmdbuf_ptr = cmdbuf_endp; 2809 cmdbuf_ptr = cmdbuf_endp;
2744 break; 2810 break;
2745 } 2811 }
2746 2812
2747 if (len == (size_t)-1) 2813 if (len == (size_t)-1)
2748 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2814 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2749 2815
2750 // assume wchar == unicode 2816 // assume wchar == unicode
2751 cmdbuf_ptr += len; 2817 cmdbuf_ptr += len;
2752 return wc & UNICODE_MASK; 2818 return wc & UNICODE_MASK;
2753 } 2819 }
2754 2820
2755 return NOCHAR; 2821 return NOCHAR;
2756} 2822}
2823
2824// read the next octet
2825uint32_t
2826rxvt_term::next_octet () NOTHROW
2827{
2828 return cmdbuf_ptr < cmdbuf_endp
2829 ? (unsigned char)*cmdbuf_ptr++
2830 : NOCHAR;
2831}
2832
2833static class out_of_input out_of_input;
2757 2834
2758/* rxvt_cmd_getc () - Return next input character */ 2835/* rxvt_cmd_getc () - Return next input character */
2759/* 2836/*
2760 * Return the next input character after first passing any keyboard input 2837 * Return the next input character after first passing any keyboard input
2761 * to the command. 2838 * to the command.
2762 */ 2839 */
2763unicode_t 2840wchar_t
2764rxvt_term::cmd_getc () 2841rxvt_term::cmd_getc () THROW ((class out_of_input))
2765{ 2842{
2766 unicode_t c = next_char (); 2843 wchar_t c = next_char ();
2767 2844
2768 if (c == NOCHAR) 2845 if (c == NOCHAR)
2769 throw out_of_input; 2846 throw out_of_input;
2770 2847
2771 return c; 2848 return c;
2772} 2849}
2773 2850
2774unicode_t 2851uint32_t
2775rxvt_term::cmd_get8 () 2852rxvt_term::cmd_get8 () THROW ((class out_of_input))
2776{ 2853{
2777 unicode_t c = next_octet (); 2854 uint32_t c = next_octet ();
2778 2855
2779 if (c == NOCHAR) 2856 if (c == NOCHAR)
2780 throw out_of_input; 2857 throw out_of_input;
2781 2858
2782 return c; 2859 return c;
2882 case C0_ESC: 2959 case C0_ESC:
2883 process_escape_seq (); 2960 process_escape_seq ();
2884 break; 2961 break;
2885 case C0_ENQ: /* terminal Status */ 2962 case C0_ENQ: /* terminal Status */
2886 if (rs[Rs_answerbackstring]) 2963 if (rs[Rs_answerbackstring])
2887 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2964 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2888 (unsigned int)strlen (rs[Rs_answerbackstring]));
2889 else 2965 else
2890 tt_write ((unsigned char *)VT100_ANS, 2966 tt_write (VT100_ANS, strlen (VT100_ANS));
2891 (unsigned int)strlen (VT100_ANS));
2892 break; 2967 break;
2893 case C0_BEL: /* bell */ 2968 case C0_BEL: /* bell */
2894 scr_bell (); 2969 scr_bell ();
2895 break; 2970 break;
2896 case C0_BS: /* backspace */ 2971 case C0_BS: /* backspace */
3020 scr_charset_set (2, (unsigned int)cmd_getc ()); 3095 scr_charset_set (2, (unsigned int)cmd_getc ());
3021 break; 3096 break;
3022 case '+': 3097 case '+':
3023 scr_charset_set (3, (unsigned int)cmd_getc ()); 3098 scr_charset_set (3, (unsigned int)cmd_getc ());
3024 break; 3099 break;
3025#if ENABLE_FRILLS 3100#if !ENABLE_MINIMAL
3026 case '6': 3101 case '6':
3027 scr_backindex (); 3102 scr_backindex ();
3028 break; 3103 break;
3029#endif 3104#endif
3030 case '7': 3105 case '7':
3031 scr_cursor (SAVE); 3106 scr_cursor (SAVE);
3032 break; 3107 break;
3033 case '8': 3108 case '8':
3034 scr_cursor (RESTORE); 3109 scr_cursor (RESTORE);
3035 break; 3110 break;
3036#if ENABLE_FRILLS 3111#if !ENABLE_MINIMAL
3037 case '9': 3112 case '9':
3038 scr_forwardindex (); 3113 scr_forwardindex ();
3039 break; 3114 break;
3040#endif 3115#endif
3041 case '=': 3116 case '=':
3051 break; 3126 break;
3052 3127
3053 /* 8.3.87: NEXT LINE */ 3128 /* 8.3.87: NEXT LINE */
3054 case C1_NEL: /* ESC E */ 3129 case C1_NEL: /* ESC E */
3055 { 3130 {
3056 unicode_t nlcr[] = { C0_LF, C0_CR }; 3131 wchar_t nlcr[] = { C0_LF, C0_CR };
3057 scr_add_lines (nlcr, 1, 2); 3132 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3058 } 3133 }
3059 break; 3134 break;
3060 3135
3061 /* kidnapped escape sequence: Should be 8.3.48 */ 3136 /* kidnapped escape sequence: Should be 8.3.48 */
3062 case C1_ESA: /* ESC G */ 3137 case C1_ESA: /* ESC G */
3084 process_dcs_seq (); 3159 process_dcs_seq ();
3085 break; 3160 break;
3086 3161
3087 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 3162 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3088 case C1_SCI: /* ESC Z */ 3163 case C1_SCI: /* ESC Z */
3089 tt_write ((const unsigned char *)ESCZ_ANSWER, 3164 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3090 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3091 break; /* steal obsolete ESC [ c */ 3165 break; /* steal obsolete ESC [ c */
3092 3166
3093 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 3167 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3094 case C1_CSI: /* ESC [ */ 3168 case C1_CSI: /* ESC [ */
3095 process_csi_seq (); 3169 process_csi_seq ();
3204 ndef = get_byte_array_bit (csi_defaults, i); 3278 ndef = get_byte_array_bit (csi_defaults, i);
3205 for (p = 0; p < nargs; p++) 3279 for (p = 0; p < nargs; p++)
3206 if (arg[p] == -1) 3280 if (arg[p] == -1)
3207 arg[p] = ndef; 3281 arg[p] = ndef;
3208 3282
3209#ifdef DEBUG_CMD
3210 fprintf (stderr, "CSI ");
3211 for (p = 0; p < nargs; p++)
3212 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3213 fprintf (stderr, "%c\n", ch);
3214#endif
3215
3216 /* 3283 /*
3217 * private mode handling 3284 * private mode handling
3218 */ 3285 */
3219 if (priv) 3286 if (priv)
3220 { 3287 {
3221 switch (priv) 3288 switch (priv)
3222 { 3289 {
3223 case '>': 3290 case '>':
3224 if (ch == CSI_DA) /* secondary device attributes */ 3291 if (ch == CSI_DA) /* secondary device attributes */
3225 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 3292 {
3293 // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt,
3294 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
3295 //
3296 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
3297 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify
3298 // that we do not support xterm mouse reporting (should be 95 when we do).
3299 //
3300 tt_printf ("\033[>%d;94;0c", 'U');
3301 }
3226 break; 3302 break;
3227 case '?': 3303 case '?':
3228 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3304 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3229 process_terminal_mode (ch, priv, nargs, arg); 3305 process_terminal_mode (ch, priv, nargs, arg);
3230 break; 3306 break;
3335 3411
3336 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 3412 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3337 arg[0] = -arg[0]; 3413 arg[0] = -arg[0];
3338 /* FALLTHROUGH */ 3414 /* FALLTHROUGH */
3339 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3415 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3340 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 3416 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3341 break; 3417 break;
3342 3418
3343 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3419 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3344 tt_write ((const unsigned char *)VT100_ANS, 3420 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3345 (unsigned int) (sizeof (VT100_ANS) - 1));
3346 break; 3421 break;
3347 3422
3348 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 3423 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3349 process_sgr_mode (nargs, arg); 3424 process_sgr_mode (nargs, arg);
3350 break; 3425 break;
3357 break; 3432 break;
3358 case 6: /* CPR requested */ 3433 case 6: /* CPR requested */
3359 scr_report_position (); 3434 scr_report_position ();
3360 break; 3435 break;
3361 case 7: /* unofficial extension */ 3436 case 7: /* unofficial extension */
3362 if (options & Opt_insecure) 3437 if (OPTION (Opt_insecure))
3363 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3438 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3364 break; 3439 break;
3365 case 8: /* unofficial extension */ 3440 case 8: /* unofficial extension */
3366 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3441 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3367 break; 3442 break;
3434 break; 3509 break;
3435 case CSI_75: 3510 case CSI_75:
3436 scr_cursor (RESTORE); 3511 scr_cursor (RESTORE);
3437 break; 3512 break;
3438 3513
3439#if ENABLE_FRILLS 3514#if !ENABLE_MINIMAL
3440 case CSI_74: 3515 case CSI_74:
3441 process_window_ops (arg, nargs); 3516 process_window_ops (arg, nargs);
3442 break; 3517 break;
3443#endif 3518#endif
3444 3519
3451 break; 3526 break;
3452 } 3527 }
3453} 3528}
3454/*}}} */ 3529/*}}} */
3455 3530
3456#if ENABLE_FRILLS 3531#if !ENABLE_MINIMAL
3457/* ARGSUSED */ 3532/* ARGSUSED */
3458void 3533void
3459rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3534rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3460{ 3535{
3461 int x, y; 3536 int x, y;
3462 XWindowAttributes wattr; 3537 XWindowAttributes wattr;
3463 Window wdummy; 3538 Window wdummy;
3464 dDisp; 3539
3540 dLocal (Display *, xdisp);
3465 3541
3466 if (nargs == 0) 3542 if (nargs == 0)
3467 return; 3543 return;
3468 3544
3469 switch (args[0]) 3545 switch (args[0])
3470 { 3546 {
3471 /* 3547 /*
3472 * commands 3548 * commands
3473 */ 3549 */
3474 case 1: /* deiconify window */ 3550 case 1: /* deiconify window */
3475 XMapWindow (disp, TermWin.parent[0]); 3551 XMapWindow (xdisp, parent[0]);
3476 break; 3552 break;
3477 case 2: /* iconify window */ 3553 case 2: /* iconify window */
3478 XIconifyWindow (disp, TermWin.parent[0], display->screen); 3554 XIconifyWindow (xdisp, parent[0], display->screen);
3479 break; 3555 break;
3480 case 3: /* set position (pixels) */ 3556 case 3: /* set position (pixels) */
3481 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); 3557 XMoveWindow (xdisp, parent[0], args[1], args[2]);
3482 break; 3558 break;
3483 case 4: /* set size (pixels) */ 3559 case 4: /* set size (pixels) */
3484 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3560 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3485 break; 3561 break;
3486 case 5: /* raise window */ 3562 case 5: /* raise window */
3487 XRaiseWindow (disp, TermWin.parent[0]); 3563 XRaiseWindow (xdisp, parent[0]);
3488 break; 3564 break;
3489 case 6: /* lower window */ 3565 case 6: /* lower window */
3490 XLowerWindow (disp, TermWin.parent[0]); 3566 XLowerWindow (xdisp, parent[0]);
3491 break; 3567 break;
3492 case 7: /* refresh window */ 3568 case 7: /* refresh window */
3493 scr_touch (true); 3569 scr_touch (true);
3494 break; 3570 break;
3495 case 8: /* set size (chars) */ 3571 case 8: /* set size (chars) */
3496 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3572 set_widthheight ((unsigned int) (args[2] * fwidth),
3497 (unsigned int) (args[1] * TermWin.fheight)); 3573 (unsigned int) (args[1] * fheight));
3498 break; 3574 break;
3499 3575
3500 //case 9: NYI, TODO, restore maximized window or maximize window 3576 //case 9: NYI, TODO, restore maximized window or maximize window
3501 default: 3577 default:
3502 if (args[0] >= 24) /* set height (chars) */ 3578 if (args[0] >= 24) /* set height (chars) */
3503 set_widthheight ((unsigned int)TermWin.width, 3579 set_widthheight ((unsigned int)width,
3504 (unsigned int) (args[1] * TermWin.fheight)); 3580 (unsigned int) (args[1] * fheight));
3505 break; 3581 break;
3506
3507 3582
3508 /* 3583 /*
3509 * reports - some output format copied from XTerm 3584 * reports - some output format copied from XTerm
3510 */ 3585 */
3511 case 11: /* report window state */ 3586 case 11: /* report window state */
3512 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3587 XGetWindowAttributes (xdisp, parent[0], &wattr);
3513 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3588 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3514 break; 3589 break;
3515 case 13: /* report window position */ 3590 case 13: /* report window position */
3516 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3591 XGetWindowAttributes (xdisp, parent[0], &wattr);
3517 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, 3592 XTranslateCoordinates (xdisp, parent[0], wattr.root,
3518 -wattr.border_width, -wattr.border_width, 3593 -wattr.border_width, -wattr.border_width,
3519 &x, &y, &wdummy); 3594 &x, &y, &wdummy);
3520 tt_printf ("\033[3;%d;%dt", x, y); 3595 tt_printf ("\033[3;%d;%dt", x, y);
3521 break; 3596 break;
3522 case 14: /* report window size (pixels) */ 3597 case 14: /* report window size (pixels) */
3523 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3598 XGetWindowAttributes (xdisp, parent[0], &wattr);
3524 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3599 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3525 break; 3600 break;
3526 case 18: /* report text area size (chars) */ 3601 case 18: /* report text area size (chars) */
3527 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3602 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3528 break; 3603 break;
3529 case 19: /* report window size (chars) */ 3604 case 19: /* report window size (chars) */
3530 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3605 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3531 break; 3606 break;
3532 case 20: /* report icon label */ 3607 case 20: /* report icon label */
3533 { 3608 {
3534 char *s; 3609 char *s;
3535 XGetIconName (disp, TermWin.parent[0], &s); 3610 XGetIconName (xdisp, parent[0], &s);
3536 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3611 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3537 XFree (s); 3612 XFree (s);
3538 } 3613 }
3539 break; 3614 break;
3540 case 21: /* report window title */ 3615 case 21: /* report window title */
3541 { 3616 {
3542 char *s; 3617 char *s;
3543 XFetchName (disp, TermWin.parent[0], &s); 3618 XFetchName (xdisp, parent[0], &s);
3544 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3619 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3545 XFree (s); 3620 XFree (s);
3546 } 3621 }
3547 break; 3622 break;
3548 } 3623 }
3549} 3624}
3552/*----------------------------------------------------------------------*/ 3627/*----------------------------------------------------------------------*/
3553/* 3628/*
3554 * get input up until STRING TERMINATOR (or BEL) 3629 * get input up until STRING TERMINATOR (or BEL)
3555 * ends_how is terminator used. returned input must be free()'d 3630 * ends_how is terminator used. returned input must be free()'d
3556 */ 3631 */
3557unsigned char * 3632char *
3558rxvt_term::get_to_st (unicode_t &ends_how) 3633rxvt_term::get_to_st (unicode_t &ends_how)
3559{ 3634{
3560 unicode_t ch; 3635 unicode_t ch;
3561 bool seen_esc = false; 3636 bool seen_esc = false;
3562 unsigned int n = 0; 3637 unsigned int n = 0;
3581 else if (ch < 0x20) 3656 else if (ch < 0x20)
3582 return NULL; /* other control character - exit */ 3657 return NULL; /* other control character - exit */
3583 3658
3584 seen_esc = false; 3659 seen_esc = false;
3585 3660
3586 if (n >= sizeof (string) - 1) 3661 if (n >= STRING_MAX - 1)
3587 // stop at some sane length 3662 // stop at some sane length
3588 return NULL; 3663 return NULL;
3589 3664
3590 if (ch == C0_SYN) 3665 if (ch == C0_SYN)
3591 string[n++] = cmd_get8 (); 3666 string[n++] = cmd_get8 ();
3595 3670
3596 string[n++] = '\0'; 3671 string[n++] = '\0';
3597 3672
3598 ends_how = (ch == 0x5c ? C0_ESC : ch); 3673 ends_how = (ch == 0x5c ? C0_ESC : ch);
3599 3674
3600 return (unsigned char *)rxvt_wcstombs (string); 3675 return rxvt_wcstombs (string);
3601} 3676}
3602 3677
3603/*----------------------------------------------------------------------*/ 3678/*----------------------------------------------------------------------*/
3604/* 3679/*
3605 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3680 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3606 */ 3681 */
3607void 3682void
3608rxvt_term::process_dcs_seq () 3683rxvt_term::process_dcs_seq ()
3609{ 3684{
3610 unsigned char *s; 3685 char *s;
3611 unicode_t eh; 3686 unicode_t eh;
3612 3687
3613 /* 3688 /*
3614 * Not handled yet 3689 * Not handled yet
3615 */ 3690 */
3634 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3709 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3635 arg = arg * 10 + (ch - '0'); 3710 arg = arg * 10 + (ch - '0');
3636 3711
3637 if (ch == ';') 3712 if (ch == ';')
3638 { 3713 {
3639 unsigned char *s = get_to_st (eh); 3714 char *s = get_to_st (eh);
3640 3715
3641 if (s) 3716 if (s)
3642 { 3717 {
3643 process_xterm_seq (arg, (char *)s, eh); 3718 process_xterm_seq (arg, s, eh);
3644 free (s); 3719 free (s);
3645 } 3720 }
3646 } 3721 }
3647} 3722}
3648 3723
3649void 3724void
3650rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3725rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3651{ 3726{
3652 if (str[0] == '?' && !str[1]) 3727 if (str[0] == '?' && !str[1])
3653 { 3728 {
3654 unsigned short r, g, b; 3729 rgba c;
3655 pix_colors_focused[color].get (display, r, g, b); 3730 pix_colors_focused[color].get (c);
3731
3732#if XFT
3733 if (c.a != rgba::MAX_CC)
3734 tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
3735 else
3736#endif
3656 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3737 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp);
3657 } 3738 }
3658 else 3739 else
3659 set_window_color (color, str); 3740 set_window_color (color, str);
3660} 3741}
3661 3742
3662/* 3743/*
3663 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3744 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3664 * 0 = change iconName/title
3665 * 1 = change iconName
3666 * 2 = change title
3667 * 4 = change color
3668 * 10 = change fg color
3669 * 11 = change bg color
3670 * 12 = change text color
3671 * 13 = change mouse foreground color
3672 * 17 = change highlight character colour
3673 * 18 = change bold character color
3674 * 19 = change underlined character color
3675 * 46 = change logfile (not implemented)
3676 * 50 = change font
3677 *
3678 * rxvt extensions:
3679 * 20 = bg pixmap
3680 * 39 = change default fg color
3681 * 49 = change default bg color
3682 * 55 = dump scrollback buffer and all of screen
3683 * 701 = change locale
3684 * 702 = find font
3685 * 703 = menu
3686 */ 3745 */
3687void 3746void
3688rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3747rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3689{ 3748{
3690 int changed = 0;
3691 int color; 3749 int color;
3692 char *buf, *name; 3750 char *buf, *name;
3693 bool query = str[0] == '?' && !str[1]; 3751 bool query = str[0] == '?' && !str[1];
3694 int saveop = op; 3752 int saveop = op;
3695 dDisp; 3753
3754 dLocal (Display *, xdisp);
3696 3755
3697 assert (str != NULL); 3756 assert (str != NULL);
3698 switch (op) 3757 switch (op)
3699 { 3758 {
3700 case XTerm_name: 3759 case XTerm_name:
3716 unsigned long bytes_after; 3775 unsigned long bytes_after;
3717 unsigned char *value = 0; 3776 unsigned char *value = 0;
3718 const char *str = ""; 3777 const char *str = "";
3719 3778
3720 if (prop 3779 if (prop
3721 && XGetWindowProperty (disp, TermWin.parent[0], 3780 && XGetWindowProperty (xdisp, parent[0],
3722 prop, 0, 1<<16, 0, AnyPropertyType, 3781 prop, 0, 1<<16, 0, AnyPropertyType,
3723 &actual_type, &actual_format, 3782 &actual_type, &actual_format,
3724 &nitems, &bytes_after, &value) == Success 3783 &nitems, &bytes_after, &value) == Success
3725 && actual_type != None 3784 && actual_type != None
3726 && actual_format == 8) 3785 && actual_format == 8)
3727 str = (const char *)(value); 3786 str = (const char *)(value);
3728 3787
3729 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3788 tt_printf ("\033]%d;%s%c", op, str, resp);
3730 3789
3731 XFree (value); 3790 XFree (value);
3732 } 3791 }
3733 else 3792 else
3734 { 3793 {
3738 { 3797 {
3739 *eq = 0; 3798 *eq = 0;
3740 set_utf8_property (display->atom (str), eq + 1); 3799 set_utf8_property (display->atom (str), eq + 1);
3741 } 3800 }
3742 else 3801 else
3743 XDeleteProperty (disp, TermWin.parent[0], 3802 XDeleteProperty (xdisp, parent[0],
3744 display->atom (str)); 3803 display->atom (str));
3745 } 3804 }
3746 break; 3805 break;
3747 3806
3748 case XTerm_Color: 3807 case XTerm_Color:
3750 { 3809 {
3751 if ((name = strchr (buf, ';')) == NULL) 3810 if ((name = strchr (buf, ';')) == NULL)
3752 break; 3811 break;
3753 3812
3754 *name++ = '\0'; 3813 *name++ = '\0';
3755 color = atoi (buf); 3814 color = atoi (buf) + minCOLOR;
3756 3815
3757 if (color < 0 || color >= TOTAL_COLORS) 3816 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3758 break; 3817 break;
3759 3818
3760 if ((buf = strchr (name, ';')) != NULL) 3819 if ((buf = strchr (name, ';')) != NULL)
3761 *buf++ = '\0'; 3820 *buf++ = '\0';
3762 3821
3763 if (name[0] == '?' && !name[1]) 3822 process_color_seq (op, color, name, resp);
3764 {
3765 unsigned short r, g, b;
3766 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3767 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3768 }
3769 else
3770 set_window_color (color + minCOLOR, name);
3771 } 3823 }
3772 break; 3824 break;
3773 case XTerm_Color00: 3825 case XTerm_Color00:
3774 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3826 process_color_seq (op, Color_fg, str, resp);
3775 break; 3827 break;
3776 case XTerm_Color01: 3828 case XTerm_Color01:
3777 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3829 process_color_seq (op, Color_bg, str, resp);
3778 break; 3830 break;
3779#ifndef NO_CURSORCOLOR 3831#ifndef NO_CURSORCOLOR
3780 case XTerm_Color_cursor: 3832 case XTerm_Color_cursor:
3781 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3833 process_color_seq (op, Color_cursor, str, resp);
3782 break; 3834 break;
3783#endif 3835#endif
3784 case XTerm_Color_pointer_fg: 3836 case XTerm_Color_pointer_fg:
3785 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3837 process_color_seq (op, Color_pointer_fg, str, resp);
3786 break; 3838 break;
3787 case XTerm_Color_pointer_bg: 3839 case XTerm_Color_pointer_bg:
3788 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3840 process_color_seq (op, Color_pointer_bg, str, resp);
3789 break; 3841 break;
3790#ifndef NO_BOLD_UNDERLINE_REVERSE 3842#ifndef NO_BOLD_UNDERLINE_REVERSE
3791 case XTerm_Color_BD:
3792 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3793 break;
3794 case XTerm_Color_IT:
3795 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3796 break;
3797 case XTerm_Color_UL:
3798 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3799 break;
3800 case XTerm_Color_RV: 3843 case XTerm_Color_RV:
3801 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3844 process_color_seq (op, Color_RV, str, resp);
3845 break;
3846 case Rxvt_Color_BD:
3847 case URxvt_Color_BD:
3848 process_color_seq (op, Color_BD, str, resp);
3849 break;
3850 case Rxvt_Color_UL:
3851 case URxvt_Color_UL:
3852 process_color_seq (op, Color_UL, str, resp);
3853 break;
3854 case URxvt_Color_IT:
3855 process_color_seq (op, Color_IT, str, resp);
3802 break; 3856 break;
3803#endif 3857#endif
3804#if TRANSPARENT && TINTING 3858#if TRANSPARENT && TINTING
3805 case XTerm_Color_tint: 3859 case URxvt_Color_tint:
3806 process_color_seq (XTerm_Color_tint, Color_tint, str, resp); 3860 process_color_seq (op, Color_tint, str, resp);
3861
3807 check_our_parents (); 3862 check_our_parents ();
3863
3808 if (am_transparent) 3864 if (am_transparent)
3809 want_full_refresh = want_refresh = 1; 3865 want_full_refresh = want_refresh = 1;
3810 break;
3811#endif
3812 3866
3867 break;
3868#endif
3869
3813 case XTerm_Pixmap: 3870 case Rxvt_Pixmap:
3871 {
3814 if (*str != ';') 3872 if (*str != ';')
3815 { 3873 {
3816#if XPM_BACKGROUND 3874#if XPM_BACKGROUND
3817 scale_pixmap (""); /* reset to default scaling */ 3875 scale_pixmap (""); /* reset to default scaling */
3818 set_bgPixmap (str); /* change pixmap */ 3876 set_bgPixmap (str); /* change pixmap */
3819#endif
3820 scr_touch (true); 3877 scr_touch (true);
3878#endif
3821 } 3879 }
3880
3881 int changed = 0;
3882
3822 while ((str = strchr (str, ';')) != NULL) 3883 while ((str = strchr (str, ';')) != NULL)
3823 { 3884 {
3824 str++; 3885 str++;
3825#if XPM_BACKGROUND 3886#if XPM_BACKGROUND
3826 changed += scale_pixmap (str); 3887 changed += scale_pixmap (str);
3827#endif 3888#endif
3828 } 3889 }
3829 3890
3830 if (changed) 3891 if (changed)
3831 { 3892 {
3832#ifdef XPM_BACKGROUND 3893#ifdef XPM_BACKGROUND
3833 resize_pixmap (); 3894 resize_pixmap ();
3834#endif
3835 scr_touch (true); 3895 scr_touch (true);
3896#endif
3836 } 3897 }
3898 }
3837 break; 3899 break;
3838 3900
3839 case XTerm_restoreFG: 3901 case Rxvt_restoreFG:
3840 set_window_color (Color_fg, str); 3902 set_window_color (Color_fg, str);
3841 break; 3903 break;
3842 case XTerm_restoreBG: 3904 case Rxvt_restoreBG:
3843 set_window_color (Color_bg, str); 3905 set_window_color (Color_bg, str);
3844 break; 3906 break;
3845 3907
3846 case XTerm_logfile: 3908 case XTerm_logfile:
3847 // TODO, when secure mode? 3909 // TODO, when secure mode?
3848 break; 3910 break;
3849 3911
3912#if 0
3913 case Rxvt_dumpscreen: /* no error notices */
3914 {
3915 int fd;
3916 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3917 {
3918 scr_dump (fd);
3919 close (fd);
3920 }
3921 }
3922 break;
3923#endif
3850 case XTerm_font: 3924 case XTerm_font:
3851 op = URxvt_font; 3925 op = URxvt_font;
3852 case URxvt_font: 3926 case URxvt_font:
3853#if ENABLE_STYLES 3927#if ENABLE_STYLES
3854 case URxvt_boldFont: 3928 case URxvt_boldFont:
3855 case URxvt_italicFont: 3929 case URxvt_italicFont:
3856 case URxvt_boldItalicFont: 3930 case URxvt_boldItalicFont:
3857#endif 3931#endif
3858 if (query) 3932 if (query)
3859 tt_printf ("\33]%d;%-.250s%c", saveop, 3933 tt_printf ("\33]%d;%-.250s%c", saveop,
3860 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc 3934 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3861 ? TermWin.fontset[op - URxvt_font]->fontdesc : "", 3935 ? fontset[op - URxvt_font]->fontdesc : "",
3862 resp); 3936 resp);
3863 else 3937 else
3864 { 3938 {
3865 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3939 const char *&res = rs[Rs_font + (op - URxvt_font)];
3866 3940
3868 allocated.push_back ((void *)res); 3942 allocated.push_back ((void *)res);
3869 set_fonts (); 3943 set_fonts ();
3870 } 3944 }
3871 break; 3945 break;
3872 3946
3873#if ENABLE_FRILLS 3947 case URxvt_version:
3874 case XTerm_locale:
3875 if (query) 3948 if (query)
3949 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3950 op,
3951 rs[Rs_name], VERSION[0], VERSION[2],
3952 resp);
3953 break;
3954
3955#if !ENABLE_MINIMAL
3956 case URxvt_locale:
3957 if (query)
3876 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3958 tt_printf ("\33]%d;%-.250s%c", op, OPTION (Opt_insecure) ? locale : "", resp);
3877 else 3959 else
3878 { 3960 {
3879 set_locale (str); 3961 set_locale (str);
3880 pty.set_utf8_mode (enc_utf8); 3962 pty->set_utf8_mode (enc_utf8);
3881# ifdef USE_XIM
3882 im_cb (); 3963 init_xlocale ();
3883# endif
3884 } 3964 }
3885 break; 3965 break;
3886#endif
3887 3966
3888#ifdef MENUBAR 3967 case URxvt_view_up:
3889 case XTerm_Menu: 3968 case URxvt_view_down:
3890 if (options & Opt_insecure) 3969 {
3891 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3970 int lines = atoi (str);
3971
3972 if (lines)
3973 scr_page (op == URxvt_view_up ? UP : DN, lines);
3974 else
3975 scr_erase_savelines ();
3976 }
3977
3892 break; 3978 break;
3893#endif 3979#endif
3894#if 0 3980
3895 case XTerm_dumpscreen: /* no error notices */ 3981#if ENABLE_PERL
3896 { 3982 case URxvt_perl:
3897 int fd; 3983 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END)))
3898 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3984 ; // no responses yet
3899 {
3900 scr_dump (fd);
3901 close (fd);
3902 }
3903 }
3904 break; 3985 break;
3905#endif 3986#endif
3906 } 3987 }
3907} 3988}
3908/*----------------------------------------------------------------------*/ 3989/*----------------------------------------------------------------------*/
3939 return state; 4020 return state;
3940} 4021}
3941 4022
3942/* we're not using priv _yet_ */ 4023/* we're not using priv _yet_ */
3943void 4024void
3944rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 4025rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3945{ 4026{
3946 unsigned int i, j; 4027 unsigned int i, j;
3947 int state; 4028 int state;
3948 4029
3949 static const struct 4030 static const struct
3960 { 5, PrivMode_rVideo }, 4041 { 5, PrivMode_rVideo },
3961 { 6, PrivMode_relOrigin }, 4042 { 6, PrivMode_relOrigin },
3962 { 7, PrivMode_Autowrap }, 4043 { 7, PrivMode_Autowrap },
3963 // 8, bi-directional support mode 4044 // 8, bi-directional support mode
3964 { 9, PrivMode_MouseX10 }, 4045 { 9, PrivMode_MouseX10 },
3965#ifdef menuBar_esc
3966 { menuBar_esc, PrivMode_menuBar },
3967#endif
3968 // 18, 19 printing-related 4046 // 18, 19 printing-related
3969 { 25, PrivMode_VisibleCursor }, 4047 { 25, PrivMode_VisibleCursor },
3970#ifdef scrollBar_esc 4048#ifdef scrollBar_esc
3971 { scrollBar_esc, PrivMode_scrollBar }, 4049 { scrollBar_esc, PrivMode_scrollBar },
3972#endif 4050#endif
4017 } 4095 }
4018 4096
4019 /* extra handling for values with state unkept */ 4097 /* extra handling for values with state unkept */
4020 switch (arg[i]) 4098 switch (arg[i])
4021 { 4099 {
4100#if ENABLE_STYLES
4101 case 1021:
4102 set_option (Opt_intensityStyles, mode);
4103
4104 scr_touch (true);
4105 break;
4106#endif
4022 case 1048: /* alternative cursor save */ 4107 case 1048: /* alternative cursor save */
4023 case 1049: 4108 case 1049:
4024 if (options & Opt_secondaryScreen) 4109 if (OPTION (Opt_secondaryScreen))
4025 if (mode == 0) 4110 if (mode == 0)
4026 scr_cursor (RESTORE); 4111 scr_cursor (RESTORE);
4027 else if (mode == 1) 4112 else if (mode == 1)
4028 scr_cursor (SAVE); 4113 scr_cursor (SAVE);
4029 break; 4114 break;
4041 */ 4126 */
4042 PrivMode (1, PrivMode_vt52); 4127 PrivMode (1, PrivMode_vt52);
4043 break; 4128 break;
4044 case 3: /* 80/132 */ 4129 case 3: /* 80/132 */
4045 if (priv_modes & PrivMode_132OK) 4130 if (priv_modes & PrivMode_132OK)
4046 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 4131 set_widthheight (((state ? 132 : 80) * fwidth), height);
4047 break; 4132 break;
4048 case 4: /* smooth scrolling */ 4133 case 4: /* smooth scrolling */
4049 if (state)
4050 options &= ~Opt_jumpScroll;
4051 else
4052 options |= Opt_jumpScroll; 4134 set_option (Opt_jumpScroll, !state);
4053 break; 4135 break;
4054 case 5: /* reverse video */ 4136 case 5: /* reverse video */
4055 scr_rvideo_mode (state); 4137 scr_rvideo_mode (state);
4056 break; 4138 break;
4057 case 6: /* relative/absolute origins */ 4139 case 6: /* relative/absolute origins */
4063 /* case 8: - auto repeat, can't do on a per window basis */ 4145 /* case 8: - auto repeat, can't do on a per window basis */
4064 case 9: /* X10 mouse reporting */ 4146 case 9: /* X10 mouse reporting */
4065 if (state) /* orthogonal */ 4147 if (state) /* orthogonal */
4066 priv_modes &= ~PrivMode_MouseX11; 4148 priv_modes &= ~PrivMode_MouseX11;
4067 break; 4149 break;
4068#ifdef menuBar_esc
4069 case menuBar_esc:
4070#ifdef MENUBAR
4071 map_menuBar (state);
4072#endif
4073 break;
4074#endif
4075#ifdef scrollBar_esc 4150#ifdef scrollBar_esc
4076 case scrollBar_esc: 4151 case scrollBar_esc:
4077 if (scrollbar_mapping (state)) 4152 if (scrollbar_mapping (state))
4078 { 4153 {
4079 resize_all_windows (0, 0, 0); 4154 resize_all_windows (0, 0, 0);
4098#if 0 4173#if 0
4099 case 1001: 4174 case 1001:
4100 break; /* X11 mouse highlighting */ 4175 break; /* X11 mouse highlighting */
4101#endif 4176#endif
4102 case 1010: /* scroll to bottom on TTY output inhibit */ 4177 case 1010: /* scroll to bottom on TTY output inhibit */
4103 if (state)
4104 options &= ~Opt_scrollTtyOutput;
4105 else
4106 options |= Opt_scrollTtyOutput; 4178 set_option (Opt_scrollTtyOutput, !state);
4107 break; 4179 break;
4108 case 1011: /* scroll to bottom on key press */ 4180 case 1011: /* scroll to bottom on key press */
4109 if (state)
4110 options |= Opt_scrollTtyKeypress; 4181 set_option (Opt_scrollTtyKeypress, state);
4111 else
4112 options &= ~Opt_scrollTtyKeypress;
4113 break; 4182 break;
4114 case 1047: /* secondary screen w/ clearing last */ 4183 case 1047: /* secondary screen w/ clearing last */
4115 if (options & Opt_secondaryScreen) 4184 if (OPTION (Opt_secondaryScreen))
4116 if (current_screen != PRIMARY) 4185 if (current_screen != PRIMARY)
4117 scr_erase_screen (2); 4186 scr_erase_screen (2);
4118 scr_change_screen (state); 4187 scr_change_screen (state);
4119 break; 4188 break;
4120 case 1049: /* secondary screen w/ clearing first */ 4189 case 1049: /* secondary screen w/ clearing first */
4121 scr_change_screen (state); 4190 scr_change_screen (state);
4122 if (options & Opt_secondaryScreen) 4191 if (OPTION (Opt_secondaryScreen))
4123 if (current_screen != PRIMARY) 4192 if (current_screen != PRIMARY)
4124 scr_erase_screen (2); 4193 scr_erase_screen (2);
4125 break; 4194 break;
4126 default: 4195 default:
4127 break; 4196 break;
4255 scr_color (Color_bg, Color_bg); 4324 scr_color (Color_bg, Color_bg);
4256 break; 4325 break;
4257 4326
4258 //case 50: // not variable spacing 4327 //case 50: // not variable spacing
4259 4328
4260#ifndef NO_BRIGHTCOLOR 4329#if !ENABLE_MINIMAL
4261 case 90: 4330 case 90:
4262 case 91: /* set bright fg color */ 4331 case 91: /* set bright fg color */
4263 case 92: 4332 case 92:
4264 case 93: 4333 case 93:
4265 case 94: 4334 case 94:
4277 case 106: 4346 case 106:
4278 case 107: 4347 case 107:
4279 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 4348 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4280 break; 4349 break;
4281#endif 4350#endif
4282
4283 } 4351 }
4284 } 4352 }
4285} 4353}
4286/*}}} */ 4354/*}}} */
4287 4355
4311 */ 4379 */
4312void 4380void
4313rxvt_term::tt_printf (const char *fmt,...) 4381rxvt_term::tt_printf (const char *fmt,...)
4314{ 4382{
4315 va_list arg_ptr; 4383 va_list arg_ptr;
4316 unsigned char buf[256]; 4384 char buf[256];
4317 4385
4318 va_start (arg_ptr, fmt); 4386 va_start (arg_ptr, fmt);
4319 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 4387 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4320 va_end (arg_ptr); 4388 va_end (arg_ptr);
4321 tt_write (buf, strlen (buf)); 4389 tt_write (buf, strlen (buf));
4326 * or generated by us in response to a query ESC sequence. 4394 * or generated by us in response to a query ESC sequence.
4327 */ 4395 */
4328const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4396const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4329 4397
4330void 4398void
4331rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4399rxvt_term::tt_write (const char *data, unsigned int len)
4332{ 4400{
4401 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
4402 return;
4403
4404 if (pty->pty < 0)
4405 return;
4406
4333 if (v_buflen == 0) 4407 if (v_buflen == 0)
4334 { 4408 {
4335 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 4409 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4336 4410
4337 if ((unsigned int)written == len) 4411 if ((unsigned int)written == len)
4338 return; 4412 return;
4339 4413
4340 data += written; 4414 data += written;
4341 len -= written; 4415 len -= written;
4342 } 4416 }
4343 4417
4344 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4418 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4345 4419
4346 memcpy (v_buffer + v_buflen, data, len); 4420 memcpy (v_buffer + v_buflen, data, len);
4347 v_buflen += len; 4421 v_buflen += len;
4348 4422
4349 pty_ev.set (EVENT_READ | EVENT_WRITE); 4423 pty_ev.set (EVENT_READ | EVENT_WRITE);
4350} 4424}
4351 4425
4352void rxvt_term::pty_write () 4426void rxvt_term::pty_write ()
4353{ 4427{
4354 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4428 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4355 4429
4356 if (written > 0) 4430 if (written > 0)
4357 { 4431 {
4358 v_buflen -= written; 4432 v_buflen -= written;
4359 4433
4368 } 4442 }
4369 4443
4370 memmove (v_buffer, v_buffer + written, v_buflen); 4444 memmove (v_buffer, v_buffer + written, v_buflen);
4371 } 4445 }
4372 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4446 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4373 // original code just ignores this... 4447 pty_ev.set (EVENT_READ);
4374 destroy ();
4375} 4448}
4376 4449
4377/*----------------------- end-of-file (C source) -----------------------*/ 4450/*----------------------- end-of-file (C source) -----------------------*/
4378 4451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines