ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.198 by root, Sat Feb 19 01:07:58 2005 UTC vs.
Revision 1.588 by sf-exg, Sun May 9 15:47:51 2021 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: command.C 2 * File: command.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
7 * - original version 7 * - original version
8 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> 8 * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com>
9 * - extensive modifications 9 * - extensive modifications
10 * Copyright (c) 1995 Garrett D'Amore <garrett@netcom.com> 10 * Copyright (c) 1995 Garrett D'Amore <garrett@netcom.com>
11 * - vt100 printing 11 * - vt100 printing
12 * Copyright (c) 1995 Steven Hirsch <hirsch@emba.uvm.edu> 12 * Copyright (c) 1995 Steven Hirsch <hirsch@emba.uvm.edu>
13 * - X11 mouse report mode and support for 13 * - X11 mouse report mode and support for
14 * DEC "private mode" save/restore functions. 14 * DEC "private mode" save/restore functions.
20 * Copyright (c) 1997 Raul Garcia Garcia <rgg@tid.es> 20 * Copyright (c) 1997 Raul Garcia Garcia <rgg@tid.es>
21 * - modification and cleanups for Solaris 2.x 21 * - modification and cleanups for Solaris 2.x
22 * and Linux 1.2.x 22 * and Linux 1.2.x
23 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 23 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
24 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 24 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
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-2014 Marc Lehmann <schmorp@schmorp.de>
31 * Copyright (c) 2007,2015 Emanuele Giaquinta <e.giaquinta@glauco.it>
31 * 32 *
32 * This program is free software; you can redistribute it and/or modify 33 * 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 34 * 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 35 * the Free Software Foundation; either version 3 of the License, or
35 * (at your option) any later version. 36 * (at your option) any later version.
36 * 37 *
37 * This program is distributed in the hope that it will be useful, 38 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of 39 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 40 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43 * along with this program; if not, write to the Free Software 44 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 45 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
45 *----------------------------------------------------------------------*/ 46 *----------------------------------------------------------------------*/
46 47
47/*{{{ includes: */ 48/*{{{ includes: */
48#include "../config.h" /* NECESSARY */ 49#include "../config.h"
49#include "rxvt.h" /* NECESSARY */ 50#include "rxvt.h"
51#include "rxvtperl.h"
50#include "version.h" 52#include "version.h"
51#include "command.h" 53#include "command.h"
52 54
53#ifdef KEYSYM_RESOURCE 55#ifdef KEYSYM_RESOURCE
54# include "keyboard.h" 56# include "keyboard.h"
55#endif 57#endif
56 58
57#include <csignal> 59#include <signal.h>
60
61#if LINUX_YIELD_HACK
62# include <time.h>
63#endif
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)
93 XK_Shift_L, 0x21e7, 96 XK_Shift_L, 0x21e7,
94 XK_Shift_R, 0x21e7, 97 XK_Shift_R, 0x21e7,
95 98
96 XK_Shift_Lock, 0x21eb, 99 XK_Shift_Lock, 0x21eb,
97 XK_ISO_Lock, 0x21eb, 100 XK_ISO_Lock, 0x21eb,
98 XK_ISO_Lock, 0x21eb,
99 XK_Caps_Lock, 0x21ec, 101 XK_Caps_Lock, 0x21ec,
100 XK_Num_Lock, 0x21ed, 102 XK_Num_Lock, 0x21ed,
101 XK_ISO_Level3_Shift, 0x21ee, 103 XK_ISO_Level3_Shift, 0x21ee,
102 XK_ISO_Level3_Lock, 0x21ef, 104 XK_ISO_Level3_Lock, 0x21ef,
103 XK_ISO_Group_Lock, 0x21f0, 105 XK_ISO_Group_Lock, 0x21f0,
129 XK_KP_Space, 0x2422, 131 XK_KP_Space, 0x2422,
130#endif 132#endif
131 0, 133 0,
132}; 134};
133 135
134void 136void ecb_cold
135rxvt_term::iso14755_54 (int x, int y) 137rxvt_term::iso14755_54 (int x, int y)
136{ 138{
137 x = Pixel2Col (x); 139 x = Pixel2Col (x);
138 y = Pixel2Row (y); 140 y = Pixel2Row (y);
139 141
140 if (x < 0 || x >= TermWin.ncol 142 if (!IN_RANGE_EXC (x, 0, ncol)
141 || y < 0 || y >= TermWin.nrow) 143 || !IN_RANGE_EXC (y, 0, nrow))
142 return; 144 return;
143 145
144 for (;;) 146 for (;;)
145 { 147 {
146 text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x]; 148 const line_t &l = ROW(y + view_start);
149
150 text_t t = l.t[x];
147 151
148 if (t != NOCHAR || !x) 152 if (t != NOCHAR || !x)
149 { 153 {
150 iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x], 154 iso14755_51 (l.t[x], l.r[x], x, y, view_start);
151 screen.rend[y + TermWin.saveLines - TermWin.view_start][x]);
152 iso14755buf = ISO_14755_54; 155 iso14755buf = ISO_14755_54;
153 break; 156 break;
154 } 157 }
155 158
156 x--; 159 x--;
157 } 160 }
158
159} 161}
160#endif
161 162
162#if ENABLE_OVERLAY 163void ecb_cold
163void
164rxvt_term::iso14755_51 (unicode_t ch, rend_t r) 164rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y, int y2)
165{ 165{
166 rxvt_fontset *fs = FONTSET (r); 166 rxvt_fontset *fs = FONTSET (r);
167 rxvt_font *f = (*fs)[fs->find_font (ch)];
168 wchar_t *chr, *alloc, ch2; 167 wchar_t *chr, *alloc, ch2, **fname;
169 int len; 168 int len;
170 169
171#if ENABLE_COMBINING 170# if ENABLE_COMBINING
172 if (IS_COMPOSE (ch)) 171 if (IS_COMPOSE (ch))
173 { 172 {
174 len = rxvt_composite.expand (ch, 0); 173 len = rxvt_composite.expand (ch, 0);
175 alloc = chr = new wchar_t[len]; 174 alloc = chr = new wchar_t[len];
176 rxvt_composite.expand (ch, chr); 175 rxvt_composite.expand (ch, chr);
177 } 176 }
178 else 177 else
179#endif 178# endif
180 { 179 {
181 ch2 = ch; 180 ch2 = ch;
182 181
183 alloc = 0; 182 alloc = 0;
184 chr = &ch2; 183 chr = &ch2;
185 len = 1; 184 len = 1;
186 } 185 }
187 186
188 int width = strlen (f->name); 187 char rowcol[40];
188 snprintf (rowcol, sizeof rowcol, "col %d row %d @%d", x, y, y2);
189 189
190 scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1); 190 char attr[80]; // plenty
191
192 sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s",
193 (int)r,
194 fgcolor_of (r), bgcolor_of (r),
195 r & RS_Bold ? " bold" : "",
196 r & RS_Italic ? " italic" : "",
197 r & RS_Blink ? " blink" : "",
198 r & RS_RVid ? " rvid" : "",
199 r & RS_Uline ? " uline" : "",
200 r & RS_Careful ? " careful" : "");
201
202 int width = 0;
203 fname = rxvt_temp_buf<wchar_t *> (len);
204 for (int i = 0; i < len; i++)
205 {
206 rxvt_font *f = (*fs)[fs->find_font_idx (chr[i])];
207 fname[i] = rxvt_utf8towcs (f->name);
208 max_it (width, wcswidth (fname[i], wcslen (fname[i])));
209 }
210
211 max_it (width, strlen (attr));
212
213 if (y >= 0)
214 {
215 y = (y >= nrow - len - 5 && x < width + 2) ? 0 : -1;
216 x = 0;
217 }
218
219 scr_overlay_new (x, y, width, len * 2 + 2);
220
221 scr_overlay_set (0, 0, rowcol);
191 222
192 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); 223 r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r));
193 224
194 for (int y = 0; y < len; y++) 225 for (int y = 0; y < len; y++)
195 { 226 {
196 char buf[9]; 227 char buf[9];
197 228
198 ch = *chr++; 229 ch = *chr++;
199 230
200 sprintf (buf, "%8x", ch); 231 sprintf (buf, "%8x", ch);
201 scr_overlay_set (0, y, buf); 232 scr_overlay_set (0, y + 1, buf);
202 scr_overlay_set (9, y, '='); 233 scr_overlay_set (9, y + 1, '=');
203#if !UNICODE3 234# if !UNICODE_3
204 if (ch >= 0x10000) 235 if (ch >= 0x10000)
205 ch = 0xfffd; 236 ch = 0xfffd;
206#endif 237# endif
207 scr_overlay_set (11, y, ch, r); 238 scr_overlay_set (11, y + 1, ch, r);
239
240 if (WCWIDTH (ch) >= 2)
208 scr_overlay_set (12, y, NOCHAR, r); 241 scr_overlay_set (12, y + 1, NOCHAR, r);
209 } 242 }
210 243
244// {
245// char buf[4+4+3+1];
246// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y);
247// scr_overlay_set (0, 0, buf);
248// }
211 scr_overlay_set (0, len, f->name); 249 scr_overlay_set (0, len + 1, attr);
250 for (int i = 0; i < len; i++)
251 {
252 scr_overlay_set (0, len + 2 + i, fname[i]);
253 free (fname[i]);
254 }
212 255
213#if ENABLE_COMBINING 256# if ENABLE_COMBINING
214 if (alloc) 257 if (alloc)
215 delete [] alloc; 258 delete [] alloc;
216#endif 259# endif
217} 260}
218#endif 261#endif
219 262
220void 263void ecb_cold
221rxvt_term::commit_iso14755 () 264rxvt_term::commit_iso14755 ()
222{ 265{
223 wchar_t ch[2];
224
225 ch[0] = iso14755buf & ISO_14755_MASK; 266 wchar_t ch = iso14755buf & ISO_14755_MASK;
226 ch[1] = 0;
227 267
228 if (iso14755buf & ISO_14755_51) 268 if (iso14755buf & ISO_14755_51)
229 { 269 {
230 char mb[16]; 270 char mb[MB_LEN_MAX];
231 int len; 271 int len;
232 272
233 // allow verbatim 0-bytes and control-bytes to be entered 273 // allow verbatim 0-bytes and control-bytes to be entered
234 if (ch[0] >= 0x20) 274 if (ch >= 0x20)
235 len = wcstombs (mb, ch, 16); 275 len = wctomb (mb, ch);
236 else 276 else
237 { 277 {
238 mb[0] = ch[0]; 278 mb[0] = ch;
239 len = 1; 279 len = 1;
240 } 280 }
241 281
242 if (len > 0) 282 if (len > 0)
243 tt_write ((unsigned char *)mb, len); 283 tt_write (mb, len);
244 else 284 else
245 scr_bell (); 285 scr_bell ();
246 } 286 }
247 287
248 iso14755buf = 0; 288 iso14755buf = 0;
249} 289}
250 290
251int 291static int ecb_cold
252rxvt_term::hex_keyval (XKeyEvent &ev) 292hex_keyval (XKeyEvent &ev)
253{ 293{
254 // check wether this event corresponds to a hex digit 294 // check whether this event corresponds to a hex digit
255 // if the modifiers had not been pressed. 295 // if the modifiers had not been pressed.
256 for (int index = 0; index < 8; index++) 296 for (int index = 0; index < 8; index++)
257 { 297 {
258 KeySym k = XLookupKeysym (&ev, index); 298 KeySym k = XLookupKeysym (&ev, index);
259 299
265 305
266 return -1; 306 return -1;
267} 307}
268#endif 308#endif
269 309
270/*{{{ Convert the keypress event into a string */ 310static inline KeySym ecb_cold
271void 311translate_keypad (KeySym keysym, bool kp)
312{
313#ifdef XK_KP_Home
314 static const KeySym keypadtrans[] = {
315 XK_KP_7, // XK_KP_Home
316 XK_KP_4, // XK_KP_Left
317 XK_KP_8, // XK_KP_Up
318 XK_KP_6, // XK_KP_Right
319 XK_KP_2, // XK_KP_Down
320 XK_KP_9, // XK_KP_Prior
321 XK_KP_3, // XK_KP_Next
322 XK_KP_1, // XK_KP_End
323 XK_KP_5, // XK_KP_Begin
324 };
325
326 if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin))
327 {
328 unsigned int index = keysym - XK_KP_Home;
329 keysym = kp ? keypadtrans[index] : XK_Home + index;
330 }
331 else if (keysym == XK_KP_Insert)
332 keysym = kp ? XK_KP_0 : XK_Insert;
333# ifndef NO_DELETE_KEY
334 else if (keysym == XK_KP_Delete)
335 keysym = kp ? XK_KP_Decimal : XK_Delete;
336# endif
337#endif
338 return keysym;
339}
340
341static inline int ecb_cold
342map_function_key (KeySym keysym)
343{
344 int param = 0;
345
346 if (IN_RANGE_INC (keysym, XK_F1, XK_F35))
347 {
348 param = 11 + keysym - XK_F1;
349 if (keysym >= XK_F17)
350 param += 4;
351 else if (keysym >= XK_F15)
352 param += 3;
353 else if (keysym >= XK_F11)
354 param += 2;
355 else if (keysym >= XK_F6)
356 param += 1;
357 }
358 else
359 switch (keysym)
360 {
361 case XK_Find:
362 param = 1;
363 break;
364 case XK_Insert:
365 param = 2;
366 break;
367#ifdef DXK_Remove
368 case DXK_Remove:
369#endif
370 case XK_Execute:
371 param = 3;
372 break;
373 case XK_Select:
374 param = 4;
375 break;
376 case XK_Prior:
377 param = 5;
378 break;
379 case XK_Next:
380 param = 6;
381 break;
382 case XK_Home:
383 param = 7;
384 break;
385 case XK_End:
386 param = 8;
387 break;
388 case XK_Help:
389 param = 28;
390 break;
391 case XK_Menu:
392 param = 29;
393 break;
394 }
395 return param;
396}
397
398static inline wchar_t *
399rxvt_wcsdup (const wchar_t *str, int len)
400{
401 wchar_t *r = (wchar_t *)rxvt_malloc ((len + 1) * sizeof (wchar_t));
402 memcpy (r, str, len * sizeof (wchar_t));
403 r[len] = 0;
404 return r;
405}
406
407void ecb_cold
272rxvt_term::lookup_key (XKeyEvent &ev) 408rxvt_term::key_press (XKeyEvent &ev)
273{ 409{
274 int ctrl, meta, shft, len; 410 int ctrl, meta, shft, len;
275 unsigned int newlen; 411 KeySym keysym = NoSymbol;
276 KeySym keysym; 412 char rkbuf[KBUFSZ + 1];
277#ifdef DEBUG_CMD 413 char *kbuf = rkbuf + 1;
278 static int debug_key = 1; /* accessible by a debugger only */ 414
415#if ISO_14755
416 if (iso14755buf & ISO_14755_52)
417 return;
279#endif 418#endif
280 int valid_keysym;
281 unsigned char kbuf[KBUFSZ];
282 419
283 /* 420 /*
284 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an 421 * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an
285 * escape sequence to toggle the Keypad. 422 * escape sequence to toggle the Keypad.
286 * 423 *
288 */ 425 */
289 shft = ev.state & ShiftMask; 426 shft = ev.state & ShiftMask;
290 ctrl = ev.state & ControlMask; 427 ctrl = ev.state & ControlMask;
291 meta = ev.state & ModMetaMask; 428 meta = ev.state & ModMetaMask;
292 429
293 if (numlock_state || (ev.state & ModNumLockMask))
294 {
295 numlock_state = (ev.state & ModNumLockMask);
296 PrivMode ((!numlock_state), PrivMode_aplKP);
297 }
298
299 kbuf[0] = 0; 430 kbuf[0] = 0;
300 431
301#ifdef USE_XIM 432#if USE_XIM
302 if (Input_Context) 433 if (Input_Context)
303 { 434 {
304 Status status_return; 435 Status status_return;
305 436
306#if 0 437#if 0
307#ifdef X_HAVE_UTF8_STRING 438#ifdef X_HAVE_UTF8_STRING
308 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful 439 if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful
309 len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, 440 len = Xutf8LookupString (Input_Context, &ev, kbuf,
310 KBUFSZ, &keysym, &status_return); 441 KBUFSZ, &keysym, &status_return);
311 else 442 else
312#endif 443#endif
313#endif 444#endif
314 { 445 {
316 447
317 // the XOpenIM manpage lies about hardcoding the locale 448 // the XOpenIM manpage lies about hardcoding the locale
318 // at the point of XOpenIM, so temporarily switch locales 449 // at the point of XOpenIM, so temporarily switch locales
319 if (rs[Rs_imLocale]) 450 if (rs[Rs_imLocale])
320 SET_LOCALE (rs[Rs_imLocale]); 451 SET_LOCALE (rs[Rs_imLocale]);
452
321 // assume wchar_t == unicode or better 453 // assume wchar_t == unicode or better
322 len = XwcLookupString (Input_Context, &ev, wkbuf, 454 len = XwcLookupString (Input_Context, &ev, wkbuf,
323 KBUFSZ, &keysym, &status_return); 455 KBUFSZ, &keysym, &status_return);
456
324 if (rs[Rs_imLocale]) 457 if (rs[Rs_imLocale])
325 SET_LOCALE (locale); 458 SET_LOCALE (locale);
326 459
327 if (status_return == XLookupChars 460 if (status_return == XLookupChars
328 || status_return == XLookupBoth) 461 || status_return == XLookupBoth)
342 } 475 }
343 } 476 }
344 else 477 else
345 len = 0; 478 len = 0;
346 } 479 }
347
348 valid_keysym = status_return == XLookupKeySym
349 || status_return == XLookupBoth;
350 } 480 }
351 else 481 else
352#endif 482#endif
353 { 483 {
354 len = XLookupString (&ev, (char *)kbuf, KBUFSZ, &keysym, &compose); 484 len = XLookupString (&ev, kbuf, KBUFSZ, &keysym, &compose);
355 valid_keysym = keysym != NoSymbol; 485 }
486
487 if (keysym != NoSymbol)
356 } 488 {
489 KeySym orig_keysym = keysym;
357 490
358 if (valid_keysym) 491 /* Shift + F1 - F10 generates F11 - F20 */
492 if (shft && keysym >= XK_F1 && keysym <= XK_F10)
493 {
494 keysym += (XK_F11 - XK_F1);
495 shft = 0; /* turn off Shift */
496 }
497
498 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
499 {
500 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
501 unsigned int newlen = 1;
502
503 if (ev.state & ModNumLockMask)
504 kp = false;
505
506 keysym = translate_keypad (keysym, kp);
507
508 switch (keysym)
509 {
510#ifndef NO_BACKSPACE_KEY
511 case XK_BackSpace:
512 if (priv_modes & PrivMode_HaveBackSpace)
513 {
514 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
515 ^ !!ctrl) ? '\b' : '\177';
516 kbuf[1] = '\0';
517 }
518 else
519 strcpy (kbuf, rs[Rs_backspace_key]);
520 break;
521#endif
522#ifndef NO_DELETE_KEY
523 case XK_Delete:
524 strcpy (kbuf, rs[Rs_delete_key]);
525 break;
526#endif
527 case XK_Tab:
528 if (shft)
529 strcpy (kbuf, "\033[Z");
530 else
531 {
532#ifdef CTRL_TAB_MAKES_META
533 if (ctrl)
534 meta = 1;
535#endif
536#ifdef MOD4_TAB_MAKES_META
537 if (ev.state & Mod4Mask)
538 meta = 1;
539#endif
540 newlen = 0;
541 }
542 break;
543
544 case XK_Up: /* "\033[A" */
545 case XK_Down: /* "\033[B" */
546 case XK_Right: /* "\033[C" */
547 case XK_Left: /* "\033[D" */
548 strcpy (kbuf, "\033[Z");
549 kbuf[2] = "DACB"[keysym - XK_Left];
550 /* do Shift first */
551 if (shft)
552 kbuf[2] = "dacb"[keysym - XK_Left];
553 else if (ctrl)
554 {
555 kbuf[1] = 'O';
556 kbuf[2] = "dacb"[keysym - XK_Left];
557 }
558 else if (priv_modes & PrivMode_aplCUR)
559 kbuf[1] = 'O';
560 break;
561
562 case XK_KP_Enter:
563 /* allow shift to override */
564 if (kp)
565 {
566 strcpy (kbuf, "\033OM");
567 break;
568 }
569
570 /* FALLTHROUGH */
571
572 case XK_Return:
573 if (priv_modes & PrivMode_LFNL)
574 {
575 kbuf[0] = '\015';
576 kbuf[1] = '\012';
577 kbuf[2] = '\0';
578 }
579 else
580 {
581 kbuf[0] = '\015';
582 kbuf[1] = '\0';
583 }
584 break;
585
586 case XK_KP_F1: /* "\033OP" */
587 case XK_KP_F2: /* "\033OQ" */
588 case XK_KP_F3: /* "\033OR" */
589 case XK_KP_F4: /* "\033OS" */
590 strcpy (kbuf, "\033OP");
591 kbuf[2] += (keysym - XK_KP_F1);
592 break;
593
594 case XK_KP_Multiply: /* "\033Oj" : "*" */
595 case XK_KP_Add: /* "\033Ok" : "+" */
596 case XK_KP_Separator: /* "\033Ol" : "," */
597 case XK_KP_Subtract: /* "\033Om" : "-" */
598 case XK_KP_Decimal: /* "\033On" : "." */
599 case XK_KP_Divide: /* "\033Oo" : "/" */
600 case XK_KP_0: /* "\033Op" : "0" */
601 case XK_KP_1: /* "\033Oq" : "1" */
602 case XK_KP_2: /* "\033Or" : "2" */
603 case XK_KP_3: /* "\033Os" : "3" */
604 case XK_KP_4: /* "\033Ot" : "4" */
605 case XK_KP_5: /* "\033Ou" : "5" */
606 case XK_KP_6: /* "\033Ov" : "6" */
607 case XK_KP_7: /* "\033Ow" : "7" */
608 case XK_KP_8: /* "\033Ox" : "8" */
609 case XK_KP_9: /* "\033Oy" : "9" */
610 /* allow shift to override */
611 if (kp)
612 {
613 strcpy (kbuf, "\033Oj");
614 kbuf[2] += (keysym - XK_KP_Multiply);
615 }
616 else
617 {
618 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
619 kbuf[1] = '\0';
620 }
621 break;
622
623 default:
624 {
625 int param = map_function_key (keysym);
626 if (param > 0)
627 sprintf (kbuf,"\033[%d~", param);
628 else
629 newlen = 0;
630 }
631 break;
632 }
633
634 if (newlen)
635 len = strlen (kbuf);
636
637 if (len > 0)
638 {
639 /*
640 * pass Shift/Control indicators for function keys ending with `~'
641 *
642 * eg,
643 * Prior = "ESC[5~"
644 * Shift+Prior = "ESC[5$"
645 * Ctrl+Prior = "ESC[5^"
646 * Ctrl+Shift+Prior = "ESC[5@"
647 */
648 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
649 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
650
651 /*
652 * Pass meta for all function keys, if 'meta' option set
653 */
654#ifdef META8_OPTION
655 if (meta && (meta_char == 0x80))
656 kbuf[len - 1] |= 0x80;
657#endif
658 }
659
660 }
661 else if (ctrl && keysym == XK_minus)
662 {
663 len = 1;
664 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
665 }
666 else if (keysym == XK_ISO_Left_Tab)
667 {
668 strcpy (kbuf, "\033[Z");
669 len = 3;
670 }
671 else
672 {
673#ifdef META8_OPTION
674 /* set 8-bit on */
675 if (meta && (meta_char == 0x80))
676 {
677 char *ch;
678
679 for (ch = kbuf; ch < kbuf + len; ch++)
680 *ch |= 0x80;
681 }
682#endif
683 /* nil */ ;
684 }
685
686 keysym = orig_keysym;
687 }
688
689 /* escape prefix */
690 if (len && meta
691#ifdef META8_OPTION
692 && meta_char == C0_ESC
693#endif
694 )
695 {
696 *--kbuf = C0_ESC;
697 len++;
698 }
699
700 if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END)))
701 return;
702
703 if (keysym != NoSymbol)
359 { 704 {
360#ifdef KEYSYM_RESOURCE 705#ifdef KEYSYM_RESOURCE
361 if (keyboard->dispatch (this, keysym, ev.state)) 706 if (keyboard->dispatch (this, keysym, ev.state, kbuf, len))
362 return; 707 return;
363#endif 708#endif
364 709
365 if (TermWin.saveLines) 710 if (saveLines)
366 { 711 {
367#ifdef UNSHIFTED_SCROLLKEYS 712#ifdef UNSHIFTED_SCROLLKEYS
368 if (!ctrl && !meta) 713 if (!ctrl && !meta)
369#else 714#else
370 if (IS_SCROLL_MOD) 715 if (IS_SCROLL_MOD)
371#endif 716#endif
372 { 717 {
373 int lnsppg; 718 int lnsppg;
374 719
375#ifdef PAGING_CONTEXT_LINES 720#ifdef PAGING_CONTEXT_LINES
376 lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; 721 lnsppg = nrow - PAGING_CONTEXT_LINES;
377#else 722#else
378 lnsppg = TermWin.nrow * 4 / 5; 723 lnsppg = nrow * 4 / 5;
379#endif 724#endif
725 max_it (lnsppg, 1);
726
380 if (keysym == XK_Prior) 727 if (keysym == XK_Prior)
381 { 728 {
382 scr_page (UP, lnsppg); 729 scr_page (lnsppg);
383 return; 730 return;
384 } 731 }
385 else if (keysym == XK_Next) 732 else if (keysym == XK_Next)
386 { 733 {
387 scr_page (DN, lnsppg); 734 scr_page (-lnsppg);
388 return; 735 return;
389 } 736 }
390 } 737 }
391#ifdef SCROLL_ON_UPDOWN_KEYS 738#ifdef SCROLL_ON_UPDOWN_KEYS
392 if (IS_SCROLL_MOD) 739 if (IS_SCROLL_MOD)
393 { 740 {
394 if (keysym == XK_Up) 741 if (keysym == XK_Up)
395 { 742 {
396 scr_page (UP, 1); 743 scr_page (1);
397 return; 744 return;
398 } 745 }
399 else if (keysym == XK_Down) 746 else if (keysym == XK_Down)
400 { 747 {
401 scr_page (DN, 1); 748 scr_page (-1);
402 return; 749 return;
403 } 750 }
404 } 751 }
405#endif 752#endif
406#ifdef SCROLL_ON_HOMEEND_KEYS 753#ifdef SCROLL_ON_HOMEEND_KEYS
407 if (IS_SCROLL_MOD) 754 if (IS_SCROLL_MOD)
408 { 755 {
409 if (keysym == XK_Home) 756 if (keysym == XK_Home)
410 { 757 {
411 scr_move_to (0, 1); 758 scr_changeview (top_row);
412 return; 759 return;
413 } 760 }
414 else if (keysym == XK_End) 761 else if (keysym == XK_End)
415 { 762 {
416 scr_move_to (1, 0); 763 scr_changeview (0);
417 return; 764 return;
418 } 765 }
419 } 766 }
420#endif 767#endif
421 } 768 }
422 769
423 if (shft) 770 if (shft)
424 { 771 {
425 /* Shift + F1 - F10 generates F11 - F20 */
426 if (keysym >= XK_F1 && keysym <= XK_F10)
427 {
428 keysym += (XK_F11 - XK_F1);
429 shft = 0; /* turn off Shift */
430 }
431 else if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys)) 772 if (!ctrl && !meta && (priv_modes & PrivMode_ShiftKeys))
432 { 773 {
433 switch (keysym) 774 switch (keysym)
434 { 775 {
435 /* normal XTerm key bindings */ 776 /* normal XTerm key bindings */
436 case XK_Insert: /* Shift+Insert = paste mouse selection */ 777 case XK_Insert: /* Shift+Insert = paste mouse selection */
437 selection_request (ev.time, 0, 0); 778 selection_request (ev.time);
438 return; 779 return;
439#if TODO 780#if TODO
440 /* rxvt extras */ 781 /* rxvt extras */
441 case XK_KP_Add: /* Shift+KP_Add = bigger font */ 782 case XK_KP_Add: /* Shift+KP_Add = bigger font */
442 change_font (FONT_UP);
443 return; 783 return;
444 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ 784 case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */
445 change_font (FONT_DN);
446 return; 785 return;
447#endif 786#endif
448 } 787 }
449 } 788 }
450 } 789 }
451 790
791 if (ctrl && meta && (keysym == XK_c || keysym == XK_v))
792 {
793 if (keysym == XK_v)
794 selection_request (ev.time, Sel_Clipboard);
795 else if (selection.len > 0)
796 {
797 free (selection.clip_text);
798 selection.clip_text = rxvt_wcsdup (selection.text, selection.len);
799 selection.clip_len = selection.len;
800 selection_grab (CurrentTime, true);
801 }
802
803 return;
804 }
805
452#if ENABLE_FRILLS || ISO_14755 806#if ENABLE_FRILLS || ISO_14755
453 // ISO 14755 support 807 // ISO 14755 support
454 if (shft && ctrl) 808 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51))
455 { 809 {
456 int hv; 810 int hv;
457 811
458 if (iso14755buf & ISO_14755_51 812 if (iso14755buf & ISO_14755_51
459 && (keysym == XK_space || keysym == XK_KP_Space 813 && (keysym == XK_space || keysym == XK_KP_Space
461 { 815 {
462 commit_iso14755 (); 816 commit_iso14755 ();
463 iso14755buf = ISO_14755_51; 817 iso14755buf = ISO_14755_51;
464# if ISO_14755 818# if ISO_14755
465 iso14755_51 (0); 819 iso14755_51 (0);
820# endif
821 return;
822 }
823 else if (keysym == XK_BackSpace)
824 {
825 iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51;
826# if ISO_14755
827 iso14755_51 (iso14755buf & ISO_14755_MASK);
466# endif 828# endif
467 return; 829 return;
468 } 830 }
469 else if ((hv = hex_keyval (ev)) >= 0) 831 else if ((hv = hex_keyval (ev)) >= 0)
470 { 832 {
475# endif 837# endif
476 return; 838 return;
477 } 839 }
478 else 840 else
479 { 841 {
480# if ENABLE_OVERLAY 842# if ISO_14755
481 scr_overlay_off (); 843 scr_overlay_off ();
482# endif 844# endif
483 iso14755buf = 0; 845 iso14755buf = 0;
484 } 846 }
485 } 847 }
848 else if (option (Opt_iso14755) &&
486 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) 849 ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
487 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) 850 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))))
488 if (!(iso14755buf & ISO_14755_STARTED)) 851 if (!(iso14755buf & ISO_14755_STARTED))
489 { 852 {
490 iso14755buf |= ISO_14755_STARTED; 853 iso14755buf |= ISO_14755_STARTED;
491# if ENABLE_OVERLAY 854# if ISO_14755
492 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); 855 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
493 scr_overlay_set (0, 0, "ISO 14755 mode"); 856 scr_overlay_set (0, 0, "ISO 14755 mode");
494# endif 857# endif
495 } 858 }
496#endif 859#endif
497 860
498#ifdef PRINTPIPE 861#ifdef PRINTPIPE
499 if (keysym == XK_Print) 862 if (keysym == XK_Print)
500 { 863 {
501 scr_printscreen (ctrl | shft); 864 scr_printscreen (ctrl | shft);
502 return; 865 return;
503 } 866 }
504#endif 867#endif
505
506 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
507 {
508 {
509 newlen = 1;
510 switch (keysym)
511 {
512#ifndef NO_BACKSPACE_KEY
513 case XK_BackSpace:
514 if (priv_modes & PrivMode_HaveBackSpace)
515 {
516 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
517 ^ !!ctrl) ? '\b' : '\177';
518 kbuf[1] = '\0';
519 }
520 else
521 strcpy (kbuf, key_backspace);
522 break;
523#endif
524#ifndef NO_DELETE_KEY
525# ifdef XK_KP_Prior
526 case XK_KP_Delete:
527 /* allow shift to override */
528 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
529 {
530 strcpy (kbuf, "\033On");
531 break;
532 }
533 /* FALLTHROUGH */
534# endif
535 case XK_Delete:
536 strcpy (kbuf, key_delete);
537 break;
538#endif
539 case XK_Tab:
540 if (shft)
541 strcpy (kbuf, "\033[Z");
542 else
543 {
544#ifdef CTRL_TAB_MAKES_META
545 if (ctrl)
546 meta = 1;
547#endif
548#ifdef MOD4_TAB_MAKES_META
549 if (ev.state & Mod4Mask)
550 meta = 1;
551#endif
552 newlen = 0;
553 }
554 break;
555
556#ifdef XK_KP_Left
557 case XK_KP_Up: /* \033Ox or standard */
558 case XK_KP_Down: /* \033Or or standard */
559 case XK_KP_Right: /* \033Ov or standard */
560 case XK_KP_Left: /* \033Ot or standard */
561 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
562 {
563 strcpy (kbuf, "\033OZ");
564 kbuf[2] = "txvr"[keysym - XK_KP_Left];
565 break;
566 }
567 else
568 /* translate to std. cursor key */
569 keysym = XK_Left + (keysym - XK_KP_Left);
570 /* FALLTHROUGH */
571#endif
572 case XK_Up: /* "\033[A" */
573 case XK_Down: /* "\033[B" */
574 case XK_Right: /* "\033[C" */
575 case XK_Left: /* "\033[D" */
576 strcpy (kbuf, "\033[Z");
577 kbuf[2] = "DACB"[keysym - XK_Left];
578 /* do Shift first */
579 if (shft)
580 kbuf[2] = "dacb"[keysym - XK_Left];
581 else if (ctrl)
582 {
583 kbuf[1] = 'O';
584 kbuf[2] = "dacb"[keysym - XK_Left];
585 }
586 else if (priv_modes & PrivMode_aplCUR)
587 kbuf[1] = 'O';
588 break;
589
590#ifndef UNSHIFTED_SCROLLKEYS
591# ifdef XK_KP_Prior
592 case XK_KP_Prior:
593 /* allow shift to override */
594 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
595 {
596 strcpy (kbuf, "\033Oy");
597 break;
598 }
599 /* FALLTHROUGH */
600# endif
601 case XK_Prior:
602 strcpy (kbuf, "\033[5~");
603 break;
604# ifdef XK_KP_Next
605 case XK_KP_Next:
606 /* allow shift to override */
607 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
608 {
609 strcpy (kbuf, "\033Os");
610 break;
611 }
612 /* FALLTHROUGH */
613# endif
614 case XK_Next:
615 strcpy (kbuf, "\033[6~");
616 break;
617#endif
618 case XK_KP_Enter:
619 /* allow shift to override */
620 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
621 {
622 strcpy (kbuf, "\033OM");
623 break;
624 }
625
626 /* FALLTHROUGH */
627
628 case XK_Return:
629 if (priv_modes & PrivMode_LFNL)
630 {
631 kbuf[0] = '\015';
632 kbuf[1] = '\012';
633 kbuf[2] = '\0';
634 }
635 else
636 {
637 kbuf[0] = '\015';
638 kbuf[1] = '\0';
639 }
640 break;
641
642#ifdef XK_KP_Begin
643 case XK_KP_Begin:
644 strcpy (kbuf, "\033Ou");
645 break;
646
647#endif
648 case XK_KP_F1: /* "\033OP" */
649 case XK_KP_F2: /* "\033OQ" */
650 case XK_KP_F3: /* "\033OR" */
651 case XK_KP_F4: /* "\033OS" */
652 strcpy (kbuf, "\033OP");
653 kbuf[2] += (keysym - XK_KP_F1);
654 break;
655
656 case XK_KP_Multiply: /* "\033Oj" : "*" */
657 case XK_KP_Add: /* "\033Ok" : "+" */
658 case XK_KP_Separator: /* "\033Ol" : "," */
659 case XK_KP_Subtract: /* "\033Om" : "-" */
660 case XK_KP_Decimal: /* "\033On" : "." */
661 case XK_KP_Divide: /* "\033Oo" : "/" */
662 case XK_KP_0: /* "\033Op" : "0" */
663 case XK_KP_1: /* "\033Oq" : "1" */
664 case XK_KP_2: /* "\033Or" : "2" */
665 case XK_KP_3: /* "\033Os" : "3" */
666 case XK_KP_4: /* "\033Ot" : "4" */
667 case XK_KP_5: /* "\033Ou" : "5" */
668 case XK_KP_6: /* "\033Ov" : "6" */
669 case XK_KP_7: /* "\033Ow" : "7" */
670 case XK_KP_8: /* "\033Ox" : "8" */
671 case XK_KP_9: /* "\033Oy" : "9" */
672 /* allow shift to override */
673 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
674 {
675 strcpy (kbuf, "\033Oj");
676 kbuf[2] += (keysym - XK_KP_Multiply);
677 }
678 else
679 {
680 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
681 kbuf[1] = '\0';
682 }
683 break;
684
685 case XK_Find:
686 strcpy (kbuf, "\033[1~");
687 break;
688
689#ifdef XK_KP_End
690 case XK_KP_Insert:
691 /* allow shift to override */
692 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
693 {
694 strcpy (kbuf, "\033Op");
695 break;
696 }
697 /* FALLTHROUGH */
698#endif
699 case XK_Insert:
700 strcpy (kbuf, "\033[2~");
701 break;
702#ifdef DXK_Remove /* support for DEC remove like key */
703 case DXK_Remove:
704 /* FALLTHROUGH */
705#endif
706 case XK_Execute:
707 strcpy (kbuf, "\033[3~");
708 break;
709 case XK_Select:
710 strcpy (kbuf, "\033[4~");
711 break;
712#ifdef XK_KP_End
713 case XK_KP_End:
714 /* allow shift to override */
715 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
716 {
717 strcpy (kbuf, "\033Oq");
718 break;
719 }
720 /* FALLTHROUGH */
721#endif
722 case XK_End:
723 strcpy (kbuf, KS_END);
724 break;
725#ifdef XK_KP_Home
726 case XK_KP_Home:
727 /* allow shift to override */
728 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
729 {
730 strcpy (kbuf, "\033Ow");
731 break;
732 }
733 /* FALLTHROUGH */
734#endif
735 case XK_Home:
736 strcpy (kbuf, KS_HOME);
737 break;
738
739#define FKEY(n, fkey) \
740 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
741
742 case XK_F1: /* "\033[11~" */
743 case XK_F2: /* "\033[12~" */
744 case XK_F3: /* "\033[13~" */
745 case XK_F4: /* "\033[14~" */
746 case XK_F5: /* "\033[15~" */
747 FKEY (11, XK_F1);
748 break;
749 case XK_F6: /* "\033[17~" */
750 case XK_F7: /* "\033[18~" */
751 case XK_F8: /* "\033[19~" */
752 case XK_F9: /* "\033[20~" */
753 case XK_F10: /* "\033[21~" */
754 FKEY (17, XK_F6);
755 break;
756 case XK_F11: /* "\033[23~" */
757 case XK_F12: /* "\033[24~" */
758 case XK_F13: /* "\033[25~" */
759 case XK_F14: /* "\033[26~" */
760 FKEY (23, XK_F11);
761 break;
762 case XK_F15: /* "\033[28~" */
763 case XK_F16: /* "\033[29~" */
764 FKEY (28, XK_F15);
765 break;
766 case XK_Help: /* "\033[28~" */
767 FKEY (28, XK_Help);
768 break;
769 case XK_Menu: /* "\033[29~" */
770 FKEY (29, XK_Menu);
771 break;
772 case XK_F17: /* "\033[31~" */
773 case XK_F18: /* "\033[32~" */
774 case XK_F19: /* "\033[33~" */
775 case XK_F20: /* "\033[34~" */
776 case XK_F21: /* "\033[35~" */
777 case XK_F22: /* "\033[36~" */
778 case XK_F23: /* "\033[37~" */
779 case XK_F24: /* "\033[38~" */
780 case XK_F25: /* "\033[39~" */
781 case XK_F26: /* "\033[40~" */
782 case XK_F27: /* "\033[41~" */
783 case XK_F28: /* "\033[42~" */
784 case XK_F29: /* "\033[43~" */
785 case XK_F30: /* "\033[44~" */
786 case XK_F31: /* "\033[45~" */
787 case XK_F32: /* "\033[46~" */
788 case XK_F33: /* "\033[47~" */
789 case XK_F34: /* "\033[48~" */
790 case XK_F35: /* "\033[49~" */
791 FKEY (31, XK_F17);
792 break;
793#undef FKEY
794 default:
795 newlen = 0;
796 break;
797 }
798
799 if (newlen)
800 len = strlen (kbuf);
801 }
802
803 /*
804 * Pass meta for all function keys, if 'meta' option set
805 */
806#ifdef META8_OPTION
807 if (meta && (meta_char == 0x80) && len > 0)
808 kbuf[len - 1] |= 0x80;
809#endif
810
811 }
812 else if (ctrl && keysym == XK_minus)
813 {
814 len = 1;
815 kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */
816 }
817 else if (keysym == XK_ISO_Left_Tab)
818 {
819 strcpy (kbuf, "\033[Z");
820 len = 3;
821 }
822 else
823 {
824#ifdef META8_OPTION
825 /* set 8-bit on */
826 if (meta && (meta_char == 0x80))
827 {
828 unsigned char *ch;
829
830 for (ch = kbuf; ch < kbuf + len; ch++)
831 *ch |= 0x80;
832
833 meta = 0;
834 }
835#endif
836 /* nil */ ;
837 }
838 } 868 }
839 869
840 if (len <= 0) 870 if (len <= 0)
841 return; /* not mapped */ 871 return; /* not mapped */
842 872
843 if (options & Opt_scrollTtyKeypress) 873 tt_write_user_input (kbuf, (unsigned int)len);
844 if (TermWin.view_start) 874}
875
876void ecb_cold
877rxvt_term::key_release (XKeyEvent &ev)
878{
879#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
880 KeySym keysym;
881
882 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
883#endif
884
885#if ENABLE_FRILLS || ISO_14755
886 // ISO 14755 support
887 if (iso14755buf)
888 if (iso14755buf & ISO_14755_52)
845 { 889 {
846 TermWin.view_start = 0; 890# if ISO_14755
847 want_refresh = 1; 891 scr_overlay_off ();
892# endif
893# if ISO_14755
894 // iso14755 part 5.2 handling: release time
895 // first: controls
896 if ((ev.state & ControlMask)
897 && ((keysym >= 0x40 && keysym <= 0x5f)
898 || (keysym >= 0x61 && keysym <= 0x7f)))
899 {
900 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
901 commit_iso14755 ();
902
903 return;
904 }
905
906 for (unsigned short *i = iso14755_symtab; i[0]; i += 2)
907 if (i[0] == keysym)
908 {
909 iso14755buf = ISO_14755_51 | i[1];
910 commit_iso14755 ();
911
912 return;
913 }
914
915 scr_bell ();
916# endif
917 iso14755buf = 0;
918
919 return;
848 } 920 }
849 921 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
850 /* 922 {
851 * these modifications only affect the static keybuffer 923# if ISO_14755
852 * pass Shift/Control indicators for function keys ending with `~' 924 scr_overlay_off ();
853 *
854 * eg,
855 * Prior = "ESC[5~"
856 * Shift+Prior = "ESC[5$"
857 * Ctrl+Prior = "ESC[5^"
858 * Ctrl+Shift+Prior = "ESC[5@"
859 * Meta adds an Escape prefix (with META8_OPTION, if meta == <escape>).
860 */
861 if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~')
862 kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~'));
863
864 /* escape prefix */
865 if (meta
866#ifdef META8_OPTION
867 && meta_char == C0_ESC
868#endif 925# endif
869 ) 926 if (iso14755buf & ISO_14755_51)
870 { 927 commit_iso14755 ();
871 const unsigned char ch = C0_ESC; 928#if ISO_14755
872 tt_write (&ch, 1); 929 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
873 } 930 {
931 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
874 932
875#if defined(DEBUG_CMD) 933 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
876 /* Display keyboard buffer contents */ 934 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
877 unsigned char *p; 935 }
878 int i;
879
880 fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len);
881 for (i = 0, p = kbuf; i < len; i++, p++)
882 fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p);
883 fprintf (stderr, "'\n");
884#endif /* DEBUG_CMD */
885 tt_write (kbuf, (unsigned int)len);
886}
887/*}}} */
888
889#if MENUBAR_MAX || defined (KEYSYM_RESOURCE)
890/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */
891/* attempt to `write' count to the input buffer */
892unsigned int
893rxvt_term::cmd_write (const unsigned char *str, unsigned int count)
894{
895 unsigned int n, s;
896
897 n = cmdbuf_ptr - cmdbuf_base;
898 s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp;
899
900 if (n > 0 && s < count)
901 {
902 memmove (cmdbuf_base, cmdbuf_ptr,
903 (unsigned int) (cmdbuf_endp - cmdbuf_ptr));
904 cmdbuf_ptr = cmdbuf_base;
905 cmdbuf_endp -= n;
906 s += n;
907 }
908
909 if (count > s)
910 {
911 rxvt_warn ("data loss: cmd_write too large, continuing.\n");
912 count = s;
913 }
914
915 for (; count--;)
916 *cmdbuf_endp++ = *str++;
917
918 cmd_parse ();
919
920 return 0;
921}
922#endif 936# endif
937 else
938 iso14755buf = 0;
939 }
940#endif
941
942 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
943 return;
944
945#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
946 if (!(ev.state & ControlMask))
947 slip_wheel_ev.stop ();
948 else if (keysym == XK_Control_L || keysym == XK_Control_R)
949 mouse_slip_wheel_speed = 0;
950#endif
951}
923 952
924void 953void
925rxvt_term::flush () 954rxvt_term::flush ()
926{ 955{
927 flush_ev.stop (); 956 flush_ev.stop ();
928 957
929#ifdef TRANSPARENT 958#ifdef HAVE_IMG
930 if (want_full_refresh) 959 if (bg_flags & BG_NEEDS_REFRESH)
931 { 960 {
932 want_full_refresh = 0; 961 bg_flags &= ~BG_NEEDS_REFRESH;
933 scr_clear ();
934 scr_touch (false); 962 scr_touch (false);
935 } 963 }
936#endif 964#endif
937 965
938 if (want_refresh) 966 if (want_refresh)
939 { 967 {
968 if (SHOULD_INVOKE (HOOK_LINE_UPDATE))
969 {
970 int row = view_start;
971 int end_row = row + nrow;
972
973 while (row > top_row && ROW (row - 1).is_longer ())
974 --row;
975
976 do
977 {
978 int start_row = row;
979 line_t *l;
980
981 do
982 {
983 l = &ROW (row++);
984
985 if (!(l->f & LINE_FILTERED))
986 {
987 // line not filtered, mark it as filtered
988 l->f |= LINE_FILTERED;
989 while (l->is_longer ())
990 {
991 l = &ROW (row++);
992 l->f |= LINE_FILTERED;
993 }
994
995 // and filter it
996 HOOK_INVOKE ((this, HOOK_LINE_UPDATE, DT_INT, start_row, DT_END));
997
998 break;
999 }
1000 }
1001 while (l->is_longer () && row < end_row);
1002 }
1003 while (row < end_row);
1004 }
1005
940 scr_refresh (refresh_type); 1006 scr_refresh ();
941 scrollbar_show (1); 1007 scrollBar.show (1);
942#ifdef USE_XIM 1008#if USE_XIM
943 IMSendSpot (); 1009 im_send_spot ();
944#endif 1010#endif
945 } 1011 }
946 1012
947 display->flush (); 1013 display->flush ();
948} 1014}
949 1015
1016/* checks whether a refresh is requested and starts the refresh timer */
950void 1017void
951rxvt_term::check_cb (check_watcher &w) 1018rxvt_term::refresh_check ()
952{ 1019{
953 SET_R (this); 1020 if (want_refresh && !flush_ev.is_active ())
954 SET_LOCALE (locale); 1021 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
955 1022
956 display->flush (); 1023 display->flush ();
957
958 if (want_refresh && !flush_ev.active)
959 flush_ev.start (NOW + 0.01);
960} 1024}
961 1025
962void 1026void
963rxvt_term::flush_cb (time_watcher &w) 1027rxvt_term::flush_cb (ev::timer &w, int revents)
964{ 1028{
965 SET_R (this); 1029 make_current ();
966 SET_LOCALE (locale);
967 1030
968 refresh_limit = 1;
969 refresh_count = 0; 1031 refresh_count = 0;
970 flush (); 1032 flush ();
971} 1033}
972 1034
973#ifdef CURSOR_BLINK 1035#ifdef CURSOR_BLINK
974void 1036void
1037rxvt_term::cursor_blink_reset ()
1038{
1039 if (!focus)
1040 return;
1041
1042 if (hidden_cursor)
1043 {
1044 hidden_cursor = 0;
1045 want_refresh = 1;
1046 }
1047
1048 if (option (Opt_cursorBlink) || (priv_modes & PrivMode_BlinkingCursor))
1049 cursor_blink_ev.again ();
1050 else
1051 cursor_blink_ev.stop ();
1052}
1053
1054void
975rxvt_term::cursor_blink_cb (time_watcher &w) 1055rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
976{ 1056{
977 hidden_cursor = !hidden_cursor; 1057 hidden_cursor = !hidden_cursor;
978 want_refresh = 1; 1058 want_refresh = 1;
979 1059 refresh_check ();
980 w.start (w.at + BLINK_INTERVAL);
981} 1060}
982#endif 1061#endif
983 1062
984#ifdef TEXT_BLINK 1063#ifdef TEXT_BLINK
985void 1064void
986rxvt_term::text_blink_cb (time_watcher &w) 1065rxvt_term::text_blink_cb (ev::timer &w, int revents)
987{ 1066{
988 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1067 if (scr_refresh_rend (RS_Blink, RS_Blink))
989 { 1068 {
990 hidden_text = !hidden_text; 1069 hidden_text = !hidden_text;
991 want_refresh = 1; 1070 want_refresh = 1;
992 w.start (w.at + TEXT_BLINK_INTERVAL); 1071 refresh_check ();
993 } 1072 }
1073 else
1074 w.stop ();
994} 1075}
995#endif 1076#endif
996 1077
997#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1078#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
998void 1079void
999rxvt_term::cont_scroll_cb (time_watcher &w) 1080rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1000{ 1081{
1001 if ((scrollbar_isUp() || scrollbar_isDn()) && 1082 if ((scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN)
1002 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1083 && scr_page (scrollBar.state == SB_STATE_UP ? UP : DN, 1))
1003 { 1084 {
1004 refresh_type |= SMOOTH_REFRESH;
1005 want_refresh = 1; 1085 want_refresh = 1;
1006 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1086 refresh_check ();
1007 } 1087 }
1088 else
1089 w.stop ();
1008} 1090}
1009#endif 1091#endif
1010 1092
1011#ifdef SELECTION_SCROLLING 1093#ifdef SELECTION_SCROLLING
1012void 1094void
1013rxvt_term::sel_scroll_cb (time_watcher &w) 1095rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1014{ 1096{
1015 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1097 if (scr_page (scroll_selection_lines))
1016 { 1098 {
1017 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1099 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1018 refresh_type |= SMOOTH_REFRESH;
1019 want_refresh = 1; 1100 want_refresh = 1;
1020 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1101 refresh_check ();
1021 } 1102 }
1103 else
1104 w.stop ();
1022} 1105}
1023#endif 1106#endif
1024 1107
1025#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1108#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1026void 1109void
1027rxvt_term::slip_wheel_cb (time_watcher &w) 1110rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1028{ 1111{
1029 if (mouse_slip_wheel_speed == 0 1112 if (scr_page (mouse_slip_wheel_speed))
1030 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1031 : scr_page (UP, mouse_slip_wheel_speed))
1032 { 1113 {
1033 if (TermWin.view_start == TermWin.nscrolled ||
1034 TermWin.view_start == 0)
1035 mouse_slip_wheel_speed = 0;
1036
1037 refresh_type |= SMOOTH_REFRESH;
1038 want_refresh = 1; 1114 want_refresh = 1;
1039 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1115 refresh_check ();
1116 }
1117
1118 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1040 } 1119 {
1120 mouse_slip_wheel_speed = 0;
1121 w.stop ();
1122 }
1123}
1124#endif
1125
1126#if LINUX_YIELD_HACK
1127static struct event_handler
1128{
1129 ev::prepare yield_ev;
1130
1131 void yield_cb (ev::prepare &w, int revents)
1132 {
1133 // this should really be sched_yield(), but the linux guys thought
1134 // that giving a process calling sched_yield () less cpu time than
1135 // ones with high nice levels is a useful thing to do. It surely is is
1136 // allowed by the sus... as is returning ENOSYS.
1137 // since the linux guys additionally thought that breaking the only
1138 // known workaround against their unusable sched_yield hack is cool,
1139 // we just nanosleep a bit and hope for the best.
1140
1141 struct timespec ts = { 0, 1000 };
1142 nanosleep (&ts, 0);
1143
1144 w.stop ();
1145 }
1146
1147 event_handler ()
1148 : yield_ev (this, &event_handler::yield_cb)
1149 {
1150 }
1151} event_handler;
1152#endif
1153
1154/* make sure all the cmd data is at beginning of cmdbuf */
1155void
1156rxvt_term::cmdbuf_reify ()
1157{
1158 if (cmdbuf_ptr == cmdbuf_base)
1159 return;
1160
1161 ssize_t used = cmdbuf_endp - cmdbuf_ptr;
1162
1163 memmove (cmdbuf_base, cmdbuf_ptr, used);
1164 cmdbuf_ptr = cmdbuf_base;
1165 cmdbuf_endp = cmdbuf_ptr + used;
1166
1167}
1168
1169#if defined (KEYSYM_RESOURCE)
1170void
1171rxvt_term::cmdbuf_append (const char *str, size_t count)
1172{
1173 cmdbuf_reify ();
1174
1175 size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp;
1176
1177 if (count > avail)
1178 return;
1179
1180 memcpy (cmdbuf_endp, str, count);
1181 cmdbuf_endp += count;
1182
1183 cmd_parse ();
1041} 1184}
1042#endif 1185#endif
1043 1186
1044bool 1187bool
1045rxvt_term::pty_fill () 1188rxvt_term::pty_fill ()
1046{ 1189{
1047 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 1190 cmdbuf_reify ();
1048 1191
1049 if (CBUFSIZ == n) 1192 size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp;
1050 { 1193
1051 rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); 1194 if (!avail)
1052 n = 0;
1053 } 1195 {
1054 1196 // normally this indicates a "too long" command sequence - just drop the data we have
1055 memmove (cmdbuf_base, cmdbuf_ptr, n);
1056 cmdbuf_ptr = cmdbuf_base; 1197 cmdbuf_ptr = cmdbuf_base;
1057 cmdbuf_endp = cmdbuf_ptr + n; 1198 cmdbuf_endp = cmdbuf_ptr;
1199 avail = CBUFSIZ;
1200 }
1058 1201
1059 n = read (pty.pty, cmdbuf_endp, CBUFSIZ - n); 1202 ssize_t r = read (pty->pty, cmdbuf_endp, avail);
1060 1203
1061 if (n > 0) 1204 if (r > 0)
1062 { 1205 {
1063 cmdbuf_endp += n; 1206 cmdbuf_endp += r;
1064 return true; 1207 return true;
1065 } 1208 }
1066 else if (n < 0 && errno != EAGAIN) 1209 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1210 {
1211#if LINUX_YIELD_HACK
1212 if (display->is_local)
1213 event_handler.yield_ev.start ();
1214#endif
1215 }
1216 else
1217 {
1218 pty_ev.stop ();
1219
1220 if (!option (Opt_hold))
1067 destroy (); 1221 destroy ();
1068 1222 }
1223
1069 return false; 1224 return false;
1070} 1225}
1071 1226
1072void 1227void
1073rxvt_term::pty_cb (io_watcher &w, short revents) 1228rxvt_term::pty_cb (ev::io &w, int revents)
1074{ 1229{
1075 SET_R (this); 1230 make_current ();
1076 SET_LOCALE (locale);
1077 1231
1078 if (revents & EVENT_READ) 1232 if (revents & ev::READ)
1079 // loop, but don't allow a single term to monopolize us 1233 // loop, but don't allow a single term to monopolize us
1080 while (pty_fill ()) 1234 for (int i = CBUFCNT; i-- && pty_fill (); )
1081 if (cmd_parse ()) 1235 cmd_parse ();
1082 break;
1083 1236
1084 if (revents & EVENT_WRITE) 1237 if (revents & ev::WRITE)
1085 pty_write (); 1238 pty_write ();
1086}
1087 1239
1088void 1240 refresh_check ();
1241}
1242
1243void ecb_cold
1089rxvt_term::pointer_unblank () 1244rxvt_term::pointer_unblank ()
1090{ 1245{
1091 XDefineCursor (display->display, TermWin.vt, TermWin_cursor); 1246 XDefineCursor (dpy, vt, TermWin_cursor);
1092 recolour_cursor (); 1247 recolor_cursor ();
1093 1248
1094#ifdef POINTER_BLANK 1249#ifdef POINTER_BLANK
1095 hidden_pointer = 0; 1250 hidden_pointer = 0;
1096 1251
1097 if (options & Opt_pointerBlank) 1252 if (option (Opt_pointerBlank))
1098 pointer_ev.start (NOW + pointerBlankDelay); 1253 pointer_ev.start (pointerBlankDelay);
1099#endif 1254#endif
1100} 1255}
1101 1256
1102#ifdef POINTER_BLANK 1257#ifdef POINTER_BLANK
1103void 1258void ecb_cold
1104rxvt_term::pointer_blank () 1259rxvt_term::pointer_blank ()
1105{ 1260{
1106 if (! (options & Opt_pointerBlank)) 1261 if (!option (Opt_pointerBlank))
1107 return; 1262 return;
1108 1263
1109 XDefineCursor (display->display, TermWin.vt, display->blank_cursor); 1264 XDefineCursor (dpy, vt, display->blank_cursor);
1110 XFlush (display->display); 1265 XFlush (dpy);
1111 1266
1112 hidden_pointer = 1; 1267 hidden_pointer = 1;
1113} 1268}
1114 1269
1115void 1270void ecb_cold
1116rxvt_term::pointer_cb (time_watcher &w) 1271rxvt_term::pointer_cb (ev::timer &w, int revents)
1117{ 1272{
1118 SET_R (this); 1273 make_current ();
1119 SET_LOCALE (locale);
1120 1274
1121 pointer_blank (); 1275 pointer_blank ();
1122} 1276}
1123#endif 1277#endif
1124 1278
1125void 1279void
1126rxvt_term::mouse_report (XButtonEvent &ev) 1280rxvt_term::mouse_report (XButtonEvent &ev)
1127{ 1281{
1128 int button_number, key_state = 0; 1282 int button_number, state = 0;
1129 int x, y; 1283 int x, y;
1284 bool release = ev.type == ButtonRelease;
1130 1285
1131 x = ev.x; 1286 x = Pixel2Col (ev.x) + 1;
1132 y = ev.y; 1287 y = Pixel2Row (ev.y) + 1;
1133 pixel_position (&x, &y);
1134 1288
1135 if (MEvent.button == AnyButton) 1289 if (ev.type == MotionNotify)
1136 button_number = 3; 1290 {
1137 else 1291 if (x == mouse_row && y == mouse_col)
1292 return;
1293
1294 mouse_row = x;
1295 mouse_col = y;
1296 state += 32;
1138 { 1297 }
1298
1139 button_number = MEvent.button - Button1; 1299 button_number = MEvent.button - Button1;
1140 /* add 0x3D for wheel events, like xterm does */ 1300 /* add 0x3D for wheel events, like xterm does */
1141 if (button_number >= 3) 1301 if (button_number >= 3)
1142 button_number += (64 - 3); 1302 button_number += 64 - 3;
1143 }
1144 1303
1145 if (priv_modes & PrivMode_MouseX10) 1304 if (priv_modes & PrivMode_MouseX10)
1146 { 1305 {
1147 /* 1306 /*
1148 * do not report ButtonRelease 1307 * do not report ButtonRelease
1149 * no state info allowed 1308 * no state info allowed
1150 */ 1309 */
1151 key_state = 0; 1310 if (release)
1152 if (button_number == 3)
1153 return; 1311 return;
1154 } 1312 }
1155 else 1313 else
1156 { 1314 {
1157 /* XTerm mouse reporting needs these values: 1315 /* XTerm mouse reporting needs these values:
1159 * 8 = Meta 1317 * 8 = Meta
1160 * 16 = Control 1318 * 16 = Control
1161 * plus will add in our own Double-Click reporting 1319 * plus will add in our own Double-Click reporting
1162 * 32 = Double Click 1320 * 32 = Double Click
1163 */ 1321 */
1164 key_state = ((MEvent.state & ShiftMask) ? 4 : 0) 1322 state += ((MEvent.state & ShiftMask) ? 4 : 0)
1165 + ((MEvent.state & ModMetaMask) ? 8 : 0) 1323 + ((MEvent.state & ModMetaMask) ? 8 : 0)
1166 + ((MEvent.state & ControlMask) ? 16 : 0); 1324 + ((MEvent.state & ControlMask) ? 16 : 0);
1167#ifdef MOUSE_REPORT_DOUBLECLICK 1325#ifdef MOUSE_REPORT_DOUBLECLICK
1168 key_state += ((MEvent.clicks > 1) ? 32 : 0); 1326 state += ((MEvent.clicks > 1) ? 32 : 0);
1169#endif 1327#endif
1170 } 1328 }
1329
1330 int code = 32 + (release ? 3 : button_number) + state;
1171 1331
1172#if DEBUG_MOUSEREPORT 1332#if DEBUG_MOUSEREPORT
1173 fprintf (stderr, "Mouse ["); 1333 fprintf (stderr, "Mouse [");
1174 if (key_state & 16) 1334 if (state & 16)
1175 fputc ('C', stderr); 1335 fputc ('C', stderr);
1176 if (key_state & 4) 1336 if (state & 4)
1177 fputc ('S', stderr); 1337 fputc ('S', stderr);
1178 if (key_state & 8) 1338 if (state & 8)
1179 fputc ('A', stderr); 1339 fputc ('A', stderr);
1180 if (key_state & 32) 1340 if (state & 32)
1181 fputc ('2', stderr); 1341 fputc ('2', stderr);
1182 fprintf (stderr, "]: <%d>, %d/%d\n", 1342 fprintf (stderr, "]: <%d>, %d/%d\n",
1183 button_number, 1343 button_number,
1184 x + 1, 1344 x,
1185 y + 1); 1345 y);
1186#endif 1346#endif
1187 1347
1348#if ENABLE_FRILLS
1349 if (priv_modes & PrivMode_ExtMouseSGR)
1350 tt_printf ("\033[<%d;%d;%d%c",
1351 button_number + state,
1352 x,
1353 y,
1354 release ? 'm' : 'M');
1355 else if (priv_modes & PrivMode_ExtMouseUrxvt)
1356 tt_printf ("\033[%d;%d;%dM",
1357 code,
1358 x,
1359 y);
1360 else if (priv_modes & PrivMode_ExtMouseUTF8)
1361 tt_printf ("\033[M%c%lc%lc",
1362 code,
1363 wint_t (32 + x),
1364 wint_t (32 + y));
1365 else
1366#endif
1188 tt_printf ("\033[M%c%c%c", 1367 tt_printf ("\033[M%c%c%c",
1189 (32 + button_number + key_state), 1368 code,
1190 (32 + x + 1), 1369 32 + x,
1191 (32 + y + 1)); 1370 32 + y);
1192} 1371}
1193
1194#ifdef USING_W11LIB
1195void
1196rxvt_W11_process_x_event (XEvent *ev)
1197{
1198 rxvt_t *r = rxvt_get_r ();
1199
1200 x_cb (*ev);
1201}
1202#endif
1203 1372
1204/*{{{ process an X event */ 1373/*{{{ process an X event */
1205void 1374void ecb_hot
1206rxvt_term::x_cb (XEvent &ev) 1375rxvt_term::x_cb (XEvent &ev)
1207{ 1376{
1208 dDisp; 1377 make_current ();
1209 1378
1210 SET_R (this); 1379 dLocal (Display *, dpy);
1211 SET_LOCALE (locale);
1212 1380
1213#if defined(CURSOR_BLINK) 1381 if (ev.xany.window == vt
1214 if ((options & Opt_cursorBlink) && ev.type == KeyPress) 1382 && SHOULD_INVOKE (HOOK_X_EVENT)
1215 { 1383 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1216 if (hidden_cursor) 1384 return;
1217 {
1218 hidden_cursor = 0;
1219 want_refresh = 1;
1220 }
1221 1385
1222 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1386 // for XQueryPointer
1223 }
1224#endif
1225
1226#if defined(POINTER_BLANK)
1227 if ((options & Opt_pointerBlank) && pointerBlankDelay > 0)
1228 {
1229 if (ev.type == MotionNotify
1230 || ev.type == ButtonPress
1231 || ev.type == ButtonRelease)
1232 if (hidden_pointer)
1233 pointer_unblank ();
1234
1235 if (ev.type == KeyPress && hidden_pointer == 0)
1236 pointer_blank ();
1237 }
1238#endif
1239
1240 Window unused_root, unused_child; 1387 Window unused_root, unused_child;
1241 int unused_root_x, unused_root_y; 1388 int unused_root_x, unused_root_y;
1242 unsigned int unused_mask; 1389 unsigned int unused_mask;
1243 1390
1244 switch (ev.type) 1391 switch (ev.type)
1245 { 1392 {
1246 case KeyPress: 1393 case KeyPress:
1247#if ISO_14755 1394 key_press (ev.xkey);
1248 if (!(iso14755buf & ISO_14755_52))
1249#endif
1250 lookup_key (ev.xkey);
1251
1252 break; 1395 break;
1253 1396
1254 case KeyRelease: 1397 case KeyRelease:
1255 { 1398 key_release (ev.xkey);
1256#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755
1257 KeySym ks;
1258
1259 ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1260#endif
1261
1262#if ENABLE_FRILLS || ISO_14755
1263 // ISO 14755 support
1264 if (iso14755buf)
1265 if (iso14755buf & ISO_14755_52)
1266 {
1267# if ENABLE_OVERLAY
1268 scr_overlay_off ();
1269# endif
1270# if ISO_14755
1271 // iso14755 part 5.2 handling: release time
1272 // first: controls
1273 if ((ev.xkey.state & ControlMask)
1274 && ((ks >= 0x40 && ks <= 0x5f)
1275 || (ks >= 0x61 && ks <= 0x7f)))
1276 {
1277 iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f);
1278 commit_iso14755 ();
1279 return; // case-break;
1280 }
1281
1282 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1283 if (i[0] == ks)
1284 {
1285 iso14755buf = ISO_14755_51 | i[1];
1286 commit_iso14755 ();
1287 return; // case-break;
1288 }
1289
1290 scr_bell ();
1291# endif
1292 iso14755buf = 0;
1293 break;
1294 }
1295 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1296 {
1297# if ENABLE_OVERLAY
1298 scr_overlay_off ();
1299# endif
1300 if (iso14755buf & ISO_14755_51)
1301 commit_iso14755 ();
1302#if ISO_14755
1303 else if (iso14755buf & ISO_14755_STARTED)
1304 {
1305 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1306
1307 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1308 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1309 }
1310# endif
1311 else
1312 iso14755buf = 0;
1313 }
1314#endif
1315
1316#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1317 if (!(ev.xkey.state & ControlMask))
1318 slip_wheel_ev.stop ();
1319 else if (ks == XK_Control_L || ks == XK_Control_R)
1320 mouse_slip_wheel_speed = 0;
1321#endif
1322 break; 1399 break;
1323 }
1324 1400
1325 case ButtonPress: 1401 case ButtonPress:
1326 button_press (ev.xbutton); 1402 button_press (ev.xbutton);
1327 break; 1403 break;
1328 1404
1330 button_release (ev.xbutton); 1406 button_release (ev.xbutton);
1331 break; 1407 break;
1332 1408
1333 case ClientMessage: 1409 case ClientMessage:
1334 if (ev.xclient.format == 32 1410 if (ev.xclient.format == 32
1411 && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END)))
1412 {
1335 && ev.xclient.message_type == xa[XA_WM_PROTOCOLS] 1413 if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS])
1414 {
1415 if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END)))
1416 {
1336 && ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) 1417 if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW])
1337 destroy (); 1418 {
1419 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1420 destroy ();
1421 }
1422#if ENABLE_EWMH
1423 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1424 XSendEvent (dpy, ev.xclient.window = display->root,
1425 False, SubstructureRedirectMask | SubstructureNotifyMask,
1426 &ev);
1427#endif
1428 }
1429 }
1338#if ENABLE_XEMBED 1430#if ENABLE_XEMBED
1339 else if (ev.xclient.format == 32
1340 && ev.xclient.message_type == xa[XA_XEMBED]) 1431 else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED])
1341 { 1432 {
1342 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) 1433 if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN)
1343 focus_in (); 1434 focus_in ();
1344 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1435 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1345 focus_out (); 1436 focus_out ();
1437 }
1438#endif
1346 } 1439 }
1347#endif
1348#ifdef OFFIX_DND
1349 /* OffiX Dnd (drag 'n' drop) protocol */
1350 else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL]
1351 && (ev.xclient.data.l[0] == DndFile
1352 || ev.xclient.data.l[0] == DndDir
1353 || ev.xclient.data.l[0] == DndLink))
1354 {
1355 /* Get Dnd data */
1356 Atom ActualType;
1357 int ActualFormat;
1358 unsigned char *data;
1359 unsigned long Size, RemainingBytes;
1360
1361 XGetWindowProperty (disp, display->root,
1362 xa[XA_DNDSELECTION],
1363 0L, 1000000L,
1364 False, AnyPropertyType,
1365 &ActualType, &ActualFormat,
1366 &Size, &RemainingBytes,
1367 &data);
1368 set_string_property (XA_CUT_BUFFER0, data);
1369 XFree (data);
1370 selection_paste (display->root, XA_CUT_BUFFER0, true);
1371 XSetInputFocus (disp, display->root, RevertToNone, CurrentTime);
1372 }
1373#endif /* OFFIX_DND */
1374 break;
1375
1376 case MappingNotify:
1377 XRefreshKeyboardMapping (&ev.xmapping);
1378 break; 1440 break;
1379 1441
1380 /* 1442 /*
1381 * XXX: this is not the _current_ arrangement 1443 * XXX: this is not the _current_ arrangement
1382 * Here's my conclusion: 1444 * Here's my conclusion:
1401 break; 1463 break;
1402 } 1464 }
1403 break; 1465 break;
1404 1466
1405 case FocusIn: 1467 case FocusIn:
1468 if (ev.xfocus.detail != NotifyInferior
1469 && ev.xfocus.detail != NotifyPointer
1470 && ev.xfocus.mode != NotifyGrab)
1406 focus_in (); 1471 focus_in ();
1407 break; 1472 break;
1408 1473
1409 case FocusOut: 1474 case FocusOut:
1475 if (ev.xfocus.detail != NotifyInferior
1476 && ev.xfocus.detail != NotifyPointer
1477 && ev.xfocus.mode != NotifyGrab)
1410 focus_out (); 1478 focus_out ();
1411 break; 1479 break;
1412 1480
1413 case ConfigureNotify: 1481 case ConfigureNotify:
1414 if (ev.xconfigure.window == TermWin.parent[0]) 1482 if (ev.xconfigure.window == parent)
1415 { 1483 {
1416 int height, width; 1484 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1417
1418 do 1485 ;
1419 { /* Wrap lots of configures into one */ 1486
1487 bool want_position_change = SHOULD_INVOKE (HOOK_POSITION_CHANGE);
1488
1489 if (want_position_change)
1490 {
1491 int x, y;
1492
1493 if (ev.xconfigure.send_event)
1494 {
1420 width = ev.xconfigure.width; 1495 x = ev.xconfigure.x;
1421 height = ev.xconfigure.height; 1496 y = ev.xconfigure.y;
1422 D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); 1497 }
1498 else
1499 get_window_origin (x, y);
1500
1501 if (x != parent_x || y != parent_y)
1502 {
1503 parent_x = x;
1504 parent_y = y;
1505 HOOK_INVOKE ((this, HOOK_POSITION_CHANGE, DT_INT, x, DT_INT, y, DT_END));
1506 }
1423 } 1507 }
1424 while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev));
1425 1508
1426 if (szHint.width != width || szHint.height != height) 1509 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1427 { 1510 {
1428 seen_resize = 1; 1511 seen_resize = 1;
1429 resize_all_windows (width, height, 1); 1512 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1430 } 1513 }
1431 1514
1432#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ 1515 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1433 if (options & Opt_transparent)
1434 check_our_parents ();
1435#endif
1436 } 1516 }
1437 break; 1517 break;
1438 1518
1439 case PropertyNotify: 1519 case PropertyNotify:
1440 if (ev.xproperty.atom == xa[XA_VT_SELECTION] 1520 HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END));
1441 && ev.xproperty.state == PropertyNewValue)
1442 selection_property (ev.xproperty.window, ev.xproperty.atom);
1443
1444 break; 1521 break;
1445 1522
1446 case SelectionClear: 1523 case SelectionClear:
1447 selection_clear (); 1524 selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]);
1448 break;
1449
1450 case SelectionNotify:
1451 if (selection_wait == Sel_normal)
1452 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1453 break; 1525 break;
1454 1526
1455 case SelectionRequest: 1527 case SelectionRequest:
1456 selection_send (ev.xselectionrequest); 1528 selection_send (ev.xselectionrequest);
1457 break; 1529 break;
1458 1530
1531 case MapNotify:
1532 mapped = 1;
1533#ifdef TEXT_BLINK
1534 text_blink_ev.start ();
1535#endif
1536 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1537 break;
1538
1459 case UnmapNotify: 1539 case UnmapNotify:
1460 TermWin.mapped = 0; 1540 mapped = 0;
1461#ifdef TEXT_BLINK 1541#ifdef TEXT_BLINK
1462 text_blink_ev.stop (); 1542 text_blink_ev.stop ();
1463#endif 1543#endif
1544 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1464 break; 1545 break;
1465
1466 case MapNotify:
1467 TermWin.mapped = 1;
1468#ifdef TEXT_BLINK
1469 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL);
1470#endif
1471 break;
1472
1473#ifdef TRANSPARENT
1474 case ReparentNotify:
1475 rootwin_cb (ev);
1476 break;
1477#endif /* TRANSPARENT */
1478 1546
1479 case GraphicsExpose: 1547 case GraphicsExpose:
1480 case Expose: 1548 case Expose:
1481 if (ev.xany.window == TermWin.vt) 1549 if (ev.xany.window == vt)
1482 { 1550 {
1483 do 1551 do
1552 {
1484 scr_expose (ev.xexpose.x, ev.xexpose.y, 1553 scr_expose (ev.xexpose.x, ev.xexpose.y,
1485 ev.xexpose.width, ev.xexpose.height, False); 1554 ev.xexpose.width, ev.xexpose.height, false);
1555 }
1486 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); 1556 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1487 1557
1488 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1558 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1489 1559
1490 while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) 1560 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1561 {
1491 scr_expose (ev.xexpose.x, ev.xexpose.y, 1562 scr_expose (ev.xexpose.x, ev.xexpose.y,
1492 ev.xexpose.width, ev.xexpose.height, False); 1563 ev.xexpose.width, ev.xexpose.height, false);
1564 }
1493 1565
1494 scr_refresh (refresh_type); 1566 want_refresh = 1;
1495 } 1567 }
1496 else 1568 else
1497 { 1569 {
1498 XEvent unused_event; 1570 XEvent unused_event;
1499 1571
1500 while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) 1572 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1501 ; 1573 ;
1502 while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) 1574 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1503 ; 1575 ;
1504 1576
1505 if (isScrollbarWindow (ev.xany.window)) 1577 if (scrollBar.state && ev.xany.window == scrollBar.win)
1506 { 1578 {
1507 scrollBar.setIdle (); 1579 scrollBar.state = SB_STATE_IDLE;
1508 scrollbar_show (0); 1580 scrollBar.show (0);
1509 } 1581 }
1510#ifdef MENUBAR
1511 if (menubar_visible () && isMenuBarWindow (ev.xany.window))
1512 menubar_expose ();
1513#endif
1514
1515#ifdef TRANSPARENT
1516 if (am_transparent && ev.xany.window == TermWin.parent[0])
1517 XClearWindow (disp, ev.xany.window);
1518#endif
1519 } 1582 }
1520 break; 1583 break;
1521 1584
1522 case MotionNotify: 1585 case MotionNotify:
1523#ifdef POINTER_BLANK 1586#ifdef POINTER_BLANK
1524 if (hidden_pointer) 1587 if (hidden_pointer)
1525 pointer_unblank (); 1588 pointer_unblank ();
1526#endif 1589#endif
1527#if MENUBAR 1590 if (!bypass_keystate
1528 if (isMenuBarWindow (ev.xany.window)) 1591 && ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1529 { 1592 || priv_modes & PrivMode_MouseAnyEvent))
1530 menubar_control (ev.xbutton); 1593 mouse_report (ev.xbutton);
1531 break;
1532 }
1533#endif
1534 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1594 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1535 break; 1595 break;
1536 1596
1537 if (ev.xany.window == TermWin.vt) 1597 if (ev.xany.window == vt)
1538 { 1598 {
1599 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1600 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1601 ; // nop
1539 if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1602 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1540 { 1603 {
1541 while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) 1604 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1542 ; 1605 ;
1543 1606
1544 XQueryPointer (disp, TermWin.vt, 1607 XQueryPointer (dpy, vt,
1545 &unused_root, &unused_child, 1608 &unused_root, &unused_child,
1546 &unused_root_x, &unused_root_y, 1609 &unused_root_x, &unused_root_y,
1547 &ev.xbutton.x, &ev.xbutton.y, 1610 &ev.xbutton.x, &ev.xbutton.y,
1548 &ev.xbutton.state); 1611 &ev.xbutton.state);
1549#ifdef MOUSE_THRESHOLD 1612#ifdef MOUSE_THRESHOLD
1550 /* deal with a `jumpy' mouse */ 1613 /* deal with a `jumpy' mouse */
1551 if ((ev.xmotion.time - MEvent.time) > MOUSE_THRESHOLD) 1614 if (ev.xmotion.time - MEvent.time > MOUSE_THRESHOLD)
1615#endif
1552 { 1616 {
1553#endif
1554#if ISO_14755 1617#if ISO_14755
1555 // 5.4 1618 // 5.4
1556 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1619 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1557 { 1620 {
1558 iso14755_54 (ev.xbutton.x, ev.xbutton.y); 1621 iso14755_54 (ev.xbutton.x, ev.xbutton.y);
1561#endif 1624#endif
1562 selection_extend (ev.xbutton.x, ev.xbutton.y, 1625 selection_extend (ev.xbutton.x, ev.xbutton.y,
1563 ev.xbutton.state & Button3Mask ? 2 : 0); 1626 ev.xbutton.state & Button3Mask ? 2 : 0);
1564 1627
1565#ifdef SELECTION_SCROLLING 1628#ifdef SELECTION_SCROLLING
1566 if (ev.xbutton.y < TermWin.int_bwidth 1629 if (ev.xbutton.y < int_bwidth
1567 || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) 1630 || Pixel2Row (ev.xbutton.y) > (nrow-1))
1568 { 1631 {
1632 page_dirn scroll_selection_dir;
1569 int dist; 1633 int dist;
1570 1634
1571 /* don't clobber the current delay if we are 1635 /* don't clobber the current delay if we are
1572 * already in the middle of scrolling. 1636 * already in the middle of scrolling.
1573 */ 1637 */
1574 if (!sel_scroll_ev.active) 1638 if (!sel_scroll_ev.is_active ())
1575 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1639 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1576 1640
1577 /* save the event params so we can highlight 1641 /* save the event params so we can highlight
1578 * the selection in the pending-scroll loop 1642 * the selection in the pending-scroll loop
1579 */ 1643 */
1580 selection_save_x = ev.xbutton.x; 1644 selection_save_x = ev.xbutton.x;
1581 selection_save_y = ev.xbutton.y; 1645 selection_save_y = ev.xbutton.y;
1582 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; 1646 selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0;
1583 1647
1584 /* calc number of lines to scroll */ 1648 /* calc number of lines to scroll */
1585 if (ev.xbutton.y < TermWin.int_bwidth) 1649 if (ev.xbutton.y < int_bwidth)
1586 { 1650 {
1587 scroll_selection_dir = UP; 1651 scroll_selection_dir = UP;
1588 dist = TermWin.int_bwidth - ev.xbutton.y; 1652 dist = int_bwidth - ev.xbutton.y;
1589 } 1653 }
1590 else 1654 else
1591 { 1655 {
1592 scroll_selection_dir = DN; 1656 scroll_selection_dir = DN;
1593 dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); 1657 dist = ev.xbutton.y - (int_bwidth + vt_height);
1594 } 1658 }
1595 1659
1596 scroll_selection_lines = Pixel2Height (dist) 1660 scroll_selection_lines = Pixel2Height (dist)
1597 / SELECTION_SCROLL_LINE_SPEEDUP 1661 / SELECTION_SCROLL_LINE_SPEEDUP
1598 + 1; 1662 + 1;
1599 MIN_IT (scroll_selection_lines, 1663 min_it (scroll_selection_lines,
1600 SELECTION_SCROLL_MAX_LINES); 1664 SELECTION_SCROLL_MAX_LINES);
1665 scroll_selection_lines *= scroll_selection_dir;
1601 } 1666 }
1602 else 1667 else
1603 { 1668 {
1604 /* we are within the text window, so we 1669 /* we are within the text window, so we
1605 * shouldn't be scrolling 1670 * shouldn't be scrolling
1606 */ 1671 */
1607 if (sel_scroll_ev.active)
1608 sel_scroll_ev.stop(); 1672 sel_scroll_ev.stop();
1609 } 1673 }
1610#endif 1674#endif
1611#ifdef MOUSE_THRESHOLD
1612 } 1675 }
1613#endif
1614 } 1676 }
1615 } 1677 }
1616 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1678 else if (scrollBar.state == SB_STATE_MOTION && ev.xany.window == scrollBar.win)
1617 { 1679 {
1618 while (XCheckTypedWindowEvent (disp, scrollBar.win, 1680 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1619 MotionNotify, &ev)) 1681 MotionNotify, &ev))
1620 ; 1682 ;
1621 1683
1622 XQueryPointer (disp, scrollBar.win, 1684 XQueryPointer (dpy, scrollBar.win,
1623 &unused_root, &unused_child, 1685 &unused_root, &unused_child,
1624 &unused_root_x, &unused_root_y, 1686 &unused_root_x, &unused_root_y,
1625 &ev.xbutton.x, &ev.xbutton.y, 1687 &ev.xbutton.x, &ev.xbutton.y,
1626 &unused_mask); 1688 &unused_mask);
1627 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1689 scr_move_to (scrollBar.position (ev.xbutton.y) - csrO,
1628 scrollbar_size ()); 1690 scrollBar.size ());
1629 scr_refresh (refresh_type);
1630 refresh_limit = 0; 1691 want_refresh = 1;
1631 scrollbar_show (1); 1692 scrollBar.show (1);
1632 } 1693 }
1633 break; 1694 break;
1634 } 1695 }
1635}
1636 1696
1637void 1697#if defined(CURSOR_BLINK)
1698 if (ev.type == KeyPress)
1699 cursor_blink_reset ();
1700#endif
1701
1702#if defined(POINTER_BLANK)
1703 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1704 {
1705 if (ev.type == MotionNotify
1706 || ev.type == ButtonPress
1707 || ev.type == ButtonRelease)
1708 if (hidden_pointer)
1709 pointer_unblank ();
1710
1711 if (ev.type == KeyPress && hidden_pointer == 0)
1712 pointer_blank ();
1713 }
1714#endif
1715
1716 refresh_check ();
1717}
1718
1719#if ENABLE_FRILLS
1720void ecb_cold
1721rxvt_term::set_urgency (bool enable)
1722{
1723 if (enable == urgency_hint)
1724 return;
1725
1726 if (XWMHints *h = XGetWMHints (dpy, parent))
1727 {
1728 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1729 XSetWMHints (dpy, parent, h);
1730 urgency_hint = enable;
1731 XFree (h);
1732 }
1733}
1734#endif
1735
1736void ecb_cold
1638rxvt_term::focus_in () 1737rxvt_term::focus_in ()
1639{ 1738{
1640 if (!TermWin.focus) 1739 if (!focus)
1641 { 1740 {
1642 TermWin.focus = 1; 1741 focus = 1;
1643 want_refresh = 1; 1742 want_refresh = 1;
1743
1644#ifdef USE_XIM 1744#if USE_XIM
1645 if (Input_Context != NULL) 1745 if (Input_Context != NULL)
1646 { 1746 {
1647 IMSetStatusPosition (); 1747 im_set_position ();
1648 XSetICFocus (Input_Context); 1748 XSetICFocus (Input_Context);
1649 } 1749 }
1650#endif 1750#endif
1651#ifdef CURSOR_BLINK 1751#if CURSOR_BLINK
1652 if (options & Opt_cursorBlink) 1752 if (option (Opt_cursorBlink))
1653 cursor_blink_ev.start (NOW + BLINK_INTERVAL); 1753 cursor_blink_ev.again ();
1654#endif 1754#endif
1655#ifdef OFF_FOCUS_FADING 1755#if OFF_FOCUS_FADING
1656 if (rs[Rs_fade]) 1756 if (rs[Rs_fade])
1657 { 1757 {
1658 pix_colors = pix_colors_focused; 1758 pix_colors = pix_colors_focused;
1659 scr_recolour (); 1759 scr_recolor ();
1660 } 1760 }
1661#endif 1761#endif
1662 } 1762#if ENABLE_FRILLS
1663} 1763 if (option (Opt_urgentOnBell))
1764 set_urgency (0);
1664 1765
1665void 1766 if (priv_modes & PrivMode_FocusEvent)
1767 tt_printf ("\x1b[I");
1768#endif
1769
1770 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1771 }
1772}
1773
1774void ecb_cold
1666rxvt_term::focus_out () 1775rxvt_term::focus_out ()
1667{ 1776{
1668 if (TermWin.focus) 1777 if (focus)
1669 { 1778 {
1670 TermWin.focus = 0; 1779 focus = 0;
1671 want_refresh = 1; 1780 want_refresh = 1;
1672 1781
1782#if ENABLE_FRILLS
1783 if (option (Opt_urgentOnBell))
1784 set_urgency (0);
1785
1786 if (priv_modes & PrivMode_FocusEvent)
1787 tt_printf ("\x1b[O");
1788#endif
1673#if ENABLE_FRILLS || ISO_14755 1789#if ENABLE_FRILLS || ISO_14755
1790 if (iso14755buf)
1791 {
1674 iso14755buf = 0; 1792 iso14755buf = 0;
1675#endif 1793# if ISO_14755
1676#if ENABLE_OVERLAY
1677 scr_overlay_off (); 1794 scr_overlay_off ();
1678#endif 1795# endif
1796 }
1797#endif
1679#ifdef USE_XIM 1798#if USE_XIM
1680 if (Input_Context != NULL) 1799 if (Input_Context != NULL)
1681 XUnsetICFocus (Input_Context); 1800 XUnsetICFocus (Input_Context);
1682#endif 1801#endif
1683#ifdef CURSOR_BLINK 1802#if CURSOR_BLINK
1684 if (options & Opt_cursorBlink) 1803 if (option (Opt_cursorBlink))
1685 cursor_blink_ev.stop (); 1804 cursor_blink_ev.stop ();
1805
1686 hidden_cursor = 0; 1806 hidden_cursor = 0;
1687#endif 1807#endif
1688#ifdef OFF_FOCUS_FADING 1808#if OFF_FOCUS_FADING
1689 if (rs[Rs_fade]) 1809 if (rs[Rs_fade])
1690 { 1810 {
1691 pix_colors = pix_colors_unfocused; 1811 pix_colors = pix_colors_unfocused;
1692 scr_recolour (); 1812 scr_recolor ();
1693 } 1813 }
1694#endif 1814#endif
1815
1816 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1817 }
1818}
1819
1820void ecb_cold
1821rxvt_term::update_fade_color (unsigned int idx, bool first_time)
1822{
1823#if OFF_FOCUS_FADING
1824 if (rs[Rs_fade])
1695 } 1825 {
1696} 1826 if (!first_time)
1827 pix_colors_focused [idx].free (this);
1697 1828
1698#if TRANSPARENT 1829 rgba c;
1699void 1830 pix_colors [Color_fade].get (c);
1831 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1832 }
1833#endif
1834}
1835
1836#if ENABLE_PERL
1837void ecb_hot
1700rxvt_term::rootwin_cb (XEvent &ev) 1838rxvt_term::rootwin_cb (XEvent &ev)
1701{ 1839{
1702 SET_R (this); 1840 make_current ();
1703 SET_LOCALE (locale); 1841
1842 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1843 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1844 return;
1704 1845
1705 switch (ev.type) 1846 switch (ev.type)
1706 { 1847 {
1707 case PropertyNotify: 1848 case PropertyNotify:
1708 /* 1849 /*
1709 * if user used some Esetroot compatible prog to set the root bg, 1850 * if user used some Esetroot compatible prog to set the root bg,
1710 * use the property to determine the pixmap. We use it later on. 1851 * use the property to determine the pixmap. We use it later on.
1711 */ 1852 */
1712 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1853 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1713 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1854 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1714 return; 1855 {
1856 HOOK_INVOKE ((this, HOOK_ROOTPMAP_CHANGE, DT_END));
1857 }
1715 1858
1716 /* FALLTHROUGH */
1717 case ReparentNotify:
1718 if ((options & Opt_transparent) && check_our_parents () && am_transparent)
1719 want_refresh = want_full_refresh = 1;
1720 break; 1859 break;
1721 } 1860 }
1861
1862 refresh_check ();
1722} 1863}
1723#endif 1864#endif
1724 1865
1725void 1866void
1726rxvt_term::button_press (XButtonEvent &ev) 1867rxvt_term::button_press (XButtonEvent &ev)
1727{ 1868{
1728 int reportmode = 0, clickintime; 1869 int reportmode = 0, clickintime;
1729 1870
1730 bypass_keystate = ev.state & (ModMetaMask | ShiftMask); 1871 bypass_keystate = ev.state & (ModMetaMask | ShiftMask);
1872
1731 if (!bypass_keystate) 1873 if (!bypass_keystate)
1732 reportmode = !! (priv_modes & PrivMode_mouse_report); 1874 reportmode = !! (priv_modes & PrivMode_mouse_report);
1733 1875
1734 /* 1876 /*
1735 * VT window processing of button press 1877 * VT window processing of button press
1736 */ 1878 */
1737 if (ev.window == TermWin.vt) 1879 if (ev.window == vt)
1738 { 1880 {
1881 if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END)))
1882 return;
1883
1739#if ISO_14755 1884#if ISO_14755
1740 // 5.4 1885 // 5.4
1741 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 1886 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
1742 { 1887 {
1743 iso14755_54 (ev.x, ev.y); 1888 iso14755_54 (ev.x, ev.y);
1744 return; 1889 return;
1745 } 1890 }
1746#endif 1891#endif
1747 1892
1748 clickintime = ev.time - MEvent.time < MULTICLICK_TIME; 1893 clickintime = ev.time - MEvent.time < multiClickTime;
1749 1894
1750 if (reportmode) 1895 if (reportmode)
1751 { 1896 {
1752 /* mouse report from vt window */ 1897 /* mouse report from vt window */
1753 /* save the xbutton state (for ButtonRelease) */ 1898 /* save the xbutton state (for ButtonRelease) */
1754 MEvent.state = ev.state; 1899 MEvent.state = ev.state;
1755#ifdef MOUSE_REPORT_DOUBLECLICK 1900#ifdef MOUSE_REPORT_DOUBLECLICK
1756 if (ev.button == MEvent.button && clickintime) 1901 if (ev.button == MEvent.button && clickintime)
1757 { 1902 {
1758 /* same button, within alloted time */ 1903 /* same button, within allowed time */
1759 MEvent.clicks++; 1904 MEvent.clicks++;
1905
1760 if (MEvent.clicks > 1) 1906 if (MEvent.clicks > 1)
1761 { 1907 {
1762 /* only report double clicks */ 1908 /* only report double clicks */
1763 MEvent.clicks = 2; 1909 MEvent.clicks = 2;
1764 mouse_report (ev); 1910 mouse_report (ev);
1776 mouse_report (ev); 1922 mouse_report (ev);
1777 } 1923 }
1778#else 1924#else
1779 MEvent.button = ev.button; 1925 MEvent.button = ev.button;
1780 mouse_report (ev); 1926 mouse_report (ev);
1781#endif /* MOUSE_REPORT_DOUBLECLICK */ 1927#endif /* MOUSE_REPORT_DOUBLECLICK */
1782 1928
1783 } 1929 }
1784 else 1930 else
1785 { 1931 {
1786 if (ev.button != MEvent.button) 1932 if (ev.button != MEvent.button)
1796#else 1942#else
1797 selection.rect = false; 1943 selection.rect = false;
1798#endif 1944#endif
1799 1945
1800 /* allow shift+left click to extend selection */ 1946 /* allow shift+left click to extend selection */
1801 if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) 1947 if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report))
1802 { 1948 {
1803 if (MEvent.button == Button1 && clickintime) 1949 if (MEvent.button == Button1 && clickintime)
1804 selection_rotate (ev.x, ev.y); 1950 selection_rotate (ev.x, ev.y);
1805 else 1951 else
1806 selection_extend (ev.x, ev.y, 1); 1952 selection_extend (ev.x, ev.y, 1);
1834 } 1980 }
1835 1981
1836 /* 1982 /*
1837 * Scrollbar window processing of button press 1983 * Scrollbar window processing of button press
1838 */ 1984 */
1839 if (isScrollbarWindow (ev.window)) 1985 if (scrollBar.state && ev.window == scrollBar.win)
1840 { 1986 {
1841 scrollBar.setIdle (); 1987 page_dirn direction = NO_DIR;
1988
1989 if (scrollBar.upButton (ev.y))
1990 direction = UP; /* up */
1991 else if (scrollBar.dnButton (ev.y))
1992 direction = DN; /* down */
1993
1994 scrollBar.state = SB_STATE_IDLE;
1842 /* 1995 /*
1843 * Rxvt-style scrollbar: 1996 * Rxvt-style scrollbar:
1844 * move up if mouse is above slider 1997 * move up if mouse is above slider
1845 * move dn if mouse is below slider 1998 * move dn if mouse is below slider
1846 * 1999 *
1855 /* 2008 /*
1856 * Mouse report disabled scrollbar: 2009 * Mouse report disabled scrollbar:
1857 * arrow buttons - send up/down 2010 * arrow buttons - send up/down
1858 * click on scrollbar - send pageup/down 2011 * click on scrollbar - send pageup/down
1859 */ 2012 */
1860 if ((scrollBar.style == R_SB_NEXT 2013 if (direction == UP)
1861 && scrollbarnext_upButton (ev.y))
1862 || (scrollBar.style == R_SB_RXVT
1863 && scrollbarrxvt_upButton (ev.y)))
1864 tt_printf ("\033[A"); 2014 tt_printf ("\033[A");
1865 else if ((scrollBar.style == R_SB_NEXT 2015 else if (direction == DN)
1866 && scrollbarnext_dnButton (ev.y))
1867 || (scrollBar.style == R_SB_RXVT
1868 && scrollbarrxvt_dnButton (ev.y)))
1869 tt_printf ("\033[B"); 2016 tt_printf ("\033[B");
1870 else 2017 else
1871 switch (ev.button) 2018 switch (ev.button)
1872 { 2019 {
1873 case Button2: 2020 case Button2:
1880 tt_printf ("\033[5~"); 2027 tt_printf ("\033[5~");
1881 break; 2028 break;
1882 } 2029 }
1883 } 2030 }
1884 else 2031 else
1885#endif /* NO_SCROLLBAR_REPORT */ 2032#endif /* NO_SCROLLBAR_REPORT */
1886
1887 {
1888 char upordown = 0;
1889
1890 if (scrollBar.style == R_SB_NEXT)
1891 { 2033 {
1892 if (scrollbarnext_upButton (ev.y)) 2034 if (direction != NO_DIR)
1893 upordown = -1; /* up */
1894 else if (scrollbarnext_dnButton (ev.y))
1895 upordown = 1; /* down */
1896 }
1897 else if (scrollBar.style == R_SB_RXVT)
1898 {
1899 if (scrollbarrxvt_upButton (ev.y))
1900 upordown = -1; /* up */
1901 else if (scrollbarrxvt_dnButton (ev.y))
1902 upordown = 1; /* down */
1903 }
1904 if (upordown)
1905 { 2035 {
1906#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 2036#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2037 if (!cont_scroll_ev.is_active ())
1907 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 2038 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1908#endif 2039#endif
1909 if (scr_page (upordown < 0 ? UP : DN, 1)) 2040 if (scr_page (direction, 1))
1910 { 2041 {
1911 if (upordown < 0) 2042 if (direction == UP)
1912 scrollBar.setUp (); 2043 scrollBar.state = SB_STATE_UP;
1913 else 2044 else
1914 scrollBar.setDn (); 2045 scrollBar.state = SB_STATE_DOWN;
1915 } 2046 }
1916 } 2047 }
1917 else 2048 else
1918 switch (ev.button) 2049 switch (ev.button)
1919 { 2050 {
1920 case Button2: 2051 case Button2:
1921 switch (scrollbar_align) 2052 switch (scrollBar.align)
1922 { 2053 {
1923 case R_SB_ALIGN_TOP: 2054 case SB_ALIGN_TOP:
1924 csrO = 0; 2055 csrO = 0;
1925 break; 2056 break;
1926 case R_SB_ALIGN_CENTRE: 2057 case SB_ALIGN_CENTRE:
1927 csrO = (scrollBar.bot - scrollBar.top) / 2; 2058 csrO = (scrollBar.bot - scrollBar.top) / 2;
1928 break; 2059 break;
1929 case R_SB_ALIGN_BOTTOM: 2060 case SB_ALIGN_BOTTOM:
1930 csrO = scrollBar.bot - scrollBar.top; 2061 csrO = scrollBar.bot - scrollBar.top;
1931 break; 2062 break;
1932 } 2063 }
1933 2064
1934 if (scrollBar.style == R_SB_XTERM 2065 if (scrollBar.style == SB_STYLE_XTERM
1935 || scrollbar_above_slider (ev.y) 2066 || scrollBar.above_slider (ev.y)
1936 || scrollbar_below_slider (ev.y)) 2067 || scrollBar.below_slider (ev.y))
1937 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); 2068 scr_move_to (scrollBar.position (ev.y) - csrO, scrollBar.size ());
1938 2069
1939 scrollBar.setMotion (); 2070 scrollBar.state = SB_STATE_MOTION;
1940 break; 2071 break;
1941 2072
1942 case Button1: 2073 case Button1:
1943 if (scrollbar_align == R_SB_ALIGN_CENTRE) 2074 if (scrollBar.align == SB_ALIGN_CENTRE)
1944 csrO = ev.y - scrollBar.top; 2075 csrO = ev.y - scrollBar.top;
1945 /* FALLTHROUGH */ 2076 /* FALLTHROUGH */
1946 2077
1947 case Button3: 2078 case Button3:
1948 if (scrollBar.style != R_SB_XTERM) 2079 if (scrollBar.style != SB_STYLE_XTERM)
1949 { 2080 {
1950 if (scrollbar_above_slider (ev.y)) 2081 if (scrollBar.above_slider (ev.y))
1951# ifdef RXVT_SCROLL_FULL 2082# ifdef RXVT_SCROLL_FULL
1952 scr_page (UP, TermWin.nrow - 1); 2083 scr_page (UP, nrow - 1);
1953# else 2084# else
1954 scr_page (UP, TermWin.nrow / 4); 2085 scr_page (UP, nrow / 4);
1955# endif 2086# endif
1956 else if (scrollbar_below_slider (ev.y)) 2087 else if (scrollBar.below_slider (ev.y))
1957# ifdef RXVT_SCROLL_FULL 2088# ifdef RXVT_SCROLL_FULL
1958 scr_page (DN, TermWin.nrow - 1); 2089 scr_page (DN, nrow - 1);
1959# else 2090# else
1960 scr_page (DN, TermWin.nrow / 4); 2091 scr_page (DN, nrow / 4);
1961# endif 2092# endif
1962 else 2093 else
1963 scrollBar.setMotion (); 2094 scrollBar.state = SB_STATE_MOTION;
1964 } 2095 }
1965 else 2096 else
1966 { 2097 {
1967 scr_page ((ev.button == Button1 ? DN : UP), 2098 scr_page ((ev.button == Button1 ? DN : UP),
1968 (TermWin.nrow 2099 (nrow
1969 * scrollbar_position (ev.y) 2100 * scrollBar.position (ev.y)
1970 / scrollbar_size ())); 2101 / scrollBar.size ()));
1971 } 2102 }
1972 2103
1973 break; 2104 break;
1974 } 2105 }
1975 } 2106 }
2107
1976 return; 2108 return;
1977 } 2109 }
1978#if MENUBAR
1979 /*
1980 * Menubar window processing of button press
1981 */
1982 if (isMenuBarWindow (ev.window))
1983 menubar_control (ev);
1984#endif
1985} 2110}
1986 2111
1987void 2112void
1988rxvt_term::button_release (XButtonEvent &ev) 2113rxvt_term::button_release (XButtonEvent &ev)
1989{ 2114{
1991 2116
1992 csrO = 0; /* reset csr Offset */ 2117 csrO = 0; /* reset csr Offset */
1993 if (!bypass_keystate) 2118 if (!bypass_keystate)
1994 reportmode = !! (priv_modes & PrivMode_mouse_report); 2119 reportmode = !! (priv_modes & PrivMode_mouse_report);
1995 2120
1996 if (scrollbar_isUpDn ()) 2121 if (scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN)
1997 { 2122 {
1998 scrollBar.setIdle (); 2123 scrollBar.state = SB_STATE_IDLE;
1999 scrollbar_show (0); 2124 scrollBar.show (0);
2000#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2001 refresh_type &= ~SMOOTH_REFRESH;
2002#endif
2003 } 2125 }
2004 2126
2005#ifdef SELECTION_SCROLLING 2127#ifdef SELECTION_SCROLLING
2006 if (sel_scroll_ev.active)
2007 sel_scroll_ev.stop(); 2128 sel_scroll_ev.stop();
2008#endif 2129#endif
2009 2130
2010 if (ev.window == TermWin.vt) 2131 if (ev.window == vt)
2011 { 2132 {
2133 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2134 return;
2135
2012#if ISO_14755 2136#if ISO_14755
2013 // 5.4 2137 // 5.4
2014 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) 2138 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54))
2015 return; 2139 return;
2016#endif 2140#endif
2141
2017 if (reportmode) 2142 if (reportmode)
2018 { 2143 {
2019 /* mouse report from vt window */ 2144 /* mouse report from vt window */
2020 /* don't report release of wheel "buttons" */ 2145 /* don't report release of wheel "buttons" */
2021 if (ev.button >= 4) 2146 if (ev.button >= 4)
2023#ifdef MOUSE_REPORT_DOUBLECLICK 2148#ifdef MOUSE_REPORT_DOUBLECLICK
2024 /* only report the release of 'slow' single clicks */ 2149 /* only report the release of 'slow' single clicks */
2025 if (MEvent.button != AnyButton 2150 if (MEvent.button != AnyButton
2026 && (ev.button != MEvent.button 2151 && (ev.button != MEvent.button
2027 || (ev.time - MEvent.time 2152 || (ev.time - MEvent.time
2028 > MULTICLICK_TIME / 2))) 2153 > multiClickTime / 2)))
2029 { 2154 {
2030 MEvent.clicks = 0; 2155 MEvent.clicks = 0;
2031 MEvent.button = AnyButton; 2156 MEvent.button = ev.button;
2032 mouse_report (ev); 2157 mouse_report (ev);
2033 } 2158 }
2034#else /* MOUSE_REPORT_DOUBLECLICK */ 2159#else /* MOUSE_REPORT_DOUBLECLICK */
2035 MEvent.button = AnyButton; 2160 MEvent.button = ev.button;
2036 mouse_report (ev); 2161 mouse_report (ev);
2037#endif /* MOUSE_REPORT_DOUBLECLICK */ 2162#endif /* MOUSE_REPORT_DOUBLECLICK */
2038 return; 2163 return;
2039 } 2164 }
2040 2165
2041 /* 2166 /*
2042 * dumb hack to compensate for the failure of click-and-drag 2167 * dumb hack to compensate for the failure of click-and-drag
2051 { 2176 {
2052 case Button1: 2177 case Button1:
2053 case Button3: 2178 case Button3:
2054 selection_make (ev.time); 2179 selection_make (ev.time);
2055 break; 2180 break;
2181
2056 case Button2: 2182 case Button2:
2057 selection_request (ev.time, ev.x, ev.y); 2183 if (IN_RANGE_EXC (ev.x, 0, vt_width) && IN_RANGE_EXC (ev.y, 0, vt_height)) // inside window?
2184 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2058 break; 2185 break;
2186
2059#ifdef MOUSE_WHEEL 2187#ifdef MOUSE_WHEEL
2060 case Button4: 2188 case Button4:
2061 case Button5: 2189 case Button5:
2062 { 2190 {
2063 int i; 2191 int lines;
2064 page_dirn v; 2192 page_dirn dirn;
2065 2193
2066 v = ev.button == Button4 ? UP : DN; 2194 dirn = ev.button == Button4 ? UP : DN;
2067 2195
2068 if (ev.state & ShiftMask) 2196 if (ev.state & ShiftMask)
2069 i = 1; 2197 lines = 1;
2070 else if (options & Opt_mouseWheelScrollPage) 2198 else if (option (Opt_mouseWheelScrollPage))
2071 i = TermWin.nrow - 1; 2199 lines = nrow - 1;
2072 else 2200 else
2073 i = 5; 2201 lines = 5;
2074 2202
2075# ifdef MOUSE_SLIP_WHEELING 2203# ifdef MOUSE_SLIP_WHEELING
2076 if (ev.state & ControlMask) 2204 if (ev.state & ControlMask)
2077 { 2205 {
2078 mouse_slip_wheel_speed += v ? -1 : 1; 2206 mouse_slip_wheel_speed += dirn;
2079 if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; 2207 clamp_it (mouse_slip_wheel_speed, -nrow, nrow);
2080 if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow;
2081 2208
2082 if (slip_wheel_ev.at < NOW) 2209 if (!slip_wheel_ev.is_active ())
2083 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2210 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2084
2085 slip_wheel_ev.start ();
2086 } 2211 }
2087 else 2212 else
2213# endif
2088 { 2214 {
2089# endif
2090# ifdef JUMP_MOUSE_WHEEL
2091 scr_page (v, i); 2215 scr_page (dirn, lines);
2092 scr_refresh (SMOOTH_REFRESH);
2093 scrollbar_show (1); 2216 scrollBar.show (1);
2094# else
2095 while (i--)
2096 {
2097 scr_page (v, 1);
2098 scr_refresh (SMOOTH_REFRESH);
2099 scrollbar_show (1);
2100 }
2101# endif
2102# ifdef MOUSE_SLIP_WHEELING
2103 } 2217 }
2104#endif
2105 } 2218 }
2106 break; 2219 break;
2107#endif 2220#endif
2108 } 2221 }
2109 } 2222 }
2110#ifdef MENUBAR
2111 else if (isMenuBarWindow (ev.window))
2112 menubar_control (ev);
2113#endif
2114} 2223}
2115
2116#ifdef TRANSPARENT
2117#if TINTING
2118/* taken from aterm-0.4.2 */
2119
2120typedef uint32_t RUINT32T;
2121
2122void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm)
2123{
2124 int sh_r, sh_g, sh_b;
2125 RUINT32T mask_r, mask_g, mask_b;
2126 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2127 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2128 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2129 int i;
2130
2131 Visual *visual = display->visual;
2132
2133 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2134
2135 /* for convenience */
2136 mask_r = visual->red_mask;
2137 mask_g = visual->green_mask;
2138 mask_b = visual->blue_mask;
2139
2140 /* boring lookup table pre-initialization */
2141 switch (srcImage->bits_per_pixel) {
2142 case 15:
2143 if ((mask_r != 0x7c00) ||
2144 (mask_g != 0x03e0) ||
2145 (mask_b != 0x001f))
2146 return;
2147 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2148 lookup_r = lookup;
2149 lookup_g = lookup+32;
2150 lookup_b = lookup+32+32;
2151 sh_r = 10;
2152 sh_g = 5;
2153 sh_b = 0;
2154 break;
2155 case 16:
2156 if ((mask_r != 0xf800) ||
2157 (mask_g != 0x07e0) ||
2158 (mask_b != 0x001f))
2159 return;
2160 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2161 lookup_r = lookup;
2162 lookup_g = lookup+32;
2163 lookup_b = lookup+32+64;
2164 sh_r = 11;
2165 sh_g = 5;
2166 sh_b = 0;
2167 break;
2168 case 24:
2169 if ((mask_r != 0xff0000) ||
2170 (mask_g != 0x00ff00) ||
2171 (mask_b != 0x0000ff))
2172 return;
2173 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2174 lookup_r = lookup;
2175 lookup_g = lookup+256;
2176 lookup_b = lookup+256+256;
2177 sh_r = 16;
2178 sh_g = 8;
2179 sh_b = 0;
2180 break;
2181 case 32:
2182 if ((mask_r != 0xff0000) ||
2183 (mask_g != 0x00ff00) ||
2184 (mask_b != 0x0000ff))
2185 return;
2186 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2187 lookup_r = lookup;
2188 lookup_g = lookup+256;
2189 lookup_b = lookup+256+256;
2190 sh_r = 16;
2191 sh_g = 8;
2192 sh_b = 0;
2193 break;
2194 default:
2195 return; /* we do not support this color depth */
2196 }
2197
2198 /* prepare limits for color transformation (each channel is handled separately) */
2199 if (shade < 0) {
2200 shade = -shade;
2201 if (shade < 0) shade = 0;
2202 if (shade > 100) shade = 100;
2203
2204 lower_lim_r = 65535-rm;
2205 lower_lim_g = 65535-gm;
2206 lower_lim_b = 65535-bm;
2207
2208 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2209 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2210 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2211
2212 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2213 } else {
2214 if (shade < 0) shade = 0;
2215 if (shade > 100) shade = 100;
2216
2217 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2218
2219 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2220 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2221 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2222 }
2223
2224 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2225 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2226 {
2227 unsigned int tmp;
2228
2229 tmp = lower_lim_r;
2230 lower_lim_r = lower_lim_b;
2231 lower_lim_b = tmp;
2232
2233 tmp = upper_lim_r;
2234 upper_lim_r = upper_lim_b;
2235 upper_lim_b = tmp;
2236 }
2237
2238 /* fill our lookup tables */
2239 for (i = 0; i <= mask_r>>sh_r; i++)
2240 {
2241 RUINT32T tmp;
2242 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2243 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2244 lookup_r[i] = (tmp/65535)<<sh_r;
2245 }
2246 for (i = 0; i <= mask_g>>sh_g; i++)
2247 {
2248 RUINT32T tmp;
2249 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2250 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2251 lookup_g[i] = (tmp/65535)<<sh_g;
2252 }
2253 for (i = 0; i <= mask_b>>sh_b; i++)
2254 {
2255 RUINT32T tmp;
2256 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2257 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2258 lookup_b[i] = (tmp/65535)<<sh_b;
2259 }
2260
2261 /* apply table to input image (replacing colors by newly calculated ones) */
2262 switch (srcImage->bits_per_pixel)
2263 {
2264 case 15:
2265 {
2266 unsigned short *p1, *pf, *p, *pl;
2267 p1 = (unsigned short *) srcImage->data;
2268 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2269 while (p1 < pf)
2270 {
2271 p = p1;
2272 pl = p1 + srcImage->width;
2273 for (; p < pl; p++)
2274 {
2275 *p = lookup_r[(*p & 0x7c00)>>10] |
2276 lookup_g[(*p & 0x03e0)>> 5] |
2277 lookup_b[(*p & 0x001f)];
2278 }
2279 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2280 }
2281 break;
2282 }
2283 case 16:
2284 {
2285 unsigned short *p1, *pf, *p, *pl;
2286 p1 = (unsigned short *) srcImage->data;
2287 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2288 while (p1 < pf)
2289 {
2290 p = p1;
2291 pl = p1 + srcImage->width;
2292 for (; p < pl; p++)
2293 {
2294 *p = lookup_r[(*p & 0xf800)>>11] |
2295 lookup_g[(*p & 0x07e0)>> 5] |
2296 lookup_b[(*p & 0x001f)];
2297 }
2298 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2299 }
2300 break;
2301 }
2302 case 24:
2303 {
2304 unsigned char *p1, *pf, *p, *pl;
2305 p1 = (unsigned char *) srcImage->data;
2306 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2307 while (p1 < pf)
2308 {
2309 p = p1;
2310 pl = p1 + srcImage->width * 3;
2311 for (; p < pl; p += 3)
2312 {
2313 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2314 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2315 p[2] = lookup_r[(p[2] & 0x0000ff)];
2316 }
2317 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2318 }
2319 break;
2320 }
2321 case 32:
2322 {
2323 RUINT32T *p1, *pf, *p, *pl;
2324 p1 = (RUINT32T *) srcImage->data;
2325 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2326
2327 while (p1 < pf)
2328 {
2329 p = p1;
2330 pl = p1 + srcImage->width;
2331 for (; p < pl; p++)
2332 {
2333 *p = lookup_r[(*p & 0xff0000)>>16] |
2334 lookup_g[(*p & 0x00ff00)>> 8] |
2335 lookup_b[(*p & 0x0000ff)] |
2336 (*p & ~0xffffff);
2337 }
2338 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2339 }
2340 break;
2341 }
2342 }
2343
2344 free (lookup);
2345}
2346#endif
2347
2348/*
2349 * Check our parents are still who we think they are.
2350 * Do transparency updates if required
2351 */
2352int
2353rxvt_term::check_our_parents ()
2354{
2355 int i, pchanged, aformat, have_pixmap, rootdepth;
2356 unsigned long nitems, bytes_after;
2357 Atom atype;
2358 unsigned char *prop = NULL;
2359 Window root, oldp, *list;
2360 Pixmap rootpixmap = None;
2361 XWindowAttributes wattr, wrootattr;
2362 dDisp;
2363
2364 pchanged = 0;
2365
2366 if (!(options & Opt_transparent))
2367 return pchanged; /* Don't try any more */
2368
2369 XGetWindowAttributes (disp, display->root, &wrootattr);
2370 rootdepth = wrootattr.depth;
2371
2372 XGetWindowAttributes (disp, TermWin.parent[0], &wattr);
2373
2374 if (rootdepth != wattr.depth)
2375 {
2376 if (am_transparent)
2377 {
2378 pchanged = 1;
2379 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2380 am_transparent = am_pixmap_trans = 0;
2381 }
2382
2383 return pchanged; /* Don't try any more */
2384 }
2385
2386 /* Get all X ops out of the queue so that our information is up-to-date. */
2387 XSync (disp, False);
2388
2389 /*
2390 * Make the frame window set by the window manager have
2391 * the root background. Some window managers put multiple nested frame
2392 * windows for each client, so we have to take care about that.
2393 */
2394 i = (xa[XA_XROOTPMAP_ID]
2395 && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID],
2396 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2397 &nitems, &bytes_after, &prop) == Success);
2398
2399 if (!i || prop == NULL)
2400 i = (xa[XA_ESETROOT_PMAP_ID]
2401 && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID],
2402 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2403 &nitems, &bytes_after, &prop) == Success);
2404
2405 if (!i || prop == NULL
2406#if TINTING
2407 || !rs[Rs_color + Color_tint]
2408#endif
2409 )
2410 have_pixmap = 0;
2411 else
2412 {
2413 have_pixmap = 1;
2414 rootpixmap = *(Pixmap *)prop;
2415 XFree (prop);
2416 }
2417
2418 if (have_pixmap)
2419 {
2420 /*
2421 * Copy display->root pixmap transparency
2422 */
2423 int sx, sy, nx, ny;
2424 unsigned int nw, nh;
2425 Window cr;
2426 XImage *image;
2427 GC gc;
2428 XGCValues gcvalue;
2429
2430 XTranslateCoordinates (disp, TermWin.parent[0], display->root,
2431 0, 0, &sx, &sy, &cr);
2432 nw = (unsigned int)szHint.width;
2433 nh = (unsigned int)szHint.height;
2434 nx = ny = 0;
2435
2436 if (sx < 0)
2437 {
2438 nw += sx;
2439 nx = -sx;
2440 sx = 0;
2441 }
2442
2443 if (sy < 0)
2444 {
2445 nh += sy;
2446 ny = -sy;
2447 sy = 0;
2448 }
2449
2450 MIN_IT (nw, (unsigned int) (wrootattr.width - sx));
2451 MIN_IT (nh, (unsigned int) (wrootattr.height - sy));
2452
2453 XSync (disp, False);
2454 allowedxerror = -1;
2455 image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2456
2457 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2458 /* XXX: may need a delay here? */
2459 allowedxerror = 0;
2460
2461 if (image == NULL)
2462 {
2463 if (am_transparent && am_pixmap_trans)
2464 {
2465 pchanged = 1;
2466 if (TermWin.pixmap != None)
2467 {
2468 XFreePixmap (disp, TermWin.pixmap);
2469 TermWin.pixmap = None;
2470 }
2471 }
2472
2473 am_pixmap_trans = 0;
2474 }
2475 else
2476 {
2477 if (TermWin.pixmap != None)
2478 XFreePixmap (disp, TermWin.pixmap);
2479
2480#if TINTING
2481 if (ISSET_PIXCOLOR (Color_tint))
2482 {
2483 unsigned short rm, gm, bm;
2484 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2485
2486 pix_colors_focused[Color_tint].get (display, rm, gm, bm);
2487
2488 ShadeXImage (display, image, shade, rm, gm, bm);
2489 }
2490#endif
2491
2492 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
2493 szHint.width, szHint.height, image->depth);
2494 gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue);
2495 XPutImage (disp, TermWin.pixmap, gc, image, 0, 0,
2496 nx, ny, image->width, image->height);
2497 XFreeGC (disp, gc);
2498 XDestroyImage (image);
2499 XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap);
2500 XClearWindow (disp, TermWin.parent[0]);
2501
2502 if (!am_transparent || !am_pixmap_trans)
2503 pchanged = 1;
2504
2505 am_transparent = am_pixmap_trans = 1;
2506 }
2507 }
2508
2509 if (am_pixmap_trans)
2510 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2511 else
2512 {
2513 unsigned int n;
2514 /*
2515 * InheritPixmap transparency
2516 */
2517 for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2518 {
2519 oldp = TermWin.parent[i];
2520 XQueryTree (disp, TermWin.parent[i - 1], &root,
2521 &TermWin.parent[i], &list, &n);
2522 XFree (list);
2523
2524 if (TermWin.parent[i] == display->root)
2525 {
2526 if (oldp != None)
2527 pchanged = 1;
2528
2529 break;
2530 }
2531
2532 if (oldp != TermWin.parent[i])
2533 pchanged = 1;
2534 }
2535
2536 n = 0;
2537
2538 if (pchanged)
2539 {
2540 for (; n < (unsigned int)i; n++)
2541 {
2542 XGetWindowAttributes (disp, TermWin.parent[n], &wattr);
2543 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2544 {
2545 n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1;
2546 break;
2547 }
2548 }
2549 }
2550
2551 if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0])))
2552 {
2553 XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]);
2554 XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]);
2555 am_transparent = 0;
2556 /* XXX: also turn off Opt_transparent? */
2557 }
2558 else
2559 {
2560#if WAIT_FOR_WM
2561 /* wait (an arbitrary period) for the WM to do its thing
2562 * needed for fvwm2.2.2 (and before?) */
2563 sleep (1);
2564#endif
2565 for (n = 0; n < (unsigned int)i; n++)
2566 {
2567 XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative);
2568 XClearWindow (disp, TermWin.parent[n]);
2569 }
2570
2571 XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative);
2572 am_transparent = 1;
2573 }
2574
2575 for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++)
2576 TermWin.parent[i] = None;
2577 }
2578
2579 if (scrollBar.win)
2580 {
2581 XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative);
2582 scrollBar.setIdle ();
2583 scrollbar_show (0);
2584 }
2585
2586 if (am_transparent)
2587 {
2588 want_refresh = want_full_refresh = 1;
2589 if (am_pixmap_trans)
2590 flush ();
2591 }
2592
2593 return pchanged;
2594}
2595#endif
2596 2224
2597/*}}} */ 2225/*}}} */
2598 2226
2599bool 2227void ecb_hot
2600rxvt_term::cmd_parse () 2228rxvt_term::cmd_parse ()
2601{ 2229{
2602 bool flag = false;
2603 unicode_t ch = NOCHAR; 2230 wchar_t ch = NOCHAR;
2604 unsigned char *seq_begin; // remember start of esc-sequence here 2231 char *seq_begin; // remember start of esc-sequence here
2605 2232
2606 for (;;) 2233 for (;;)
2607 { 2234 {
2608 if (ch == NOCHAR) 2235 if (ecb_unlikely (ch == NOCHAR))
2609 { 2236 {
2610 seq_begin = cmdbuf_ptr; 2237 seq_begin = cmdbuf_ptr;
2611 ch = next_char (); 2238 ch = next_char ();
2612 }
2613 2239
2614 if (ch == NOCHAR) // TODO: improve 2240 if (ch == NOCHAR)
2615 break; 2241 break;
2242 }
2616 2243
2617 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2244 if (ecb_likely (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2618 { 2245 {
2619 if (!seen_input) 2246 if (ecb_unlikely (!seen_input))
2620 { 2247 {
2621 seen_input = 1; 2248 seen_input = 1;
2622 // many badly-written programs (e.g. jed) contain a race condition: 2249 // many badly-written programs (e.g. jed) contain a race condition:
2623 // they first read the screensize and then install a SIGWINCH handler. 2250 // they first read the screensize and then install a SIGWINCH handler.
2624 // some window managers resize the window early, and these programs 2251 // some window managers resize the window early, and these programs
2629 if (seen_resize && cmd_pid) 2256 if (seen_resize && cmd_pid)
2630 kill (-cmd_pid, SIGWINCH); 2257 kill (-cmd_pid, SIGWINCH);
2631 } 2258 }
2632 2259
2633 /* Read a text string from the input buffer */ 2260 /* Read a text string from the input buffer */
2634 unicode_t buf[UBUFSIZ]; 2261 wchar_t buf[UBUFSIZ];
2635 bool refreshnow = false; 2262 bool refreshnow = false;
2636 int nlines = 0; 2263 int nlines = 0;
2637 unicode_t *str = buf; 2264 wchar_t *str = buf;
2265 wchar_t *eol = str + min (ncol, UBUFSIZ);
2638 2266
2639 for (;;) 2267 for (;;)
2640 { 2268 {
2641 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2269 if (ecb_unlikely (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2642 break; 2270 break;
2643 2271
2644 *str++ = ch; 2272 *str++ = ch;
2645 2273
2646 if (ch == C0_LF) 2274 if (ecb_unlikely (ch == C0_LF || str >= eol))
2647 { 2275 {
2276 if (ch == C0_LF)
2648 nlines++; 2277 nlines++;
2278
2649 refresh_count++; 2279 refresh_count++;
2650 2280
2651 if (!(options & Opt_jumpScroll) 2281 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2652 || (refresh_count >= refresh_limit * (TermWin.nrow - 1)))
2653 { 2282 {
2283 refresh_count = 0;
2284
2285 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2286 {
2654 refreshnow = true; 2287 refreshnow = true;
2655 ch = NOCHAR; 2288 ch = NOCHAR;
2656 break; 2289 break;
2290 }
2657 } 2291 }
2658 2292
2659 // scr_add_lines only works for nlines <= TermWin.nrow - 1. 2293 // scr_add_lines only works for nlines <= nrow - 1.
2660 if (nlines >= TermWin.nrow - 1) 2294 if (nlines >= nrow - 1)
2661 { 2295 {
2296 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2297 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2662 scr_add_lines (buf, nlines, str - buf); 2298 scr_add_lines (buf, str - buf, nlines);
2299
2663 nlines = 0; 2300 nlines = 0;
2664 str = buf; 2301 str = buf;
2302 eol = str + min (ncol, UBUFSIZ);
2665 } 2303 }
2666 }
2667 2304
2668 if (str >= buf + UBUFSIZ) 2305 if (str >= eol)
2669 { 2306 {
2307 if (eol >= buf + UBUFSIZ)
2308 {
2670 ch = NOCHAR; 2309 ch = NOCHAR;
2671 break; 2310 break;
2311 }
2312 else
2313 eol = min (eol + ncol, buf + UBUFSIZ);
2314 }
2315
2672 } 2316 }
2673 2317
2674 seq_begin = cmdbuf_ptr; 2318 seq_begin = cmdbuf_ptr;
2675 ch = next_char (); 2319 ch = next_char ();
2676 } 2320 }
2677 2321
2322 if (!(SHOULD_INVOKE (HOOK_ADD_LINES)
2323 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2678 scr_add_lines (buf, nlines, str - buf); 2324 scr_add_lines (buf, str - buf, nlines);
2679 2325
2680 /* 2326 /*
2681 * If there have been a lot of new lines, then update the screen 2327 * If there have been a lot of new lines, then update the screen
2682 * What the heck I'll cheat and only refresh less than every page-full. 2328 * What the heck we'll cheat and only refresh less than every page-full.
2683 * the number of pages between refreshes is refresh_limit, which 2329 * if skipScroll is enabled.
2684 * is incremented here because we must be doing flat-out scrolling.
2685 */ 2330 */
2686 if (refreshnow) 2331 if (refreshnow)
2687 { 2332 {
2688 if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2689 refresh_limit++;
2690 else
2691 {
2692 flag = true;
2693 scr_refresh (refresh_type); 2333 scr_refresh ();
2694 } 2334 want_refresh = 1;
2695 } 2335 }
2696
2697 } 2336 }
2698 else 2337 else
2699 { 2338 {
2700 try 2339 try
2701 { 2340 {
2709 } 2348 }
2710 2349
2711 ch = NOCHAR; 2350 ch = NOCHAR;
2712 } 2351 }
2713 } 2352 }
2714
2715 return flag;
2716}
2717
2718// read the next octet
2719unicode_t
2720rxvt_term::next_octet ()
2721{
2722 return cmdbuf_ptr < cmdbuf_endp
2723 ? *cmdbuf_ptr++
2724 : NOCHAR;
2725} 2353}
2726 2354
2727// read the next character 2355// read the next character
2728unicode_t 2356wchar_t ecb_hot
2729rxvt_term::next_char () 2357rxvt_term::next_char () NOTHROW
2730{ 2358{
2731 while (cmdbuf_ptr < cmdbuf_endp) 2359 while (cmdbuf_ptr < cmdbuf_endp)
2732 { 2360 {
2733 // assume 7-bit to be ascii ALWAYS 2361 // assume 7-bit to be ascii ALWAYS (always true in POSIX)
2734 if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2362 if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f))
2735 return *cmdbuf_ptr++; 2363 return *cmdbuf_ptr++;
2736 2364
2737 wchar_t wc; 2365 wchar_t wc;
2738 size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2366 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2739 2367
2740 if (len == (size_t)-2) 2368 if (len == (size_t)-2)
2741 { 2369 {
2742 // the mbstate stores incomplete sequences. didn't know this :/ 2370 // the mbstate stores incomplete sequences. didn't know this :/
2743 cmdbuf_ptr = cmdbuf_endp; 2371 cmdbuf_ptr = cmdbuf_endp;
2744 break; 2372 break;
2745 } 2373 }
2746 2374
2747 if (len == (size_t)-1) 2375 if (len == (size_t)-1)
2376 {
2377 mbstate.reset (); // reset now undefined conversion state
2378 // a -1 might indicate that a previous incomplete char is invalid (previous return -2)
2379 // in which case we "erroneously" return the next byte which might be valid.
2748 return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2380 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2381 }
2749 2382
2750 // assume wchar == unicode 2383 // assume wchar == unicode
2751 cmdbuf_ptr += len; 2384 cmdbuf_ptr += len;
2752 return wc & UNICODE_MASK; 2385 return wc & UNICODE_MASK;
2753 } 2386 }
2754 2387
2755 return NOCHAR; 2388 return NOCHAR;
2756} 2389}
2757 2390
2758/* rxvt_cmd_getc () - Return next input character */ 2391// read the next octet
2759/* 2392uint32_t ecb_hot
2760 * Return the next input character after first passing any keyboard input 2393rxvt_term::next_octet () NOTHROW
2761 * to the command.
2762 */
2763unicode_t
2764rxvt_term::cmd_getc ()
2765{ 2394{
2395 return cmdbuf_ptr < cmdbuf_endp
2396 ? (unsigned char)*cmdbuf_ptr++
2397 : NOCHAR;
2398}
2399
2400static class out_of_input out_of_input;
2401
2402wchar_t ecb_hot
2403rxvt_term::cmd_getc () THROW ((class out_of_input))
2404{
2766 unicode_t c = next_char (); 2405 wchar_t c = next_char ();
2767 2406
2768 if (c == NOCHAR) 2407 if (c == NOCHAR)
2769 throw out_of_input; 2408 throw out_of_input;
2770 2409
2771 return c; 2410 return c;
2772} 2411}
2773 2412
2774unicode_t 2413uint32_t ecb_hot
2775rxvt_term::cmd_get8 () 2414rxvt_term::cmd_get8 () THROW ((class out_of_input))
2776{ 2415{
2777 unicode_t c = next_octet (); 2416 uint32_t c = next_octet ();
2778 2417
2779 if (c == NOCHAR) 2418 if (c == NOCHAR)
2780 throw out_of_input; 2419 throw out_of_input;
2781 2420
2782 return c; 2421 return c;
2783} 2422}
2784 2423
2785/*{{{ print pipe */ 2424/*{{{ print pipe */
2786/*----------------------------------------------------------------------*/ 2425/*----------------------------------------------------------------------*/
2787#ifdef PRINTPIPE 2426#ifdef PRINTPIPE
2788FILE * 2427FILE * ecb_cold
2789rxvt_term::popen_printer () 2428rxvt_term::popen_printer ()
2790{ 2429{
2791 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2430 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2792 2431
2793 if (stream == NULL) 2432 if (stream == NULL)
2794 rxvt_warn ("can't open printer pipe, not printing.\n"); 2433 rxvt_warn ("can't open printer pipe, not printing.\n");
2795 2434
2796 return stream; 2435 return stream;
2797} 2436}
2798 2437
2799int 2438int ecb_cold
2800rxvt_term::pclose_printer (FILE *stream) 2439rxvt_term::pclose_printer (FILE *stream)
2801{ 2440{
2802 fflush (stream); 2441 fflush (stream);
2803 return pclose (stream); 2442 return pclose (stream);
2804} 2443}
2805 2444
2806/* 2445/*
2807 * simulate attached vt100 printer 2446 * simulate attached vt100 printer
2808 */ 2447 */
2809void 2448void ecb_cold
2810rxvt_term::process_print_pipe () 2449rxvt_term::process_print_pipe ()
2811{ 2450{
2812 int done; 2451 FILE *fd = popen_printer ();
2813 FILE *fd;
2814 2452
2815 if ((fd = popen_printer ()) == NULL) 2453 if (!fd)
2816 return; 2454 return;
2817 2455
2818 /* 2456 /*
2819 * Send all input to the printer until either ESC[4i or ESC[?4i 2457 * Send all input to the printer until either ESC[4i or ESC[?4i
2820 * is received. 2458 * is received.
2821 */ 2459 */
2822 for (done = 0; !done;) 2460 for (int done = 0; !done; )
2823 { 2461 {
2824 unsigned char buf[8]; 2462 unsigned char buf[8];
2825 unicode_t ch; 2463 unicode_t ch;
2826 unsigned int i, len; 2464 unsigned int i, len;
2827 2465
2846 { 2484 {
2847 if ((buf[len++] = cmd_getc ()) == 'i') 2485 if ((buf[len++] = cmd_getc ()) == 'i')
2848 break; /* done = 1 */ 2486 break; /* done = 1 */
2849 } 2487 }
2850 } 2488 }
2851 2489
2852 for (i = 0; i < len; i++) 2490 for (i = 0; i < len; i++)
2853 if (putc (buf[i], fd) == EOF) 2491 if (putc (buf[i], fd) == EOF)
2854 { 2492 {
2855 done = 1; 2493 done = 1;
2856 break; 2494 break;
2858 } 2496 }
2859 } 2497 }
2860 2498
2861 pclose_printer (fd); 2499 pclose_printer (fd);
2862} 2500}
2863#endif /* PRINTPIPE */ 2501#endif /* PRINTPIPE */
2864/*}}} */ 2502/*}}} */
2865 2503
2866/* *INDENT-OFF* */
2867enum { 2504enum {
2868 C1_40 = 0x40, 2505 C1_40 = 0x40,
2869 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, 2506 C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA,
2870 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3, 2507 C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3,
2871 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA, 2508 C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA,
2872 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, 2509 C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC,
2873}; 2510};
2874/* *INDENT-ON* */
2875 2511
2876/*{{{ process non-printing single characters */ 2512/*{{{ process non-printing single characters */
2877void 2513void ecb_hot
2878rxvt_term::process_nonprinting (unicode_t ch) 2514rxvt_term::process_nonprinting (unicode_t ch)
2879{ 2515{
2880 switch (ch) 2516 switch (ch)
2881 { 2517 {
2882 case C0_ESC: 2518 case C0_ESC:
2883 process_escape_seq (); 2519 process_escape_seq ();
2884 break; 2520 break;
2885 case C0_ENQ: /* terminal Status */ 2521 case C0_ENQ: /* terminal Status */
2886 if (rs[Rs_answerbackstring]) 2522 if (rs[Rs_answerbackstring])
2887 tt_write ((const unsigned char *)rs[Rs_answerbackstring], 2523 tt_write (rs [Rs_answerbackstring], strlen (rs [Rs_answerbackstring]));
2888 (unsigned int)strlen (rs[Rs_answerbackstring]));
2889 else 2524 else
2890 tt_write ((unsigned char *)VT100_ANS, 2525 tt_write (VT100_ANS, strlen (VT100_ANS));
2891 (unsigned int)strlen (VT100_ANS));
2892 break; 2526 break;
2893 case C0_BEL: /* bell */ 2527 case C0_BEL: /* bell */
2894 scr_bell (); 2528 scr_bell ();
2895 break; 2529 break;
2896 case C0_BS: /* backspace */ 2530 case C0_BS: /* backspace */
2914 scr_charset_choose (0); 2548 scr_charset_choose (0);
2915 break; 2549 break;
2916 2550
2917#ifdef EIGHT_BIT_CONTROLS 2551#ifdef EIGHT_BIT_CONTROLS
2918 // 8-bit controls 2552 // 8-bit controls
2919 case 0x90: /* DCS */ 2553 case 0x90: /* DCS */
2920 process_dcs_seq (); 2554 process_dcs_seq ();
2921 break; 2555 break;
2922 case 0x9b: /* CSI */ 2556 case 0x9b: /* CSI */
2923 process_csi_seq (); 2557 process_csi_seq ();
2924 break; 2558 break;
2925 case 0x9d: /* CSI */ 2559 case 0x9d: /* OSC */
2926 process_osc_seq (); 2560 process_osc_seq ();
2927 break; 2561 break;
2928#endif 2562#endif
2929 } 2563 }
2930} 2564}
2931/*}}} */ 2565/*}}} */
2932 2566
2933 2567
2934/*{{{ process VT52 escape sequences */ 2568/*{{{ process VT52 escape sequences */
2935void 2569void ecb_cold
2936rxvt_term::process_escape_vt52 (unicode_t ch) 2570rxvt_term::process_escape_vt52 (unicode_t ch)
2937{ 2571{
2938 int row, col; 2572 int row, col;
2939 2573
2940 switch (ch) 2574 switch (ch)
2974 break; 2608 break;
2975 case 'Z': /* identify the terminal type */ 2609 case 'Z': /* identify the terminal type */
2976 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ 2610 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2977 break; 2611 break;
2978 case '<': /* turn off VT52 mode */ 2612 case '<': /* turn off VT52 mode */
2979 PrivMode (0, PrivMode_vt52); 2613 priv_modes &= ~PrivMode_vt52;
2980 break; 2614 break;
2981 case 'F': /* use special graphics character set */ 2615 case 'F': /* use special graphics character set */
2982 case 'G': /* use regular character set */ 2616 case 'G': /* use regular character set */
2983 /* unimplemented */ 2617 /* unimplemented */
2984 break; 2618 break;
2990} 2624}
2991/*}}} */ 2625/*}}} */
2992 2626
2993 2627
2994/*{{{ process escape sequences */ 2628/*{{{ process escape sequences */
2995void 2629void ecb_hot
2996rxvt_term::process_escape_seq () 2630rxvt_term::process_escape_seq ()
2997{ 2631{
2998 unicode_t ch = cmd_getc (); 2632 unicode_t ch = cmd_getc ();
2999 2633
3000 if (priv_modes & PrivMode_vt52) 2634 if (priv_modes & PrivMode_vt52)
3003 return; 2637 return;
3004 } 2638 }
3005 2639
3006 switch (ch) 2640 switch (ch)
3007 { 2641 {
3008 /* case 1: do_tek_mode (); break; */
3009 case '#': 2642 case '#':
3010 if (cmd_getc () == '8') 2643 if (cmd_getc () == '8')
3011 scr_E (); 2644 scr_E ();
3012 break; 2645 break;
3013 case '(': 2646 case '(':
3020 scr_charset_set (2, (unsigned int)cmd_getc ()); 2653 scr_charset_set (2, (unsigned int)cmd_getc ());
3021 break; 2654 break;
3022 case '+': 2655 case '+':
3023 scr_charset_set (3, (unsigned int)cmd_getc ()); 2656 scr_charset_set (3, (unsigned int)cmd_getc ());
3024 break; 2657 break;
3025#if ENABLE_FRILLS 2658#if !ENABLE_MINIMAL
3026 case '6': 2659 case '6':
3027 scr_backindex (); 2660 scr_backindex ();
3028 break; 2661 break;
3029#endif 2662#endif
3030 case '7': 2663 case '7':
3031 scr_cursor (SAVE); 2664 scr_cursor (SAVE);
3032 break; 2665 break;
3033 case '8': 2666 case '8':
3034 scr_cursor (RESTORE); 2667 scr_cursor (RESTORE);
3035 break; 2668 break;
3036#if ENABLE_FRILLS 2669#if !ENABLE_MINIMAL
3037 case '9': 2670 case '9':
3038 scr_forwardindex (); 2671 scr_forwardindex ();
3039 break; 2672 break;
3040#endif 2673#endif
2674 // DECPAM/DECPNM
3041 case '=': 2675 case '=':
2676 priv_modes |= PrivMode_aplKP;
2677 break;
3042 case '>': 2678 case '>':
3043 PrivMode ((ch == '='), PrivMode_aplKP); 2679 priv_modes &= ~PrivMode_aplKP;
3044 break; 2680 break;
3045 2681
3046 case C1_40: 2682 case C1_40:
3047 cmd_getc (); 2683 cmd_getc ();
3048 break; 2684 break;
3051 break; 2687 break;
3052 2688
3053 /* 8.3.87: NEXT LINE */ 2689 /* 8.3.87: NEXT LINE */
3054 case C1_NEL: /* ESC E */ 2690 case C1_NEL: /* ESC E */
3055 { 2691 {
3056 unicode_t nlcr[] = { C0_LF, C0_CR }; 2692 wchar_t nlcr[] = { C0_LF, C0_CR };
3057 scr_add_lines (nlcr, 1, 2); 2693 scr_add_lines (nlcr, ecb_array_length (nlcr), 1);
3058 } 2694 }
3059 break; 2695 break;
3060 2696
2697#if 0 // disabled because embedded newlines can make exploits easier
3061 /* kidnapped escape sequence: Should be 8.3.48 */ 2698 /* kidnapped escape sequence: Should be 8.3.48 */
3062 case C1_ESA: /* ESC G */ 2699 case C1_ESA: /* ESC G */
3063 process_graphics (); 2700 // used by original rxvt for rob nations own graphics mode
2701 if (cmd_getc () == 'Q' && option (Opt_insecure))
2702 tt_printf ("\033G0\012"); /* query graphics - no graphics */
3064 break; 2703 break;
2704#endif
3065 2705
3066 /* 8.3.63: CHARACTER TABULATION SET */ 2706 /* 8.3.63: CHARACTER TABULATION SET */
3067 case C1_HTS: /* ESC H */ 2707 case C1_HTS: /* ESC H */
3068 scr_set_tab (1); 2708 scr_set_tab (1);
3069 break; 2709 break;
3072 case C1_RI: /* ESC M */ 2712 case C1_RI: /* ESC M */
3073 scr_index (DN); 2713 scr_index (DN);
3074 break; 2714 break;
3075 2715
3076 /* 8.3.142: SINGLE-SHIFT TWO */ 2716 /* 8.3.142: SINGLE-SHIFT TWO */
3077 /*case C1_SS2: scr_single_shift (2); break; */ 2717 /* case C1_SS2: break; */
3078 2718
3079 /* 8.3.143: SINGLE-SHIFT THREE */ 2719 /* 8.3.143: SINGLE-SHIFT THREE */
3080 /*case C1_SS3: scr_single_shift (3); break; */ 2720 /* case C1_SS3: break; */
3081 2721
3082 /* 8.3.27: DEVICE CONTROL STRING */ 2722 /* 8.3.27: DEVICE CONTROL STRING */
3083 case C1_DCS: /* ESC P */ 2723 case C1_DCS: /* ESC P */
3084 process_dcs_seq (); 2724 process_dcs_seq ();
3085 break; 2725 break;
3086 2726
3087 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2727 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3088 case C1_SCI: /* ESC Z */ 2728 case C1_SCI: /* ESC Z */
3089 tt_write ((const unsigned char *)ESCZ_ANSWER, 2729 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3090 (unsigned int) (sizeof (ESCZ_ANSWER) - 1));
3091 break; /* steal obsolete ESC [ c */ 2730 break; /* steal obsolete ESC [ c */
3092 2731
3093 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2732 /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */
3094 case C1_CSI: /* ESC [ */ 2733 case C1_CSI: /* ESC [ */
3095 process_csi_seq (); 2734 process_csi_seq ();
3096 break; 2735 break;
3097 2736
3098 /* 8.3.90: OPERATING SYSTEM COMMAND */ 2737 /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */
3099 case C1_OSC: /* ESC ] */ 2738 case C1_OSC: /* ESC ] */
3100 process_osc_seq (); 2739 process_osc_seq ();
3101 break; 2740 break;
3102 2741
3103 /* 8.3.106: RESET TO INITIAL STATE */ 2742 /* 8.3.106: RESET TO INITIAL STATE (RIS) */
3104 case 'c': 2743 case 'c':
3105 mbstate.reset (); 2744 mbstate.reset ();
3106 scr_poweron (); 2745 scr_poweron ();
3107 scrollbar_show (1); 2746 scrollBar.show (1);
3108 break; 2747 break;
3109 2748
3110 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2749 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3111 case 'n': 2750 case 'n':
3112 scr_charset_choose (2); 2751 scr_charset_choose (2);
3119 } 2758 }
3120} 2759}
3121/*}}} */ 2760/*}}} */
3122 2761
3123/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */ 2762/*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */
3124/* *INDENT-OFF* */
3125enum { 2763enum {
3126 CSI_ICH = 0x40, 2764 CSI_ICH = 0x40,
3127 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, 2765 CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA,
3128 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA , 2766 CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA ,
3129 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC, 2767 CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC,
3132 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ, 2770 CSI_SM , CSI_MC , CSI_HPB, CSI_VPB, CSI_RM , CSI_SGR, CSI_DSR, CSI_DAQ,
3133 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 , 2771 CSI_70 , CSI_71 , CSI_72 , CSI_73 , CSI_74 , CSI_75 , CSI_76 , CSI_77 ,
3134 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F 2772 CSI_78 , CSI_79 , CSI_7A , CSI_7B , CSI_7C , CSI_7D , CSI_7E , CSI_7F
3135}; 2773};
3136 2774
3137#define make_byte(b7,b6,b5,b4,b3,b2,b1,b0) \ 2775#define make_byte(b0,b1,b2,b3,b4,b5,b6,b7) \
3138 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \ 2776 (((b7) << 7) | ((b6) << 6) | ((b5) << 5) | ((b4) << 4) \
3139 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0)) 2777 | ((b3) << 3) | ((b2) << 2) | ((b1) << 1) | (b0))
3140#define get_byte_array_bit(array, bit) \ 2778#define get_byte_array_bit(array, bit) \
3141 (!! ((array)[ (bit) / 8] & (128 >> ((bit) & 7)))) 2779 (!! ((array)[(bit) >> 3] & (1 << ((bit) & 7))))
3142 2780
3143const unsigned char csi_defaults[] = 2781static const unsigned char csi_defaults[] =
3144 { 2782 {
3145 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */ 2783 make_byte (1,1,1,1,1,1,1,1), /* @, A, B, C, D, E, F, G, */
3146 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */ 2784 make_byte (1,1,0,0,1,1,0,0), /* H, I, J, K, L, M, N, O, */
3147 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */ 2785 make_byte (1,0,1,1,1,1,1,0), /* P, Q, R, S, T, U, V, W, */
3148 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */ 2786 make_byte (1,1,1,0,0,0,1,0), /* X, Y, Z, [, \, ], ^, _, */
3149 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */ 2787 make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */
3150 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */ 2788 make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */
3151 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */ 2789 make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */
3152 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ 2790 make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */
3153 }; 2791 };
3154/* *INDENT-ON* */
3155 2792
3156void 2793void ecb_hot
3157rxvt_term::process_csi_seq () 2794rxvt_term::process_csi_seq ()
3158{ 2795{
3159 unicode_t ch, priv, i; 2796 unicode_t ch, priv, prev_ch, i;
3160 unsigned int nargs, p; 2797 unsigned int nargs, p;
3161 int n, ndef; 2798 int n, ndef;
3162 int arg[ESC_ARGS]; 2799 int arg[ESC_ARGS] = { };
3163 2800
3164 for (nargs = ESC_ARGS; nargs > 0;) 2801 nargs = 0;
3165 arg[--nargs] = 0;
3166 2802
3167 priv = 0; 2803 priv = 0;
3168 ch = cmd_getc (); 2804 ch = cmd_getc ();
3169 if (ch >= '<' && ch <= '?') 2805 if ((ch >= '<' && ch <= '?') || ch == '!')
2806 {
3170 { /* '<' '=' '>' '?' */ 2807 /* '<' '=' '>' '?' '!' */
3171 priv = ch; 2808 priv = ch;
3172 ch = cmd_getc (); 2809 ch = cmd_getc ();
3173 } 2810 }
3174 2811
2812 prev_ch = 0;
3175 /* read any numerical arguments */ 2813 /* read any numerical arguments */
3176 for (n = -1; ch < CSI_ICH; ) 2814 for (n = -1; ch < CSI_ICH; )
3177 { 2815 {
3178 if (isdigit (ch)) 2816 if (isdigit (ch))
3179 { 2817 {
3189 n = -1; 2827 n = -1;
3190 } 2828 }
3191 else if (IS_CONTROL (ch)) 2829 else if (IS_CONTROL (ch))
3192 process_nonprinting (ch); 2830 process_nonprinting (ch);
3193 2831
2832 prev_ch = ch;
3194 ch = cmd_getc (); 2833 ch = cmd_getc ();
3195 } 2834 }
3196 2835
3197 if (ch > CSI_7F) 2836 if (ch > CSI_7F)
3198 return; 2837 return;
3204 ndef = get_byte_array_bit (csi_defaults, i); 2843 ndef = get_byte_array_bit (csi_defaults, i);
3205 for (p = 0; p < nargs; p++) 2844 for (p = 0; p < nargs; p++)
3206 if (arg[p] == -1) 2845 if (arg[p] == -1)
3207 arg[p] = ndef; 2846 arg[p] = ndef;
3208 2847
3209#ifdef DEBUG_CMD
3210 fprintf (stderr, "CSI ");
3211 for (p = 0; p < nargs; p++)
3212 fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : "");
3213 fprintf (stderr, "%c\n", ch);
3214#endif
3215
3216 /* 2848 /*
3217 * private mode handling 2849 * private mode handling
3218 */ 2850 */
3219 if (priv) 2851 if (priv)
3220 { 2852 {
3221 switch (priv) 2853 switch (priv)
3222 { 2854 {
3223 case '>': 2855 case '>':
3224 if (ch == CSI_DA) /* secondary device attributes */ 2856 if (ch == CSI_DA) /* secondary device attributes */
3225 tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); 2857 {
2858 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
2859 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
2860 //
2861 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
2862 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
2863 // versions.
2864 //
2865 tt_printf ("\033[>%d;95;0c", 'U');
2866 }
3226 break; 2867 break;
2868
3227 case '?': 2869 case '?':
3228 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2870 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3229 process_terminal_mode (ch, priv, nargs, arg); 2871 process_terminal_mode (ch, priv, nargs, arg);
3230 break; 2872 break;
2873
2874 case '!':
2875 if (ch == CSI_70)
2876 {
2877 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2878 scr_soft_reset ();
2879
2880 static const int pm_h[] = { 7, 25 };
2881 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1006, 1015, 1049 };
2882
2883 process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h);
2884 process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l);
3231 } 2885 }
2886 break;
2887 }
2888
3232 return; 2889 return;
3233 } 2890 }
3234 2891
3235 switch (ch) 2892 switch (ch)
3236 { 2893 {
3250 } 2907 }
3251 break; 2908 break;
3252#endif 2909#endif
3253 2910
3254 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */ 2911 case CSI_CUU: /* 8.3.22: (1) CURSOR UP */
3255 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ 2912 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */
3256 arg[0] = -arg[0]; 2913 arg[0] = -arg[0];
3257 /* FALLTHROUGH */ 2914 /* FALLTHROUGH */
3258 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */ 2915 case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */
3259 case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ 2916 case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */
3260 scr_gotorc (arg[0], 0, RELATIVE); 2917 scr_gotorc (arg[0], 0, RELATIVE);
3261 break; 2918 break;
3262 2919
3263 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */ 2920 case CSI_CUB: /* 8.3.18: (1) CURSOR LEFT */
3264 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */ 2921 case CSI_HPB: /* 8.3.59: (1) CHARACTER POSITION BACKWARD */
3265#ifdef ISO6429 2922#ifdef ISO6429
3266 arg[0] = -arg[0]; 2923 arg[0] = -arg[0];
3267#else /* emulate common DEC VTs */ 2924#else /* emulate common DEC VTs */
3268 arg[0] = arg[0] ? -arg[0] : -1; 2925 arg[0] = arg[0] ? -arg[0] : -1;
3269#endif 2926#endif
3335 2992
3336 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */ 2993 case CSI_SD: /* 8.3.114: (1) SCROLL DOWN */
3337 arg[0] = -arg[0]; 2994 arg[0] = -arg[0];
3338 /* FALLTHROUGH */ 2995 /* FALLTHROUGH */
3339 case CSI_SU: /* 8.3.148: (1) SCROLL UP */ 2996 case CSI_SU: /* 8.3.148: (1) SCROLL UP */
3340 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); 2997 scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]);
3341 break; 2998 break;
3342 2999
3343 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ 3000 case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */
3344 tt_write ((const unsigned char *)VT100_ANS, 3001 tt_write (VT100_ANS, sizeof (VT100_ANS) - 1);
3345 (unsigned int) (sizeof (VT100_ANS) - 1));
3346 break; 3002 break;
3347 3003
3348 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */ 3004 case CSI_SGR: /* 8.3.118: (0) SELECT GRAPHIC RENDITION */
3349 process_sgr_mode (nargs, arg); 3005 process_sgr_mode (nargs, arg);
3350 break; 3006 break;
3357 break; 3013 break;
3358 case 6: /* CPR requested */ 3014 case 6: /* CPR requested */
3359 scr_report_position (); 3015 scr_report_position ();
3360 break; 3016 break;
3361 case 7: /* unofficial extension */ 3017 case 7: /* unofficial extension */
3362 if (options & Opt_insecure) 3018 if (option (Opt_insecure))
3363 tt_printf ("%-.250s\012", rs[Rs_display_name]); 3019 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3364 break; 3020 break;
3365 case 8: /* unofficial extension */ 3021 case 8: /* unofficial extension */
3366 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 3022 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3367 break; 3023 break;
3415 scr_insert_mode (1); 3071 scr_insert_mode (1);
3416 else if (arg[0] == 20) 3072 else if (arg[0] == 20)
3417 priv_modes |= PrivMode_LFNL; 3073 priv_modes |= PrivMode_LFNL;
3418 break; 3074 break;
3419 3075
3076 case CSI_71: // DECSCUSR: set cursor style
3077 if (prev_ch == ' ')
3078 set_cursor_style (arg[0]);
3079 break;
3080
3420 /* 3081 /*
3421 * PRIVATE USE beyond this point. All CSI_7? sequences here 3082 * PRIVATE USE beyond this point. All CSI_7? sequences here
3422 */ 3083 */
3423 case CSI_72: /* DECSTBM: set top and bottom margins */ 3084 case CSI_72: /* DECSTBM: set top and bottom margins */
3424 if (nargs == 1) 3085 if (nargs == 1)
3434 break; 3095 break;
3435 case CSI_75: 3096 case CSI_75:
3436 scr_cursor (RESTORE); 3097 scr_cursor (RESTORE);
3437 break; 3098 break;
3438 3099
3439#if ENABLE_FRILLS 3100#if !ENABLE_MINIMAL
3440 case CSI_74: 3101 case CSI_74:
3441 process_window_ops (arg, nargs); 3102 process_window_ops (arg, nargs);
3442 break; 3103 break;
3443#endif 3104#endif
3444 3105
3451 break; 3112 break;
3452 } 3113 }
3453} 3114}
3454/*}}} */ 3115/*}}} */
3455 3116
3456#if ENABLE_FRILLS 3117#if !ENABLE_MINIMAL
3457/* ARGSUSED */
3458void 3118void
3459rxvt_term::process_window_ops (const int *args, unsigned int nargs) 3119rxvt_term::process_window_ops (const int *args, unsigned int nargs)
3460{ 3120{
3461 int x, y; 3121 int x, y;
3462 XWindowAttributes wattr; 3122 XWindowAttributes wattr;
3463 Window wdummy; 3123 Window wdummy;
3464 dDisp; 3124
3125 dLocal (Display *, dpy);
3465 3126
3466 if (nargs == 0) 3127 if (nargs == 0)
3467 return; 3128 return;
3468 3129
3469 switch (args[0]) 3130 switch (args[0])
3470 { 3131 {
3471 /* 3132 /*
3472 * commands 3133 * commands
3473 */ 3134 */
3474 case 1: /* deiconify window */ 3135 case 1: /* deiconify window */
3475 XMapWindow (disp, TermWin.parent[0]); 3136 XMapWindow (dpy, parent);
3476 break; 3137 break;
3477 case 2: /* iconify window */ 3138 case 2: /* iconify window */
3478 XIconifyWindow (disp, TermWin.parent[0], display->screen); 3139 XIconifyWindow (dpy, parent, display->screen);
3479 break; 3140 break;
3480 case 3: /* set position (pixels) */ 3141 case 3: /* set position (pixels) */
3481 XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); 3142 XMoveWindow (dpy, parent, args[1], args[2]);
3482 break; 3143 break;
3483 case 4: /* set size (pixels) */ 3144 case 4: /* set size (pixels) */
3484 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3145 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3485 break; 3146 break;
3486 case 5: /* raise window */ 3147 case 5: /* raise window */
3487 XRaiseWindow (disp, TermWin.parent[0]); 3148 XRaiseWindow (dpy, parent);
3488 break; 3149 break;
3489 case 6: /* lower window */ 3150 case 6: /* lower window */
3490 XLowerWindow (disp, TermWin.parent[0]); 3151 XLowerWindow (dpy, parent);
3491 break; 3152 break;
3492 case 7: /* refresh window */ 3153 case 7: /* refresh window */
3493 scr_touch (true); 3154 scr_touch (true);
3494 break; 3155 break;
3495 case 8: /* set size (chars) */ 3156 case 8: /* set size (chars) */
3496 set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), 3157 set_widthheight ((unsigned int) (args[2] * fwidth),
3497 (unsigned int) (args[1] * TermWin.fheight)); 3158 (unsigned int) (args[1] * fheight));
3498 break; 3159 break;
3499 3160
3500 //case 9: NYI, TODO, restore maximized window or maximize window 3161 //case 9: NYI, TODO, restore maximized window or maximize window
3501 default: 3162 default:
3502 if (args[0] >= 24) /* set height (chars) */ 3163 if (args[0] >= 24) /* set height (chars) */
3503 set_widthheight ((unsigned int)TermWin.width, 3164 set_widthheight ((unsigned int)vt_width,
3504 (unsigned int) (args[1] * TermWin.fheight)); 3165 (unsigned int) (args[1] * fheight));
3505 break; 3166 break;
3506
3507 3167
3508 /* 3168 /*
3509 * reports - some output format copied from XTerm 3169 * reports - some output format copied from XTerm
3510 */ 3170 */
3511 case 11: /* report window state */ 3171 case 11: /* report window state */
3512 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3172 XGetWindowAttributes (dpy, parent, &wattr);
3513 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3173 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3514 break; 3174 break;
3515 case 13: /* report window position */ 3175 case 13: /* report window position */
3516 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3176 XGetWindowAttributes (dpy, parent, &wattr);
3517 XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, 3177 XTranslateCoordinates (dpy, parent, wattr.root,
3518 -wattr.border_width, -wattr.border_width, 3178 -wattr.border_width, -wattr.border_width,
3519 &x, &y, &wdummy); 3179 &x, &y, &wdummy);
3520 tt_printf ("\033[3;%d;%dt", x, y); 3180 tt_printf ("\033[3;%d;%dt", x, y);
3521 break; 3181 break;
3522 case 14: /* report window size (pixels) */ 3182 case 14: /* report window size (pixels) */
3523 XGetWindowAttributes (disp, TermWin.parent[0], &wattr); 3183 XGetWindowAttributes (dpy, parent, &wattr);
3524 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3184 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3525 break; 3185 break;
3526 case 18: /* report text area size (chars) */ 3186 case 18: /* report text area size (chars) */
3527 tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); 3187 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3528 break; 3188 break;
3529 case 19: /* report window size (chars) */ 3189 case 19: /* report window size (chars) */
3530 tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); 3190 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3531 break; 3191 break;
3532 case 20: /* report icon label */ 3192 case 20: /* report icon label */
3533 { 3193 {
3534 char *s; 3194 char *s;
3535 XGetIconName (disp, TermWin.parent[0], &s); 3195 XGetIconName (dpy, parent, &s);
3536 tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3196 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3537 XFree (s); 3197 XFree (s);
3538 } 3198 }
3539 break; 3199 break;
3540 case 21: /* report window title */ 3200 case 21: /* report window title */
3541 { 3201 {
3542 char *s; 3202 char *s;
3543 XFetchName (disp, TermWin.parent[0], &s); 3203 XFetchName (dpy, parent, &s);
3544 tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ 3204 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3545 XFree (s); 3205 XFree (s);
3546 } 3206 }
3547 break; 3207 break;
3548 } 3208 }
3549} 3209}
3552/*----------------------------------------------------------------------*/ 3212/*----------------------------------------------------------------------*/
3553/* 3213/*
3554 * get input up until STRING TERMINATOR (or BEL) 3214 * get input up until STRING TERMINATOR (or BEL)
3555 * ends_how is terminator used. returned input must be free()'d 3215 * ends_how is terminator used. returned input must be free()'d
3556 */ 3216 */
3557unsigned char * 3217char *
3558rxvt_term::get_to_st (unicode_t &ends_how) 3218rxvt_term::get_to_st (unicode_t &ends_how)
3559{ 3219{
3560 unicode_t ch; 3220 unicode_t ch;
3561 bool seen_esc = false; 3221 bool seen_esc = false;
3562 unsigned int n = 0; 3222 unsigned int n = 0;
3563 wchar_t string[STRING_MAX]; 3223 wchar_t string[CBUFSIZ];
3564 3224
3565 while ((ch = cmd_getc ()) != NOCHAR) 3225 while ((ch = cmd_getc ()) != NOCHAR)
3566 { 3226 {
3567 if (seen_esc) 3227 if (seen_esc)
3568 { 3228 {
3576 seen_esc = true; 3236 seen_esc = true;
3577 continue; 3237 continue;
3578 } 3238 }
3579 else if (ch == C0_BEL || ch == CHAR_ST) 3239 else if (ch == C0_BEL || ch == CHAR_ST)
3580 break; 3240 break;
3241 else if (ch == C0_SYN)
3242 ch = cmd_get8 ();
3581 else if (ch < 0x20) 3243 else if (ch < 0x20)
3582 return NULL; /* other control character - exit */ 3244 return NULL; /* other control character - exit */
3583 3245
3584 seen_esc = false; 3246 seen_esc = false;
3585 3247
3586 if (n >= sizeof (string) - 1) 3248 if (n >= sizeof (string) - 1)
3587 // stop at some sane length 3249 // stop at some sane length
3588 return NULL; 3250 return NULL;
3589 3251
3590 if (ch == C0_SYN)
3591 string[n++] = cmd_get8 ();
3592 else
3593 string[n++] = ch; 3252 string[n++] = ch;
3594 } 3253 }
3595 3254
3596 string[n++] = '\0'; 3255 string[n++] = '\0';
3597 3256
3598 ends_how = (ch == 0x5c ? C0_ESC : ch); 3257 ends_how = (ch == 0x5c ? C0_ESC : ch);
3599 3258
3600 return (unsigned char *)rxvt_wcstombs (string); 3259 return rxvt_wcstombs (string);
3601} 3260}
3602 3261
3603/*----------------------------------------------------------------------*/ 3262/*----------------------------------------------------------------------*/
3604/* 3263/*
3605 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)' 3264 * process DEVICE CONTROL STRING `ESC P ... (ST|BEL)' or `0x90 ... (ST|BEL)'
3606 */ 3265 */
3607void 3266void
3608rxvt_term::process_dcs_seq () 3267rxvt_term::process_dcs_seq ()
3609{ 3268{
3610 unsigned char *s;
3611 unicode_t eh;
3612
3613 /* 3269 /*
3614 * Not handled yet 3270 * Not handled yet
3615 */ 3271 */
3272
3273 unicode_t eh;
3616 s = get_to_st (eh); 3274 char *s = get_to_st (eh);
3617 if (s) 3275 if (s)
3618 free (s); 3276 free (s);
3619 3277
3620 return; 3278 return;
3621} 3279}
3625 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)' 3283 * process OPERATING SYSTEM COMMAND sequence `ESC ] Ps ; Pt (ST|BEL)'
3626 */ 3284 */
3627void 3285void
3628rxvt_term::process_osc_seq () 3286rxvt_term::process_osc_seq ()
3629{ 3287{
3630 unicode_t ch, eh;
3631 int arg; 3288 int arg;
3632 3289
3633 ch = cmd_getc (); 3290 unicode_t ch = cmd_getc ();
3634 for (arg = 0; isdigit (ch); ch = cmd_getc ()) 3291 for (arg = 0; isdigit (ch); ch = cmd_getc ())
3635 arg = arg * 10 + (ch - '0'); 3292 arg = arg * 10 + (ch - '0');
3636 3293
3637 if (ch == ';') 3294 if (ch == ';')
3638 { 3295 {
3296 unicode_t eh;
3639 unsigned char *s = get_to_st (eh); 3297 char *s = get_to_st (eh);
3640 3298
3641 if (s) 3299 if (s)
3642 { 3300 {
3643 process_xterm_seq (arg, (char *)s, eh); 3301 process_xterm_seq (arg, s, eh);
3644 free (s); 3302 free (s);
3645 } 3303 }
3646 } 3304 }
3647} 3305}
3648 3306
3307static unsigned int
3308colorcube_index (unsigned int idx_r,
3309 unsigned int idx_g,
3310 unsigned int idx_b)
3311{
3312 assert (idx_r < Red_levels);
3313 assert (idx_g < Green_levels);
3314 assert (idx_b < Blue_levels);
3315
3316 return idx_r * Blue_levels * Green_levels +
3317 idx_g * Blue_levels +
3318 idx_b;
3319}
3320
3321/*
3322 * Find the nearest color slot in the hidden color cube,
3323 * adapt its value to the 32bit RGBA color.
3324 */
3325unsigned int
3326rxvt_term::map_rgb24_color (unsigned int r, unsigned int g, unsigned int b, unsigned int a)
3327{
3328 r &= 0xff;
3329 g &= 0xff;
3330 b &= 0xff;
3331 a &= 0xff;
3332
3333 uint32_t color = (a << 24) | (r << 16) | (g << 8) | b;
3334
3335 unsigned int idx_r = r * (Red_levels - 1) / 0xff;
3336 unsigned int idx_g = g * (Green_levels - 1) / 0xff;
3337 unsigned int idx_b = b * (Blue_levels - 1) / 0xff;
3338 unsigned int idx = colorcube_index (idx_r, idx_g, idx_b);
3339
3340 /* we allow one of the 6 directly neighbouring colours */
3341 /* to replace the current color, if they not used recently */
3342 static const signed char dxyz[][3] = {
3343 0, 0, 0,
3344 0, 0, +1,
3345 0, 0, -1,
3346 0, +1, 0,
3347 0, -1, 0,
3348 +1, 0, 0,
3349 -1, 0, 0,
3350 };
3351
3352 for (int n = 0; n < ecb_array_length (dxyz); ++n)
3353 {
3354 int r = idx_r + dxyz[n][0];
3355 int g = idx_g + dxyz[n][1];
3356 int b = idx_b + dxyz[n][2];
3357
3358 if (!IN_RANGE_EXC (r, 0, Red_levels )) continue;
3359 if (!IN_RANGE_EXC (g, 0, Green_levels)) continue;
3360 if (!IN_RANGE_EXC (b, 0, Blue_levels )) continue;
3361
3362 unsigned int index = colorcube_index (r, g, b);
3363
3364 if (rgb24_color[index] == color)
3365 {
3366 rgb24_seqno[index] = ++rgb24_sequence;
3367 return index + minTermCOLOR24;
3368 }
3369
3370 // minor issue: could update index 0 few more times
3371 if ((rgb24_seqno[index] | rgb24_color[index]) == 0)
3372 {
3373 idx = index;
3374 goto update;
3375 }
3376
3377 // like (rgb24_seqno[idx] > rgb24_seqno[index])
3378 // but also handles wrap around values good enough
3379 if ((uint16_t)(rgb24_seqno[idx] - rgb24_seqno[index]) < 0x7fff)
3380 idx = index;
3381 }
3382
3383update:
3384 rgb24_color[idx] = color;
3385 rgb24_seqno[idx] = ++rgb24_sequence;
3386
3387 idx += minTermCOLOR24;
3388 pix_colors_focused [idx].free (this);
3389 pix_colors_focused [idx].set (this, rgba (r * 0x0101, g * 0x0101, b * 0x0101, a * 0x0101));
3390 update_fade_color (idx, false);
3391
3392 return idx;
3393}
3394
3649void 3395void
3650rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) 3396rxvt_term::process_color_seq (int report, int color, const char *str, char resp)
3651{ 3397{
3652 if (str[0] == '?' && !str[1]) 3398 if (str[0] == '?' && !str[1])
3653 { 3399 {
3654 unsigned short r, g, b; 3400 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3401 return;
3402
3403 rgba c;
3655 pix_colors_focused[color].get (display, r, g, b); 3404 pix_colors_focused[color].get (c);
3405 color -= minCOLOR;
3406
3407#if XFT
3408 if (c.a != rgba::MAX_CC)
3409 tt_printf ("\033]%d;%d;rgba:%04x/%04x/%04x/%04x%c", report, color, c.r, c.g, c.b, c.a, resp);
3410 else
3411#endif
3656 tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); 3412 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", report, color, c.r, c.g, c.b, resp);
3657 } 3413 }
3658 else 3414 else
3659 set_window_color (color, str); 3415 set_window_color (color, str);
3660} 3416}
3661 3417
3662/* 3418/*
3663 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3419 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3664 * 0 = change iconName/title
3665 * 1 = change iconName
3666 * 2 = change title
3667 * 4 = change color
3668 * 10 = change fg color
3669 * 11 = change bg color
3670 * 12 = change text color
3671 * 13 = change mouse foreground color
3672 * 17 = change highlight character colour
3673 * 18 = change bold character color
3674 * 19 = change underlined character color
3675 * 46 = change logfile (not implemented)
3676 * 50 = change font
3677 *
3678 * rxvt extensions:
3679 * 20 = bg pixmap
3680 * 39 = change default fg color
3681 * 49 = change default bg color
3682 * 55 = dump scrollback buffer and all of screen
3683 * 701 = change locale
3684 * 702 = find font
3685 * 703 = menu
3686 */ 3420 */
3687void 3421void
3688rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) 3422rxvt_term::process_xterm_seq (int op, char *str, char resp)
3689{ 3423{
3690 int changed = 0;
3691 int color; 3424 int color;
3692 char *buf, *name; 3425 char *buf, *name;
3693 bool query = str[0] == '?' && !str[1]; 3426 bool query = str[0] == '?' && !str[1];
3694 int saveop = op; 3427 int saveop = op;
3695 dDisp; 3428
3429 dLocal (Display *, dpy);
3696 3430
3697 assert (str != NULL); 3431 assert (str != NULL);
3432
3433 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3434 return;
3435
3698 switch (op) 3436 switch (op)
3699 { 3437 {
3700 case XTerm_name: 3438 case XTerm_name:
3701 set_title (str); 3439 set_title (str);
3702 /* FALLTHROUGH */ 3440 /* FALLTHROUGH */
3716 unsigned long bytes_after; 3454 unsigned long bytes_after;
3717 unsigned char *value = 0; 3455 unsigned char *value = 0;
3718 const char *str = ""; 3456 const char *str = "";
3719 3457
3720 if (prop 3458 if (prop
3721 && XGetWindowProperty (disp, TermWin.parent[0], 3459 && XGetWindowProperty (dpy, parent,
3722 prop, 0, 1<<16, 0, AnyPropertyType, 3460 prop, 0, 1<<16, 0, AnyPropertyType,
3723 &actual_type, &actual_format, 3461 &actual_type, &actual_format,
3724 &nitems, &bytes_after, &value) == Success 3462 &nitems, &bytes_after, &value) == Success
3725 && actual_type != None 3463 && actual_type != None
3726 && actual_format == 8) 3464 && actual_format == 8)
3727 str = (const char *)(value); 3465 str = (const char *)(value);
3728 3466
3729 tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); 3467 tt_printf ("\033]%d;%s%c", op, option (Opt_insecure) ? str : "", resp);
3730 3468
3731 XFree (value); 3469 XFree (value);
3732 } 3470 }
3733 else 3471 else
3734 { 3472 {
3735 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3473 char *eq = strchr (str, '=');
3736 3474
3737 if (eq) 3475 if (eq)
3738 { 3476 {
3739 *eq = 0; 3477 *eq = 0;
3740 set_utf8_property (display->atom (str), eq + 1); 3478 set_utf8_property (display->atom (str), eq + 1);
3741 } 3479 }
3742 else 3480 else
3743 XDeleteProperty (disp, TermWin.parent[0], 3481 XDeleteProperty (dpy, parent,
3744 display->atom (str)); 3482 display->atom (str));
3745 } 3483 }
3746 break; 3484 break;
3747 3485
3748 case XTerm_Color: 3486 case XTerm_Color:
3750 { 3488 {
3751 if ((name = strchr (buf, ';')) == NULL) 3489 if ((name = strchr (buf, ';')) == NULL)
3752 break; 3490 break;
3753 3491
3754 *name++ = '\0'; 3492 *name++ = '\0';
3755 color = atoi (buf); 3493 color = atoi (buf) + minCOLOR;
3756 3494
3757 if (color < 0 || color >= TOTAL_COLORS) 3495 if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR))
3758 break; 3496 break;
3759 3497
3760 if ((buf = strchr (name, ';')) != NULL) 3498 if ((buf = strchr (name, ';')) != NULL)
3761 *buf++ = '\0'; 3499 *buf++ = '\0';
3762 3500
3763 if (name[0] == '?' && !name[1]) 3501 process_color_seq (op, color, name, resp);
3764 {
3765 unsigned short r, g, b;
3766 pix_colors_focused[color + minCOLOR].get (display, r, g, b);
3767 tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp);
3768 }
3769 else
3770 set_window_color (color + minCOLOR, name);
3771 } 3502 }
3772 break; 3503 break;
3504 case Rxvt_restoreFG:
3773 case XTerm_Color00: 3505 case XTerm_Color00:
3774 process_color_seq (XTerm_Color00, Color_fg, str, resp); 3506 process_color_seq (op, Color_fg, str, resp);
3775 break; 3507 break;
3508 case Rxvt_restoreBG:
3776 case XTerm_Color01: 3509 case XTerm_Color01:
3777 process_color_seq (XTerm_Color00, Color_bg, str, resp); 3510 process_color_seq (op, Color_bg, str, resp);
3778 break; 3511 break;
3779#ifndef NO_CURSORCOLOR 3512#ifndef NO_CURSORCOLOR
3780 case XTerm_Color_cursor: 3513 case XTerm_Color_cursor:
3781 process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); 3514 process_color_seq (op, Color_cursor, str, resp);
3782 break; 3515 break;
3783#endif 3516#endif
3784 case XTerm_Color_pointer_fg: 3517 case XTerm_Color_pointer_fg:
3785 process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); 3518 process_color_seq (op, Color_pointer_fg, str, resp);
3786 break; 3519 break;
3787 case XTerm_Color_pointer_bg: 3520 case XTerm_Color_pointer_bg:
3788 process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); 3521 process_color_seq (op, Color_pointer_bg, str, resp);
3789 break; 3522 break;
3523#ifdef OPTION_HC
3524 case XTerm_Color_HC:
3525 process_color_seq (op, Color_HC, str, resp);
3526 break;
3527 case XTerm_Color_HTC:
3528 process_color_seq (op, Color_HTC, str, resp);
3529 break;
3530#endif
3790#ifndef NO_BOLD_UNDERLINE_REVERSE 3531#ifndef NO_BOLD_UNDERLINE_REVERSE
3791 case XTerm_Color_BD: 3532 case URxvt_Color_BD:
3792 process_color_seq (XTerm_Color_BD, Color_BD, str, resp); 3533 process_color_seq (op, Color_BD, str, resp);
3793 break; 3534 break;
3794 case XTerm_Color_IT:
3795 process_color_seq (XTerm_Color_IT, Color_IT, str, resp);
3796 break;
3797 case XTerm_Color_UL: 3535 case URxvt_Color_UL:
3798 process_color_seq (XTerm_Color_UL, Color_UL, str, resp); 3536 process_color_seq (op, Color_UL, str, resp);
3799 break; 3537 break;
3800 case XTerm_Color_RV: 3538 case URxvt_Color_IT:
3539 process_color_seq (op, Color_IT, str, resp);
3540 break;
3541#endif
3542 case URxvt_Color_border:
3801 process_color_seq (XTerm_Color_RV, Color_RV, str, resp); 3543 process_color_seq (op, Color_border, str, resp);
3802 break;
3803#endif
3804#if TRANSPARENT && TINTING
3805 case XTerm_Color_tint:
3806 process_color_seq (XTerm_Color_tint, Color_tint, str, resp);
3807 check_our_parents ();
3808 if (am_transparent)
3809 want_full_refresh = want_refresh = 1;
3810 break;
3811#endif
3812
3813 case XTerm_Pixmap:
3814 if (*str != ';')
3815 {
3816#if XPM_BACKGROUND
3817 scale_pixmap (""); /* reset to default scaling */
3818 set_bgPixmap (str); /* change pixmap */
3819#endif
3820 scr_touch (true);
3821 }
3822 while ((str = strchr (str, ';')) != NULL)
3823 {
3824 str++;
3825#if XPM_BACKGROUND
3826 changed += scale_pixmap (str);
3827#endif
3828 }
3829
3830 if (changed)
3831 {
3832#ifdef XPM_BACKGROUND
3833 resize_pixmap ();
3834#endif
3835 scr_touch (true);
3836 }
3837 break;
3838
3839 case XTerm_restoreFG:
3840 set_window_color (Color_fg, str);
3841 break;
3842 case XTerm_restoreBG:
3843 set_window_color (Color_bg, str);
3844 break; 3544 break;
3845 3545
3846 case XTerm_logfile: 3546 case XTerm_logfile:
3847 // TODO, when secure mode? 3547 // TODO, when secure mode?
3848 break; 3548 break;
3849 3549
3550#if 0
3551 case Rxvt_dumpscreen: /* no error notices */
3552 {
3553 int fd;
3554 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3555 {
3556 scr_dump (fd);
3557 close (fd);
3558 }
3559 }
3560 break;
3561#endif
3850 case XTerm_font: 3562 case XTerm_font:
3851 op = URxvt_font; 3563 op = URxvt_font;
3852 case URxvt_font: 3564 case URxvt_font:
3853#if ENABLE_STYLES 3565#if ENABLE_STYLES
3854 case URxvt_boldFont: 3566 case URxvt_boldFont:
3855 case URxvt_italicFont: 3567 case URxvt_italicFont:
3856 case URxvt_boldItalicFont: 3568 case URxvt_boldItalicFont:
3857#endif 3569#endif
3858 if (query) 3570 if (query)
3859 tt_printf ("\33]%d;%-.250s%c", saveop, 3571 tt_printf ("\33]%d;%-.250s%c", saveop,
3860 (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc 3572 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3861 ? TermWin.fontset[op - URxvt_font]->fontdesc : "", 3573 ? fontset[op - URxvt_font]->fontdesc : "",
3862 resp); 3574 resp);
3863 else 3575 else
3864 { 3576 {
3865 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3577 const char *&res = rs[Rs_font + (op - URxvt_font)];
3866 3578
3868 allocated.push_back ((void *)res); 3580 allocated.push_back ((void *)res);
3869 set_fonts (); 3581 set_fonts ();
3870 } 3582 }
3871 break; 3583 break;
3872 3584
3873#if ENABLE_FRILLS 3585 case URxvt_version:
3874 case XTerm_locale:
3875 if (query) 3586 if (query)
3587 tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c",
3588 op,
3589 rs[Rs_name], VERSION[0], VERSION[2],
3590 resp);
3591 break;
3592
3593#if !ENABLE_MINIMAL
3594 case URxvt_locale:
3595 if (query)
3876 tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); 3596 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3877 else 3597 else
3878 { 3598 {
3879 set_locale (str); 3599 set_locale (str);
3880 pty.set_utf8_mode (enc_utf8); 3600 pty->set_utf8_mode (enc_utf8);
3881# ifdef USE_XIM
3882 im_cb (); 3601 init_xlocale ();
3883# endif
3884 } 3602 }
3885 break; 3603 break;
3886#endif
3887 3604
3888#ifdef MENUBAR 3605 case URxvt_view_up:
3889 case XTerm_Menu: 3606 case URxvt_view_down:
3890 if (options & Opt_insecure) 3607 {
3891 menubar_dispatch (const_cast<char *>(str)); // casting away constness is checked 3608 int lines = atoi (str);
3609
3610 if (lines)
3611 scr_page (op == URxvt_view_up ? UP : DN, lines);
3612 else
3613 scr_erase_savelines ();
3614 }
3615
3892 break; 3616 break;
3893#endif 3617#endif
3894#if 0 3618
3895 case XTerm_dumpscreen: /* no error notices */ 3619#if ENABLE_PERL
3896 { 3620 case URxvt_perl:
3897 int fd; 3621 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3898 if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0)
3899 {
3900 scr_dump (fd);
3901 close (fd);
3902 }
3903 }
3904 break; 3622 break;
3905#endif 3623#endif
3906 } 3624 }
3907} 3625}
3908/*----------------------------------------------------------------------*/ 3626/*----------------------------------------------------------------------*/
3915 * 's' = save 3633 * 's' = save
3916 * 'r' = restore 3634 * 'r' = restore
3917 * 't' = toggle 3635 * 't' = toggle
3918 * so no need for fancy checking 3636 * so no need for fancy checking
3919 */ 3637 */
3920int 3638int ecb_cold
3921rxvt_term::privcases (int mode, unsigned long bit) 3639rxvt_term::privcases (int mode, unsigned long bit)
3922{ 3640{
3923 int state; 3641 int state;
3924 3642
3925 if (mode == 's') 3643 if (mode == 's')
3926 { 3644 {
3927 SavedModes |= (priv_modes & bit); 3645 if (priv_modes & bit)
3646 SavedModes |= bit;
3647 else
3648 SavedModes &= ~bit;
3928 return -1; 3649 return -1;
3929 } 3650 }
3930 else 3651 else
3931 { 3652 {
3932 if (mode == 'r') 3653 if (mode == 'r')
3933 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3654 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3934 else 3655 else
3935 state = (mode == 't') ? ! (priv_modes & bit) : mode; 3656 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3936 PrivMode (state, bit); 3657
3658 if (state)
3659 priv_modes |= bit;
3660 else
3661 priv_modes &= ~bit;
3937 } 3662 }
3938 3663
3939 return state; 3664 return state;
3940} 3665}
3941 3666
3942/* we're not using priv _yet_ */ 3667/* we're not using priv _yet_ */
3943void 3668void
3944rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) 3669rxvt_term::process_terminal_mode (int mode, int priv ecb_unused, unsigned int nargs, const int *arg)
3945{ 3670{
3946 unsigned int i, j; 3671 unsigned int i, j;
3947 int state; 3672 int state;
3948 3673
3949 static const struct 3674 static const struct
3950 { 3675 {
3951 const int argval; 3676 const int argval;
3952 const unsigned long bit; 3677 const unsigned long bit;
3953 }
3954
3955 argtopriv[] = { 3678 } argtopriv[] = {
3956 { 1, PrivMode_aplCUR }, 3679 { 1, PrivMode_aplCUR }, // DECCKM
3957 { 2, PrivMode_vt52 }, 3680 { 2, PrivMode_vt52 }, // DECANM
3958 { 3, PrivMode_132 }, 3681 { 3, PrivMode_132 }, // DECCOLM
3959 { 4, PrivMode_smoothScroll }, 3682 { 4, PrivMode_smoothScroll }, // DECSCLM
3960 { 5, PrivMode_rVideo }, 3683 { 5, PrivMode_rVideo }, // DECSCNM
3961 { 6, PrivMode_relOrigin }, 3684 { 6, PrivMode_relOrigin }, // DECOM
3962 { 7, PrivMode_Autowrap }, 3685 { 7, PrivMode_Autowrap }, // DECAWM
3963 // 8, bi-directional support mode 3686 // 8, auto-repeat keys // DECARM
3964 { 9, PrivMode_MouseX10 }, 3687 { 9, PrivMode_MouseX10 },
3965#ifdef menuBar_esc
3966 { menuBar_esc, PrivMode_menuBar },
3967#endif
3968 // 18, 19 printing-related
3969 { 25, PrivMode_VisibleCursor }, 3688 { 12, PrivMode_BlinkingCursor },
3689 // 18 end FF to printer after print screen
3690 // 19 Print screen prints full screen/scroll region
3691 { 25, PrivMode_VisibleCursor }, // DECTCEM cnorm/cvvis/civis
3970#ifdef scrollBar_esc 3692#ifdef scrollBar_esc
3971 { scrollBar_esc, PrivMode_scrollBar }, 3693 { scrollBar_esc, PrivMode_scrollBar },
3972#endif 3694#endif
3973 { 35, PrivMode_ShiftKeys }, // rxvt extension 3695 { 35, PrivMode_ShiftKeys }, // rxvt extension
3696 // 38, tektronix mode // DECTEK
3974 { 40, PrivMode_132OK }, 3697 { 40, PrivMode_132OK },
3975 // 41 xterm more fixes NYI 3698 // 41 xterm more fixes NYI
3976 // 45 margin bell NYI 3699 // 45 margin bell NYI
3977 // 46 start logging 3700 // 46 start logging
3978 { 47, PrivMode_Screen }, 3701 { 47, PrivMode_Screen },
3979 { 66, PrivMode_aplKP }, 3702 { 66, PrivMode_aplKP }, // DECNKM
3980#ifndef NO_BACKSPACE_KEY 3703#ifndef NO_BACKSPACE_KEY
3981 { 67, PrivMode_BackSpace }, 3704 { 67, PrivMode_BackSpace }, // DECBKM
3982#endif 3705#endif
3983 { 1000, PrivMode_MouseX11 }, 3706 { 1000, PrivMode_MouseX11 },
3984 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3707 { 1002, PrivMode_MouseBtnEvent },
3985 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3708 { 1003, PrivMode_MouseAnyEvent },
3986 // 1003 Use All Motion Mouse Tracking. NYI, TODO 3709#if ENABLE_FRILLS
3710 { 1004, PrivMode_FocusEvent },
3711 { 1005, PrivMode_ExtMouseUTF8 },
3712 { 1006, PrivMode_ExtMouseSGR },
3713#endif
3987 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3714 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3988 { 1011, PrivMode_Keypress }, // rxvt extension 3715 { 1011, PrivMode_Keypress }, // rxvt extension
3716#if ENABLE_FRILLS
3717 { 1015, PrivMode_ExtMouseUrxvt }, // urxvt extension of 1005
3718#endif
3989 // 1035 enable modifiers for alt, numlock NYI 3719 // 1035 enable modifiers for alt, numlock NYI
3990 // 1036 send ESC for meta keys NYI 3720 // 1036 send ESC for meta keys NYI
3991 // 1037 send DEL for keypad delete NYI 3721 // 1037 send DEL for keypad delete NYI
3992 { 1047, PrivMode_Screen }, 3722 { 1047, PrivMode_Screen },
3993 // 1048 save and restore cursor 3723 // 1048 save and restore cursor, implemented in code
3994 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3724 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3995 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3725 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3726 { 2004, PrivMode_BracketPaste },
3996 }; 3727 };
3997 3728
3998 if (nargs == 0) 3729 if (nargs == 0)
3999 return; 3730 return;
4000 3731
4007 for (i = 0; i < nargs; i++) 3738 for (i = 0; i < nargs; i++)
4008 { 3739 {
4009 state = -1; 3740 state = -1;
4010 3741
4011 /* basic handling */ 3742 /* basic handling */
4012 for (j = 0; j < (sizeof (argtopriv)/sizeof (argtopriv[0])); j++) 3743 for (j = 0; j < ecb_array_length (argtopriv); j++)
4013 if (argtopriv[j].argval == arg[i]) 3744 if (argtopriv[j].argval == arg[i])
4014 { 3745 {
4015 state = privcases (mode, argtopriv[j].bit); 3746 state = privcases (mode, argtopriv[j].bit);
4016 break; 3747 break;
4017 } 3748 }
4018 3749
4019 /* extra handling for values with state unkept */ 3750 /* extra handling for values with state unkept */
4020 switch (arg[i]) 3751 switch (arg[i])
4021 { 3752 {
3753#if ENABLE_STYLES
3754 case 1021:
3755 set_option (Opt_intensityStyles, mode);
3756
3757 scr_touch (true);
3758 break;
3759#endif
4022 case 1048: /* alternative cursor save */ 3760 case 1048: /* alternative cursor save */
4023 case 1049:
4024 if (options & Opt_secondaryScreen) 3761 if (option (Opt_secondaryScreen))
4025 if (mode == 0) 3762 if (mode == 0)
4026 scr_cursor (RESTORE); 3763 scr_cursor (RESTORE);
4027 else if (mode == 1) 3764 else if (mode == 1)
4028 scr_cursor (SAVE); 3765 scr_cursor (SAVE);
4029 break; 3766 break;
4037 case 2: /* VT52 mode */ 3774 case 2: /* VT52 mode */
4038 /* oddball mode. should be set regardless of set/reset 3775 /* oddball mode. should be set regardless of set/reset
4039 * parameter. Return from VT52 mode with an ESC < from 3776 * parameter. Return from VT52 mode with an ESC < from
4040 * within VT52 mode 3777 * within VT52 mode
4041 */ 3778 */
4042 PrivMode (1, PrivMode_vt52); 3779 priv_modes |= PrivMode_vt52;
4043 break; 3780 break;
4044 case 3: /* 80/132 */ 3781 case 3: /* 80/132 */
4045 if (priv_modes & PrivMode_132OK) 3782 if (priv_modes & PrivMode_132OK)
4046 set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); 3783 set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight);
4047 break; 3784 break;
4048 case 4: /* smooth scrolling */ 3785 case 4: /* smooth scrolling */
4049 if (state)
4050 options &= ~Opt_jumpScroll;
4051 else
4052 options |= Opt_jumpScroll; 3786 set_option (Opt_jumpScroll, !state);
4053 break; 3787 break;
4054 case 5: /* reverse video */ 3788 case 5: /* reverse video */
4055 scr_rvideo_mode (state); 3789 scr_rvideo_mode (state);
4056 break; 3790 break;
4057 case 6: /* relative/absolute origins */ 3791 case 6: /* relative/absolute origins */
4061 scr_autowrap (state); 3795 scr_autowrap (state);
4062 break; 3796 break;
4063 /* case 8: - auto repeat, can't do on a per window basis */ 3797 /* case 8: - auto repeat, can't do on a per window basis */
4064 case 9: /* X10 mouse reporting */ 3798 case 9: /* X10 mouse reporting */
4065 if (state) /* orthogonal */ 3799 if (state) /* orthogonal */
4066 priv_modes &= ~PrivMode_MouseX11; 3800 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4067 break; 3801 break;
4068#ifdef menuBar_esc
4069 case menuBar_esc:
4070#ifdef MENUBAR
4071 map_menuBar (state);
4072#endif
4073 break;
4074#endif
4075#ifdef scrollBar_esc 3802#ifdef scrollBar_esc
4076 case scrollBar_esc: 3803 case scrollBar_esc:
4077 if (scrollbar_mapping (state)) 3804 scrollBar.map (state);
4078 {
4079 resize_all_windows (0, 0, 0); 3805 resize_all_windows (0, 0, 0);
4080 scr_touch (true); 3806 scr_touch (true);
4081 } 3807 break;
3808#endif
3809#ifdef CURSOR_BLINK
3810 case 12:
3811 cursor_blink_reset ();
4082 break; 3812 break;
4083#endif 3813#endif
4084 case 25: /* visible/invisible cursor */ 3814 case 25: /* visible/invisible cursor */
4085 scr_cursor_visible (state); 3815 scr_cursor_visible (state);
4086 break; 3816 break;
4091 break; 3821 break;
4092 /* case 66: - application key pad */ 3822 /* case 66: - application key pad */
4093 /* case 67: - backspace key */ 3823 /* case 67: - backspace key */
4094 case 1000: /* X11 mouse reporting */ 3824 case 1000: /* X11 mouse reporting */
4095 if (state) /* orthogonal */ 3825 if (state) /* orthogonal */
4096 priv_modes &= ~PrivMode_MouseX10; 3826 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4097 break; 3827 break;
4098#if 0
4099 case 1001: 3828 case 1002:
4100 break; /* X11 mouse highlighting */ 3829 case 1003:
4101#endif 3830 if (state)
3831 {
3832 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3833 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3834 mouse_row = mouse_col = 0;
3835 vt_emask_mouse = PointerMotionMask;
3836 }
3837 else
3838 vt_emask_mouse = NoEventMask;
3839
3840 vt_select_input ();
3841 break;
4102 case 1010: /* scroll to bottom on TTY output inhibit */ 3842 case 1010: /* scroll to bottom on TTY output inhibit */
4103 if (state)
4104 options &= ~Opt_scrollTtyOutput;
4105 else
4106 options |= Opt_scrollTtyOutput; 3843 set_option (Opt_scrollTtyOutput, !state);
4107 break; 3844 break;
4108 case 1011: /* scroll to bottom on key press */ 3845 case 1011: /* scroll to bottom on key press */
4109 if (state)
4110 options |= Opt_scrollTtyKeypress; 3846 set_option (Opt_scrollTtyKeypress, state);
4111 else
4112 options &= ~Opt_scrollTtyKeypress;
4113 break; 3847 break;
4114 case 1047: /* secondary screen w/ clearing last */ 3848 case 1047: /* secondary screen w/ clearing last */
4115 if (options & Opt_secondaryScreen) 3849 if (option (Opt_secondaryScreen))
4116 if (current_screen != PRIMARY) 3850 if (!state)
4117 scr_erase_screen (2); 3851 scr_erase_screen (2);
3852
4118 scr_change_screen (state); 3853 scr_change_screen (state);
4119 break; 3854 break;
4120 case 1049: /* secondary screen w/ clearing first */ 3855 case 1049: /* secondary screen w/ clearing first */
3856 if (option (Opt_secondaryScreen))
3857 if (state)
3858 scr_cursor (SAVE);
3859
4121 scr_change_screen (state); 3860 scr_change_screen (state);
3861
4122 if (options & Opt_secondaryScreen) 3862 if (option (Opt_secondaryScreen))
4123 if (current_screen != PRIMARY) 3863 if (state)
4124 scr_erase_screen (2); 3864 scr_erase_screen (2);
3865 else
3866 scr_cursor (RESTORE);
4125 break; 3867 break;
4126 default: 3868 default:
4127 break; 3869 break;
4128 } 3870 }
4129 } 3871 }
4130} 3872}
4131/*}}} */ 3873/*}}} */
4132 3874
4133/*{{{ process sgr sequences */ 3875/*{{{ process sgr sequences */
4134void 3876void ecb_hot
4135rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) 3877rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg)
4136{ 3878{
4137 unsigned int i; 3879 unsigned int i;
4138 short rendset; 3880 short rendset;
4139 int rendstyle; 3881 int rendstyle;
4181 //case 19: // ninth alt font 3923 //case 19: // ninth alt font
4182 //case 20: // gothic 3924 //case 20: // gothic
4183 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613) 3925 case 21: // disable bold, faint, sometimes doubly underlined (iso 8613)
4184 rendset = 0, rendstyle = RS_Bold; 3926 rendset = 0, rendstyle = RS_Bold;
4185 break; 3927 break;
4186 case 22: // normal intensity 3928 case 22: // bold off (vt220)
4187 rendset = 0, rendstyle = RS_Bold; 3929 rendset = 0, rendstyle = RS_Bold;
4188 break; 3930 break;
4189 case 23: // disable italic 3931 case 23: // disable italic
4190 rendset = 0, rendstyle = RS_Italic; 3932 rendset = 0, rendstyle = RS_Italic;
4191 break; 3933 break;
4192 case 24: 3934 case 24: // underline off (vt220)
4193 rendset = 0, rendstyle = RS_Uline; 3935 rendset = 0, rendstyle = RS_Uline;
4194 break; 3936 break;
4195 case 25: 3937 case 25: // blink off (vt220)
4196 rendset = 0, rendstyle = RS_Blink; 3938 rendset = 0, rendstyle = RS_Blink;
4197 break; 3939 break;
4198 case 26: // variable spacing (iso 8613) 3940 case 26: // variable spacing (iso 8613)
4199 rendset = 0, rendstyle = RS_Blink; 3941 rendset = 0, rendstyle = RS_Blink;
4200 break; 3942 break;
4201 case 27: 3943 case 27: // reverse off (vt220)
4202 rendset = 0, rendstyle = RS_RVid; 3944 rendset = 0, rendstyle = RS_RVid;
4203 break; 3945 break;
4204 //case 28: // visible. NYI 3946 //case 28: // visible. NYI
4205 //case 29: // not crossed-out 3947 //case 29: // not crossed-out
4206 } 3948 }
4221 case 35: 3963 case 35:
4222 case 36: 3964 case 36:
4223 case 37: 3965 case 37:
4224 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg); 3966 scr_color ((unsigned int) (minCOLOR + (arg[i] - 30)), Color_fg);
4225 break; 3967 break;
4226 case 38: // set fg color, ISO 8613-6
4227 if (nargs > i + 2 && arg[i + 1] == 5)
4228 {
4229 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_fg);
4230 i += 2;
4231 }
4232 break;
4233 case 39: /* default fg */ 3968 case 39: /* default fg */
4234 scr_color (Color_fg, Color_fg); 3969 scr_color (Color_fg, Color_fg);
4235 break; 3970 break;
4236 3971
4237 case 40: 3972 case 40:
4242 case 45: 3977 case 45:
4243 case 46: 3978 case 46:
4244 case 47: 3979 case 47:
4245 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg); 3980 scr_color ((unsigned int) (minCOLOR + (arg[i] - 40)), Color_bg);
4246 break; 3981 break;
4247 case 48: // set bg color, ISO 8613-6
4248 if (nargs > i + 2 && arg[i + 1] == 5)
4249 {
4250 scr_color ((unsigned int) (minCOLOR + arg[i + 2]), Color_bg);
4251 i += 2;
4252 }
4253 break;
4254 case 49: /* default bg */ 3982 case 49: /* default bg */
4255 scr_color (Color_bg, Color_bg); 3983 scr_color (Color_bg, Color_bg);
4256 break; 3984 break;
4257 3985
3986 case 38: // set fg color, ISO 8613-6
3987 case 48: // set bg color, ISO 8613-6
3988 {
3989 unsigned int fgbg = arg[i] == 38 ? Color_fg : Color_bg;
3990 unsigned int idx;
3991
3992 if (nargs > i + 2 && arg[i + 1] == 5)
3993 {
3994 idx = minCOLOR + arg[i + 2];
3995 i += 2;
3996
3997 scr_color (idx, fgbg);
3998 }
3999 else if (nargs > i + 4 && arg[i + 1] == 2)
4000 {
4001 unsigned int r = arg[i + 2];
4002 unsigned int g = arg[i + 3];
4003 unsigned int b = arg[i + 4];
4004 unsigned int a = 0xff;
4005
4006 idx = map_rgb24_color (r, g, b, a);
4007
4008 i += 4;
4009
4010 scr_color (idx, fgbg);
4011 }
4012 }
4013 break;
4014
4258 //case 50: // not variable spacing 4015 //case 50: // not variable spacing
4259 4016
4260#ifndef NO_BRIGHTCOLOR 4017#if !ENABLE_MINIMAL
4261 case 90: 4018 case 90:
4262 case 91: /* set bright fg color */ 4019 case 91: /* set bright fg color */
4263 case 92: 4020 case 92:
4264 case 93: 4021 case 93:
4265 case 94: 4022 case 94:
4277 case 106: 4034 case 106:
4278 case 107: 4035 case 107:
4279 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg); 4036 scr_color ((unsigned int) (minBrightCOLOR + (arg[i] - 100)), Color_bg);
4280 break; 4037 break;
4281#endif 4038#endif
4282
4283 } 4039 }
4284 } 4040 }
4041}
4042
4043void
4044rxvt_term::set_cursor_style (int style)
4045{
4046 if (!IN_RANGE_INC (style, 0, 6))
4047 return;
4048
4049 if (style == 0)
4050 style = 1;
4051
4052 cursor_type = (style - 1) / 2;
4053 set_option (Opt_cursorUnderline, cursor_type == 1);
4054
4055#ifdef CURSOR_BLINK
4056 set_option (Opt_cursorBlink, style & 1);
4057 cursor_blink_reset ();
4058#endif
4059
4060 want_refresh = 1;
4285} 4061}
4286/*}}} */ 4062/*}}} */
4287 4063
4288/*{{{ (do not) process Rob Nation's own graphics mode sequences */
4289void
4290rxvt_term::process_graphics ()
4291{
4292 unicode_t ch, cmd = cmd_getc ();
4293
4294 if (cmd == 'Q')
4295 { /* query graphics */
4296 tt_printf ("\033G0\012"); /* no graphics */
4297 return;
4298 }
4299 /* swallow other graphics sequences until terminating ':' */
4300 do
4301 ch = cmd_getc ();
4302 while (ch != ':');
4303}
4304/*}}} */
4305
4306/* ------------------------------------------------------------------------- */ 4064/* ---------------------------------------------------------------------- */
4065/* Write data to the pty as typed by the user, pasted with the mouse,
4066 * or generated by us in response to a query ESC sequence.
4067 */
4307 4068
4308/* 4069/*
4309 * Send printf () formatted output to the command. 4070 * Send printf () formatted output to the command.
4310 * Only use for small amounts of data. 4071 * Only use for small amounts of data.
4311 */ 4072 */
4312void 4073void
4313rxvt_term::tt_printf (const char *fmt,...) 4074rxvt_term::tt_printf (const char *fmt,...)
4314{ 4075{
4315 va_list arg_ptr; 4076 va_list arg_ptr;
4316 unsigned char buf[256]; 4077 char buf[256];
4317 4078
4318 va_start (arg_ptr, fmt); 4079 va_start (arg_ptr, fmt);
4319 vsnprintf ((char *)buf, 256, fmt, arg_ptr); 4080 vsnprintf ((char *)buf, 256, fmt, arg_ptr);
4320 va_end (arg_ptr); 4081 va_end (arg_ptr);
4321 tt_write (buf, strlen (buf)); 4082 tt_write (buf, strlen (buf));
4322} 4083}
4323 4084
4324/* ---------------------------------------------------------------------- */
4325/* Write data to the pty as typed by the user, pasted with the mouse, 4085/* Write data to the pty as typed by the user. */
4326 * or generated by us in response to a query ESC sequence.
4327 */
4328const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4329
4330void 4086void
4331rxvt_term::tt_write (const unsigned char *data, unsigned int len) 4087rxvt_term::tt_write_user_input (const char *data, unsigned int len)
4332{ 4088{
4089 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
4090 return;
4091
4092 if (option (Opt_scrollTtyKeypress))
4093 if (view_start)
4094 {
4095 view_start = 0;
4096 want_refresh = 1;
4097 }
4098
4099 tt_write_ (data, len);
4100}
4101
4102void
4103rxvt_term::tt_write (const char *data, unsigned int len)
4104{
4105 if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END)))
4106 return;
4107
4108 tt_write_ (data, len);
4109}
4110
4111static const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT
4112
4113void
4114rxvt_term::tt_write_ (const char *data, unsigned int len)
4115{
4116 if (pty->pty < 0)
4117 return;
4118
4333 if (v_buflen == 0) 4119 if (v_buflen == 0)
4334 { 4120 {
4335 ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); 4121 ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE));
4336 4122
4123 max_it (written, 0);
4124
4337 if ((unsigned int)written == len) 4125 if (written == len)
4338 return; 4126 return;
4339 4127
4340 data += written; 4128 data += written;
4341 len -= written; 4129 len -= written;
4342 } 4130 }
4343 4131
4344 v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); 4132 v_buffer = (char *)rxvt_realloc (v_buffer, v_buflen + len);
4345 4133
4346 memcpy (v_buffer + v_buflen, data, len); 4134 memcpy (v_buffer + v_buflen, data, len);
4347 v_buflen += len; 4135 v_buflen += len;
4348 4136
4349 pty_ev.set (EVENT_READ | EVENT_WRITE); 4137 pty_ev.set (ev::READ | ev::WRITE);
4350} 4138}
4351 4139
4352void rxvt_term::pty_write () 4140void rxvt_term::pty_write ()
4353{ 4141{
4354 int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4142 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4355 4143
4356 if (written > 0) 4144 if (written > 0)
4357 { 4145 {
4358 v_buflen -= written; 4146 v_buflen -= written;
4359 4147
4360 if (v_buflen == 0) 4148 if (v_buflen == 0)
4361 { 4149 {
4362 free (v_buffer); 4150 free (v_buffer);
4363 v_buffer = 0; 4151 v_buffer = 0;
4364 v_buflen = 0;
4365 4152
4366 pty_ev.set (EVENT_READ); 4153 pty_ev.set (ev::READ);
4367 return; 4154 return;
4368 } 4155 }
4369 4156
4370 memmove (v_buffer, v_buffer + written, v_buflen); 4157 memmove (v_buffer, v_buffer + written, v_buflen);
4371 } 4158 }
4372 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4159 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4373 // original code just ignores this... 4160 pty_ev.set (ev::READ);
4374 destroy ();
4375} 4161}
4376 4162
4377/*----------------------- end-of-file (C source) -----------------------*/ 4163/*----------------------- end-of-file (C source) -----------------------*/
4378 4164

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines