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.215 by root, Fri Dec 23 14:46:34 2005 UTC vs.
Revision 1.274 by root, Fri Jan 20 10:27:08 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;
187 len = 1; 188 len = 1;
188 } 189 }
189 190
191 char attr[80]; // plenty
192
193 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
194 (int)r,
195 fgcolor_of (r), bgcolor_of (r),
196 r & RS_Bold ? " bold" : "",
197 r & RS_Italic ? " italic" : "",
198 r & RS_Blink ? " blink" : "",
199 r & RS_RVid ? " rvid" : "",
200 r & RS_Uline ? " uline" : "",
201 r & RS_Careful ? " careful" : "");
202
190 int width = wcswidth (fname, wcslen (fname)); 203 int width = wcswidth (fname, wcslen (fname));
191 204
192 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1); 205 max_it (width, 8+5); // for char + hey
206 max_it (width, strlen (attr));
207
208 if (y >= 0)
209 {
210 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
211 x = 0;
212 }
213
214 scr_overlay_new (x, y, width, len + 2);
193 215
194 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 216 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
195 217
196 for (int y = 0; y < len; y++) 218 for (int y = 0; y < len; y++)
197 { 219 {
200 ch = *chr++; 222 ch = *chr++;
201 223
202 sprintf (buf, "%8x", ch); 224 sprintf (buf, "%8x", ch);
203 scr_overlay_set (0, y, buf); 225 scr_overlay_set (0, y, buf);
204 scr_overlay_set (9, y, '='); 226 scr_overlay_set (9, y, '=');
205#if !UNICODE3 227# if !UNICODE3
206 if (ch >= 0x10000) 228 if (ch >= 0x10000)
207 ch = 0xfffd; 229 ch = 0xfffd;
208#endif 230# endif
209 scr_overlay_set (11, y, ch, r); 231 scr_overlay_set (11, y, ch, r);
210 scr_overlay_set (12, y, NOCHAR, r); 232 scr_overlay_set (12, y, NOCHAR, r);
211 } 233 }
212 234
235 scr_overlay_set (0, len , attr);
213 scr_overlay_set (0, len, fname); 236 scr_overlay_set (0, len + 1, fname);
214 237
215 free (fname); 238 free (fname);
216 239
217#if ENABLE_COMBINING 240# if ENABLE_COMBINING
218 if (alloc) 241 if (alloc)
219 delete [] alloc; 242 delete [] alloc;
220#endif 243# endif
221} 244}
222#endif 245#endif
223 246
224void 247void
225rxvt_term::commit_iso14755 () 248rxvt_term::commit_iso14755 ()
242 mb[0] = ch[0]; 265 mb[0] = ch[0];
243 len = 1; 266 len = 1;
244 } 267 }
245 268
246 if (len > 0) 269 if (len > 0)
247 tt_write ((unsigned char *)mb, len); 270 tt_write (mb, len);
248 else 271 else
249 scr_bell (); 272 scr_bell ();
250 } 273 }
251 274
252 iso14755buf = 0; 275 iso14755buf = 0;
280 KeySym keysym; 303 KeySym keysym;
281#ifdef DEBUG_CMD 304#ifdef DEBUG_CMD
282 static int debug_key = 1; /* accessible by a debugger only */ 305 static int debug_key = 1; /* accessible by a debugger only */
283#endif 306#endif
284 int valid_keysym; 307 int valid_keysym;
285 unsigned char kbuf[KBUFSZ]; 308 char kbuf[KBUFSZ];
286 309
287 /* 310 /*
288 * 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
289 * escape sequence to toggle the Keypad. 312 * escape sequence to toggle the Keypad.
290 * 313 *
308 Status status_return; 331 Status status_return;
309 332
310#if 0 333#if 0
311#ifdef X_HAVE_UTF8_STRING 334#ifdef X_HAVE_UTF8_STRING
312 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
313 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 336 len = Xutf8LookupString (Input_Context, &ev, kbuf,
314 KBUFSZ, &keysym, &status_return); 337 KBUFSZ, &keysym, &status_return);
315 else 338 else
316#endif 339#endif
317#endif 340#endif
318 { 341 {
355 || status_return == XLookupBoth; 378 || status_return == XLookupBoth;
356 } 379 }
357 else 380 else
358#endif 381#endif
359 { 382 {
360 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); 383 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
361 valid_keysym = keysym != NoSymbol; 384 valid_keysym = keysym != NoSymbol;
362 } 385 }
363 386
364 if (valid_keysym) 387 if (valid_keysym)
365 { 388 {
417 scr_move_to (0, 1); 440 scr_move_to (0, 1);
418 return; 441 return;
419 } 442 }
420 else if (keysym == XK_End) 443 else if (keysym == XK_End)
421 { 444 {
422 scr_move_to (1, 0); 445 scr_move_to (1, 1);
423 return; 446 return;
424 } 447 }
425 } 448 }
426#endif 449#endif
427 } 450 }
438 { 461 {
439 switch (keysym) 462 switch (keysym)
440 { 463 {
441 /* normal XTerm key bindings */ 464 /* normal XTerm key bindings */
442 case XK_Insert: /* Shift+Insert = paste mouse selection */ 465 case XK_Insert: /* Shift+Insert = paste mouse selection */
443 selection_request (ev.time, 0, 0); 466 selection_request (ev.time, Sel_Primary);
444 return; 467 return;
445#if TODO 468#if TODO
446 /* rxvt extras */ 469 /* rxvt extras */
447 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 470 case XK_KP_Add: /* Shift+KP_Add = bigger font */
448 change_font (FONT_UP); 471 change_font (FONT_UP);
829 { 852 {
830#ifdef META8_OPTION 853#ifdef META8_OPTION
831 /* set 8-bit on */ 854 /* set 8-bit on */
832 if (meta && (meta_char == 0x80)) 855 if (meta && (meta_char == 0x80))
833 { 856 {
834 unsigned char *ch; 857 char *ch;
835 858
836 for (ch = kbuf; ch < kbuf + len; ch++) 859 for (ch = kbuf; ch < kbuf + len; ch++)
837 *ch |= 0x80; 860 *ch |= 0x80;
838 861
839 meta = 0; 862 meta = 0;
841#endif 864#endif
842 /* nil */ ; 865 /* nil */ ;
843 } 866 }
844 } 867 }
845 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
846 if (len <= 0) 872 if (len <= 0)
847 return; /* not mapped */ 873 return; /* not mapped */
848 874
849 if (options & Opt_scrollTtyKeypress) 875 if (OPTION (Opt_scrollTtyKeypress))
850 if (view_start) 876 if (view_start)
851 { 877 {
852 view_start = 0; 878 view_start = 0;
853 want_refresh = 1; 879 want_refresh = 1;
854 } 880 }
872#ifdef META8_OPTION 898#ifdef META8_OPTION
873 && meta_char == C0_ESC 899 && meta_char == C0_ESC
874#endif 900#endif
875 ) 901 )
876 { 902 {
877 const unsigned char ch = C0_ESC; 903 const char ch = C0_ESC;
878 tt_write (&ch, 1); 904 tt_write (&ch, 1);
879 } 905 }
880 906
881#if defined(DEBUG_CMD) 907#if defined(DEBUG_CMD)
882 /* Display keyboard buffer contents */ 908 /* Display keyboard buffer contents */
890#endif /* DEBUG_CMD */ 916#endif /* DEBUG_CMD */
891 tt_write (kbuf, (unsigned int)len); 917 tt_write (kbuf, (unsigned int)len);
892} 918}
893/*}}} */ 919/*}}} */
894 920
895#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) 921#if defined (KEYSYM_RESOURCE)
896/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
897/* attempt to `write' count to the input buffer */
898unsigned int 922unsigned int
899rxvt_term::cmd_write (const unsigned char *str, unsigned int count) 923rxvt_term::cmd_write (const char *str, unsigned int count)
900{ 924{
901 unsigned int n, s; 925 unsigned int n, s;
902 926
903 n = cmdbuf_ptr - cmdbuf_base; 927 n = cmdbuf_ptr - cmdbuf_base;
904 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; 928 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
941 } 965 }
942#endif 966#endif
943 967
944 if (want_refresh) 968 if (want_refresh)
945 { 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
946 scr_refresh (refresh_type); 1008 scr_refresh ();
947 scrollbar_show (1); 1009 scrollbar_show (1);
948#ifdef USE_XIM 1010#ifdef USE_XIM
949 IMSendSpot (); 1011 IMSendSpot ();
950#endif 1012#endif
951 } 1013 }
954} 1016}
955 1017
956void 1018void
957rxvt_term::check_cb (check_watcher &w) 1019rxvt_term::check_cb (check_watcher &w)
958{ 1020{
959 SET_R (this); 1021 make_current ();
960 SET_LOCALE (locale);
961 1022
962 display->flush (); 1023 display->flush ();
963 1024
964 if (want_refresh && !flush_ev.active) 1025 if (want_refresh && !flush_ev.active)
965 flush_ev.start (NOW + 0.01); 1026 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
966} 1027}
967 1028
968void 1029void
969rxvt_term::flush_cb (time_watcher &w) 1030rxvt_term::flush_cb (time_watcher &w)
970{ 1031{
971 SET_R (this); 1032 make_current ();
972 SET_LOCALE (locale);
973 1033
974 refresh_limit = 1; 1034 refresh_limit = 1;
975 refresh_count = 0; 1035 refresh_count = 0;
976 flush (); 1036 flush ();
977} 1037}
981rxvt_term::cursor_blink_cb (time_watcher &w) 1041rxvt_term::cursor_blink_cb (time_watcher &w)
982{ 1042{
983 hidden_cursor = !hidden_cursor; 1043 hidden_cursor = !hidden_cursor;
984 want_refresh = 1; 1044 want_refresh = 1;
985 1045
986 w.start (w.at + BLINK_INTERVAL); 1046 w.start (w.at + CURSOR_BLINK_INTERVAL);
987} 1047}
988#endif 1048#endif
989 1049
990#ifdef TEXT_BLINK 1050#ifdef TEXT_BLINK
991void 1051void
1005rxvt_term::cont_scroll_cb (time_watcher &w) 1065rxvt_term::cont_scroll_cb (time_watcher &w)
1006{ 1066{
1007 if ((scrollbar_isUp() || scrollbar_isDn()) && 1067 if ((scrollbar_isUp() || scrollbar_isDn()) &&
1008 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1068 scr_page (scrollbar_isUp() ? UP : DN, 1))
1009 { 1069 {
1010 refresh_type |= SMOOTH_REFRESH;
1011 want_refresh = 1; 1070 want_refresh = 1;
1012 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1071 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1013 } 1072 }
1014} 1073}
1015#endif 1074#endif
1019rxvt_term::sel_scroll_cb (time_watcher &w) 1078rxvt_term::sel_scroll_cb (time_watcher &w)
1020{ 1079{
1021 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1080 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1022 { 1081 {
1023 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1082 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1024 refresh_type |= SMOOTH_REFRESH;
1025 want_refresh = 1; 1083 want_refresh = 1;
1026 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1084 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1027 } 1085 }
1028} 1086}
1029#endif 1087#endif
1034{ 1092{
1035 if (mouse_slip_wheel_speed == 0 1093 if (mouse_slip_wheel_speed == 0
1036 || 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)
1037 : scr_page (UP, mouse_slip_wheel_speed)) 1095 : scr_page (UP, mouse_slip_wheel_speed))
1038 { 1096 {
1039 if (view_start == nsaved || 1097 if (view_start == top_row || view_start == 0)
1040 view_start == 0)
1041 mouse_slip_wheel_speed = 0; 1098 mouse_slip_wheel_speed = 0;
1042 1099
1043 refresh_type |= SMOOTH_REFRESH;
1044 want_refresh = 1; 1100 want_refresh = 1;
1045 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1101 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY);
1046 } 1102 }
1047} 1103}
1048#endif 1104#endif
1049 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
1050bool 1124bool
1051rxvt_term::pty_fill () 1125rxvt_term::pty_fill ()
1052{ 1126{
1053 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1127 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
1054 1128
1055 if (CBUFSIZ == n) 1129 if (CBUFSIZ == n)
1056 { 1130 {
1057 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");
1058 n = 0; 1132 n = 0;
1059 } 1133 }
1060 1134
1061 memmove (cmdbuf_base, cmdbuf_ptr, n); 1135 memmove (cmdbuf_base, cmdbuf_ptr, n);
1062 cmdbuf_ptr = cmdbuf_base; 1136 cmdbuf_ptr = cmdbuf_base;
1063 cmdbuf_endp = cmdbuf_ptr + n; 1137 cmdbuf_endp = cmdbuf_ptr + n;
1064 1138
1065 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1139 ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n);
1066 1140
1067 if (n > 0) 1141 if (r > 0)
1068 { 1142 {
1069 cmdbuf_endp += n; 1143 cmdbuf_endp += r;
1070 return true; 1144 return true;
1071 } 1145 }
1072 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
1073 { 1154 {
1074 pty_ev.stop (); 1155 pty_ev.stop ();
1075 1156
1076 if (!(options & Opt_hold)) 1157 if (!OPTION (Opt_hold))
1077 destroy (); 1158 destroy ();
1078 } 1159 }
1079 1160
1080 return false; 1161 return false;
1081} 1162}
1082 1163
1083void 1164void
1084rxvt_term::pty_cb (io_watcher &w, short revents) 1165rxvt_term::pty_cb (io_watcher &w, short revents)
1085{ 1166{
1086 SET_R (this); 1167 make_current ();
1087 SET_LOCALE (locale);
1088 1168
1089 if (revents & EVENT_READ) 1169 if (revents & EVENT_READ)
1090 // loop, but don't allow a single term to monopolize us 1170 // loop, but don't allow a single term to monopolize us
1091 while (pty_fill ()) 1171 while (pty_fill ())
1092 if (cmd_parse ()) 1172 if (cmd_parse ())
1103 recolour_cursor (); 1183 recolour_cursor ();
1104 1184
1105#ifdef POINTER_BLANK 1185#ifdef POINTER_BLANK
1106 hidden_pointer = 0; 1186 hidden_pointer = 0;
1107 1187
1108 if (options & Opt_pointerBlank) 1188 if (OPTION (Opt_pointerBlank))
1109 pointer_ev.start (NOW + pointerBlankDelay); 1189 pointer_ev.start (NOW + pointerBlankDelay);
1110#endif 1190#endif
1111} 1191}
1112 1192
1113#ifdef POINTER_BLANK 1193#ifdef POINTER_BLANK
1114void 1194void
1115rxvt_term::pointer_blank () 1195rxvt_term::pointer_blank ()
1116{ 1196{
1117 if (! (options & Opt_pointerBlank)) 1197 if (!OPTION (Opt_pointerBlank))
1118 return; 1198 return;
1119 1199
1120 XDefineCursor (display->display, vt, display->blank_cursor); 1200 XDefineCursor (display->display, vt, display->blank_cursor);
1121 XFlush (display->display); 1201 XFlush (display->display);
1122 1202
1124} 1204}
1125 1205
1126void 1206void
1127rxvt_term::pointer_cb (time_watcher &w) 1207rxvt_term::pointer_cb (time_watcher &w)
1128{ 1208{
1129 SET_R (this); 1209 make_current ();
1130 SET_LOCALE (locale);
1131 1210
1132 pointer_blank (); 1211 pointer_blank ();
1133} 1212}
1134#endif 1213#endif
1135 1214
1214 1293
1215/*{{{ process an X event */ 1294/*{{{ process an X event */
1216void 1295void
1217rxvt_term::x_cb (XEvent &ev) 1296rxvt_term::x_cb (XEvent &ev)
1218{ 1297{
1298 make_current ();
1299
1219 dDisp; 1300 dDisp;
1220 1301
1221 SET_R (this); 1302 if (ev.xany.window == vt
1222 SET_LOCALE (locale); 1303 && SHOULD_INVOKE (HOOK_X_EVENT)
1304 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1305 return;
1223 1306
1224#if defined(CURSOR_BLINK) 1307 // for XQueryPointer
1225 if ((options & Opt_cursorBlink) && ev.type == KeyPress)
1226 {
1227 if (hidden_cursor)
1228 {
1229 hidden_cursor = 0;
1230 want_refresh = 1;
1231 }
1232
1233 cursor_blink_ev.start (NOW + BLINK_INTERVAL);
1234 }
1235#endif
1236
1237#if defined(POINTER_BLANK)
1238 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1239 {
1240 if (ev.type == MotionNotify
1241 || ev.type == ButtonPress
1242 || ev.type == ButtonRelease)
1243 if (hidden_pointer)
1244 pointer_unblank ();
1245
1246 if (ev.type == KeyPress && hidden_pointer == 0)
1247 pointer_blank ();
1248 }
1249#endif
1250
1251 Window unused_root, unused_child; 1308 Window unused_root, unused_child;
1252 int unused_root_x, unused_root_y; 1309 int unused_root_x, unused_root_y;
1253 unsigned int unused_mask; 1310 unsigned int unused_mask;
1254 1311
1255 switch (ev.type) 1312 switch (ev.type)
1262 1319
1263 break; 1320 break;
1264 1321
1265 case KeyRelease: 1322 case KeyRelease:
1266 { 1323 {
1267#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 1324#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1268 KeySym ks; 1325 KeySym keysym;
1269 1326
1270 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 :/
1271#endif 1328#endif
1272 1329
1273#if ENABLE_FRILLS || ISO_14755 1330#if ENABLE_FRILLS || ISO_14755
1274 // ISO 14755 support 1331 // ISO 14755 support
1275 if (iso14755buf) 1332 if (iso14755buf)
1280# endif 1337# endif
1281# if ISO_14755 1338# if ISO_14755
1282 // iso14755 part 5.2 handling: release time 1339 // iso14755 part 5.2 handling: release time
1283 // first: controls 1340 // first: controls
1284 if ((ev.xkey.state & ControlMask) 1341 if ((ev.xkey.state & ControlMask)
1285 && ((ks >= 0x40 && ks <= 0x5f) 1342 && ((keysym >= 0x40 && keysym <= 0x5f)
1286 || (ks >= 0x61 && ks <= 0x7f))) 1343 || (keysym >= 0x61 && keysym <= 0x7f)))
1287 { 1344 {
1288 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f); 1345 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1289 commit_iso14755 (); 1346 commit_iso14755 ();
1290 return; // case-break; 1347 goto skip_switch;
1291 } 1348 }
1292 1349
1293 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) 1350 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1294 if (i[0] == ks) 1351 if (i[0] == keysym)
1295 { 1352 {
1296 iso14755buf = ISO_14755_51 | i[1]; 1353 iso14755buf = ISO_14755_51 | i[1];
1297 commit_iso14755 (); 1354 commit_iso14755 ();
1298 return; // case-break; 1355 goto skip_switch;
1299 } 1356 }
1300 1357
1301 scr_bell (); 1358 scr_bell ();
1302# endif 1359# endif
1303 iso14755buf = 0; 1360 iso14755buf = 0;
1322 else 1379 else
1323 iso14755buf = 0; 1380 iso14755buf = 0;
1324 } 1381 }
1325#endif 1382#endif
1326 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
1327#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1388#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1328 if (!(ev.xkey.state & ControlMask)) 1389 if (!(ev.xkey.state & ControlMask))
1329 slip_wheel_ev.stop (); 1390 slip_wheel_ev.stop ();
1330 else if (ks == XK_Control_L || ks == XK_Control_R) 1391 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1331 mouse_slip_wheel_speed = 0; 1392 mouse_slip_wheel_speed = 0;
1332#endif 1393#endif
1333 break; 1394 break;
1334 } 1395 }
1335 1396
1438 { 1499 {
1439 seen_resize = 1; 1500 seen_resize = 1;
1440 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1501 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1441 } 1502 }
1442 1503
1504 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1505
1443#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1506#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1444 if (options & Opt_transparent) 1507 if (OPTION (Opt_transparent))
1445 check_our_parents (); 1508 check_our_parents ();
1446#endif 1509#endif
1447 } 1510 }
1448 break; 1511 break;
1449 1512
1465 1528
1466 case SelectionRequest: 1529 case SelectionRequest:
1467 selection_send (ev.xselectionrequest); 1530 selection_send (ev.xselectionrequest);
1468 break; 1531 break;
1469 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
1470 case UnmapNotify: 1541 case UnmapNotify:
1471 mapped = 0; 1542 mapped = 0;
1472#ifdef TEXT_BLINK 1543#ifdef TEXT_BLINK
1473 text_blink_ev.stop (); 1544 text_blink_ev.stop ();
1474#endif 1545#endif
1475 break; 1546 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1476
1477 case MapNotify:
1478 mapped = 1;
1479#ifdef TEXT_BLINK
1480 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1481#endif
1482 break; 1547 break;
1483 1548
1484#ifdef TRANSPARENT 1549#ifdef TRANSPARENT
1485 case ReparentNotify: 1550 case ReparentNotify:
1486 rootwin_cb (ev); 1551 rootwin_cb (ev);
1500 1565
1501 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) 1566 while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev))
1502 scr_expose (ev.xexpose.x, ev.xexpose.y, 1567 scr_expose (ev.xexpose.x, ev.xexpose.y,
1503 ev.xexpose.width, ev.xexpose.height, False); 1568 ev.xexpose.width, ev.xexpose.height, False);
1504 1569
1505 scr_refresh (refresh_type); 1570 want_refresh = 1;
1506 } 1571 }
1507 else 1572 else
1508 { 1573 {
1509 XEvent unused_event; 1574 XEvent unused_event;
1510 1575
1516 if (isScrollbarWindow (ev.xany.window)) 1581 if (isScrollbarWindow (ev.xany.window))
1517 { 1582 {
1518 scrollBar.setIdle (); 1583 scrollBar.setIdle ();
1519 scrollbar_show (0); 1584 scrollbar_show (0);
1520 } 1585 }
1521#ifdef MENUBAR
1522 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1523 menubar_expose ();
1524#endif
1525 1586
1526#ifdef TRANSPARENT 1587#ifdef TRANSPARENT
1527 if (am_transparent && ev.xany.window == parent[0]) 1588 if (am_transparent && ev.xany.window == parent[0])
1528 XClearWindow (disp, ev.xany.window); 1589 XClearWindow (disp, ev.xany.window);
1529#endif 1590#endif
1533 case MotionNotify: 1594 case MotionNotify:
1534#ifdef POINTER_BLANK 1595#ifdef POINTER_BLANK
1535 if (hidden_pointer) 1596 if (hidden_pointer)
1536 pointer_unblank (); 1597 pointer_unblank ();
1537#endif 1598#endif
1538#if MENUBAR
1539 if (isMenuBarWindow (ev.xany.window))
1540 {
1541 menubar_control (ev.xbutton);
1542 break;
1543 }
1544#endif
1545 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1599 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1546 break; 1600 break;
1547 1601
1548 if (ev.xany.window == vt) 1602 if (ev.xany.window == vt)
1549 { 1603 {
1604 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1605 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1606 ; // nop
1550 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1607 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1551 { 1608 {
1552 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) 1609 while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev))
1553 ; 1610 ;
1554 1611
1555 XQueryPointer (disp, vt, 1612 XQueryPointer (disp, vt,
1635 &unused_root_x, &unused_root_y, 1692 &unused_root_x, &unused_root_y,
1636 &ev.xbutton.x, &ev.xbutton.y, 1693 &ev.xbutton.x, &ev.xbutton.y,
1637 &unused_mask); 1694 &unused_mask);
1638 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1695 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1639 scrollbar_size ()); 1696 scrollbar_size ());
1640 scr_refresh (refresh_type); 1697 want_refresh = 1;
1641 refresh_limit = 0; 1698 refresh_limit = 0;
1642 scrollbar_show (1); 1699 scrollbar_show (1);
1643 } 1700 }
1644 break; 1701 break;
1645 } 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
1646} 1732}
1647 1733
1648void 1734void
1649rxvt_term::focus_in () 1735rxvt_term::focus_in ()
1650{ 1736{
1651 if (!focus) 1737 if (!focus)
1652 { 1738 {
1653 focus = 1; 1739 focus = 1;
1654 want_refresh = 1; 1740 want_refresh = 1;
1741
1742 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1743
1655#if USE_XIM 1744#if USE_XIM
1656 if (Input_Context != NULL) 1745 if (Input_Context != NULL)
1657 { 1746 {
1658 IMSetStatusPosition (); 1747 IMSetStatusPosition ();
1659 XSetICFocus (Input_Context); 1748 XSetICFocus (Input_Context);
1660 } 1749 }
1661#endif 1750#endif
1662#if CURSOR_BLINK 1751#if CURSOR_BLINK
1663 if (options & Opt_cursorBlink) 1752 if (OPTION (Opt_cursorBlink))
1664 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1753 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL);
1665#endif 1754#endif
1666#if OFF_FOCUS_FADING 1755#if OFF_FOCUS_FADING
1667 if (rs[Rs_fade]) 1756 if (rs[Rs_fade])
1668 { 1757 {
1669 pix_colors = pix_colors_focused; 1758 pix_colors = pix_colors_focused;
1679 if (focus) 1768 if (focus)
1680 { 1769 {
1681 focus = 0; 1770 focus = 0;
1682 want_refresh = 1; 1771 want_refresh = 1;
1683 1772
1773 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1774
1684#if ENABLE_FRILLS || ISO_14755 1775#if ENABLE_FRILLS || ISO_14755
1776 if (iso14755buf)
1777 {
1685 iso14755buf = 0; 1778 iso14755buf = 0;
1686#endif
1687#if ENABLE_OVERLAY 1779# if ENABLE_OVERLAY
1688 scr_overlay_off (); 1780 scr_overlay_off ();
1781# endif
1782 }
1689#endif 1783#endif
1690#if USE_XIM 1784#if USE_XIM
1691 if (Input_Context != NULL) 1785 if (Input_Context != NULL)
1692 XUnsetICFocus (Input_Context); 1786 XUnsetICFocus (Input_Context);
1693#endif 1787#endif
1694#if CURSOR_BLINK 1788#if CURSOR_BLINK
1695 if (options & Opt_cursorBlink) 1789 if (OPTION (Opt_cursorBlink))
1696 cursor_blink_ev.stop (); 1790 cursor_blink_ev.stop ();
1697 hidden_cursor = 0; 1791 hidden_cursor = 0;
1698#endif 1792#endif
1699#if OFF_FOCUS_FADING 1793#if OFF_FOCUS_FADING
1700 if (rs[Rs_fade]) 1794 if (rs[Rs_fade])
1708 1802
1709#if TRANSPARENT 1803#if TRANSPARENT
1710void 1804void
1711rxvt_term::rootwin_cb (XEvent &ev) 1805rxvt_term::rootwin_cb (XEvent &ev)
1712{ 1806{
1713 SET_R (this); 1807 make_current ();
1714 SET_LOCALE (locale);
1715 1808
1716 switch (ev.type) 1809 switch (ev.type)
1717 { 1810 {
1718 case PropertyNotify: 1811 case PropertyNotify:
1719 /* 1812 /*
1724 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1817 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID])
1725 return; 1818 return;
1726 1819
1727 /* FALLTHROUGH */ 1820 /* FALLTHROUGH */
1728 case ReparentNotify: 1821 case ReparentNotify:
1729 if ((options & Opt_transparent) && check_our_parents () && am_transparent) 1822 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1730 want_refresh = want_full_refresh = 1; 1823 want_refresh = want_full_refresh = 1;
1731 break; 1824 break;
1732 } 1825 }
1733} 1826}
1734#endif 1827#endif
1737rxvt_term::button_press (XButtonEvent &ev) 1830rxvt_term::button_press (XButtonEvent &ev)
1738{ 1831{
1739 int reportmode = 0, clickintime; 1832 int reportmode = 0, clickintime;
1740 1833
1741 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1834 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1835
1742 if (!bypass_keystate) 1836 if (!bypass_keystate)
1743 reportmode = !! (priv_modes & PrivMode_mouse_report); 1837 reportmode = !! (priv_modes & PrivMode_mouse_report);
1744 1838
1745 /* 1839 /*
1746 * VT window processing of button press 1840 * VT window processing of button press
1766#ifdef MOUSE_REPORT_DOUBLECLICK 1860#ifdef MOUSE_REPORT_DOUBLECLICK
1767 if (ev.button == MEvent.button && clickintime) 1861 if (ev.button == MEvent.button && clickintime)
1768 { 1862 {
1769 /* same button, within alloted time */ 1863 /* same button, within alloted time */
1770 MEvent.clicks++; 1864 MEvent.clicks++;
1865
1771 if (MEvent.clicks > 1) 1866 if (MEvent.clicks > 1)
1772 { 1867 {
1773 /* only report double clicks */ 1868 /* only report double clicks */
1774 MEvent.clicks = 2; 1869 MEvent.clicks = 2;
1775 mouse_report (ev); 1870 mouse_report (ev);
1795 else 1890 else
1796 { 1891 {
1797 if (ev.button != MEvent.button) 1892 if (ev.button != MEvent.button)
1798 MEvent.clicks = 0; 1893 MEvent.clicks = 0;
1799 1894
1895 if (!HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1800 switch (ev.button) 1896 switch (ev.button)
1801 { 1897 {
1802 case Button1: 1898 case Button1:
1803 /* allow meta + click to select rectangular areas */ 1899 /* allow meta + click to select rectangular areas */
1804 /* should be done in screen.C */ 1900 /* should be done in screen.C */
1805#if ENABLE_FRILLS 1901#if ENABLE_FRILLS
1806 selection.rect = !!(ev.state & ModMetaMask); 1902 selection.rect = !!(ev.state & ModMetaMask);
1807#else 1903#else
1808 selection.rect = false; 1904 selection.rect = false;
1809#endif 1905#endif
1810 1906
1811 /* allow shift+left click to extend selection */ 1907 /* allow shift+left click to extend selection */
1812 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1908 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1813 { 1909 {
1814 if (MEvent.button == Button1 && clickintime) 1910 if (MEvent.button == Button1 && clickintime)
1815 selection_rotate (ev.x, ev.y); 1911 selection_rotate (ev.x, ev.y);
1816 else 1912 else
1817 selection_extend (ev.x, ev.y, 1); 1913 selection_extend (ev.x, ev.y, 1);
1818 } 1914 }
1819 else 1915 else
1820 { 1916 {
1821 if (MEvent.button == Button1 && clickintime) 1917 if (MEvent.button == Button1 && clickintime)
1822 MEvent.clicks++; 1918 MEvent.clicks++;
1823 else 1919 else
1824 MEvent.clicks = 1; 1920 MEvent.clicks = 1;
1825 1921
1826 selection_click (MEvent.clicks, ev.x, ev.y); 1922 selection_click (MEvent.clicks, ev.x, ev.y);
1827 } 1923 }
1828 1924
1829 MEvent.button = Button1; 1925 MEvent.button = Button1;
1830 break; 1926 break;
1831 1927
1832 case Button3: 1928 case Button3:
1833 if (MEvent.button == Button3 && clickintime) 1929 if (MEvent.button == Button3 && clickintime)
1834 selection_rotate (ev.x, ev.y); 1930 selection_rotate (ev.x, ev.y);
1835 else 1931 else
1836 selection_extend (ev.x, ev.y, 1); 1932 selection_extend (ev.x, ev.y, 1);
1837 1933
1838 MEvent.button = Button3; 1934 MEvent.button = Button3;
1839 break; 1935 break;
1840 } 1936 }
1841 } 1937 }
1842 1938
1843 MEvent.time = ev.time; 1939 MEvent.time = ev.time;
1844 return; 1940 return;
1845 } 1941 }
1846 1942
1982 } 2078 }
1983 2079
1984 break; 2080 break;
1985 } 2081 }
1986 } 2082 }
2083
1987 return; 2084 return;
1988 } 2085 }
1989#if MENUBAR
1990 /*
1991 * Menubar window processing of button press
1992 */
1993 if (isMenuBarWindow (ev.window))
1994 menubar_control (ev);
1995#endif
1996} 2086}
1997 2087
1998void 2088void
1999rxvt_term::button_release (XButtonEvent &ev) 2089rxvt_term::button_release (XButtonEvent &ev)
2000{ 2090{
2006 2096
2007 if (scrollbar_isUpDn ()) 2097 if (scrollbar_isUpDn ())
2008 { 2098 {
2009 scrollBar.setIdle (); 2099 scrollBar.setIdle ();
2010 scrollbar_show (0); 2100 scrollbar_show (0);
2011#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2012 refresh_type &= ~SMOOTH_REFRESH;
2013#endif
2014 } 2101 }
2015 2102
2016#ifdef SELECTION_SCROLLING 2103#ifdef SELECTION_SCROLLING
2017 if (sel_scroll_ev.active) 2104 if (sel_scroll_ev.active)
2018 sel_scroll_ev.stop(); 2105 sel_scroll_ev.stop();
2056 if (priv_modes & PrivMode_mouse_report 2143 if (priv_modes & PrivMode_mouse_report
2057 && bypass_keystate 2144 && bypass_keystate
2058 && ev.button == Button1 && MEvent.clicks <= 1) 2145 && ev.button == Button1 && MEvent.clicks <= 1)
2059 selection_extend (ev.x, ev.y, 0); 2146 selection_extend (ev.x, ev.y, 0);
2060 2147
2148 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2149 return;
2150
2061 switch (ev.button) 2151 switch (ev.button)
2062 { 2152 {
2063 case Button1: 2153 case Button1:
2064 case Button3: 2154 case Button3:
2065 selection_make (ev.time); 2155 selection_make (ev.time);
2066 break; 2156 break;
2157
2067 case Button2: 2158 case Button2:
2068 selection_request (ev.time, ev.x, ev.y); 2159 if (IN_RANGE_EXC (ev.x, 0, width)
2160 && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2161 {
2162 if (ev.state & ShiftMask)
2163 selection_request (ev.time, Sel_Clipboard);
2164 else
2165 selection_request (ev.time, Sel_Primary);
2166 }
2069 break; 2167 break;
2168
2070#ifdef MOUSE_WHEEL 2169#ifdef MOUSE_WHEEL
2071 case Button4: 2170 case Button4:
2072 case Button5: 2171 case Button5:
2073 { 2172 {
2074 int i; 2173 int i;
2076 2175
2077 v = ev.button == Button4 ? UP : DN; 2176 v = ev.button == Button4 ? UP : DN;
2078 2177
2079 if (ev.state & ShiftMask) 2178 if (ev.state & ShiftMask)
2080 i = 1; 2179 i = 1;
2081 else if (options & Opt_mouseWheelScrollPage) 2180 else if (OPTION (Opt_mouseWheelScrollPage))
2082 i = nrow - 1; 2181 i = nrow - 1;
2083 else 2182 else
2084 i = 5; 2183 i = 5;
2085 2184
2086# ifdef MOUSE_SLIP_WHEELING 2185# ifdef MOUSE_SLIP_WHEELING
2096 slip_wheel_ev.start (); 2195 slip_wheel_ev.start ();
2097 } 2196 }
2098 else 2197 else
2099 { 2198 {
2100# endif 2199# endif
2101# ifdef JUMP_MOUSE_WHEEL
2102 scr_page (v, i); 2200 scr_page (v, i);
2103 scr_refresh (SMOOTH_REFRESH);
2104 scrollbar_show (1); 2201 scrollbar_show (1);
2105# else
2106 while (i--)
2107 {
2108 scr_page (v, 1);
2109 scr_refresh (SMOOTH_REFRESH);
2110 scrollbar_show (1);
2111 }
2112# endif
2113# ifdef MOUSE_SLIP_WHEELING 2202# ifdef MOUSE_SLIP_WHEELING
2114 } 2203 }
2115#endif 2204# endif
2116 } 2205 }
2117 break; 2206 break;
2118#endif 2207#endif
2119 } 2208 }
2120 } 2209 }
2121#ifdef MENUBAR
2122 else if (isMenuBarWindow (ev.window))
2123 menubar_control (ev);
2124#endif
2125} 2210}
2126 2211
2127#ifdef TRANSPARENT 2212#ifdef TRANSPARENT
2128#if TINTING 2213#if TINTING
2129/* taken from aterm-0.4.2 */ 2214/* taken from aterm-0.4.2 */
2372 XWindowAttributes wattr, wrootattr; 2457 XWindowAttributes wattr, wrootattr;
2373 dDisp; 2458 dDisp;
2374 2459
2375 pchanged = 0; 2460 pchanged = 0;
2376 2461
2377 if (!(options & Opt_transparent)) 2462 if (!OPTION (Opt_transparent))
2378 return pchanged; /* Don't try any more */ 2463 return pchanged; /* Don't try any more */
2379 2464
2380 XGetWindowAttributes (disp, display->root, &wrootattr); 2465 XGetWindowAttributes (disp, display->root, &wrootattr);
2381 rootdepth = wrootattr.depth; 2466 rootdepth = wrootattr.depth;
2382 2467
2609 2694
2610bool 2695bool
2611rxvt_term::cmd_parse () 2696rxvt_term::cmd_parse ()
2612{ 2697{
2613 bool flag = false; 2698 bool flag = false;
2614 unicode_t ch = NOCHAR; 2699 wchar_t ch = NOCHAR;
2615 unsigned char *seq_begin; // remember start of esc-sequence here 2700 char *seq_begin; // remember start of esc-sequence here
2616 2701
2617 for (;;) 2702 for (;;)
2618 { 2703 {
2619 if (ch == NOCHAR) 2704 if (ch == NOCHAR)
2620 { 2705 {
2621 seq_begin = cmdbuf_ptr; 2706 seq_begin = cmdbuf_ptr;
2622 ch = next_char (); 2707 ch = next_char ();
2623 }
2624 2708
2625 if (ch == NOCHAR) // TODO: improve 2709 if (ch == NOCHAR)
2626 break; 2710 break;
2711 }
2627 2712
2628 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2713 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)
2629 { 2714 {
2630 if (!seen_input) 2715 if (!seen_input)
2631 { 2716 {
2640 if (seen_resize && cmd_pid) 2725 if (seen_resize && cmd_pid)
2641 kill (-cmd_pid, SIGWINCH); 2726 kill (-cmd_pid, SIGWINCH);
2642 } 2727 }
2643 2728
2644 /* Read a text string from the input buffer */ 2729 /* Read a text string from the input buffer */
2645 unicode_t buf[UBUFSIZ]; 2730 wchar_t buf[UBUFSIZ];
2646 bool refreshnow = false; 2731 bool refreshnow = false;
2647 int nlines = 0; 2732 int nlines = 0;
2648 unicode_t *str = buf; 2733 wchar_t *str = buf;
2649 unicode_t *eol = str + min (ncol, UBUFSIZ); 2734 wchar_t *eol = str + min (ncol, UBUFSIZ);
2650 2735
2651 for (;;) 2736 for (;;)
2652 { 2737 {
2653 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2738 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))
2654 break; 2739 break;
2660 if (ch == C0_LF) 2745 if (ch == C0_LF)
2661 nlines++; 2746 nlines++;
2662 2747
2663 refresh_count++; 2748 refresh_count++;
2664 2749
2665 if (!(options & Opt_jumpScroll) 2750 if (!OPTION (Opt_jumpScroll)
2666 || (refresh_count >= refresh_limit * (nrow - 1))) 2751 || (refresh_count >= refresh_limit * (nrow - 1)))
2667 { 2752 {
2668 refreshnow = true; 2753 refreshnow = true;
2754 refresh_count = 0;
2669 ch = NOCHAR; 2755 ch = NOCHAR;
2670 break; 2756 break;
2671 } 2757 }
2672 2758
2673 // scr_add_lines only works for nlines <= nrow - 1. 2759 // scr_add_lines only works for nlines <= nrow - 1.
2674 if (nlines >= nrow - 1) 2760 if (nlines >= nrow - 1)
2675 { 2761 {
2762 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2763 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2676 scr_add_lines (buf, nlines, str - buf); 2764 scr_add_lines (buf, str - buf, nlines);
2765
2677 nlines = 0; 2766 nlines = 0;
2678 str = buf; 2767 str = buf;
2679 eol = str + min (ncol, UBUFSIZ); 2768 eol = str + min (ncol, UBUFSIZ);
2680 } 2769 }
2681 2770
2694 2783
2695 seq_begin = cmdbuf_ptr; 2784 seq_begin = cmdbuf_ptr;
2696 ch = next_char (); 2785 ch = next_char ();
2697 } 2786 }
2698 2787
2788 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2789 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2699 scr_add_lines (buf, nlines, str - buf); 2790 scr_add_lines (buf, str - buf, nlines);
2700 2791
2701 /* 2792 /*
2702 * If there have been a lot of new lines, then update the screen 2793 * If there have been a lot of new lines, then update the screen
2703 * What the heck I'll cheat and only refresh less than every page-full. 2794 * What the heck I'll cheat and only refresh less than every page-full.
2704 * the number of pages between refreshes is refresh_limit, which 2795 * the number of pages between refreshes is refresh_limit, which
2705 * is incremented here because we must be doing flat-out scrolling. 2796 * is incremented here because we must be doing flat-out scrolling.
2706 */ 2797 */
2707 if (refreshnow) 2798 if (refreshnow)
2708 { 2799 {
2709 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) 2800 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2710 refresh_limit++; 2801 refresh_limit++;
2711 else 2802 else
2712 { 2803 {
2713 flag = true; 2804 flag = true;
2714 scr_refresh (refresh_type); 2805 scr_refresh ();
2806 want_refresh = 1;
2715 } 2807 }
2716 } 2808 }
2717 2809
2718 } 2810 }
2719 else 2811 else
2734 } 2826 }
2735 2827
2736 return flag; 2828 return flag;
2737} 2829}
2738 2830
2739// read the next octet
2740unicode_t
2741rxvt_term::next_octet ()
2742{
2743 return cmdbuf_ptr < cmdbuf_endp
2744 ? *cmdbuf_ptr++
2745 : NOCHAR;
2746}
2747
2748// read the next character 2831// read the next character
2749unicode_t 2832wchar_t
2750rxvt_term::next_char () 2833rxvt_term::next_char () NOTHROW
2751{ 2834{
2752 while (cmdbuf_ptr < cmdbuf_endp) 2835 while (cmdbuf_ptr < cmdbuf_endp)
2753 { 2836 {
2754 // assume 7-bit to be ascii ALWAYS 2837 // assume 7-bit to be ascii ALWAYS
2755 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2838 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)
2756 return *cmdbuf_ptr++; 2839 return *cmdbuf_ptr++;
2757 2840
2758 wchar_t wc; 2841 wchar_t wc;
2759 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2842 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2760 2843
2761 if (len == (size_t)-2) 2844 if (len == (size_t)-2)
2762 { 2845 {
2763 // the mbstate stores incomplete sequences. didn't know this :/ 2846 // the mbstate stores incomplete sequences. didn't know this :/
2764 cmdbuf_ptr = cmdbuf_endp; 2847 cmdbuf_ptr = cmdbuf_endp;
2765 break; 2848 break;
2766 } 2849 }
2767 2850
2768 if (len == (size_t)-1) 2851 if (len == (size_t)-1)
2769 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2852 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2770 2853
2771 // assume wchar == unicode 2854 // assume wchar == unicode
2772 cmdbuf_ptr += len; 2855 cmdbuf_ptr += len;
2773 return wc & UNICODE_MASK; 2856 return wc & UNICODE_MASK;
2774 } 2857 }
2775 2858
2776 return NOCHAR; 2859 return NOCHAR;
2777} 2860}
2861
2862// read the next octet
2863uint32_t
2864rxvt_term::next_octet () NOTHROW
2865{
2866 return cmdbuf_ptr < cmdbuf_endp
2867 ? (unsigned char)*cmdbuf_ptr++
2868 : NOCHAR;
2869}
2870
2871static class out_of_input out_of_input;
2778 2872
2779/* rxvt_cmd_getc () - Return next input character */ 2873/* rxvt_cmd_getc () - Return next input character */
2780/* 2874/*
2781 * Return the next input character after first passing any keyboard input 2875 * Return the next input character after first passing any keyboard input
2782 * to the command. 2876 * to the command.
2783 */ 2877 */
2784unicode_t 2878wchar_t
2785rxvt_term::cmd_getc () 2879rxvt_term::cmd_getc () THROW ((class out_of_input))
2786{ 2880{
2787 unicode_t c = next_char (); 2881 wchar_t c = next_char ();
2788 2882
2789 if (c == NOCHAR) 2883 if (c == NOCHAR)
2790 throw out_of_input; 2884 throw out_of_input;
2791 2885
2792 return c; 2886 return c;
2793} 2887}
2794 2888
2795unicode_t 2889uint32_t
2796rxvt_term::cmd_get8 () 2890rxvt_term::cmd_get8 () THROW ((class out_of_input))
2797{ 2891{
2798 unicode_t c = next_octet (); 2892 uint32_t c = next_octet ();
2799 2893
2800 if (c == NOCHAR) 2894 if (c == NOCHAR)
2801 throw out_of_input; 2895 throw out_of_input;
2802 2896
2803 return c; 2897 return c;
2903 case C0_ESC: 2997 case C0_ESC:
2904 process_escape_seq (); 2998 process_escape_seq ();
2905 break; 2999 break;
2906 case C0_ENQ: /* terminal Status */ 3000 case C0_ENQ: /* terminal Status */
2907 if (rs[Rs_answerbackstring]) 3001 if (rs[Rs_answerbackstring])
2908 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 3002 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2909 (unsigned int)strlen (rs[Rs_answerbackstring]));
2910 else 3003 else
2911 tt_write ((unsigned char *)VT100_ANS, 3004 tt_write (VT100_ANS, strlen (VT100_ANS));
2912 (unsigned int)strlen (VT100_ANS));
2913 break; 3005 break;
2914 case C0_BEL: /* bell */ 3006 case C0_BEL: /* bell */
2915 scr_bell (); 3007 scr_bell ();
2916 break; 3008 break;
2917 case C0_BS: /* backspace */ 3009 case C0_BS: /* backspace */
3072 break; 3164 break;
3073 3165
3074 /* 8.3.87: NEXT LINE */ 3166 /* 8.3.87: NEXT LINE */
3075 case C1_NEL: /* ESC E */ 3167 case C1_NEL: /* ESC E */
3076 { 3168 {
3077 unicode_t nlcr[] = { C0_LF, C0_CR }; 3169 wchar_t nlcr[] = { C0_LF, C0_CR };
3078 scr_add_lines (nlcr, 1, 2); 3170 scr_add_lines (nlcr, sizeof (nlcr) / sizeof (nlcr [0]), 1);
3079 } 3171 }
3080 break; 3172 break;
3081 3173
3082 /* kidnapped escape sequence: Should be 8.3.48 */ 3174 /* kidnapped escape sequence: Should be 8.3.48 */
3083 case C1_ESA: /* ESC G */ 3175 case C1_ESA: /* ESC G */
3105 process_dcs_seq (); 3197 process_dcs_seq ();
3106 break; 3198 break;
3107 3199
3108 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 3200 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3109 case C1_SCI: /* ESC Z */ 3201 case C1_SCI: /* ESC Z */
3110 tt_write ((const unsigned char *)ESCZ_ANSWER, 3202 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3111 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3112 break; /* steal obsolete ESC [ c */ 3203 break; /* steal obsolete ESC [ c */
3113 3204
3114 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 3205 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */
3115 case C1_CSI: /* ESC [ */ 3206 case C1_CSI: /* ESC [ */
3116 process_csi_seq (); 3207 process_csi_seq ();
3360 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 3451 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3361 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]); 3452 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3362 break; 3453 break;
3363 3454
3364 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3455 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3365 tt_write ((const unsigned char *)VT100_ANS, 3456 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3366 (unsigned int) (sizeof (VT100_ANS) - 1));
3367 break; 3457 break;
3368 3458
3369 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 3459 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3370 process_sgr_mode (nargs, arg); 3460 process_sgr_mode (nargs, arg);
3371 break; 3461 break;
3378 break; 3468 break;
3379 case 6: /* CPR requested */ 3469 case 6: /* CPR requested */
3380 scr_report_position (); 3470 scr_report_position ();
3381 break; 3471 break;
3382 case 7: /* unofficial extension */ 3472 case 7: /* unofficial extension */
3383 if (options & Opt_insecure) 3473 if (OPTION (Opt_insecure))
3384 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3474 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3385 break; 3475 break;
3386 case 8: /* unofficial extension */ 3476 case 8: /* unofficial extension */
3387 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3477 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3388 break; 3478 break;
3552 break; 3642 break;
3553 case 20: /* report icon label */ 3643 case 20: /* report icon label */
3554 { 3644 {
3555 char *s; 3645 char *s;
3556 XGetIconName (disp, parent[0], &s); 3646 XGetIconName (disp, parent[0], &s);
3557 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3647 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3558 XFree (s); 3648 XFree (s);
3559 } 3649 }
3560 break; 3650 break;
3561 case 21: /* report window title */ 3651 case 21: /* report window title */
3562 { 3652 {
3563 char *s; 3653 char *s;
3564 XFetchName (disp, parent[0], &s); 3654 XFetchName (disp, parent[0], &s);
3565 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3655 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */
3566 XFree (s); 3656 XFree (s);
3567 } 3657 }
3568 break; 3658 break;
3569 } 3659 }
3570} 3660}
3573/*----------------------------------------------------------------------*/ 3663/*----------------------------------------------------------------------*/
3574/* 3664/*
3575 * get input up until STRING TERMINATOR (or BEL) 3665 * get input up until STRING TERMINATOR (or BEL)
3576 * ends_how is terminator used. returned input must be free()'d 3666 * ends_how is terminator used. returned input must be free()'d
3577 */ 3667 */
3578unsigned char * 3668char *
3579rxvt_term::get_to_st (unicode_t &ends_how) 3669rxvt_term::get_to_st (unicode_t &ends_how)
3580{ 3670{
3581 unicode_t ch; 3671 unicode_t ch;
3582 bool seen_esc = false; 3672 bool seen_esc = false;
3583 unsigned int n = 0; 3673 unsigned int n = 0;
3616 3706
3617 string[n++] = '\0'; 3707 string[n++] = '\0';
3618 3708
3619 ends_how = (ch == 0x5c ? C0_ESC : ch); 3709 ends_how = (ch == 0x5c ? C0_ESC : ch);
3620 3710
3621 return (unsigned char *)rxvt_wcstombs (string); 3711 return rxvt_wcstombs (string);
3622} 3712}
3623 3713
3624/*----------------------------------------------------------------------*/ 3714/*----------------------------------------------------------------------*/
3625/* 3715/*
3626 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3716 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3627 */ 3717 */
3628void 3718void
3629rxvt_term::process_dcs_seq () 3719rxvt_term::process_dcs_seq ()
3630{ 3720{
3631 unsigned char *s; 3721 char *s;
3632 unicode_t eh; 3722 unicode_t eh;
3633 3723
3634 /* 3724 /*
3635 * Not handled yet 3725 * Not handled yet
3636 */ 3726 */
3655 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3745 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3656 arg = arg * 10 + (ch - '0'); 3746 arg = arg * 10 + (ch - '0');
3657 3747
3658 if (ch == ';') 3748 if (ch == ';')
3659 { 3749 {
3660 unsigned char *s = get_to_st (eh); 3750 char *s = get_to_st (eh);
3661 3751
3662 if (s) 3752 if (s)
3663 { 3753 {
3664 process_xterm_seq (arg, (char *)s, eh); 3754 process_xterm_seq (arg, s, eh);
3665 free (s); 3755 free (s);
3666 } 3756 }
3667 } 3757 }
3668} 3758}
3669 3759
3670void 3760void
3671rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3761rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3672{ 3762{
3673 if (str[0] == '?' && !str[1]) 3763 if (str[0] == '?' && !str[1])
3674 { 3764 {
3675 unsigned short r, g, b; 3765 unsigned short r, g, b;
3676 pix_colors_focused[color].get (display, r, g, b); 3766 pix_colors_focused[color].get (display, r, g, b);
3682 3772
3683/* 3773/*
3684 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3774 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3685 */ 3775 */
3686void 3776void
3687rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3777rxvt_term::process_xterm_seq (int op, const char *str, char resp)
3688{ 3778{
3689 int changed = 0;
3690 int color; 3779 int color;
3691 char *buf, *name; 3780 char *buf, *name;
3692 bool query = str[0] == '?' && !str[1]; 3781 bool query = str[0] == '?' && !str[1];
3693 int saveop = op; 3782 int saveop = op;
3694 dDisp; 3783 dDisp;
3749 { 3838 {
3750 if ((name = strchr (buf, ';')) == NULL) 3839 if ((name = strchr (buf, ';')) == NULL)
3751 break; 3840 break;
3752 3841
3753 *name++ = '\0'; 3842 *name++ = '\0';
3754 color = atoi (buf); 3843 color = atoi (buf) + minCOLOR;
3755 3844
3756 if (color < 0 || color >= TOTAL_COLORS) 3845 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3757 break; 3846 break;
3758 3847
3759 if ((buf = strchr (name, ';')) != NULL) 3848 if ((buf = strchr (name, ';')) != NULL)
3760 *buf++ = '\0'; 3849 *buf++ = '\0';
3761 3850
3762 if (name[0] == '?' && !name[1]) 3851 if (name[0] == '?' && !name[1])
3763 { 3852 {
3764 unsigned short r, g, b; 3853 unsigned short r, g, b;
3765 pix_colors_focused[color + minCOLOR].get (display, r, g, b); 3854 pix_colors_focused[color].get (display, r, g, b);
3766 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp); 3855 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3767 } 3856 }
3768 else 3857 else
3769 set_window_color (color + minCOLOR, name); 3858 set_window_color (color, name);
3770 } 3859 }
3771 break; 3860 break;
3772 case XTerm_Color00: 3861 case XTerm_Color00:
3773 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3862 process_color_seq (XTerm_Color00, Color_fg, str, resp);
3774 break; 3863 break;
3775 case XTerm_Color01: 3864 case XTerm_Color01:
3776 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3865 process_color_seq (XTerm_Color01, Color_bg, str, resp);
3777 break; 3866 break;
3778#ifndef NO_CURSORCOLOR 3867#ifndef NO_CURSORCOLOR
3779 case XTerm_Color_cursor: 3868 case XTerm_Color_cursor:
3780 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3869 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp);
3781 break; 3870 break;
3785 break; 3874 break;
3786 case XTerm_Color_pointer_bg: 3875 case XTerm_Color_pointer_bg:
3787 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3876 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp);
3788 break; 3877 break;
3789#ifndef NO_BOLD_UNDERLINE_REVERSE 3878#ifndef NO_BOLD_UNDERLINE_REVERSE
3790 case XTerm_Color_BD:
3791 process_color_seq (XTerm_Color_BD, Color_BD, str, resp);
3792 break;
3793 case XTerm_Color_UL:
3794 process_color_seq (XTerm_Color_UL, Color_UL, str, resp);
3795 break;
3796 case XTerm_Color_RV: 3879 case XTerm_Color_RV:
3797 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3880 process_color_seq (XTerm_Color_RV, Color_RV, str, resp);
3881 break;
3882 case Rxvt_Color_BD:
3883 case URxvt_Color_BD:
3884 process_color_seq (op, Color_BD, str, resp);
3885 break;
3886 case Rxvt_Color_UL:
3887 case URxvt_Color_UL:
3888 process_color_seq (op, Color_UL, str, resp);
3798 break; 3889 break;
3799 case URxvt_Color_IT: 3890 case URxvt_Color_IT:
3800 process_color_seq (URxvt_Color_IT, Color_IT, str, resp); 3891 process_color_seq (URxvt_Color_IT, Color_IT, str, resp);
3801 break; 3892 break;
3802#endif 3893#endif
3807 if (am_transparent) 3898 if (am_transparent)
3808 want_full_refresh = want_refresh = 1; 3899 want_full_refresh = want_refresh = 1;
3809 break; 3900 break;
3810#endif 3901#endif
3811 3902
3812 case XTerm_Pixmap: 3903 case Rxvt_Pixmap:
3904 {
3813 if (*str != ';') 3905 if (*str != ';')
3814 { 3906 {
3815#if XPM_BACKGROUND 3907#if XPM_BACKGROUND
3816 scale_pixmap (""); /* reset to default scaling */ 3908 scale_pixmap (""); /* reset to default scaling */
3817 set_bgPixmap (str); /* change pixmap */ 3909 set_bgPixmap (str); /* change pixmap */
3818#endif
3819 scr_touch (true); 3910 scr_touch (true);
3911#endif
3820 } 3912 }
3913
3914 int changed = 0;
3915
3821 while ((str = strchr (str, ';')) != NULL) 3916 while ((str = strchr (str, ';')) != NULL)
3822 { 3917 {
3823 str++; 3918 str++;
3824#if XPM_BACKGROUND 3919#if XPM_BACKGROUND
3825 changed += scale_pixmap (str); 3920 changed += scale_pixmap (str);
3826#endif 3921#endif
3827 } 3922 }
3828 3923
3829 if (changed) 3924 if (changed)
3830 { 3925 {
3831#ifdef XPM_BACKGROUND 3926#ifdef XPM_BACKGROUND
3832 resize_pixmap (); 3927 resize_pixmap ();
3833#endif
3834 scr_touch (true); 3928 scr_touch (true);
3929#endif
3835 } 3930 }
3931 }
3836 break; 3932 break;
3837 3933
3838 case XTerm_restoreFG: 3934 case Rxvt_restoreFG:
3839 set_window_color (Color_fg, str); 3935 set_window_color (Color_fg, str);
3840 break; 3936 break;
3841 case XTerm_restoreBG: 3937 case Rxvt_restoreBG:
3842 set_window_color (Color_bg, str); 3938 set_window_color (Color_bg, str);
3843 break; 3939 break;
3844 3940
3845 case XTerm_logfile: 3941 case XTerm_logfile:
3846 // TODO, when secure mode? 3942 // TODO, when secure mode?
3847 break; 3943 break;
3848 3944
3849#ifdef MENUBAR
3850 case URxvt_Menu:
3851 if (options & Opt_insecure)
3852 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked
3853 break;
3854#endif
3855#if 0 3945#if 0
3856 case XTerm_dumpscreen: /* no error notices */ 3946 case Rxvt_dumpscreen: /* no error notices */
3857 { 3947 {
3858 int fd; 3948 int fd;
3859 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) 3949 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3860 { 3950 {
3861 scr_dump (fd); 3951 scr_dump (fd);
3872 case URxvt_italicFont: 3962 case URxvt_italicFont:
3873 case URxvt_boldItalicFont: 3963 case URxvt_boldItalicFont:
3874#endif 3964#endif
3875 if (query) 3965 if (query)
3876 tt_printf ("\33]%d;%-.250s%c", saveop, 3966 tt_printf ("\33]%d;%-.250s%c", saveop,
3877 (options & Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3967 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3878 ? fontset[op - URxvt_font]->fontdesc : "", 3968 ? fontset[op - URxvt_font]->fontdesc : "",
3879 resp); 3969 resp);
3880 else 3970 else
3881 { 3971 {
3882 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3972 const char *&res = rs[Rs_font + (op - URxvt_font)];
3888 break; 3978 break;
3889 3979
3890#if ENABLE_FRILLS 3980#if ENABLE_FRILLS
3891 case URxvt_locale: 3981 case URxvt_locale:
3892 if (query) 3982 if (query)
3893 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, (options & Opt_insecure) ? locale : "", resp); 3983 tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp);
3894 else 3984 else
3895 { 3985 {
3896 set_locale (str); 3986 set_locale (str);
3897 pty.set_utf8_mode (enc_utf8); 3987 pty->set_utf8_mode (enc_utf8);
3898 init_xlocale (); 3988 init_xlocale ();
3899 } 3989 }
3900 break; 3990 break;
3901 3991
3902 case URxvt_view_up: 3992 case URxvt_view_up:
3903 case URxvt_view_down: 3993 case URxvt_view_down:
3994 {
3904 int lines = atoi (str); 3995 int lines = atoi (str);
3905 3996
3906 if (lines) 3997 if (lines)
3907 scr_page (op == URxvt_view_up ? UP : DN, lines); 3998 scr_page (op == URxvt_view_up ? UP : DN, lines);
3908 else 3999 else
3909 {
3910 scr_erase_savelines (); 4000 scr_erase_savelines ();
3911 } 4001 }
3912 4002
4003 break;
4004#endif
4005
4006#if ENABLE_PERL
4007 case URxvt_perl:
4008 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END)))
4009 ; // no responses yet
3913 break; 4010 break;
3914#endif 4011#endif
3915 } 4012 }
3916} 4013}
3917/*----------------------------------------------------------------------*/ 4014/*----------------------------------------------------------------------*/
3948 return state; 4045 return state;
3949} 4046}
3950 4047
3951/* we're not using priv _yet_ */ 4048/* we're not using priv _yet_ */
3952void 4049void
3953rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 4050rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg)
3954{ 4051{
3955 unsigned int i, j; 4052 unsigned int i, j;
3956 int state; 4053 int state;
3957 4054
3958 static const struct 4055 static const struct
3969 { 5, PrivMode_rVideo }, 4066 { 5, PrivMode_rVideo },
3970 { 6, PrivMode_relOrigin }, 4067 { 6, PrivMode_relOrigin },
3971 { 7, PrivMode_Autowrap }, 4068 { 7, PrivMode_Autowrap },
3972 // 8, bi-directional support mode 4069 // 8, bi-directional support mode
3973 { 9, PrivMode_MouseX10 }, 4070 { 9, PrivMode_MouseX10 },
3974#ifdef menuBar_esc
3975 { menuBar_esc, PrivMode_menuBar },
3976#endif
3977 // 18, 19 printing-related 4071 // 18, 19 printing-related
3978 { 25, PrivMode_VisibleCursor }, 4072 { 25, PrivMode_VisibleCursor },
3979#ifdef scrollBar_esc 4073#ifdef scrollBar_esc
3980 { scrollBar_esc, PrivMode_scrollBar }, 4074 { scrollBar_esc, PrivMode_scrollBar },
3981#endif 4075#endif
4026 } 4120 }
4027 4121
4028 /* extra handling for values with state unkept */ 4122 /* extra handling for values with state unkept */
4029 switch (arg[i]) 4123 switch (arg[i])
4030 { 4124 {
4125#if ENABLE_STYLES
4126 case 1021:
4127 set_option (Opt_intensityStyles, mode);
4128
4129 scr_touch (true);
4130 break;
4131#endif
4031 case 1048: /* alternative cursor save */ 4132 case 1048: /* alternative cursor save */
4032 case 1049: 4133 case 1049:
4033 if (options & Opt_secondaryScreen) 4134 if (OPTION (Opt_secondaryScreen))
4034 if (mode == 0) 4135 if (mode == 0)
4035 scr_cursor (RESTORE); 4136 scr_cursor (RESTORE);
4036 else if (mode == 1) 4137 else if (mode == 1)
4037 scr_cursor (SAVE); 4138 scr_cursor (SAVE);
4038 break; 4139 break;
4053 case 3: /* 80/132 */ 4154 case 3: /* 80/132 */
4054 if (priv_modes & PrivMode_132OK) 4155 if (priv_modes & PrivMode_132OK)
4055 set_widthheight (((state ? 132 : 80) * fwidth), height); 4156 set_widthheight (((state ? 132 : 80) * fwidth), height);
4056 break; 4157 break;
4057 case 4: /* smooth scrolling */ 4158 case 4: /* smooth scrolling */
4058 if (state)
4059 options &= ~Opt_jumpScroll;
4060 else
4061 options |= Opt_jumpScroll; 4159 set_option (Opt_jumpScroll, !state);
4062 break; 4160 break;
4063 case 5: /* reverse video */ 4161 case 5: /* reverse video */
4064 scr_rvideo_mode (state); 4162 scr_rvideo_mode (state);
4065 break; 4163 break;
4066 case 6: /* relative/absolute origins */ 4164 case 6: /* relative/absolute origins */
4072 /* case 8: - auto repeat, can't do on a per window basis */ 4170 /* case 8: - auto repeat, can't do on a per window basis */
4073 case 9: /* X10 mouse reporting */ 4171 case 9: /* X10 mouse reporting */
4074 if (state) /* orthogonal */ 4172 if (state) /* orthogonal */
4075 priv_modes &= ~PrivMode_MouseX11; 4173 priv_modes &= ~PrivMode_MouseX11;
4076 break; 4174 break;
4077#ifdef menuBar_esc
4078 case menuBar_esc:
4079#ifdef MENUBAR
4080 map_menuBar (state);
4081#endif
4082 break;
4083#endif
4084#ifdef scrollBar_esc 4175#ifdef scrollBar_esc
4085 case scrollBar_esc: 4176 case scrollBar_esc:
4086 if (scrollbar_mapping (state)) 4177 if (scrollbar_mapping (state))
4087 { 4178 {
4088 resize_all_windows (0, 0, 0); 4179 resize_all_windows (0, 0, 0);
4107#if 0 4198#if 0
4108 case 1001: 4199 case 1001:
4109 break; /* X11 mouse highlighting */ 4200 break; /* X11 mouse highlighting */
4110#endif 4201#endif
4111 case 1010: /* scroll to bottom on TTY output inhibit */ 4202 case 1010: /* scroll to bottom on TTY output inhibit */
4112 if (state)
4113 options &= ~Opt_scrollTtyOutput;
4114 else
4115 options |= Opt_scrollTtyOutput; 4203 set_option (Opt_scrollTtyOutput, !state);
4116 break; 4204 break;
4117 case 1011: /* scroll to bottom on key press */ 4205 case 1011: /* scroll to bottom on key press */
4118 if (state)
4119 options |= Opt_scrollTtyKeypress; 4206 set_option (Opt_scrollTtyKeypress, state);
4120 else
4121 options &= ~Opt_scrollTtyKeypress;
4122 break; 4207 break;
4123 case 1047: /* secondary screen w/ clearing last */ 4208 case 1047: /* secondary screen w/ clearing last */
4124 if (options & Opt_secondaryScreen) 4209 if (OPTION (Opt_secondaryScreen))
4125 if (current_screen != PRIMARY) 4210 if (current_screen != PRIMARY)
4126 scr_erase_screen (2); 4211 scr_erase_screen (2);
4127 scr_change_screen (state); 4212 scr_change_screen (state);
4128 break; 4213 break;
4129 case 1049: /* secondary screen w/ clearing first */ 4214 case 1049: /* secondary screen w/ clearing first */
4130 scr_change_screen (state); 4215 scr_change_screen (state);
4131 if (options & Opt_secondaryScreen) 4216 if (OPTION (Opt_secondaryScreen))
4132 if (current_screen != PRIMARY) 4217 if (current_screen != PRIMARY)
4133 scr_erase_screen (2); 4218 scr_erase_screen (2);
4134 break; 4219 break;
4135 default: 4220 default:
4136 break; 4221 break;
4264 scr_color (Color_bg, Color_bg); 4349 scr_color (Color_bg, Color_bg);
4265 break; 4350 break;
4266 4351
4267 //case 50: // not variable spacing 4352 //case 50: // not variable spacing
4268 4353
4269#ifndef NO_BRIGHTCOLOR 4354#if ENABLE_FRILLS
4270 case 90: 4355 case 90:
4271 case 91: /* set bright fg color */ 4356 case 91: /* set bright fg color */
4272 case 92: 4357 case 92:
4273 case 93: 4358 case 93:
4274 case 94: 4359 case 94:
4286 case 106: 4371 case 106:
4287 case 107: 4372 case 107:
4288 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 4373 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4289 break; 4374 break;
4290#endif 4375#endif
4291
4292 } 4376 }
4293 } 4377 }
4294} 4378}
4295/*}}} */ 4379/*}}} */
4296 4380
4320 */ 4404 */
4321void 4405void
4322rxvt_term::tt_printf (const char *fmt,...) 4406rxvt_term::tt_printf (const char *fmt,...)
4323{ 4407{
4324 va_list arg_ptr; 4408 va_list arg_ptr;
4325 unsigned char buf[256]; 4409 char buf[256];
4326 4410
4327 va_start (arg_ptr, fmt); 4411 va_start (arg_ptr, fmt);
4328 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 4412 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4329 va_end (arg_ptr); 4413 va_end (arg_ptr);
4330 tt_write (buf, strlen (buf)); 4414 tt_write (buf, strlen (buf));
4335 * or generated by us in response to a query ESC sequence. 4419 * or generated by us in response to a query ESC sequence.
4336 */ 4420 */
4337const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT 4421const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4338 4422
4339void 4423void
4340rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4424rxvt_term::tt_write (const char *data, unsigned int len)
4341{ 4425{
4426 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
4427 return;
4428
4429 if (pty->pty < 0)
4430 return;
4431
4342 if (v_buflen == 0) 4432 if (v_buflen == 0)
4343 { 4433 {
4344 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 4434 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4345 4435
4346 if ((unsigned int)written == len) 4436 if ((unsigned int)written == len)
4347 return; 4437 return;
4348 4438
4349 data += written; 4439 data += written;
4350 len -= written; 4440 len -= written;
4351 } 4441 }
4352 4442
4353 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4443 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4354 4444
4355 memcpy (v_buffer + v_buflen, data, len); 4445 memcpy (v_buffer + v_buflen, data, len);
4356 v_buflen += len; 4446 v_buflen += len;
4357 4447
4358 pty_ev.set (EVENT_READ | EVENT_WRITE); 4448 pty_ev.set (EVENT_READ | EVENT_WRITE);
4359} 4449}
4360 4450
4361void rxvt_term::pty_write () 4451void rxvt_term::pty_write ()
4362{ 4452{
4363 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4453 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4364 4454
4365 if (written > 0) 4455 if (written > 0)
4366 { 4456 {
4367 v_buflen -= written; 4457 v_buflen -= written;
4368 4458

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines