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.301 by root, Tue Jan 31 21:23:13 2006 UTC vs.
Revision 1.425 by root, Wed Nov 5 12:28:15 2008 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
492# if ISO_14755 594# if ISO_14755
493 iso14755_51 (0); 595 iso14755_51 (0);
494# endif 596# endif
495 return; 597 return;
496 } 598 }
599 else if (keysym == XK_BackSpace)
600 {
601 iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51;
602# if ISO_14755
603 iso14755_51 (iso14755buf & ISO_14755_MASK);
604# endif
605 return;
606 }
497 else if ((hv = hex_keyval (ev)) >= 0) 607 else if ((hv = hex_keyval (ev)) >= 0)
498 { 608 {
499 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK) 609 iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK)
500 | hv | ISO_14755_51; 610 | hv | ISO_14755_51;
501# if ISO_14755 611# if ISO_14755
503# endif 613# endif
504 return; 614 return;
505 } 615 }
506 else 616 else
507 { 617 {
508# if ENABLE_OVERLAY 618# if ISO_14755
509 scr_overlay_off (); 619 scr_overlay_off ();
510# endif 620# endif
511 iso14755buf = 0; 621 iso14755buf = 0;
512 } 622 }
513 } 623 }
514 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R)) 624 else if ((ctrl && (keysym == XK_Shift_L || keysym == XK_Shift_R))
515 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R))) 625 || (shft && (keysym == XK_Control_L || keysym == XK_Control_R)))
516 if (!(iso14755buf & ISO_14755_STARTED)) 626 if (!(iso14755buf & ISO_14755_STARTED))
517 { 627 {
518 iso14755buf |= ISO_14755_STARTED; 628 iso14755buf |= ISO_14755_STARTED;
519# if ENABLE_OVERLAY 629# if ISO_14755
520 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); 630 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1);
521 scr_overlay_set (0, 0, "ISO 14755 mode"); 631 scr_overlay_set (0, 0, "ISO 14755 mode");
522# endif 632# endif
523 } 633 }
524#endif 634#endif
525 635
526#ifdef PRINTPIPE 636#ifdef PRINTPIPE
527 if (keysym == XK_Print) 637 if (keysym == XK_Print)
528 { 638 {
529 scr_printscreen (ctrl | shft); 639 scr_printscreen (ctrl | shft);
530 return; 640 return;
531 } 641 }
532#endif 642#endif
533 643
534 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 644 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
535 { 645 {
646 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
647 unsigned int newlen = 1;
648
649 switch (translate_keypad (keysym, kp))
536 { 650 {
651#ifndef NO_BACKSPACE_KEY
652 case XK_BackSpace:
653 if (priv_modes & PrivMode_HaveBackSpace)
654 {
655 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
656 ^ !!ctrl) ? '\b' : '\177';
657 kbuf[1] = '\0';
658 }
659 else
660 strcpy (kbuf, rs[Rs_backspace_key]);
661 break;
662#endif
663#ifndef NO_DELETE_KEY
664 case XK_Delete:
665 strcpy (kbuf, rs[Rs_delete_key]);
666 break;
667#endif
668 case XK_Tab:
669 if (shft)
670 strcpy (kbuf, "\033[Z");
671 else
672 {
673#ifdef CTRL_TAB_MAKES_META
674 if (ctrl)
675 meta = 1;
676#endif
677#ifdef MOD4_TAB_MAKES_META
678 if (ev.state & Mod4Mask)
679 meta = 1;
680#endif
537 newlen = 1; 681 newlen = 0;
538 switch (keysym) 682 }
683 break;
684
685 case XK_Up: /* "\033[A" */
686 case XK_Down: /* "\033[B" */
687 case XK_Right: /* "\033[C" */
688 case XK_Left: /* "\033[D" */
689 strcpy (kbuf, "\033[Z");
690 kbuf[2] = "DACB"[keysym - XK_Left];
691 /* do Shift first */
692 if (shft)
693 kbuf[2] = "dacb"[keysym - XK_Left];
694 else if (ctrl)
695 {
696 kbuf[1] = 'O';
697 kbuf[2] = "dacb"[keysym - XK_Left];
698 }
699 else if (priv_modes & PrivMode_aplCUR)
700 kbuf[1] = 'O';
701 break;
702
703 case XK_KP_Enter:
704 /* allow shift to override */
705 if (kp)
706 {
707 strcpy (kbuf, "\033OM");
708 break;
709 }
710
711 /* FALLTHROUGH */
712
713 case XK_Return:
714 if (priv_modes & PrivMode_LFNL)
715 {
716 kbuf[0] = '\015';
717 kbuf[1] = '\012';
718 kbuf[2] = '\0';
719 }
720 else
721 {
722 kbuf[0] = '\015';
723 kbuf[1] = '\0';
724 }
725 break;
726
727 case XK_KP_F1: /* "\033OP" */
728 case XK_KP_F2: /* "\033OQ" */
729 case XK_KP_F3: /* "\033OR" */
730 case XK_KP_F4: /* "\033OS" */
731 strcpy (kbuf, "\033OP");
732 kbuf[2] += (keysym - XK_KP_F1);
733 break;
734
735 case XK_KP_Multiply: /* "\033Oj" : "*" */
736 case XK_KP_Add: /* "\033Ok" : "+" */
737 case XK_KP_Separator: /* "\033Ol" : "," */
738 case XK_KP_Subtract: /* "\033Om" : "-" */
739 case XK_KP_Decimal: /* "\033On" : "." */
740 case XK_KP_Divide: /* "\033Oo" : "/" */
741 case XK_KP_0: /* "\033Op" : "0" */
742 case XK_KP_1: /* "\033Oq" : "1" */
743 case XK_KP_2: /* "\033Or" : "2" */
744 case XK_KP_3: /* "\033Os" : "3" */
745 case XK_KP_4: /* "\033Ot" : "4" */
746 case XK_KP_5: /* "\033Ou" : "5" */
747 case XK_KP_6: /* "\033Ov" : "6" */
748 case XK_KP_7: /* "\033Ow" : "7" */
749 case XK_KP_8: /* "\033Ox" : "8" */
750 case XK_KP_9: /* "\033Oy" : "9" */
751 /* allow shift to override */
752 if (kp)
753 {
754 strcpy (kbuf, "\033Oj");
755 kbuf[2] += (keysym - XK_KP_Multiply);
756 }
757 else
758 {
759 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
760 kbuf[1] = '\0';
761 }
762 break;
763
764 default:
539 { 765 {
540#ifndef NO_BACKSPACE_KEY 766 int param = map_function_key (keysym);
541 case XK_BackSpace: 767 if (param > 0)
542 if (priv_modes & PrivMode_HaveBackSpace) 768 sprintf (kbuf,"\033[%d~", param);
543 {
544 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
545 ^ !!ctrl) ? '\b' : '\177';
546 kbuf[1] = '\0';
547 }
548 else 769 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; 770 newlen = 0;
824 break;
825 } 771 }
826 772 break;
827 if (newlen)
828 len = strlen (kbuf);
829 } 773 }
774
775 if (newlen)
776 len = strlen (kbuf);
830 777
831 /* 778 /*
832 * Pass meta for all function keys, if 'meta' option set 779 * Pass meta for all function keys, if 'meta' option set
833 */ 780 */
834#ifdef META8_OPTION 781#ifdef META8_OPTION
869 return; 816 return;
870 817
871 if (len <= 0) 818 if (len <= 0)
872 return; /* not mapped */ 819 return; /* not mapped */
873 820
874 if (OPTION (Opt_scrollTtyKeypress)) 821 if (option (Opt_scrollTtyKeypress))
875 if (view_start) 822 if (view_start)
876 { 823 {
877 view_start = 0; 824 view_start = 0;
878 want_refresh = 1; 825 want_refresh = 1;
879 } 826 }
903 tt_write (&ch, 1); 850 tt_write (&ch, 1);
904 } 851 }
905 852
906 tt_write (kbuf, (unsigned int)len); 853 tt_write (kbuf, (unsigned int)len);
907} 854}
908/*}}} */ 855
856void
857rxvt_term::key_release (XKeyEvent &ev)
858{
859#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
860 KeySym keysym;
861
862 keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
863#endif
864
865#if ENABLE_FRILLS || ISO_14755
866 // ISO 14755 support
867 if (iso14755buf)
868 if (iso14755buf & ISO_14755_52)
869 {
870# if ISO_14755
871 scr_overlay_off ();
872# endif
873# if ISO_14755
874 // iso14755 part 5.2 handling: release time
875 // first: controls
876 if ((ev.state & ControlMask)
877 && ((keysym >= 0x40 && keysym <= 0x5f)
878 || (keysym >= 0x61 && keysym <= 0x7f)))
879 {
880 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
881 commit_iso14755 ();
882
883 return;
884 }
885
886 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
887 if (i[0] == keysym)
888 {
889 iso14755buf = ISO_14755_51 | i[1];
890 commit_iso14755 ();
891
892 return;
893 }
894
895 scr_bell ();
896# endif
897 iso14755buf = 0;
898
899 return;
900 }
901 else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
902 {
903# if ISO_14755
904 scr_overlay_off ();
905# endif
906 if (iso14755buf & ISO_14755_51)
907 commit_iso14755 ();
908#if ISO_14755
909 else if (option (Opt_iso14755_52) && iso14755buf & ISO_14755_STARTED)
910 {
911 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
912
913 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
914 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
915 }
916# endif
917 else
918 iso14755buf = 0;
919 }
920#endif
921
922 if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
923 return;
924
925#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
926 if (!(ev.state & ControlMask))
927 slip_wheel_ev.stop ();
928 else if (keysym == XK_Control_L || keysym == XK_Control_R)
929 mouse_slip_wheel_speed = 0;
930#endif
931}
909 932
910#if defined (KEYSYM_RESOURCE) 933#if defined (KEYSYM_RESOURCE)
911unsigned int 934unsigned int
912rxvt_term::cmd_write (const char *str, unsigned int count) 935rxvt_term::cmd_write (const char *str, unsigned int count)
913{ 936{
943void 966void
944rxvt_term::flush () 967rxvt_term::flush ()
945{ 968{
946 flush_ev.stop (); 969 flush_ev.stop ();
947 970
948#ifdef TRANSPARENT 971#ifdef HAVE_BG_PIXMAP
949 if (want_full_refresh) 972 if (bgPixmap.check_clearChanged ())
950 { 973 {
951 want_full_refresh = 0; 974// scr_clear (true); This needs to be researched further!
952 scr_clear ();
953 scr_touch (false); 975 scr_touch (false);
954 } 976 }
955#endif 977#endif
956 978
957 if (want_refresh) 979 if (want_refresh)
993 } 1015 }
994 while (row < end_row); 1016 while (row < end_row);
995 } 1017 }
996 1018
997 scr_refresh (); 1019 scr_refresh ();
998 scrollbar_show (1); 1020 scrollBar.show (1);
999#ifdef USE_XIM 1021#ifdef USE_XIM
1000 IMSendSpot (); 1022 IMSendSpot ();
1001#endif 1023#endif
1002 } 1024 }
1003 1025
1004 display->flush (); 1026 display->flush ();
1005} 1027}
1006 1028
1029/* checks wether a refresh is requested and starts the refresh timer */
1007void 1030void
1008rxvt_term::check_cb (check_watcher &w) 1031rxvt_term::refresh_check ()
1032{
1033 if (want_refresh && !flush_ev.is_active ())
1034 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
1035
1036 display->flush ();
1037}
1038
1039void
1040rxvt_term::flush_cb (ev::timer &w, int revents)
1009{ 1041{
1010 make_current (); 1042 make_current ();
1011 1043
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; 1044 refresh_count = 0;
1025 flush (); 1045 flush ();
1026} 1046}
1027 1047
1028#ifdef CURSOR_BLINK 1048#ifdef CURSOR_BLINK
1029void 1049void
1030rxvt_term::cursor_blink_cb (time_watcher &w) 1050rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
1031{ 1051{
1032 hidden_cursor = !hidden_cursor; 1052 hidden_cursor = !hidden_cursor;
1033 want_refresh = 1; 1053 want_refresh = 1;
1034 1054 refresh_check ();
1035 w.start (w.at + CURSOR_BLINK_INTERVAL);
1036} 1055}
1037#endif 1056#endif
1038 1057
1039#ifdef TEXT_BLINK 1058#ifdef TEXT_BLINK
1040void 1059void
1041rxvt_term::text_blink_cb (time_watcher &w) 1060rxvt_term::text_blink_cb (ev::timer &w, int revents)
1042{ 1061{
1043 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1062 if (scr_refresh_rend (RS_Blink, RS_Blink))
1044 { 1063 {
1045 hidden_text = !hidden_text; 1064 hidden_text = !hidden_text;
1046 want_refresh = 1; 1065 want_refresh = 1;
1047 w.start (w.at + TEXT_BLINK_INTERVAL); 1066 refresh_check ();
1048 } 1067 }
1068 else
1069 w.stop ();
1049} 1070}
1050#endif 1071#endif
1051 1072
1052#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1073#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1053void 1074void
1054rxvt_term::cont_scroll_cb (time_watcher &w) 1075rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1055{ 1076{
1056 if ((scrollbar_isUp() || scrollbar_isDn()) && 1077 if ((scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
1057 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1078 && scr_page (scrollBar.state == STATE_UP ? UP : DN, 1))
1058 { 1079 {
1059 want_refresh = 1; 1080 want_refresh = 1;
1060 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1081 refresh_check ();
1061 } 1082 }
1083 else
1084 w.stop ();
1062} 1085}
1063#endif 1086#endif
1064 1087
1065#ifdef SELECTION_SCROLLING 1088#ifdef SELECTION_SCROLLING
1066void 1089void
1067rxvt_term::sel_scroll_cb (time_watcher &w) 1090rxvt_term::sel_scroll_cb (ev::timer &w, int revents)
1068{ 1091{
1069 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1092 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1070 { 1093 {
1071 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1094 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1072 want_refresh = 1; 1095 want_refresh = 1;
1073 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1096 refresh_check ();
1074 } 1097 }
1098 else
1099 w.stop ();
1075} 1100}
1076#endif 1101#endif
1077 1102
1078#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1103#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1079void 1104void
1080rxvt_term::slip_wheel_cb (time_watcher &w) 1105rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1081{ 1106{
1082 if (mouse_slip_wheel_speed == 0 1107 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 { 1108 {
1086 if (view_start == top_row || view_start == 0)
1087 mouse_slip_wheel_speed = 0;
1088
1089 want_refresh = 1; 1109 want_refresh = 1;
1090 w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); 1110 refresh_check ();
1111 }
1112
1113 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1091 } 1114 {
1115 mouse_slip_wheel_speed = 0;
1116 w.stop ();
1117 }
1092} 1118}
1119#endif
1120
1121#if LINUX_YIELD_HACK
1122static struct event_handler
1123{
1124 ev::prepare yield_ev;
1125
1126 void yield_cb (ev::prepare &w, int revents)
1127 {
1128 // this should really be sched_yield(), but the linux guys thought
1129 // that giving a process calling sched_yield () less cpu time than
1130 // ones with high nice levels is a useful thing to do. It surely is is
1131 // allowed by the sus... as is returning ENOSYS.
1132 // since the linux guys additionally thought that breaking the only
1133 // known workaroudn against their unusable sched_yield hack is cool,
1134 // we just nanosleep a bit and hope for the best.
1135
1136 struct timespec ts = { 0, 1000 };
1137 nanosleep (&ts, 0);
1138
1139 w.stop ();
1140 }
1141
1142 event_handler ()
1143 : yield_ev (this, &event_handler::yield_cb)
1144 {
1145 }
1146} event_handler;
1093#endif 1147#endif
1094 1148
1095bool 1149bool
1096rxvt_term::pty_fill () 1150rxvt_term::pty_fill ()
1097{ 1151{
1114 cmdbuf_endp += r; 1168 cmdbuf_endp += r;
1115 return true; 1169 return true;
1116 } 1170 }
1117 else if (r < 0 && (errno == EAGAIN || errno == EINTR)) 1171 else if (r < 0 && (errno == EAGAIN || errno == EINTR))
1118 { 1172 {
1119#if HAVE_SCHED_YIELD 1173#if LINUX_YIELD_HACK
1120 if (display->is_local) 1174 if (display->is_local)
1121 event_handler.cw_yield.start (); 1175 event_handler.yield_ev.start ();
1122#endif 1176#endif
1123 } 1177 }
1124 else 1178 else
1125 { 1179 {
1126 pty_ev.stop (); 1180 pty_ev.stop ();
1127 1181
1128 if (!OPTION (Opt_hold)) 1182 if (!option (Opt_hold))
1129 destroy (); 1183 destroy ();
1130 } 1184 }
1131 1185
1132 return false; 1186 return false;
1133} 1187}
1134 1188
1135void 1189void
1136rxvt_term::pty_cb (io_watcher &w, short revents) 1190rxvt_term::pty_cb (ev::io &w, int revents)
1137{ 1191{
1138 make_current (); 1192 make_current ();
1139 1193
1140 if (revents & EVENT_READ) 1194 if (revents & ev::READ)
1141 // loop, but don't allow a single term to monopolize us 1195 // loop, but don't allow a single term to monopolize us
1142 while (pty_fill ()) 1196 for (int i = CBUFCNT; i-- && pty_fill (); )
1143 if (cmd_parse ()) 1197 cmd_parse ();
1144 break;
1145 1198
1146 if (revents & EVENT_WRITE) 1199 if (revents & ev::WRITE)
1147 pty_write (); 1200 pty_write ();
1201
1202 refresh_check ();
1148} 1203}
1149 1204
1150void 1205void
1151rxvt_term::pointer_unblank () 1206rxvt_term::pointer_unblank ()
1152{ 1207{
1153 XDefineCursor (xdisp, vt, TermWin_cursor); 1208 XDefineCursor (dpy, vt, TermWin_cursor);
1154 recolour_cursor (); 1209 recolour_cursor ();
1155 1210
1156#ifdef POINTER_BLANK 1211#ifdef POINTER_BLANK
1157 hidden_pointer = 0; 1212 hidden_pointer = 0;
1158 1213
1159 if (OPTION (Opt_pointerBlank)) 1214 if (option (Opt_pointerBlank))
1160 pointer_ev.start (NOW + pointerBlankDelay); 1215 pointer_ev.start (pointerBlankDelay);
1161#endif 1216#endif
1162} 1217}
1163 1218
1164#ifdef POINTER_BLANK 1219#ifdef POINTER_BLANK
1165void 1220void
1166rxvt_term::pointer_blank () 1221rxvt_term::pointer_blank ()
1167{ 1222{
1168 if (!OPTION (Opt_pointerBlank)) 1223 if (!option (Opt_pointerBlank))
1169 return; 1224 return;
1170 1225
1171 XDefineCursor (xdisp, vt, display->blank_cursor); 1226 XDefineCursor (dpy, vt, display->blank_cursor);
1172 XFlush (xdisp); 1227 XFlush (dpy);
1173 1228
1174 hidden_pointer = 1; 1229 hidden_pointer = 1;
1175} 1230}
1176 1231
1177void 1232void
1178rxvt_term::pointer_cb (time_watcher &w) 1233rxvt_term::pointer_cb (ev::timer &w, int revents)
1179{ 1234{
1180 make_current (); 1235 make_current ();
1181 1236
1182 pointer_blank (); 1237 pointer_blank ();
1183} 1238}
1186void 1241void
1187rxvt_term::mouse_report (XButtonEvent &ev) 1242rxvt_term::mouse_report (XButtonEvent &ev)
1188{ 1243{
1189 int button_number, key_state = 0; 1244 int button_number, key_state = 0;
1190 int x, y; 1245 int x, y;
1246 int code = 32;
1191 1247
1192 x = ev.x; 1248 x = Pixel2Col (ev.x);
1193 y = ev.y; 1249 y = Pixel2Row (ev.y);
1194 pixel_position (&x, &y); 1250 if (ev.type == MotionNotify)
1251 {
1252 if (x == mouse_row && y == mouse_col)
1253 return;
1254 mouse_row = x;
1255 mouse_col = y;
1256 code += 32;
1257 }
1195 1258
1196 if (MEvent.button == AnyButton) 1259 if (MEvent.button == AnyButton)
1197 button_number = 3; 1260 button_number = 3;
1198 else 1261 else
1199 { 1262 {
1245 x + 1, 1308 x + 1,
1246 y + 1); 1309 y + 1);
1247#endif 1310#endif
1248 1311
1249 tt_printf ("\033[M%c%c%c", 1312 tt_printf ("\033[M%c%c%c",
1250 (32 + button_number + key_state), 1313 (code + button_number + key_state),
1251 (32 + x + 1), 1314 (32 + x + 1),
1252 (32 + y + 1)); 1315 (32 + y + 1));
1253} 1316}
1254 1317
1255/*{{{ process an X event */ 1318/*{{{ process an X event */
1256void 1319void
1257rxvt_term::x_cb (XEvent &ev) 1320rxvt_term::x_cb (XEvent &ev)
1258{ 1321{
1259 make_current (); 1322 make_current ();
1260 1323
1261 dLocal (Display *, xdisp); 1324 dLocal (Display *, dpy);
1262 1325
1263 if (ev.xany.window == vt 1326 if (ev.xany.window == vt
1264 && SHOULD_INVOKE (HOOK_X_EVENT) 1327 && SHOULD_INVOKE (HOOK_X_EVENT)
1265 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END))) 1328 && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END)))
1266 return; 1329 return;
1271 unsigned int unused_mask; 1334 unsigned int unused_mask;
1272 1335
1273 switch (ev.type) 1336 switch (ev.type)
1274 { 1337 {
1275 case KeyPress: 1338 case KeyPress:
1276#if ISO_14755 1339 key_press (ev.xkey);
1277 if (!(iso14755buf & ISO_14755_52))
1278#endif
1279 lookup_key (ev.xkey);
1280
1281 break; 1340 break;
1282 1341
1283 case KeyRelease: 1342 case KeyRelease:
1284 { 1343 key_release (ev.xkey);
1285#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL
1286 KeySym keysym;
1287
1288 keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/
1289#endif
1290
1291#if ENABLE_FRILLS || ISO_14755
1292 // ISO 14755 support
1293 if (iso14755buf)
1294 if (iso14755buf & ISO_14755_52)
1295 {
1296# if ENABLE_OVERLAY
1297 scr_overlay_off ();
1298# endif
1299# if ISO_14755
1300 // iso14755 part 5.2 handling: release time
1301 // first: controls
1302 if ((ev.xkey.state & ControlMask)
1303 && ((keysym >= 0x40 && keysym <= 0x5f)
1304 || (keysym >= 0x61 && keysym <= 0x7f)))
1305 {
1306 iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f);
1307 commit_iso14755 ();
1308 goto skip_switch;
1309 }
1310
1311 for (unsigned short *i = iso14755_symtab; i[0]; i+= 2)
1312 if (i[0] == keysym)
1313 {
1314 iso14755buf = ISO_14755_51 | i[1];
1315 commit_iso14755 ();
1316 goto skip_switch;
1317 }
1318
1319 scr_bell ();
1320# endif
1321 iso14755buf = 0;
1322 break;
1323 }
1324 else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask))
1325 {
1326# if ENABLE_OVERLAY
1327 scr_overlay_off ();
1328# endif
1329 if (iso14755buf & ISO_14755_51)
1330 commit_iso14755 ();
1331#if ISO_14755
1332 else if (iso14755buf & ISO_14755_STARTED)
1333 {
1334 iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair
1335
1336 scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1);
1337 scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE");
1338 }
1339# endif
1340 else
1341 iso14755buf = 0;
1342 }
1343#endif
1344
1345 if (ev.xany.window == vt
1346 && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END)))
1347 break;
1348
1349#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1350 if (!(ev.xkey.state & ControlMask))
1351 slip_wheel_ev.stop ();
1352 else if (keysym == XK_Control_L || keysym == XK_Control_R)
1353 mouse_slip_wheel_speed = 0;
1354#endif
1355 break; 1344 break;
1356 }
1357 1345
1358 case ButtonPress: 1346 case ButtonPress:
1359 button_press (ev.xbutton); 1347 button_press (ev.xbutton);
1360 break; 1348 break;
1361 1349
1376 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END))) 1364 if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END)))
1377 destroy (); 1365 destroy ();
1378 } 1366 }
1379#if ENABLE_EWMH 1367#if ENABLE_EWMH
1380 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) 1368 else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING])
1381 XSendEvent (xdisp, ev.xclient.window = display->root, 1369 XSendEvent (dpy, ev.xclient.window = display->root,
1382 False, SubstructureRedirectMask | SubstructureNotifyMask, 1370 False, SubstructureRedirectMask | SubstructureNotifyMask,
1383 &ev); 1371 &ev);
1384#endif 1372#endif
1385 } 1373 }
1386 } 1374 }
1392 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) 1380 else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT)
1393 focus_out (); 1381 focus_out ();
1394 } 1382 }
1395#endif 1383#endif
1396 } 1384 }
1397 break;
1398
1399 case MappingNotify:
1400 XRefreshKeyboardMapping (&ev.xmapping);
1401 break; 1385 break;
1402 1386
1403 /* 1387 /*
1404 * XXX: this is not the _current_ arrangement 1388 * XXX: this is not the _current_ arrangement
1405 * Here's my conclusion: 1389 * Here's my conclusion:
1424 break; 1408 break;
1425 } 1409 }
1426 break; 1410 break;
1427 1411
1428 case FocusIn: 1412 case FocusIn:
1413 if (ev.xfocus.detail != NotifyInferior
1414 && ev.xfocus.detail != NotifyPointer
1415 && ev.xfocus.mode != NotifyGrab)
1429 focus_in (); 1416 focus_in ();
1430 break; 1417 break;
1431 1418
1432 case FocusOut: 1419 case FocusOut:
1420 if (ev.xfocus.detail != NotifyInferior
1421 && ev.xfocus.detail != NotifyPointer
1422 && ev.xfocus.mode != NotifyGrab)
1433 focus_out (); 1423 focus_out ();
1434 break; 1424 break;
1435 1425
1436 case ConfigureNotify: 1426 case ConfigureNotify:
1427 /*fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1428 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1429 szHint.width, szHint.height);*/
1437 if (ev.xconfigure.window == parent[0]) 1430 if (ev.xconfigure.window == parent[0])
1438 { 1431 {
1439 while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev)) 1432 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1440 ; 1433 ;
1441 1434
1442 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) 1435 if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height)
1443 { 1436 {
1444 seen_resize = 1; 1437 seen_resize = 1;
1445 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); 1438 resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1);
1446 } 1439 }
1440 else
1441 {
1442#ifdef HAVE_BG_PIXMAP
1443 if (bgPixmap.window_position_sensitive ())
1444 {
1445 if (mapped)
1446 update_background ();
1447 else
1448 bgPixmap.invalidate ();
1449 }
1450#endif
1451 }
1447 1452
1448 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); 1453 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1449
1450#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */
1451 if (OPTION (Opt_transparent))
1452 check_our_parents ();
1453#endif
1454 } 1454 }
1455 break; 1455 break;
1456 1456
1457 case PropertyNotify: 1457 case PropertyNotify:
1458 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) 1458 if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)))
1474 case SelectionRequest: 1474 case SelectionRequest:
1475 selection_send (ev.xselectionrequest); 1475 selection_send (ev.xselectionrequest);
1476 break; 1476 break;
1477 1477
1478 case MapNotify: 1478 case MapNotify:
1479#ifdef HAVE_BG_PIXMAP
1480 /* This is needed spcifically to fix the case of no window manager or a
1481 * non-reparenting window manager. In those cases we never get first
1482 * ConfigureNotify. Also that speeds startup under normal WM, by taking
1483 * care of multiplicity of ConfigureNotify events arriwing while WM does
1484 * reparenting.
1485 * We should not render background immidiately, as there could be several
1486 * ConfigureNotify's to follow. Lets take care of all of them in one scoop
1487 * by scheduling background redraw as soon as we can, but giving a short
1488 * bit of time for ConfigureNotifies to arrive.
1489 * We should render background PRIOR to drawing any text, but AFTER all
1490 * of ConfigureNotifys for the best results.
1491 */
1492 if (bgPixmap.flags & bgPixmap_t::isInvalid)
1493 update_background_ev.start (0.025);
1494#endif
1479 mapped = 1; 1495 mapped = 1;
1480#ifdef TEXT_BLINK 1496#ifdef TEXT_BLINK
1481 text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); 1497 text_blink_ev.start ();
1482#endif 1498#endif
1483 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1499 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1484 break; 1500 break;
1485 1501
1486 case UnmapNotify: 1502 case UnmapNotify:
1488#ifdef TEXT_BLINK 1504#ifdef TEXT_BLINK
1489 text_blink_ev.stop (); 1505 text_blink_ev.stop ();
1490#endif 1506#endif
1491 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1507 HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1492 break; 1508 break;
1493
1494#ifdef TRANSPARENT
1495 case ReparentNotify:
1496 rootwin_cb (ev);
1497 break;
1498#endif /* TRANSPARENT */
1499 1509
1500 case GraphicsExpose: 1510 case GraphicsExpose:
1501 case Expose: 1511 case Expose:
1502 if (ev.xany.window == vt) 1512 if (ev.xany.window == vt)
1503 { 1513 {
1504 do 1514 do
1515 {
1505 scr_expose (ev.xexpose.x, ev.xexpose.y, 1516 scr_expose (ev.xexpose.x, ev.xexpose.y,
1506 ev.xexpose.width, ev.xexpose.height, False); 1517 ev.xexpose.width, ev.xexpose.height, False);
1518 }
1507 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)); 1519 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev));
1508 1520
1509 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; 1521 ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose;
1510 1522
1511 while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)) 1523 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1524 {
1512 scr_expose (ev.xexpose.x, ev.xexpose.y, 1525 scr_expose (ev.xexpose.x, ev.xexpose.y,
1513 ev.xexpose.width, ev.xexpose.height, False); 1526 ev.xexpose.width, ev.xexpose.height, False);
1527 }
1514 1528
1515 want_refresh = 1; 1529 want_refresh = 1;
1516 } 1530 }
1517 else 1531 else
1518 { 1532 {
1519 XEvent unused_event; 1533 XEvent unused_event;
1520 1534
1521 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event)) 1535 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1522 ; 1536 ;
1523 while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event)) 1537 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1524 ; 1538 ;
1525 1539
1526 if (isScrollbarWindow (ev.xany.window)) 1540 if (scrollBar.state && ev.xany.window == scrollBar.win)
1527 { 1541 {
1528 scrollBar.setIdle (); 1542 scrollBar.state = STATE_IDLE;
1529 scrollbar_show (0); 1543 scrollBar.show (0);
1530 } 1544 }
1531
1532#ifdef TRANSPARENT
1533 if (am_transparent && ev.xany.window == parent[0])
1534 XClearWindow (xdisp, ev.xany.window);
1535#endif
1536 } 1545 }
1537 break; 1546 break;
1538 1547
1539 case MotionNotify: 1548 case MotionNotify:
1540#ifdef POINTER_BLANK 1549#ifdef POINTER_BLANK
1541 if (hidden_pointer) 1550 if (hidden_pointer)
1542 pointer_unblank (); 1551 pointer_unblank ();
1543#endif 1552#endif
1553 if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask))
1554 || priv_modes & PrivMode_MouseAnyEvent)
1555 mouse_report (ev.xbutton);
1544 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) 1556 if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate)
1545 break; 1557 break;
1546 1558
1547 if (ev.xany.window == vt) 1559 if (ev.xany.window == vt)
1548 { 1560 {
1549 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY) 1561 if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY)
1550 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) 1562 && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END)))
1551 ; // nop 1563 ; // nop
1552 else if (ev.xbutton.state & (Button1Mask | Button3Mask)) 1564 else if (ev.xbutton.state & (Button1Mask | Button3Mask))
1553 { 1565 {
1554 while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev)) 1566 while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev))
1555 ; 1567 ;
1556 1568
1557 XQueryPointer (xdisp, vt, 1569 XQueryPointer (dpy, vt,
1558 &unused_root, &unused_child, 1570 &unused_root, &unused_child,
1559 &unused_root_x, &unused_root_y, 1571 &unused_root_x, &unused_root_y,
1560 &ev.xbutton.x, &ev.xbutton.y, 1572 &ev.xbutton.x, &ev.xbutton.y,
1561 &ev.xbutton.state); 1573 &ev.xbutton.state);
1562#ifdef MOUSE_THRESHOLD 1574#ifdef MOUSE_THRESHOLD
1582 int dist; 1594 int dist;
1583 1595
1584 /* don't clobber the current delay if we are 1596 /* don't clobber the current delay if we are
1585 * already in the middle of scrolling. 1597 * already in the middle of scrolling.
1586 */ 1598 */
1587 if (!sel_scroll_ev.active) 1599 if (!sel_scroll_ev.is_active ())
1588 sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1600 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1589 1601
1590 /* save the event params so we can highlight 1602 /* save the event params so we can highlight
1591 * the selection in the pending-scroll loop 1603 * the selection in the pending-scroll loop
1592 */ 1604 */
1593 selection_save_x = ev.xbutton.x; 1605 selection_save_x = ev.xbutton.x;
1615 else 1627 else
1616 { 1628 {
1617 /* we are within the text window, so we 1629 /* we are within the text window, so we
1618 * shouldn't be scrolling 1630 * shouldn't be scrolling
1619 */ 1631 */
1620 if (sel_scroll_ev.active)
1621 sel_scroll_ev.stop(); 1632 sel_scroll_ev.stop();
1622 } 1633 }
1623#endif 1634#endif
1624#ifdef MOUSE_THRESHOLD 1635#ifdef MOUSE_THRESHOLD
1625 } 1636 }
1626#endif 1637#endif
1627 } 1638 }
1628 } 1639 }
1629 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1640 else if (scrollBar.state == STATE_MOTION && ev.xany.window == scrollBar.win)
1630 { 1641 {
1631 while (XCheckTypedWindowEvent (xdisp, scrollBar.win, 1642 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1632 MotionNotify, &ev)) 1643 MotionNotify, &ev))
1633 ; 1644 ;
1634 1645
1635 XQueryPointer (xdisp, scrollBar.win, 1646 XQueryPointer (dpy, scrollBar.win,
1636 &unused_root, &unused_child, 1647 &unused_root, &unused_child,
1637 &unused_root_x, &unused_root_y, 1648 &unused_root_x, &unused_root_y,
1638 &ev.xbutton.x, &ev.xbutton.y, 1649 &ev.xbutton.x, &ev.xbutton.y,
1639 &unused_mask); 1650 &unused_mask);
1640 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1651 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1641 scrollbar_size ()); 1652 scrollBar.size ());
1642 want_refresh = 1; 1653 want_refresh = 1;
1643 refresh_limit = 0;
1644 scrollbar_show (1); 1654 scrollBar.show (1);
1645 } 1655 }
1646 break; 1656 break;
1647 } 1657 }
1648 1658
1649skip_switch: ;
1650
1651#if defined(CURSOR_BLINK) 1659#if defined(CURSOR_BLINK)
1652 if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) 1660 if (option (Opt_cursorBlink) && ev.type == KeyPress)
1653 { 1661 {
1654 if (hidden_cursor) 1662 if (hidden_cursor)
1655 { 1663 {
1656 hidden_cursor = 0; 1664 hidden_cursor = 0;
1657 want_refresh = 1; 1665 want_refresh = 1;
1658 } 1666 }
1659 1667
1660 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); 1668 cursor_blink_ev.again ();
1661 } 1669 }
1662#endif 1670#endif
1663 1671
1664#if defined(POINTER_BLANK) 1672#if defined(POINTER_BLANK)
1665 if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) 1673 if (option (Opt_pointerBlank) && pointerBlankDelay > 0)
1666 { 1674 {
1667 if (ev.type == MotionNotify 1675 if (ev.type == MotionNotify
1668 || ev.type == ButtonPress 1676 || ev.type == ButtonPress
1669 || ev.type == ButtonRelease) 1677 || ev.type == ButtonRelease)
1670 if (hidden_pointer) 1678 if (hidden_pointer)
1672 1680
1673 if (ev.type == KeyPress && hidden_pointer == 0) 1681 if (ev.type == KeyPress && hidden_pointer == 0)
1674 pointer_blank (); 1682 pointer_blank ();
1675 } 1683 }
1676#endif 1684#endif
1685
1686 refresh_check ();
1687}
1688
1689void
1690rxvt_term::set_urgency (bool enable)
1691{
1692 if (enable == urgency_hint)
1693 return;
1694
1695 if (XWMHints *h = XGetWMHints (dpy, parent[0]))
1696 {
1697 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1698 XSetWMHints (dpy, parent[0], h);
1699 urgency_hint = enable;
1700 }
1677} 1701}
1678 1702
1679void 1703void
1680rxvt_term::focus_in () 1704rxvt_term::focus_in ()
1681{ 1705{
1682 if (!focus) 1706 if (!focus)
1683 { 1707 {
1684 focus = 1; 1708 focus = 1;
1685 want_refresh = 1; 1709 want_refresh = 1;
1686 1710
1687 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1688
1689#if USE_XIM 1711#if USE_XIM
1690 if (Input_Context != NULL) 1712 if (Input_Context != NULL)
1691 { 1713 {
1692 IMSetStatusPosition (); 1714 IMSetPosition ();
1693 XSetICFocus (Input_Context); 1715 XSetICFocus (Input_Context);
1694 } 1716 }
1695#endif 1717#endif
1696#if CURSOR_BLINK 1718#if CURSOR_BLINK
1697 if (OPTION (Opt_cursorBlink)) 1719 if (option (Opt_cursorBlink))
1698 cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); 1720 cursor_blink_ev.again ();
1699#endif 1721#endif
1700#if OFF_FOCUS_FADING 1722#if OFF_FOCUS_FADING
1701 if (rs[Rs_fade]) 1723 if (rs[Rs_fade])
1702 { 1724 {
1703 pix_colors = pix_colors_focused; 1725 pix_colors = pix_colors_focused;
1704 scr_recolour (); 1726 scr_recolour ();
1705 } 1727 }
1706#endif 1728#endif
1729#if ENABLE_FRILLS
1730 if (option (Opt_urgentOnBell))
1731 set_urgency (0);
1732#endif
1733
1734 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1707 } 1735 }
1708} 1736}
1709 1737
1710void 1738void
1711rxvt_term::focus_out () 1739rxvt_term::focus_out ()
1713 if (focus) 1741 if (focus)
1714 { 1742 {
1715 focus = 0; 1743 focus = 0;
1716 want_refresh = 1; 1744 want_refresh = 1;
1717 1745
1718 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); 1746#if ENABLE_FRILLS
1719 1747 if (option (Opt_urgentOnBell))
1748 set_urgency (0);
1749#endif
1720#if ENABLE_FRILLS || ISO_14755 1750#if ENABLE_FRILLS || ISO_14755
1721 if (iso14755buf) 1751 if (iso14755buf)
1722 { 1752 {
1723 iso14755buf = 0; 1753 iso14755buf = 0;
1724# if ENABLE_OVERLAY 1754# if ISO_14755
1725 scr_overlay_off (); 1755 scr_overlay_off ();
1726# endif 1756# endif
1727 } 1757 }
1728#endif 1758#endif
1729#if USE_XIM 1759#if USE_XIM
1730 if (Input_Context != NULL) 1760 if (Input_Context != NULL)
1731 XUnsetICFocus (Input_Context); 1761 XUnsetICFocus (Input_Context);
1732#endif 1762#endif
1733#if CURSOR_BLINK 1763#if CURSOR_BLINK
1734 if (OPTION (Opt_cursorBlink)) 1764 if (option (Opt_cursorBlink))
1735 cursor_blink_ev.stop (); 1765 cursor_blink_ev.stop ();
1766
1736 hidden_cursor = 0; 1767 hidden_cursor = 0;
1737#endif 1768#endif
1738#if OFF_FOCUS_FADING 1769#if OFF_FOCUS_FADING
1739 if (rs[Rs_fade]) 1770 if (rs[Rs_fade])
1740 { 1771 {
1741 pix_colors = pix_colors_unfocused; 1772 pix_colors = pix_colors_unfocused;
1742 scr_recolour (); 1773 scr_recolour ();
1743 } 1774 }
1744#endif 1775#endif
1776
1777 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1778 }
1779}
1780
1781void
1782rxvt_term::update_fade_color (unsigned int idx)
1783{
1784#if OFF_FOCUS_FADING
1785 if (rs[Rs_fade])
1745 } 1786 {
1787 rgba c;
1788 pix_colors [Color_fade].get (c);
1789 pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
1790 }
1791#endif
1746} 1792}
1747 1793
1748#if TRANSPARENT 1794#if ENABLE_TRANSPARENCY || ENABLE_PERL
1749void 1795void
1750rxvt_term::rootwin_cb (XEvent &ev) 1796rxvt_term::rootwin_cb (XEvent &ev)
1751{ 1797{
1752 make_current (); 1798 make_current ();
1753 1799
1800 if (SHOULD_INVOKE (HOOK_ROOT_EVENT)
1801 && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END)))
1802 return;
1803
1804# if ENABLE_TRANSPARENCY
1754 switch (ev.type) 1805 switch (ev.type)
1755 { 1806 {
1756 case PropertyNotify: 1807 case PropertyNotify:
1757 /* 1808 /*
1758 * if user used some Esetroot compatible prog to set the root bg, 1809 * if user used some Esetroot compatible prog to set the root bg,
1759 * use the property to determine the pixmap. We use it later on. 1810 * use the property to determine the pixmap. We use it later on.
1760 */ 1811 */
1761 if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] 1812 if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID]
1762 && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) 1813 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1763 return; 1814 {
1815 bgPixmap.set_root_pixmap ();
1816 update_background ();
1817 }
1764 1818
1765 /* FALLTHROUGH */
1766 case ReparentNotify:
1767 if (OPTION (Opt_transparent) && check_our_parents () && am_transparent)
1768 want_refresh = want_full_refresh = 1;
1769 break; 1819 break;
1770 } 1820 }
1821# endif
1822
1823 refresh_check ();
1771} 1824}
1772#endif 1825#endif
1773 1826
1774void 1827void
1775rxvt_term::button_press (XButtonEvent &ev) 1828rxvt_term::button_press (XButtonEvent &ev)
1830 mouse_report (ev); 1883 mouse_report (ev);
1831 } 1884 }
1832#else 1885#else
1833 MEvent.button = ev.button; 1886 MEvent.button = ev.button;
1834 mouse_report (ev); 1887 mouse_report (ev);
1835#endif /* MOUSE_REPORT_DOUBLECLICK */ 1888#endif /* MOUSE_REPORT_DOUBLECLICK */
1836 1889
1837 } 1890 }
1838 else 1891 else
1839 { 1892 {
1840 if (ev.button != MEvent.button) 1893 if (ev.button != MEvent.button)
1888 } 1941 }
1889 1942
1890 /* 1943 /*
1891 * Scrollbar window processing of button press 1944 * Scrollbar window processing of button press
1892 */ 1945 */
1893 if (isScrollbarWindow (ev.window)) 1946 if (scrollBar.state && ev.window == scrollBar.win)
1894 { 1947 {
1895 scrollBar.setIdle (); 1948 page_dirn direction = NO_DIR;
1949
1950 if (scrollBar.upButton (ev.y))
1951 direction = UP; /* up */
1952 else if (scrollBar.dnButton (ev.y))
1953 direction = DN; /* down */
1954
1955 scrollBar.state = STATE_IDLE;
1896 /* 1956 /*
1897 * Rxvt-style scrollbar: 1957 * Rxvt-style scrollbar:
1898 * move up if mouse is above slider 1958 * move up if mouse is above slider
1899 * move dn if mouse is below slider 1959 * move dn if mouse is below slider
1900 * 1960 *
1909 /* 1969 /*
1910 * Mouse report disabled scrollbar: 1970 * Mouse report disabled scrollbar:
1911 * arrow buttons - send up/down 1971 * arrow buttons - send up/down
1912 * click on scrollbar - send pageup/down 1972 * click on scrollbar - send pageup/down
1913 */ 1973 */
1914 if ((scrollBar.style == R_SB_NEXT 1974 if (direction == UP)
1915 && scrollbarnext_upButton (ev.y))
1916 || (scrollBar.style == R_SB_RXVT
1917 && scrollbarrxvt_upButton (ev.y)))
1918 tt_printf ("\033[A"); 1975 tt_printf ("\033[A");
1919 else if ((scrollBar.style == R_SB_NEXT 1976 else if (direction == DN)
1920 && scrollbarnext_dnButton (ev.y))
1921 || (scrollBar.style == R_SB_RXVT
1922 && scrollbarrxvt_dnButton (ev.y)))
1923 tt_printf ("\033[B"); 1977 tt_printf ("\033[B");
1924 else 1978 else
1925 switch (ev.button) 1979 switch (ev.button)
1926 { 1980 {
1927 case Button2: 1981 case Button2:
1934 tt_printf ("\033[5~"); 1988 tt_printf ("\033[5~");
1935 break; 1989 break;
1936 } 1990 }
1937 } 1991 }
1938 else 1992 else
1939#endif /* NO_SCROLLBAR_REPORT */ 1993#endif /* NO_SCROLLBAR_REPORT */
1940
1941 {
1942 char upordown = 0;
1943
1944 if (scrollBar.style == R_SB_NEXT)
1945 { 1994 {
1946 if (scrollbarnext_upButton (ev.y)) 1995 if (direction != NO_DIR)
1947 upordown = -1; /* up */
1948 else if (scrollbarnext_dnButton (ev.y))
1949 upordown = 1; /* down */
1950 }
1951 else if (scrollBar.style == R_SB_RXVT)
1952 {
1953 if (scrollbarrxvt_upButton (ev.y))
1954 upordown = -1; /* up */
1955 else if (scrollbarrxvt_dnButton (ev.y))
1956 upordown = 1; /* down */
1957 }
1958 if (upordown)
1959 { 1996 {
1960#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1997#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1998 if (!cont_scroll_ev.is_active ())
1961 cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); 1999 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1962#endif 2000#endif
1963 if (scr_page (upordown < 0 ? UP : DN, 1)) 2001 if (scr_page (direction, 1))
1964 { 2002 {
1965 if (upordown < 0) 2003 if (direction == UP)
1966 scrollBar.setUp (); 2004 scrollBar.state = STATE_UP;
1967 else 2005 else
1968 scrollBar.setDn (); 2006 scrollBar.state = STATE_DOWN;
1969 } 2007 }
1970 } 2008 }
1971 else 2009 else
1972 switch (ev.button) 2010 switch (ev.button)
1973 { 2011 {
1974 case Button2: 2012 case Button2:
1975 switch (scrollbar_align) 2013 switch (scrollBar.align)
1976 { 2014 {
1977 case R_SB_ALIGN_TOP: 2015 case R_SB_ALIGN_TOP:
1978 csrO = 0; 2016 csrO = 0;
1979 break; 2017 break;
1980 case R_SB_ALIGN_CENTRE: 2018 case R_SB_ALIGN_CENTRE:
1986 } 2024 }
1987 2025
1988 if (scrollBar.style == R_SB_XTERM 2026 if (scrollBar.style == R_SB_XTERM
1989 || scrollbar_above_slider (ev.y) 2027 || scrollbar_above_slider (ev.y)
1990 || scrollbar_below_slider (ev.y)) 2028 || scrollbar_below_slider (ev.y))
1991 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); 2029 scr_move_to (scrollbar_position (ev.y) - csrO, scrollBar.size ());
1992 2030
1993 scrollBar.setMotion (); 2031 scrollBar.state = STATE_MOTION;
1994 break; 2032 break;
1995 2033
1996 case Button1: 2034 case Button1:
1997 if (scrollbar_align == R_SB_ALIGN_CENTRE) 2035 if (scrollBar.align == R_SB_ALIGN_CENTRE)
1998 csrO = ev.y - scrollBar.top; 2036 csrO = ev.y - scrollBar.top;
1999 /* FALLTHROUGH */ 2037 /* FALLTHROUGH */
2000 2038
2001 case Button3: 2039 case Button3:
2002 if (scrollBar.style != R_SB_XTERM) 2040 if (scrollBar.style != R_SB_XTERM)
2012 scr_page (DN, nrow - 1); 2050 scr_page (DN, nrow - 1);
2013# else 2051# else
2014 scr_page (DN, nrow / 4); 2052 scr_page (DN, nrow / 4);
2015# endif 2053# endif
2016 else 2054 else
2017 scrollBar.setMotion (); 2055 scrollBar.state = STATE_MOTION;
2018 } 2056 }
2019 else 2057 else
2020 { 2058 {
2021 scr_page ((ev.button == Button1 ? DN : UP), 2059 scr_page ((ev.button == Button1 ? DN : UP),
2022 (nrow 2060 (nrow
2023 * scrollbar_position (ev.y) 2061 * scrollbar_position (ev.y)
2024 / scrollbar_size ())); 2062 / scrollBar.size ()));
2025 } 2063 }
2026 2064
2027 break; 2065 break;
2028 } 2066 }
2029 } 2067 }
2039 2077
2040 csrO = 0; /* reset csr Offset */ 2078 csrO = 0; /* reset csr Offset */
2041 if (!bypass_keystate) 2079 if (!bypass_keystate)
2042 reportmode = !! (priv_modes & PrivMode_mouse_report); 2080 reportmode = !! (priv_modes & PrivMode_mouse_report);
2043 2081
2044 if (scrollbar_isUpDn ()) 2082 if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
2045 { 2083 {
2046 scrollBar.setIdle (); 2084 scrollBar.state = STATE_IDLE;
2047 scrollbar_show (0); 2085 scrollBar.show (0);
2048 } 2086 }
2049 2087
2050#ifdef SELECTION_SCROLLING 2088#ifdef SELECTION_SCROLLING
2051 if (sel_scroll_ev.active)
2052 sel_scroll_ev.stop(); 2089 sel_scroll_ev.stop();
2053#endif 2090#endif
2054 2091
2055 if (ev.window == vt) 2092 if (ev.window == vt)
2056 { 2093 {
2057 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) 2094 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2081 mouse_report (ev); 2118 mouse_report (ev);
2082 } 2119 }
2083#else /* MOUSE_REPORT_DOUBLECLICK */ 2120#else /* MOUSE_REPORT_DOUBLECLICK */
2084 MEvent.button = AnyButton; 2121 MEvent.button = AnyButton;
2085 mouse_report (ev); 2122 mouse_report (ev);
2086#endif /* MOUSE_REPORT_DOUBLECLICK */ 2123#endif /* MOUSE_REPORT_DOUBLECLICK */
2087 return; 2124 return;
2088 } 2125 }
2089 2126
2090 /* 2127 /*
2091 * dumb hack to compensate for the failure of click-and-drag 2128 * dumb hack to compensate for the failure of click-and-drag
2103 selection_make (ev.time); 2140 selection_make (ev.time);
2104 break; 2141 break;
2105 2142
2106 case Button2: 2143 case Button2:
2107 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? 2144 if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window?
2108 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary); 2145 selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary);
2109 break; 2146 break;
2110 2147
2111#ifdef MOUSE_WHEEL 2148#ifdef MOUSE_WHEEL
2112 case Button4: 2149 case Button4:
2113 case Button5: 2150 case Button5:
2117 2154
2118 v = ev.button == Button4 ? UP : DN; 2155 v = ev.button == Button4 ? UP : DN;
2119 2156
2120 if (ev.state & ShiftMask) 2157 if (ev.state & ShiftMask)
2121 i = 1; 2158 i = 1;
2122 else if (OPTION (Opt_mouseWheelScrollPage)) 2159 else if (option (Opt_mouseWheelScrollPage))
2123 i = nrow - 1; 2160 i = nrow - 1;
2124 else 2161 else
2125 i = 5; 2162 i = 5;
2126 2163
2127# ifdef MOUSE_SLIP_WHEELING 2164# ifdef MOUSE_SLIP_WHEELING
2129 { 2166 {
2130 mouse_slip_wheel_speed += v ? -1 : 1; 2167 mouse_slip_wheel_speed += v ? -1 : 1;
2131 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; 2168 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2132 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; 2169 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2133 2170
2134 if (slip_wheel_ev.at < NOW) 2171 if (!slip_wheel_ev.is_active ())
2135 slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; 2172 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2136
2137 slip_wheel_ev.start ();
2138 } 2173 }
2139 else 2174 else
2175# endif
2140 { 2176 {
2141# endif
2142 scr_page (v, i); 2177 scr_page (v, i);
2143 scrollbar_show (1); 2178 scrollBar.show (1);
2144# ifdef MOUSE_SLIP_WHEELING
2145 } 2179 }
2146# endif
2147 } 2180 }
2148 break; 2181 break;
2149#endif 2182#endif
2150 } 2183 }
2151 } 2184 }
2152} 2185}
2153 2186
2154#ifdef TRANSPARENT
2155#if TINTING
2156/* taken from aterm-0.4.2 */
2157
2158typedef uint32_t RUINT32T;
2159
2160void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
2161{
2162 int sh_r, sh_g, sh_b;
2163 RUINT32T mask_r, mask_g, mask_b;
2164 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
2165 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
2166 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
2167 int i;
2168
2169 Visual *visual = term->visual;
2170
2171 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
2172
2173 /* for convenience */
2174 mask_r = visual->red_mask;
2175 mask_g = visual->green_mask;
2176 mask_b = visual->blue_mask;
2177
2178 /* boring lookup table pre-initialization */
2179 switch (srcImage->bits_per_pixel) {
2180 case 15:
2181 if ((mask_r != 0x7c00) ||
2182 (mask_g != 0x03e0) ||
2183 (mask_b != 0x001f))
2184 return;
2185 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
2186 lookup_r = lookup;
2187 lookup_g = lookup+32;
2188 lookup_b = lookup+32+32;
2189 sh_r = 10;
2190 sh_g = 5;
2191 sh_b = 0;
2192 break;
2193 case 16:
2194 if ((mask_r != 0xf800) ||
2195 (mask_g != 0x07e0) ||
2196 (mask_b != 0x001f))
2197 return;
2198 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
2199 lookup_r = lookup;
2200 lookup_g = lookup+32;
2201 lookup_b = lookup+32+64;
2202 sh_r = 11;
2203 sh_g = 5;
2204 sh_b = 0;
2205 break;
2206 case 24:
2207 if ((mask_r != 0xff0000) ||
2208 (mask_g != 0x00ff00) ||
2209 (mask_b != 0x0000ff))
2210 return;
2211 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2212 lookup_r = lookup;
2213 lookup_g = lookup+256;
2214 lookup_b = lookup+256+256;
2215 sh_r = 16;
2216 sh_g = 8;
2217 sh_b = 0;
2218 break;
2219 case 32:
2220 if ((mask_r != 0xff0000) ||
2221 (mask_g != 0x00ff00) ||
2222 (mask_b != 0x0000ff))
2223 return;
2224 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
2225 lookup_r = lookup;
2226 lookup_g = lookup+256;
2227 lookup_b = lookup+256+256;
2228 sh_r = 16;
2229 sh_g = 8;
2230 sh_b = 0;
2231 break;
2232 default:
2233 return; /* we do not support this color depth */
2234 }
2235
2236 /* prepare limits for color transformation (each channel is handled separately) */
2237 if (shade < 0) {
2238 shade = -shade;
2239 if (shade < 0) shade = 0;
2240 if (shade > 100) shade = 100;
2241
2242 lower_lim_r = 65535-rm;
2243 lower_lim_g = 65535-gm;
2244 lower_lim_b = 65535-bm;
2245
2246 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
2247 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
2248 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
2249
2250 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
2251 } else {
2252 if (shade < 0) shade = 0;
2253 if (shade > 100) shade = 100;
2254
2255 lower_lim_r = lower_lim_g = lower_lim_b = 0;
2256
2257 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
2258 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
2259 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
2260 }
2261
2262 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
2263 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
2264 {
2265 unsigned int tmp;
2266
2267 tmp = lower_lim_r;
2268 lower_lim_r = lower_lim_b;
2269 lower_lim_b = tmp;
2270
2271 tmp = upper_lim_r;
2272 upper_lim_r = upper_lim_b;
2273 upper_lim_b = tmp;
2274 }
2275
2276 /* fill our lookup tables */
2277 for (i = 0; i <= mask_r>>sh_r; i++)
2278 {
2279 RUINT32T tmp;
2280 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
2281 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
2282 lookup_r[i] = (tmp/65535)<<sh_r;
2283 }
2284 for (i = 0; i <= mask_g>>sh_g; i++)
2285 {
2286 RUINT32T tmp;
2287 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
2288 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
2289 lookup_g[i] = (tmp/65535)<<sh_g;
2290 }
2291 for (i = 0; i <= mask_b>>sh_b; i++)
2292 {
2293 RUINT32T tmp;
2294 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
2295 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
2296 lookup_b[i] = (tmp/65535)<<sh_b;
2297 }
2298
2299 /* apply table to input image (replacing colors by newly calculated ones) */
2300 switch (srcImage->bits_per_pixel)
2301 {
2302 case 15:
2303 {
2304 unsigned short *p1, *pf, *p, *pl;
2305 p1 = (unsigned short *) srcImage->data;
2306 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2307 while (p1 < pf)
2308 {
2309 p = p1;
2310 pl = p1 + srcImage->width;
2311 for (; p < pl; p++)
2312 {
2313 *p = lookup_r[(*p & 0x7c00)>>10] |
2314 lookup_g[(*p & 0x03e0)>> 5] |
2315 lookup_b[(*p & 0x001f)];
2316 }
2317 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2318 }
2319 break;
2320 }
2321 case 16:
2322 {
2323 unsigned short *p1, *pf, *p, *pl;
2324 p1 = (unsigned short *) srcImage->data;
2325 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2326 while (p1 < pf)
2327 {
2328 p = p1;
2329 pl = p1 + srcImage->width;
2330 for (; p < pl; p++)
2331 {
2332 *p = lookup_r[(*p & 0xf800)>>11] |
2333 lookup_g[(*p & 0x07e0)>> 5] |
2334 lookup_b[(*p & 0x001f)];
2335 }
2336 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
2337 }
2338 break;
2339 }
2340 case 24:
2341 {
2342 unsigned char *p1, *pf, *p, *pl;
2343 p1 = (unsigned char *) srcImage->data;
2344 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2345 while (p1 < pf)
2346 {
2347 p = p1;
2348 pl = p1 + srcImage->width * 3;
2349 for (; p < pl; p += 3)
2350 {
2351 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
2352 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
2353 p[2] = lookup_r[(p[2] & 0x0000ff)];
2354 }
2355 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
2356 }
2357 break;
2358 }
2359 case 32:
2360 {
2361 RUINT32T *p1, *pf, *p, *pl;
2362 p1 = (RUINT32T *) srcImage->data;
2363 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
2364
2365 while (p1 < pf)
2366 {
2367 p = p1;
2368 pl = p1 + srcImage->width;
2369 for (; p < pl; p++)
2370 {
2371 *p = lookup_r[(*p & 0xff0000)>>16] |
2372 lookup_g[(*p & 0x00ff00)>> 8] |
2373 lookup_b[(*p & 0x0000ff)] |
2374 (*p & ~0xffffff);
2375 }
2376 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
2377 }
2378 break;
2379 }
2380 }
2381
2382 free (lookup);
2383}
2384#endif
2385
2386/*
2387 * Check our parents are still who we think they are.
2388 * Do transparency updates if required
2389 */
2390int
2391rxvt_term::check_our_parents ()
2392{
2393 int i, pchanged, aformat, have_pixmap, rootdepth;
2394 unsigned long nitems, bytes_after;
2395 Atom atype;
2396 unsigned char *prop = NULL;
2397 Window root, oldp, *list;
2398 Pixmap rootpixmap = None;
2399 XWindowAttributes wattr, wrootattr;
2400
2401 pchanged = 0;
2402
2403 if (!OPTION (Opt_transparent))
2404 return pchanged; /* Don't try any more */
2405
2406 XGetWindowAttributes (xdisp, display->root, &wrootattr);
2407 rootdepth = wrootattr.depth;
2408
2409 XGetWindowAttributes (xdisp, parent[0], &wattr);
2410
2411 if (rootdepth != wattr.depth)
2412 {
2413 if (am_transparent)
2414 {
2415 pchanged = 1;
2416 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2417 am_transparent = am_pixmap_trans = 0;
2418 }
2419
2420 return pchanged; /* Don't try any more */
2421 }
2422
2423 /* Get all X ops out of the queue so that our information is up-to-date. */
2424 XSync (xdisp, False);
2425
2426 /*
2427 * Make the frame window set by the window manager have
2428 * the root background. Some window managers put multiple nested frame
2429 * windows for each client, so we have to take care about that.
2430 */
2431 i = (xa[XA_XROOTPMAP_ID]
2432 && XGetWindowProperty (xdisp, display->root, xa[XA_XROOTPMAP_ID],
2433 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2434 &nitems, &bytes_after, &prop) == Success);
2435
2436 if (!i || prop == NULL)
2437 i = (xa[XA_ESETROOT_PMAP_ID]
2438 && XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID],
2439 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
2440 &nitems, &bytes_after, &prop) == Success);
2441
2442 if (!i || prop == NULL
2443#if TINTING
2444 || !ISSET_PIXCOLOR (Color_tint)
2445#endif
2446 )
2447 have_pixmap = 0;
2448 else
2449 {
2450 have_pixmap = 1;
2451 rootpixmap = *(Pixmap *)prop;
2452 XFree (prop);
2453 }
2454
2455 if (have_pixmap)
2456 {
2457 /*
2458 * Copy display->root pixmap transparency
2459 */
2460 int sx, sy, nx, ny;
2461 unsigned int nw, nh;
2462 Window cr;
2463 XImage *image;
2464 GC gc;
2465 XGCValues gcvalue;
2466
2467 XTranslateCoordinates (xdisp, parent[0], display->root,
2468 0, 0, &sx, &sy, &cr);
2469 nw = (unsigned int)szHint.width;
2470 nh = (unsigned int)szHint.height;
2471 nx = ny = 0;
2472
2473 if (sx < 0)
2474 {
2475 nw += sx;
2476 nx = -sx;
2477 sx = 0;
2478 }
2479
2480 if (sy < 0)
2481 {
2482 nh += sy;
2483 ny = -sy;
2484 sy = 0;
2485 }
2486
2487 min_it (nw, (unsigned int) (wrootattr.width - sx));
2488 min_it (nh, (unsigned int) (wrootattr.height - sy));
2489
2490 XSync (xdisp, False);
2491 allowedxerror = -1;
2492 image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
2493
2494 /* XXX: handle BadMatch - usually because we're outside the pixmap */
2495 /* XXX: may need a delay here? */
2496 allowedxerror = 0;
2497
2498 if (image == NULL)
2499 {
2500 if (am_transparent && am_pixmap_trans)
2501 {
2502 pchanged = 1;
2503 if (pixmap != None)
2504 {
2505 XFreePixmap (xdisp, pixmap);
2506 pixmap = None;
2507 }
2508 }
2509
2510 am_pixmap_trans = 0;
2511 }
2512 else
2513 {
2514 if (pixmap != None)
2515 XFreePixmap (xdisp, pixmap);
2516
2517#if TINTING
2518 if (ISSET_PIXCOLOR (Color_tint))
2519 {
2520 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
2521
2522 rgba c;
2523 pix_colors_focused [Color_tint].get (c);
2524
2525 ShadeXImage (this, image, shade, c.r, c.g, c.b);
2526 }
2527#endif
2528
2529 pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth);
2530 gc = XCreateGC (xdisp, vt, 0UL, &gcvalue);
2531 XPutImage (xdisp, pixmap, gc, image, 0, 0,
2532 nx, ny, image->width, image->height);
2533 XFreeGC (xdisp, gc);
2534 XDestroyImage (image);
2535 XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap);
2536 XClearWindow (xdisp, parent[0]);
2537
2538 if (!am_transparent || !am_pixmap_trans)
2539 pchanged = 1;
2540
2541 am_transparent = am_pixmap_trans = 1;
2542 }
2543 }
2544
2545 if (am_pixmap_trans)
2546 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2547 else
2548 {
2549 unsigned int n;
2550 /*
2551 * InheritPixmap transparency
2552 */
2553 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2554 {
2555 oldp = parent[i];
2556 XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n);
2557 XFree (list);
2558
2559 if (parent[i] == display->root)
2560 {
2561 if (oldp != None)
2562 pchanged = 1;
2563
2564 break;
2565 }
2566
2567 if (oldp != parent[i])
2568 pchanged = 1;
2569 }
2570
2571 n = 0;
2572
2573 if (pchanged)
2574 for (; n < (unsigned int)i; n++)
2575 {
2576 XGetWindowAttributes (xdisp, parent[n], &wattr);
2577
2578 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
2579 {
2580 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
2581 break;
2582 }
2583 }
2584
2585 if (n > (sizeof (parent) / sizeof (parent[0])))
2586 {
2587 XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]);
2588 XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
2589 am_transparent = 0;
2590 /* XXX: also turn off Opt_transparent? */
2591 }
2592 else
2593 {
2594 for (n = 0; n < (unsigned int)i; n++)
2595 {
2596 XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative);
2597 XClearWindow (xdisp, parent[n]);
2598 }
2599
2600 XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative);
2601 am_transparent = 1;
2602 }
2603
2604 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
2605 parent[i] = None;
2606 }
2607
2608 if (scrollBar.win)
2609 {
2610 XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative);
2611 scrollBar.setIdle ();
2612 scrollbar_show (0);
2613 }
2614
2615 if (am_transparent)
2616 {
2617 want_refresh = want_full_refresh = 1;
2618 if (am_pixmap_trans)
2619 flush ();
2620 }
2621
2622 return pchanged;
2623}
2624#endif
2625
2626/*}}} */ 2187/*}}} */
2627 2188
2628bool 2189void
2629rxvt_term::cmd_parse () 2190rxvt_term::cmd_parse ()
2630{ 2191{
2631 bool flag = false;
2632 wchar_t ch = NOCHAR; 2192 wchar_t ch = NOCHAR;
2633 char *seq_begin; // remember start of esc-sequence here 2193 char *seq_begin; // remember start of esc-sequence here
2634 2194
2635 for (;;) 2195 for (;;)
2636 { 2196 {
2637 if (ch == NOCHAR) 2197 if (expect_false (ch == NOCHAR))
2638 { 2198 {
2639 seq_begin = cmdbuf_ptr; 2199 seq_begin = cmdbuf_ptr;
2640 ch = next_char (); 2200 ch = next_char ();
2641 2201
2642 if (ch == NOCHAR) 2202 if (ch == NOCHAR)
2643 break; 2203 break;
2644 } 2204 }
2645 2205
2646 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2206 if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2647 { 2207 {
2648 if (!seen_input) 2208 if (expect_false (!seen_input))
2649 { 2209 {
2650 seen_input = 1; 2210 seen_input = 1;
2651 // many badly-written programs (e.g. jed) contain a race condition: 2211 // many badly-written programs (e.g. jed) contain a race condition:
2652 // they first read the screensize and then install a SIGWINCH handler. 2212 // they first read the screensize and then install a SIGWINCH handler.
2653 // some window managers resize the window early, and these programs 2213 // some window managers resize the window early, and these programs
2666 wchar_t *str = buf; 2226 wchar_t *str = buf;
2667 wchar_t *eol = str + min (ncol, UBUFSIZ); 2227 wchar_t *eol = str + min (ncol, UBUFSIZ);
2668 2228
2669 for (;;) 2229 for (;;)
2670 { 2230 {
2671 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2231 if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2672 break; 2232 break;
2673 2233
2674 *str++ = ch; 2234 *str++ = ch;
2675 2235
2676 if (ch == C0_LF || str >= eol) 2236 if (expect_false (ch == C0_LF || str >= eol))
2677 { 2237 {
2678 if (ch == C0_LF) 2238 if (ch == C0_LF)
2679 nlines++; 2239 nlines++;
2680 2240
2681 refresh_count++; 2241 refresh_count++;
2682 2242
2683 if (!OPTION (Opt_jumpScroll) 2243 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2684 || (refresh_count >= refresh_limit * (nrow - 1)))
2685 { 2244 {
2686 refreshnow = true;
2687 refresh_count = 0; 2245 refresh_count = 0;
2246
2247 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2248 {
2249 refreshnow = true;
2688 ch = NOCHAR; 2250 ch = NOCHAR;
2689 break; 2251 break;
2252 }
2690 } 2253 }
2691 2254
2692 // scr_add_lines only works for nlines <= nrow - 1. 2255 // scr_add_lines only works for nlines <= nrow - 1.
2693 if (nlines >= nrow - 1) 2256 if (nlines >= nrow - 1)
2694 { 2257 {
2722 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) 2285 && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))))
2723 scr_add_lines (buf, str - buf, nlines); 2286 scr_add_lines (buf, str - buf, nlines);
2724 2287
2725 /* 2288 /*
2726 * If there have been a lot of new lines, then update the screen 2289 * If there have been a lot of new lines, then update the screen
2727 * What the heck I'll cheat and only refresh less than every page-full. 2290 * What the heck we'll cheat and only refresh less than every page-full.
2728 * the number of pages between refreshes is refresh_limit, which 2291 * if skipScroll is enabled.
2729 * is incremented here because we must be doing flat-out scrolling.
2730 */ 2292 */
2731 if (refreshnow) 2293 if (refreshnow)
2732 { 2294 {
2733 if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
2734 refresh_limit++;
2735 else
2736 {
2737 flag = true;
2738 scr_refresh (); 2295 scr_refresh ();
2739 want_refresh = 1; 2296 want_refresh = 1;
2740 }
2741 } 2297 }
2742
2743 } 2298 }
2744 else 2299 else
2745 { 2300 {
2746 try 2301 try
2747 { 2302 {
2755 } 2310 }
2756 2311
2757 ch = NOCHAR; 2312 ch = NOCHAR;
2758 } 2313 }
2759 } 2314 }
2760
2761 return flag;
2762} 2315}
2763 2316
2764// read the next character 2317// read the next character
2765wchar_t 2318wchar_t
2766rxvt_term::next_char () NOTHROW 2319rxvt_term::next_char () NOTHROW
2767{ 2320{
2768 while (cmdbuf_ptr < cmdbuf_endp) 2321 while (cmdbuf_ptr < cmdbuf_endp)
2769 { 2322 {
2770 // assume 7-bit to be ascii ALWAYS 2323 // assume 7-bit to be ascii ALWAYS
2771 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2324 if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b))
2772 return *cmdbuf_ptr++; 2325 return *cmdbuf_ptr++;
2773 2326
2774 wchar_t wc; 2327 wchar_t wc;
2775 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2328 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2776 2329
2780 cmdbuf_ptr = cmdbuf_endp; 2333 cmdbuf_ptr = cmdbuf_endp;
2781 break; 2334 break;
2782 } 2335 }
2783 2336
2784 if (len == (size_t)-1) 2337 if (len == (size_t)-1)
2338 {
2339 mbrtowc (0, 0, 0, mbstate); // reset now undefined conversion state
2785 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2340 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2341 }
2786 2342
2787 // assume wchar == unicode 2343 // assume wchar == unicode
2788 cmdbuf_ptr += len; 2344 cmdbuf_ptr += len;
2789 return wc & UNICODE_MASK; 2345 return wc & UNICODE_MASK;
2790 } 2346 }
2834/*----------------------------------------------------------------------*/ 2390/*----------------------------------------------------------------------*/
2835#ifdef PRINTPIPE 2391#ifdef PRINTPIPE
2836FILE * 2392FILE *
2837rxvt_term::popen_printer () 2393rxvt_term::popen_printer ()
2838{ 2394{
2839 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2395 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2840 2396
2841 if (stream == NULL) 2397 if (stream == NULL)
2842 rxvt_warn ("can't open printer pipe, not printing.\n"); 2398 rxvt_warn ("can't open printer pipe, not printing.\n");
2843 2399
2844 return stream; 2400 return stream;
2855 * simulate attached vt100 printer 2411 * simulate attached vt100 printer
2856 */ 2412 */
2857void 2413void
2858rxvt_term::process_print_pipe () 2414rxvt_term::process_print_pipe ()
2859{ 2415{
2860 int done; 2416 FILE *fd = popen_printer ();
2861 FILE *fd;
2862 2417
2863 if ((fd = popen_printer ()) == NULL) 2418 if (!fd)
2864 return; 2419 return;
2865 2420
2866 /* 2421 /*
2867 * Send all input to the printer until either ESC[4i or ESC[?4i 2422 * Send all input to the printer until either ESC[4i or ESC[?4i
2868 * is received. 2423 * is received.
2869 */ 2424 */
2870 for (done = 0; !done;) 2425 for (int done = 0; !done; )
2871 { 2426 {
2872 unsigned char buf[8]; 2427 unsigned char buf[8];
2873 unicode_t ch; 2428 unicode_t ch;
2874 unsigned int i, len; 2429 unsigned int i, len;
2875 2430
2894 { 2449 {
2895 if ((buf[len++] = cmd_getc ()) == 'i') 2450 if ((buf[len++] = cmd_getc ()) == 'i')
2896 break; /* done = 1 */ 2451 break; /* done = 1 */
2897 } 2452 }
2898 } 2453 }
2899 2454
2900 for (i = 0; i < len; i++) 2455 for (i = 0; i < len; i++)
2901 if (putc (buf[i], fd) == EOF) 2456 if (putc (buf[i], fd) == EOF)
2902 { 2457 {
2903 done = 1; 2458 done = 1;
2904 break; 2459 break;
2906 } 2461 }
2907 } 2462 }
2908 2463
2909 pclose_printer (fd); 2464 pclose_printer (fd);
2910} 2465}
2911#endif /* PRINTPIPE */ 2466#endif /* PRINTPIPE */
2912/*}}} */ 2467/*}}} */
2913 2468
2914/* *INDENT-OFF* */ 2469/* *INDENT-OFF* */
2915enum { 2470enum {
2916 C1_40 = 0x40, 2471 C1_40 = 0x40,
2966 process_dcs_seq (); 2521 process_dcs_seq ();
2967 break; 2522 break;
2968 case 0x9b: /* CSI */ 2523 case 0x9b: /* CSI */
2969 process_csi_seq (); 2524 process_csi_seq ();
2970 break; 2525 break;
2971 case 0x9d: /* CSI */ 2526 case 0x9d: /* OSC */
2972 process_osc_seq (); 2527 process_osc_seq ();
2973 break; 2528 break;
2974#endif 2529#endif
2975 } 2530 }
2976} 2531}
3020 break; 2575 break;
3021 case 'Z': /* identify the terminal type */ 2576 case 'Z': /* identify the terminal type */
3022 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ 2577 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
3023 break; 2578 break;
3024 case '<': /* turn off VT52 mode */ 2579 case '<': /* turn off VT52 mode */
3025 PrivMode (0, PrivMode_vt52); 2580 set_privmode (PrivMode_vt52, 0);
3026 break; 2581 break;
3027 case 'F': /* use special graphics character set */ 2582 case 'F': /* use special graphics character set */
3028 case 'G': /* use regular character set */ 2583 case 'G': /* use regular character set */
3029 /* unimplemented */ 2584 /* unimplemented */
3030 break; 2585 break;
3084 scr_forwardindex (); 2639 scr_forwardindex ();
3085 break; 2640 break;
3086#endif 2641#endif
3087 case '=': 2642 case '=':
3088 case '>': 2643 case '>':
3089 PrivMode ((ch == '='), PrivMode_aplKP); 2644 set_privmode (PrivMode_aplKP, ch == '=');
3090 break; 2645 break;
3091 2646
3092 case C1_40: 2647 case C1_40:
3093 cmd_getc (); 2648 cmd_getc ();
3094 break; 2649 break;
3133 /* 8.3.110: SINGLE CHARACTER INTRODUCER */ 2688 /* 8.3.110: SINGLE CHARACTER INTRODUCER */
3134 case C1_SCI: /* ESC Z */ 2689 case C1_SCI: /* ESC Z */
3135 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1); 2690 tt_write (ESCZ_ANSWER, sizeof (ESCZ_ANSWER) - 1);
3136 break; /* steal obsolete ESC [ c */ 2691 break; /* steal obsolete ESC [ c */
3137 2692
3138 /* 8.3.16: CONTROL SEQUENCE INTRODUCER */ 2693 /* 8.3.16: CONTROL SEQUENCE INTRODUCER (CSI) */
3139 case C1_CSI: /* ESC [ */ 2694 case C1_CSI: /* ESC [ */
3140 process_csi_seq (); 2695 process_csi_seq ();
3141 break; 2696 break;
3142 2697
3143 /* 8.3.90: OPERATING SYSTEM COMMAND */ 2698 /* 8.3.90: OPERATING SYSTEM COMMAND (OSC) */
3144 case C1_OSC: /* ESC ] */ 2699 case C1_OSC: /* ESC ] */
3145 process_osc_seq (); 2700 process_osc_seq ();
3146 break; 2701 break;
3147 2702
3148 /* 8.3.106: RESET TO INITIAL STATE */ 2703 /* 8.3.106: RESET TO INITIAL STATE (RIS) */
3149 case 'c': 2704 case 'c':
3150 mbstate.reset (); 2705 mbstate.reset ();
3151 scr_poweron (); 2706 scr_poweron ();
3152 scrollbar_show (1); 2707 scrollBar.show (1);
3153 break; 2708 break;
3154 2709
3155 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2710 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
3156 case 'n': 2711 case 'n':
3157 scr_charset_choose (2); 2712 scr_charset_choose (2);
3202rxvt_term::process_csi_seq () 2757rxvt_term::process_csi_seq ()
3203{ 2758{
3204 unicode_t ch, priv, i; 2759 unicode_t ch, priv, i;
3205 unsigned int nargs, p; 2760 unsigned int nargs, p;
3206 int n, ndef; 2761 int n, ndef;
3207 int arg[ESC_ARGS]; 2762 int arg[ESC_ARGS] = { };
3208 2763
3209 for (nargs = ESC_ARGS; nargs > 0;) 2764 nargs = 0;
3210 arg[--nargs] = 0;
3211 2765
3212 priv = 0; 2766 priv = 0;
3213 ch = cmd_getc (); 2767 ch = cmd_getc ();
3214 if (ch >= '<' && ch <= '?') 2768 if ((ch >= '<' && ch <= '?') || ch == '!')
2769 {
3215 { /* '<' '=' '>' '?' */ 2770 /* '<' '=' '>' '?' '!' */
3216 priv = ch; 2771 priv = ch;
3217 ch = cmd_getc (); 2772 ch = cmd_getc ();
3218 } 2773 }
3219 2774
3220 /* read any numerical arguments */ 2775 /* read any numerical arguments */
3259 switch (priv) 2814 switch (priv)
3260 { 2815 {
3261 case '>': 2816 case '>':
3262 if (ch == CSI_DA) /* secondary device attributes */ 2817 if (ch == CSI_DA) /* secondary device attributes */
3263 { 2818 {
3264 // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, 2819 // first parameter is normally 0 for vt100, 1 for vt220, 'R' for rxvt,
3265 // 'U' for rxvt-unicode != 7.[34] (where it was broken). 2820 // 'U' for rxvt-unicode != 7.[34] (where it was broken).
3266 // 2821 //
3267 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt 2822 // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt
3268 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify 2823 // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later
3269 // that we do not support xterm mouse reporting (should be 95 when we do). 2824 // versions.
3270 // 2825 //
3271 tt_printf ("\033[>%d;94;0c", 'U'); 2826 tt_printf ("\033[>%d;95;0c", 'U');
3272 } 2827 }
3273 break; 2828 break;
2829
3274 case '?': 2830 case '?':
3275 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2831 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
3276 process_terminal_mode (ch, priv, nargs, arg); 2832 process_terminal_mode (ch, priv, nargs, arg);
3277 break; 2833 break;
2834
2835 case '!':
2836 if (ch == CSI_70)
2837 {
2838 /* DECSTR: soft terminal reset, used by our terminfo since 9.06 */
2839 scr_soft_reset ();
2840
2841 static const int pm_h[] = { 7, 25 };
2842 static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1049 };
2843
2844 process_terminal_mode ('h', 0, sizeof (pm_h) / sizeof (pm_h[0]), pm_h);
2845 process_terminal_mode ('l', 0, sizeof (pm_l) / sizeof (pm_l[0]), pm_l);
3278 } 2846 }
2847 break;
2848 }
2849
3279 return; 2850 return;
3280 } 2851 }
3281 2852
3282 switch (ch) 2853 switch (ch)
3283 { 2854 {
3403 break; 2974 break;
3404 case 6: /* CPR requested */ 2975 case 6: /* CPR requested */
3405 scr_report_position (); 2976 scr_report_position ();
3406 break; 2977 break;
3407 case 7: /* unofficial extension */ 2978 case 7: /* unofficial extension */
3408 if (OPTION (Opt_insecure)) 2979 if (option (Opt_insecure))
3409 tt_printf ("%-.250s\012", rs[Rs_display_name]); 2980 tt_printf ("%-.250s\012", rs[Rs_display_name]);
3410 break; 2981 break;
3411 case 8: /* unofficial extension */ 2982 case 8: /* unofficial extension */
3412 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); 2983 process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST);
3413 break; 2984 break;
3506{ 3077{
3507 int x, y; 3078 int x, y;
3508 XWindowAttributes wattr; 3079 XWindowAttributes wattr;
3509 Window wdummy; 3080 Window wdummy;
3510 3081
3511 dLocal (Display *, xdisp); 3082 dLocal (Display *, dpy);
3512 3083
3513 if (nargs == 0) 3084 if (nargs == 0)
3514 return; 3085 return;
3515 3086
3516 switch (args[0]) 3087 switch (args[0])
3517 { 3088 {
3518 /* 3089 /*
3519 * commands 3090 * commands
3520 */ 3091 */
3521 case 1: /* deiconify window */ 3092 case 1: /* deiconify window */
3522 XMapWindow (xdisp, parent[0]); 3093 XMapWindow (dpy, parent[0]);
3523 break; 3094 break;
3524 case 2: /* iconify window */ 3095 case 2: /* iconify window */
3525 XIconifyWindow (xdisp, parent[0], display->screen); 3096 XIconifyWindow (dpy, parent[0], display->screen);
3526 break; 3097 break;
3527 case 3: /* set position (pixels) */ 3098 case 3: /* set position (pixels) */
3528 XMoveWindow (xdisp, parent[0], args[1], args[2]); 3099 XMoveWindow (dpy, parent[0], args[1], args[2]);
3529 break; 3100 break;
3530 case 4: /* set size (pixels) */ 3101 case 4: /* set size (pixels) */
3531 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); 3102 set_widthheight ((unsigned int)args[2], (unsigned int)args[1]);
3532 break; 3103 break;
3533 case 5: /* raise window */ 3104 case 5: /* raise window */
3534 XRaiseWindow (xdisp, parent[0]); 3105 XRaiseWindow (dpy, parent[0]);
3535 break; 3106 break;
3536 case 6: /* lower window */ 3107 case 6: /* lower window */
3537 XLowerWindow (xdisp, parent[0]); 3108 XLowerWindow (dpy, parent[0]);
3538 break; 3109 break;
3539 case 7: /* refresh window */ 3110 case 7: /* refresh window */
3540 scr_touch (true); 3111 scr_touch (true);
3541 break; 3112 break;
3542 case 8: /* set size (chars) */ 3113 case 8: /* set size (chars) */
3553 3124
3554 /* 3125 /*
3555 * reports - some output format copied from XTerm 3126 * reports - some output format copied from XTerm
3556 */ 3127 */
3557 case 11: /* report window state */ 3128 case 11: /* report window state */
3558 XGetWindowAttributes (xdisp, parent[0], &wattr); 3129 XGetWindowAttributes (dpy, parent[0], &wattr);
3559 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); 3130 tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2);
3560 break; 3131 break;
3561 case 13: /* report window position */ 3132 case 13: /* report window position */
3562 XGetWindowAttributes (xdisp, parent[0], &wattr); 3133 XGetWindowAttributes (dpy, parent[0], &wattr);
3563 XTranslateCoordinates (xdisp, parent[0], wattr.root, 3134 XTranslateCoordinates (dpy, parent[0], wattr.root,
3564 -wattr.border_width, -wattr.border_width, 3135 -wattr.border_width, -wattr.border_width,
3565 &x, &y, &wdummy); 3136 &x, &y, &wdummy);
3566 tt_printf ("\033[3;%d;%dt", x, y); 3137 tt_printf ("\033[3;%d;%dt", x, y);
3567 break; 3138 break;
3568 case 14: /* report window size (pixels) */ 3139 case 14: /* report window size (pixels) */
3569 XGetWindowAttributes (xdisp, parent[0], &wattr); 3140 XGetWindowAttributes (dpy, parent[0], &wattr);
3570 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); 3141 tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width);
3571 break; 3142 break;
3572 case 18: /* report text area size (chars) */ 3143 case 18: /* report text area size (chars) */
3573 tt_printf ("\033[8;%d;%dt", nrow, ncol); 3144 tt_printf ("\033[8;%d;%dt", nrow, ncol);
3574 break; 3145 break;
3576 tt_printf ("\033[9;%d;%dt", nrow, ncol); 3147 tt_printf ("\033[9;%d;%dt", nrow, ncol);
3577 break; 3148 break;
3578 case 20: /* report icon label */ 3149 case 20: /* report icon label */
3579 { 3150 {
3580 char *s; 3151 char *s;
3581 XGetIconName (xdisp, parent[0], &s); 3152 XGetIconName (dpy, parent[0], &s);
3582 tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ 3153 tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3583 XFree (s); 3154 XFree (s);
3584 } 3155 }
3585 break; 3156 break;
3586 case 21: /* report window title */ 3157 case 21: /* report window title */
3587 { 3158 {
3588 char *s; 3159 char *s;
3589 XFetchName (xdisp, parent[0], &s); 3160 XFetchName (dpy, parent[0], &s);
3590 tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ 3161 tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */
3591 XFree (s); 3162 XFree (s);
3592 } 3163 }
3593 break; 3164 break;
3594 } 3165 }
3595} 3166}
3622 seen_esc = true; 3193 seen_esc = true;
3623 continue; 3194 continue;
3624 } 3195 }
3625 else if (ch == C0_BEL || ch == CHAR_ST) 3196 else if (ch == C0_BEL || ch == CHAR_ST)
3626 break; 3197 break;
3198 else if (ch == C0_SYN)
3199 ch = cmd_get8 ();
3627 else if (ch < 0x20) 3200 else if (ch < 0x20)
3628 return NULL; /* other control character - exit */ 3201 return NULL; /* other control character - exit */
3629 3202
3630 seen_esc = false; 3203 seen_esc = false;
3631 3204
3632 if (n >= STRING_MAX - 1) 3205 if (n >= STRING_MAX - 1)
3633 // stop at some sane length 3206 // stop at some sane length
3634 return NULL; 3207 return NULL;
3635 3208
3636 if (ch == C0_SYN)
3637 string[n++] = cmd_get8 ();
3638 else
3639 string[n++] = ch; 3209 string[n++] = ch;
3640 } 3210 }
3641 3211
3642 string[n++] = '\0'; 3212 string[n++] = '\0';
3643 3213
3644 ends_how = (ch == 0x5c ? C0_ESC : ch); 3214 ends_how = (ch == 0x5c ? C0_ESC : ch);
3720 int color; 3290 int color;
3721 char *buf, *name; 3291 char *buf, *name;
3722 bool query = str[0] == '?' && !str[1]; 3292 bool query = str[0] == '?' && !str[1];
3723 int saveop = op; 3293 int saveop = op;
3724 3294
3725 dLocal (Display *, xdisp); 3295 dLocal (Display *, dpy);
3726 3296
3727 assert (str != NULL); 3297 assert (str != NULL);
3298
3299 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END)))
3300 return;
3301
3728 switch (op) 3302 switch (op)
3729 { 3303 {
3730 case XTerm_name: 3304 case XTerm_name:
3731 set_title (str); 3305 set_title (str);
3732 /* FALLTHROUGH */ 3306 /* FALLTHROUGH */
3746 unsigned long bytes_after; 3320 unsigned long bytes_after;
3747 unsigned char *value = 0; 3321 unsigned char *value = 0;
3748 const char *str = ""; 3322 const char *str = "";
3749 3323
3750 if (prop 3324 if (prop
3751 && XGetWindowProperty (xdisp, parent[0], 3325 && XGetWindowProperty (dpy, parent[0],
3752 prop, 0, 1<<16, 0, AnyPropertyType, 3326 prop, 0, 1<<16, 0, AnyPropertyType,
3753 &actual_type, &actual_format, 3327 &actual_type, &actual_format,
3754 &nitems, &bytes_after, &value) == Success 3328 &nitems, &bytes_after, &value) == Success
3755 && actual_type != None 3329 && actual_type != None
3756 && actual_format == 8) 3330 && actual_format == 8)
3768 { 3342 {
3769 *eq = 0; 3343 *eq = 0;
3770 set_utf8_property (display->atom (str), eq + 1); 3344 set_utf8_property (display->atom (str), eq + 1);
3771 } 3345 }
3772 else 3346 else
3773 XDeleteProperty (xdisp, parent[0], 3347 XDeleteProperty (dpy, parent[0],
3774 display->atom (str)); 3348 display->atom (str));
3775 } 3349 }
3776 break; 3350 break;
3777 3351
3778 case XTerm_Color: 3352 case XTerm_Color:
3791 *buf++ = '\0'; 3365 *buf++ = '\0';
3792 3366
3793 process_color_seq (op, color, name, resp); 3367 process_color_seq (op, color, name, resp);
3794 } 3368 }
3795 break; 3369 break;
3370 case Rxvt_restoreFG:
3796 case XTerm_Color00: 3371 case XTerm_Color00:
3797 process_color_seq (op, Color_fg, str, resp); 3372 process_color_seq (op, Color_fg, str, resp);
3798 break; 3373 break;
3374 case Rxvt_restoreBG:
3799 case XTerm_Color01: 3375 case XTerm_Color01:
3800 process_color_seq (op, Color_bg, str, resp); 3376 process_color_seq (op, Color_bg, str, resp);
3801 break; 3377 break;
3802#ifndef NO_CURSORCOLOR 3378#ifndef NO_CURSORCOLOR
3803 case XTerm_Color_cursor: 3379 case XTerm_Color_cursor:
3824 break; 3400 break;
3825 case URxvt_Color_IT: 3401 case URxvt_Color_IT:
3826 process_color_seq (op, Color_IT, str, resp); 3402 process_color_seq (op, Color_IT, str, resp);
3827 break; 3403 break;
3828#endif 3404#endif
3829#if TRANSPARENT && TINTING 3405#if ENABLE_TRANSPARENCY
3830 case URxvt_Color_tint: 3406 case URxvt_Color_tint:
3831 process_color_seq (op, Color_tint, str, resp); 3407 process_color_seq (op, Color_tint, str, resp);
3408 {
3409 bool changed = false;
3832 3410
3833 check_our_parents (); 3411 if (ISSET_PIXCOLOR (Color_tint))
3412 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3413 else
3414 changed = bgPixmap.unset_tint ();
3834 3415
3835 if (am_transparent) 3416 if (changed)
3836 want_full_refresh = want_refresh = 1; 3417 update_background ();
3418 }
3837 3419
3838 break; 3420 break;
3839#endif 3421#endif
3840 3422
3423#if BG_IMAGE_FROM_FILE
3841 case Rxvt_Pixmap: 3424 case Rxvt_Pixmap:
3842 { 3425 if (!strcmp (str, "?"))
3843 if (*str != ';')
3844 { 3426 {
3845#if XPM_BACKGROUND 3427 char str[256];
3846 scale_pixmap (""); /* reset to default scaling */ 3428
3847 set_bgPixmap (str); /* change pixmap */ 3429 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
3848 scr_touch (true); 3430 min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767),
3849#endif 3431 min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767));
3432 process_xterm_seq (XTerm_title, str, CHAR_ST);
3850 } 3433 }
3851 3434 else
3435 {
3852 int changed = 0; 3436 int changed = 0;
3853 3437
3854 while ((str = strchr (str, ';')) != NULL) 3438 if (*str != ';')
3855 { 3439 {
3440 /* reset to default scaling :*/
3441 bgPixmap.unset_geometry ();
3442 if (bgPixmap.set_file (str)) /* change pixmap */
3443 changed++;
3444 str = strchr (str, ';');
3445 if (str == NULL)
3446 bgPixmap.set_defaultGeometry ();
3447 }
3448
3449 while (str)
3450 {
3856 str++; 3451 str++;
3857#if XPM_BACKGROUND 3452 if (bgPixmap.set_geometry (str))
3858 changed += scale_pixmap (str); 3453 changed++;
3859#endif 3454 str = strchr (str, ';');
3860 } 3455 }
3861 3456
3862 if (changed) 3457 if (changed)
3863 { 3458 update_background ();
3864#ifdef XPM_BACKGROUND
3865 resize_pixmap ();
3866 scr_touch (true);
3867#endif
3868 } 3459 }
3869 }
3870 break; 3460 break;
3871 3461#endif
3872 case Rxvt_restoreFG:
3873 set_window_color (Color_fg, str);
3874 break;
3875 case Rxvt_restoreBG:
3876 set_window_color (Color_bg, str);
3877 break;
3878 3462
3879 case XTerm_logfile: 3463 case XTerm_logfile:
3880 // TODO, when secure mode? 3464 // TODO, when secure mode?
3881 break; 3465 break;
3882 3466
3900 case URxvt_italicFont: 3484 case URxvt_italicFont:
3901 case URxvt_boldItalicFont: 3485 case URxvt_boldItalicFont:
3902#endif 3486#endif
3903 if (query) 3487 if (query)
3904 tt_printf ("\33]%d;%-.250s%c", saveop, 3488 tt_printf ("\33]%d;%-.250s%c", saveop,
3905 OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc 3489 option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc
3906 ? fontset[op - URxvt_font]->fontdesc : "", 3490 ? fontset[op - URxvt_font]->fontdesc : "",
3907 resp); 3491 resp);
3908 else 3492 else
3909 { 3493 {
3910 const char *&res = rs[Rs_font + (op - URxvt_font)]; 3494 const char *&res = rs[Rs_font + (op - URxvt_font)];
3924 break; 3508 break;
3925 3509
3926#if !ENABLE_MINIMAL 3510#if !ENABLE_MINIMAL
3927 case URxvt_locale: 3511 case URxvt_locale:
3928 if (query) 3512 if (query)
3929 tt_printf ("\33]%d;%-.250s%c", op, OPTION (Opt_insecure) ? locale : "", resp); 3513 tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp);
3930 else 3514 else
3931 { 3515 {
3932 set_locale (str); 3516 set_locale (str);
3933 pty->set_utf8_mode (enc_utf8); 3517 pty->set_utf8_mode (enc_utf8);
3934 init_xlocale (); 3518 init_xlocale ();
3949 break; 3533 break;
3950#endif 3534#endif
3951 3535
3952#if ENABLE_PERL 3536#if ENABLE_PERL
3953 case URxvt_perl: 3537 case URxvt_perl:
3954 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END))) 3538 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3955 ; // no responses yet
3956 break; 3539 break;
3957#endif 3540#endif
3958 } 3541 }
3959} 3542}
3960/*----------------------------------------------------------------------*/ 3543/*----------------------------------------------------------------------*/
3983 { 3566 {
3984 if (mode == 'r') 3567 if (mode == 'r')
3985 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3568 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3986 else 3569 else
3987 state = (mode == 't') ? ! (priv_modes & bit) : mode; 3570 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3988 PrivMode (state, bit); 3571 set_privmode (bit, state);
3989 } 3572 }
3990 3573
3991 return state; 3574 return state;
3992} 3575}
3993 3576
3997{ 3580{
3998 unsigned int i, j; 3581 unsigned int i, j;
3999 int state; 3582 int state;
4000 3583
4001 static const struct 3584 static const struct
4002 { 3585 {
4003 const int argval; 3586 const int argval;
4004 const unsigned long bit; 3587 const unsigned long bit;
4005 }
4006
4007 argtopriv[] = { 3588 } argtopriv[] = {
4008 { 1, PrivMode_aplCUR }, 3589 { 1, PrivMode_aplCUR }, // DECCKM
4009 { 2, PrivMode_vt52 }, 3590 { 2, PrivMode_vt52 },
4010 { 3, PrivMode_132 }, 3591 { 3, PrivMode_132 }, // DECCOLM
4011 { 4, PrivMode_smoothScroll }, 3592 { 4, PrivMode_smoothScroll }, // DECSCLM
4012 { 5, PrivMode_rVideo }, 3593 { 5, PrivMode_rVideo }, // DECSCNM
4013 { 6, PrivMode_relOrigin }, 3594 { 6, PrivMode_relOrigin }, // DECOM
4014 { 7, PrivMode_Autowrap }, 3595 { 7, PrivMode_Autowrap }, // DECAWM
4015 // 8, bi-directional support mode 3596 // 8, auto-repeat keys // DECARM
4016 { 9, PrivMode_MouseX10 }, 3597 { 9, PrivMode_MouseX10 },
4017 // 18, 19 printing-related 3598 // 18, 19 printing-related
4018 { 25, PrivMode_VisibleCursor }, 3599 { 25, PrivMode_VisibleCursor }, // cnorm/cvvis/civis
4019#ifdef scrollBar_esc 3600#ifdef scrollBar_esc
4020 { scrollBar_esc, PrivMode_scrollBar }, 3601 { scrollBar_esc, PrivMode_scrollBar },
4021#endif 3602#endif
4022 { 35, PrivMode_ShiftKeys }, // rxvt extension 3603 { 35, PrivMode_ShiftKeys }, // rxvt extension
3604 // 38, tektronix mode // DECTEK
4023 { 40, PrivMode_132OK }, 3605 { 40, PrivMode_132OK },
4024 // 41 xterm more fixes NYI 3606 // 41 xterm more fixes NYI
4025 // 45 margin bell NYI 3607 // 45 margin bell NYI
4026 // 46 start logging 3608 // 46 start logging
4027 { 47, PrivMode_Screen }, 3609 { 47, PrivMode_Screen },
4028 { 66, PrivMode_aplKP }, 3610 { 66, PrivMode_aplKP }, // DECPAM/DECPNM
4029#ifndef NO_BACKSPACE_KEY 3611#ifndef NO_BACKSPACE_KEY
4030 { 67, PrivMode_BackSpace }, 3612 { 67, PrivMode_BackSpace }, // DECBKM
4031#endif 3613#endif
4032 { 1000, PrivMode_MouseX11 }, 3614 { 1000, PrivMode_MouseX11 },
4033 // 1001 Use Hilite Mouse Tracking. NYI, TODO 3615 { 1002, PrivMode_MouseBtnEvent },
4034 // 1002 Use Cell Motion Mouse Tracking. NYI, TODO 3616 { 1003, PrivMode_MouseAnyEvent },
4035 // 1003 Use All Motion Mouse Tracking. NYI, TODO
4036 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3617 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
4037 { 1011, PrivMode_Keypress }, // rxvt extension 3618 { 1011, PrivMode_Keypress }, // rxvt extension
4038 // 1035 enable modifiers for alt, numlock NYI 3619 // 1035 enable modifiers for alt, numlock NYI
4039 // 1036 send ESC for meta keys NYI 3620 // 1036 send ESC for meta keys NYI
4040 // 1037 send DEL for keypad delete NYI 3621 // 1037 send DEL for keypad delete NYI
4041 { 1047, PrivMode_Screen }, 3622 { 1047, PrivMode_Screen },
4042 // 1048 save and restore cursor 3623 // 1048 save and restore cursor
4043 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3624 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
4044 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3625 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3626 { 2004, PrivMode_BracketPaste },
4045 }; 3627 };
4046 3628
4047 if (nargs == 0) 3629 if (nargs == 0)
4048 return; 3630 return;
4049 3631
4075 scr_touch (true); 3657 scr_touch (true);
4076 break; 3658 break;
4077#endif 3659#endif
4078 case 1048: /* alternative cursor save */ 3660 case 1048: /* alternative cursor save */
4079 case 1049: 3661 case 1049:
4080 if (OPTION (Opt_secondaryScreen)) 3662 if (option (Opt_secondaryScreen))
4081 if (mode == 0) 3663 if (mode == 0)
4082 scr_cursor (RESTORE); 3664 scr_cursor (RESTORE);
4083 else if (mode == 1) 3665 else if (mode == 1)
4084 scr_cursor (SAVE); 3666 scr_cursor (SAVE);
4085 break; 3667 break;
4093 case 2: /* VT52 mode */ 3675 case 2: /* VT52 mode */
4094 /* oddball mode. should be set regardless of set/reset 3676 /* oddball mode. should be set regardless of set/reset
4095 * parameter. Return from VT52 mode with an ESC < from 3677 * parameter. Return from VT52 mode with an ESC < from
4096 * within VT52 mode 3678 * within VT52 mode
4097 */ 3679 */
4098 PrivMode (1, PrivMode_vt52); 3680 set_privmode (PrivMode_vt52, 1);
4099 break; 3681 break;
4100 case 3: /* 80/132 */ 3682 case 3: /* 80/132 */
4101 if (priv_modes & PrivMode_132OK) 3683 if (priv_modes & PrivMode_132OK)
4102 set_widthheight (((state ? 132 : 80) * fwidth), height); 3684 set_widthheight ((state ? 132 : 80) * fwidth, 24 * fheight);
4103 break; 3685 break;
4104 case 4: /* smooth scrolling */ 3686 case 4: /* smooth scrolling */
4105 set_option (Opt_jumpScroll, !state); 3687 set_option (Opt_jumpScroll, !state);
4106 break; 3688 break;
4107 case 5: /* reverse video */ 3689 case 5: /* reverse video */
4114 scr_autowrap (state); 3696 scr_autowrap (state);
4115 break; 3697 break;
4116 /* case 8: - auto repeat, can't do on a per window basis */ 3698 /* case 8: - auto repeat, can't do on a per window basis */
4117 case 9: /* X10 mouse reporting */ 3699 case 9: /* X10 mouse reporting */
4118 if (state) /* orthogonal */ 3700 if (state) /* orthogonal */
4119 priv_modes &= ~PrivMode_MouseX11; 3701 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4120 break; 3702 break;
4121#ifdef scrollBar_esc 3703#ifdef scrollBar_esc
4122 case scrollBar_esc: 3704 case scrollBar_esc:
4123 if (scrollbar_mapping (state)) 3705 if (scrollBar.map (state))
4124 { 3706 {
4125 resize_all_windows (0, 0, 0); 3707 resize_all_windows (0, 0, 0);
4126 scr_touch (true); 3708 scr_touch (true);
4127 } 3709 }
4128 break; 3710 break;
4137 break; 3719 break;
4138 /* case 66: - application key pad */ 3720 /* case 66: - application key pad */
4139 /* case 67: - backspace key */ 3721 /* case 67: - backspace key */
4140 case 1000: /* X11 mouse reporting */ 3722 case 1000: /* X11 mouse reporting */
4141 if (state) /* orthogonal */ 3723 if (state) /* orthogonal */
4142 priv_modes &= ~PrivMode_MouseX10; 3724 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
4143 break; 3725 break;
4144#if 0
4145 case 1001: 3726 case 1002:
4146 break; /* X11 mouse highlighting */ 3727 case 1003:
4147#endif 3728 if (state)
3729 {
3730 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3731 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3732 vt_emask_mouse = PointerMotionMask;
3733 }
3734 else
3735 vt_emask_mouse = NoEventMask;
3736
3737 vt_select_input ();
3738 break;
4148 case 1010: /* scroll to bottom on TTY output inhibit */ 3739 case 1010: /* scroll to bottom on TTY output inhibit */
4149 set_option (Opt_scrollTtyOutput, !state); 3740 set_option (Opt_scrollTtyOutput, !state);
4150 break; 3741 break;
4151 case 1011: /* scroll to bottom on key press */ 3742 case 1011: /* scroll to bottom on key press */
4152 set_option (Opt_scrollTtyKeypress, state); 3743 set_option (Opt_scrollTtyKeypress, state);
4153 break; 3744 break;
4154 case 1047: /* secondary screen w/ clearing last */ 3745 case 1047: /* secondary screen w/ clearing last */
4155 if (OPTION (Opt_secondaryScreen)) 3746 if (option (Opt_secondaryScreen))
4156 if (current_screen != PRIMARY) 3747 if (current_screen != PRIMARY)
4157 scr_erase_screen (2); 3748 scr_erase_screen (2);
3749
4158 scr_change_screen (state); 3750 scr_change_screen (state);
4159 break; 3751 break;
4160 case 1049: /* secondary screen w/ clearing first */ 3752 case 1049: /* secondary screen w/ clearing first */
4161 scr_change_screen (state); 3753 scr_change_screen (state);
4162 if (OPTION (Opt_secondaryScreen)) 3754 if (option (Opt_secondaryScreen))
4163 if (current_screen != PRIMARY) 3755 if (current_screen != PRIMARY)
4164 scr_erase_screen (2); 3756 scr_erase_screen (2);
4165 break; 3757 break;
4166 default: 3758 default:
4167 break; 3759 break;
4329rxvt_term::process_graphics () 3921rxvt_term::process_graphics ()
4330{ 3922{
4331 unicode_t ch, cmd = cmd_getc (); 3923 unicode_t ch, cmd = cmd_getc ();
4332 3924
4333 if (cmd == 'Q') 3925 if (cmd == 'Q')
3926 {
4334 { /* query graphics */ 3927 /* query graphics */
4335 tt_printf ("\033G0\012"); /* no graphics */ 3928 tt_printf ("\033G0\012"); /* no graphics */
4336 return; 3929 return;
4337 } 3930 }
4338 /* swallow other graphics sequences until terminating ':' */ 3931 /* swallow other graphics sequences until terminating ':' */
4339 do 3932 do
4389 v_buffer = (char *)realloc (v_buffer, v_buflen + len); 3982 v_buffer = (char *)realloc (v_buffer, v_buflen + len);
4390 3983
4391 memcpy (v_buffer + v_buflen, data, len); 3984 memcpy (v_buffer + v_buflen, data, len);
4392 v_buflen += len; 3985 v_buflen += len;
4393 3986
4394 pty_ev.set (EVENT_READ | EVENT_WRITE); 3987 pty_ev.set (ev::READ | ev::WRITE);
4395} 3988}
4396 3989
4397void rxvt_term::pty_write () 3990void rxvt_term::pty_write ()
4398{ 3991{
4399 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); 3992 int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE));
4404 3997
4405 if (v_buflen == 0) 3998 if (v_buflen == 0)
4406 { 3999 {
4407 free (v_buffer); 4000 free (v_buffer);
4408 v_buffer = 0; 4001 v_buffer = 0;
4409 v_buflen = 0;
4410 4002
4411 pty_ev.set (EVENT_READ); 4003 pty_ev.set (ev::READ);
4412 return; 4004 return;
4413 } 4005 }
4414 4006
4415 memmove (v_buffer, v_buffer + written, v_buflen); 4007 memmove (v_buffer, v_buffer + written, v_buflen);
4416 } 4008 }
4417 else if (written != -1 || (errno != EAGAIN && errno != EINTR)) 4009 else if (written != -1 || (errno != EAGAIN && errno != EINTR))
4418 pty_ev.set (EVENT_READ); 4010 pty_ev.set (ev::READ);
4419} 4011}
4420 4012
4421/*----------------------- end-of-file (C source) -----------------------*/ 4013/*----------------------- end-of-file (C source) -----------------------*/
4422 4014

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines