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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines