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.302 by root, Tue Jan 31 21:35:39 2006 UTC vs.
Revision 1.438 by root, Thu Feb 4 21:55:12 2010 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: command.C 2 * File: command.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> 6 * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk>
25 * - extensive modifications 25 * - extensive modifications
26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org> 26 * Copyright (c) 1998 Alfredo K. Kojima <kojima@windowmaker.org>
27 * Copyright (c) 2001 Marius Gedminas 27 * Copyright (c) 2001 Marius Gedminas
28 * - Ctrl/Mod4+Tab works like Meta+Tab (options) 28 * - Ctrl/Mod4+Tab works like Meta+Tab (options)
29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org> 29 * Copyright (c) 2003 Rob McMullen <robm@flipturn.org>
30 * Copyright (c) 2003-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.
55# include "keyboard.h" 56# include "keyboard.h"
56#endif 57#endif
57 58
58#include <csignal> 59#include <csignal>
59 60
61#if LINUX_YIELD_HACK
62# include <ctime>
63#endif
64
60/*----------------------------------------------------------------------*/ 65/*----------------------------------------------------------------------*/
61 66
62#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) 67#define IS_CONTROL(ch) !((ch) & 0xffffff60UL)
63 68
64#if ENABLE_FRILLS || ISO_14755 69#if ENABLE_FRILLS || ISO_14755
91 XK_Shift_L, 0x21e7, 96 XK_Shift_L, 0x21e7,
92 XK_Shift_R, 0x21e7, 97 XK_Shift_R, 0x21e7,
93 98
94 XK_Shift_Lock, 0x21eb, 99 XK_Shift_Lock, 0x21eb,
95 XK_ISO_Lock, 0x21eb, 100 XK_ISO_Lock, 0x21eb,
96 XK_ISO_Lock, 0x21eb,
97 XK_Caps_Lock, 0x21ec, 101 XK_Caps_Lock, 0x21ec,
98 XK_Num_Lock, 0x21ed, 102 XK_Num_Lock, 0x21ed,
99 XK_ISO_Level3_Shift, 0x21ee, 103 XK_ISO_Level3_Shift, 0x21ee,
100 XK_ISO_Level3_Lock, 0x21ef, 104 XK_ISO_Level3_Lock, 0x21ef,
101 XK_ISO_Group_Lock, 0x21f0, 105 XK_ISO_Group_Lock, 0x21f0,
195 r & RS_Uline ? " uline" : "", 199 r & RS_Uline ? " uline" : "",
196 r & RS_Careful ? " careful" : ""); 200 r & RS_Careful ? " careful" : "");
197 201
198 int width = wcswidth (fname, wcslen (fname)); 202 int width = wcswidth (fname, wcslen (fname));
199 203
200 max_it (width, 8+5); // for char + hey 204 max_it (width, 8+5); // for char + hex
201 max_it (width, strlen (attr)); 205 max_it (width, strlen (attr));
202 206
203 if (y >= 0) 207 if (y >= 0)
204 { 208 {
205 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; 209 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
217 ch = *chr++; 221 ch = *chr++;
218 222
219 sprintf (buf, "%8x", ch); 223 sprintf (buf, "%8x", ch);
220 scr_overlay_set (0, y, buf); 224 scr_overlay_set (0, y, buf);
221 scr_overlay_set (9, y, '='); 225 scr_overlay_set (9, y, '=');
222# if !UNICODE3 226# if !UNICODE_3
223 if (ch >= 0x10000) 227 if (ch >= 0x10000)
224 ch = 0xfffd; 228 ch = 0xfffd;
225# endif 229# endif
226 scr_overlay_set (11, y, ch, r); 230 scr_overlay_set (11, y, ch, r);
227 231
275 } 279 }
276 280
277 iso14755buf = 0; 281 iso14755buf = 0;
278} 282}
279 283
280int 284static int
281rxvt_term::hex_keyval (XKeyEvent &ev) 285hex_keyval (XKeyEvent &ev)
282{ 286{
283 // check wether this event corresponds to a hex digit 287 // check wether this event corresponds to a hex digit
284 // if the modifiers had not been pressed. 288 // if the modifiers had not been pressed.
285 for (int index = 0; index < 8; index++) 289 for (int index = 0; index < 8; index++)
286 { 290 {
294 298
295 return -1; 299 return -1;
296} 300}
297#endif 301#endif
298 302
299/*{{{ 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
300void 398void
301rxvt_term::lookup_key (XKeyEvent &ev) 399rxvt_term::key_press (XKeyEvent &ev)
302{ 400{
303 int ctrl, meta, shft, len; 401 int ctrl, meta, shft, len;
304 unsigned int newlen;
305 KeySym keysym; 402 KeySym keysym;
306 int valid_keysym; 403 int valid_keysym;
307 char kbuf[KBUFSZ]; 404 char kbuf[KBUFSZ];
405
406#if ISO_14755
407 if (iso14755buf & ISO_14755_52)
408 return;
409#endif
308 410
309 /* 411 /*
310 * 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
311 * escape sequence to toggle the Keypad. 413 * escape sequence to toggle the Keypad.
312 * 414 *
317 meta = ev.state & ModMetaMask; 419 meta = ev.state & ModMetaMask;
318 420
319 if (numlock_state || (ev.state & ModNumLockMask)) 421 if (numlock_state || (ev.state & ModNumLockMask))
320 { 422 {
321 numlock_state = (ev.state & ModNumLockMask); 423 numlock_state = (ev.state & ModNumLockMask);
322 PrivMode ((!numlock_state), PrivMode_aplKP); 424 set_privmode (PrivMode_aplKP, !numlock_state);
323 } 425 }
324 426
325 kbuf[0] = 0; 427 kbuf[0] = 0;
326 428
327#ifdef USE_XIM 429#ifdef USE_XIM
403#ifdef PAGING_CONTEXT_LINES 505#ifdef PAGING_CONTEXT_LINES
404 lnsppg = nrow - PAGING_CONTEXT_LINES; 506 lnsppg = nrow - PAGING_CONTEXT_LINES;
405#else 507#else
406 lnsppg = nrow * 4 / 5; 508 lnsppg = nrow * 4 / 5;
407#endif 509#endif
510 max_it (lnsppg, 1);
511
408 if (keysym == XK_Prior) 512 if (keysym == XK_Prior)
409 { 513 {
410 scr_page (UP, lnsppg); 514 scr_page (UP, lnsppg);
411 return; 515 return;
412 } 516 }
477 } 581 }
478 } 582 }
479 583
480#if ENABLE_FRILLS || ISO_14755 584#if ENABLE_FRILLS || ISO_14755
481 // ISO 14755 support 585 // ISO 14755 support
482 if (shft && ctrl) 586 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_51))
483 { 587 {
484 int hv; 588 int hv;
485 589
486 if (iso14755buf & ISO_14755_51 590 if (iso14755buf & ISO_14755_51
487 && (keysym == XK_space || keysym == XK_KP_Space 591 && (keysym == XK_space || keysym == XK_KP_Space
489 { 593 {
490 commit_iso14755 (); 594 commit_iso14755 ();
491 iso14755buf = ISO_14755_51; 595 iso14755buf = ISO_14755_51;
492# if ISO_14755 596# if ISO_14755
493 iso14755_51 (0); 597 iso14755_51 (0);
598# endif
599 return;
600 }
601 else if (keysym == XK_BackSpace)
602 {
603 iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51;
604# if ISO_14755
605 iso14755_51 (iso14755buf & ISO_14755_MASK);
494# endif 606# endif
495 return; 607 return;
496 } 608 }
497 else if ((hv = hex_keyval (ev)) >= 0) 609 else if ((hv = hex_keyval (ev)) >= 0)
498 { 610 {
503# endif 615# endif
504 return; 616 return;
505 } 617 }
506 else 618 else
507 { 619 {
508# if ENABLE_OVERLAY 620# if ISO_14755
509 scr_overlay_off (); 621 scr_overlay_off ();
510# endif 622# endif
511 iso14755buf = 0; 623 iso14755buf = 0;
512 } 624 }
513 } 625 }
626 else if (option (Opt_iso14755) &&
514 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) 627 ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
515 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) 628 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))))
516 if (!(iso14755buf & ISO_14755_STARTED)) 629 if (!(iso14755buf & ISO_14755_STARTED))
517 { 630 {
518 iso14755buf |= ISO_14755_STARTED; 631 iso14755buf |= ISO_14755_STARTED;
519# if ENABLE_OVERLAY 632# if ISO_14755
520 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); 633 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
521 scr_overlay_set (0, 0, "ISO 14755 mode"); 634 scr_overlay_set (0, 0, "ISO 14755 mode");
522# endif 635# endif
523 } 636 }
524#endif 637#endif
525 638
526#ifdef PRINTPIPE 639#ifdef PRINTPIPE
527 if (keysym == XK_Print) 640 if (keysym == XK_Print)
528 { 641 {
529 scr_printscreen (ctrl | shft); 642 scr_printscreen (ctrl | shft);
530 return; 643 return;
531 } 644 }
532#endif 645#endif
533 646
534 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 647 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
535 { 648 {
649 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
650 unsigned int newlen = 1;
651
652 switch (translate_keypad (keysym, kp))
536 { 653 {
654#ifndef NO_BACKSPACE_KEY
655 case XK_BackSpace:
656 if (priv_modes & PrivMode_HaveBackSpace)
657 {
658 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
659 ^ !!ctrl) ? '\b' : '\177';
660 kbuf[1] = '\0';
661 }
662 else
663 strcpy (kbuf, rs[Rs_backspace_key]);
664 break;
665#endif
666#ifndef NO_DELETE_KEY
667 case XK_Delete:
668 strcpy (kbuf, rs[Rs_delete_key]);
669 break;
670#endif
671 case XK_Tab:
672 if (shft)
673 strcpy (kbuf, "\033[Z");
674 else
675 {
676#ifdef CTRL_TAB_MAKES_META
677 if (ctrl)
678 meta = 1;
679#endif
680#ifdef MOD4_TAB_MAKES_META
681 if (ev.state & Mod4Mask)
682 meta = 1;
683#endif
537 newlen = 1; 684 newlen = 0;
538 switch (keysym) 685 }
686 break;
687
688 case XK_Up: /* "\033[A" */
689 case XK_Down: /* "\033[B" */
690 case XK_Right: /* "\033[C" */
691 case XK_Left: /* "\033[D" */
692 strcpy (kbuf, "\033[Z");
693 kbuf[2] = "DACB"[keysym - XK_Left];
694 /* do Shift first */
695 if (shft)
696 kbuf[2] = "dacb"[keysym - XK_Left];
697 else if (ctrl)
698 {
699 kbuf[1] = 'O';
700 kbuf[2] = "dacb"[keysym - XK_Left];
701 }
702 else if (priv_modes & PrivMode_aplCUR)
703 kbuf[1] = 'O';
704 break;
705
706 case XK_KP_Enter:
707 /* allow shift to override */
708 if (kp)
709 {
710 strcpy (kbuf, "\033OM");
711 break;
712 }
713
714 /* FALLTHROUGH */
715
716 case XK_Return:
717 if (priv_modes & PrivMode_LFNL)
718 {
719 kbuf[0] = '\015';
720 kbuf[1] = '\012';
721 kbuf[2] = '\0';
722 }
723 else
724 {
725 kbuf[0] = '\015';
726 kbuf[1] = '\0';
727 }
728 break;
729
730 case XK_KP_F1: /* "\033OP" */
731 case XK_KP_F2: /* "\033OQ" */
732 case XK_KP_F3: /* "\033OR" */
733 case XK_KP_F4: /* "\033OS" */
734 strcpy (kbuf, "\033OP");
735 kbuf[2] += (keysym - XK_KP_F1);
736 break;
737
738 case XK_KP_Multiply: /* "\033Oj" : "*" */
739 case XK_KP_Add: /* "\033Ok" : "+" */
740 case XK_KP_Separator: /* "\033Ol" : "," */
741 case XK_KP_Subtract: /* "\033Om" : "-" */
742 case XK_KP_Decimal: /* "\033On" : "." */
743 case XK_KP_Divide: /* "\033Oo" : "/" */
744 case XK_KP_0: /* "\033Op" : "0" */
745 case XK_KP_1: /* "\033Oq" : "1" */
746 case XK_KP_2: /* "\033Or" : "2" */
747 case XK_KP_3: /* "\033Os" : "3" */
748 case XK_KP_4: /* "\033Ot" : "4" */
749 case XK_KP_5: /* "\033Ou" : "5" */
750 case XK_KP_6: /* "\033Ov" : "6" */
751 case XK_KP_7: /* "\033Ow" : "7" */
752 case XK_KP_8: /* "\033Ox" : "8" */
753 case XK_KP_9: /* "\033Oy" : "9" */
754 /* allow shift to override */
755 if (kp)
756 {
757 strcpy (kbuf, "\033Oj");
758 kbuf[2] += (keysym - XK_KP_Multiply);
759 }
760 else
761 {
762 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
763 kbuf[1] = '\0';
764 }
765 break;
766
767 default:
539 { 768 {
540#ifndef NO_BACKSPACE_KEY 769 int param = map_function_key (keysym);
541 case XK_BackSpace: 770 if (param > 0)
542 if (priv_modes & PrivMode_HaveBackSpace) 771 sprintf (kbuf,"\033[%d~", param);
543 {
544 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
545 ^ !!ctrl) ? '\b' : '\177';
546 kbuf[1] = '\0';
547 }
548 else 772 else
549 strcpy (kbuf, key_backspace);
550 break;
551#endif
552#ifndef NO_DELETE_KEY
553# ifdef XK_KP_Prior
554 case XK_KP_Delete:
555 /* allow shift to override */
556 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
557 {
558 strcpy (kbuf, "\033On");
559 break;
560 }
561 /* FALLTHROUGH */
562# endif
563 case XK_Delete:
564 strcpy (kbuf, key_delete);
565 break;
566#endif
567 case XK_Tab:
568 if (shft)
569 strcpy (kbuf, "\033[Z");
570 else
571 {
572#ifdef CTRL_TAB_MAKES_META
573 if (ctrl)
574 meta = 1;
575#endif
576#ifdef MOD4_TAB_MAKES_META
577 if (ev.state & Mod4Mask)
578 meta = 1;
579#endif
580 newlen = 0;
581 }
582 break;
583
584#ifdef XK_KP_Left
585 case XK_KP_Up: /* \033Ox or standard */
586 case XK_KP_Down: /* \033Or or standard */
587 case XK_KP_Right: /* \033Ov or standard */
588 case XK_KP_Left: /* \033Ot or standard */
589 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
590 {
591 strcpy (kbuf, "\033OZ");
592 kbuf[2] = "txvr"[keysym - XK_KP_Left];
593 break;
594 }
595 else
596 /* translate to std. cursor key */
597 keysym = XK_Left + (keysym - XK_KP_Left);
598 /* FALLTHROUGH */
599#endif
600 case XK_Up: /* "\033[A" */
601 case XK_Down: /* "\033[B" */
602 case XK_Right: /* "\033[C" */
603 case XK_Left: /* "\033[D" */
604 strcpy (kbuf, "\033[Z");
605 kbuf[2] = "DACB"[keysym - XK_Left];
606 /* do Shift first */
607 if (shft)
608 kbuf[2] = "dacb"[keysym - XK_Left];
609 else if (ctrl)
610 {
611 kbuf[1] = 'O';
612 kbuf[2] = "dacb"[keysym - XK_Left];
613 }
614 else if (priv_modes & PrivMode_aplCUR)
615 kbuf[1] = 'O';
616 break;
617
618#ifndef UNSHIFTED_SCROLLKEYS
619# ifdef XK_KP_Prior
620 case XK_KP_Prior:
621 /* allow shift to override */
622 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
623 {
624 strcpy (kbuf, "\033Oy");
625 break;
626 }
627 /* FALLTHROUGH */
628# endif
629 case XK_Prior:
630 strcpy (kbuf, "\033[5~");
631 break;
632# ifdef XK_KP_Next
633 case XK_KP_Next:
634 /* allow shift to override */
635 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
636 {
637 strcpy (kbuf, "\033Os");
638 break;
639 }
640 /* FALLTHROUGH */
641# endif
642 case XK_Next:
643 strcpy (kbuf, "\033[6~");
644 break;
645#endif
646 case XK_KP_Enter:
647 /* allow shift to override */
648 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
649 {
650 strcpy (kbuf, "\033OM");
651 break;
652 }
653
654 /* FALLTHROUGH */
655
656 case XK_Return:
657 if (priv_modes & PrivMode_LFNL)
658 {
659 kbuf[0] = '\015';
660 kbuf[1] = '\012';
661 kbuf[2] = '\0';
662 }
663 else
664 {
665 kbuf[0] = '\015';
666 kbuf[1] = '\0';
667 }
668 break;
669
670#ifdef XK_KP_Begin
671 case XK_KP_Begin:
672 strcpy (kbuf, "\033Ou");
673 break;
674
675#endif
676 case XK_KP_F1: /* "\033OP" */
677 case XK_KP_F2: /* "\033OQ" */
678 case XK_KP_F3: /* "\033OR" */
679 case XK_KP_F4: /* "\033OS" */
680 strcpy (kbuf, "\033OP");
681 kbuf[2] += (keysym - XK_KP_F1);
682 break;
683
684 case XK_KP_Multiply: /* "\033Oj" : "*" */
685 case XK_KP_Add: /* "\033Ok" : "+" */
686 case XK_KP_Separator: /* "\033Ol" : "," */
687 case XK_KP_Subtract: /* "\033Om" : "-" */
688 case XK_KP_Decimal: /* "\033On" : "." */
689 case XK_KP_Divide: /* "\033Oo" : "/" */
690 case XK_KP_0: /* "\033Op" : "0" */
691 case XK_KP_1: /* "\033Oq" : "1" */
692 case XK_KP_2: /* "\033Or" : "2" */
693 case XK_KP_3: /* "\033Os" : "3" */
694 case XK_KP_4: /* "\033Ot" : "4" */
695 case XK_KP_5: /* "\033Ou" : "5" */
696 case XK_KP_6: /* "\033Ov" : "6" */
697 case XK_KP_7: /* "\033Ow" : "7" */
698 case XK_KP_8: /* "\033Ox" : "8" */
699 case XK_KP_9: /* "\033Oy" : "9" */
700 /* allow shift to override */
701 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
702 {
703 strcpy (kbuf, "\033Oj");
704 kbuf[2] += (keysym - XK_KP_Multiply);
705 }
706 else
707 {
708 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
709 kbuf[1] = '\0';
710 }
711 break;
712
713 case XK_Find:
714 strcpy (kbuf, "\033[1~");
715 break;
716
717#ifdef XK_KP_End
718 case XK_KP_Insert:
719 /* allow shift to override */
720 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
721 {
722 strcpy (kbuf, "\033Op");
723 break;
724 }
725 /* FALLTHROUGH */
726#endif
727 case XK_Insert:
728 strcpy (kbuf, "\033[2~");
729 break;
730#ifdef DXK_Remove /* support for DEC remove like key */
731 case DXK_Remove:
732 /* FALLTHROUGH */
733#endif
734 case XK_Execute:
735 strcpy (kbuf, "\033[3~");
736 break;
737 case XK_Select:
738 strcpy (kbuf, "\033[4~");
739 break;
740#ifdef XK_KP_End
741 case XK_KP_End:
742 /* allow shift to override */
743 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
744 {
745 strcpy (kbuf, "\033Oq");
746 break;
747 }
748 /* FALLTHROUGH */
749#endif
750 case XK_End:
751 strcpy (kbuf, KS_END);
752 break;
753#ifdef XK_KP_Home
754 case XK_KP_Home:
755 /* allow shift to override */
756 if ((priv_modes & PrivMode_aplKP) ? !shft : shft)
757 {
758 strcpy (kbuf, "\033Ow");
759 break;
760 }
761 /* FALLTHROUGH */
762#endif
763 case XK_Home:
764 strcpy (kbuf, KS_HOME);
765 break;
766
767#define FKEY(n, fkey) \
768 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
769
770 case XK_F1: /* "\033[11~" */
771 case XK_F2: /* "\033[12~" */
772 case XK_F3: /* "\033[13~" */
773 case XK_F4: /* "\033[14~" */
774 case XK_F5: /* "\033[15~" */
775 FKEY (11, XK_F1);
776 break;
777 case XK_F6: /* "\033[17~" */
778 case XK_F7: /* "\033[18~" */
779 case XK_F8: /* "\033[19~" */
780 case XK_F9: /* "\033[20~" */
781 case XK_F10: /* "\033[21~" */
782 FKEY (17, XK_F6);
783 break;
784 case XK_F11: /* "\033[23~" */
785 case XK_F12: /* "\033[24~" */
786 case XK_F13: /* "\033[25~" */
787 case XK_F14: /* "\033[26~" */
788 FKEY (23, XK_F11);
789 break;
790 case XK_F15: /* "\033[28~" */
791 case XK_F16: /* "\033[29~" */
792 FKEY (28, XK_F15);
793 break;
794 case XK_Help: /* "\033[28~" */
795 FKEY (28, XK_Help);
796 break;
797 case XK_Menu: /* "\033[29~" */
798 FKEY (29, XK_Menu);
799 break;
800 case XK_F17: /* "\033[31~" */
801 case XK_F18: /* "\033[32~" */
802 case XK_F19: /* "\033[33~" */
803 case XK_F20: /* "\033[34~" */
804 case XK_F21: /* "\033[35~" */
805 case XK_F22: /* "\033[36~" */
806 case XK_F23: /* "\033[37~" */
807 case XK_F24: /* "\033[38~" */
808 case XK_F25: /* "\033[39~" */
809 case XK_F26: /* "\033[40~" */
810 case XK_F27: /* "\033[41~" */
811 case XK_F28: /* "\033[42~" */
812 case XK_F29: /* "\033[43~" */
813 case XK_F30: /* "\033[44~" */
814 case XK_F31: /* "\033[45~" */
815 case XK_F32: /* "\033[46~" */
816 case XK_F33: /* "\033[47~" */
817 case XK_F34: /* "\033[48~" */
818 case XK_F35: /* "\033[49~" */
819 FKEY (31, XK_F17);
820 break;
821#undef FKEY
822 default:
823 newlen = 0; 773 newlen = 0;
824 break;
825 } 774 }
826 775 break;
827 if (newlen)
828 len = strlen (kbuf);
829 } 776 }
777
778 if (newlen)
779 len = strlen (kbuf);
830 780
831 /* 781 /*
832 * Pass meta for all function keys, if 'meta' option set 782 * Pass meta for all function keys, if 'meta' option set
833 */ 783 */
834#ifdef META8_OPTION 784#ifdef META8_OPTION
869 return; 819 return;
870 820
871 if (len <= 0) 821 if (len <= 0)
872 return; /* not mapped */ 822 return; /* not mapped */
873 823
874 if (OPTION (Opt_scrollTtyKeypress)) 824 if (option (Opt_scrollTtyKeypress))
875 if (view_start) 825 if (view_start)
876 { 826 {
877 view_start = 0; 827 view_start = 0;
878 want_refresh = 1; 828 want_refresh = 1;
879 } 829 }
903 tt_write (&ch, 1); 853 tt_write (&ch, 1);
904 } 854 }
905 855
906 tt_write (kbuf, (unsigned int)len); 856 tt_write (kbuf, (unsigned int)len);
907} 857}
908/*}}} */ 858
859void
860rxvt_term::key_release (XKeyEvent &ev)
861{
862#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
863 KeySym keysym;
864
865 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
866#endif
867
868#if ENABLE_FRILLS || ISO_14755
869 // ISO 14755 support
870 if (iso14755buf)
871 if (iso14755buf & ISO_14755_52)
872 {
873# if ISO_14755
874 scr_overlay_off ();
875# endif
876# if ISO_14755
877 // iso14755 part 5.2 handling: release time
878 // first: controls
879 if ((ev.state & ControlMask)
880 && ((keysym >= 0x40 && keysym <= 0x5f)
881 || (keysym >= 0x61 && keysym <= 0x7f)))
882 {
883 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
884 commit_iso14755 ();
885
886 return;
887 }
888
889 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
890 if (i[0] == keysym)
891 {
892 iso14755buf = ISO_14755_51 | i[1];
893 commit_iso14755 ();
894
895 return;
896 }
897
898 scr_bell ();
899# endif
900 iso14755buf = 0;
901
902 return;
903 }
904 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
905 {
906# if ISO_14755
907 scr_overlay_off ();
908# endif
909 if (iso14755buf & ISO_14755_51)
910 commit_iso14755 ();
911#if ISO_14755
912 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
913 {
914 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
915
916 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
917 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
918 }
919# endif
920 else
921 iso14755buf = 0;
922 }
923#endif
924
925 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
926 return;
927
928#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
929 if (!(ev.state & ControlMask))
930 slip_wheel_ev.stop ();
931 else if (keysym == XK_Control_L || keysym == XK_Control_R)
932 mouse_slip_wheel_speed = 0;
933#endif
934}
909 935
910#if defined (KEYSYM_RESOURCE) 936#if defined (KEYSYM_RESOURCE)
911unsigned int 937unsigned int
912rxvt_term::cmd_write (const char *str, unsigned int count) 938rxvt_term::cmd_write (const char *str, unsigned int count)
913{ 939{
943void 969void
944rxvt_term::flush () 970rxvt_term::flush ()
945{ 971{
946 flush_ev.stop (); 972 flush_ev.stop ();
947 973
948#ifdef TRANSPARENT 974#ifdef HAVE_BG_PIXMAP
949 if (want_full_refresh) 975 if (bgPixmap.check_clearChanged ())
950 { 976 {
951 want_full_refresh = 0; 977// scr_clear (true); This needs to be researched further!
952 scr_clear ();
953 scr_touch (false); 978 scr_touch (false);
954 } 979 }
955#endif 980#endif
956 981
957 if (want_refresh) 982 if (want_refresh)
993 } 1018 }
994 while (row < end_row); 1019 while (row < end_row);
995 } 1020 }
996 1021
997 scr_refresh (); 1022 scr_refresh ();
998 scrollbar_show (1); 1023 scrollBar.show (1);
999#ifdef USE_XIM 1024#ifdef USE_XIM
1000 IMSendSpot (); 1025 IMSendSpot ();
1001#endif 1026#endif
1002 } 1027 }
1003 1028
1004 display->flush (); 1029 display->flush ();
1005} 1030}
1006 1031
1032/* checks wether a refresh is requested and starts the refresh timer */
1007void 1033void
1008rxvt_term::check_cb (check_watcher &w) 1034rxvt_term::refresh_check ()
1035{
1036 if (want_refresh && !flush_ev.is_active ())
1037 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
1038
1039 display->flush ();
1040}
1041
1042void
1043rxvt_term::flush_cb (ev::timer &w, int revents)
1009{ 1044{
1010 make_current (); 1045 make_current ();
1011 1046
1012 display->flush ();
1013
1014 if (want_refresh && !flush_ev.active)
1015 flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally
1016}
1017
1018void
1019rxvt_term::flush_cb (time_watcher &w)
1020{
1021 make_current ();
1022
1023 refresh_limit = 1;
1024 refresh_count = 0; 1047 refresh_count = 0;
1025 flush (); 1048 flush ();
1026} 1049}
1027 1050
1028#ifdef CURSOR_BLINK 1051#ifdef CURSOR_BLINK
1029void 1052void
1030rxvt_term::cursor_blink_cb (time_watcher &w) 1053rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
1031{ 1054{
1032 hidden_cursor = !hidden_cursor; 1055 hidden_cursor = !hidden_cursor;
1033 want_refresh = 1; 1056 want_refresh = 1;
1034 1057 refresh_check ();
1035 w.start (w.at + CURSOR_BLINK_INTERVAL);
1036} 1058}
1037#endif 1059#endif
1038 1060
1039#ifdef TEXT_BLINK 1061#ifdef TEXT_BLINK
1040void 1062void
1041rxvt_term::text_blink_cb (time_watcher &w) 1063rxvt_term::text_blink_cb (ev::timer &w, int revents)
1042{ 1064{
1043 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1065 if (scr_refresh_rend (RS_Blink, RS_Blink))
1044 { 1066 {
1045 hidden_text = !hidden_text; 1067 hidden_text = !hidden_text;
1046 want_refresh = 1; 1068 want_refresh = 1;
1047 w.start (w.at + TEXT_BLINK_INTERVAL); 1069 refresh_check ();
1048 } 1070 }
1071 else
1072 w.stop ();
1049} 1073}
1050#endif 1074#endif
1051 1075
1052#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1076#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1053void 1077void
1054rxvt_term::cont_scroll_cb (time_watcher &w) 1078rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1055{ 1079{
1056 if ((scrollbar_isUp() || scrollbar_isDn()) && 1080 if ((scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
1057 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1081 && scr_page (scrollBar.state == STATE_UP ? UP : DN, 1))
1058 { 1082 {
1059 want_refresh = 1; 1083 want_refresh = 1;
1060 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1084 refresh_check ();
1061 } 1085 }
1086 else
1087 w.stop ();
1062} 1088}
1063#endif 1089#endif
1064 1090
1065#ifdef SELECTION_SCROLLING 1091#ifdef SELECTION_SCROLLING
1066void 1092void
1067rxvt_term::sel_scroll_cb (time_watcher &w) 1093rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1068{ 1094{
1069 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1095 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1070 { 1096 {
1071 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1097 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1072 want_refresh = 1; 1098 want_refresh = 1;
1073 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1099 refresh_check ();
1074 } 1100 }
1101 else
1102 w.stop ();
1075} 1103}
1076#endif 1104#endif
1077 1105
1078#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1106#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1079void 1107void
1080rxvt_term::slip_wheel_cb (time_watcher &w) 1108rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1081{ 1109{
1082 if (mouse_slip_wheel_speed == 0 1110 if (scr_changeview (view_start - mouse_slip_wheel_speed))
1083 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1084 : scr_page (UP, mouse_slip_wheel_speed))
1085 { 1111 {
1086 if (view_start == top_row || view_start == 0)
1087 mouse_slip_wheel_speed = 0;
1088
1089 want_refresh = 1; 1112 want_refresh = 1;
1090 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1113 refresh_check ();
1114 }
1115
1116 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1117 {
1118 mouse_slip_wheel_speed = 0;
1119 w.stop ();
1091 } 1120 }
1092} 1121}
1093#endif 1122#endif
1094 1123
1095#if LINUX_YIELD_HACK 1124#if LINUX_YIELD_HACK
1096static struct event_handler 1125static struct event_handler
1097{ 1126{
1098 check_watcher yield_ev; 1127 ev::prepare yield_ev;
1099 1128
1100 void yield_cb (check_watcher &w) 1129 void yield_cb (ev::prepare &w, int revents)
1101 { 1130 {
1102 usleep (0); 1131 // this should really be sched_yield(), but the linux guys thought
1132 // that giving a process calling sched_yield () less cpu time than
1133 // ones with high nice levels is a useful thing to do. It surely is is
1134 // allowed by the sus... as is returning ENOSYS.
1135 // since the linux guys additionally thought that breaking the only
1136 // known workaroudn against their unusable sched_yield hack is cool,
1137 // we just nanosleep a bit and hope for the best.
1138
1139 struct timespec ts = { 0, 1000 };
1140 nanosleep (&ts, 0);
1141
1103 w.stop (); 1142 w.stop ();
1104 } 1143 }
1105 1144
1106 event_handler () 1145 event_handler ()
1107 : yield_ev (this, &event_handler::yield_cb) 1146 : yield_ev (this, &event_handler::yield_cb)
1141 } 1180 }
1142 else 1181 else
1143 { 1182 {
1144 pty_ev.stop (); 1183 pty_ev.stop ();
1145 1184
1146 if (!OPTION (Opt_hold)) 1185 if (!option (Opt_hold))
1147 destroy (); 1186 destroy ();
1148 } 1187 }
1149 1188
1150 return false; 1189 return false;
1151} 1190}
1152 1191
1153void 1192void
1154rxvt_term::pty_cb (io_watcher &w, short revents) 1193rxvt_term::pty_cb (ev::io &w, int revents)
1155{ 1194{
1156 make_current (); 1195 make_current ();
1157 1196
1158 if (revents & EVENT_READ) 1197 if (revents & ev::READ)
1159 // loop, but don't allow a single term to monopolize us 1198 // loop, but don't allow a single term to monopolize us
1160 while (pty_fill ()) 1199 for (int i = CBUFCNT; i-- && pty_fill (); )
1161 if (cmd_parse ()) 1200 cmd_parse ();
1162 break;
1163 1201
1164 if (revents & EVENT_WRITE) 1202 if (revents & ev::WRITE)
1165 pty_write (); 1203 pty_write ();
1204
1205 refresh_check ();
1166} 1206}
1167 1207
1168void 1208void
1169rxvt_term::pointer_unblank () 1209rxvt_term::pointer_unblank ()
1170{ 1210{
1171 XDefineCursor (xdisp, vt, TermWin_cursor); 1211 XDefineCursor (dpy, vt, TermWin_cursor);
1172 recolour_cursor (); 1212 recolour_cursor ();
1173 1213
1174#ifdef POINTER_BLANK 1214#ifdef POINTER_BLANK
1175 hidden_pointer = 0; 1215 hidden_pointer = 0;
1176 1216
1177 if (OPTION (Opt_pointerBlank)) 1217 if (option (Opt_pointerBlank))
1178 pointer_ev.start (NOW + pointerBlankDelay); 1218 pointer_ev.start (pointerBlankDelay);
1179#endif 1219#endif
1180} 1220}
1181 1221
1182#ifdef POINTER_BLANK 1222#ifdef POINTER_BLANK
1183void 1223void
1184rxvt_term::pointer_blank () 1224rxvt_term::pointer_blank ()
1185{ 1225{
1186 if (!OPTION (Opt_pointerBlank)) 1226 if (!option (Opt_pointerBlank))
1187 return; 1227 return;
1188 1228
1189 XDefineCursor (xdisp, vt, display->blank_cursor); 1229 XDefineCursor (dpy, vt, display->blank_cursor);
1190 XFlush (xdisp); 1230 XFlush (dpy);
1191 1231
1192 hidden_pointer = 1; 1232 hidden_pointer = 1;
1193} 1233}
1194 1234
1195void 1235void
1196rxvt_term::pointer_cb (time_watcher &w) 1236rxvt_term::pointer_cb (ev::timer &w, int revents)
1197{ 1237{
1198 make_current (); 1238 make_current ();
1199 1239
1200 pointer_blank (); 1240 pointer_blank ();
1201} 1241}
1204void 1244void
1205rxvt_term::mouse_report (XButtonEvent &ev) 1245rxvt_term::mouse_report (XButtonEvent &ev)
1206{ 1246{
1207 int button_number, key_state = 0; 1247 int button_number, key_state = 0;
1208 int x, y; 1248 int x, y;
1249 int code = 32;
1209 1250
1210 x = ev.x; 1251 x = Pixel2Col (ev.x);
1211 y = ev.y; 1252 y = Pixel2Row (ev.y);
1212 pixel_position (&x, &y); 1253 if (ev.type == MotionNotify)
1254 {
1255 if (x == mouse_row && y == mouse_col)
1256 return;
1257 mouse_row = x;
1258 mouse_col = y;
1259 code += 32;
1260 }
1213 1261
1214 if (MEvent.button == AnyButton) 1262 if (MEvent.button == AnyButton)
1215 button_number = 3; 1263 button_number = 3;
1216 else 1264 else
1217 { 1265 {
1263 x + 1, 1311 x + 1,
1264 y + 1); 1312 y + 1);
1265#endif 1313#endif
1266 1314
1267 tt_printf ("\033[M%c%c%c", 1315 tt_printf ("\033[M%c%c%c",
1268 (32 + button_number + key_state), 1316 (code + button_number + key_state),
1269 (32 + x + 1), 1317 (32 + x + 1),
1270 (32 + y + 1)); 1318 (32 + y + 1));
1271} 1319}
1272 1320
1273/*{{{ process an X event */ 1321/*{{{ process an X event */
1274void 1322void
1275rxvt_term::x_cb (XEvent &ev) 1323rxvt_term::x_cb (XEvent &ev)
1276{ 1324{
1277 make_current (); 1325 make_current ();
1278 1326
1279 dLocal (Display *, xdisp); 1327 dLocal (Display *, dpy);
1280 1328
1281 if (ev.xany.window == vt 1329 if (ev.xany.window == vt
1282 && SHOULD_INVOKE (HOOK_X_EVENT) 1330 && SHOULD_INVOKE (HOOK_X_EVENT)
1283 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END))) 1331 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1284 return; 1332 return;
1289 unsigned int unused_mask; 1337 unsigned int unused_mask;
1290 1338
1291 switch (ev.type) 1339 switch (ev.type)
1292 { 1340 {
1293 case KeyPress: 1341 case KeyPress:
1294#if ISO_14755 1342 key_press (ev.xkey);
1295 if (!(iso14755buf & ISO_14755_52))
1296#endif
1297 lookup_key (ev.xkey);
1298
1299 break; 1343 break;
1300 1344
1301 case KeyRelease: 1345 case KeyRelease:
1302 { 1346 key_release (ev.xkey);
1303#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1304 KeySym keysym;
1305
1306 keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1307#endif
1308
1309#if ENABLE_FRILLS || ISO_14755
1310 // ISO 14755 support
1311 if (iso14755buf)
1312 if (iso14755buf & ISO_14755_52)
1313 {
1314# if ENABLE_OVERLAY
1315 scr_overlay_off ();
1316# endif
1317# if ISO_14755
1318 // iso14755 part 5.2 handling: release time
1319 // first: controls
1320 if ((ev.xkey.state & ControlMask)
1321 && ((keysym >= 0x40 && keysym <= 0x5f)
1322 || (keysym >= 0x61 && keysym <= 0x7f)))
1323 {
1324 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1325 commit_iso14755 ();
1326 goto skip_switch;
1327 }
1328
1329 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1330 if (i[0] == keysym)
1331 {
1332 iso14755buf = ISO_14755_51 | i[1];
1333 commit_iso14755 ();
1334 goto skip_switch;
1335 }
1336
1337 scr_bell ();
1338# endif
1339 iso14755buf = 0;
1340 break;
1341 }
1342 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1343 {
1344# if ENABLE_OVERLAY
1345 scr_overlay_off ();
1346# endif
1347 if (iso14755buf & ISO_14755_51)
1348 commit_iso14755 ();
1349#if ISO_14755
1350 else if (iso14755buf & ISO_14755_STARTED)
1351 {
1352 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1353
1354 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1355 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1356 }
1357# endif
1358 else
1359 iso14755buf = 0;
1360 }
1361#endif
1362
1363 if (ev.xany.window == vt
1364 && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
1365 break;
1366
1367#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1368 if (!(ev.xkey.state & ControlMask))
1369 slip_wheel_ev.stop ();
1370 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1371 mouse_slip_wheel_speed = 0;
1372#endif
1373 break; 1347 break;
1374 }
1375 1348
1376 case ButtonPress: 1349 case ButtonPress:
1377 button_press (ev.xbutton); 1350 button_press (ev.xbutton);
1378 break; 1351 break;
1379 1352
1394 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END))) 1367 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1395 destroy (); 1368 destroy ();
1396 } 1369 }
1397#if ENABLE_EWMH 1370#if ENABLE_EWMH
1398 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1371 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1399 XSendEvent (xdisp, ev.xclient.window = display->root, 1372 XSendEvent (dpy, ev.xclient.window = display->root,
1400 False, SubstructureRedirectMask | SubstructureNotifyMask, 1373 False, SubstructureRedirectMask | SubstructureNotifyMask,
1401 &ev); 1374 &ev);
1402#endif 1375#endif
1403 } 1376 }
1404 } 1377 }
1410 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1383 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1411 focus_out (); 1384 focus_out ();
1412 } 1385 }
1413#endif 1386#endif
1414 } 1387 }
1415 break;
1416
1417 case MappingNotify:
1418 XRefreshKeyboardMapping (&ev.xmapping);
1419 break; 1388 break;
1420 1389
1421 /* 1390 /*
1422 * XXX: this is not the _current_ arrangement 1391 * XXX: this is not the _current_ arrangement
1423 * Here's my conclusion: 1392 * Here's my conclusion:
1442 break; 1411 break;
1443 } 1412 }
1444 break; 1413 break;
1445 1414
1446 case FocusIn: 1415 case FocusIn:
1416 if (ev.xfocus.detail != NotifyInferior
1417 && ev.xfocus.detail != NotifyPointer
1418 && ev.xfocus.mode != NotifyGrab)
1447 focus_in (); 1419 focus_in ();
1448 break; 1420 break;
1449 1421
1450 case FocusOut: 1422 case FocusOut:
1423 if (ev.xfocus.detail != NotifyInferior
1424 && ev.xfocus.detail != NotifyPointer
1425 && ev.xfocus.mode != NotifyGrab)
1451 focus_out (); 1426 focus_out ();
1452 break; 1427 break;
1453 1428
1454 case ConfigureNotify: 1429 case ConfigureNotify:
1430 /*fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1431 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1432 szHint.width, szHint.height);*/
1455 if (ev.xconfigure.window == parent[0]) 1433 if (ev.xconfigure.window == parent[0])
1456 { 1434 {
1457 while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev)) 1435 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1458 ; 1436 ;
1459 1437
1460 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) 1438 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1461 { 1439 {
1462 seen_resize = 1; 1440 seen_resize = 1;
1463 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1441 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1464 } 1442 }
1443 else
1444 {
1445#ifdef HAVE_BG_PIXMAP
1446 if (bgPixmap.window_position_sensitive ())
1447 {
1448 if (mapped)
1449 update_background ();
1450 else
1451 bgPixmap.invalidate ();
1452 }
1453#endif
1454 }
1465 1455
1466 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); 1456 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1467
1468#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1469 if (OPTION (Opt_transparent))
1470 check_our_parents ();
1471#endif
1472 } 1457 }
1473 break; 1458 break;
1474 1459
1475 case PropertyNotify: 1460 case PropertyNotify:
1476 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) 1461 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1479 selection_property (ev.xproperty.window, ev.xproperty.atom); 1464 selection_property (ev.xproperty.window, ev.xproperty.atom);
1480 1465
1481 break; 1466 break;
1482 1467
1483 case SelectionClear: 1468 case SelectionClear:
1484 selection_clear (); 1469 selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]);
1485 break; 1470 break;
1486 1471
1487 case SelectionNotify: 1472 case SelectionNotify:
1488 if (selection_wait == Sel_normal) 1473 if (selection_wait == Sel_normal)
1489 selection_paste (ev.xselection.requestor, ev.xselection.property, true); 1474 selection_paste (ev.xselection.requestor, ev.xselection.property, true);
1492 case SelectionRequest: 1477 case SelectionRequest:
1493 selection_send (ev.xselectionrequest); 1478 selection_send (ev.xselectionrequest);
1494 break; 1479 break;
1495 1480
1496 case MapNotify: 1481 case MapNotify:
1482#ifdef HAVE_BG_PIXMAP
1483 /* This is needed spcifically to fix the case of no window manager or a
1484 * non-reparenting window manager. In those cases we never get first
1485 * ConfigureNotify. Also that speeds startup under normal WM, by taking
1486 * care of multiplicity of ConfigureNotify events arriwing while WM does
1487 * reparenting.
1488 * We should not render background immidiately, as there could be several
1489 * ConfigureNotify's to follow. Lets take care of all of them in one scoop
1490 * by scheduling background redraw as soon as we can, but giving a short
1491 * bit of time for ConfigureNotifies to arrive.
1492 * We should render background PRIOR to drawing any text, but AFTER all
1493 * of ConfigureNotifys for the best results.
1494 */
1495 if (bgPixmap.flags & bgPixmap_t::isInvalid)
1496 update_background_ev.start (0.025);
1497#endif
1497 mapped = 1; 1498 mapped = 1;
1498#ifdef TEXT_BLINK 1499#ifdef TEXT_BLINK
1499 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 1500 text_blink_ev.start ();
1500#endif 1501#endif
1501 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1502 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1502 break; 1503 break;
1503 1504
1504 case UnmapNotify: 1505 case UnmapNotify:
1506#ifdef TEXT_BLINK 1507#ifdef TEXT_BLINK
1507 text_blink_ev.stop (); 1508 text_blink_ev.stop ();
1508#endif 1509#endif
1509 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1510 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1510 break; 1511 break;
1511
1512#ifdef TRANSPARENT
1513 case ReparentNotify:
1514 rootwin_cb (ev);
1515 break;
1516#endif /* TRANSPARENT */
1517 1512
1518 case GraphicsExpose: 1513 case GraphicsExpose:
1519 case Expose: 1514 case Expose:
1520 if (ev.xany.window == vt) 1515 if (ev.xany.window == vt)
1521 { 1516 {
1522 do 1517 do
1518 {
1523 scr_expose (ev.xexpose.x, ev.xexpose.y, 1519 scr_expose (ev.xexpose.x, ev.xexpose.y,
1524 ev.xexpose.width, ev.xexpose.height, False); 1520 ev.xexpose.width, ev.xexpose.height, False);
1521 }
1525 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)); 1522 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1526 1523
1527 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1524 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1528 1525
1529 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)) 1526 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1527 {
1530 scr_expose (ev.xexpose.x, ev.xexpose.y, 1528 scr_expose (ev.xexpose.x, ev.xexpose.y,
1531 ev.xexpose.width, ev.xexpose.height, False); 1529 ev.xexpose.width, ev.xexpose.height, False);
1530 }
1532 1531
1533 want_refresh = 1; 1532 want_refresh = 1;
1534 } 1533 }
1535 else 1534 else
1536 { 1535 {
1537 XEvent unused_event; 1536 XEvent unused_event;
1538 1537
1539 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event)) 1538 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1540 ; 1539 ;
1541 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event)) 1540 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1542 ; 1541 ;
1543 1542
1544 if (isScrollbarWindow (ev.xany.window)) 1543 if (scrollBar.state && ev.xany.window == scrollBar.win)
1545 { 1544 {
1546 scrollBar.setIdle (); 1545 scrollBar.state = STATE_IDLE;
1547 scrollbar_show (0); 1546 scrollBar.show (0);
1548 } 1547 }
1549
1550#ifdef TRANSPARENT
1551 if (am_transparent && ev.xany.window == parent[0])
1552 XClearWindow (xdisp, ev.xany.window);
1553#endif
1554 } 1548 }
1555 break; 1549 break;
1556 1550
1557 case MotionNotify: 1551 case MotionNotify:
1558#ifdef POINTER_BLANK 1552#ifdef POINTER_BLANK
1559 if (hidden_pointer) 1553 if (hidden_pointer)
1560 pointer_unblank (); 1554 pointer_unblank ();
1561#endif 1555#endif
1556 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1557 || priv_modes & PrivMode_MouseAnyEvent)
1558 mouse_report (ev.xbutton);
1562 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1559 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1563 break; 1560 break;
1564 1561
1565 if (ev.xany.window == vt) 1562 if (ev.xany.window == vt)
1566 { 1563 {
1567 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY) 1564 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1568 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) 1565 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1569 ; // nop 1566 ; // nop
1570 else if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1567 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1571 { 1568 {
1572 while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev)) 1569 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1573 ; 1570 ;
1574 1571
1575 XQueryPointer (xdisp, vt, 1572 XQueryPointer (dpy, vt,
1576 &unused_root, &unused_child, 1573 &unused_root, &unused_child,
1577 &unused_root_x, &unused_root_y, 1574 &unused_root_x, &unused_root_y,
1578 &ev.xbutton.x, &ev.xbutton.y, 1575 &ev.xbutton.x, &ev.xbutton.y,
1579 &ev.xbutton.state); 1576 &ev.xbutton.state);
1580#ifdef MOUSE_THRESHOLD 1577#ifdef MOUSE_THRESHOLD
1600 int dist; 1597 int dist;
1601 1598
1602 /* don't clobber the current delay if we are 1599 /* don't clobber the current delay if we are
1603 * already in the middle of scrolling. 1600 * already in the middle of scrolling.
1604 */ 1601 */
1605 if (!sel_scroll_ev.active) 1602 if (!sel_scroll_ev.is_active ())
1606 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1603 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1607 1604
1608 /* save the event params so we can highlight 1605 /* save the event params so we can highlight
1609 * the selection in the pending-scroll loop 1606 * the selection in the pending-scroll loop
1610 */ 1607 */
1611 selection_save_x = ev.xbutton.x; 1608 selection_save_x = ev.xbutton.x;
1633 else 1630 else
1634 { 1631 {
1635 /* we are within the text window, so we 1632 /* we are within the text window, so we
1636 * shouldn't be scrolling 1633 * shouldn't be scrolling
1637 */ 1634 */
1638 if (sel_scroll_ev.active)
1639 sel_scroll_ev.stop(); 1635 sel_scroll_ev.stop();
1640 } 1636 }
1641#endif 1637#endif
1642#ifdef MOUSE_THRESHOLD 1638#ifdef MOUSE_THRESHOLD
1643 } 1639 }
1644#endif 1640#endif
1645 } 1641 }
1646 } 1642 }
1647 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1643 else if (scrollBar.state == STATE_MOTION && ev.xany.window == scrollBar.win)
1648 { 1644 {
1649 while (XCheckTypedWindowEvent (xdisp, scrollBar.win, 1645 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1650 MotionNotify, &ev)) 1646 MotionNotify, &ev))
1651 ; 1647 ;
1652 1648
1653 XQueryPointer (xdisp, scrollBar.win, 1649 XQueryPointer (dpy, scrollBar.win,
1654 &unused_root, &unused_child, 1650 &unused_root, &unused_child,
1655 &unused_root_x, &unused_root_y, 1651 &unused_root_x, &unused_root_y,
1656 &ev.xbutton.x, &ev.xbutton.y, 1652 &ev.xbutton.x, &ev.xbutton.y,
1657 &unused_mask); 1653 &unused_mask);
1658 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1654 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1659 scrollbar_size ()); 1655 scrollBar.size ());
1660 want_refresh = 1; 1656 want_refresh = 1;
1661 refresh_limit = 0;
1662 scrollbar_show (1); 1657 scrollBar.show (1);
1663 } 1658 }
1664 break; 1659 break;
1665 } 1660 }
1666 1661
1667skip_switch: ;
1668
1669#if defined(CURSOR_BLINK) 1662#if defined(CURSOR_BLINK)
1670 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) 1663 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1671 { 1664 {
1672 if (hidden_cursor) 1665 if (hidden_cursor)
1673 { 1666 {
1674 hidden_cursor = 0; 1667 hidden_cursor = 0;
1675 want_refresh = 1; 1668 want_refresh = 1;
1676 } 1669 }
1677 1670
1678 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); 1671 cursor_blink_ev.again ();
1679 } 1672 }
1680#endif 1673#endif
1681 1674
1682#if defined(POINTER_BLANK) 1675#if defined(POINTER_BLANK)
1683 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) 1676 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1684 { 1677 {
1685 if (ev.type == MotionNotify 1678 if (ev.type == MotionNotify
1686 || ev.type == ButtonPress 1679 || ev.type == ButtonPress
1687 || ev.type == ButtonRelease) 1680 || ev.type == ButtonRelease)
1688 if (hidden_pointer) 1681 if (hidden_pointer)
1690 1683
1691 if (ev.type == KeyPress && hidden_pointer == 0) 1684 if (ev.type == KeyPress && hidden_pointer == 0)
1692 pointer_blank (); 1685 pointer_blank ();
1693 } 1686 }
1694#endif 1687#endif
1688
1689 refresh_check ();
1695} 1690}
1691
1692#if ENABLE_FRILLS
1693void
1694rxvt_term::set_urgency (bool enable)
1695{
1696 if (enable == urgency_hint)
1697 return;
1698
1699 if (XWMHints *h = XGetWMHints (dpy, parent[0]))
1700 {
1701 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1702 XSetWMHints (dpy, parent[0], h);
1703 urgency_hint = enable;
1704 }
1705}
1706#endif
1696 1707
1697void 1708void
1698rxvt_term::focus_in () 1709rxvt_term::focus_in ()
1699{ 1710{
1700 if (!focus) 1711 if (!focus)
1701 { 1712 {
1702 focus = 1; 1713 focus = 1;
1703 want_refresh = 1; 1714 want_refresh = 1;
1704 1715
1705 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1706
1707#if USE_XIM 1716#if USE_XIM
1708 if (Input_Context != NULL) 1717 if (Input_Context != NULL)
1709 { 1718 {
1710 IMSetStatusPosition (); 1719 IMSetPosition ();
1711 XSetICFocus (Input_Context); 1720 XSetICFocus (Input_Context);
1712 } 1721 }
1713#endif 1722#endif
1714#if CURSOR_BLINK 1723#if CURSOR_BLINK
1715 if (OPTION (Opt_cursorBlink)) 1724 if (option (Opt_cursorBlink))
1716 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); 1725 cursor_blink_ev.again ();
1717#endif 1726#endif
1718#if OFF_FOCUS_FADING 1727#if OFF_FOCUS_FADING
1719 if (rs[Rs_fade]) 1728 if (rs[Rs_fade])
1720 { 1729 {
1721 pix_colors = pix_colors_focused; 1730 pix_colors = pix_colors_focused;
1722 scr_recolour (); 1731 scr_recolour ();
1723 } 1732 }
1724#endif 1733#endif
1734#if ENABLE_FRILLS
1735 if (option (Opt_urgentOnBell))
1736 set_urgency (0);
1737#endif
1738
1739 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1725 } 1740 }
1726} 1741}
1727 1742
1728void 1743void
1729rxvt_term::focus_out () 1744rxvt_term::focus_out ()
1731 if (focus) 1746 if (focus)
1732 { 1747 {
1733 focus = 0; 1748 focus = 0;
1734 want_refresh = 1; 1749 want_refresh = 1;
1735 1750
1736 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); 1751#if ENABLE_FRILLS
1737 1752 if (option (Opt_urgentOnBell))
1753 set_urgency (0);
1754#endif
1738#if ENABLE_FRILLS || ISO_14755 1755#if ENABLE_FRILLS || ISO_14755
1739 if (iso14755buf) 1756 if (iso14755buf)
1740 { 1757 {
1741 iso14755buf = 0; 1758 iso14755buf = 0;
1742# if ENABLE_OVERLAY 1759# if ISO_14755
1743 scr_overlay_off (); 1760 scr_overlay_off ();
1744# endif 1761# endif
1745 } 1762 }
1746#endif 1763#endif
1747#if USE_XIM 1764#if USE_XIM
1748 if (Input_Context != NULL) 1765 if (Input_Context != NULL)
1749 XUnsetICFocus (Input_Context); 1766 XUnsetICFocus (Input_Context);
1750#endif 1767#endif
1751#if CURSOR_BLINK 1768#if CURSOR_BLINK
1752 if (OPTION (Opt_cursorBlink)) 1769 if (option (Opt_cursorBlink))
1753 cursor_blink_ev.stop (); 1770 cursor_blink_ev.stop ();
1771
1754 hidden_cursor = 0; 1772 hidden_cursor = 0;
1755#endif 1773#endif
1756#if OFF_FOCUS_FADING 1774#if OFF_FOCUS_FADING
1757 if (rs[Rs_fade]) 1775 if (rs[Rs_fade])
1758 { 1776 {
1759 pix_colors = pix_colors_unfocused; 1777 pix_colors = pix_colors_unfocused;
1760 scr_recolour (); 1778 scr_recolour ();
1761 } 1779 }
1762#endif 1780#endif
1781
1782 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1783 }
1784}
1785
1786void
1787rxvt_term::update_fade_color (unsigned int idx)
1788{
1789#if OFF_FOCUS_FADING
1790 if (rs[Rs_fade])
1763 } 1791 {
1792 rgba c;
1793 pix_colors [Color_fade].get (c);
1794 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1795 }
1796#endif
1764} 1797}
1765 1798
1766#if TRANSPARENT 1799#if ENABLE_TRANSPARENCY || ENABLE_PERL
1767void 1800void
1768rxvt_term::rootwin_cb (XEvent &ev) 1801rxvt_term::rootwin_cb (XEvent &ev)
1769{ 1802{
1770 make_current (); 1803 make_current ();
1771 1804
1805 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1806 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1807 return;
1808
1809# if ENABLE_TRANSPARENCY
1772 switch (ev.type) 1810 switch (ev.type)
1773 { 1811 {
1774 case PropertyNotify: 1812 case PropertyNotify:
1775 /* 1813 /*
1776 * if user used some Esetroot compatible prog to set the root bg, 1814 * if user used some Esetroot compatible prog to set the root bg,
1777 * use the property to determine the pixmap. We use it later on. 1815 * use the property to determine the pixmap. We use it later on.
1778 */ 1816 */
1779 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1817 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1780 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1818 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1781 return; 1819 {
1820 bgPixmap.set_root_pixmap ();
1821 update_background ();
1822 }
1782 1823
1783 /* FALLTHROUGH */
1784 case ReparentNotify:
1785 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1786 want_refresh = want_full_refresh = 1;
1787 break; 1824 break;
1788 } 1825 }
1826# endif
1827
1828 refresh_check ();
1789} 1829}
1790#endif 1830#endif
1791 1831
1792void 1832void
1793rxvt_term::button_press (XButtonEvent &ev) 1833rxvt_term::button_press (XButtonEvent &ev)
1848 mouse_report (ev); 1888 mouse_report (ev);
1849 } 1889 }
1850#else 1890#else
1851 MEvent.button = ev.button; 1891 MEvent.button = ev.button;
1852 mouse_report (ev); 1892 mouse_report (ev);
1853#endif /* MOUSE_REPORT_DOUBLECLICK */ 1893#endif /* MOUSE_REPORT_DOUBLECLICK */
1854 1894
1855 } 1895 }
1856 else 1896 else
1857 { 1897 {
1858 if (ev.button != MEvent.button) 1898 if (ev.button != MEvent.button)
1906 } 1946 }
1907 1947
1908 /* 1948 /*
1909 * Scrollbar window processing of button press 1949 * Scrollbar window processing of button press
1910 */ 1950 */
1911 if (isScrollbarWindow (ev.window)) 1951 if (scrollBar.state && ev.window == scrollBar.win)
1912 { 1952 {
1913 scrollBar.setIdle (); 1953 page_dirn direction = NO_DIR;
1954
1955 if (scrollBar.upButton (ev.y))
1956 direction = UP; /* up */
1957 else if (scrollBar.dnButton (ev.y))
1958 direction = DN; /* down */
1959
1960 scrollBar.state = STATE_IDLE;
1914 /* 1961 /*
1915 * Rxvt-style scrollbar: 1962 * Rxvt-style scrollbar:
1916 * move up if mouse is above slider 1963 * move up if mouse is above slider
1917 * move dn if mouse is below slider 1964 * move dn if mouse is below slider
1918 * 1965 *
1927 /* 1974 /*
1928 * Mouse report disabled scrollbar: 1975 * Mouse report disabled scrollbar:
1929 * arrow buttons - send up/down 1976 * arrow buttons - send up/down
1930 * click on scrollbar - send pageup/down 1977 * click on scrollbar - send pageup/down
1931 */ 1978 */
1932 if ((scrollBar.style == R_SB_NEXT 1979 if (direction == UP)
1933 && scrollbarnext_upButton (ev.y))
1934 || (scrollBar.style == R_SB_RXVT
1935 && scrollbarrxvt_upButton (ev.y)))
1936 tt_printf ("\033[A"); 1980 tt_printf ("\033[A");
1937 else if ((scrollBar.style == R_SB_NEXT 1981 else if (direction == DN)
1938 && scrollbarnext_dnButton (ev.y))
1939 || (scrollBar.style == R_SB_RXVT
1940 && scrollbarrxvt_dnButton (ev.y)))
1941 tt_printf ("\033[B"); 1982 tt_printf ("\033[B");
1942 else 1983 else
1943 switch (ev.button) 1984 switch (ev.button)
1944 { 1985 {
1945 case Button2: 1986 case Button2:
1952 tt_printf ("\033[5~"); 1993 tt_printf ("\033[5~");
1953 break; 1994 break;
1954 } 1995 }
1955 } 1996 }
1956 else 1997 else
1957#endif /* NO_SCROLLBAR_REPORT */ 1998#endif /* NO_SCROLLBAR_REPORT */
1958
1959 {
1960 char upordown = 0;
1961
1962 if (scrollBar.style == R_SB_NEXT)
1963 { 1999 {
1964 if (scrollbarnext_upButton (ev.y)) 2000 if (direction != NO_DIR)
1965 upordown = -1; /* up */
1966 else if (scrollbarnext_dnButton (ev.y))
1967 upordown = 1; /* down */
1968 }
1969 else if (scrollBar.style == R_SB_RXVT)
1970 {
1971 if (scrollbarrxvt_upButton (ev.y))
1972 upordown = -1; /* up */
1973 else if (scrollbarrxvt_dnButton (ev.y))
1974 upordown = 1; /* down */
1975 }
1976 if (upordown)
1977 { 2001 {
1978#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 2002#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
2003 if (!cont_scroll_ev.is_active ())
1979 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 2004 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1980#endif 2005#endif
1981 if (scr_page (upordown < 0 ? UP : DN, 1)) 2006 if (scr_page (direction, 1))
1982 { 2007 {
1983 if (upordown < 0) 2008 if (direction == UP)
1984 scrollBar.setUp (); 2009 scrollBar.state = STATE_UP;
1985 else 2010 else
1986 scrollBar.setDn (); 2011 scrollBar.state = STATE_DOWN;
1987 } 2012 }
1988 } 2013 }
1989 else 2014 else
1990 switch (ev.button) 2015 switch (ev.button)
1991 { 2016 {
1992 case Button2: 2017 case Button2:
1993 switch (scrollbar_align) 2018 switch (scrollBar.align)
1994 { 2019 {
1995 case R_SB_ALIGN_TOP: 2020 case R_SB_ALIGN_TOP:
1996 csrO = 0; 2021 csrO = 0;
1997 break; 2022 break;
1998 case R_SB_ALIGN_CENTRE: 2023 case R_SB_ALIGN_CENTRE:
2004 } 2029 }
2005 2030
2006 if (scrollBar.style == R_SB_XTERM 2031 if (scrollBar.style == R_SB_XTERM
2007 || scrollbar_above_slider (ev.y) 2032 || scrollbar_above_slider (ev.y)
2008 || scrollbar_below_slider (ev.y)) 2033 || scrollbar_below_slider (ev.y))
2009 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); 2034 scr_move_to (scrollbar_position (ev.y) - csrO, scrollBar.size ());
2010 2035
2011 scrollBar.setMotion (); 2036 scrollBar.state = STATE_MOTION;
2012 break; 2037 break;
2013 2038
2014 case Button1: 2039 case Button1:
2015 if (scrollbar_align == R_SB_ALIGN_CENTRE) 2040 if (scrollBar.align == R_SB_ALIGN_CENTRE)
2016 csrO = ev.y - scrollBar.top; 2041 csrO = ev.y - scrollBar.top;
2017 /* FALLTHROUGH */ 2042 /* FALLTHROUGH */
2018 2043
2019 case Button3: 2044 case Button3:
2020 if (scrollBar.style != R_SB_XTERM) 2045 if (scrollBar.style != R_SB_XTERM)
2030 scr_page (DN, nrow - 1); 2055 scr_page (DN, nrow - 1);
2031# else 2056# else
2032 scr_page (DN, nrow / 4); 2057 scr_page (DN, nrow / 4);
2033# endif 2058# endif
2034 else 2059 else
2035 scrollBar.setMotion (); 2060 scrollBar.state = STATE_MOTION;
2036 } 2061 }
2037 else 2062 else
2038 { 2063 {
2039 scr_page ((ev.button == Button1 ? DN : UP), 2064 scr_page ((ev.button == Button1 ? DN : UP),
2040 (nrow 2065 (nrow
2041 * scrollbar_position (ev.y) 2066 * scrollbar_position (ev.y)
2042 / scrollbar_size ())); 2067 / scrollBar.size ()));
2043 } 2068 }
2044 2069
2045 break; 2070 break;
2046 } 2071 }
2047 } 2072 }
2057 2082
2058 csrO = 0; /* reset csr Offset */ 2083 csrO = 0; /* reset csr Offset */
2059 if (!bypass_keystate) 2084 if (!bypass_keystate)
2060 reportmode = !! (priv_modes & PrivMode_mouse_report); 2085 reportmode = !! (priv_modes & PrivMode_mouse_report);
2061 2086
2062 if (scrollbar_isUpDn ()) 2087 if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
2063 { 2088 {
2064 scrollBar.setIdle (); 2089 scrollBar.state = STATE_IDLE;
2065 scrollbar_show (0); 2090 scrollBar.show (0);
2066 } 2091 }
2067 2092
2068#ifdef SELECTION_SCROLLING 2093#ifdef SELECTION_SCROLLING
2069 if (sel_scroll_ev.active)
2070 sel_scroll_ev.stop(); 2094 sel_scroll_ev.stop();
2071#endif 2095#endif
2072 2096
2073 if (ev.window == vt) 2097 if (ev.window == vt)
2074 { 2098 {
2075 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) 2099 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2099 mouse_report (ev); 2123 mouse_report (ev);
2100 } 2124 }
2101#else /* MOUSE_REPORT_DOUBLECLICK */ 2125#else /* MOUSE_REPORT_DOUBLECLICK */
2102 MEvent.button = AnyButton; 2126 MEvent.button = AnyButton;
2103 mouse_report (ev); 2127 mouse_report (ev);
2104#endif /* MOUSE_REPORT_DOUBLECLICK */ 2128#endif /* MOUSE_REPORT_DOUBLECLICK */
2105 return; 2129 return;
2106 } 2130 }
2107 2131
2108 /* 2132 /*
2109 * dumb hack to compensate for the failure of click-and-drag 2133 * dumb hack to compensate for the failure of click-and-drag
2121 selection_make (ev.time); 2145 selection_make (ev.time);
2122 break; 2146 break;
2123 2147
2124 case Button2: 2148 case Button2:
2125 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? 2149 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2126 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary); 2150 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2127 break; 2151 break;
2128 2152
2129#ifdef MOUSE_WHEEL 2153#ifdef MOUSE_WHEEL
2130 case Button4: 2154 case Button4:
2131 case Button5: 2155 case Button5:
2135 2159
2136 v = ev.button == Button4 ? UP : DN; 2160 v = ev.button == Button4 ? UP : DN;
2137 2161
2138 if (ev.state & ShiftMask) 2162 if (ev.state & ShiftMask)
2139 i = 1; 2163 i = 1;
2140 else if (OPTION (Opt_mouseWheelScrollPage)) 2164 else if (option (Opt_mouseWheelScrollPage))
2141 i = nrow - 1; 2165 i = nrow - 1;
2142 else 2166 else
2143 i = 5; 2167 i = 5;
2144 2168
2145# ifdef MOUSE_SLIP_WHEELING 2169# ifdef MOUSE_SLIP_WHEELING
2147 { 2171 {
2148 mouse_slip_wheel_speed += v ? -1 : 1; 2172 mouse_slip_wheel_speed += v ? -1 : 1;
2149 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; 2173 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2150 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; 2174 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2151 2175
2152 if (slip_wheel_ev.at < NOW) 2176 if (!slip_wheel_ev.is_active ())
2153 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2177 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2154
2155 slip_wheel_ev.start ();
2156 } 2178 }
2157 else 2179 else
2180# endif
2158 { 2181 {
2159# endif
2160 scr_page (v, i); 2182 scr_page (v, i);
2161 scrollbar_show (1); 2183 scrollBar.show (1);
2162# ifdef MOUSE_SLIP_WHEELING
2163 } 2184 }
2164# endif
2165 } 2185 }
2166 break; 2186 break;
2167#endif 2187#endif
2168 } 2188 }
2169 } 2189 }
2170} 2190}
2171 2191
2172#ifdef TRANSPARENT
2173#if TINTING
2174/* taken from aterm-0.4.2 */
2175
2176typedef uint32_t RUINT32T;
2177
2178void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
2179{
2180 int sh_r, sh_g, sh_b;
2181 RUINT32T mask_r, mask_g, mask_b;
2182 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2183 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2184 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2185 int i;
2186
2187 Visual *visual = term->visual;
2188
2189 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2190
2191 /* for convenience */
2192 mask_r = visual->red_mask;
2193 mask_g = visual->green_mask;
2194 mask_b = visual->blue_mask;
2195
2196 /* boring lookup table pre-initialization */
2197 switch (srcImage->bits_per_pixel) {
2198 case 15:
2199 if ((mask_r != 0x7c00) ||
2200 (mask_g != 0x03e0) ||
2201 (mask_b != 0x001f))
2202 return;
2203 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2204 lookup_r = lookup;
2205 lookup_g = lookup+32;
2206 lookup_b = lookup+32+32;
2207 sh_r = 10;
2208 sh_g = 5;
2209 sh_b = 0;
2210 break;
2211 case 16:
2212 if ((mask_r != 0xf800) ||
2213 (mask_g != 0x07e0) ||
2214 (mask_b != 0x001f))
2215 return;
2216 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2217 lookup_r = lookup;
2218 lookup_g = lookup+32;
2219 lookup_b = lookup+32+64;
2220 sh_r = 11;
2221 sh_g = 5;
2222 sh_b = 0;
2223 break;
2224 case 24:
2225 if ((mask_r != 0xff0000) ||
2226 (mask_g != 0x00ff00) ||
2227 (mask_b != 0x0000ff))
2228 return;
2229 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2230 lookup_r = lookup;
2231 lookup_g = lookup+256;
2232 lookup_b = lookup+256+256;
2233 sh_r = 16;
2234 sh_g = 8;
2235 sh_b = 0;
2236 break;
2237 case 32:
2238 if ((mask_r != 0xff0000) ||
2239 (mask_g != 0x00ff00) ||
2240 (mask_b != 0x0000ff))
2241 return;
2242 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2243 lookup_r = lookup;
2244 lookup_g = lookup+256;
2245 lookup_b = lookup+256+256;
2246 sh_r = 16;
2247 sh_g = 8;
2248 sh_b = 0;
2249 break;
2250 default:
2251 return; /* we do not support this color depth */
2252 }
2253
2254 /* prepare limits for color transformation (each channel is handled separately) */
2255 if (shade < 0) {
2256 shade = -shade;
2257 if (shade < 0) shade = 0;
2258 if (shade > 100) shade = 100;
2259
2260 lower_lim_r = 65535-rm;
2261 lower_lim_g = 65535-gm;
2262 lower_lim_b = 65535-bm;
2263
2264 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2265 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2266 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2267
2268 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2269 } else {
2270 if (shade < 0) shade = 0;
2271 if (shade > 100) shade = 100;
2272
2273 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2274
2275 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2276 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2277 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2278 }
2279
2280 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2281 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2282 {
2283 unsigned int tmp;
2284
2285 tmp = lower_lim_r;
2286 lower_lim_r = lower_lim_b;
2287 lower_lim_b = tmp;
2288
2289 tmp = upper_lim_r;
2290 upper_lim_r = upper_lim_b;
2291 upper_lim_b = tmp;
2292 }
2293
2294 /* fill our lookup tables */
2295 for (i = 0; i <= mask_r>>sh_r; i++)
2296 {
2297 RUINT32T tmp;
2298 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2299 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2300 lookup_r[i] = (tmp/65535)<<sh_r;
2301 }
2302 for (i = 0; i <= mask_g>>sh_g; i++)
2303 {
2304 RUINT32T tmp;
2305 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2306 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2307 lookup_g[i] = (tmp/65535)<<sh_g;
2308 }
2309 for (i = 0; i <= mask_b>>sh_b; i++)
2310 {
2311 RUINT32T tmp;
2312 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2313 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2314 lookup_b[i] = (tmp/65535)<<sh_b;
2315 }
2316
2317 /* apply table to input image (replacing colors by newly calculated ones) */
2318 switch (srcImage->bits_per_pixel)
2319 {
2320 case 15:
2321 {
2322 unsigned short *p1, *pf, *p, *pl;
2323 p1 = (unsigned short *) srcImage->data;
2324 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2325 while (p1 < pf)
2326 {
2327 p = p1;
2328 pl = p1 + srcImage->width;
2329 for (; p < pl; p++)
2330 {
2331 *p = lookup_r[(*p & 0x7c00)>>10] |
2332 lookup_g[(*p & 0x03e0)>> 5] |
2333 lookup_b[(*p & 0x001f)];
2334 }
2335 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2336 }
2337 break;
2338 }
2339 case 16:
2340 {
2341 unsigned short *p1, *pf, *p, *pl;
2342 p1 = (unsigned short *) srcImage->data;
2343 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2344 while (p1 < pf)
2345 {
2346 p = p1;
2347 pl = p1 + srcImage->width;
2348 for (; p < pl; p++)
2349 {
2350 *p = lookup_r[(*p & 0xf800)>>11] |
2351 lookup_g[(*p & 0x07e0)>> 5] |
2352 lookup_b[(*p & 0x001f)];
2353 }
2354 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2355 }
2356 break;
2357 }
2358 case 24:
2359 {
2360 unsigned char *p1, *pf, *p, *pl;
2361 p1 = (unsigned char *) srcImage->data;
2362 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2363 while (p1 < pf)
2364 {
2365 p = p1;
2366 pl = p1 + srcImage->width * 3;
2367 for (; p < pl; p += 3)
2368 {
2369 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2370 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2371 p[2] = lookup_r[(p[2] & 0x0000ff)];
2372 }
2373 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2374 }
2375 break;
2376 }
2377 case 32:
2378 {
2379 RUINT32T *p1, *pf, *p, *pl;
2380 p1 = (RUINT32T *) srcImage->data;
2381 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2382
2383 while (p1 < pf)
2384 {
2385 p = p1;
2386 pl = p1 + srcImage->width;
2387 for (; p < pl; p++)
2388 {
2389 *p = lookup_r[(*p & 0xff0000)>>16] |
2390 lookup_g[(*p & 0x00ff00)>> 8] |
2391 lookup_b[(*p & 0x0000ff)] |
2392 (*p & ~0xffffff);
2393 }
2394 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2395 }
2396 break;
2397 }
2398 }
2399
2400 free (lookup);
2401}
2402#endif
2403
2404/*
2405 * Check our parents are still who we think they are.
2406 * Do transparency updates if required
2407 */
2408int
2409rxvt_term::check_our_parents ()
2410{
2411 int i, pchanged, aformat, have_pixmap, rootdepth;
2412 unsigned long nitems, bytes_after;
2413 Atom atype;
2414 unsigned char *prop = NULL;
2415 Window root, oldp, *list;
2416 Pixmap rootpixmap = None;
2417 XWindowAttributes wattr, wrootattr;
2418
2419 pchanged = 0;
2420
2421 if (!OPTION (Opt_transparent))
2422 return pchanged; /* Don't try any more */
2423
2424 XGetWindowAttributes (xdisp, display->root, &wrootattr);
2425 rootdepth = wrootattr.depth;
2426
2427 XGetWindowAttributes (xdisp, parent[0], &wattr);
2428
2429 if (rootdepth != wattr.depth)
2430 {
2431 if (am_transparent)
2432 {
2433 pchanged = 1;
2434 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2435 am_transparent = am_pixmap_trans = 0;
2436 }
2437
2438 return pchanged; /* Don't try any more */
2439 }
2440
2441 /* Get all X ops out of the queue so that our information is up-to-date. */
2442 XSync (xdisp, False);
2443
2444 /*
2445 * Make the frame window set by the window manager have
2446 * the root background. Some window managers put multiple nested frame
2447 * windows for each client, so we have to take care about that.
2448 */
2449 i = (xa[XA_XROOTPMAP_ID]
2450 && XGetWindowProperty (xdisp, display->root, xa[XA_XROOTPMAP_ID],
2451 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2452 &nitems, &bytes_after, &prop) == Success);
2453
2454 if (!i || prop == NULL)
2455 i = (xa[XA_ESETROOT_PMAP_ID]
2456 && XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID],
2457 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2458 &nitems, &bytes_after, &prop) == Success);
2459
2460 if (!i || prop == NULL
2461#if TINTING
2462 || !ISSET_PIXCOLOR (Color_tint)
2463#endif
2464 )
2465 have_pixmap = 0;
2466 else
2467 {
2468 have_pixmap = 1;
2469 rootpixmap = *(Pixmap *)prop;
2470 XFree (prop);
2471 }
2472
2473 if (have_pixmap)
2474 {
2475 /*
2476 * Copy display->root pixmap transparency
2477 */
2478 int sx, sy, nx, ny;
2479 unsigned int nw, nh;
2480 Window cr;
2481 XImage *image;
2482 GC gc;
2483 XGCValues gcvalue;
2484
2485 XTranslateCoordinates (xdisp, parent[0], display->root,
2486 0, 0, &sx, &sy, &cr);
2487 nw = (unsigned int)szHint.width;
2488 nh = (unsigned int)szHint.height;
2489 nx = ny = 0;
2490
2491 if (sx < 0)
2492 {
2493 nw += sx;
2494 nx = -sx;
2495 sx = 0;
2496 }
2497
2498 if (sy < 0)
2499 {
2500 nh += sy;
2501 ny = -sy;
2502 sy = 0;
2503 }
2504
2505 min_it (nw, (unsigned int) (wrootattr.width - sx));
2506 min_it (nh, (unsigned int) (wrootattr.height - sy));
2507
2508 XSync (xdisp, False);
2509 allowedxerror = -1;
2510 image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2511
2512 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2513 /* XXX: may need a delay here? */
2514 allowedxerror = 0;
2515
2516 if (image == NULL)
2517 {
2518 if (am_transparent && am_pixmap_trans)
2519 {
2520 pchanged = 1;
2521 if (pixmap != None)
2522 {
2523 XFreePixmap (xdisp, pixmap);
2524 pixmap = None;
2525 }
2526 }
2527
2528 am_pixmap_trans = 0;
2529 }
2530 else
2531 {
2532 if (pixmap != None)
2533 XFreePixmap (xdisp, pixmap);
2534
2535#if TINTING
2536 if (ISSET_PIXCOLOR (Color_tint))
2537 {
2538 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2539
2540 rgba c;
2541 pix_colors_focused [Color_tint].get (c);
2542
2543 ShadeXImage (this, image, shade, c.r, c.g, c.b);
2544 }
2545#endif
2546
2547 pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth);
2548 gc = XCreateGC (xdisp, vt, 0UL, &gcvalue);
2549 XPutImage (xdisp, pixmap, gc, image, 0, 0,
2550 nx, ny, image->width, image->height);
2551 XFreeGC (xdisp, gc);
2552 XDestroyImage (image);
2553 XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap);
2554 XClearWindow (xdisp, parent[0]);
2555
2556 if (!am_transparent || !am_pixmap_trans)
2557 pchanged = 1;
2558
2559 am_transparent = am_pixmap_trans = 1;
2560 }
2561 }
2562
2563 if (am_pixmap_trans)
2564 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2565 else
2566 {
2567 unsigned int n;
2568 /*
2569 * InheritPixmap transparency
2570 */
2571 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2572 {
2573 oldp = parent[i];
2574 XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n);
2575 XFree (list);
2576
2577 if (parent[i] == display->root)
2578 {
2579 if (oldp != None)
2580 pchanged = 1;
2581
2582 break;
2583 }
2584
2585 if (oldp != parent[i])
2586 pchanged = 1;
2587 }
2588
2589 n = 0;
2590
2591 if (pchanged)
2592 for (; n < (unsigned int)i; n++)
2593 {
2594 XGetWindowAttributes (xdisp, parent[n], &wattr);
2595
2596 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2597 {
2598 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2599 break;
2600 }
2601 }
2602
2603 if (n > (sizeof (parent) / sizeof (parent[0])))
2604 {
2605 XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]);
2606 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2607 am_transparent = 0;
2608 /* XXX: also turn off Opt_transparent? */
2609 }
2610 else
2611 {
2612 for (n = 0; n < (unsigned int)i; n++)
2613 {
2614 XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative);
2615 XClearWindow (xdisp, parent[n]);
2616 }
2617
2618 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2619 am_transparent = 1;
2620 }
2621
2622 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2623 parent[i] = None;
2624 }
2625
2626 if (scrollBar.win)
2627 {
2628 XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative);
2629 scrollBar.setIdle ();
2630 scrollbar_show (0);
2631 }
2632
2633 if (am_transparent)
2634 {
2635 want_refresh = want_full_refresh = 1;
2636 if (am_pixmap_trans)
2637 flush ();
2638 }
2639
2640 return pchanged;
2641}
2642#endif
2643
2644/*}}} */ 2192/*}}} */
2645 2193
2646bool 2194void
2647rxvt_term::cmd_parse () 2195rxvt_term::cmd_parse ()
2648{ 2196{
2649 bool flag = false;
2650 wchar_t ch = NOCHAR; 2197 wchar_t ch = NOCHAR;
2651 char *seq_begin; // remember start of esc-sequence here 2198 char *seq_begin; // remember start of esc-sequence here
2652 2199
2653 for (;;) 2200 for (;;)
2654 { 2201 {
2655 if (ch == NOCHAR) 2202 if (expect_false (ch == NOCHAR))
2656 { 2203 {
2657 seq_begin = cmdbuf_ptr; 2204 seq_begin = cmdbuf_ptr;
2658 ch = next_char (); 2205 ch = next_char ();
2659 2206
2660 if (ch == NOCHAR) 2207 if (ch == NOCHAR)
2661 break; 2208 break;
2662 } 2209 }
2663 2210
2664 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2211 if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2665 { 2212 {
2666 if (!seen_input) 2213 if (expect_false (!seen_input))
2667 { 2214 {
2668 seen_input = 1; 2215 seen_input = 1;
2669 // many badly-written programs (e.g. jed) contain a race condition: 2216 // many badly-written programs (e.g. jed) contain a race condition:
2670 // they first read the screensize and then install a SIGWINCH handler. 2217 // they first read the screensize and then install a SIGWINCH handler.
2671 // some window managers resize the window early, and these programs 2218 // some window managers resize the window early, and these programs
2684 wchar_t *str = buf; 2231 wchar_t *str = buf;
2685 wchar_t *eol = str + min (ncol, UBUFSIZ); 2232 wchar_t *eol = str + min (ncol, UBUFSIZ);
2686 2233
2687 for (;;) 2234 for (;;)
2688 { 2235 {
2689 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2236 if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2690 break; 2237 break;
2691 2238
2692 *str++ = ch; 2239 *str++ = ch;
2693 2240
2694 if (ch == C0_LF || str >= eol) 2241 if (expect_false (ch == C0_LF || str >= eol))
2695 { 2242 {
2696 if (ch == C0_LF) 2243 if (ch == C0_LF)
2697 nlines++; 2244 nlines++;
2698 2245
2699 refresh_count++; 2246 refresh_count++;
2700 2247
2701 if (!OPTION (Opt_jumpScroll) 2248 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2702 || (refresh_count >= refresh_limit * (nrow - 1)))
2703 { 2249 {
2704 refreshnow = true;
2705 refresh_count = 0; 2250 refresh_count = 0;
2251
2252 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2253 {
2254 refreshnow = true;
2706 ch = NOCHAR; 2255 ch = NOCHAR;
2707 break; 2256 break;
2257 }
2708 } 2258 }
2709 2259
2710 // scr_add_lines only works for nlines <= nrow - 1. 2260 // scr_add_lines only works for nlines <= nrow - 1.
2711 if (nlines >= nrow - 1) 2261 if (nlines >= nrow - 1)
2712 { 2262 {
2740 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) 2290 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2741 scr_add_lines (buf, str - buf, nlines); 2291 scr_add_lines (buf, str - buf, nlines);
2742 2292
2743 /* 2293 /*
2744 * If there have been a lot of new lines, then update the screen 2294 * If there have been a lot of new lines, then update the screen
2745 * What the heck I'll cheat and only refresh less than every page-full. 2295 * What the heck we'll cheat and only refresh less than every page-full.
2746 * the number of pages between refreshes is refresh_limit, which 2296 * if skipScroll is enabled.
2747 * is incremented here because we must be doing flat-out scrolling.
2748 */ 2297 */
2749 if (refreshnow) 2298 if (refreshnow)
2750 { 2299 {
2751 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2752 refresh_limit++;
2753 else
2754 {
2755 flag = true;
2756 scr_refresh (); 2300 scr_refresh ();
2757 want_refresh = 1; 2301 want_refresh = 1;
2758 }
2759 } 2302 }
2760
2761 } 2303 }
2762 else 2304 else
2763 { 2305 {
2764 try 2306 try
2765 { 2307 {
2773 } 2315 }
2774 2316
2775 ch = NOCHAR; 2317 ch = NOCHAR;
2776 } 2318 }
2777 } 2319 }
2778
2779 return flag;
2780} 2320}
2781 2321
2782// read the next character 2322// read the next character
2783wchar_t 2323wchar_t
2784rxvt_term::next_char () NOTHROW 2324rxvt_term::next_char () NOTHROW
2785{ 2325{
2786 while (cmdbuf_ptr < cmdbuf_endp) 2326 while (cmdbuf_ptr < cmdbuf_endp)
2787 { 2327 {
2788 // assume 7-bit to be ascii ALWAYS 2328 // assume 7-bit to be ascii ALWAYS
2789 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2329 if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b))
2790 return *cmdbuf_ptr++; 2330 return *cmdbuf_ptr++;
2791 2331
2792 wchar_t wc; 2332 wchar_t wc;
2793 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2333 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2794 2334
2798 cmdbuf_ptr = cmdbuf_endp; 2338 cmdbuf_ptr = cmdbuf_endp;
2799 break; 2339 break;
2800 } 2340 }
2801 2341
2802 if (len == (size_t)-1) 2342 if (len == (size_t)-1)
2343 {
2344 mbstate.reset (); // reset now undefined conversion state
2803 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2345 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2346 }
2804 2347
2805 // assume wchar == unicode 2348 // assume wchar == unicode
2806 cmdbuf_ptr += len; 2349 cmdbuf_ptr += len;
2807 return wc & UNICODE_MASK; 2350 return wc & UNICODE_MASK;
2808 } 2351 }
2852/*----------------------------------------------------------------------*/ 2395/*----------------------------------------------------------------------*/
2853#ifdef PRINTPIPE 2396#ifdef PRINTPIPE
2854FILE * 2397FILE *
2855rxvt_term::popen_printer () 2398rxvt_term::popen_printer ()
2856{ 2399{
2857 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2400 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2858 2401
2859 if (stream == NULL) 2402 if (stream == NULL)
2860 rxvt_warn ("can't open printer pipe, not printing.\n"); 2403 rxvt_warn ("can't open printer pipe, not printing.\n");
2861 2404
2862 return stream; 2405 return stream;
2873 * simulate attached vt100 printer 2416 * simulate attached vt100 printer
2874 */ 2417 */
2875void 2418void
2876rxvt_term::process_print_pipe () 2419rxvt_term::process_print_pipe ()
2877{ 2420{
2878 int done; 2421 FILE *fd = popen_printer ();
2879 FILE *fd;
2880 2422
2881 if ((fd = popen_printer ()) == NULL) 2423 if (!fd)
2882 return; 2424 return;
2883 2425
2884 /* 2426 /*
2885 * Send all input to the printer until either ESC[4i or ESC[?4i 2427 * Send all input to the printer until either ESC[4i or ESC[?4i
2886 * is received. 2428 * is received.
2887 */ 2429 */
2888 for (done = 0; !done;) 2430 for (int done = 0; !done; )
2889 { 2431 {
2890 unsigned char buf[8]; 2432 unsigned char buf[8];
2891 unicode_t ch; 2433 unicode_t ch;
2892 unsigned int i, len; 2434 unsigned int i, len;
2893 2435
2912 { 2454 {
2913 if ((buf[len++] = cmd_getc ()) == 'i') 2455 if ((buf[len++] = cmd_getc ()) == 'i')
2914 break; /* done = 1 */ 2456 break; /* done = 1 */
2915 } 2457 }
2916 } 2458 }
2917 2459
2918 for (i = 0; i < len; i++) 2460 for (i = 0; i < len; i++)
2919 if (putc (buf[i], fd) == EOF) 2461 if (putc (buf[i], fd) == EOF)
2920 { 2462 {
2921 done = 1; 2463 done = 1;
2922 break; 2464 break;
2924 } 2466 }
2925 } 2467 }
2926 2468
2927 pclose_printer (fd); 2469 pclose_printer (fd);
2928} 2470}
2929#endif /* PRINTPIPE */ 2471#endif /* PRINTPIPE */
2930/*}}} */ 2472/*}}} */
2931 2473
2932/* *INDENT-OFF* */ 2474/* *INDENT-OFF* */
2933enum { 2475enum {
2934 C1_40 = 0x40, 2476 C1_40 = 0x40,
2984 process_dcs_seq (); 2526 process_dcs_seq ();
2985 break; 2527 break;
2986 case 0x9b: /* CSI */ 2528 case 0x9b: /* CSI */
2987 process_csi_seq (); 2529 process_csi_seq ();
2988 break; 2530 break;
2989 case 0x9d: /* CSI */ 2531 case 0x9d: /* OSC */
2990 process_osc_seq (); 2532 process_osc_seq ();
2991 break; 2533 break;
2992#endif 2534#endif
2993 } 2535 }
2994} 2536}
3038 break; 2580 break;
3039 case 'Z': /* identify the terminal type */ 2581 case 'Z': /* identify the terminal type */
3040 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ 2582 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
3041 break; 2583 break;
3042 case '<': /* turn off VT52 mode */ 2584 case '<': /* turn off VT52 mode */
3043 PrivMode (0, PrivMode_vt52); 2585 set_privmode (PrivMode_vt52, 0);
3044 break; 2586 break;
3045 case 'F': /* use special graphics character set */ 2587 case 'F': /* use special graphics character set */
3046 case 'G': /* use regular character set */ 2588 case 'G': /* use regular character set */
3047 /* unimplemented */ 2589 /* unimplemented */
3048 break; 2590 break;
3102 scr_forwardindex (); 2644 scr_forwardindex ();
3103 break; 2645 break;
3104#endif 2646#endif
3105 case '=': 2647 case '=':
3106 case '>': 2648 case '>':
3107 PrivMode ((ch == '='), PrivMode_aplKP); 2649 set_privmode (PrivMode_aplKP, ch == '=');
3108 break; 2650 break;
3109 2651
3110 case C1_40: 2652 case C1_40:
3111 cmd_getc (); 2653 cmd_getc ();
3112 break; 2654 break;
3151 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2693 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3152 case C1_SCI: /* ESC Z */ 2694 case C1_SCI: /* ESC Z */
3153 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1); 2695 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3154 break; /* steal obsolete ESC [ c */ 2696 break; /* steal obsolete ESC [ c */
3155 2697
3156 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2698 /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */
3157 case C1_CSI: /* ESC [ */ 2699 case C1_CSI: /* ESC [ */
3158 process_csi_seq (); 2700 process_csi_seq ();
3159 break; 2701 break;
3160 2702
3161 /* 8.3.90: OPERATING SYSTEM COMMAND */ 2703 /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */
3162 case C1_OSC: /* ESC ] */ 2704 case C1_OSC: /* ESC ] */
3163 process_osc_seq (); 2705 process_osc_seq ();
3164 break; 2706 break;
3165 2707
3166 /* 8.3.106: RESET TO INITIAL STATE */ 2708 /* 8.3.106: RESET TO INITIAL STATE (RIS) */
3167 case 'c': 2709 case 'c':
3168 mbstate.reset (); 2710 mbstate.reset ();
3169 scr_poweron (); 2711 scr_poweron ();
3170 scrollbar_show (1); 2712 scrollBar.show (1);
3171 break; 2713 break;
3172 2714
3173 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2715 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3174 case 'n': 2716 case 'n':
3175 scr_charset_choose (2); 2717 scr_charset_choose (2);
3220rxvt_term::process_csi_seq () 2762rxvt_term::process_csi_seq ()
3221{ 2763{
3222 unicode_t ch, priv, i; 2764 unicode_t ch, priv, i;
3223 unsigned int nargs, p; 2765 unsigned int nargs, p;
3224 int n, ndef; 2766 int n, ndef;
3225 int arg[ESC_ARGS]; 2767 int arg[ESC_ARGS] = { };
3226 2768
3227 for (nargs = ESC_ARGS; nargs > 0;) 2769 nargs = 0;
3228 arg[--nargs] = 0;
3229 2770
3230 priv = 0; 2771 priv = 0;
3231 ch = cmd_getc (); 2772 ch = cmd_getc ();
3232 if (ch >= '<' && ch <= '?') 2773 if ((ch >= '<' && ch <= '?') || ch == '!')
2774 {
3233 { /* '<' '=' '>' '?' */ 2775 /* '<' '=' '>' '?' '!' */
3234 priv = ch; 2776 priv = ch;
3235 ch = cmd_getc (); 2777 ch = cmd_getc ();
3236 } 2778 }
3237 2779
3238 /* read any numerical arguments */ 2780 /* read any numerical arguments */
3277 switch (priv) 2819 switch (priv)
3278 { 2820 {
3279 case '>': 2821 case '>':
3280 if (ch == CSI_DA) /* secondary device attributes */ 2822 if (ch == CSI_DA) /* secondary device attributes */
3281 { 2823 {
3282 // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, 2824 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
3283 // 'U' for rxvt-unicode != 7.[34] (where it was broken). 2825 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
3284 // 2826 //
3285 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt 2827 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
3286 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify 2828 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
3287 // that we do not support xterm mouse reporting (should be 95 when we do). 2829 // versions.
3288 // 2830 //
3289 tt_printf ("\033[>%d;94;0c", 'U'); 2831 tt_printf ("\033[>%d;95;0c", 'U');
3290 } 2832 }
3291 break; 2833 break;
2834
3292 case '?': 2835 case '?':
3293 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2836 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3294 process_terminal_mode (ch, priv, nargs, arg); 2837 process_terminal_mode (ch, priv, nargs, arg);
3295 break; 2838 break;
2839
2840 case '!':
2841 if (ch == CSI_70)
2842 {
2843 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2844 scr_soft_reset ();
2845
2846 static const int pm_h[] = { 7, 25 };
2847 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1049 };
2848
2849 process_terminal_mode ('h', 0, sizeof (pm_h) / sizeof (pm_h[0]), pm_h);
2850 process_terminal_mode ('l', 0, sizeof (pm_l) / sizeof (pm_l[0]), pm_l);
3296 } 2851 }
2852 break;
2853 }
2854
3297 return; 2855 return;
3298 } 2856 }
3299 2857
3300 switch (ch) 2858 switch (ch)
3301 { 2859 {
3421 break; 2979 break;
3422 case 6: /* CPR requested */ 2980 case 6: /* CPR requested */
3423 scr_report_position (); 2981 scr_report_position ();
3424 break; 2982 break;
3425 case 7: /* unofficial extension */ 2983 case 7: /* unofficial extension */
3426 if (OPTION (Opt_insecure)) 2984 if (option (Opt_insecure))
3427 tt_printf ("%-.250s\012", rs[Rs_display_name]); 2985 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3428 break; 2986 break;
3429 case 8: /* unofficial extension */ 2987 case 8: /* unofficial extension */
3430 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2988 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3431 break; 2989 break;
3524{ 3082{
3525 int x, y; 3083 int x, y;
3526 XWindowAttributes wattr; 3084 XWindowAttributes wattr;
3527 Window wdummy; 3085 Window wdummy;
3528 3086
3529 dLocal (Display *, xdisp); 3087 dLocal (Display *, dpy);
3530 3088
3531 if (nargs == 0) 3089 if (nargs == 0)
3532 return; 3090 return;
3533 3091
3534 switch (args[0]) 3092 switch (args[0])
3535 { 3093 {
3536 /* 3094 /*
3537 * commands 3095 * commands
3538 */ 3096 */
3539 case 1: /* deiconify window */ 3097 case 1: /* deiconify window */
3540 XMapWindow (xdisp, parent[0]); 3098 XMapWindow (dpy, parent[0]);
3541 break; 3099 break;
3542 case 2: /* iconify window */ 3100 case 2: /* iconify window */
3543 XIconifyWindow (xdisp, parent[0], display->screen); 3101 XIconifyWindow (dpy, parent[0], display->screen);
3544 break; 3102 break;
3545 case 3: /* set position (pixels) */ 3103 case 3: /* set position (pixels) */
3546 XMoveWindow (xdisp, parent[0], args[1], args[2]); 3104 XMoveWindow (dpy, parent[0], args[1], args[2]);
3547 break; 3105 break;
3548 case 4: /* set size (pixels) */ 3106 case 4: /* set size (pixels) */
3549 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3107 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3550 break; 3108 break;
3551 case 5: /* raise window */ 3109 case 5: /* raise window */
3552 XRaiseWindow (xdisp, parent[0]); 3110 XRaiseWindow (dpy, parent[0]);
3553 break; 3111 break;
3554 case 6: /* lower window */ 3112 case 6: /* lower window */
3555 XLowerWindow (xdisp, parent[0]); 3113 XLowerWindow (dpy, parent[0]);
3556 break; 3114 break;
3557 case 7: /* refresh window */ 3115 case 7: /* refresh window */
3558 scr_touch (true); 3116 scr_touch (true);
3559 break; 3117 break;
3560 case 8: /* set size (chars) */ 3118 case 8: /* set size (chars) */
3571 3129
3572 /* 3130 /*
3573 * reports - some output format copied from XTerm 3131 * reports - some output format copied from XTerm
3574 */ 3132 */
3575 case 11: /* report window state */ 3133 case 11: /* report window state */
3576 XGetWindowAttributes (xdisp, parent[0], &wattr); 3134 XGetWindowAttributes (dpy, parent[0], &wattr);
3577 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3135 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3578 break; 3136 break;
3579 case 13: /* report window position */ 3137 case 13: /* report window position */
3580 XGetWindowAttributes (xdisp, parent[0], &wattr); 3138 XGetWindowAttributes (dpy, parent[0], &wattr);
3581 XTranslateCoordinates (xdisp, parent[0], wattr.root, 3139 XTranslateCoordinates (dpy, parent[0], wattr.root,
3582 -wattr.border_width, -wattr.border_width, 3140 -wattr.border_width, -wattr.border_width,
3583 &x, &y, &wdummy); 3141 &x, &y, &wdummy);
3584 tt_printf ("\033[3;%d;%dt", x, y); 3142 tt_printf ("\033[3;%d;%dt", x, y);
3585 break; 3143 break;
3586 case 14: /* report window size (pixels) */ 3144 case 14: /* report window size (pixels) */
3587 XGetWindowAttributes (xdisp, parent[0], &wattr); 3145 XGetWindowAttributes (dpy, parent[0], &wattr);
3588 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3146 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3589 break; 3147 break;
3590 case 18: /* report text area size (chars) */ 3148 case 18: /* report text area size (chars) */
3591 tt_printf ("\033[8;%d;%dt", nrow, ncol); 3149 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3592 break; 3150 break;
3594 tt_printf ("\033[9;%d;%dt", nrow, ncol); 3152 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3595 break; 3153 break;
3596 case 20: /* report icon label */ 3154 case 20: /* report icon label */
3597 { 3155 {
3598 char *s; 3156 char *s;
3599 XGetIconName (xdisp, parent[0], &s); 3157 XGetIconName (dpy, parent[0], &s);
3600 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ 3158 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3601 XFree (s); 3159 XFree (s);
3602 } 3160 }
3603 break; 3161 break;
3604 case 21: /* report window title */ 3162 case 21: /* report window title */
3605 { 3163 {
3606 char *s; 3164 char *s;
3607 XFetchName (xdisp, parent[0], &s); 3165 XFetchName (dpy, parent[0], &s);
3608 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ 3166 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3609 XFree (s); 3167 XFree (s);
3610 } 3168 }
3611 break; 3169 break;
3612 } 3170 }
3613} 3171}
3640 seen_esc = true; 3198 seen_esc = true;
3641 continue; 3199 continue;
3642 } 3200 }
3643 else if (ch == C0_BEL || ch == CHAR_ST) 3201 else if (ch == C0_BEL || ch == CHAR_ST)
3644 break; 3202 break;
3203 else if (ch == C0_SYN)
3204 ch = cmd_get8 ();
3645 else if (ch < 0x20) 3205 else if (ch < 0x20)
3646 return NULL; /* other control character - exit */ 3206 return NULL; /* other control character - exit */
3647 3207
3648 seen_esc = false; 3208 seen_esc = false;
3649 3209
3650 if (n >= STRING_MAX - 1) 3210 if (n >= STRING_MAX - 1)
3651 // stop at some sane length 3211 // stop at some sane length
3652 return NULL; 3212 return NULL;
3653 3213
3654 if (ch == C0_SYN)
3655 string[n++] = cmd_get8 ();
3656 else
3657 string[n++] = ch; 3214 string[n++] = ch;
3658 } 3215 }
3659 3216
3660 string[n++] = '\0'; 3217 string[n++] = '\0';
3661 3218
3662 ends_how = (ch == 0x5c ? C0_ESC : ch); 3219 ends_how = (ch == 0x5c ? C0_ESC : ch);
3731 3288
3732/* 3289/*
3733 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) 3290 * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL)
3734 */ 3291 */
3735void 3292void
3736rxvt_term::process_xterm_seq (int op, const char *str, char resp) 3293rxvt_term::process_xterm_seq (int op, char *str, char resp)
3737{ 3294{
3738 int color; 3295 int color;
3739 char *buf, *name; 3296 char *buf, *name;
3740 bool query = str[0] == '?' && !str[1]; 3297 bool query = str[0] == '?' && !str[1];
3741 int saveop = op; 3298 int saveop = op;
3742 3299
3743 dLocal (Display *, xdisp); 3300 dLocal (Display *, dpy);
3744 3301
3745 assert (str != NULL); 3302 assert (str != NULL);
3303
3304 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3305 return;
3306
3746 switch (op) 3307 switch (op)
3747 { 3308 {
3748 case XTerm_name: 3309 case XTerm_name:
3749 set_title (str); 3310 set_title (str);
3750 /* FALLTHROUGH */ 3311 /* FALLTHROUGH */
3764 unsigned long bytes_after; 3325 unsigned long bytes_after;
3765 unsigned char *value = 0; 3326 unsigned char *value = 0;
3766 const char *str = ""; 3327 const char *str = "";
3767 3328
3768 if (prop 3329 if (prop
3769 && XGetWindowProperty (xdisp, parent[0], 3330 && XGetWindowProperty (dpy, parent[0],
3770 prop, 0, 1<<16, 0, AnyPropertyType, 3331 prop, 0, 1<<16, 0, AnyPropertyType,
3771 &actual_type, &actual_format, 3332 &actual_type, &actual_format,
3772 &nitems, &bytes_after, &value) == Success 3333 &nitems, &bytes_after, &value) == Success
3773 && actual_type != None 3334 && actual_type != None
3774 && actual_format == 8) 3335 && actual_format == 8)
3778 3339
3779 XFree (value); 3340 XFree (value);
3780 } 3341 }
3781 else 3342 else
3782 { 3343 {
3783 char *eq = strchr (str, '='); // constness lost, but verified to be ok 3344 char *eq = strchr (str, '=');
3784 3345
3785 if (eq) 3346 if (eq)
3786 { 3347 {
3787 *eq = 0; 3348 *eq = 0;
3788 set_utf8_property (display->atom (str), eq + 1); 3349 set_utf8_property (display->atom (str), eq + 1);
3789 } 3350 }
3790 else 3351 else
3791 XDeleteProperty (xdisp, parent[0], 3352 XDeleteProperty (dpy, parent[0],
3792 display->atom (str)); 3353 display->atom (str));
3793 } 3354 }
3794 break; 3355 break;
3795 3356
3796 case XTerm_Color: 3357 case XTerm_Color:
3809 *buf++ = '\0'; 3370 *buf++ = '\0';
3810 3371
3811 process_color_seq (op, color, name, resp); 3372 process_color_seq (op, color, name, resp);
3812 } 3373 }
3813 break; 3374 break;
3375 case Rxvt_restoreFG:
3814 case XTerm_Color00: 3376 case XTerm_Color00:
3815 process_color_seq (op, Color_fg, str, resp); 3377 process_color_seq (op, Color_fg, str, resp);
3816 break; 3378 break;
3379 case Rxvt_restoreBG:
3817 case XTerm_Color01: 3380 case XTerm_Color01:
3818 process_color_seq (op, Color_bg, str, resp); 3381 process_color_seq (op, Color_bg, str, resp);
3819 break; 3382 break;
3820#ifndef NO_CURSORCOLOR 3383#ifndef NO_CURSORCOLOR
3821 case XTerm_Color_cursor: 3384 case XTerm_Color_cursor:
3842 break; 3405 break;
3843 case URxvt_Color_IT: 3406 case URxvt_Color_IT:
3844 process_color_seq (op, Color_IT, str, resp); 3407 process_color_seq (op, Color_IT, str, resp);
3845 break; 3408 break;
3846#endif 3409#endif
3847#if TRANSPARENT && TINTING 3410 case URxvt_Color_border:
3411 process_color_seq (op, Color_border, str, resp);
3412 break;
3413#if ENABLE_TRANSPARENCY
3848 case URxvt_Color_tint: 3414 case URxvt_Color_tint:
3849 process_color_seq (op, Color_tint, str, resp); 3415 process_color_seq (op, Color_tint, str, resp);
3416 {
3417 bool changed = false;
3850 3418
3851 check_our_parents (); 3419 if (ISSET_PIXCOLOR (Color_tint))
3420 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3421 else
3422 changed = bgPixmap.unset_tint ();
3852 3423
3853 if (am_transparent) 3424 if (changed)
3854 want_full_refresh = want_refresh = 1; 3425 update_background ();
3426 }
3855 3427
3856 break; 3428 break;
3857#endif 3429#endif
3858 3430
3431#if BG_IMAGE_FROM_FILE
3859 case Rxvt_Pixmap: 3432 case Rxvt_Pixmap:
3860 { 3433 if (!strcmp (str, "?"))
3861 if (*str != ';')
3862 { 3434 {
3863#if XPM_BACKGROUND 3435 char str[256];
3864 scale_pixmap (""); /* reset to default scaling */ 3436
3865 set_bgPixmap (str); /* change pixmap */ 3437 sprintf (str, "[%dx%d+%d+%d]",
3866 scr_touch (true); 3438 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3867#endif 3439 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3440 process_xterm_seq (XTerm_title, str, CHAR_ST);
3868 } 3441 }
3869 3442 else
3443 {
3870 int changed = 0; 3444 int changed = 0;
3871 3445
3872 while ((str = strchr (str, ';')) != NULL) 3446 if (*str != ';')
3873 { 3447 {
3448 /* reset to default scaling :*/
3449 bgPixmap.unset_geometry ();
3450 if (bgPixmap.set_file (str)) /* change pixmap */
3451 changed++;
3452 str = strchr (str, ';');
3453 if (str == NULL)
3454 bgPixmap.set_defaultGeometry ();
3455 }
3456
3457 while (str)
3458 {
3874 str++; 3459 str++;
3875#if XPM_BACKGROUND 3460 if (bgPixmap.set_geometry (str))
3876 changed += scale_pixmap (str); 3461 changed++;
3877#endif 3462 str = strchr (str, ';');
3878 } 3463 }
3879 3464
3880 if (changed) 3465 if (changed)
3881 { 3466 update_background ();
3882#ifdef XPM_BACKGROUND
3883 resize_pixmap ();
3884 scr_touch (true);
3885#endif
3886 } 3467 }
3887 }
3888 break; 3468 break;
3889 3469#endif
3890 case Rxvt_restoreFG:
3891 set_window_color (Color_fg, str);
3892 break;
3893 case Rxvt_restoreBG:
3894 set_window_color (Color_bg, str);
3895 break;
3896 3470
3897 case XTerm_logfile: 3471 case XTerm_logfile:
3898 // TODO, when secure mode? 3472 // TODO, when secure mode?
3899 break; 3473 break;
3900 3474
3918 case URxvt_italicFont: 3492 case URxvt_italicFont:
3919 case URxvt_boldItalicFont: 3493 case URxvt_boldItalicFont:
3920#endif 3494#endif
3921 if (query) 3495 if (query)
3922 tt_printf ("\33]%d;%-.250s%c", saveop, 3496 tt_printf ("\33]%d;%-.250s%c", saveop,
3923 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3497 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3924 ? fontset[op - URxvt_font]->fontdesc : "", 3498 ? fontset[op - URxvt_font]->fontdesc : "",
3925 resp); 3499 resp);
3926 else 3500 else
3927 { 3501 {
3928 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3502 const char *&res = rs[Rs_font + (op - URxvt_font)];
3942 break; 3516 break;
3943 3517
3944#if !ENABLE_MINIMAL 3518#if !ENABLE_MINIMAL
3945 case URxvt_locale: 3519 case URxvt_locale:
3946 if (query) 3520 if (query)
3947 tt_printf ("\33]%d;%-.250s%c", op, OPTION (Opt_insecure) ? locale : "", resp); 3521 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3948 else 3522 else
3949 { 3523 {
3950 set_locale (str); 3524 set_locale (str);
3951 pty->set_utf8_mode (enc_utf8); 3525 pty->set_utf8_mode (enc_utf8);
3952 init_xlocale (); 3526 init_xlocale ();
3967 break; 3541 break;
3968#endif 3542#endif
3969 3543
3970#if ENABLE_PERL 3544#if ENABLE_PERL
3971 case URxvt_perl: 3545 case URxvt_perl:
3972 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END))) 3546 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3973 ; // no responses yet
3974 break; 3547 break;
3975#endif 3548#endif
3976 } 3549 }
3977} 3550}
3978/*----------------------------------------------------------------------*/ 3551/*----------------------------------------------------------------------*/
4001 { 3574 {
4002 if (mode == 'r') 3575 if (mode == 'r')
4003 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3576 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
4004 else 3577 else
4005 state = (mode == 't') ? ! (priv_modes & bit) : mode; 3578 state = (mode == 't') ? ! (priv_modes & bit) : mode;
4006 PrivMode (state, bit); 3579 set_privmode (bit, state);
4007 } 3580 }
4008 3581
4009 return state; 3582 return state;
4010} 3583}
4011 3584
4015{ 3588{
4016 unsigned int i, j; 3589 unsigned int i, j;
4017 int state; 3590 int state;
4018 3591
4019 static const struct 3592 static const struct
4020 { 3593 {
4021 const int argval; 3594 const int argval;
4022 const unsigned long bit; 3595 const unsigned long bit;
4023 }
4024
4025 argtopriv[] = { 3596 } argtopriv[] = {
4026 { 1, PrivMode_aplCUR }, 3597 { 1, PrivMode_aplCUR }, // DECCKM
4027 { 2, PrivMode_vt52 }, 3598 { 2, PrivMode_vt52 },
4028 { 3, PrivMode_132 }, 3599 { 3, PrivMode_132 }, // DECCOLM
4029 { 4, PrivMode_smoothScroll }, 3600 { 4, PrivMode_smoothScroll }, // DECSCLM
4030 { 5, PrivMode_rVideo }, 3601 { 5, PrivMode_rVideo }, // DECSCNM
4031 { 6, PrivMode_relOrigin }, 3602 { 6, PrivMode_relOrigin }, // DECOM
4032 { 7, PrivMode_Autowrap }, 3603 { 7, PrivMode_Autowrap }, // DECAWM
4033 // 8, bi-directional support mode 3604 // 8, auto-repeat keys // DECARM
4034 { 9, PrivMode_MouseX10 }, 3605 { 9, PrivMode_MouseX10 },
4035 // 18, 19 printing-related 3606 // 18 end FF to printer after print screen
3607 // 19 Print screen prints full screen/scorll region
4036 { 25, PrivMode_VisibleCursor }, 3608 { 25, PrivMode_VisibleCursor }, // cnorm/cvvis/civis
4037#ifdef scrollBar_esc 3609#ifdef scrollBar_esc
4038 { scrollBar_esc, PrivMode_scrollBar }, 3610 { scrollBar_esc, PrivMode_scrollBar },
4039#endif 3611#endif
4040 { 35, PrivMode_ShiftKeys }, // rxvt extension 3612 { 35, PrivMode_ShiftKeys }, // rxvt extension
3613 // 38, tektronix mode // DECTEK
4041 { 40, PrivMode_132OK }, 3614 { 40, PrivMode_132OK },
4042 // 41 xterm more fixes NYI 3615 // 41 xterm more fixes NYI
4043 // 45 margin bell NYI 3616 // 45 margin bell NYI
4044 // 46 start logging 3617 // 46 start logging
4045 { 47, PrivMode_Screen }, 3618 { 47, PrivMode_Screen },
4046 { 66, PrivMode_aplKP }, 3619 { 66, PrivMode_aplKP }, // DECPAM/DECPNM
4047#ifndef NO_BACKSPACE_KEY 3620#ifndef NO_BACKSPACE_KEY
4048 { 67, PrivMode_BackSpace }, 3621 { 67, PrivMode_BackSpace }, // DECBKM
4049#endif 3622#endif
4050 { 1000, PrivMode_MouseX11 }, 3623 { 1000, PrivMode_MouseX11 },
4051 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3624 { 1002, PrivMode_MouseBtnEvent },
4052 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3625 { 1003, PrivMode_MouseAnyEvent },
4053 // 1003 Use All Motion Mouse Tracking. NYI, TODO
4054 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3626 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
4055 { 1011, PrivMode_Keypress }, // rxvt extension 3627 { 1011, PrivMode_Keypress }, // rxvt extension
4056 // 1035 enable modifiers for alt, numlock NYI 3628 // 1035 enable modifiers for alt, numlock NYI
4057 // 1036 send ESC for meta keys NYI 3629 // 1036 send ESC for meta keys NYI
4058 // 1037 send DEL for keypad delete NYI 3630 // 1037 send DEL for keypad delete NYI
4059 { 1047, PrivMode_Screen }, 3631 { 1047, PrivMode_Screen },
4060 // 1048 save and restore cursor 3632 // 1048 save and restore cursor
4061 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3633 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
4062 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3634 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3635 { 2004, PrivMode_BracketPaste },
4063 }; 3636 };
4064 3637
4065 if (nargs == 0) 3638 if (nargs == 0)
4066 return; 3639 return;
4067 3640
4092 3665
4093 scr_touch (true); 3666 scr_touch (true);
4094 break; 3667 break;
4095#endif 3668#endif
4096 case 1048: /* alternative cursor save */ 3669 case 1048: /* alternative cursor save */
4097 case 1049:
4098 if (OPTION (Opt_secondaryScreen)) 3670 if (option (Opt_secondaryScreen))
4099 if (mode == 0) 3671 if (mode == 0)
4100 scr_cursor (RESTORE); 3672 scr_cursor (RESTORE);
4101 else if (mode == 1) 3673 else if (mode == 1)
4102 scr_cursor (SAVE); 3674 scr_cursor (SAVE);
4103 break; 3675 break;
4111 case 2: /* VT52 mode */ 3683 case 2: /* VT52 mode */
4112 /* oddball mode. should be set regardless of set/reset 3684 /* oddball mode. should be set regardless of set/reset
4113 * parameter. Return from VT52 mode with an ESC < from 3685 * parameter. Return from VT52 mode with an ESC < from
4114 * within VT52 mode 3686 * within VT52 mode
4115 */ 3687 */
4116 PrivMode (1, PrivMode_vt52); 3688 set_privmode (PrivMode_vt52, 1);
4117 break; 3689 break;
4118 case 3: /* 80/132 */ 3690 case 3: /* 80/132 */
4119 if (priv_modes & PrivMode_132OK) 3691 if (priv_modes & PrivMode_132OK)
4120 set_widthheight (((state ? 132 : 80) * fwidth), height); 3692 set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight);
4121 break; 3693 break;
4122 case 4: /* smooth scrolling */ 3694 case 4: /* smooth scrolling */
4123 set_option (Opt_jumpScroll, !state); 3695 set_option (Opt_jumpScroll, !state);
4124 break; 3696 break;
4125 case 5: /* reverse video */ 3697 case 5: /* reverse video */
4132 scr_autowrap (state); 3704 scr_autowrap (state);
4133 break; 3705 break;
4134 /* case 8: - auto repeat, can't do on a per window basis */ 3706 /* case 8: - auto repeat, can't do on a per window basis */
4135 case 9: /* X10 mouse reporting */ 3707 case 9: /* X10 mouse reporting */
4136 if (state) /* orthogonal */ 3708 if (state) /* orthogonal */
4137 priv_modes &= ~PrivMode_MouseX11; 3709 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4138 break; 3710 break;
4139#ifdef scrollBar_esc 3711#ifdef scrollBar_esc
4140 case scrollBar_esc: 3712 case scrollBar_esc:
4141 if (scrollbar_mapping (state)) 3713 if (scrollBar.map (state))
4142 { 3714 {
4143 resize_all_windows (0, 0, 0); 3715 resize_all_windows (0, 0, 0);
4144 scr_touch (true); 3716 scr_touch (true);
4145 } 3717 }
4146 break; 3718 break;
4155 break; 3727 break;
4156 /* case 66: - application key pad */ 3728 /* case 66: - application key pad */
4157 /* case 67: - backspace key */ 3729 /* case 67: - backspace key */
4158 case 1000: /* X11 mouse reporting */ 3730 case 1000: /* X11 mouse reporting */
4159 if (state) /* orthogonal */ 3731 if (state) /* orthogonal */
4160 priv_modes &= ~PrivMode_MouseX10; 3732 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4161 break; 3733 break;
4162#if 0
4163 case 1001: 3734 case 1002:
4164 break; /* X11 mouse highlighting */ 3735 case 1003:
4165#endif 3736 if (state)
3737 {
3738 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3739 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3740 vt_emask_mouse = PointerMotionMask;
3741 }
3742 else
3743 vt_emask_mouse = NoEventMask;
3744
3745 vt_select_input ();
3746 break;
4166 case 1010: /* scroll to bottom on TTY output inhibit */ 3747 case 1010: /* scroll to bottom on TTY output inhibit */
4167 set_option (Opt_scrollTtyOutput, !state); 3748 set_option (Opt_scrollTtyOutput, !state);
4168 break; 3749 break;
4169 case 1011: /* scroll to bottom on key press */ 3750 case 1011: /* scroll to bottom on key press */
4170 set_option (Opt_scrollTtyKeypress, state); 3751 set_option (Opt_scrollTtyKeypress, state);
4171 break; 3752 break;
4172 case 1047: /* secondary screen w/ clearing last */ 3753 case 1047: /* secondary screen w/ clearing last */
4173 if (OPTION (Opt_secondaryScreen)) 3754 if (option (Opt_secondaryScreen))
4174 if (current_screen != PRIMARY) 3755 if (!state)
4175 scr_erase_screen (2); 3756 scr_erase_screen (2);
3757
4176 scr_change_screen (state); 3758 scr_change_screen (state);
4177 break; 3759 break;
4178 case 1049: /* secondary screen w/ clearing first */ 3760 case 1049: /* secondary screen w/ clearing first */
3761 if (option (Opt_secondaryScreen))
3762 if (state)
3763 scr_cursor (SAVE);
3764
4179 scr_change_screen (state); 3765 scr_change_screen (state);
3766
4180 if (OPTION (Opt_secondaryScreen)) 3767 if (option (Opt_secondaryScreen))
4181 if (current_screen != PRIMARY) 3768 if (state)
4182 scr_erase_screen (2); 3769 scr_erase_screen (2);
3770 else
3771 scr_cursor (RESTORE);
4183 break; 3772 break;
4184 default: 3773 default:
4185 break; 3774 break;
4186 } 3775 }
4187 } 3776 }
4347rxvt_term::process_graphics () 3936rxvt_term::process_graphics ()
4348{ 3937{
4349 unicode_t ch, cmd = cmd_getc (); 3938 unicode_t ch, cmd = cmd_getc ();
4350 3939
4351 if (cmd == 'Q') 3940 if (cmd == 'Q')
3941 {
4352 { /* query graphics */ 3942 /* query graphics */
4353 tt_printf ("\033G0\012"); /* no graphics */ 3943 tt_printf ("\033G0\012"); /* no graphics */
4354 return; 3944 return;
4355 } 3945 }
4356 /* swallow other graphics sequences until terminating ':' */ 3946 /* swallow other graphics sequences until terminating ':' */
4357 do 3947 do
4407 v_buffer = (char *)realloc (v_buffer, v_buflen + len); 3997 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4408 3998
4409 memcpy (v_buffer + v_buflen, data, len); 3999 memcpy (v_buffer + v_buflen, data, len);
4410 v_buflen += len; 4000 v_buflen += len;
4411 4001
4412 pty_ev.set (EVENT_READ | EVENT_WRITE); 4002 pty_ev.set (ev::READ | ev::WRITE);
4413} 4003}
4414 4004
4415void rxvt_term::pty_write () 4005void rxvt_term::pty_write ()
4416{ 4006{
4417 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 4007 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4422 4012
4423 if (v_buflen == 0) 4013 if (v_buflen == 0)
4424 { 4014 {
4425 free (v_buffer); 4015 free (v_buffer);
4426 v_buffer = 0; 4016 v_buffer = 0;
4427 v_buflen = 0;
4428 4017
4429 pty_ev.set (EVENT_READ); 4018 pty_ev.set (ev::READ);
4430 return; 4019 return;
4431 } 4020 }
4432 4021
4433 memmove (v_buffer, v_buffer + written, v_buflen); 4022 memmove (v_buffer, v_buffer + written, v_buflen);
4434 } 4023 }
4435 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4024 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4436 pty_ev.set (EVENT_READ); 4025 pty_ev.set (ev::READ);
4437} 4026}
4438 4027
4439/*----------------------- end-of-file (C source) -----------------------*/ 4028/*----------------------- end-of-file (C source) -----------------------*/
4440 4029

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines