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.201 by root, Mon Feb 21 19:26:07 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
1335 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) 1397 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1336 { 1398 {
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 {
1337 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1403 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1404 {
1405 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1338 destroy (); 1406 destroy ();
1407 }
1339#if ENABLE_EWMH 1408#if ENABLE_EWMH
1340 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1409 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1341 XSendEvent (disp, ev.xclient.window = display->root, 1410 XSendEvent (xdisp, ev.xclient.window = display->root,
1342 False, SubstructureRedirectMask | SubstructureNotifyMask, 1411 False, SubstructureRedirectMask | SubstructureNotifyMask,
1343 &ev); 1412 &ev);
1413#endif
1414 }
1415 }
1416#if ENABLE_XEMBED
1417 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1418 {
1419 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1420 focus_in ();
1421 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1422 focus_out ();
1423 }
1344#endif 1424#endif
1345 } 1425 }
1346#if ENABLE_XEMBED
1347 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1348 {
1349 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1350 focus_in ();
1351 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1352 focus_out ();
1353 }
1354#endif
1355#ifdef OFFIX_DND
1356 /* OffiX Dnd (drag 'n' drop) protocol */
1357 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1358 && (ev.xclient.data.l[0] == DndFile
1359 || ev.xclient.data.l[0] == DndDir
1360 || ev.xclient.data.l[0] == DndLink))
1361 {
1362 /* Get Dnd data */
1363 Atom ActualType;
1364 int ActualFormat;
1365 unsigned char *data;
1366 unsigned long Size, RemainingBytes;
1367
1368 XGetWindowProperty (disp, display->root,
1369 xa[XA_DNDSELECTION],
1370 0L, 1000000L,
1371 False, AnyPropertyType,
1372 &ActualType, &ActualFormat,
1373 &Size, &RemainingBytes,
1374 &data);
1375 set_string_property (XA_CUT_BUFFER0, data);
1376 XFree (data);
1377 selection_paste (display->root, XA_CUT_BUFFER0, true);
1378 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1379 }
1380#endif /* OFFIX_DND */
1381 break; 1426 break;
1382 1427
1383 case MappingNotify: 1428 case MappingNotify:
1384 XRefreshKeyboardMapping (&ev.xmapping); 1429 XRefreshKeyboardMapping (&ev.xmapping);
1385 break; 1430 break;
1416 case FocusOut: 1461 case FocusOut:
1417 focus_out (); 1462 focus_out ();
1418 break; 1463 break;
1419 1464
1420 case ConfigureNotify: 1465 case ConfigureNotify:
1421 if (ev.xconfigure.window == TermWin.parent[0]) 1466 if (ev.xconfigure.window == parent[0])
1422 { 1467 {
1423 int height, width;
1424
1425 do
1426 { /* Wrap lots of configures into one */
1427 width = ev.xconfigure.width;
1428 height = ev.xconfigure.height;
1429 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height));
1430 }
1431 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)); 1468 while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev))
1469 ;
1432 1470
1433 if (szHint.width != width || szHint.height != height) 1471 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1434 { 1472 {
1435 seen_resize = 1; 1473 seen_resize = 1;
1436 resize_all_windows (width, height, 1); 1474 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1437 } 1475 }
1438 1476
1477 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1478
1439#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1479#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1440 if (options & Opt_transparent) 1480 if (OPTION (Opt_transparent))
1441 check_our_parents (); 1481 check_our_parents ();
1442#endif 1482#endif
1443 } 1483 }
1444 break; 1484 break;
1445 1485
1446 case PropertyNotify: 1486 case PropertyNotify:
1487 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1447 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1488 if (ev.xproperty.atom == xa[XA_VT_SELECTION]
1448 && ev.xproperty.state == PropertyNewValue) 1489 && ev.xproperty.state == PropertyNewValue)
1449 selection_property (ev.xproperty.window, ev.xproperty.atom); 1490 selection_property (ev.xproperty.window, ev.xproperty.atom);
1450 1491
1451 break; 1492 break;
1452 1493
1453 case SelectionClear: 1494 case SelectionClear:
1454 selection_clear (); 1495 selection_clear ();
1461 1502
1462 case SelectionRequest: 1503 case SelectionRequest:
1463 selection_send (ev.xselectionrequest); 1504 selection_send (ev.xselectionrequest);
1464 break; 1505 break;
1465 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
1466 case UnmapNotify: 1515 case UnmapNotify:
1467 TermWin.mapped = 0; 1516 mapped = 0;
1468#ifdef TEXT_BLINK 1517#ifdef TEXT_BLINK
1469 text_blink_ev.stop (); 1518 text_blink_ev.stop ();
1470#endif 1519#endif
1471 break; 1520 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1472
1473 case MapNotify:
1474 TermWin.mapped = 1;
1475#ifdef TEXT_BLINK
1476 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1477#endif
1478 break; 1521 break;
1479 1522
1480#ifdef TRANSPARENT 1523#ifdef TRANSPARENT
1481 case ReparentNotify: 1524 case ReparentNotify:
1482 rootwin_cb (ev); 1525 rootwin_cb (ev);
1483 break; 1526 break;
1484#endif /* TRANSPARENT */ 1527#endif /* TRANSPARENT */
1485 1528
1486 case GraphicsExpose: 1529 case GraphicsExpose:
1487 case Expose: 1530 case Expose:
1488 if (ev.xany.window == TermWin.vt) 1531 if (ev.xany.window == vt)
1489 { 1532 {
1490 do 1533 do
1491 scr_expose (ev.xexpose.x, ev.xexpose.y, 1534 scr_expose (ev.xexpose.x, ev.xexpose.y,
1492 ev.xexpose.width, ev.xexpose.height, False); 1535 ev.xexpose.width, ev.xexpose.height, False);
1493 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); 1536 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev));
1494 1537
1495 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1538 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1496 1539
1497 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) 1540 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev))
1498 scr_expose (ev.xexpose.x, ev.xexpose.y, 1541 scr_expose (ev.xexpose.x, ev.xexpose.y,
1499 ev.xexpose.width, ev.xexpose.height, False); 1542 ev.xexpose.width, ev.xexpose.height, False);
1500 1543
1501 scr_refresh (refresh_type); 1544 want_refresh = 1;
1502 } 1545 }
1503 else 1546 else
1504 { 1547 {
1505 XEvent unused_event; 1548 XEvent unused_event;
1506 1549
1507 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1550 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event))
1508 ; 1551 ;
1509 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1552 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event))
1510 ; 1553 ;
1511 1554
1512 if (isScrollbarWindow (ev.xany.window)) 1555 if (isScrollbarWindow (ev.xany.window))
1513 { 1556 {
1514 scrollBar.setIdle (); 1557 scrollBar.setIdle ();
1515 scrollbar_show (0); 1558 scrollbar_show (0);
1516 } 1559 }
1517#ifdef MENUBAR
1518 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1519 menubar_expose ();
1520#endif
1521 1560
1522#ifdef TRANSPARENT 1561#ifdef TRANSPARENT
1523 if (am_transparent && ev.xany.window == TermWin.parent[0]) 1562 if (am_transparent && ev.xany.window == parent[0])
1524 XClearWindow (disp, ev.xany.window); 1563 XClearWindow (xdisp, ev.xany.window);
1525#endif 1564#endif
1526 } 1565 }
1527 break; 1566 break;
1528 1567
1529 case MotionNotify: 1568 case MotionNotify:
1530#ifdef POINTER_BLANK 1569#ifdef POINTER_BLANK
1531 if (hidden_pointer) 1570 if (hidden_pointer)
1532 pointer_unblank (); 1571 pointer_unblank ();
1533#endif 1572#endif
1534#if MENUBAR
1535 if (isMenuBarWindow (ev.xany.window))
1536 {
1537 menubar_control (ev.xbutton);
1538 break;
1539 }
1540#endif
1541 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1573 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1542 break; 1574 break;
1543 1575
1544 if (ev.xany.window == TermWin.vt) 1576 if (ev.xany.window == vt)
1545 { 1577 {
1578 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1579 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1580 ; // nop
1546 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1581 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1547 { 1582 {
1548 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) 1583 while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev))
1549 ; 1584 ;
1550 1585
1551 XQueryPointer (disp, TermWin.vt, 1586 XQueryPointer (xdisp, vt,
1552 &unused_root, &unused_child, 1587 &unused_root, &unused_child,
1553 &unused_root_x, &unused_root_y, 1588 &unused_root_x, &unused_root_y,
1554 &ev.xbutton.x, &ev.xbutton.y, 1589 &ev.xbutton.x, &ev.xbutton.y,
1555 &ev.xbutton.state); 1590 &ev.xbutton.state);
1556#ifdef MOUSE_THRESHOLD 1591#ifdef MOUSE_THRESHOLD
1568#endif 1603#endif
1569 selection_extend (ev.xbutton.x, ev.xbutton.y, 1604 selection_extend (ev.xbutton.x, ev.xbutton.y,
1570 ev.xbutton.state & Button3Mask ? 2 : 0); 1605 ev.xbutton.state & Button3Mask ? 2 : 0);
1571 1606
1572#ifdef SELECTION_SCROLLING 1607#ifdef SELECTION_SCROLLING
1573 if (ev.xbutton.y < TermWin.int_bwidth 1608 if (ev.xbutton.y < int_bwidth
1574 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1609 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1575 { 1610 {
1576 int dist; 1611 int dist;
1577 1612
1578 /* don't clobber the current delay if we are 1613 /* don't clobber the current delay if we are
1579 * already in the middle of scrolling. 1614 * already in the middle of scrolling.
1587 selection_save_x = ev.xbutton.x; 1622 selection_save_x = ev.xbutton.x;
1588 selection_save_y = ev.xbutton.y; 1623 selection_save_y = ev.xbutton.y;
1589 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1624 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1590 1625
1591 /* calc number of lines to scroll */ 1626 /* calc number of lines to scroll */
1592 if (ev.xbutton.y < TermWin.int_bwidth) 1627 if (ev.xbutton.y < int_bwidth)
1593 { 1628 {
1594 scroll_selection_dir = UP; 1629 scroll_selection_dir = UP;
1595 dist = TermWin.int_bwidth - ev.xbutton.y; 1630 dist = int_bwidth - ev.xbutton.y;
1596 } 1631 }
1597 else 1632 else
1598 { 1633 {
1599 scroll_selection_dir = DN; 1634 scroll_selection_dir = DN;
1600 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1635 dist = ev.xbutton.y - (int_bwidth + height);
1601 } 1636 }
1602 1637
1603 scroll_selection_lines = Pixel2Height (dist) 1638 scroll_selection_lines = Pixel2Height (dist)
1604 / SELECTION_SCROLL_LINE_SPEEDUP 1639 / SELECTION_SCROLL_LINE_SPEEDUP
1605 + 1; 1640 + 1;
1606 MIN_IT (scroll_selection_lines, 1641 min_it (scroll_selection_lines,
1607 SELECTION_SCROLL_MAX_LINES); 1642 SELECTION_SCROLL_MAX_LINES);
1608 } 1643 }
1609 else 1644 else
1610 { 1645 {
1611 /* we are within the text window, so we 1646 /* we are within the text window, so we
1620#endif 1655#endif
1621 } 1656 }
1622 } 1657 }
1623 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1658 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ())
1624 { 1659 {
1625 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1660 while (XCheckTypedWindowEvent (xdisp, scrollBar.win,
1626 MotionNotify, &ev)) 1661 MotionNotify, &ev))
1627 ; 1662 ;
1628 1663
1629 XQueryPointer (disp, scrollBar.win, 1664 XQueryPointer (xdisp, scrollBar.win,
1630 &unused_root, &unused_child, 1665 &unused_root, &unused_child,
1631 &unused_root_x, &unused_root_y, 1666 &unused_root_x, &unused_root_y,
1632 &ev.xbutton.x, &ev.xbutton.y, 1667 &ev.xbutton.x, &ev.xbutton.y,
1633 &unused_mask); 1668 &unused_mask);
1634 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1669 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1635 scrollbar_size ()); 1670 scrollbar_size ());
1636 scr_refresh (refresh_type); 1671 want_refresh = 1;
1637 refresh_limit = 0; 1672 refresh_limit = 0;
1638 scrollbar_show (1); 1673 scrollbar_show (1);
1639 } 1674 }
1640 break; 1675 break;
1641 } 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
1642} 1706}
1643 1707
1644void 1708void
1645rxvt_term::focus_in () 1709rxvt_term::focus_in ()
1646{ 1710{
1647 if (!TermWin.focus) 1711 if (!focus)
1648 { 1712 {
1649 TermWin.focus = 1; 1713 focus = 1;
1650 want_refresh = 1; 1714 want_refresh = 1;
1715
1716 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1717
1651#ifdef USE_XIM 1718#if USE_XIM
1652 if (Input_Context != NULL) 1719 if (Input_Context != NULL)
1653 { 1720 {
1654 IMSetStatusPosition (); 1721 IMSetStatusPosition ();
1655 XSetICFocus (Input_Context); 1722 XSetICFocus (Input_Context);
1656 } 1723 }
1657#endif 1724#endif
1658#ifdef CURSOR_BLINK 1725#if CURSOR_BLINK
1659 if (options & Opt_cursorBlink) 1726 if (OPTION (Opt_cursorBlink))
1660 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1727 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1661#endif 1728#endif
1662#ifdef OFF_FOCUS_FADING 1729#if OFF_FOCUS_FADING
1663 if (rs[Rs_fade]) 1730 if (rs[Rs_fade])
1664 { 1731 {
1665 pix_colors = pix_colors_focused; 1732 pix_colors = pix_colors_focused;
1666 scr_recolour (); 1733 scr_recolour ();
1667 } 1734 }
1670} 1737}
1671 1738
1672void 1739void
1673rxvt_term::focus_out () 1740rxvt_term::focus_out ()
1674{ 1741{
1675 if (TermWin.focus) 1742 if (focus)
1676 { 1743 {
1677 TermWin.focus = 0; 1744 focus = 0;
1678 want_refresh = 1; 1745 want_refresh = 1;
1679 1746
1747 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1748
1680#if ENABLE_FRILLS || ISO_14755 1749#if ENABLE_FRILLS || ISO_14755
1750 if (iso14755buf)
1751 {
1681 iso14755buf = 0; 1752 iso14755buf = 0;
1682#endif
1683#if ENABLE_OVERLAY 1753# if ENABLE_OVERLAY
1684 scr_overlay_off (); 1754 scr_overlay_off ();
1685#endif 1755# endif
1756 }
1757#endif
1686#ifdef USE_XIM 1758#if USE_XIM
1687 if (Input_Context != NULL) 1759 if (Input_Context != NULL)
1688 XUnsetICFocus (Input_Context); 1760 XUnsetICFocus (Input_Context);
1689#endif 1761#endif
1690#ifdef CURSOR_BLINK 1762#if CURSOR_BLINK
1691 if (options & Opt_cursorBlink) 1763 if (OPTION (Opt_cursorBlink))
1692 cursor_blink_ev.stop (); 1764 cursor_blink_ev.stop ();
1693 hidden_cursor = 0; 1765 hidden_cursor = 0;
1694#endif 1766#endif
1695#ifdef OFF_FOCUS_FADING 1767#if OFF_FOCUS_FADING
1696 if (rs[Rs_fade]) 1768 if (rs[Rs_fade])
1697 { 1769 {
1698 pix_colors = pix_colors_unfocused; 1770 pix_colors = pix_colors_unfocused;
1699 scr_recolour (); 1771 scr_recolour ();
1700 } 1772 }
1704 1776
1705#if TRANSPARENT 1777#if TRANSPARENT
1706void 1778void
1707rxvt_term::rootwin_cb (XEvent &ev) 1779rxvt_term::rootwin_cb (XEvent &ev)
1708{ 1780{
1709 SET_R (this); 1781 make_current ();
1710 SET_LOCALE (locale);
1711 1782
1712 switch (ev.type) 1783 switch (ev.type)
1713 { 1784 {
1714 case PropertyNotify: 1785 case PropertyNotify:
1715 /* 1786 /*
1720 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1791 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1721 return; 1792 return;
1722 1793
1723 /* FALLTHROUGH */ 1794 /* FALLTHROUGH */
1724 case ReparentNotify: 1795 case ReparentNotify:
1725 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1796 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1726 want_refresh = want_full_refresh = 1; 1797 want_refresh = want_full_refresh = 1;
1727 break; 1798 break;
1728 } 1799 }
1729} 1800}
1730#endif 1801#endif
1733rxvt_term::button_press (XButtonEvent &ev) 1804rxvt_term::button_press (XButtonEvent &ev)
1734{ 1805{
1735 int reportmode = 0, clickintime; 1806 int reportmode = 0, clickintime;
1736 1807
1737 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1808 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1809
1738 if (!bypass_keystate) 1810 if (!bypass_keystate)
1739 reportmode = !! (priv_modes & PrivMode_mouse_report); 1811 reportmode = !! (priv_modes & PrivMode_mouse_report);
1740 1812
1741 /* 1813 /*
1742 * VT window processing of button press 1814 * VT window processing of button press
1743 */ 1815 */
1744 if (ev.window == TermWin.vt) 1816 if (ev.window == vt)
1745 { 1817 {
1818 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1819 return;
1820
1746#if ISO_14755 1821#if ISO_14755
1747 // 5.4 1822 // 5.4
1748 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1823 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1749 { 1824 {
1750 iso14755_54 (ev.x, ev.y); 1825 iso14755_54 (ev.x, ev.y);
1762#ifdef MOUSE_REPORT_DOUBLECLICK 1837#ifdef MOUSE_REPORT_DOUBLECLICK
1763 if (ev.button == MEvent.button && clickintime) 1838 if (ev.button == MEvent.button && clickintime)
1764 { 1839 {
1765 /* same button, within alloted time */ 1840 /* same button, within alloted time */
1766 MEvent.clicks++; 1841 MEvent.clicks++;
1842
1767 if (MEvent.clicks > 1) 1843 if (MEvent.clicks > 1)
1768 { 1844 {
1769 /* only report double clicks */ 1845 /* only report double clicks */
1770 MEvent.clicks = 2; 1846 MEvent.clicks = 2;
1771 mouse_report (ev); 1847 mouse_report (ev);
1803#else 1879#else
1804 selection.rect = false; 1880 selection.rect = false;
1805#endif 1881#endif
1806 1882
1807 /* allow shift+left click to extend selection */ 1883 /* allow shift+left click to extend selection */
1808 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1884 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1809 { 1885 {
1810 if (MEvent.button == Button1 && clickintime) 1886 if (MEvent.button == Button1 && clickintime)
1811 selection_rotate (ev.x, ev.y); 1887 selection_rotate (ev.x, ev.y);
1812 else 1888 else
1813 selection_extend (ev.x, ev.y, 1); 1889 selection_extend (ev.x, ev.y, 1);
1954 case Button3: 2030 case Button3:
1955 if (scrollBar.style != R_SB_XTERM) 2031 if (scrollBar.style != R_SB_XTERM)
1956 { 2032 {
1957 if (scrollbar_above_slider (ev.y)) 2033 if (scrollbar_above_slider (ev.y))
1958# ifdef RXVT_SCROLL_FULL 2034# ifdef RXVT_SCROLL_FULL
1959 scr_page (UP, TermWin.nrow - 1); 2035 scr_page (UP, nrow - 1);
1960# else 2036# else
1961 scr_page (UP, TermWin.nrow / 4); 2037 scr_page (UP, nrow / 4);
1962# endif 2038# endif
1963 else if (scrollbar_below_slider (ev.y)) 2039 else if (scrollbar_below_slider (ev.y))
1964# ifdef RXVT_SCROLL_FULL 2040# ifdef RXVT_SCROLL_FULL
1965 scr_page (DN, TermWin.nrow - 1); 2041 scr_page (DN, nrow - 1);
1966# else 2042# else
1967 scr_page (DN, TermWin.nrow / 4); 2043 scr_page (DN, nrow / 4);
1968# endif 2044# endif
1969 else 2045 else
1970 scrollBar.setMotion (); 2046 scrollBar.setMotion ();
1971 } 2047 }
1972 else 2048 else
1973 { 2049 {
1974 scr_page ((ev.button == Button1 ? DN : UP), 2050 scr_page ((ev.button == Button1 ? DN : UP),
1975 (TermWin.nrow 2051 (nrow
1976 * scrollbar_position (ev.y) 2052 * scrollbar_position (ev.y)
1977 / scrollbar_size ())); 2053 / scrollbar_size ()));
1978 } 2054 }
1979 2055
1980 break; 2056 break;
1981 } 2057 }
1982 } 2058 }
2059
1983 return; 2060 return;
1984 } 2061 }
1985#if MENUBAR
1986 /*
1987 * Menubar window processing of button press
1988 */
1989 if (isMenuBarWindow (ev.window))
1990 menubar_control (ev);
1991#endif
1992} 2062}
1993 2063
1994void 2064void
1995rxvt_term::button_release (XButtonEvent &ev) 2065rxvt_term::button_release (XButtonEvent &ev)
1996{ 2066{
2002 2072
2003 if (scrollbar_isUpDn ()) 2073 if (scrollbar_isUpDn ())
2004 { 2074 {
2005 scrollBar.setIdle (); 2075 scrollBar.setIdle ();
2006 scrollbar_show (0); 2076 scrollbar_show (0);
2007#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2008 refresh_type &= ~SMOOTH_REFRESH;
2009#endif
2010 } 2077 }
2011 2078
2012#ifdef SELECTION_SCROLLING 2079#ifdef SELECTION_SCROLLING
2013 if (sel_scroll_ev.active) 2080 if (sel_scroll_ev.active)
2014 sel_scroll_ev.stop(); 2081 sel_scroll_ev.stop();
2015#endif 2082#endif
2016 2083
2017 if (ev.window == TermWin.vt) 2084 if (ev.window == vt)
2018 { 2085 {
2086 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2087 return;
2088
2019#if ISO_14755 2089#if ISO_14755
2020 // 5.4 2090 // 5.4
2021 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2091 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2022 return; 2092 return;
2023#endif 2093#endif
2094
2024 if (reportmode) 2095 if (reportmode)
2025 { 2096 {
2026 /* mouse report from vt window */ 2097 /* mouse report from vt window */
2027 /* don't report release of wheel "buttons" */ 2098 /* don't report release of wheel "buttons" */
2028 if (ev.button >= 4) 2099 if (ev.button >= 4)
2058 { 2129 {
2059 case Button1: 2130 case Button1:
2060 case Button3: 2131 case Button3:
2061 selection_make (ev.time); 2132 selection_make (ev.time);
2062 break; 2133 break;
2134
2063 case Button2: 2135 case Button2:
2064 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);
2065 break; 2138 break;
2139
2066#ifdef MOUSE_WHEEL 2140#ifdef MOUSE_WHEEL
2067 case Button4: 2141 case Button4:
2068 case Button5: 2142 case Button5:
2069 { 2143 {
2070 int i; 2144 int i;
2072 2146
2073 v = ev.button == Button4 ? UP : DN; 2147 v = ev.button == Button4 ? UP : DN;
2074 2148
2075 if (ev.state & ShiftMask) 2149 if (ev.state & ShiftMask)
2076 i = 1; 2150 i = 1;
2077 else if (options & Opt_mouseWheelScrollPage) 2151 else if (OPTION (Opt_mouseWheelScrollPage))
2078 i = TermWin.nrow - 1; 2152 i = nrow - 1;
2079 else 2153 else
2080 i = 5; 2154 i = 5;
2081 2155
2082# ifdef MOUSE_SLIP_WHEELING 2156# ifdef MOUSE_SLIP_WHEELING
2083 if (ev.state & ControlMask) 2157 if (ev.state & ControlMask)
2084 { 2158 {
2085 mouse_slip_wheel_speed += v ? -1 : 1; 2159 mouse_slip_wheel_speed += v ? -1 : 1;
2086 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;
2087 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;
2088 2162
2089 if (slip_wheel_ev.at < NOW) 2163 if (slip_wheel_ev.at < NOW)
2090 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2164 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY;
2091 2165
2092 slip_wheel_ev.start (); 2166 slip_wheel_ev.start ();
2093 } 2167 }
2094 else 2168 else
2095 { 2169 {
2096# endif 2170# endif
2097# ifdef JUMP_MOUSE_WHEEL
2098 scr_page (v, i); 2171 scr_page (v, i);
2099 scr_refresh (SMOOTH_REFRESH);
2100 scrollbar_show (1); 2172 scrollbar_show (1);
2101# else
2102 while (i--)
2103 {
2104 scr_page (v, 1);
2105 scr_refresh (SMOOTH_REFRESH);
2106 scrollbar_show (1);
2107 }
2108# endif
2109# ifdef MOUSE_SLIP_WHEELING 2173# ifdef MOUSE_SLIP_WHEELING
2110 } 2174 }
2111#endif 2175# endif
2112 } 2176 }
2113 break; 2177 break;
2114#endif 2178#endif
2115 } 2179 }
2116 } 2180 }
2117#ifdef MENUBAR
2118 else if (isMenuBarWindow (ev.window))
2119 menubar_control (ev);
2120#endif
2121} 2181}
2122 2182
2123#ifdef TRANSPARENT 2183#ifdef TRANSPARENT
2124#if TINTING 2184#if TINTING
2125/* taken from aterm-0.4.2 */ 2185/* taken from aterm-0.4.2 */
2126 2186
2127typedef uint32_t RUINT32T; 2187typedef uint32_t RUINT32T;
2128 2188
2129void 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)
2130{ 2190{
2131 int sh_r, sh_g, sh_b; 2191 int sh_r, sh_g, sh_b;
2132 RUINT32T mask_r, mask_g, mask_b; 2192 RUINT32T mask_r, mask_g, mask_b;
2133 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; 2193 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2134 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 2194 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2135 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 2195 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2136 int i; 2196 int i;
2137 2197
2138 Visual *visual = display->visual; 2198 Visual *visual = term->visual;
2139 2199
2140 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 2200 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2141 2201
2142 /* for convenience */ 2202 /* for convenience */
2143 mask_r = visual->red_mask; 2203 mask_r = visual->red_mask;
2364 Atom atype; 2424 Atom atype;
2365 unsigned char *prop = NULL; 2425 unsigned char *prop = NULL;
2366 Window root, oldp, *list; 2426 Window root, oldp, *list;
2367 Pixmap rootpixmap = None; 2427 Pixmap rootpixmap = None;
2368 XWindowAttributes wattr, wrootattr; 2428 XWindowAttributes wattr, wrootattr;
2369 dDisp;
2370 2429
2371 pchanged = 0; 2430 pchanged = 0;
2372 2431
2373 if (!(options & Opt_transparent)) 2432 if (!OPTION (Opt_transparent))
2374 return pchanged; /* Don't try any more */ 2433 return pchanged; /* Don't try any more */
2375 2434
2376 XGetWindowAttributes (disp, display->root, &wrootattr); 2435 XGetWindowAttributes (xdisp, display->root, &wrootattr);
2377 rootdepth = wrootattr.depth; 2436 rootdepth = wrootattr.depth;
2378 2437
2379 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 2438 XGetWindowAttributes (xdisp, parent[0], &wattr);
2380 2439
2381 if (rootdepth != wattr.depth) 2440 if (rootdepth != wattr.depth)
2382 { 2441 {
2383 if (am_transparent) 2442 if (am_transparent)
2384 { 2443 {
2385 pchanged = 1; 2444 pchanged = 1;
2386 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); 2445 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2387 am_transparent = am_pixmap_trans = 0; 2446 am_transparent = am_pixmap_trans = 0;
2388 } 2447 }
2389 2448
2390 return pchanged; /* Don't try any more */ 2449 return pchanged; /* Don't try any more */
2391 } 2450 }
2392 2451
2393 /* 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. */
2394 XSync (disp, False); 2453 XSync (xdisp, False);
2395 2454
2396 /* 2455 /*
2397 * Make the frame window set by the window manager have 2456 * Make the frame window set by the window manager have
2398 * the root background. Some window managers put multiple nested frame 2457 * the root background. Some window managers put multiple nested frame
2399 * 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.
2400 */ 2459 */
2401 i = (xa[XA_XROOTPMAP_ID] 2460 i = (xa[XA_XROOTPMAP_ID]
2402 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID], 2461 && XGetWindowProperty (xdisp, display->root, xa[XA_XROOTPMAP_ID],
2403 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2462 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2404 &nitems, &bytes_after, &prop) == Success); 2463 &nitems, &bytes_after, &prop) == Success);
2405 2464
2406 if (!i || prop == NULL) 2465 if (!i || prop == NULL)
2407 i = (xa[XA_ESETROOT_PMAP_ID] 2466 i = (xa[XA_ESETROOT_PMAP_ID]
2408 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID], 2467 && XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID],
2409 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 2468 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2410 &nitems, &bytes_after, &prop) == Success); 2469 &nitems, &bytes_after, &prop) == Success);
2411 2470
2412 if (!i || prop == NULL 2471 if (!i || prop == NULL
2413#if TINTING 2472#if TINTING
2414 || !rs[Rs_color + Color_tint] 2473 || !ISSET_PIXCOLOR (Color_tint)
2415#endif 2474#endif
2416 ) 2475 )
2417 have_pixmap = 0; 2476 have_pixmap = 0;
2418 else 2477 else
2419 { 2478 {
2432 Window cr; 2491 Window cr;
2433 XImage *image; 2492 XImage *image;
2434 GC gc; 2493 GC gc;
2435 XGCValues gcvalue; 2494 XGCValues gcvalue;
2436 2495
2437 XTranslateCoordinates (disp, TermWin.parent[0], display->root, 2496 XTranslateCoordinates (xdisp, parent[0], display->root,
2438 0, 0, &sx, &sy, &cr); 2497 0, 0, &sx, &sy, &cr);
2439 nw = (unsigned int)szHint.width; 2498 nw = (unsigned int)szHint.width;
2440 nh = (unsigned int)szHint.height; 2499 nh = (unsigned int)szHint.height;
2441 nx = ny = 0; 2500 nx = ny = 0;
2442 2501
2452 nh += sy; 2511 nh += sy;
2453 ny = -sy; 2512 ny = -sy;
2454 sy = 0; 2513 sy = 0;
2455 } 2514 }
2456 2515
2457 MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); 2516 min_it (nw, (unsigned int) (wrootattr.width - sx));
2458 MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); 2517 min_it (nh, (unsigned int) (wrootattr.height - sy));
2459 2518
2460 XSync (disp, False); 2519 XSync (xdisp, False);
2461 allowedxerror = -1; 2520 allowedxerror = -1;
2462 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); 2521 image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2463 2522
2464 /* XXX: handle BadMatch - usually because we're outside the pixmap */ 2523 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2465 /* XXX: may need a delay here? */ 2524 /* XXX: may need a delay here? */
2466 allowedxerror = 0; 2525 allowedxerror = 0;
2467 2526
2468 if (image == NULL) 2527 if (image == NULL)
2469 { 2528 {
2470 if (am_transparent && am_pixmap_trans) 2529 if (am_transparent && am_pixmap_trans)
2471 { 2530 {
2472 pchanged = 1; 2531 pchanged = 1;
2473 if (TermWin.pixmap != None) 2532 if (pixmap != None)
2474 { 2533 {
2475 XFreePixmap (disp, TermWin.pixmap); 2534 XFreePixmap (xdisp, pixmap);
2476 TermWin.pixmap = None; 2535 pixmap = None;
2477 } 2536 }
2478 } 2537 }
2479 2538
2480 am_pixmap_trans = 0; 2539 am_pixmap_trans = 0;
2481 } 2540 }
2482 else 2541 else
2483 { 2542 {
2484 if (TermWin.pixmap != None) 2543 if (pixmap != None)
2485 XFreePixmap (disp, TermWin.pixmap); 2544 XFreePixmap (xdisp, pixmap);
2486 2545
2487#if TINTING 2546#if TINTING
2488 if (ISSET_PIXCOLOR (Color_tint)) 2547 if (ISSET_PIXCOLOR (Color_tint))
2489 { 2548 {
2490 unsigned short rm, gm, bm;
2491 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; 2549 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2492 2550
2551 rgba c;
2493 pix_colors_focused[Color_tint].get (display, rm, gm, bm); 2552 pix_colors_focused [Color_tint].get (c);
2494 2553
2495 ShadeXImage (display, image, shade, rm, gm, bm); 2554 ShadeXImage (this, image, shade, c.r, c.g, c.b);
2496 } 2555 }
2497#endif 2556#endif
2498 2557
2499 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt, 2558 pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth);
2500 szHint.width, szHint.height, image->depth);
2501 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue); 2559 gc = XCreateGC (xdisp, vt, 0UL, &gcvalue);
2502 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0, 2560 XPutImage (xdisp, pixmap, gc, image, 0, 0,
2503 nx, ny, image->width, image->height); 2561 nx, ny, image->width, image->height);
2504 XFreeGC (disp, gc); 2562 XFreeGC (xdisp, gc);
2505 XDestroyImage (image); 2563 XDestroyImage (image);
2506 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap); 2564 XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap);
2507 XClearWindow (disp, TermWin.parent[0]); 2565 XClearWindow (xdisp, parent[0]);
2508 2566
2509 if (!am_transparent || !am_pixmap_trans) 2567 if (!am_transparent || !am_pixmap_trans)
2510 pchanged = 1; 2568 pchanged = 1;
2511 2569
2512 am_transparent = am_pixmap_trans = 1; 2570 am_transparent = am_pixmap_trans = 1;
2513 } 2571 }
2514 } 2572 }
2515 2573
2516 if (am_pixmap_trans) 2574 if (am_pixmap_trans)
2517 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); 2575 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2518 else 2576 else
2519 { 2577 {
2520 unsigned int n; 2578 unsigned int n;
2521 /* 2579 /*
2522 * InheritPixmap transparency 2580 * InheritPixmap transparency
2523 */ 2581 */
2524 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2582 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2525 { 2583 {
2526 oldp = TermWin.parent[i]; 2584 oldp = parent[i];
2527 XQueryTree (disp, TermWin.parent[i - 1], &root, 2585 XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n);
2528 &TermWin.parent[i], &list, &n);
2529 XFree (list); 2586 XFree (list);
2530 2587
2531 if (TermWin.parent[i] == display->root) 2588 if (parent[i] == display->root)
2532 { 2589 {
2533 if (oldp != None) 2590 if (oldp != None)
2534 pchanged = 1; 2591 pchanged = 1;
2535 2592
2536 break; 2593 break;
2537 } 2594 }
2538 2595
2539 if (oldp != TermWin.parent[i]) 2596 if (oldp != parent[i])
2540 pchanged = 1; 2597 pchanged = 1;
2541 } 2598 }
2542 2599
2543 n = 0; 2600 n = 0;
2544 2601
2545 if (pchanged) 2602 if (pchanged)
2546 {
2547 for (; n < (unsigned int)i; n++) 2603 for (; n < (unsigned int)i; n++)
2548 { 2604 {
2549 XGetWindowAttributes (disp, TermWin.parent[n], &wattr); 2605 XGetWindowAttributes (xdisp, parent[n], &wattr);
2606
2550 if (wattr.depth != rootdepth || wattr.c_class == InputOnly) 2607 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2551 { 2608 {
2552 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; 2609 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2553 break; 2610 break;
2554 } 2611 }
2555 } 2612 }
2613
2614 if (n > (sizeof (parent) / sizeof (parent[0])))
2556 } 2615 {
2557
2558 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2559 {
2560 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]); 2616 XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]);
2561 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); 2617 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2562 am_transparent = 0; 2618 am_transparent = 0;
2563 /* XXX: also turn off Opt_transparent? */ 2619 /* XXX: also turn off Opt_transparent? */
2564 } 2620 }
2565 else 2621 else
2566 { 2622 {
2567#if WAIT_FOR_WM
2568 /* wait (an arbitrary period) for the WM to do its thing
2569 * needed for fvwm2.2.2 (and before?) */
2570 sleep (1);
2571#endif
2572 for (n = 0; n < (unsigned int)i; n++) 2623 for (n = 0; n < (unsigned int)i; n++)
2573 { 2624 {
2574 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative); 2625 XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative);
2575 XClearWindow (disp, TermWin.parent[n]); 2626 XClearWindow (xdisp, parent[n]);
2576 } 2627 }
2577 2628
2578 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); 2629 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2579 am_transparent = 1; 2630 am_transparent = 1;
2580 } 2631 }
2581 2632
2582 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) 2633 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2583 TermWin.parent[i] = None; 2634 parent[i] = None;
2584 } 2635 }
2585 2636
2586 if (scrollBar.win) 2637 if (scrollBar.win)
2587 { 2638 {
2588 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative); 2639 XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative);
2589 scrollBar.setIdle (); 2640 scrollBar.setIdle ();
2590 scrollbar_show (0); 2641 scrollbar_show (0);
2591 } 2642 }
2592 2643
2593 if (am_transparent) 2644 if (am_transparent)
2605 2656
2606bool 2657bool
2607rxvt_term::cmd_parse () 2658rxvt_term::cmd_parse ()
2608{ 2659{
2609 bool flag = false; 2660 bool flag = false;
2610 unicode_t ch = NOCHAR; 2661 wchar_t ch = NOCHAR;
2611 unsigned char *seq_begin; // remember start of esc-sequence here 2662 char *seq_begin; // remember start of esc-sequence here
2612 2663
2613 for (;;) 2664 for (;;)
2614 { 2665 {
2615 if (ch == NOCHAR) 2666 if (ch == NOCHAR)
2616 { 2667 {
2617 seq_begin = cmdbuf_ptr; 2668 seq_begin = cmdbuf_ptr;
2618 ch = next_char (); 2669 ch = next_char ();
2619 }
2620 2670
2621 if (ch == NOCHAR) // TODO: improve 2671 if (ch == NOCHAR)
2622 break; 2672 break;
2673 }
2623 2674
2624 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)
2625 { 2676 {
2626 if (!seen_input) 2677 if (!seen_input)
2627 { 2678 {
2636 if (seen_resize && cmd_pid) 2687 if (seen_resize && cmd_pid)
2637 kill (-cmd_pid, SIGWINCH); 2688 kill (-cmd_pid, SIGWINCH);
2638 } 2689 }
2639 2690
2640 /* Read a text string from the input buffer */ 2691 /* Read a text string from the input buffer */
2641 unicode_t buf[UBUFSIZ]; 2692 wchar_t buf[UBUFSIZ];
2642 bool refreshnow = false; 2693 bool refreshnow = false;
2643 int nlines = 0; 2694 int nlines = 0;
2644 unicode_t *str = buf; 2695 wchar_t *str = buf;
2696 wchar_t *eol = str + min (ncol, UBUFSIZ);
2645 2697
2646 for (;;) 2698 for (;;)
2647 { 2699 {
2648 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))
2649 break; 2701 break;
2650 2702
2651 *str++ = ch; 2703 *str++ = ch;
2652 2704
2653 if (ch == C0_LF) 2705 if (ch == C0_LF || str >= eol)
2654 { 2706 {
2707 if (ch == C0_LF)
2655 nlines++; 2708 nlines++;
2709
2656 refresh_count++; 2710 refresh_count++;
2657 2711
2658 if (!(options & Opt_jumpScroll) 2712 if (!OPTION (Opt_jumpScroll)
2659 || (refresh_count >= refresh_limit * (TermWin.nrow - 1))) 2713 || (refresh_count >= refresh_limit * (nrow - 1)))
2660 { 2714 {
2661 refreshnow = true; 2715 refreshnow = true;
2716 refresh_count = 0;
2662 ch = NOCHAR; 2717 ch = NOCHAR;
2663 break; 2718 break;
2664 } 2719 }
2665 2720
2666 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2721 // scr_add_lines only works for nlines <= nrow - 1.
2667 if (nlines >= TermWin.nrow - 1) 2722 if (nlines >= nrow - 1)
2668 { 2723 {
2724 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2725 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2669 scr_add_lines (buf, nlines, str - buf); 2726 scr_add_lines (buf, str - buf, nlines);
2727
2670 nlines = 0; 2728 nlines = 0;
2671 str = buf; 2729 str = buf;
2730 eol = str + min (ncol, UBUFSIZ);
2672 } 2731 }
2673 }
2674 2732
2675 if (str >= buf + UBUFSIZ) 2733 if (str >= eol)
2676 { 2734 {
2735 if (eol >= buf + UBUFSIZ)
2736 {
2677 ch = NOCHAR; 2737 ch = NOCHAR;
2678 break; 2738 break;
2739 }
2740 else
2741 eol = min (eol + ncol, buf + UBUFSIZ);
2742 }
2743
2679 } 2744 }
2680 2745
2681 seq_begin = cmdbuf_ptr; 2746 seq_begin = cmdbuf_ptr;
2682 ch = next_char (); 2747 ch = next_char ();
2683 } 2748 }
2684 2749
2750 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2751 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2685 scr_add_lines (buf, nlines, str - buf); 2752 scr_add_lines (buf, str - buf, nlines);
2686 2753
2687 /* 2754 /*
2688 * 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
2689 * 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.
2690 * the number of pages between refreshes is refresh_limit, which 2757 * the number of pages between refreshes is refresh_limit, which
2691 * is incremented here because we must be doing flat-out scrolling. 2758 * is incremented here because we must be doing flat-out scrolling.
2692 */ 2759 */
2693 if (refreshnow) 2760 if (refreshnow)
2694 { 2761 {
2695 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 2762 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2696 refresh_limit++; 2763 refresh_limit++;
2697 else 2764 else
2698 { 2765 {
2699 flag = true; 2766 flag = true;
2700 scr_refresh (refresh_type); 2767 scr_refresh ();
2768 want_refresh = 1;
2701 } 2769 }
2702 } 2770 }
2703 2771
2704 } 2772 }
2705 else 2773 else
2720 } 2788 }
2721 2789
2722 return flag; 2790 return flag;
2723} 2791}
2724 2792
2725// read the next octet
2726unicode_t
2727rxvt_term::next_octet ()
2728{
2729 return cmdbuf_ptr < cmdbuf_endp
2730 ? *cmdbuf_ptr++
2731 : NOCHAR;
2732}
2733
2734// read the next character 2793// read the next character
2735unicode_t 2794wchar_t
2736rxvt_term::next_char () 2795rxvt_term::next_char () NOTHROW
2737{ 2796{
2738 while (cmdbuf_ptr < cmdbuf_endp) 2797 while (cmdbuf_ptr < cmdbuf_endp)
2739 { 2798 {
2740 // assume 7-bit to be ascii ALWAYS 2799 // assume 7-bit to be ascii ALWAYS
2741 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2800 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2742 return *cmdbuf_ptr++; 2801 return *cmdbuf_ptr++;
2743 2802
2744 wchar_t wc; 2803 wchar_t wc;
2745 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);
2746 2805
2747 if (len == (size_t)-2) 2806 if (len == (size_t)-2)
2748 { 2807 {
2749 // the mbstate stores incomplete sequences. didn't know this :/ 2808 // the mbstate stores incomplete sequences. didn't know this :/
2750 cmdbuf_ptr = cmdbuf_endp; 2809 cmdbuf_ptr = cmdbuf_endp;
2751 break; 2810 break;
2752 } 2811 }
2753 2812
2754 if (len == (size_t)-1) 2813 if (len == (size_t)-1)
2755 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
2756 2815
2757 // assume wchar == unicode 2816 // assume wchar == unicode
2758 cmdbuf_ptr += len; 2817 cmdbuf_ptr += len;
2759 return wc & UNICODE_MASK; 2818 return wc & UNICODE_MASK;
2760 } 2819 }
2761 2820
2762 return NOCHAR; 2821 return NOCHAR;
2763} 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;
2764 2834
2765/* rxvt_cmd_getc () - Return next input character */ 2835/* rxvt_cmd_getc () - Return next input character */
2766/* 2836/*
2767 * Return the next input character after first passing any keyboard input 2837 * Return the next input character after first passing any keyboard input
2768 * to the command. 2838 * to the command.
2769 */ 2839 */
2770unicode_t 2840wchar_t
2771rxvt_term::cmd_getc () 2841rxvt_term::cmd_getc () THROW ((class out_of_input))
2772{ 2842{
2773 unicode_t c = next_char (); 2843 wchar_t c = next_char ();
2774 2844
2775 if (c == NOCHAR) 2845 if (c == NOCHAR)
2776 throw out_of_input; 2846 throw out_of_input;
2777 2847
2778 return c; 2848 return c;
2779} 2849}
2780 2850
2781unicode_t 2851uint32_t
2782rxvt_term::cmd_get8 () 2852rxvt_term::cmd_get8 () THROW ((class out_of_input))
2783{ 2853{
2784 unicode_t c = next_octet (); 2854 uint32_t c = next_octet ();
2785 2855
2786 if (c == NOCHAR) 2856 if (c == NOCHAR)
2787 throw out_of_input; 2857 throw out_of_input;
2788 2858
2789 return c; 2859 return c;
2889 case C0_ESC: 2959 case C0_ESC:
2890 process_escape_seq (); 2960 process_escape_seq ();
2891 break; 2961 break;
2892 case C0_ENQ: /* terminal Status */ 2962 case C0_ENQ: /* terminal Status */
2893 if (rs[Rs_answerbackstring]) 2963 if (rs[Rs_answerbackstring])
2894 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2964 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2895 (unsigned int)strlen (rs[Rs_answerbackstring]));
2896 else 2965 else
2897 tt_write ((unsigned char *)VT100_ANS, 2966 tt_write (VT100_ANS, strlen (VT100_ANS));
2898 (unsigned int)strlen (VT100_ANS));
2899 break; 2967 break;
2900 case C0_BEL: /* bell */ 2968 case C0_BEL: /* bell */
2901 scr_bell (); 2969 scr_bell ();
2902 break; 2970 break;
2903 case C0_BS: /* backspace */ 2971 case C0_BS: /* backspace */
3027 scr_charset_set (2, (unsigned int)cmd_getc ()); 3095 scr_charset_set (2, (unsigned int)cmd_getc ());
3028 break; 3096 break;
3029 case '+': 3097 case '+':
3030 scr_charset_set (3, (unsigned int)cmd_getc ()); 3098 scr_charset_set (3, (unsigned int)cmd_getc ());
3031 break; 3099 break;
3032#if ENABLE_FRILLS 3100#if !ENABLE_MINIMAL
3033 case '6': 3101 case '6':
3034 scr_backindex (); 3102 scr_backindex ();
3035 break; 3103 break;
3036#endif 3104#endif
3037 case '7': 3105 case '7':
3038 scr_cursor (SAVE); 3106 scr_cursor (SAVE);
3039 break; 3107 break;
3040 case '8': 3108 case '8':
3041 scr_cursor (RESTORE); 3109 scr_cursor (RESTORE);
3042 break; 3110 break;
3043#if ENABLE_FRILLS 3111#if !ENABLE_MINIMAL
3044 case '9': 3112 case '9':
3045 scr_forwardindex (); 3113 scr_forwardindex ();
3046 break; 3114 break;
3047#endif 3115#endif
3048 case '=': 3116 case '=':
3058 break; 3126 break;
3059 3127
3060 /* 8.3.87: NEXT LINE */ 3128 /* 8.3.87: NEXT LINE */
3061 case C1_NEL: /* ESC E */ 3129 case C1_NEL: /* ESC E */
3062 { 3130 {
3063 unicode_t nlcr[] = { C0_LF, C0_CR }; 3131 wchar_t nlcr[] = { C0_LF, C0_CR };
3064 scr_add_lines (nlcr, 1, 2); 3132 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3065 } 3133 }
3066 break; 3134 break;
3067 3135
3068 /* kidnapped escape sequence: Should be 8.3.48 */ 3136 /* kidnapped escape sequence: Should be 8.3.48 */
3069 case C1_ESA: /* ESC G */ 3137 case C1_ESA: /* ESC G */
3091 process_dcs_seq (); 3159 process_dcs_seq ();
3092 break; 3160 break;
3093 3161
3094 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 3162 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3095 case C1_SCI: /* ESC Z */ 3163 case C1_SCI: /* ESC Z */
3096 tt_write ((const unsigned char *)ESCZ_ANSWER, 3164 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3097 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3098 break; /* steal obsolete ESC [ c */ 3165 break; /* steal obsolete ESC [ c */
3099 3166
3100 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 3167 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3101 case C1_CSI: /* ESC [ */ 3168 case C1_CSI: /* ESC [ */
3102 process_csi_seq (); 3169 process_csi_seq ();
3211 ndef = get_byte_array_bit (csi_defaults, i); 3278 ndef = get_byte_array_bit (csi_defaults, i);
3212 for (p = 0; p < nargs; p++) 3279 for (p = 0; p < nargs; p++)
3213 if (arg[p] == -1) 3280 if (arg[p] == -1)
3214 arg[p] = ndef; 3281 arg[p] = ndef;
3215 3282
3216#ifdef DEBUG_CMD
3217 fprintf (stderr, "CSI ");
3218 for (p = 0; p < nargs; p++)
3219 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3220 fprintf (stderr, "%c\n", ch);
3221#endif
3222
3223 /* 3283 /*
3224 * private mode handling 3284 * private mode handling
3225 */ 3285 */
3226 if (priv) 3286 if (priv)
3227 { 3287 {
3228 switch (priv) 3288 switch (priv)
3229 { 3289 {
3230 case '>': 3290 case '>':
3231 if (ch == CSI_DA) /* secondary device attributes */ 3291 if (ch == CSI_DA) /* secondary device attributes */
3232 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 }
3233 break; 3302 break;
3234 case '?': 3303 case '?':
3235 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 3304 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3236 process_terminal_mode (ch, priv, nargs, arg); 3305 process_terminal_mode (ch, priv, nargs, arg);
3237 break; 3306 break;
3342 3411
3343 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 3412 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3344 arg[0] = -arg[0]; 3413 arg[0] = -arg[0];
3345 /* FALLTHROUGH */ 3414 /* FALLTHROUGH */
3346 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3415 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3347 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 3416 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3348 break; 3417 break;
3349 3418
3350 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3419 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3351 tt_write ((const unsigned char *)VT100_ANS, 3420 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3352 (unsigned int) (sizeof (VT100_ANS) - 1));
3353 break; 3421 break;
3354 3422
3355 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 3423 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3356 process_sgr_mode (nargs, arg); 3424 process_sgr_mode (nargs, arg);
3357 break; 3425 break;
3364 break; 3432 break;
3365 case 6: /* CPR requested */ 3433 case 6: /* CPR requested */
3366 scr_report_position (); 3434 scr_report_position ();
3367 break; 3435 break;
3368 case 7: /* unofficial extension */ 3436 case 7: /* unofficial extension */
3369 if (options & Opt_insecure) 3437 if (OPTION (Opt_insecure))
3370 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3438 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3371 break; 3439 break;
3372 case 8: /* unofficial extension */ 3440 case 8: /* unofficial extension */
3373 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3441 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3374 break; 3442 break;
3441 break; 3509 break;
3442 case CSI_75: 3510 case CSI_75:
3443 scr_cursor (RESTORE); 3511 scr_cursor (RESTORE);
3444 break; 3512 break;
3445 3513
3446#if ENABLE_FRILLS 3514#if !ENABLE_MINIMAL
3447 case CSI_74: 3515 case CSI_74:
3448 process_window_ops (arg, nargs); 3516 process_window_ops (arg, nargs);
3449 break; 3517 break;
3450#endif 3518#endif
3451 3519
3458 break; 3526 break;
3459 } 3527 }
3460} 3528}
3461/*}}} */ 3529/*}}} */
3462 3530
3463#if ENABLE_FRILLS 3531#if !ENABLE_MINIMAL
3464/* ARGSUSED */ 3532/* ARGSUSED */
3465void 3533void
3466rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3534rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3467{ 3535{
3468 int x, y; 3536 int x, y;
3469 XWindowAttributes wattr; 3537 XWindowAttributes wattr;
3470 Window wdummy; 3538 Window wdummy;
3471 dDisp; 3539
3540 dLocal (Display *, xdisp);
3472 3541
3473 if (nargs == 0) 3542 if (nargs == 0)
3474 return; 3543 return;
3475 3544
3476 switch (args[0]) 3545 switch (args[0])
3477 { 3546 {
3478 /* 3547 /*
3479 * commands 3548 * commands
3480 */ 3549 */
3481 case 1: /* deiconify window */ 3550 case 1: /* deiconify window */
3482 XMapWindow (disp, TermWin.parent[0]); 3551 XMapWindow (xdisp, parent[0]);
3483 break; 3552 break;
3484 case 2: /* iconify window */ 3553 case 2: /* iconify window */
3485 XIconifyWindow (disp, TermWin.parent[0], display->screen); 3554 XIconifyWindow (xdisp, parent[0], display->screen);
3486 break; 3555 break;
3487 case 3: /* set position (pixels) */ 3556 case 3: /* set position (pixels) */
3488 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); 3557 XMoveWindow (xdisp, parent[0], args[1], args[2]);
3489 break; 3558 break;
3490 case 4: /* set size (pixels) */ 3559 case 4: /* set size (pixels) */
3491 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3560 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3492 break; 3561 break;
3493 case 5: /* raise window */ 3562 case 5: /* raise window */
3494 XRaiseWindow (disp, TermWin.parent[0]); 3563 XRaiseWindow (xdisp, parent[0]);
3495 break; 3564 break;
3496 case 6: /* lower window */ 3565 case 6: /* lower window */
3497 XLowerWindow (disp, TermWin.parent[0]); 3566 XLowerWindow (xdisp, parent[0]);
3498 break; 3567 break;
3499 case 7: /* refresh window */ 3568 case 7: /* refresh window */
3500 scr_touch (true); 3569 scr_touch (true);
3501 break; 3570 break;
3502 case 8: /* set size (chars) */ 3571 case 8: /* set size (chars) */
3503 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3572 set_widthheight ((unsigned int) (args[2] * fwidth),
3504 (unsigned int) (args[1] * TermWin.fheight)); 3573 (unsigned int) (args[1] * fheight));
3505 break; 3574 break;
3506 3575
3507 //case 9: NYI, TODO, restore maximized window or maximize window 3576 //case 9: NYI, TODO, restore maximized window or maximize window
3508 default: 3577 default:
3509 if (args[0] >= 24) /* set height (chars) */ 3578 if (args[0] >= 24) /* set height (chars) */
3510 set_widthheight ((unsigned int)TermWin.width, 3579 set_widthheight ((unsigned int)width,
3511 (unsigned int) (args[1] * TermWin.fheight)); 3580 (unsigned int) (args[1] * fheight));
3512 break; 3581 break;
3513
3514 3582
3515 /* 3583 /*
3516 * reports - some output format copied from XTerm 3584 * reports - some output format copied from XTerm
3517 */ 3585 */
3518 case 11: /* report window state */ 3586 case 11: /* report window state */
3519 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3587 XGetWindowAttributes (xdisp, parent[0], &wattr);
3520 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3588 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3521 break; 3589 break;
3522 case 13: /* report window position */ 3590 case 13: /* report window position */
3523 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3591 XGetWindowAttributes (xdisp, parent[0], &wattr);
3524 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, 3592 XTranslateCoordinates (xdisp, parent[0], wattr.root,
3525 -wattr.border_width, -wattr.border_width, 3593 -wattr.border_width, -wattr.border_width,
3526 &x, &y, &wdummy); 3594 &x, &y, &wdummy);
3527 tt_printf ("\033[3;%d;%dt", x, y); 3595 tt_printf ("\033[3;%d;%dt", x, y);
3528 break; 3596 break;
3529 case 14: /* report window size (pixels) */ 3597 case 14: /* report window size (pixels) */
3530 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3598 XGetWindowAttributes (xdisp, parent[0], &wattr);
3531 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3599 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3532 break; 3600 break;
3533 case 18: /* report text area size (chars) */ 3601 case 18: /* report text area size (chars) */
3534 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3602 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3535 break; 3603 break;
3536 case 19: /* report window size (chars) */ 3604 case 19: /* report window size (chars) */
3537 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3605 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3538 break; 3606 break;
3539 case 20: /* report icon label */ 3607 case 20: /* report icon label */
3540 { 3608 {
3541 char *s; 3609 char *s;
3542 XGetIconName (disp, TermWin.parent[0], &s); 3610 XGetIconName (xdisp, parent[0], &s);
3543 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 */
3544 XFree (s); 3612 XFree (s);
3545 } 3613 }
3546 break; 3614 break;
3547 case 21: /* report window title */ 3615 case 21: /* report window title */
3548 { 3616 {
3549 char *s; 3617 char *s;
3550 XFetchName (disp, TermWin.parent[0], &s); 3618 XFetchName (xdisp, parent[0], &s);
3551 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 */
3552 XFree (s); 3620 XFree (s);
3553 } 3621 }
3554 break; 3622 break;
3555 } 3623 }
3556} 3624}
3559/*----------------------------------------------------------------------*/ 3627/*----------------------------------------------------------------------*/
3560/* 3628/*
3561 * get input up until STRING TERMINATOR (or BEL) 3629 * get input up until STRING TERMINATOR (or BEL)
3562 * ends_how is terminator used. returned input must be free()'d 3630 * ends_how is terminator used. returned input must be free()'d
3563 */ 3631 */
3564unsigned char * 3632char *
3565rxvt_term::get_to_st (unicode_t &ends_how) 3633rxvt_term::get_to_st (unicode_t &ends_how)
3566{ 3634{
3567 unicode_t ch; 3635 unicode_t ch;
3568 bool seen_esc = false; 3636 bool seen_esc = false;
3569 unsigned int n = 0; 3637 unsigned int n = 0;
3588 else if (ch < 0x20) 3656 else if (ch < 0x20)
3589 return NULL; /* other control character - exit */ 3657 return NULL; /* other control character - exit */
3590 3658
3591 seen_esc = false; 3659 seen_esc = false;
3592 3660
3593 if (n >= sizeof (string) - 1) 3661 if (n >= STRING_MAX - 1)
3594 // stop at some sane length 3662 // stop at some sane length
3595 return NULL; 3663 return NULL;
3596 3664
3597 if (ch == C0_SYN) 3665 if (ch == C0_SYN)
3598 string[n++] = cmd_get8 (); 3666 string[n++] = cmd_get8 ();
3602 3670
3603 string[n++] = '\0'; 3671 string[n++] = '\0';
3604 3672
3605 ends_how = (ch == 0x5c ? C0_ESC : ch); 3673 ends_how = (ch == 0x5c ? C0_ESC : ch);
3606 3674
3607 return (unsigned char *)rxvt_wcstombs (string); 3675 return rxvt_wcstombs (string);
3608} 3676}
3609 3677
3610/*----------------------------------------------------------------------*/ 3678/*----------------------------------------------------------------------*/
3611/* 3679/*
3612 * 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)'
3613 */ 3681 */
3614void 3682void
3615rxvt_term::process_dcs_seq () 3683rxvt_term::process_dcs_seq ()
3616{ 3684{
3617 unsigned char *s; 3685 char *s;
3618 unicode_t eh; 3686 unicode_t eh;
3619 3687
3620 /* 3688 /*
3621 * Not handled yet 3689 * Not handled yet
3622 */ 3690 */
3641 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3709 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3642 arg = arg * 10 + (ch - '0'); 3710 arg = arg * 10 + (ch - '0');
3643 3711
3644 if (ch == ';') 3712 if (ch == ';')
3645 { 3713 {
3646 unsigned char *s = get_to_st (eh); 3714 char *s = get_to_st (eh);
3647 3715
3648 if (s) 3716 if (s)
3649 { 3717 {
3650 process_xterm_seq (arg, (char *)s, eh); 3718 process_xterm_seq (arg, s, eh);
3651 free (s); 3719 free (s);
3652 } 3720 }
3653 } 3721 }
3654} 3722}
3655 3723
3656void 3724void
3657rxvt_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)
3658{ 3726{
3659 if (str[0] == '?' && !str[1]) 3727 if (str[0] == '?' && !str[1])
3660 { 3728 {
3661 unsigned short r, g, b; 3729 rgba c;
3662 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
3663 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);
3664 } 3738 }
3665 else 3739 else
3666 set_window_color (color, str); 3740 set_window_color (color, str);
3667} 3741}
3668 3742
3669/* 3743/*
3670 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3744 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3671 */ 3745 */
3672void 3746void
3673rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3747rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3674{ 3748{
3675 int changed = 0;
3676 int color; 3749 int color;
3677 char *buf, *name; 3750 char *buf, *name;
3678 bool query = str[0] == '?' && !str[1]; 3751 bool query = str[0] == '?' && !str[1];
3679 int saveop = op; 3752 int saveop = op;
3680 dDisp; 3753
3754 dLocal (Display *, xdisp);
3681 3755
3682 assert (str != NULL); 3756 assert (str != NULL);
3683 switch (op) 3757 switch (op)
3684 { 3758 {
3685 case XTerm_name: 3759 case XTerm_name:
3701 unsigned long bytes_after; 3775 unsigned long bytes_after;
3702 unsigned char *value = 0; 3776 unsigned char *value = 0;
3703 const char *str = ""; 3777 const char *str = "";
3704 3778
3705 if (prop 3779 if (prop
3706 && XGetWindowProperty (disp, TermWin.parent[0], 3780 && XGetWindowProperty (xdisp, parent[0],
3707 prop, 0, 1<<16, 0, AnyPropertyType, 3781 prop, 0, 1<<16, 0, AnyPropertyType,
3708 &actual_type, &actual_format, 3782 &actual_type, &actual_format,
3709 &nitems, &bytes_after, &value) == Success 3783 &nitems, &bytes_after, &value) == Success
3710 && actual_type != None 3784 && actual_type != None
3711 && actual_format == 8) 3785 && actual_format == 8)
3712 str = (const char *)(value); 3786 str = (const char *)(value);
3713 3787
3714 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3788 tt_printf ("\033]%d;%s%c", op, str, resp);
3715 3789
3716 XFree (value); 3790 XFree (value);
3717 } 3791 }
3718 else 3792 else
3719 { 3793 {
3723 { 3797 {
3724 *eq = 0; 3798 *eq = 0;
3725 set_utf8_property (display->atom (str), eq + 1); 3799 set_utf8_property (display->atom (str), eq + 1);
3726 } 3800 }
3727 else 3801 else
3728 XDeleteProperty (disp, TermWin.parent[0], 3802 XDeleteProperty (xdisp, parent[0],
3729 display->atom (str)); 3803 display->atom (str));
3730 } 3804 }
3731 break; 3805 break;
3732 3806
3733 case XTerm_Color: 3807 case XTerm_Color:
3735 { 3809 {
3736 if ((name = strchr (buf, ';')) == NULL) 3810 if ((name = strchr (buf, ';')) == NULL)
3737 break; 3811 break;
3738 3812
3739 *name++ = '\0'; 3813 *name++ = '\0';
3740 color = atoi (buf); 3814 color = atoi (buf) + minCOLOR;
3741 3815
3742 if (color < 0 || color >= TOTAL_COLORS) 3816 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3743 break; 3817 break;
3744 3818
3745 if ((buf = strchr (name, ';')) != NULL) 3819 if ((buf = strchr (name, ';')) != NULL)
3746 *buf++ = '\0'; 3820 *buf++ = '\0';
3747 3821
3748 if (name[0] == '?' && !name[1]) 3822 process_color_seq (op, color, name, resp);
3749 {
3750 unsigned short r, g, b;
3751 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3752 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3753 }
3754 else
3755 set_window_color (color + minCOLOR, name);
3756 } 3823 }
3757 break; 3824 break;
3758 case XTerm_Color00: 3825 case XTerm_Color00:
3759 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3826 process_color_seq (op, Color_fg, str, resp);
3760 break; 3827 break;
3761 case XTerm_Color01: 3828 case XTerm_Color01:
3762 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3829 process_color_seq (op, Color_bg, str, resp);
3763 break; 3830 break;
3764#ifndef NO_CURSORCOLOR 3831#ifndef NO_CURSORCOLOR
3765 case XTerm_Color_cursor: 3832 case XTerm_Color_cursor:
3766 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3833 process_color_seq (op, Color_cursor, str, resp);
3767 break; 3834 break;
3768#endif 3835#endif
3769 case XTerm_Color_pointer_fg: 3836 case XTerm_Color_pointer_fg:
3770 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3837 process_color_seq (op, Color_pointer_fg, str, resp);
3771 break; 3838 break;
3772 case XTerm_Color_pointer_bg: 3839 case XTerm_Color_pointer_bg:
3773 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3840 process_color_seq (op, Color_pointer_bg, str, resp);
3774 break; 3841 break;
3775#ifndef NO_BOLD_UNDERLINE_REVERSE 3842#ifndef NO_BOLD_UNDERLINE_REVERSE
3776 case XTerm_Color_BD:
3777 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3778 break;
3779 case XTerm_Color_UL:
3780 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3781 break;
3782 case XTerm_Color_RV: 3843 case XTerm_Color_RV:
3783 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);
3784 break; 3853 break;
3785 case URxvt_Color_IT: 3854 case URxvt_Color_IT:
3786 process_color_seq (URxvt_Color_IT, Color_IT, str, resp); 3855 process_color_seq (op, Color_IT, str, resp);
3787 break; 3856 break;
3788#endif 3857#endif
3789#if TRANSPARENT && TINTING 3858#if TRANSPARENT && TINTING
3790 case URxvt_Color_tint: 3859 case URxvt_Color_tint:
3791 process_color_seq (URxvt_Color_tint, Color_tint, str, resp); 3860 process_color_seq (op, Color_tint, str, resp);
3861
3792 check_our_parents (); 3862 check_our_parents ();
3863
3793 if (am_transparent) 3864 if (am_transparent)
3794 want_full_refresh = want_refresh = 1; 3865 want_full_refresh = want_refresh = 1;
3795 break;
3796#endif
3797 3866
3867 break;
3868#endif
3869
3798 case XTerm_Pixmap: 3870 case Rxvt_Pixmap:
3871 {
3799 if (*str != ';') 3872 if (*str != ';')
3800 { 3873 {
3801#if XPM_BACKGROUND 3874#if XPM_BACKGROUND
3802 scale_pixmap (""); /* reset to default scaling */ 3875 scale_pixmap (""); /* reset to default scaling */
3803 set_bgPixmap (str); /* change pixmap */ 3876 set_bgPixmap (str); /* change pixmap */
3804#endif
3805 scr_touch (true); 3877 scr_touch (true);
3878#endif
3806 } 3879 }
3880
3881 int changed = 0;
3882
3807 while ((str = strchr (str, ';')) != NULL) 3883 while ((str = strchr (str, ';')) != NULL)
3808 { 3884 {
3809 str++; 3885 str++;
3810#if XPM_BACKGROUND 3886#if XPM_BACKGROUND
3811 changed += scale_pixmap (str); 3887 changed += scale_pixmap (str);
3812#endif 3888#endif
3813 } 3889 }
3814 3890
3815 if (changed) 3891 if (changed)
3816 { 3892 {
3817#ifdef XPM_BACKGROUND 3893#ifdef XPM_BACKGROUND
3818 resize_pixmap (); 3894 resize_pixmap ();
3819#endif
3820 scr_touch (true); 3895 scr_touch (true);
3896#endif
3821 } 3897 }
3898 }
3822 break; 3899 break;
3823 3900
3824 case XTerm_restoreFG: 3901 case Rxvt_restoreFG:
3825 set_window_color (Color_fg, str); 3902 set_window_color (Color_fg, str);
3826 break; 3903 break;
3827 case XTerm_restoreBG: 3904 case Rxvt_restoreBG:
3828 set_window_color (Color_bg, str); 3905 set_window_color (Color_bg, str);
3829 break; 3906 break;
3830 3907
3831 case XTerm_logfile: 3908 case XTerm_logfile:
3832 // TODO, when secure mode? 3909 // TODO, when secure mode?
3833 break; 3910 break;
3834 3911
3835#ifdef MENUBAR
3836 case URxvt_Menu:
3837 if (options & Opt_insecure)
3838 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3839 break;
3840#endif
3841#if 0 3912#if 0
3842 case XTerm_dumpscreen: /* no error notices */ 3913 case Rxvt_dumpscreen: /* no error notices */
3843 { 3914 {
3844 int fd; 3915 int fd;
3845 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3916 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3846 { 3917 {
3847 scr_dump (fd); 3918 scr_dump (fd);
3858 case URxvt_italicFont: 3929 case URxvt_italicFont:
3859 case URxvt_boldItalicFont: 3930 case URxvt_boldItalicFont:
3860#endif 3931#endif
3861 if (query) 3932 if (query)
3862 tt_printf ("\33]%d;%-.250s%c", saveop, 3933 tt_printf ("\33]%d;%-.250s%c", saveop,
3863 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc 3934 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3864 ? TermWin.fontset[op - URxvt_font]->fontdesc : "", 3935 ? fontset[op - URxvt_font]->fontdesc : "",
3865 resp); 3936 resp);
3866 else 3937 else
3867 { 3938 {
3868 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3939 const char *&res = rs[Rs_font + (op - URxvt_font)];
3869 3940
3871 allocated.push_back ((void *)res); 3942 allocated.push_back ((void *)res);
3872 set_fonts (); 3943 set_fonts ();
3873 } 3944 }
3874 break; 3945 break;
3875 3946
3876#if ENABLE_FRILLS 3947 case URxvt_version:
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
3877 case URxvt_locale: 3956 case URxvt_locale:
3878 if (query) 3957 if (query)
3879 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp); 3958 tt_printf ("\33]%d;%-.250s%c", op, OPTION (Opt_insecure) ? locale : "", resp);
3880 else 3959 else
3881 { 3960 {
3882 set_locale (str); 3961 set_locale (str);
3883 pty.set_utf8_mode (enc_utf8); 3962 pty->set_utf8_mode (enc_utf8);
3884 init_xlocale (); 3963 init_xlocale ();
3885 } 3964 }
3886 break; 3965 break;
3887 3966
3888 case URxvt_view_up: 3967 case URxvt_view_up:
3889 case URxvt_view_down: 3968 case URxvt_view_down:
3969 {
3890 int lines = atoi (str); 3970 int lines = atoi (str);
3891 3971
3892 if (lines) 3972 if (lines)
3893 scr_page (op == URxvt_view_up ? UP : DN, lines); 3973 scr_page (op == URxvt_view_up ? UP : DN, lines);
3894 else 3974 else
3895 {
3896 scr_erase_savelines (); 3975 scr_erase_savelines ();
3897 } 3976 }
3898 3977
3978 break;
3979#endif
3980
3981#if ENABLE_PERL
3982 case URxvt_perl:
3983 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END)))
3984 ; // no responses yet
3899 break; 3985 break;
3900#endif 3986#endif
3901 } 3987 }
3902} 3988}
3903/*----------------------------------------------------------------------*/ 3989/*----------------------------------------------------------------------*/
3934 return state; 4020 return state;
3935} 4021}
3936 4022
3937/* we're not using priv _yet_ */ 4023/* we're not using priv _yet_ */
3938void 4024void
3939rxvt_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)
3940{ 4026{
3941 unsigned int i, j; 4027 unsigned int i, j;
3942 int state; 4028 int state;
3943 4029
3944 static const struct 4030 static const struct
3955 { 5, PrivMode_rVideo }, 4041 { 5, PrivMode_rVideo },
3956 { 6, PrivMode_relOrigin }, 4042 { 6, PrivMode_relOrigin },
3957 { 7, PrivMode_Autowrap }, 4043 { 7, PrivMode_Autowrap },
3958 // 8, bi-directional support mode 4044 // 8, bi-directional support mode
3959 { 9, PrivMode_MouseX10 }, 4045 { 9, PrivMode_MouseX10 },
3960#ifdef menuBar_esc
3961 { menuBar_esc, PrivMode_menuBar },
3962#endif
3963 // 18, 19 printing-related 4046 // 18, 19 printing-related
3964 { 25, PrivMode_VisibleCursor }, 4047 { 25, PrivMode_VisibleCursor },
3965#ifdef scrollBar_esc 4048#ifdef scrollBar_esc
3966 { scrollBar_esc, PrivMode_scrollBar }, 4049 { scrollBar_esc, PrivMode_scrollBar },
3967#endif 4050#endif
4012 } 4095 }
4013 4096
4014 /* extra handling for values with state unkept */ 4097 /* extra handling for values with state unkept */
4015 switch (arg[i]) 4098 switch (arg[i])
4016 { 4099 {
4100#if ENABLE_STYLES
4101 case 1021:
4102 set_option (Opt_intensityStyles, mode);
4103
4104 scr_touch (true);
4105 break;
4106#endif
4017 case 1048: /* alternative cursor save */ 4107 case 1048: /* alternative cursor save */
4018 case 1049: 4108 case 1049:
4019 if (options & Opt_secondaryScreen) 4109 if (OPTION (Opt_secondaryScreen))
4020 if (mode == 0) 4110 if (mode == 0)
4021 scr_cursor (RESTORE); 4111 scr_cursor (RESTORE);
4022 else if (mode == 1) 4112 else if (mode == 1)
4023 scr_cursor (SAVE); 4113 scr_cursor (SAVE);
4024 break; 4114 break;
4036 */ 4126 */
4037 PrivMode (1, PrivMode_vt52); 4127 PrivMode (1, PrivMode_vt52);
4038 break; 4128 break;
4039 case 3: /* 80/132 */ 4129 case 3: /* 80/132 */
4040 if (priv_modes & PrivMode_132OK) 4130 if (priv_modes & PrivMode_132OK)
4041 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 4131 set_widthheight (((state ? 132 : 80) * fwidth), height);
4042 break; 4132 break;
4043 case 4: /* smooth scrolling */ 4133 case 4: /* smooth scrolling */
4044 if (state)
4045 options &= ~Opt_jumpScroll;
4046 else
4047 options |= Opt_jumpScroll; 4134 set_option (Opt_jumpScroll, !state);
4048 break; 4135 break;
4049 case 5: /* reverse video */ 4136 case 5: /* reverse video */
4050 scr_rvideo_mode (state); 4137 scr_rvideo_mode (state);
4051 break; 4138 break;
4052 case 6: /* relative/absolute origins */ 4139 case 6: /* relative/absolute origins */
4058 /* 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 */
4059 case 9: /* X10 mouse reporting */ 4146 case 9: /* X10 mouse reporting */
4060 if (state) /* orthogonal */ 4147 if (state) /* orthogonal */
4061 priv_modes &= ~PrivMode_MouseX11; 4148 priv_modes &= ~PrivMode_MouseX11;
4062 break; 4149 break;
4063#ifdef menuBar_esc
4064 case menuBar_esc:
4065#ifdef MENUBAR
4066 map_menuBar (state);
4067#endif
4068 break;
4069#endif
4070#ifdef scrollBar_esc 4150#ifdef scrollBar_esc
4071 case scrollBar_esc: 4151 case scrollBar_esc:
4072 if (scrollbar_mapping (state)) 4152 if (scrollbar_mapping (state))
4073 { 4153 {
4074 resize_all_windows (0, 0, 0); 4154 resize_all_windows (0, 0, 0);
4093#if 0 4173#if 0
4094 case 1001: 4174 case 1001:
4095 break; /* X11 mouse highlighting */ 4175 break; /* X11 mouse highlighting */
4096#endif 4176#endif
4097 case 1010: /* scroll to bottom on TTY output inhibit */ 4177 case 1010: /* scroll to bottom on TTY output inhibit */
4098 if (state)
4099 options &= ~Opt_scrollTtyOutput;
4100 else
4101 options |= Opt_scrollTtyOutput; 4178 set_option (Opt_scrollTtyOutput, !state);
4102 break; 4179 break;
4103 case 1011: /* scroll to bottom on key press */ 4180 case 1011: /* scroll to bottom on key press */
4104 if (state)
4105 options |= Opt_scrollTtyKeypress; 4181 set_option (Opt_scrollTtyKeypress, state);
4106 else
4107 options &= ~Opt_scrollTtyKeypress;
4108 break; 4182 break;
4109 case 1047: /* secondary screen w/ clearing last */ 4183 case 1047: /* secondary screen w/ clearing last */
4110 if (options & Opt_secondaryScreen) 4184 if (OPTION (Opt_secondaryScreen))
4111 if (current_screen != PRIMARY) 4185 if (current_screen != PRIMARY)
4112 scr_erase_screen (2); 4186 scr_erase_screen (2);
4113 scr_change_screen (state); 4187 scr_change_screen (state);
4114 break; 4188 break;
4115 case 1049: /* secondary screen w/ clearing first */ 4189 case 1049: /* secondary screen w/ clearing first */
4116 scr_change_screen (state); 4190 scr_change_screen (state);
4117 if (options & Opt_secondaryScreen) 4191 if (OPTION (Opt_secondaryScreen))
4118 if (current_screen != PRIMARY) 4192 if (current_screen != PRIMARY)
4119 scr_erase_screen (2); 4193 scr_erase_screen (2);
4120 break; 4194 break;
4121 default: 4195 default:
4122 break; 4196 break;
4250 scr_color (Color_bg, Color_bg); 4324 scr_color (Color_bg, Color_bg);
4251 break; 4325 break;
4252 4326
4253 //case 50: // not variable spacing 4327 //case 50: // not variable spacing
4254 4328
4255#ifndef NO_BRIGHTCOLOR 4329#if !ENABLE_MINIMAL
4256 case 90: 4330 case 90:
4257 case 91: /* set bright fg color */ 4331 case 91: /* set bright fg color */
4258 case 92: 4332 case 92:
4259 case 93: 4333 case 93:
4260 case 94: 4334 case 94:
4272 case 106: 4346 case 106:
4273 case 107: 4347 case 107:
4274 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 4348 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4275 break; 4349 break;
4276#endif 4350#endif
4277
4278 } 4351 }
4279 } 4352 }
4280} 4353}
4281/*}}} */ 4354/*}}} */
4282 4355
4306 */ 4379 */
4307void 4380void
4308rxvt_term::tt_printf (const char *fmt,...) 4381rxvt_term::tt_printf (const char *fmt,...)
4309{ 4382{
4310 va_list arg_ptr; 4383 va_list arg_ptr;
4311 unsigned char buf[256]; 4384 char buf[256];
4312 4385
4313 va_start (arg_ptr, fmt); 4386 va_start (arg_ptr, fmt);
4314 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 4387 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4315 va_end (arg_ptr); 4388 va_end (arg_ptr);
4316 tt_write (buf, strlen (buf)); 4389 tt_write (buf, strlen (buf));
4321 * or generated by us in response to a query ESC sequence. 4394 * or generated by us in response to a query ESC sequence.
4322 */ 4395 */
4323const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4396const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4324 4397
4325void 4398void
4326rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4399rxvt_term::tt_write (const char *data, unsigned int len)
4327{ 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
4328 if (v_buflen == 0) 4407 if (v_buflen == 0)
4329 { 4408 {
4330 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));
4331 4410
4332 if ((unsigned int)written == len) 4411 if ((unsigned int)written == len)
4333 return; 4412 return;
4334 4413
4335 data += written; 4414 data += written;
4336 len -= written; 4415 len -= written;
4337 } 4416 }
4338 4417
4339 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4418 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4340 4419
4341 memcpy (v_buffer + v_buflen, data, len); 4420 memcpy (v_buffer + v_buflen, data, len);
4342 v_buflen += len; 4421 v_buflen += len;
4343 4422
4344 pty_ev.set (EVENT_READ | EVENT_WRITE); 4423 pty_ev.set (EVENT_READ | EVENT_WRITE);
4345} 4424}
4346 4425
4347void rxvt_term::pty_write () 4426void rxvt_term::pty_write ()
4348{ 4427{
4349 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));
4350 4429
4351 if (written > 0) 4430 if (written > 0)
4352 { 4431 {
4353 v_buflen -= written; 4432 v_buflen -= written;
4354 4433
4363 } 4442 }
4364 4443
4365 memmove (v_buffer, v_buffer + written, v_buflen); 4444 memmove (v_buffer, v_buffer + written, v_buflen);
4366 } 4445 }
4367 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4446 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4368 // original code just ignores this... 4447 pty_ev.set (EVENT_READ);
4369 destroy ();
4370} 4448}
4371 4449
4372/*----------------------- end-of-file (C source) -----------------------*/ 4450/*----------------------- end-of-file (C source) -----------------------*/
4373 4451

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines