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.216 by root, Tue Dec 27 01:25:42 2005 UTC vs.
Revision 1.275 by root, Fri Jan 20 10:35: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
54#if HAVE_SCHED_YIELD
55#undef HAVE_SCHED_YIELD // disabled for the time being
56//# include <sched.h>
57#endif
58
53#ifdef KEYSYM_RESOURCE 59#ifdef KEYSYM_RESOURCE
54# include "keyboard.h" 60# include "keyboard.h"
55#endif 61#endif
56 62
57#include <csignal> 63#include <csignal>
58 64
59/*----------------------------------------------------------------------*/ 65/*----------------------------------------------------------------------*/
60 66
61#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 67#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 68
66#if ENABLE_FRILLS || ISO_14755 69#if ENABLE_FRILLS || ISO_14755
67 70
68#define ISO_14755_STARTED 0x80000000UL 71#define ISO_14755_STARTED 0x80000000UL
69#define ISO_14755_51 0x40000000UL // basic (section 5.1) 72#define ISO_14755_51 0x40000000UL // basic (section 5.1)
141 || !IN_RANGE_EXC (y, 0, nrow)) 144 || !IN_RANGE_EXC (y, 0, nrow))
142 return; 145 return;
143 146
144 for (;;) 147 for (;;)
145 { 148 {
146 const line_t &l = ROW(y - view_start); 149 const line_t &l = ROW(y + view_start);
147 150
148 text_t t = l.t[x]; 151 text_t t = l.t[x];
149 152
150 if (t != NOCHAR || !x) 153 if (t != NOCHAR || !x)
151 { 154 {
152 iso14755_51 (l.t[x], l.r[x]); 155 iso14755_51 (l.t[x], l.r[x], x, y);
153 iso14755buf = ISO_14755_54; 156 iso14755buf = ISO_14755_54;
154 break; 157 break;
155 } 158 }
156 159
157 x--; 160 x--;
158 } 161 }
159} 162}
160#endif
161 163
162#if ENABLE_OVERLAY
163void 164void
164rxvt_term::iso14755_51 (unicode_t ch, rend_t r) 165rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y)
165{ 166{
166 rxvt_fontset *fs = FONTSET (r); 167 rxvt_fontset *fs = FONTSET (r);
167 rxvt_font *f = (*fs)[fs->find_font (ch)]; 168 rxvt_font *f = (*fs)[fs->find_font (ch)];
168 wchar_t *chr, *alloc, ch2, *fname; 169 wchar_t *chr, *alloc, ch2, *fname;
169 int len; 170 int len;
170 171
171 fname = rxvt_utf8towcs (f->name); 172 fname = rxvt_utf8towcs (f->name);
172 173
173#if ENABLE_COMBINING 174# if ENABLE_COMBINING
174 if (IS_COMPOSE (ch)) 175 if (IS_COMPOSE (ch))
175 { 176 {
176 len = rxvt_composite.expand (ch, 0); 177 len = rxvt_composite.expand (ch, 0);
177 alloc = chr = new wchar_t[len]; 178 alloc = chr = new wchar_t[len];
178 rxvt_composite.expand (ch, chr); 179 rxvt_composite.expand (ch, chr);
179 } 180 }
180 else 181 else
181#endif 182# endif
182 { 183 {
183 ch2 = ch; 184 ch2 = ch;
184 185
185 alloc = 0; 186 alloc = 0;
186 chr = &ch2; 187 chr = &ch2;
189 190
190 char attr[80]; // plenty 191 char attr[80]; // plenty
191 192
192 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s", 193 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
193 (int)r, 194 (int)r,
194 GET_FGCOLOR (r), GET_BGCOLOR (r), 195 fgcolor_of (r), bgcolor_of (r),
195 r & RS_Bold ? " bold" : "", 196 r & RS_Bold ? " bold" : "",
196 r & RS_Italic ? " italic" : "", 197 r & RS_Italic ? " italic" : "",
197 r & RS_Blink ? " blink" : "", 198 r & RS_Blink ? " blink" : "",
198 r & RS_RVid ? " rvid" : "", 199 r & RS_RVid ? " rvid" : "",
199 r & RS_Uline ? " uline" : "", 200 r & RS_Uline ? " uline" : "",
202 int width = wcswidth (fname, wcslen (fname)); 203 int width = wcswidth (fname, wcslen (fname));
203 204
204 max_it (width, 8+5); // for char + hey 205 max_it (width, 8+5); // for char + hey
205 max_it (width, strlen (attr)); 206 max_it (width, strlen (attr));
206 207
208 if (y >= 0)
209 {
210 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
211 x = 0;
212 }
213
207 scr_overlay_new (0, -1, width, len + 2); 214 scr_overlay_new (x, y, width, len + 2);
208 215
209 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 216 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
210 217
211 for (int y = 0; y < len; y++) 218 for (int y = 0; y < len; y++)
212 { 219 {
215 ch = *chr++; 222 ch = *chr++;
216 223
217 sprintf (buf, "%8x", ch); 224 sprintf (buf, "%8x", ch);
218 scr_overlay_set (0, y, buf); 225 scr_overlay_set (0, y, buf);
219 scr_overlay_set (9, y, '='); 226 scr_overlay_set (9, y, '=');
220#if !UNICODE3 227# if !UNICODE3
221 if (ch >= 0x10000) 228 if (ch >= 0x10000)
222 ch = 0xfffd; 229 ch = 0xfffd;
223#endif 230# endif
224 scr_overlay_set (11, y, ch, r); 231 scr_overlay_set (11, y, ch, r);
225 scr_overlay_set (12, y, NOCHAR, r); 232 scr_overlay_set (12, y, NOCHAR, r);
226 } 233 }
227 234
228 scr_overlay_set (0, len , attr); 235 scr_overlay_set (0, len , attr);
229 scr_overlay_set (0, len + 1, fname); 236 scr_overlay_set (0, len + 1, fname);
230 237
231 free (fname); 238 free (fname);
232 239
233#if ENABLE_COMBINING 240# if ENABLE_COMBINING
234 if (alloc) 241 if (alloc)
235 delete [] alloc; 242 delete [] alloc;
236#endif 243# endif
237} 244}
238#endif 245#endif
239 246
240void 247void
241rxvt_term::commit_iso14755 () 248rxvt_term::commit_iso14755 ()
258 mb[0] = ch[0]; 265 mb[0] = ch[0];
259 len = 1; 266 len = 1;
260 } 267 }
261 268
262 if (len > 0) 269 if (len > 0)
263 tt_write ((unsigned char *)mb, len); 270 tt_write (mb, len);
264 else 271 else
265 scr_bell (); 272 scr_bell ();
266 } 273 }
267 274
268 iso14755buf = 0; 275 iso14755buf = 0;
296 KeySym keysym; 303 KeySym keysym;
297#ifdef DEBUG_CMD 304#ifdef DEBUG_CMD
298 static int debug_key = 1; /* accessible by a debugger only */ 305 static int debug_key = 1; /* accessible by a debugger only */
299#endif 306#endif
300 int valid_keysym; 307 int valid_keysym;
301 unsigned char kbuf[KBUFSZ]; 308 char kbuf[KBUFSZ];
302 309
303 /* 310 /*
304 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 311 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
305 * escape sequence to toggle the Keypad. 312 * escape sequence to toggle the Keypad.
306 * 313 *
324 Status status_return; 331 Status status_return;
325 332
326#if 0 333#if 0
327#ifdef X_HAVE_UTF8_STRING 334#ifdef X_HAVE_UTF8_STRING
328 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful 335 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
329 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 336 len = Xutf8LookupString (Input_Context, &ev, kbuf,
330 KBUFSZ, &keysym, &status_return); 337 KBUFSZ, &keysym, &status_return);
331 else 338 else
332#endif 339#endif
333#endif 340#endif
334 { 341 {
371 || status_return == XLookupBoth; 378 || status_return == XLookupBoth;
372 } 379 }
373 else 380 else
374#endif 381#endif
375 { 382 {
376 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); 383 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
377 valid_keysym = keysym != NoSymbol; 384 valid_keysym = keysym != NoSymbol;
378 } 385 }
379 386
380 if (valid_keysym) 387 if (valid_keysym)
381 { 388 {
433 scr_move_to (0, 1); 440 scr_move_to (0, 1);
434 return; 441 return;
435 } 442 }
436 else if (keysym == XK_End) 443 else if (keysym == XK_End)
437 { 444 {
438 scr_move_to (1, 0); 445 scr_move_to (1, 1);
439 return; 446 return;
440 } 447 }
441 } 448 }
442#endif 449#endif
443 } 450 }
454 { 461 {
455 switch (keysym) 462 switch (keysym)
456 { 463 {
457 /* normal XTerm key bindings */ 464 /* normal XTerm key bindings */
458 case XK_Insert: /* Shift+Insert = paste mouse selection */ 465 case XK_Insert: /* Shift+Insert = paste mouse selection */
459 selection_request (ev.time, 0, 0); 466 selection_request (ev.time);
460 return; 467 return;
461#if TODO 468#if TODO
462 /* rxvt extras */ 469 /* rxvt extras */
463 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 470 case XK_KP_Add: /* Shift+KP_Add = bigger font */
464 change_font (FONT_UP); 471 change_font (FONT_UP);
845 { 852 {
846#ifdef META8_OPTION 853#ifdef META8_OPTION
847 /* set 8-bit on */ 854 /* set 8-bit on */
848 if (meta && (meta_char == 0x80)) 855 if (meta && (meta_char == 0x80))
849 { 856 {
850 unsigned char *ch; 857 char *ch;
851 858
852 for (ch = kbuf; ch < kbuf + len; ch++) 859 for (ch = kbuf; ch < kbuf + len; ch++)
853 *ch |= 0x80; 860 *ch |= 0x80;
854 861
855 meta = 0; 862 meta = 0;
857#endif 864#endif
858 /* nil */ ; 865 /* nil */ ;
859 } 866 }
860 } 867 }
861 868
869 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
870 return;
871
862 if (len <= 0) 872 if (len <= 0)
863 return; /* not mapped */ 873 return; /* not mapped */
864 874
865 if (options & Opt_scrollTtyKeypress) 875 if (OPTION (Opt_scrollTtyKeypress))
866 if (view_start) 876 if (view_start)
867 { 877 {
868 view_start = 0; 878 view_start = 0;
869 want_refresh = 1; 879 want_refresh = 1;
870 } 880 }
888#ifdef META8_OPTION 898#ifdef META8_OPTION
889 && meta_char == C0_ESC 899 && meta_char == C0_ESC
890#endif 900#endif
891 ) 901 )
892 { 902 {
893 const unsigned char ch = C0_ESC; 903 const char ch = C0_ESC;
894 tt_write (&ch, 1); 904 tt_write (&ch, 1);
895 } 905 }
896 906
897#if defined(DEBUG_CMD) 907#if defined(DEBUG_CMD)
898 /* Display keyboard buffer contents */ 908 /* Display keyboard buffer contents */
906#endif /* DEBUG_CMD */ 916#endif /* DEBUG_CMD */
907 tt_write (kbuf, (unsigned int)len); 917 tt_write (kbuf, (unsigned int)len);
908} 918}
909/*}}} */ 919/*}}} */
910 920
911#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) 921#if defined (KEYSYM_RESOURCE)
912/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
913/* attempt to `write' count to the input buffer */
914unsigned int 922unsigned int
915rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 923rxvt_term::cmd_write (const char *str, unsigned int count)
916{ 924{
917 unsigned int n, s; 925 unsigned int n, s;
918 926
919 n = cmdbuf_ptr - cmdbuf_base; 927 n = cmdbuf_ptr - cmdbuf_base;
920 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; 928 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
957 } 965 }
958#endif 966#endif
959 967
960 if (want_refresh) 968 if (want_refresh)
961 { 969 {
970 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
971 {
972 int row = view_start;
973 int end_row = row + nrow;
974
975 while (row > top_row && ROW (row - 1).is_longer ())
976 --row;
977
978 do
979 {
980 int start_row = row;
981 line_t *l;
982
983 do
984 {
985 l = &ROW (row++);
986
987 if (!(l->f & LINE_FILTERED))
988 {
989 // line not filtered, mark it as filtered
990 l->f |= LINE_FILTERED;
991 while (l->is_longer ())
992 {
993 l = &ROW (row++);
994 l->f |= LINE_FILTERED;
995 }
996
997 // and filter it
998 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
999
1000 break;
1001 }
1002 }
1003 while (l->is_longer () && row < end_row);
1004 }
1005 while (row < end_row);
1006 }
1007
962 scr_refresh (refresh_type); 1008 scr_refresh ();
963 scrollbar_show (1); 1009 scrollbar_show (1);
964#ifdef USE_XIM 1010#ifdef USE_XIM
965 IMSendSpot (); 1011 IMSendSpot ();
966#endif 1012#endif
967 } 1013 }
970} 1016}
971 1017
972void 1018void
973rxvt_term::check_cb (check_watcher &w) 1019rxvt_term::check_cb (check_watcher &w)
974{ 1020{
975 SET_R (this); 1021 make_current ();
976 SET_LOCALE (locale);
977 1022
978 display->flush (); 1023 display->flush ();
979 1024
980 if (want_refresh && !flush_ev.active) 1025 if (want_refresh && !flush_ev.active)
981 flush_ev.start (NOW + 0.01); 1026 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
982} 1027}
983 1028
984void 1029void
985rxvt_term::flush_cb (time_watcher &w) 1030rxvt_term::flush_cb (time_watcher &w)
986{ 1031{
987 SET_R (this); 1032 make_current ();
988 SET_LOCALE (locale);
989 1033
990 refresh_limit = 1; 1034 refresh_limit = 1;
991 refresh_count = 0; 1035 refresh_count = 0;
992 flush (); 1036 flush ();
993} 1037}
997rxvt_term::cursor_blink_cb (time_watcher &w) 1041rxvt_term::cursor_blink_cb (time_watcher &w)
998{ 1042{
999 hidden_cursor = !hidden_cursor; 1043 hidden_cursor = !hidden_cursor;
1000 want_refresh = 1; 1044 want_refresh = 1;
1001 1045
1002 w.start (w.at + BLINK_INTERVAL); 1046 w.start (w.at + CURSOR_BLINK_INTERVAL);
1003} 1047}
1004#endif 1048#endif
1005 1049
1006#ifdef TEXT_BLINK 1050#ifdef TEXT_BLINK
1007void 1051void
1021rxvt_term::cont_scroll_cb (time_watcher &w) 1065rxvt_term::cont_scroll_cb (time_watcher &w)
1022{ 1066{
1023 if ((scrollbar_isUp() || scrollbar_isDn()) && 1067 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1024 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1068 scr_page (scrollbar_isUp() ? UP : DN, 1))
1025 { 1069 {
1026 refresh_type |= SMOOTH_REFRESH;
1027 want_refresh = 1; 1070 want_refresh = 1;
1028 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1071 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1029 } 1072 }
1030} 1073}
1031#endif 1074#endif
1035rxvt_term::sel_scroll_cb (time_watcher &w) 1078rxvt_term::sel_scroll_cb (time_watcher &w)
1036{ 1079{
1037 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1080 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1038 { 1081 {
1039 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1082 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1040 refresh_type |= SMOOTH_REFRESH;
1041 want_refresh = 1; 1083 want_refresh = 1;
1042 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1084 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1043 } 1085 }
1044} 1086}
1045#endif 1087#endif
1050{ 1092{
1051 if (mouse_slip_wheel_speed == 0 1093 if (mouse_slip_wheel_speed == 0
1052 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) 1094 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1053 : scr_page (UP, mouse_slip_wheel_speed)) 1095 : scr_page (UP, mouse_slip_wheel_speed))
1054 { 1096 {
1055 if (view_start == nsaved || 1097 if (view_start == top_row || view_start == 0)
1056 view_start == 0)
1057 mouse_slip_wheel_speed = 0; 1098 mouse_slip_wheel_speed = 0;
1058 1099
1059 refresh_type |= SMOOTH_REFRESH;
1060 want_refresh = 1; 1100 want_refresh = 1;
1061 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1101 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1062 } 1102 }
1063} 1103}
1064#endif 1104#endif
1065 1105
1106#if HAVE_SCHED_YIELD
1107static struct event_handler
1108{
1109 check_watcher cw_yield;
1110
1111 void yield (check_watcher &w)
1112 {
1113 sched_yield ();
1114 w.stop ();
1115 }
1116
1117 event_handler ()
1118 : cw_yield (this, &event_handler::yield)
1119 {
1120 }
1121} event_handler;
1122#endif
1123
1066bool 1124bool
1067rxvt_term::pty_fill () 1125rxvt_term::pty_fill ()
1068{ 1126{
1069 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1127 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1070 1128
1071 if (CBUFSIZ == n) 1129 if (CBUFSIZ == n)
1072 { 1130 {
1073 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");
1074 n = 0; 1132 n = 0;
1075 } 1133 }
1076 1134
1077 memmove (cmdbuf_base, cmdbuf_ptr, n); 1135 memmove (cmdbuf_base, cmdbuf_ptr, n);
1078 cmdbuf_ptr = cmdbuf_base; 1136 cmdbuf_ptr = cmdbuf_base;
1079 cmdbuf_endp = cmdbuf_ptr + n; 1137 cmdbuf_endp = cmdbuf_ptr + n;
1080 1138
1081 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1139 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1082 1140
1083 if (n > 0) 1141 if (r > 0)
1084 { 1142 {
1085 cmdbuf_endp += n; 1143 cmdbuf_endp += r;
1086 return true; 1144 return true;
1087 } 1145 }
1088 else if ((n < 0 && errno != EAGAIN && errno != EINTR) || n == 0) 1146 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1147 {
1148#if HAVE_SCHED_YIELD
1149 if (display->is_local)
1150 event_handler.cw_yield.start ();
1151#endif
1152 }
1153 else
1089 { 1154 {
1090 pty_ev.stop (); 1155 pty_ev.stop ();
1091 1156
1092 if (!(options & Opt_hold)) 1157 if (!OPTION (Opt_hold))
1093 destroy (); 1158 destroy ();
1094 } 1159 }
1095 1160
1096 return false; 1161 return false;
1097} 1162}
1098 1163
1099void 1164void
1100rxvt_term::pty_cb (io_watcher &w, short revents) 1165rxvt_term::pty_cb (io_watcher &w, short revents)
1101{ 1166{
1102 SET_R (this); 1167 make_current ();
1103 SET_LOCALE (locale);
1104 1168
1105 if (revents & EVENT_READ) 1169 if (revents & EVENT_READ)
1106 // loop, but don't allow a single term to monopolize us 1170 // loop, but don't allow a single term to monopolize us
1107 while (pty_fill ()) 1171 while (pty_fill ())
1108 if (cmd_parse ()) 1172 if (cmd_parse ())
1119 recolour_cursor (); 1183 recolour_cursor ();
1120 1184
1121#ifdef POINTER_BLANK 1185#ifdef POINTER_BLANK
1122 hidden_pointer = 0; 1186 hidden_pointer = 0;
1123 1187
1124 if (options & Opt_pointerBlank) 1188 if (OPTION (Opt_pointerBlank))
1125 pointer_ev.start (NOW + pointerBlankDelay); 1189 pointer_ev.start (NOW + pointerBlankDelay);
1126#endif 1190#endif
1127} 1191}
1128 1192
1129#ifdef POINTER_BLANK 1193#ifdef POINTER_BLANK
1130void 1194void
1131rxvt_term::pointer_blank () 1195rxvt_term::pointer_blank ()
1132{ 1196{
1133 if (! (options & Opt_pointerBlank)) 1197 if (!OPTION (Opt_pointerBlank))
1134 return; 1198 return;
1135 1199
1136 XDefineCursor (display->display, vt, display->blank_cursor); 1200 XDefineCursor (display->display, vt, display->blank_cursor);
1137 XFlush (display->display); 1201 XFlush (display->display);
1138 1202
1140} 1204}
1141 1205
1142void 1206void
1143rxvt_term::pointer_cb (time_watcher &w) 1207rxvt_term::pointer_cb (time_watcher &w)
1144{ 1208{
1145 SET_R (this); 1209 make_current ();
1146 SET_LOCALE (locale);
1147 1210
1148 pointer_blank (); 1211 pointer_blank ();
1149} 1212}
1150#endif 1213#endif
1151 1214
1230 1293
1231/*{{{ process an X event */ 1294/*{{{ process an X event */
1232void 1295void
1233rxvt_term::x_cb (XEvent &ev) 1296rxvt_term::x_cb (XEvent &ev)
1234{ 1297{
1298 make_current ();
1299
1235 dDisp; 1300 dDisp;
1236 1301
1237 SET_R (this); 1302 if (ev.xany.window == vt
1238 SET_LOCALE (locale); 1303 && SHOULD_INVOKE (HOOK_X_EVENT)
1304 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1305 return;
1239 1306
1240#if defined(CURSOR_BLINK) 1307 // for XQueryPointer
1241 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1242 {
1243 if (hidden_cursor)
1244 {
1245 hidden_cursor = 0;
1246 want_refresh = 1;
1247 }
1248
1249 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1250 }
1251#endif
1252
1253#if defined(POINTER_BLANK)
1254 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1255 {
1256 if (ev.type == MotionNotify
1257 || ev.type == ButtonPress
1258 || ev.type == ButtonRelease)
1259 if (hidden_pointer)
1260 pointer_unblank ();
1261
1262 if (ev.type == KeyPress && hidden_pointer == 0)
1263 pointer_blank ();
1264 }
1265#endif
1266
1267 Window unused_root, unused_child; 1308 Window unused_root, unused_child;
1268 int unused_root_x, unused_root_y; 1309 int unused_root_x, unused_root_y;
1269 unsigned int unused_mask; 1310 unsigned int unused_mask;
1270 1311
1271 switch (ev.type) 1312 switch (ev.type)
1278 1319
1279 break; 1320 break;
1280 1321
1281 case KeyRelease: 1322 case KeyRelease:
1282 { 1323 {
1283#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 1324#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1284 KeySym ks; 1325 KeySym keysym;
1285 1326
1286 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ 1327 keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1287#endif 1328#endif
1288 1329
1289#if ENABLE_FRILLS || ISO_14755 1330#if ENABLE_FRILLS || ISO_14755
1290 // ISO 14755 support 1331 // ISO 14755 support
1291 if (iso14755buf) 1332 if (iso14755buf)
1296# endif 1337# endif
1297# if ISO_14755 1338# if ISO_14755
1298 // iso14755 part 5.2 handling: release time 1339 // iso14755 part 5.2 handling: release time
1299 // first: controls 1340 // first: controls
1300 if ((ev.xkey.state & ControlMask) 1341 if ((ev.xkey.state & ControlMask)
1301 && ((ks >= 0x40 && ks <= 0x5f) 1342 && ((keysym >= 0x40 && keysym <= 0x5f)
1302 || (ks >= 0x61 && ks <= 0x7f))) 1343 || (keysym >= 0x61 && keysym <= 0x7f)))
1303 { 1344 {
1304 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f); 1345 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1305 commit_iso14755 (); 1346 commit_iso14755 ();
1306 return; // case-break; 1347 goto skip_switch;
1307 } 1348 }
1308 1349
1309 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) 1350 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1310 if (i[0] == ks) 1351 if (i[0] == keysym)
1311 { 1352 {
1312 iso14755buf = ISO_14755_51 | i[1]; 1353 iso14755buf = ISO_14755_51 | i[1];
1313 commit_iso14755 (); 1354 commit_iso14755 ();
1314 return; // case-break; 1355 goto skip_switch;
1315 } 1356 }
1316 1357
1317 scr_bell (); 1358 scr_bell ();
1318# endif 1359# endif
1319 iso14755buf = 0; 1360 iso14755buf = 0;
1338 else 1379 else
1339 iso14755buf = 0; 1380 iso14755buf = 0;
1340 } 1381 }
1341#endif 1382#endif
1342 1383
1384 if (ev.xany.window == vt
1385 && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
1386 break;
1387
1343#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1388#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1344 if (!(ev.xkey.state & ControlMask)) 1389 if (!(ev.xkey.state & ControlMask))
1345 slip_wheel_ev.stop (); 1390 slip_wheel_ev.stop ();
1346 else if (ks == XK_Control_L || ks == XK_Control_R) 1391 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1347 mouse_slip_wheel_speed = 0; 1392 mouse_slip_wheel_speed = 0;
1348#endif 1393#endif
1349 break; 1394 break;
1350 } 1395 }
1351 1396
1454 { 1499 {
1455 seen_resize = 1; 1500 seen_resize = 1;
1456 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1501 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1457 } 1502 }
1458 1503
1504 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1505
1459#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1506#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1460 if (options & Opt_transparent) 1507 if (OPTION (Opt_transparent))
1461 check_our_parents (); 1508 check_our_parents ();
1462#endif 1509#endif
1463 } 1510 }
1464 break; 1511 break;
1465 1512
1481 1528
1482 case SelectionRequest: 1529 case SelectionRequest:
1483 selection_send (ev.xselectionrequest); 1530 selection_send (ev.xselectionrequest);
1484 break; 1531 break;
1485 1532
1533 case MapNotify:
1534 mapped = 1;
1535#ifdef TEXT_BLINK
1536 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1537#endif
1538 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1539 break;
1540
1486 case UnmapNotify: 1541 case UnmapNotify:
1487 mapped = 0; 1542 mapped = 0;
1488#ifdef TEXT_BLINK 1543#ifdef TEXT_BLINK
1489 text_blink_ev.stop (); 1544 text_blink_ev.stop ();
1490#endif 1545#endif
1491 break; 1546 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1492
1493 case MapNotify:
1494 mapped = 1;
1495#ifdef TEXT_BLINK
1496 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1497#endif
1498 break; 1547 break;
1499 1548
1500#ifdef TRANSPARENT 1549#ifdef TRANSPARENT
1501 case ReparentNotify: 1550 case ReparentNotify:
1502 rootwin_cb (ev); 1551 rootwin_cb (ev);
1516 1565
1517 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) 1566 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1518 scr_expose (ev.xexpose.x, ev.xexpose.y, 1567 scr_expose (ev.xexpose.x, ev.xexpose.y,
1519 ev.xexpose.width, ev.xexpose.height, False); 1568 ev.xexpose.width, ev.xexpose.height, False);
1520 1569
1521 scr_refresh (refresh_type); 1570 want_refresh = 1;
1522 } 1571 }
1523 else 1572 else
1524 { 1573 {
1525 XEvent unused_event; 1574 XEvent unused_event;
1526 1575
1532 if (isScrollbarWindow (ev.xany.window)) 1581 if (isScrollbarWindow (ev.xany.window))
1533 { 1582 {
1534 scrollBar.setIdle (); 1583 scrollBar.setIdle ();
1535 scrollbar_show (0); 1584 scrollbar_show (0);
1536 } 1585 }
1537#ifdef MENUBAR
1538 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1539 menubar_expose ();
1540#endif
1541 1586
1542#ifdef TRANSPARENT 1587#ifdef TRANSPARENT
1543 if (am_transparent && ev.xany.window == parent[0]) 1588 if (am_transparent && ev.xany.window == parent[0])
1544 XClearWindow (disp, ev.xany.window); 1589 XClearWindow (disp, ev.xany.window);
1545#endif 1590#endif
1549 case MotionNotify: 1594 case MotionNotify:
1550#ifdef POINTER_BLANK 1595#ifdef POINTER_BLANK
1551 if (hidden_pointer) 1596 if (hidden_pointer)
1552 pointer_unblank (); 1597 pointer_unblank ();
1553#endif 1598#endif
1554#if MENUBAR
1555 if (isMenuBarWindow (ev.xany.window))
1556 {
1557 menubar_control (ev.xbutton);
1558 break;
1559 }
1560#endif
1561 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1599 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1562 break; 1600 break;
1563 1601
1564 if (ev.xany.window == vt) 1602 if (ev.xany.window == vt)
1565 { 1603 {
1604 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1605 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1606 ; // nop
1566 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1607 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1567 { 1608 {
1568 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) 1609 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1569 ; 1610 ;
1570 1611
1571 XQueryPointer (disp, vt, 1612 XQueryPointer (disp, vt,
1651 &unused_root_x, &unused_root_y, 1692 &unused_root_x, &unused_root_y,
1652 &ev.xbutton.x, &ev.xbutton.y, 1693 &ev.xbutton.x, &ev.xbutton.y,
1653 &unused_mask); 1694 &unused_mask);
1654 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1695 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1655 scrollbar_size ()); 1696 scrollbar_size ());
1656 scr_refresh (refresh_type); 1697 want_refresh = 1;
1657 refresh_limit = 0; 1698 refresh_limit = 0;
1658 scrollbar_show (1); 1699 scrollbar_show (1);
1659 } 1700 }
1660 break; 1701 break;
1661 } 1702 }
1703
1704skip_switch: ;
1705
1706#if defined(CURSOR_BLINK)
1707 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress)
1708 {
1709 if (hidden_cursor)
1710 {
1711 hidden_cursor = 0;
1712 want_refresh = 1;
1713 }
1714
1715 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1716 }
1717#endif
1718
1719#if defined(POINTER_BLANK)
1720 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0)
1721 {
1722 if (ev.type == MotionNotify
1723 || ev.type == ButtonPress
1724 || ev.type == ButtonRelease)
1725 if (hidden_pointer)
1726 pointer_unblank ();
1727
1728 if (ev.type == KeyPress && hidden_pointer == 0)
1729 pointer_blank ();
1730 }
1731#endif
1662} 1732}
1663 1733
1664void 1734void
1665rxvt_term::focus_in () 1735rxvt_term::focus_in ()
1666{ 1736{
1667 if (!focus) 1737 if (!focus)
1668 { 1738 {
1669 focus = 1; 1739 focus = 1;
1670 want_refresh = 1; 1740 want_refresh = 1;
1741
1742 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1743
1671#if USE_XIM 1744#if USE_XIM
1672 if (Input_Context != NULL) 1745 if (Input_Context != NULL)
1673 { 1746 {
1674 IMSetStatusPosition (); 1747 IMSetStatusPosition ();
1675 XSetICFocus (Input_Context); 1748 XSetICFocus (Input_Context);
1676 } 1749 }
1677#endif 1750#endif
1678#if CURSOR_BLINK 1751#if CURSOR_BLINK
1679 if (options & Opt_cursorBlink) 1752 if (OPTION (Opt_cursorBlink))
1680 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1753 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1681#endif 1754#endif
1682#if OFF_FOCUS_FADING 1755#if OFF_FOCUS_FADING
1683 if (rs[Rs_fade]) 1756 if (rs[Rs_fade])
1684 { 1757 {
1685 pix_colors = pix_colors_focused; 1758 pix_colors = pix_colors_focused;
1695 if (focus) 1768 if (focus)
1696 { 1769 {
1697 focus = 0; 1770 focus = 0;
1698 want_refresh = 1; 1771 want_refresh = 1;
1699 1772
1773 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1774
1700#if ENABLE_FRILLS || ISO_14755 1775#if ENABLE_FRILLS || ISO_14755
1776 if (iso14755buf)
1777 {
1701 iso14755buf = 0; 1778 iso14755buf = 0;
1702#endif
1703#if ENABLE_OVERLAY 1779# if ENABLE_OVERLAY
1704 scr_overlay_off (); 1780 scr_overlay_off ();
1781# endif
1782 }
1705#endif 1783#endif
1706#if USE_XIM 1784#if USE_XIM
1707 if (Input_Context != NULL) 1785 if (Input_Context != NULL)
1708 XUnsetICFocus (Input_Context); 1786 XUnsetICFocus (Input_Context);
1709#endif 1787#endif
1710#if CURSOR_BLINK 1788#if CURSOR_BLINK
1711 if (options & Opt_cursorBlink) 1789 if (OPTION (Opt_cursorBlink))
1712 cursor_blink_ev.stop (); 1790 cursor_blink_ev.stop ();
1713 hidden_cursor = 0; 1791 hidden_cursor = 0;
1714#endif 1792#endif
1715#if OFF_FOCUS_FADING 1793#if OFF_FOCUS_FADING
1716 if (rs[Rs_fade]) 1794 if (rs[Rs_fade])
1724 1802
1725#if TRANSPARENT 1803#if TRANSPARENT
1726void 1804void
1727rxvt_term::rootwin_cb (XEvent &ev) 1805rxvt_term::rootwin_cb (XEvent &ev)
1728{ 1806{
1729 SET_R (this); 1807 make_current ();
1730 SET_LOCALE (locale);
1731 1808
1732 switch (ev.type) 1809 switch (ev.type)
1733 { 1810 {
1734 case PropertyNotify: 1811 case PropertyNotify:
1735 /* 1812 /*
1740 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1817 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1741 return; 1818 return;
1742 1819
1743 /* FALLTHROUGH */ 1820 /* FALLTHROUGH */
1744 case ReparentNotify: 1821 case ReparentNotify:
1745 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1822 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1746 want_refresh = want_full_refresh = 1; 1823 want_refresh = want_full_refresh = 1;
1747 break; 1824 break;
1748 } 1825 }
1749} 1826}
1750#endif 1827#endif
1753rxvt_term::button_press (XButtonEvent &ev) 1830rxvt_term::button_press (XButtonEvent &ev)
1754{ 1831{
1755 int reportmode = 0, clickintime; 1832 int reportmode = 0, clickintime;
1756 1833
1757 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1834 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1835
1758 if (!bypass_keystate) 1836 if (!bypass_keystate)
1759 reportmode = !! (priv_modes & PrivMode_mouse_report); 1837 reportmode = !! (priv_modes & PrivMode_mouse_report);
1760 1838
1761 /* 1839 /*
1762 * VT window processing of button press 1840 * VT window processing of button press
1782#ifdef MOUSE_REPORT_DOUBLECLICK 1860#ifdef MOUSE_REPORT_DOUBLECLICK
1783 if (ev.button == MEvent.button && clickintime) 1861 if (ev.button == MEvent.button && clickintime)
1784 { 1862 {
1785 /* same button, within alloted time */ 1863 /* same button, within alloted time */
1786 MEvent.clicks++; 1864 MEvent.clicks++;
1865
1787 if (MEvent.clicks > 1) 1866 if (MEvent.clicks > 1)
1788 { 1867 {
1789 /* only report double clicks */ 1868 /* only report double clicks */
1790 MEvent.clicks = 2; 1869 MEvent.clicks = 2;
1791 mouse_report (ev); 1870 mouse_report (ev);
1811 else 1890 else
1812 { 1891 {
1813 if (ev.button != MEvent.button) 1892 if (ev.button != MEvent.button)
1814 MEvent.clicks = 0; 1893 MEvent.clicks = 0;
1815 1894
1895 if (!HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1816 switch (ev.button) 1896 switch (ev.button)
1817 { 1897 {
1818 case Button1: 1898 case Button1:
1819 /* allow meta + click to select rectangular areas */ 1899 /* allow meta + click to select rectangular areas */
1820 /* should be done in screen.C */ 1900 /* should be done in screen.C */
1821#if ENABLE_FRILLS 1901#if ENABLE_FRILLS
1822 selection.rect = !!(ev.state & ModMetaMask); 1902 selection.rect = !!(ev.state & ModMetaMask);
1823#else 1903#else
1824 selection.rect = false; 1904 selection.rect = false;
1825#endif 1905#endif
1826 1906
1827 /* allow shift+left click to extend selection */ 1907 /* allow shift+left click to extend selection */
1828 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1908 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1829 { 1909 {
1830 if (MEvent.button == Button1 && clickintime) 1910 if (MEvent.button == Button1 && clickintime)
1831 selection_rotate (ev.x, ev.y); 1911 selection_rotate (ev.x, ev.y);
1832 else 1912 else
1833 selection_extend (ev.x, ev.y, 1); 1913 selection_extend (ev.x, ev.y, 1);
1834 } 1914 }
1835 else 1915 else
1836 { 1916 {
1837 if (MEvent.button == Button1 && clickintime) 1917 if (MEvent.button == Button1 && clickintime)
1838 MEvent.clicks++; 1918 MEvent.clicks++;
1839 else 1919 else
1840 MEvent.clicks = 1; 1920 MEvent.clicks = 1;
1841 1921
1842 selection_click (MEvent.clicks, ev.x, ev.y); 1922 selection_click (MEvent.clicks, ev.x, ev.y);
1843 } 1923 }
1844 1924
1845 MEvent.button = Button1; 1925 MEvent.button = Button1;
1846 break; 1926 break;
1847 1927
1848 case Button3: 1928 case Button3:
1849 if (MEvent.button == Button3 && clickintime) 1929 if (MEvent.button == Button3 && clickintime)
1850 selection_rotate (ev.x, ev.y); 1930 selection_rotate (ev.x, ev.y);
1851 else 1931 else
1852 selection_extend (ev.x, ev.y, 1); 1932 selection_extend (ev.x, ev.y, 1);
1853 1933
1854 MEvent.button = Button3; 1934 MEvent.button = Button3;
1855 break; 1935 break;
1856 } 1936 }
1857 } 1937 }
1858 1938
1859 MEvent.time = ev.time; 1939 MEvent.time = ev.time;
1860 return; 1940 return;
1861 } 1941 }
1862 1942
1998 } 2078 }
1999 2079
2000 break; 2080 break;
2001 } 2081 }
2002 } 2082 }
2083
2003 return; 2084 return;
2004 } 2085 }
2005#if MENUBAR
2006 /*
2007 * Menubar window processing of button press
2008 */
2009 if (isMenuBarWindow (ev.window))
2010 menubar_control (ev);
2011#endif
2012} 2086}
2013 2087
2014void 2088void
2015rxvt_term::button_release (XButtonEvent &ev) 2089rxvt_term::button_release (XButtonEvent &ev)
2016{ 2090{
2022 2096
2023 if (scrollbar_isUpDn ()) 2097 if (scrollbar_isUpDn ())
2024 { 2098 {
2025 scrollBar.setIdle (); 2099 scrollBar.setIdle ();
2026 scrollbar_show (0); 2100 scrollbar_show (0);
2027#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2028 refresh_type &= ~SMOOTH_REFRESH;
2029#endif
2030 } 2101 }
2031 2102
2032#ifdef SELECTION_SCROLLING 2103#ifdef SELECTION_SCROLLING
2033 if (sel_scroll_ev.active) 2104 if (sel_scroll_ev.active)
2034 sel_scroll_ev.stop(); 2105 sel_scroll_ev.stop();
2072 if (priv_modes & PrivMode_mouse_report 2143 if (priv_modes & PrivMode_mouse_report
2073 && bypass_keystate 2144 && bypass_keystate
2074 && ev.button == Button1 && MEvent.clicks <= 1) 2145 && ev.button == Button1 && MEvent.clicks <= 1)
2075 selection_extend (ev.x, ev.y, 0); 2146 selection_extend (ev.x, ev.y, 0);
2076 2147
2148 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2149 return;
2150
2077 switch (ev.button) 2151 switch (ev.button)
2078 { 2152 {
2079 case Button1: 2153 case Button1:
2080 case Button3: 2154 case Button3:
2081 selection_make (ev.time); 2155 selection_make (ev.time);
2082 break; 2156 break;
2157
2083 case Button2: 2158 case Button2:
2084 selection_request (ev.time, ev.x, ev.y); 2159 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2160 selection_request (ev.time, ev.state & ShiftMask ? Sel_Clipboard : Sel_Primary);
2085 break; 2161 break;
2162
2086#ifdef MOUSE_WHEEL 2163#ifdef MOUSE_WHEEL
2087 case Button4: 2164 case Button4:
2088 case Button5: 2165 case Button5:
2089 { 2166 {
2090 int i; 2167 int i;
2092 2169
2093 v = ev.button == Button4 ? UP : DN; 2170 v = ev.button == Button4 ? UP : DN;
2094 2171
2095 if (ev.state & ShiftMask) 2172 if (ev.state & ShiftMask)
2096 i = 1; 2173 i = 1;
2097 else if (options & Opt_mouseWheelScrollPage) 2174 else if (OPTION (Opt_mouseWheelScrollPage))
2098 i = nrow - 1; 2175 i = nrow - 1;
2099 else 2176 else
2100 i = 5; 2177 i = 5;
2101 2178
2102# ifdef MOUSE_SLIP_WHEELING 2179# ifdef MOUSE_SLIP_WHEELING
2112 slip_wheel_ev.start (); 2189 slip_wheel_ev.start ();
2113 } 2190 }
2114 else 2191 else
2115 { 2192 {
2116# endif 2193# endif
2117# ifdef JUMP_MOUSE_WHEEL
2118 scr_page (v, i); 2194 scr_page (v, i);
2119 scr_refresh (SMOOTH_REFRESH);
2120 scrollbar_show (1); 2195 scrollbar_show (1);
2121# else
2122 while (i--)
2123 {
2124 scr_page (v, 1);
2125 scr_refresh (SMOOTH_REFRESH);
2126 scrollbar_show (1);
2127 }
2128# endif
2129# ifdef MOUSE_SLIP_WHEELING 2196# ifdef MOUSE_SLIP_WHEELING
2130 } 2197 }
2131#endif 2198# endif
2132 } 2199 }
2133 break; 2200 break;
2134#endif 2201#endif
2135 } 2202 }
2136 } 2203 }
2137#ifdef MENUBAR
2138 else if (isMenuBarWindow (ev.window))
2139 menubar_control (ev);
2140#endif
2141} 2204}
2142 2205
2143#ifdef TRANSPARENT 2206#ifdef TRANSPARENT
2144#if TINTING 2207#if TINTING
2145/* taken from aterm-0.4.2 */ 2208/* taken from aterm-0.4.2 */
2388 XWindowAttributes wattr, wrootattr; 2451 XWindowAttributes wattr, wrootattr;
2389 dDisp; 2452 dDisp;
2390 2453
2391 pchanged = 0; 2454 pchanged = 0;
2392 2455
2393 if (!(options & Opt_transparent)) 2456 if (!OPTION (Opt_transparent))
2394 return pchanged; /* Don't try any more */ 2457 return pchanged; /* Don't try any more */
2395 2458
2396 XGetWindowAttributes (disp, display->root, &wrootattr); 2459 XGetWindowAttributes (disp, display->root, &wrootattr);
2397 rootdepth = wrootattr.depth; 2460 rootdepth = wrootattr.depth;
2398 2461
2625 2688
2626bool 2689bool
2627rxvt_term::cmd_parse () 2690rxvt_term::cmd_parse ()
2628{ 2691{
2629 bool flag = false; 2692 bool flag = false;
2630 unicode_t ch = NOCHAR; 2693 wchar_t ch = NOCHAR;
2631 unsigned char *seq_begin; // remember start of esc-sequence here 2694 char *seq_begin; // remember start of esc-sequence here
2632 2695
2633 for (;;) 2696 for (;;)
2634 { 2697 {
2635 if (ch == NOCHAR) 2698 if (ch == NOCHAR)
2636 { 2699 {
2637 seq_begin = cmdbuf_ptr; 2700 seq_begin = cmdbuf_ptr;
2638 ch = next_char (); 2701 ch = next_char ();
2639 }
2640 2702
2641 if (ch == NOCHAR) // TODO: improve 2703 if (ch == NOCHAR)
2642 break; 2704 break;
2705 }
2643 2706
2644 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2707 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2645 { 2708 {
2646 if (!seen_input) 2709 if (!seen_input)
2647 { 2710 {
2656 if (seen_resize && cmd_pid) 2719 if (seen_resize && cmd_pid)
2657 kill (-cmd_pid, SIGWINCH); 2720 kill (-cmd_pid, SIGWINCH);
2658 } 2721 }
2659 2722
2660 /* Read a text string from the input buffer */ 2723 /* Read a text string from the input buffer */
2661 unicode_t buf[UBUFSIZ]; 2724 wchar_t buf[UBUFSIZ];
2662 bool refreshnow = false; 2725 bool refreshnow = false;
2663 int nlines = 0; 2726 int nlines = 0;
2664 unicode_t *str = buf; 2727 wchar_t *str = buf;
2665 unicode_t *eol = str + min (ncol, UBUFSIZ); 2728 wchar_t *eol = str + min (ncol, UBUFSIZ);
2666 2729
2667 for (;;) 2730 for (;;)
2668 { 2731 {
2669 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2732 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2670 break; 2733 break;
2676 if (ch == C0_LF) 2739 if (ch == C0_LF)
2677 nlines++; 2740 nlines++;
2678 2741
2679 refresh_count++; 2742 refresh_count++;
2680 2743
2681 if (!(options & Opt_jumpScroll) 2744 if (!OPTION (Opt_jumpScroll)
2682 || (refresh_count >= refresh_limit * (nrow - 1))) 2745 || (refresh_count >= refresh_limit * (nrow - 1)))
2683 { 2746 {
2684 refreshnow = true; 2747 refreshnow = true;
2748 refresh_count = 0;
2685 ch = NOCHAR; 2749 ch = NOCHAR;
2686 break; 2750 break;
2687 } 2751 }
2688 2752
2689 // scr_add_lines only works for nlines <= nrow - 1. 2753 // scr_add_lines only works for nlines <= nrow - 1.
2690 if (nlines >= nrow - 1) 2754 if (nlines >= nrow - 1)
2691 { 2755 {
2756 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2757 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2692 scr_add_lines (buf, nlines, str - buf); 2758 scr_add_lines (buf, str - buf, nlines);
2759
2693 nlines = 0; 2760 nlines = 0;
2694 str = buf; 2761 str = buf;
2695 eol = str + min (ncol, UBUFSIZ); 2762 eol = str + min (ncol, UBUFSIZ);
2696 } 2763 }
2697 2764
2710 2777
2711 seq_begin = cmdbuf_ptr; 2778 seq_begin = cmdbuf_ptr;
2712 ch = next_char (); 2779 ch = next_char ();
2713 } 2780 }
2714 2781
2782 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2783 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2715 scr_add_lines (buf, nlines, str - buf); 2784 scr_add_lines (buf, str - buf, nlines);
2716 2785
2717 /* 2786 /*
2718 * If there have been a lot of new lines, then update the screen 2787 * If there have been a lot of new lines, then update the screen
2719 * What the heck I'll cheat and only refresh less than every page-full. 2788 * What the heck I'll cheat and only refresh less than every page-full.
2720 * the number of pages between refreshes is refresh_limit, which 2789 * the number of pages between refreshes is refresh_limit, which
2721 * is incremented here because we must be doing flat-out scrolling. 2790 * is incremented here because we must be doing flat-out scrolling.
2722 */ 2791 */
2723 if (refreshnow) 2792 if (refreshnow)
2724 { 2793 {
2725 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 2794 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2726 refresh_limit++; 2795 refresh_limit++;
2727 else 2796 else
2728 { 2797 {
2729 flag = true; 2798 flag = true;
2730 scr_refresh (refresh_type); 2799 scr_refresh ();
2800 want_refresh = 1;
2731 } 2801 }
2732 } 2802 }
2733 2803
2734 } 2804 }
2735 else 2805 else
2750 } 2820 }
2751 2821
2752 return flag; 2822 return flag;
2753} 2823}
2754 2824
2755// read the next octet
2756unicode_t
2757rxvt_term::next_octet ()
2758{
2759 return cmdbuf_ptr < cmdbuf_endp
2760 ? *cmdbuf_ptr++
2761 : NOCHAR;
2762}
2763
2764// read the next character 2825// read the next character
2765unicode_t 2826wchar_t
2766rxvt_term::next_char () 2827rxvt_term::next_char () NOTHROW
2767{ 2828{
2768 while (cmdbuf_ptr < cmdbuf_endp) 2829 while (cmdbuf_ptr < cmdbuf_endp)
2769 { 2830 {
2770 // assume 7-bit to be ascii ALWAYS 2831 // assume 7-bit to be ascii ALWAYS
2771 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2832 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2772 return *cmdbuf_ptr++; 2833 return *cmdbuf_ptr++;
2773 2834
2774 wchar_t wc; 2835 wchar_t wc;
2775 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2836 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2776 2837
2777 if (len == (size_t)-2) 2838 if (len == (size_t)-2)
2778 { 2839 {
2779 // the mbstate stores incomplete sequences. didn't know this :/ 2840 // the mbstate stores incomplete sequences. didn't know this :/
2780 cmdbuf_ptr = cmdbuf_endp; 2841 cmdbuf_ptr = cmdbuf_endp;
2781 break; 2842 break;
2782 } 2843 }
2783 2844
2784 if (len == (size_t)-1) 2845 if (len == (size_t)-1)
2785 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2846 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2786 2847
2787 // assume wchar == unicode 2848 // assume wchar == unicode
2788 cmdbuf_ptr += len; 2849 cmdbuf_ptr += len;
2789 return wc & UNICODE_MASK; 2850 return wc & UNICODE_MASK;
2790 } 2851 }
2791 2852
2792 return NOCHAR; 2853 return NOCHAR;
2793} 2854}
2855
2856// read the next octet
2857uint32_t
2858rxvt_term::next_octet () NOTHROW
2859{
2860 return cmdbuf_ptr < cmdbuf_endp
2861 ? (unsigned char)*cmdbuf_ptr++
2862 : NOCHAR;
2863}
2864
2865static class out_of_input out_of_input;
2794 2866
2795/* rxvt_cmd_getc () - Return next input character */ 2867/* rxvt_cmd_getc () - Return next input character */
2796/* 2868/*
2797 * Return the next input character after first passing any keyboard input 2869 * Return the next input character after first passing any keyboard input
2798 * to the command. 2870 * to the command.
2799 */ 2871 */
2800unicode_t 2872wchar_t
2801rxvt_term::cmd_getc () 2873rxvt_term::cmd_getc () THROW ((class out_of_input))
2802{ 2874{
2803 unicode_t c = next_char (); 2875 wchar_t c = next_char ();
2804 2876
2805 if (c == NOCHAR) 2877 if (c == NOCHAR)
2806 throw out_of_input; 2878 throw out_of_input;
2807 2879
2808 return c; 2880 return c;
2809} 2881}
2810 2882
2811unicode_t 2883uint32_t
2812rxvt_term::cmd_get8 () 2884rxvt_term::cmd_get8 () THROW ((class out_of_input))
2813{ 2885{
2814 unicode_t c = next_octet (); 2886 uint32_t c = next_octet ();
2815 2887
2816 if (c == NOCHAR) 2888 if (c == NOCHAR)
2817 throw out_of_input; 2889 throw out_of_input;
2818 2890
2819 return c; 2891 return c;
2919 case C0_ESC: 2991 case C0_ESC:
2920 process_escape_seq (); 2992 process_escape_seq ();
2921 break; 2993 break;
2922 case C0_ENQ: /* terminal Status */ 2994 case C0_ENQ: /* terminal Status */
2923 if (rs[Rs_answerbackstring]) 2995 if (rs[Rs_answerbackstring])
2924 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2996 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2925 (unsigned int)strlen (rs[Rs_answerbackstring]));
2926 else 2997 else
2927 tt_write ((unsigned char *)VT100_ANS, 2998 tt_write (VT100_ANS, strlen (VT100_ANS));
2928 (unsigned int)strlen (VT100_ANS));
2929 break; 2999 break;
2930 case C0_BEL: /* bell */ 3000 case C0_BEL: /* bell */
2931 scr_bell (); 3001 scr_bell ();
2932 break; 3002 break;
2933 case C0_BS: /* backspace */ 3003 case C0_BS: /* backspace */
3088 break; 3158 break;
3089 3159
3090 /* 8.3.87: NEXT LINE */ 3160 /* 8.3.87: NEXT LINE */
3091 case C1_NEL: /* ESC E */ 3161 case C1_NEL: /* ESC E */
3092 { 3162 {
3093 unicode_t nlcr[] = { C0_LF, C0_CR }; 3163 wchar_t nlcr[] = { C0_LF, C0_CR };
3094 scr_add_lines (nlcr, 1, 2); 3164 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3095 } 3165 }
3096 break; 3166 break;
3097 3167
3098 /* kidnapped escape sequence: Should be 8.3.48 */ 3168 /* kidnapped escape sequence: Should be 8.3.48 */
3099 case C1_ESA: /* ESC G */ 3169 case C1_ESA: /* ESC G */
3121 process_dcs_seq (); 3191 process_dcs_seq ();
3122 break; 3192 break;
3123 3193
3124 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 3194 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3125 case C1_SCI: /* ESC Z */ 3195 case C1_SCI: /* ESC Z */
3126 tt_write ((const unsigned char *)ESCZ_ANSWER, 3196 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3127 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3128 break; /* steal obsolete ESC [ c */ 3197 break; /* steal obsolete ESC [ c */
3129 3198
3130 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 3199 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3131 case C1_CSI: /* ESC [ */ 3200 case C1_CSI: /* ESC [ */
3132 process_csi_seq (); 3201 process_csi_seq ();
3376 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3445 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3377 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]); 3446 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3378 break; 3447 break;
3379 3448
3380 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3449 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3381 tt_write ((const unsigned char *)VT100_ANS, 3450 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3382 (unsigned int) (sizeof (VT100_ANS) - 1));
3383 break; 3451 break;
3384 3452
3385 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 3453 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3386 process_sgr_mode (nargs, arg); 3454 process_sgr_mode (nargs, arg);
3387 break; 3455 break;
3394 break; 3462 break;
3395 case 6: /* CPR requested */ 3463 case 6: /* CPR requested */
3396 scr_report_position (); 3464 scr_report_position ();
3397 break; 3465 break;
3398 case 7: /* unofficial extension */ 3466 case 7: /* unofficial extension */
3399 if (options & Opt_insecure) 3467 if (OPTION (Opt_insecure))
3400 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3468 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3401 break; 3469 break;
3402 case 8: /* unofficial extension */ 3470 case 8: /* unofficial extension */
3403 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3471 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3404 break; 3472 break;
3568 break; 3636 break;
3569 case 20: /* report icon label */ 3637 case 20: /* report icon label */
3570 { 3638 {
3571 char *s; 3639 char *s;
3572 XGetIconName (disp, parent[0], &s); 3640 XGetIconName (disp, parent[0], &s);
3573 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3641 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3574 XFree (s); 3642 XFree (s);
3575 } 3643 }
3576 break; 3644 break;
3577 case 21: /* report window title */ 3645 case 21: /* report window title */
3578 { 3646 {
3579 char *s; 3647 char *s;
3580 XFetchName (disp, parent[0], &s); 3648 XFetchName (disp, parent[0], &s);
3581 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3649 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3582 XFree (s); 3650 XFree (s);
3583 } 3651 }
3584 break; 3652 break;
3585 } 3653 }
3586} 3654}
3589/*----------------------------------------------------------------------*/ 3657/*----------------------------------------------------------------------*/
3590/* 3658/*
3591 * get input up until STRING TERMINATOR (or BEL) 3659 * get input up until STRING TERMINATOR (or BEL)
3592 * ends_how is terminator used. returned input must be free()'d 3660 * ends_how is terminator used. returned input must be free()'d
3593 */ 3661 */
3594unsigned char * 3662char *
3595rxvt_term::get_to_st (unicode_t &ends_how) 3663rxvt_term::get_to_st (unicode_t &ends_how)
3596{ 3664{
3597 unicode_t ch; 3665 unicode_t ch;
3598 bool seen_esc = false; 3666 bool seen_esc = false;
3599 unsigned int n = 0; 3667 unsigned int n = 0;
3632 3700
3633 string[n++] = '\0'; 3701 string[n++] = '\0';
3634 3702
3635 ends_how = (ch == 0x5c ? C0_ESC : ch); 3703 ends_how = (ch == 0x5c ? C0_ESC : ch);
3636 3704
3637 return (unsigned char *)rxvt_wcstombs (string); 3705 return rxvt_wcstombs (string);
3638} 3706}
3639 3707
3640/*----------------------------------------------------------------------*/ 3708/*----------------------------------------------------------------------*/
3641/* 3709/*
3642 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3710 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3643 */ 3711 */
3644void 3712void
3645rxvt_term::process_dcs_seq () 3713rxvt_term::process_dcs_seq ()
3646{ 3714{
3647 unsigned char *s; 3715 char *s;
3648 unicode_t eh; 3716 unicode_t eh;
3649 3717
3650 /* 3718 /*
3651 * Not handled yet 3719 * Not handled yet
3652 */ 3720 */
3671 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3739 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3672 arg = arg * 10 + (ch - '0'); 3740 arg = arg * 10 + (ch - '0');
3673 3741
3674 if (ch == ';') 3742 if (ch == ';')
3675 { 3743 {
3676 unsigned char *s = get_to_st (eh); 3744 char *s = get_to_st (eh);
3677 3745
3678 if (s) 3746 if (s)
3679 { 3747 {
3680 process_xterm_seq (arg, (char *)s, eh); 3748 process_xterm_seq (arg, s, eh);
3681 free (s); 3749 free (s);
3682 } 3750 }
3683 } 3751 }
3684} 3752}
3685 3753
3686void 3754void
3687rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3755rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3688{ 3756{
3689 if (str[0] == '?' && !str[1]) 3757 if (str[0] == '?' && !str[1])
3690 { 3758 {
3691 unsigned short r, g, b; 3759 unsigned short r, g, b;
3692 pix_colors_focused[color].get (display, r, g, b); 3760 pix_colors_focused[color].get (display, r, g, b);
3698 3766
3699/* 3767/*
3700 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3768 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3701 */ 3769 */
3702void 3770void
3703rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3771rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3704{ 3772{
3705 int changed = 0;
3706 int color; 3773 int color;
3707 char *buf, *name; 3774 char *buf, *name;
3708 bool query = str[0] == '?' && !str[1]; 3775 bool query = str[0] == '?' && !str[1];
3709 int saveop = op; 3776 int saveop = op;
3710 dDisp; 3777 dDisp;
3765 { 3832 {
3766 if ((name = strchr (buf, ';')) == NULL) 3833 if ((name = strchr (buf, ';')) == NULL)
3767 break; 3834 break;
3768 3835
3769 *name++ = '\0'; 3836 *name++ = '\0';
3770 color = atoi (buf); 3837 color = atoi (buf) + minCOLOR;
3771 3838
3772 if (color < 0 || color >= TOTAL_COLORS) 3839 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3773 break; 3840 break;
3774 3841
3775 if ((buf = strchr (name, ';')) != NULL) 3842 if ((buf = strchr (name, ';')) != NULL)
3776 *buf++ = '\0'; 3843 *buf++ = '\0';
3777 3844
3778 if (name[0] == '?' && !name[1]) 3845 if (name[0] == '?' && !name[1])
3779 { 3846 {
3780 unsigned short r, g, b; 3847 unsigned short r, g, b;
3781 pix_colors_focused[color + minCOLOR].get (display, r, g, b); 3848 pix_colors_focused[color].get (display, r, g, b);
3782 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp); 3849 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3783 } 3850 }
3784 else 3851 else
3785 set_window_color (color + minCOLOR, name); 3852 set_window_color (color, name);
3786 } 3853 }
3787 break; 3854 break;
3788 case XTerm_Color00: 3855 case XTerm_Color00:
3789 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3856 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3790 break; 3857 break;
3791 case XTerm_Color01: 3858 case XTerm_Color01:
3792 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3859 process_color_seq (XTerm_Color01, Color_bg, str, resp);
3793 break; 3860 break;
3794#ifndef NO_CURSORCOLOR 3861#ifndef NO_CURSORCOLOR
3795 case XTerm_Color_cursor: 3862 case XTerm_Color_cursor:
3796 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3863 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3797 break; 3864 break;
3801 break; 3868 break;
3802 case XTerm_Color_pointer_bg: 3869 case XTerm_Color_pointer_bg:
3803 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3870 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3804 break; 3871 break;
3805#ifndef NO_BOLD_UNDERLINE_REVERSE 3872#ifndef NO_BOLD_UNDERLINE_REVERSE
3806 case XTerm_Color_BD:
3807 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3808 break;
3809 case XTerm_Color_UL:
3810 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3811 break;
3812 case XTerm_Color_RV: 3873 case XTerm_Color_RV:
3813 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3874 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3875 break;
3876 case Rxvt_Color_BD:
3877 case URxvt_Color_BD:
3878 process_color_seq (op, Color_BD, str, resp);
3879 break;
3880 case Rxvt_Color_UL:
3881 case URxvt_Color_UL:
3882 process_color_seq (op, Color_UL, str, resp);
3814 break; 3883 break;
3815 case URxvt_Color_IT: 3884 case URxvt_Color_IT:
3816 process_color_seq (URxvt_Color_IT, Color_IT, str, resp); 3885 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3817 break; 3886 break;
3818#endif 3887#endif
3823 if (am_transparent) 3892 if (am_transparent)
3824 want_full_refresh = want_refresh = 1; 3893 want_full_refresh = want_refresh = 1;
3825 break; 3894 break;
3826#endif 3895#endif
3827 3896
3828 case XTerm_Pixmap: 3897 case Rxvt_Pixmap:
3898 {
3829 if (*str != ';') 3899 if (*str != ';')
3830 { 3900 {
3831#if XPM_BACKGROUND 3901#if XPM_BACKGROUND
3832 scale_pixmap (""); /* reset to default scaling */ 3902 scale_pixmap (""); /* reset to default scaling */
3833 set_bgPixmap (str); /* change pixmap */ 3903 set_bgPixmap (str); /* change pixmap */
3834#endif
3835 scr_touch (true); 3904 scr_touch (true);
3905#endif
3836 } 3906 }
3907
3908 int changed = 0;
3909
3837 while ((str = strchr (str, ';')) != NULL) 3910 while ((str = strchr (str, ';')) != NULL)
3838 { 3911 {
3839 str++; 3912 str++;
3840#if XPM_BACKGROUND 3913#if XPM_BACKGROUND
3841 changed += scale_pixmap (str); 3914 changed += scale_pixmap (str);
3842#endif 3915#endif
3843 } 3916 }
3844 3917
3845 if (changed) 3918 if (changed)
3846 { 3919 {
3847#ifdef XPM_BACKGROUND 3920#ifdef XPM_BACKGROUND
3848 resize_pixmap (); 3921 resize_pixmap ();
3849#endif
3850 scr_touch (true); 3922 scr_touch (true);
3923#endif
3851 } 3924 }
3925 }
3852 break; 3926 break;
3853 3927
3854 case XTerm_restoreFG: 3928 case Rxvt_restoreFG:
3855 set_window_color (Color_fg, str); 3929 set_window_color (Color_fg, str);
3856 break; 3930 break;
3857 case XTerm_restoreBG: 3931 case Rxvt_restoreBG:
3858 set_window_color (Color_bg, str); 3932 set_window_color (Color_bg, str);
3859 break; 3933 break;
3860 3934
3861 case XTerm_logfile: 3935 case XTerm_logfile:
3862 // TODO, when secure mode? 3936 // TODO, when secure mode?
3863 break; 3937 break;
3864 3938
3865#ifdef MENUBAR
3866 case URxvt_Menu:
3867 if (options & Opt_insecure)
3868 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3869 break;
3870#endif
3871#if 0 3939#if 0
3872 case XTerm_dumpscreen: /* no error notices */ 3940 case Rxvt_dumpscreen: /* no error notices */
3873 { 3941 {
3874 int fd; 3942 int fd;
3875 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3943 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3876 { 3944 {
3877 scr_dump (fd); 3945 scr_dump (fd);
3888 case URxvt_italicFont: 3956 case URxvt_italicFont:
3889 case URxvt_boldItalicFont: 3957 case URxvt_boldItalicFont:
3890#endif 3958#endif
3891 if (query) 3959 if (query)
3892 tt_printf ("\33]%d;%-.250s%c", saveop, 3960 tt_printf ("\33]%d;%-.250s%c", saveop,
3893 (options & Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3961 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3894 ? fontset[op - URxvt_font]->fontdesc : "", 3962 ? fontset[op - URxvt_font]->fontdesc : "",
3895 resp); 3963 resp);
3896 else 3964 else
3897 { 3965 {
3898 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3966 const char *&res = rs[Rs_font + (op - URxvt_font)];
3904 break; 3972 break;
3905 3973
3906#if ENABLE_FRILLS 3974#if ENABLE_FRILLS
3907 case URxvt_locale: 3975 case URxvt_locale:
3908 if (query) 3976 if (query)
3909 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp); 3977 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp);
3910 else 3978 else
3911 { 3979 {
3912 set_locale (str); 3980 set_locale (str);
3913 pty.set_utf8_mode (enc_utf8); 3981 pty->set_utf8_mode (enc_utf8);
3914 init_xlocale (); 3982 init_xlocale ();
3915 } 3983 }
3916 break; 3984 break;
3917 3985
3918 case URxvt_view_up: 3986 case URxvt_view_up:
3919 case URxvt_view_down: 3987 case URxvt_view_down:
3988 {
3920 int lines = atoi (str); 3989 int lines = atoi (str);
3921 3990
3922 if (lines) 3991 if (lines)
3923 scr_page (op == URxvt_view_up ? UP : DN, lines); 3992 scr_page (op == URxvt_view_up ? UP : DN, lines);
3924 else 3993 else
3925 {
3926 scr_erase_savelines (); 3994 scr_erase_savelines ();
3927 } 3995 }
3928 3996
3997 break;
3998#endif
3999
4000#if ENABLE_PERL
4001 case URxvt_perl:
4002 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END)))
4003 ; // no responses yet
3929 break; 4004 break;
3930#endif 4005#endif
3931 } 4006 }
3932} 4007}
3933/*----------------------------------------------------------------------*/ 4008/*----------------------------------------------------------------------*/
3964 return state; 4039 return state;
3965} 4040}
3966 4041
3967/* we're not using priv _yet_ */ 4042/* we're not using priv _yet_ */
3968void 4043void
3969rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 4044rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3970{ 4045{
3971 unsigned int i, j; 4046 unsigned int i, j;
3972 int state; 4047 int state;
3973 4048
3974 static const struct 4049 static const struct
3985 { 5, PrivMode_rVideo }, 4060 { 5, PrivMode_rVideo },
3986 { 6, PrivMode_relOrigin }, 4061 { 6, PrivMode_relOrigin },
3987 { 7, PrivMode_Autowrap }, 4062 { 7, PrivMode_Autowrap },
3988 // 8, bi-directional support mode 4063 // 8, bi-directional support mode
3989 { 9, PrivMode_MouseX10 }, 4064 { 9, PrivMode_MouseX10 },
3990#ifdef menuBar_esc
3991 { menuBar_esc, PrivMode_menuBar },
3992#endif
3993 // 18, 19 printing-related 4065 // 18, 19 printing-related
3994 { 25, PrivMode_VisibleCursor }, 4066 { 25, PrivMode_VisibleCursor },
3995#ifdef scrollBar_esc 4067#ifdef scrollBar_esc
3996 { scrollBar_esc, PrivMode_scrollBar }, 4068 { scrollBar_esc, PrivMode_scrollBar },
3997#endif 4069#endif
4042 } 4114 }
4043 4115
4044 /* extra handling for values with state unkept */ 4116 /* extra handling for values with state unkept */
4045 switch (arg[i]) 4117 switch (arg[i])
4046 { 4118 {
4119#if ENABLE_STYLES
4120 case 1021:
4121 set_option (Opt_intensityStyles, mode);
4122
4123 scr_touch (true);
4124 break;
4125#endif
4047 case 1048: /* alternative cursor save */ 4126 case 1048: /* alternative cursor save */
4048 case 1049: 4127 case 1049:
4049 if (options & Opt_secondaryScreen) 4128 if (OPTION (Opt_secondaryScreen))
4050 if (mode == 0) 4129 if (mode == 0)
4051 scr_cursor (RESTORE); 4130 scr_cursor (RESTORE);
4052 else if (mode == 1) 4131 else if (mode == 1)
4053 scr_cursor (SAVE); 4132 scr_cursor (SAVE);
4054 break; 4133 break;
4069 case 3: /* 80/132 */ 4148 case 3: /* 80/132 */
4070 if (priv_modes & PrivMode_132OK) 4149 if (priv_modes & PrivMode_132OK)
4071 set_widthheight (((state ? 132 : 80) * fwidth), height); 4150 set_widthheight (((state ? 132 : 80) * fwidth), height);
4072 break; 4151 break;
4073 case 4: /* smooth scrolling */ 4152 case 4: /* smooth scrolling */
4074 if (state)
4075 options &= ~Opt_jumpScroll;
4076 else
4077 options |= Opt_jumpScroll; 4153 set_option (Opt_jumpScroll, !state);
4078 break; 4154 break;
4079 case 5: /* reverse video */ 4155 case 5: /* reverse video */
4080 scr_rvideo_mode (state); 4156 scr_rvideo_mode (state);
4081 break; 4157 break;
4082 case 6: /* relative/absolute origins */ 4158 case 6: /* relative/absolute origins */
4088 /* case 8: - auto repeat, can't do on a per window basis */ 4164 /* case 8: - auto repeat, can't do on a per window basis */
4089 case 9: /* X10 mouse reporting */ 4165 case 9: /* X10 mouse reporting */
4090 if (state) /* orthogonal */ 4166 if (state) /* orthogonal */
4091 priv_modes &= ~PrivMode_MouseX11; 4167 priv_modes &= ~PrivMode_MouseX11;
4092 break; 4168 break;
4093#ifdef menuBar_esc
4094 case menuBar_esc:
4095#ifdef MENUBAR
4096 map_menuBar (state);
4097#endif
4098 break;
4099#endif
4100#ifdef scrollBar_esc 4169#ifdef scrollBar_esc
4101 case scrollBar_esc: 4170 case scrollBar_esc:
4102 if (scrollbar_mapping (state)) 4171 if (scrollbar_mapping (state))
4103 { 4172 {
4104 resize_all_windows (0, 0, 0); 4173 resize_all_windows (0, 0, 0);
4123#if 0 4192#if 0
4124 case 1001: 4193 case 1001:
4125 break; /* X11 mouse highlighting */ 4194 break; /* X11 mouse highlighting */
4126#endif 4195#endif
4127 case 1010: /* scroll to bottom on TTY output inhibit */ 4196 case 1010: /* scroll to bottom on TTY output inhibit */
4128 if (state)
4129 options &= ~Opt_scrollTtyOutput;
4130 else
4131 options |= Opt_scrollTtyOutput; 4197 set_option (Opt_scrollTtyOutput, !state);
4132 break; 4198 break;
4133 case 1011: /* scroll to bottom on key press */ 4199 case 1011: /* scroll to bottom on key press */
4134 if (state)
4135 options |= Opt_scrollTtyKeypress; 4200 set_option (Opt_scrollTtyKeypress, state);
4136 else
4137 options &= ~Opt_scrollTtyKeypress;
4138 break; 4201 break;
4139 case 1047: /* secondary screen w/ clearing last */ 4202 case 1047: /* secondary screen w/ clearing last */
4140 if (options & Opt_secondaryScreen) 4203 if (OPTION (Opt_secondaryScreen))
4141 if (current_screen != PRIMARY) 4204 if (current_screen != PRIMARY)
4142 scr_erase_screen (2); 4205 scr_erase_screen (2);
4143 scr_change_screen (state); 4206 scr_change_screen (state);
4144 break; 4207 break;
4145 case 1049: /* secondary screen w/ clearing first */ 4208 case 1049: /* secondary screen w/ clearing first */
4146 scr_change_screen (state); 4209 scr_change_screen (state);
4147 if (options & Opt_secondaryScreen) 4210 if (OPTION (Opt_secondaryScreen))
4148 if (current_screen != PRIMARY) 4211 if (current_screen != PRIMARY)
4149 scr_erase_screen (2); 4212 scr_erase_screen (2);
4150 break; 4213 break;
4151 default: 4214 default:
4152 break; 4215 break;
4280 scr_color (Color_bg, Color_bg); 4343 scr_color (Color_bg, Color_bg);
4281 break; 4344 break;
4282 4345
4283 //case 50: // not variable spacing 4346 //case 50: // not variable spacing
4284 4347
4285#ifndef NO_BRIGHTCOLOR 4348#if ENABLE_FRILLS
4286 case 90: 4349 case 90:
4287 case 91: /* set bright fg color */ 4350 case 91: /* set bright fg color */
4288 case 92: 4351 case 92:
4289 case 93: 4352 case 93:
4290 case 94: 4353 case 94:
4302 case 106: 4365 case 106:
4303 case 107: 4366 case 107:
4304 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 4367 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4305 break; 4368 break;
4306#endif 4369#endif
4307
4308 } 4370 }
4309 } 4371 }
4310} 4372}
4311/*}}} */ 4373/*}}} */
4312 4374
4336 */ 4398 */
4337void 4399void
4338rxvt_term::tt_printf (const char *fmt,...) 4400rxvt_term::tt_printf (const char *fmt,...)
4339{ 4401{
4340 va_list arg_ptr; 4402 va_list arg_ptr;
4341 unsigned char buf[256]; 4403 char buf[256];
4342 4404
4343 va_start (arg_ptr, fmt); 4405 va_start (arg_ptr, fmt);
4344 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 4406 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4345 va_end (arg_ptr); 4407 va_end (arg_ptr);
4346 tt_write (buf, strlen (buf)); 4408 tt_write (buf, strlen (buf));
4351 * or generated by us in response to a query ESC sequence. 4413 * or generated by us in response to a query ESC sequence.
4352 */ 4414 */
4353const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4415const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4354 4416
4355void 4417void
4356rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4418rxvt_term::tt_write (const char *data, unsigned int len)
4357{ 4419{
4420 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
4421 return;
4422
4423 if (pty->pty < 0)
4424 return;
4425
4358 if (v_buflen == 0) 4426 if (v_buflen == 0)
4359 { 4427 {
4360 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 4428 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4361 4429
4362 if ((unsigned int)written == len) 4430 if ((unsigned int)written == len)
4363 return; 4431 return;
4364 4432
4365 data += written; 4433 data += written;
4366 len -= written; 4434 len -= written;
4367 } 4435 }
4368 4436
4369 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4437 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4370 4438
4371 memcpy (v_buffer + v_buflen, data, len); 4439 memcpy (v_buffer + v_buflen, data, len);
4372 v_buflen += len; 4440 v_buflen += len;
4373 4441
4374 pty_ev.set (EVENT_READ | EVENT_WRITE); 4442 pty_ev.set (EVENT_READ | EVENT_WRITE);
4375} 4443}
4376 4444
4377void rxvt_term::pty_write () 4445void rxvt_term::pty_write ()
4378{ 4446{
4379 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4447 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4380 4448
4381 if (written > 0) 4449 if (written > 0)
4382 { 4450 {
4383 v_buflen -= written; 4451 v_buflen -= written;
4384 4452

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines