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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines