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.364 by ayin, Mon Nov 12 14:53:13 2007 UTC vs.
Revision 1.420 by root, Wed Oct 15 14:48:22 2008 UTC

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.
198 r & RS_Uline ? " uline" : "", 199 r & RS_Uline ? " uline" : "",
199 r & RS_Careful ? " careful" : ""); 200 r & RS_Careful ? " careful" : "");
200 201
201 int width = wcswidth (fname, wcslen (fname)); 202 int width = wcswidth (fname, wcslen (fname));
202 203
203 max_it (width, 8+5); // for char + hey 204 max_it (width, 8+5); // for char + hex
204 max_it (width, strlen (attr)); 205 max_it (width, strlen (attr));
205 206
206 if (y >= 0) 207 if (y >= 0)
207 { 208 {
208 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; 209 y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1;
220 ch = *chr++; 221 ch = *chr++;
221 222
222 sprintf (buf, "%8x", ch); 223 sprintf (buf, "%8x", ch);
223 scr_overlay_set (0, y, buf); 224 scr_overlay_set (0, y, buf);
224 scr_overlay_set (9, y, '='); 225 scr_overlay_set (9, y, '=');
225# if !UNICODE3 226# if !UNICODE_3
226 if (ch >= 0x10000) 227 if (ch >= 0x10000)
227 ch = 0xfffd; 228 ch = 0xfffd;
228# endif 229# endif
229 scr_overlay_set (11, y, ch, r); 230 scr_overlay_set (11, y, ch, r);
230 231
278 } 279 }
279 280
280 iso14755buf = 0; 281 iso14755buf = 0;
281} 282}
282 283
283int 284static int
284rxvt_term::hex_keyval (XKeyEvent &ev) 285hex_keyval (XKeyEvent &ev)
285{ 286{
286 // check wether this event corresponds to a hex digit 287 // check wether this event corresponds to a hex digit
287 // if the modifiers had not been pressed. 288 // if the modifiers had not been pressed.
288 for (int index = 0; index < 8; index++) 289 for (int index = 0; index < 8; index++)
289 { 290 {
297 298
298 return -1; 299 return -1;
299} 300}
300#endif 301#endif
301 302
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
302void 398void
303rxvt_term::key_press (XKeyEvent &ev) 399rxvt_term::key_press (XKeyEvent &ev)
304{ 400{
305 int ctrl, meta, shft, len; 401 int ctrl, meta, shft, len;
306 unsigned int newlen;
307 KeySym keysym; 402 KeySym keysym;
308 int valid_keysym; 403 int valid_keysym;
309 char kbuf[KBUFSZ]; 404 char kbuf[KBUFSZ];
310 405
311#if ISO_14755 406#if ISO_14755
324 meta = ev.state & ModMetaMask; 419 meta = ev.state & ModMetaMask;
325 420
326 if (numlock_state || (ev.state & ModNumLockMask)) 421 if (numlock_state || (ev.state & ModNumLockMask))
327 { 422 {
328 numlock_state = (ev.state & ModNumLockMask); 423 numlock_state = (ev.state & ModNumLockMask);
329 PrivMode ((!numlock_state), PrivMode_aplKP); 424 set_privmode (PrivMode_aplKP, !numlock_state);
330 } 425 }
331 426
332 kbuf[0] = 0; 427 kbuf[0] = 0;
333 428
334#ifdef USE_XIM 429#ifdef USE_XIM
546 } 641 }
547#endif 642#endif
548 643
549 if (keysym >= 0xFF00 && keysym <= 0xFFFF) 644 if (keysym >= 0xFF00 && keysym <= 0xFFFF)
550 { 645 {
646 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft;
647 unsigned int newlen = 1;
648
649 switch (translate_keypad (keysym, kp))
551 { 650 {
552 bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; 651#ifndef NO_BACKSPACE_KEY
553 newlen = 1; 652 case XK_BackSpace:
554#ifdef XK_KP_Home 653 if (priv_modes & PrivMode_HaveBackSpace)
555 static const KeySym keypadtrans[] = { 654 {
556 XK_KP_7, // XK_KP_Home 655 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
557 XK_KP_4, // XK_KP_Left 656 ^ !!ctrl) ? '\b' : '\177';
558 XK_KP_8, // XK_KP_Up 657 kbuf[1] = '\0';
559 XK_KP_6, // XK_KP_Right
560 XK_KP_2, // XK_KP_Down
561#ifndef UNSHIFTED_SCROLLKEYS
562 XK_KP_9, // XK_KP_Prior
563 XK_KP_3, // XK_KP_Next
564#else
565 XK_Prior,
566 XK_Next,
567#endif
568 XK_KP_1, // XK_KP_End
569 XK_KP_5, // XK_KP_Begin
570 }; 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
681 newlen = 0;
682 }
683 break;
571 684
572 if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin)) 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:
573 { 765 {
574 unsigned int index = keysym - XK_KP_Home; 766 int param = map_function_key (keysym);
575 keysym = kp ? keypadtrans[index] : XK_Home + index; 767 if (param > 0)
768 sprintf (kbuf,"\033[%d~", param);
769 else
770 newlen = 0;
576 } 771 }
577 else if (keysym == XK_KP_Insert)
578 keysym = kp ? XK_KP_0 : XK_Insert;
579#ifndef NO_DELETE_KEY
580 else if (keysym == XK_KP_Delete)
581 keysym = kp ? XK_KP_Decimal : XK_Delete;
582#endif
583#endif
584 switch (keysym)
585 {
586#ifndef NO_BACKSPACE_KEY
587 case XK_BackSpace:
588 if (priv_modes & PrivMode_HaveBackSpace)
589 {
590 kbuf[0] = (!! (priv_modes & PrivMode_BackSpace)
591 ^ !!ctrl) ? '\b' : '\177';
592 kbuf[1] = '\0';
593 }
594 else
595 strcpy (kbuf, rs[Rs_backspace_key]);
596 break; 772 break;
597#endif
598#ifndef NO_DELETE_KEY
599 case XK_Delete:
600 strcpy (kbuf, rs[Rs_delete_key]);
601 break;
602#endif
603 case XK_Tab:
604 if (shft)
605 strcpy (kbuf, "\033[Z");
606 else
607 {
608#ifdef CTRL_TAB_MAKES_META
609 if (ctrl)
610 meta = 1;
611#endif
612#ifdef MOD4_TAB_MAKES_META
613 if (ev.state & Mod4Mask)
614 meta = 1;
615#endif
616 newlen = 0;
617 }
618 break;
619
620 case XK_Up: /* "\033[A" */
621 case XK_Down: /* "\033[B" */
622 case XK_Right: /* "\033[C" */
623 case XK_Left: /* "\033[D" */
624 strcpy (kbuf, "\033[Z");
625 kbuf[2] = "DACB"[keysym - XK_Left];
626 /* do Shift first */
627 if (shft)
628 kbuf[2] = "dacb"[keysym - XK_Left];
629 else if (ctrl)
630 {
631 kbuf[1] = 'O';
632 kbuf[2] = "dacb"[keysym - XK_Left];
633 }
634 else if (priv_modes & PrivMode_aplCUR)
635 kbuf[1] = 'O';
636 break;
637
638#ifndef UNSHIFTED_SCROLLKEYS
639 case XK_Prior:
640 strcpy (kbuf, "\033[5~");
641 break;
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 (kp)
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 case XK_KP_F1: /* "\033OP" */
671 case XK_KP_F2: /* "\033OQ" */
672 case XK_KP_F3: /* "\033OR" */
673 case XK_KP_F4: /* "\033OS" */
674 strcpy (kbuf, "\033OP");
675 kbuf[2] += (keysym - XK_KP_F1);
676 break;
677
678 case XK_KP_Multiply: /* "\033Oj" : "*" */
679 case XK_KP_Add: /* "\033Ok" : "+" */
680 case XK_KP_Separator: /* "\033Ol" : "," */
681 case XK_KP_Subtract: /* "\033Om" : "-" */
682 case XK_KP_Decimal: /* "\033On" : "." */
683 case XK_KP_Divide: /* "\033Oo" : "/" */
684 case XK_KP_0: /* "\033Op" : "0" */
685 case XK_KP_1: /* "\033Oq" : "1" */
686 case XK_KP_2: /* "\033Or" : "2" */
687 case XK_KP_3: /* "\033Os" : "3" */
688 case XK_KP_4: /* "\033Ot" : "4" */
689 case XK_KP_5: /* "\033Ou" : "5" */
690 case XK_KP_6: /* "\033Ov" : "6" */
691 case XK_KP_7: /* "\033Ow" : "7" */
692 case XK_KP_8: /* "\033Ox" : "8" */
693 case XK_KP_9: /* "\033Oy" : "9" */
694 /* allow shift to override */
695 if (kp)
696 {
697 strcpy (kbuf, "\033Oj");
698 kbuf[2] += (keysym - XK_KP_Multiply);
699 }
700 else
701 {
702 kbuf[0] = ('*' + (keysym - XK_KP_Multiply));
703 kbuf[1] = '\0';
704 }
705 break;
706
707 case XK_Find:
708 strcpy (kbuf, "\033[1~");
709 break;
710
711 case XK_Insert:
712 strcpy (kbuf, "\033[2~");
713 break;
714#ifdef DXK_Remove /* support for DEC remove like key */
715 case DXK_Remove:
716 /* FALLTHROUGH */
717#endif
718 case XK_Execute:
719 strcpy (kbuf, "\033[3~");
720 break;
721 case XK_Select:
722 strcpy (kbuf, "\033[4~");
723 break;
724 case XK_End:
725 strcpy (kbuf, KS_END);
726 break;
727 case XK_Home:
728 strcpy (kbuf, KS_HOME);
729 break;
730
731#define FKEY(n, fkey) \
732 sprintf ((char *)kbuf,"\033[%2d~", (int) ((n) + (keysym - fkey)))
733
734 case XK_F1: /* "\033[11~" */
735 case XK_F2: /* "\033[12~" */
736 case XK_F3: /* "\033[13~" */
737 case XK_F4: /* "\033[14~" */
738 case XK_F5: /* "\033[15~" */
739 FKEY (11, XK_F1);
740 break;
741 case XK_F6: /* "\033[17~" */
742 case XK_F7: /* "\033[18~" */
743 case XK_F8: /* "\033[19~" */
744 case XK_F9: /* "\033[20~" */
745 case XK_F10: /* "\033[21~" */
746 FKEY (17, XK_F6);
747 break;
748 case XK_F11: /* "\033[23~" */
749 case XK_F12: /* "\033[24~" */
750 case XK_F13: /* "\033[25~" */
751 case XK_F14: /* "\033[26~" */
752 FKEY (23, XK_F11);
753 break;
754 case XK_F15: /* "\033[28~" */
755 case XK_F16: /* "\033[29~" */
756 FKEY (28, XK_F15);
757 break;
758 case XK_Help: /* "\033[28~" */
759 FKEY (28, XK_Help);
760 break;
761 case XK_Menu: /* "\033[29~" */
762 FKEY (29, XK_Menu);
763 break;
764 case XK_F17: /* "\033[31~" */
765 case XK_F18: /* "\033[32~" */
766 case XK_F19: /* "\033[33~" */
767 case XK_F20: /* "\033[34~" */
768 case XK_F21: /* "\033[35~" */
769 case XK_F22: /* "\033[36~" */
770 case XK_F23: /* "\033[37~" */
771 case XK_F24: /* "\033[38~" */
772 case XK_F25: /* "\033[39~" */
773 case XK_F26: /* "\033[40~" */
774 case XK_F27: /* "\033[41~" */
775 case XK_F28: /* "\033[42~" */
776 case XK_F29: /* "\033[43~" */
777 case XK_F30: /* "\033[44~" */
778 case XK_F31: /* "\033[45~" */
779 case XK_F32: /* "\033[46~" */
780 case XK_F33: /* "\033[47~" */
781 case XK_F34: /* "\033[48~" */
782 case XK_F35: /* "\033[49~" */
783 FKEY (31, XK_F17);
784 break;
785#undef FKEY
786 default:
787 newlen = 0;
788 break;
789 }
790
791 if (newlen)
792 len = strlen (kbuf);
793 } 773 }
774
775 if (newlen)
776 len = strlen (kbuf);
794 777
795 /* 778 /*
796 * Pass meta for all function keys, if 'meta' option set 779 * Pass meta for all function keys, if 'meta' option set
797 */ 780 */
798#ifdef META8_OPTION 781#ifdef META8_OPTION
1032 } 1015 }
1033 while (row < end_row); 1016 while (row < end_row);
1034 } 1017 }
1035 1018
1036 scr_refresh (); 1019 scr_refresh ();
1037 scrollbar_show (1); 1020 scrollBar.show (1);
1038#ifdef USE_XIM 1021#ifdef USE_XIM
1039 IMSendSpot (); 1022 IMSendSpot ();
1040#endif 1023#endif
1041 } 1024 }
1042 1025
1043 display->flush (); 1026 display->flush ();
1044} 1027}
1045 1028
1029/* checks wether a refresh is requested and starts the refresh timer */
1046void 1030void
1047rxvt_term::prepare_cb (ev::prepare &w, int revents) 1031rxvt_term::refresh_check ()
1048{ 1032{
1049 make_current (); 1033 if (want_refresh && !flush_ev.is_active ())
1034 flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally
1050 1035
1051 display->flush (); 1036 display->flush ();
1052
1053 if (want_refresh && !flush_ev.active)
1054 flush_ev.start (1. / 60.); // refresh at max. 60 hz normally
1055} 1037}
1056 1038
1057void 1039void
1058rxvt_term::flush_cb (ev::timer &w, int revents) 1040rxvt_term::flush_cb (ev::timer &w, int revents)
1059{ 1041{
1067void 1049void
1068rxvt_term::cursor_blink_cb (ev::timer &w, int revents) 1050rxvt_term::cursor_blink_cb (ev::timer &w, int revents)
1069{ 1051{
1070 hidden_cursor = !hidden_cursor; 1052 hidden_cursor = !hidden_cursor;
1071 want_refresh = 1; 1053 want_refresh = 1;
1054 refresh_check ();
1072} 1055}
1073#endif 1056#endif
1074 1057
1075#ifdef TEXT_BLINK 1058#ifdef TEXT_BLINK
1076void 1059void
1078{ 1061{
1079 if (scr_refresh_rend (RS_Blink, RS_Blink)) 1062 if (scr_refresh_rend (RS_Blink, RS_Blink))
1080 { 1063 {
1081 hidden_text = !hidden_text; 1064 hidden_text = !hidden_text;
1082 want_refresh = 1; 1065 want_refresh = 1;
1066 refresh_check ();
1083 } 1067 }
1068 else
1069 w.stop ();
1084} 1070}
1085#endif 1071#endif
1086 1072
1087#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1073#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1088void 1074void
1089rxvt_term::cont_scroll_cb (ev::timer &w, int revents) 1075rxvt_term::cont_scroll_cb (ev::timer &w, int revents)
1090{ 1076{
1091 if ((scrollbar_isUp() || scrollbar_isDn()) && 1077 if ((scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
1092 scr_page (scrollbar_isUp() ? UP : DN, 1)) 1078 && scr_page (scrollBar.state == STATE_UP ? UP : DN, 1))
1079 {
1093 want_refresh = 1; 1080 want_refresh = 1;
1081 refresh_check ();
1082 }
1094 else 1083 else
1095 w.stop (); 1084 w.stop ();
1096} 1085}
1097#endif 1086#endif
1098 1087
1102{ 1091{
1103 if (scr_page (scroll_selection_dir, scroll_selection_lines)) 1092 if (scr_page (scroll_selection_dir, scroll_selection_lines))
1104 { 1093 {
1105 selection_extend (selection_save_x, selection_save_y, selection_save_state); 1094 selection_extend (selection_save_x, selection_save_y, selection_save_state);
1106 want_refresh = 1; 1095 want_refresh = 1;
1096 refresh_check ();
1107 } 1097 }
1108 else 1098 else
1109 w.stop (); 1099 w.stop ();
1110} 1100}
1111#endif 1101#endif
1112 1102
1113#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 1103#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1114void 1104void
1115rxvt_term::slip_wheel_cb (ev::timer &w, int revents) 1105rxvt_term::slip_wheel_cb (ev::timer &w, int revents)
1116{ 1106{
1117 if (mouse_slip_wheel_speed == 0 1107 if (scr_changeview (view_start - mouse_slip_wheel_speed))
1118 || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed)
1119 : scr_page (UP, mouse_slip_wheel_speed))
1120 { 1108 {
1121 if (view_start == top_row || view_start == 0)
1122 mouse_slip_wheel_speed = 0;
1123
1124 want_refresh = 1; 1109 want_refresh = 1;
1110 refresh_check ();
1111 }
1112
1113 if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0)
1125 } 1114 {
1126 else 1115 mouse_slip_wheel_speed = 0;
1127 w.stop (); 1116 w.stop ();
1117 }
1128} 1118}
1129#endif 1119#endif
1130 1120
1131#if LINUX_YIELD_HACK 1121#if LINUX_YIELD_HACK
1132static struct event_handler 1122static struct event_handler
1204 if (cmd_parse ()) 1194 if (cmd_parse ())
1205 break; 1195 break;
1206 1196
1207 if (revents & ev::WRITE) 1197 if (revents & ev::WRITE)
1208 pty_write (); 1198 pty_write ();
1199
1200 refresh_check ();
1209} 1201}
1210 1202
1211void 1203void
1212rxvt_term::pointer_unblank () 1204rxvt_term::pointer_unblank ()
1213{ 1205{
1251 int x, y; 1243 int x, y;
1252 int code = 32; 1244 int code = 32;
1253 1245
1254 x = Pixel2Col (ev.x); 1246 x = Pixel2Col (ev.x);
1255 y = Pixel2Row (ev.y); 1247 y = Pixel2Row (ev.y);
1256 if (ev.type == MotionNotify) { 1248 if (ev.type == MotionNotify)
1249 {
1257 if (x == mouse_row && y == mouse_col) 1250 if (x == mouse_row && y == mouse_col)
1258 return; 1251 return;
1259 mouse_row = x; 1252 mouse_row = x;
1260 mouse_col = y; 1253 mouse_col = y;
1261 code += 32; 1254 code += 32;
1262 } 1255 }
1263 1256
1264 if (MEvent.button == AnyButton) 1257 if (MEvent.button == AnyButton)
1265 button_number = 3; 1258 button_number = 3;
1266 else 1259 else
1267 { 1260 {
1427 && ev.xfocus.mode != NotifyGrab) 1420 && ev.xfocus.mode != NotifyGrab)
1428 focus_out (); 1421 focus_out ();
1429 break; 1422 break;
1430 1423
1431 case ConfigureNotify: 1424 case ConfigureNotify:
1432 /* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n", 1425 /*fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n",
1433 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y, 1426 ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y,
1434 szHint.width, szHint.height); */ 1427 szHint.width, szHint.height);*/
1435 if (ev.xconfigure.window == parent[0]) 1428 if (ev.xconfigure.window == parent[0])
1436 { 1429 {
1437 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) 1430 while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev))
1438 ; 1431 ;
1439 1432
1444 } 1437 }
1445 else 1438 else
1446 { 1439 {
1447#ifdef HAVE_BG_PIXMAP 1440#ifdef HAVE_BG_PIXMAP
1448 if (bgPixmap.window_position_sensitive ()) 1441 if (bgPixmap.window_position_sensitive ())
1442 {
1443 if (mapped)
1449 update_background (); 1444 update_background ();
1445 else
1446 bgPixmap.invalidate ();
1447 }
1450#endif 1448#endif
1451 } 1449 }
1450
1452 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); 1451 HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END));
1453 } 1452 }
1454 break; 1453 break;
1455 1454
1456 case PropertyNotify: 1455 case PropertyNotify:
1473 case SelectionRequest: 1472 case SelectionRequest:
1474 selection_send (ev.xselectionrequest); 1473 selection_send (ev.xselectionrequest);
1475 break; 1474 break;
1476 1475
1477 case MapNotify: 1476 case MapNotify:
1477#ifdef HAVE_BG_PIXMAP
1478 /* This is needed spcifically to fix the case of no window manager or a
1479 * non-reparenting window manager. In those cases we never get first
1480 * ConfigureNotify. Also that speeds startup under normal WM, by taking
1481 * care of multiplicity of ConfigureNotify events arriwing while WM does
1482 * reparenting.
1483 * We should not render background immidiately, as there could be several
1484 * ConfigureNotify's to follow. Lets take care of all of them in one scoop
1485 * by scheduling background redraw as soon as we can, but giving a short
1486 * bit of time for ConfigureNotifies to arrive.
1487 * We should render background PRIOR to drawing any text, but AFTER all
1488 * of ConfigureNotifys for the best results.
1489 */
1490 if (bgPixmap.flags & bgPixmap_t::isInvalid)
1491 update_background_ev.start (0.025);
1492#endif
1478 mapped = 1; 1493 mapped = 1;
1479#ifdef TEXT_BLINK 1494#ifdef TEXT_BLINK
1480 text_blink_ev.start (TEXT_BLINK_INTERVAL); 1495 text_blink_ev.start ();
1481#endif 1496#endif
1482 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); 1497 HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END));
1483 break; 1498 break;
1484 1499
1485 case UnmapNotify: 1500 case UnmapNotify:
1506 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)) 1521 while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev))
1507 { 1522 {
1508 scr_expose (ev.xexpose.x, ev.xexpose.y, 1523 scr_expose (ev.xexpose.x, ev.xexpose.y,
1509 ev.xexpose.width, ev.xexpose.height, False); 1524 ev.xexpose.width, ev.xexpose.height, False);
1510 } 1525 }
1526
1511 want_refresh = 1; 1527 want_refresh = 1;
1512 } 1528 }
1513 else 1529 else
1514 { 1530 {
1515 XEvent unused_event; 1531 XEvent unused_event;
1517 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event)) 1533 while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event))
1518 ; 1534 ;
1519 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event)) 1535 while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event))
1520 ; 1536 ;
1521 1537
1522 if (isScrollbarWindow (ev.xany.window)) 1538 if (scrollBar.state && ev.xany.window == scrollBar.win)
1523 { 1539 {
1524 scrollBar.setIdle (); 1540 scrollBar.state = STATE_IDLE;
1525 scrollbar_show (0); 1541 scrollBar.show (0);
1526 } 1542 }
1527 } 1543 }
1528 break; 1544 break;
1529 1545
1530 case MotionNotify: 1546 case MotionNotify:
1576 int dist; 1592 int dist;
1577 1593
1578 /* don't clobber the current delay if we are 1594 /* don't clobber the current delay if we are
1579 * already in the middle of scrolling. 1595 * already in the middle of scrolling.
1580 */ 1596 */
1581 if (!sel_scroll_ev.active) 1597 if (!sel_scroll_ev.is_active ())
1582 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); 1598 sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1583 1599
1584 /* save the event params so we can highlight 1600 /* save the event params so we can highlight
1585 * the selection in the pending-scroll loop 1601 * the selection in the pending-scroll loop
1586 */ 1602 */
1609 else 1625 else
1610 { 1626 {
1611 /* we are within the text window, so we 1627 /* we are within the text window, so we
1612 * shouldn't be scrolling 1628 * shouldn't be scrolling
1613 */ 1629 */
1614 if (sel_scroll_ev.active)
1615 sel_scroll_ev.stop(); 1630 sel_scroll_ev.stop();
1616 } 1631 }
1617#endif 1632#endif
1618#ifdef MOUSE_THRESHOLD 1633#ifdef MOUSE_THRESHOLD
1619 } 1634 }
1620#endif 1635#endif
1621 } 1636 }
1622 } 1637 }
1623 else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) 1638 else if (scrollBar.state == STATE_MOTION && ev.xany.window == scrollBar.win)
1624 { 1639 {
1625 while (XCheckTypedWindowEvent (dpy, scrollBar.win, 1640 while (XCheckTypedWindowEvent (dpy, scrollBar.win,
1626 MotionNotify, &ev)) 1641 MotionNotify, &ev))
1627 ; 1642 ;
1628 1643
1630 &unused_root, &unused_child, 1645 &unused_root, &unused_child,
1631 &unused_root_x, &unused_root_y, 1646 &unused_root_x, &unused_root_y,
1632 &ev.xbutton.x, &ev.xbutton.y, 1647 &ev.xbutton.x, &ev.xbutton.y,
1633 &unused_mask); 1648 &unused_mask);
1634 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, 1649 scr_move_to (scrollbar_position (ev.xbutton.y) - csrO,
1635 scrollbar_size ()); 1650 scrollBar.size ());
1636 want_refresh = 1; 1651 want_refresh = 1;
1637 scrollbar_show (1); 1652 scrollBar.show (1);
1638 } 1653 }
1639 break; 1654 break;
1640 } 1655 }
1641 1656
1642#if defined(CURSOR_BLINK) 1657#if defined(CURSOR_BLINK)
1663 1678
1664 if (ev.type == KeyPress && hidden_pointer == 0) 1679 if (ev.type == KeyPress && hidden_pointer == 0)
1665 pointer_blank (); 1680 pointer_blank ();
1666 } 1681 }
1667#endif 1682#endif
1683
1684 refresh_check ();
1685}
1686
1687void
1688rxvt_term::set_urgency (bool enable)
1689{
1690 if (enable == urgency_hint)
1691 return;
1692
1693 if (XWMHints *h = XGetWMHints (dpy, parent[0]))
1694 {
1695 h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0);
1696 XSetWMHints (dpy, parent[0], h);
1697 urgency_hint = enable;
1698 }
1668} 1699}
1669 1700
1670void 1701void
1671rxvt_term::focus_in () 1702rxvt_term::focus_in ()
1672{ 1703{
1673 if (!focus) 1704 if (!focus)
1674 { 1705 {
1675 focus = 1; 1706 focus = 1;
1676 want_refresh = 1; 1707 want_refresh = 1;
1677 1708
1678 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1679
1680#if USE_XIM 1709#if USE_XIM
1681 if (Input_Context != NULL) 1710 if (Input_Context != NULL)
1682 { 1711 {
1683 IMSetPosition (); 1712 IMSetPosition ();
1684 XSetICFocus (Input_Context); 1713 XSetICFocus (Input_Context);
1685 } 1714 }
1686#endif 1715#endif
1687#if CURSOR_BLINK 1716#if CURSOR_BLINK
1688 if (option (Opt_cursorBlink)) 1717 if (option (Opt_cursorBlink))
1689 cursor_blink_ev.start (CURSOR_BLINK_INTERVAL, CURSOR_BLINK_INTERVAL); 1718 cursor_blink_ev.again ();
1690#endif 1719#endif
1691#if OFF_FOCUS_FADING 1720#if OFF_FOCUS_FADING
1692 if (rs[Rs_fade]) 1721 if (rs[Rs_fade])
1693 { 1722 {
1694 pix_colors = pix_colors_focused; 1723 pix_colors = pix_colors_focused;
1695 scr_recolour (); 1724 scr_recolour ();
1696 } 1725 }
1697#endif 1726#endif
1698#if ENABLE_FRILLS 1727#if ENABLE_FRILLS
1699 if (option (Opt_urgentOnBell)) 1728 if (option (Opt_urgentOnBell))
1700 { 1729 set_urgency (0);
1701 if (XWMHints *h = XGetWMHints(dpy, parent[0]))
1702 {
1703 h->flags &= ~XUrgencyHint;
1704 XSetWMHints (dpy, parent[0], h);
1705 }
1706 }
1707#endif 1730#endif
1731
1732 HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END));
1708 } 1733 }
1709} 1734}
1710 1735
1711void 1736void
1712rxvt_term::focus_out () 1737rxvt_term::focus_out ()
1714 if (focus) 1739 if (focus)
1715 { 1740 {
1716 focus = 0; 1741 focus = 0;
1717 want_refresh = 1; 1742 want_refresh = 1;
1718 1743
1719 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); 1744#if ENABLE_FRILLS
1720 1745 if (option (Opt_urgentOnBell))
1746 set_urgency (0);
1747#endif
1721#if ENABLE_FRILLS || ISO_14755 1748#if ENABLE_FRILLS || ISO_14755
1722 if (iso14755buf) 1749 if (iso14755buf)
1723 { 1750 {
1724 iso14755buf = 0; 1751 iso14755buf = 0;
1725# if ISO_14755 1752# if ISO_14755
1742 { 1769 {
1743 pix_colors = pix_colors_unfocused; 1770 pix_colors = pix_colors_unfocused;
1744 scr_recolour (); 1771 scr_recolour ();
1745 } 1772 }
1746#endif 1773#endif
1774
1775 HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END));
1747 } 1776 }
1748} 1777}
1749 1778
1750void 1779void
1751rxvt_term::update_fade_color (unsigned int idx) 1780rxvt_term::update_fade_color (unsigned int idx)
1782 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID]) 1811 || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID])
1783 { 1812 {
1784 bgPixmap.set_root_pixmap (); 1813 bgPixmap.set_root_pixmap ();
1785 update_background (); 1814 update_background ();
1786 } 1815 }
1816
1787 break; 1817 break;
1788 } 1818 }
1789# endif 1819# endif
1820
1821 refresh_check ();
1790} 1822}
1791#endif 1823#endif
1792 1824
1793void 1825void
1794rxvt_term::button_press (XButtonEvent &ev) 1826rxvt_term::button_press (XButtonEvent &ev)
1849 mouse_report (ev); 1881 mouse_report (ev);
1850 } 1882 }
1851#else 1883#else
1852 MEvent.button = ev.button; 1884 MEvent.button = ev.button;
1853 mouse_report (ev); 1885 mouse_report (ev);
1854#endif /* MOUSE_REPORT_DOUBLECLICK */ 1886#endif /* MOUSE_REPORT_DOUBLECLICK */
1855 1887
1856 } 1888 }
1857 else 1889 else
1858 { 1890 {
1859 if (ev.button != MEvent.button) 1891 if (ev.button != MEvent.button)
1907 } 1939 }
1908 1940
1909 /* 1941 /*
1910 * Scrollbar window processing of button press 1942 * Scrollbar window processing of button press
1911 */ 1943 */
1912 if (isScrollbarWindow (ev.window)) 1944 if (scrollBar.state && ev.window == scrollBar.win)
1913 { 1945 {
1914 scrollBar.setIdle (); 1946 page_dirn direction = NO_DIR;
1947
1948 if (scrollBar.upButton (ev.y))
1949 direction = UP; /* up */
1950 else if (scrollBar.dnButton (ev.y))
1951 direction = DN; /* down */
1952
1953 scrollBar.state = STATE_IDLE;
1915 /* 1954 /*
1916 * Rxvt-style scrollbar: 1955 * Rxvt-style scrollbar:
1917 * move up if mouse is above slider 1956 * move up if mouse is above slider
1918 * move dn if mouse is below slider 1957 * move dn if mouse is below slider
1919 * 1958 *
1928 /* 1967 /*
1929 * Mouse report disabled scrollbar: 1968 * Mouse report disabled scrollbar:
1930 * arrow buttons - send up/down 1969 * arrow buttons - send up/down
1931 * click on scrollbar - send pageup/down 1970 * click on scrollbar - send pageup/down
1932 */ 1971 */
1933 if ((scrollBar.style == R_SB_NEXT 1972 if (direction == UP)
1934 && scrollbarnext_upButton (ev.y))
1935 || (scrollBar.style == R_SB_RXVT
1936 && scrollbarrxvt_upButton (ev.y)))
1937 tt_printf ("\033[A"); 1973 tt_printf ("\033[A");
1938 else if ((scrollBar.style == R_SB_NEXT 1974 else if (direction == DN)
1939 && scrollbarnext_dnButton (ev.y))
1940 || (scrollBar.style == R_SB_RXVT
1941 && scrollbarrxvt_dnButton (ev.y)))
1942 tt_printf ("\033[B"); 1975 tt_printf ("\033[B");
1943 else 1976 else
1944 switch (ev.button) 1977 switch (ev.button)
1945 { 1978 {
1946 case Button2: 1979 case Button2:
1953 tt_printf ("\033[5~"); 1986 tt_printf ("\033[5~");
1954 break; 1987 break;
1955 } 1988 }
1956 } 1989 }
1957 else 1990 else
1958#endif /* NO_SCROLLBAR_REPORT */ 1991#endif /* NO_SCROLLBAR_REPORT */
1959
1960 {
1961 char upordown = 0;
1962
1963 if (scrollBar.style == R_SB_NEXT)
1964 { 1992 {
1965 if (scrollbarnext_upButton (ev.y)) 1993 if (direction != NO_DIR)
1966 upordown = -1; /* up */
1967 else if (scrollbarnext_dnButton (ev.y))
1968 upordown = 1; /* down */
1969 }
1970 else if (scrollBar.style == R_SB_RXVT)
1971 {
1972 if (scrollbarrxvt_upButton (ev.y))
1973 upordown = -1; /* up */
1974 else if (scrollbarrxvt_dnButton (ev.y))
1975 upordown = 1; /* down */
1976 }
1977 if (upordown)
1978 { 1994 {
1979#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING 1995#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING
1996 if (!cont_scroll_ev.is_active ())
1980 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); 1997 cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
1981#endif 1998#endif
1982 if (scr_page (upordown < 0 ? UP : DN, 1)) 1999 if (scr_page (direction, 1))
1983 { 2000 {
1984 if (upordown < 0) 2001 if (direction == UP)
1985 scrollBar.setUp (); 2002 scrollBar.state = STATE_UP;
1986 else 2003 else
1987 scrollBar.setDn (); 2004 scrollBar.state = STATE_DOWN;
1988 } 2005 }
1989 } 2006 }
1990 else 2007 else
1991 switch (ev.button) 2008 switch (ev.button)
1992 { 2009 {
1993 case Button2: 2010 case Button2:
1994 switch (scrollbar_align) 2011 switch (scrollBar.align)
1995 { 2012 {
1996 case R_SB_ALIGN_TOP: 2013 case R_SB_ALIGN_TOP:
1997 csrO = 0; 2014 csrO = 0;
1998 break; 2015 break;
1999 case R_SB_ALIGN_CENTRE: 2016 case R_SB_ALIGN_CENTRE:
2005 } 2022 }
2006 2023
2007 if (scrollBar.style == R_SB_XTERM 2024 if (scrollBar.style == R_SB_XTERM
2008 || scrollbar_above_slider (ev.y) 2025 || scrollbar_above_slider (ev.y)
2009 || scrollbar_below_slider (ev.y)) 2026 || scrollbar_below_slider (ev.y))
2010 scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); 2027 scr_move_to (scrollbar_position (ev.y) - csrO, scrollBar.size ());
2011 2028
2012 scrollBar.setMotion (); 2029 scrollBar.state = STATE_MOTION;
2013 break; 2030 break;
2014 2031
2015 case Button1: 2032 case Button1:
2016 if (scrollbar_align == R_SB_ALIGN_CENTRE) 2033 if (scrollBar.align == R_SB_ALIGN_CENTRE)
2017 csrO = ev.y - scrollBar.top; 2034 csrO = ev.y - scrollBar.top;
2018 /* FALLTHROUGH */ 2035 /* FALLTHROUGH */
2019 2036
2020 case Button3: 2037 case Button3:
2021 if (scrollBar.style != R_SB_XTERM) 2038 if (scrollBar.style != R_SB_XTERM)
2031 scr_page (DN, nrow - 1); 2048 scr_page (DN, nrow - 1);
2032# else 2049# else
2033 scr_page (DN, nrow / 4); 2050 scr_page (DN, nrow / 4);
2034# endif 2051# endif
2035 else 2052 else
2036 scrollBar.setMotion (); 2053 scrollBar.state = STATE_MOTION;
2037 } 2054 }
2038 else 2055 else
2039 { 2056 {
2040 scr_page ((ev.button == Button1 ? DN : UP), 2057 scr_page ((ev.button == Button1 ? DN : UP),
2041 (nrow 2058 (nrow
2042 * scrollbar_position (ev.y) 2059 * scrollbar_position (ev.y)
2043 / scrollbar_size ())); 2060 / scrollBar.size ()));
2044 } 2061 }
2045 2062
2046 break; 2063 break;
2047 } 2064 }
2048 } 2065 }
2058 2075
2059 csrO = 0; /* reset csr Offset */ 2076 csrO = 0; /* reset csr Offset */
2060 if (!bypass_keystate) 2077 if (!bypass_keystate)
2061 reportmode = !! (priv_modes & PrivMode_mouse_report); 2078 reportmode = !! (priv_modes & PrivMode_mouse_report);
2062 2079
2063 if (scrollbar_isUpDn ()) 2080 if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN)
2064 { 2081 {
2065 scrollBar.setIdle (); 2082 scrollBar.state = STATE_IDLE;
2066 scrollbar_show (0); 2083 scrollBar.show (0);
2067 } 2084 }
2068 2085
2069#ifdef SELECTION_SCROLLING 2086#ifdef SELECTION_SCROLLING
2070 if (sel_scroll_ev.active)
2071 sel_scroll_ev.stop(); 2087 sel_scroll_ev.stop();
2072#endif 2088#endif
2073 2089
2074 if (ev.window == vt) 2090 if (ev.window == vt)
2075 { 2091 {
2076 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) 2092 if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END)))
2100 mouse_report (ev); 2116 mouse_report (ev);
2101 } 2117 }
2102#else /* MOUSE_REPORT_DOUBLECLICK */ 2118#else /* MOUSE_REPORT_DOUBLECLICK */
2103 MEvent.button = AnyButton; 2119 MEvent.button = AnyButton;
2104 mouse_report (ev); 2120 mouse_report (ev);
2105#endif /* MOUSE_REPORT_DOUBLECLICK */ 2121#endif /* MOUSE_REPORT_DOUBLECLICK */
2106 return; 2122 return;
2107 } 2123 }
2108 2124
2109 /* 2125 /*
2110 * dumb hack to compensate for the failure of click-and-drag 2126 * dumb hack to compensate for the failure of click-and-drag
2148 { 2164 {
2149 mouse_slip_wheel_speed += v ? -1 : 1; 2165 mouse_slip_wheel_speed += v ? -1 : 1;
2150 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; 2166 if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow;
2151 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; 2167 if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow;
2152 2168
2169 if (!slip_wheel_ev.is_active ())
2153 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY); 2170 slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY);
2154 } 2171 }
2155 else 2172 else
2173# endif
2156 { 2174 {
2157# endif
2158 scr_page (v, i); 2175 scr_page (v, i);
2159 scrollbar_show (1); 2176 scrollBar.show (1);
2160# ifdef MOUSE_SLIP_WHEELING
2161 } 2177 }
2162# endif
2163 } 2178 }
2164 break; 2179 break;
2165#endif 2180#endif
2166 } 2181 }
2167 } 2182 }
2176 wchar_t ch = NOCHAR; 2191 wchar_t ch = NOCHAR;
2177 char *seq_begin; // remember start of esc-sequence here 2192 char *seq_begin; // remember start of esc-sequence here
2178 2193
2179 for (;;) 2194 for (;;)
2180 { 2195 {
2181 if (ch == NOCHAR) 2196 if (expect_false (ch == NOCHAR))
2182 { 2197 {
2183 seq_begin = cmdbuf_ptr; 2198 seq_begin = cmdbuf_ptr;
2184 ch = next_char (); 2199 ch = next_char ();
2185 2200
2186 if (ch == NOCHAR) 2201 if (ch == NOCHAR)
2187 break; 2202 break;
2188 } 2203 }
2189 2204
2190 if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) 2205 if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT))
2191 { 2206 {
2192 if (!seen_input) 2207 if (expect_false (!seen_input))
2193 { 2208 {
2194 seen_input = 1; 2209 seen_input = 1;
2195 // many badly-written programs (e.g. jed) contain a race condition: 2210 // many badly-written programs (e.g. jed) contain a race condition:
2196 // they first read the screensize and then install a SIGWINCH handler. 2211 // they first read the screensize and then install a SIGWINCH handler.
2197 // some window managers resize the window early, and these programs 2212 // some window managers resize the window early, and these programs
2210 wchar_t *str = buf; 2225 wchar_t *str = buf;
2211 wchar_t *eol = str + min (ncol, UBUFSIZ); 2226 wchar_t *eol = str + min (ncol, UBUFSIZ);
2212 2227
2213 for (;;) 2228 for (;;)
2214 { 2229 {
2215 if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) 2230 if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)))
2216 break; 2231 break;
2217 2232
2218 *str++ = ch; 2233 *str++ = ch;
2219 2234
2220 if (ch == C0_LF || str >= eol) 2235 if (expect_false (ch == C0_LF || str >= eol))
2221 { 2236 {
2222 if (ch == C0_LF) 2237 if (ch == C0_LF)
2223 nlines++; 2238 nlines++;
2224 2239
2225 refresh_count++; 2240 refresh_count++;
2226 2241
2227 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1) 2242 if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1)
2228 { 2243 {
2229 refresh_count = 0; 2244 refresh_count = 0;
2230 2245
2231 if (!option (Opt_skipScroll) || ev::ev_time () > ev::now () + 1. / 60.) 2246 if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.)
2232 { 2247 {
2233 refreshnow = true; 2248 refreshnow = true;
2234 ch = NOCHAR; 2249 ch = NOCHAR;
2235 break; 2250 break;
2236 } 2251 }
2307rxvt_term::next_char () NOTHROW 2322rxvt_term::next_char () NOTHROW
2308{ 2323{
2309 while (cmdbuf_ptr < cmdbuf_endp) 2324 while (cmdbuf_ptr < cmdbuf_endp)
2310 { 2325 {
2311 // assume 7-bit to be ascii ALWAYS 2326 // assume 7-bit to be ascii ALWAYS
2312 if ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) 2327 if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b))
2313 return *cmdbuf_ptr++; 2328 return *cmdbuf_ptr++;
2314 2329
2315 wchar_t wc; 2330 wchar_t wc;
2316 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); 2331 size_t len = mbrtowc (&wc, cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate);
2317 2332
2321 cmdbuf_ptr = cmdbuf_endp; 2336 cmdbuf_ptr = cmdbuf_endp;
2322 break; 2337 break;
2323 } 2338 }
2324 2339
2325 if (len == (size_t)-1) 2340 if (len == (size_t)-1)
2341 {
2342 mbrtowc (0, 0, 0, mbstate); // reset now undefined conversion state
2326 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through 2343 return (unsigned char)*cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through
2344 }
2327 2345
2328 // assume wchar == unicode 2346 // assume wchar == unicode
2329 cmdbuf_ptr += len; 2347 cmdbuf_ptr += len;
2330 return wc & UNICODE_MASK; 2348 return wc & UNICODE_MASK;
2331 } 2349 }
2375/*----------------------------------------------------------------------*/ 2393/*----------------------------------------------------------------------*/
2376#ifdef PRINTPIPE 2394#ifdef PRINTPIPE
2377FILE * 2395FILE *
2378rxvt_term::popen_printer () 2396rxvt_term::popen_printer ()
2379{ 2397{
2380 FILE *stream = popen (rs[Rs_print_pipe], "w"); 2398 FILE *stream = popen (rs[Rs_print_pipe] ? rs[Rs_print_pipe] : PRINTPIPE, "w");
2381 2399
2382 if (stream == NULL) 2400 if (stream == NULL)
2383 rxvt_warn ("can't open printer pipe, not printing.\n"); 2401 rxvt_warn ("can't open printer pipe, not printing.\n");
2384 2402
2385 return stream; 2403 return stream;
2396 * simulate attached vt100 printer 2414 * simulate attached vt100 printer
2397 */ 2415 */
2398void 2416void
2399rxvt_term::process_print_pipe () 2417rxvt_term::process_print_pipe ()
2400{ 2418{
2401 int done; 2419 FILE *fd = popen_printer ();
2402 FILE *fd;
2403 2420
2404 if ((fd = popen_printer ()) == NULL) 2421 if (!fd)
2405 return; 2422 return;
2406 2423
2407 /* 2424 /*
2408 * Send all input to the printer until either ESC[4i or ESC[?4i 2425 * Send all input to the printer until either ESC[4i or ESC[?4i
2409 * is received. 2426 * is received.
2410 */ 2427 */
2411 for (done = 0; !done;) 2428 for (int done = 0; !done; )
2412 { 2429 {
2413 unsigned char buf[8]; 2430 unsigned char buf[8];
2414 unicode_t ch; 2431 unicode_t ch;
2415 unsigned int i, len; 2432 unsigned int i, len;
2416 2433
2447 } 2464 }
2448 } 2465 }
2449 2466
2450 pclose_printer (fd); 2467 pclose_printer (fd);
2451} 2468}
2452#endif /* PRINTPIPE */ 2469#endif /* PRINTPIPE */
2453/*}}} */ 2470/*}}} */
2454 2471
2455/* *INDENT-OFF* */ 2472/* *INDENT-OFF* */
2456enum { 2473enum {
2457 C1_40 = 0x40, 2474 C1_40 = 0x40,
2561 break; 2578 break;
2562 case 'Z': /* identify the terminal type */ 2579 case 'Z': /* identify the terminal type */
2563 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ 2580 tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */
2564 break; 2581 break;
2565 case '<': /* turn off VT52 mode */ 2582 case '<': /* turn off VT52 mode */
2566 PrivMode (0, PrivMode_vt52); 2583 set_privmode (PrivMode_vt52, 0);
2567 break; 2584 break;
2568 case 'F': /* use special graphics character set */ 2585 case 'F': /* use special graphics character set */
2569 case 'G': /* use regular character set */ 2586 case 'G': /* use regular character set */
2570 /* unimplemented */ 2587 /* unimplemented */
2571 break; 2588 break;
2625 scr_forwardindex (); 2642 scr_forwardindex ();
2626 break; 2643 break;
2627#endif 2644#endif
2628 case '=': 2645 case '=':
2629 case '>': 2646 case '>':
2630 PrivMode ((ch == '='), PrivMode_aplKP); 2647 set_privmode (PrivMode_aplKP, ch == '=');
2631 break; 2648 break;
2632 2649
2633 case C1_40: 2650 case C1_40:
2634 cmd_getc (); 2651 cmd_getc ();
2635 break; 2652 break;
2688 2705
2689 /* 8.3.106: RESET TO INITIAL STATE */ 2706 /* 8.3.106: RESET TO INITIAL STATE */
2690 case 'c': 2707 case 'c':
2691 mbstate.reset (); 2708 mbstate.reset ();
2692 scr_poweron (); 2709 scr_poweron ();
2693 scrollbar_show (1); 2710 scrollBar.show (1);
2694 break; 2711 break;
2695 2712
2696 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */ 2713 /* 8.3.79: LOCKING-SHIFT TWO (see ISO2022) */
2697 case 'n': 2714 case 'n':
2698 scr_charset_choose (2); 2715 scr_charset_choose (2);
2750 nargs = 0; 2767 nargs = 0;
2751 2768
2752 priv = 0; 2769 priv = 0;
2753 ch = cmd_getc (); 2770 ch = cmd_getc ();
2754 if (ch >= '<' && ch <= '?') 2771 if (ch >= '<' && ch <= '?')
2772 {
2755 { /* '<' '=' '>' '?' */ 2773 /* '<' '=' '>' '?' */
2756 priv = ch; 2774 priv = ch;
2757 ch = cmd_getc (); 2775 ch = cmd_getc ();
2758 } 2776 }
2759 2777
2760 /* read any numerical arguments */ 2778 /* read any numerical arguments */
2809 // versions. 2827 // versions.
2810 // 2828 //
2811 tt_printf ("\033[>%d;95;0c", 'U'); 2829 tt_printf ("\033[>%d;95;0c", 'U');
2812 } 2830 }
2813 break; 2831 break;
2832
2814 case '?': 2833 case '?':
2815 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') 2834 if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't')
2816 process_terminal_mode (ch, priv, nargs, arg); 2835 process_terminal_mode (ch, priv, nargs, arg);
2817 break; 2836 break;
2818 } 2837 }
3334 *buf++ = '\0'; 3353 *buf++ = '\0';
3335 3354
3336 process_color_seq (op, color, name, resp); 3355 process_color_seq (op, color, name, resp);
3337 } 3356 }
3338 break; 3357 break;
3358 case Rxvt_restoreFG:
3339 case XTerm_Color00: 3359 case XTerm_Color00:
3340 process_color_seq (op, Color_fg, str, resp); 3360 process_color_seq (op, Color_fg, str, resp);
3341 break; 3361 break;
3362 case Rxvt_restoreBG:
3342 case XTerm_Color01: 3363 case XTerm_Color01:
3343 process_color_seq (op, Color_bg, str, resp); 3364 process_color_seq (op, Color_bg, str, resp);
3344 break; 3365 break;
3345#ifndef NO_CURSORCOLOR 3366#ifndef NO_CURSORCOLOR
3346 case XTerm_Color_cursor: 3367 case XTerm_Color_cursor:
3372#if ENABLE_TRANSPARENCY 3393#if ENABLE_TRANSPARENCY
3373 case URxvt_Color_tint: 3394 case URxvt_Color_tint:
3374 process_color_seq (op, Color_tint, str, resp); 3395 process_color_seq (op, Color_tint, str, resp);
3375 { 3396 {
3376 bool changed = false; 3397 bool changed = false;
3398
3377 if (ISSET_PIXCOLOR (Color_tint)) 3399 if (ISSET_PIXCOLOR (Color_tint))
3378 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]); 3400 changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]);
3379 else 3401 else
3380 changed = bgPixmap.unset_tint (); 3402 changed = bgPixmap.unset_tint ();
3403
3381 if (changed) 3404 if (changed)
3382 update_background (); 3405 update_background ();
3383 } 3406 }
3384 3407
3385 break; 3408 break;
3408 changed++; 3431 changed++;
3409 str = strchr (str, ';'); 3432 str = strchr (str, ';');
3410 if (str == NULL) 3433 if (str == NULL)
3411 bgPixmap.set_defaultGeometry (); 3434 bgPixmap.set_defaultGeometry ();
3412 } 3435 }
3436
3413 while (str) 3437 while (str)
3414 { 3438 {
3415 str++; 3439 str++;
3416 if (bgPixmap.set_geometry (str)) 3440 if (bgPixmap.set_geometry (str))
3417 changed++; 3441 changed++;
3418 str = strchr (str, ';'); 3442 str = strchr (str, ';');
3419 } 3443 }
3444
3420 if (changed) 3445 if (changed)
3421 update_background (); 3446 update_background ();
3422 } 3447 }
3423 break; 3448 break;
3424#endif 3449#endif
3425
3426 case Rxvt_restoreFG:
3427 set_window_color (Color_fg, str);
3428 break;
3429 case Rxvt_restoreBG:
3430 set_window_color (Color_bg, str);
3431 break;
3432 3450
3433 case XTerm_logfile: 3451 case XTerm_logfile:
3434 // TODO, when secure mode? 3452 // TODO, when secure mode?
3435 break; 3453 break;
3436 3454
3503 break; 3521 break;
3504#endif 3522#endif
3505 3523
3506#if ENABLE_PERL 3524#if ENABLE_PERL
3507 case URxvt_perl: 3525 case URxvt_perl:
3508 if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END))) 3526 HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_STR_LEN, &resp, 1, DT_END));
3509 ; // no responses yet
3510 break; 3527 break;
3511#endif 3528#endif
3512 } 3529 }
3513} 3530}
3514/*----------------------------------------------------------------------*/ 3531/*----------------------------------------------------------------------*/
3537 { 3554 {
3538 if (mode == 'r') 3555 if (mode == 'r')
3539 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */ 3556 state = (SavedModes & bit) ? 1 : 0; /* no overlapping */
3540 else 3557 else
3541 state = (mode == 't') ? ! (priv_modes & bit) : mode; 3558 state = (mode == 't') ? ! (priv_modes & bit) : mode;
3542 PrivMode (state, bit); 3559 set_privmode (bit, state);
3543 } 3560 }
3544 3561
3545 return state; 3562 return state;
3546} 3563}
3547 3564
3580 { 66, PrivMode_aplKP }, 3597 { 66, PrivMode_aplKP },
3581#ifndef NO_BACKSPACE_KEY 3598#ifndef NO_BACKSPACE_KEY
3582 { 67, PrivMode_BackSpace }, 3599 { 67, PrivMode_BackSpace },
3583#endif 3600#endif
3584 { 1000, PrivMode_MouseX11 }, 3601 { 1000, PrivMode_MouseX11 },
3585 // 1001 Use Hilite Mouse Tracking. NYI, TODO
3586 { 1002, PrivMode_MouseBtnEvent }, 3602 { 1002, PrivMode_MouseBtnEvent },
3587 { 1003, PrivMode_MouseAnyEvent }, 3603 { 1003, PrivMode_MouseAnyEvent },
3588 { 1010, PrivMode_TtyOutputInh }, // rxvt extension 3604 { 1010, PrivMode_TtyOutputInh }, // rxvt extension
3589 { 1011, PrivMode_Keypress }, // rxvt extension 3605 { 1011, PrivMode_Keypress }, // rxvt extension
3590 // 1035 enable modifiers for alt, numlock NYI 3606 // 1035 enable modifiers for alt, numlock NYI
3592 // 1037 send DEL for keypad delete NYI 3608 // 1037 send DEL for keypad delete NYI
3593 { 1047, PrivMode_Screen }, 3609 { 1047, PrivMode_Screen },
3594 // 1048 save and restore cursor 3610 // 1048 save and restore cursor
3595 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ 3611 { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */
3596 // 1051, 1052, 1060, 1061 keyboard emulation NYI 3612 // 1051, 1052, 1060, 1061 keyboard emulation NYI
3613 { 2004, PrivMode_BracketPaste },
3597 }; 3614 };
3598 3615
3599 if (nargs == 0) 3616 if (nargs == 0)
3600 return; 3617 return;
3601 3618
3645 case 2: /* VT52 mode */ 3662 case 2: /* VT52 mode */
3646 /* oddball mode. should be set regardless of set/reset 3663 /* oddball mode. should be set regardless of set/reset
3647 * parameter. Return from VT52 mode with an ESC < from 3664 * parameter. Return from VT52 mode with an ESC < from
3648 * within VT52 mode 3665 * within VT52 mode
3649 */ 3666 */
3650 PrivMode (1, PrivMode_vt52); 3667 set_privmode (PrivMode_vt52, 1);
3651 break; 3668 break;
3652 case 3: /* 80/132 */ 3669 case 3: /* 80/132 */
3653 if (priv_modes & PrivMode_132OK) 3670 if (priv_modes & PrivMode_132OK)
3671 {
3672 scr_poweron ();
3654 set_widthheight (((state ? 132 : 80) * fwidth), height); 3673 set_widthheight (((state ? 132 : 80) * fwidth), 24 * fheight);
3674 }
3655 break; 3675 break;
3656 case 4: /* smooth scrolling */ 3676 case 4: /* smooth scrolling */
3657 set_option (Opt_jumpScroll, !state); 3677 set_option (Opt_jumpScroll, !state);
3658 break; 3678 break;
3659 case 5: /* reverse video */ 3679 case 5: /* reverse video */
3670 if (state) /* orthogonal */ 3690 if (state) /* orthogonal */
3671 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); 3691 priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
3672 break; 3692 break;
3673#ifdef scrollBar_esc 3693#ifdef scrollBar_esc
3674 case scrollBar_esc: 3694 case scrollBar_esc:
3675 if (scrollbar_mapping (state)) 3695 if (scrollBar.map (state))
3676 { 3696 {
3677 resize_all_windows (0, 0, 0); 3697 resize_all_windows (0, 0, 0);
3678 scr_touch (true); 3698 scr_touch (true);
3679 } 3699 }
3680 break; 3700 break;
3691 /* case 67: - backspace key */ 3711 /* case 67: - backspace key */
3692 case 1000: /* X11 mouse reporting */ 3712 case 1000: /* X11 mouse reporting */
3693 if (state) /* orthogonal */ 3713 if (state) /* orthogonal */
3694 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); 3714 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent);
3695 break; 3715 break;
3696#if 0
3697 case 1001:
3698 break; /* X11 mouse highlighting */
3699#endif
3700 case 1002: 3716 case 1002:
3701 case 1003: 3717 case 1003:
3702 if (state) { 3718 if (state)
3719 {
3703 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11); 3720 priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11);
3704 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent; 3721 priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent;
3705 vt_emask_mouse = PointerMotionMask; 3722 vt_emask_mouse = PointerMotionMask;
3723 }
3706 } else 3724 else
3707 vt_emask_mouse = NoEventMask; 3725 vt_emask_mouse = NoEventMask;
3708 vt_select_input (); 3726 vt_select_input ();
3709 break; 3727 break;
3710 case 1010: /* scroll to bottom on TTY output inhibit */ 3728 case 1010: /* scroll to bottom on TTY output inhibit */
3711 set_option (Opt_scrollTtyOutput, !state); 3729 set_option (Opt_scrollTtyOutput, !state);
3891rxvt_term::process_graphics () 3909rxvt_term::process_graphics ()
3892{ 3910{
3893 unicode_t ch, cmd = cmd_getc (); 3911 unicode_t ch, cmd = cmd_getc ();
3894 3912
3895 if (cmd == 'Q') 3913 if (cmd == 'Q')
3914 {
3896 { /* query graphics */ 3915 /* query graphics */
3897 tt_printf ("\033G0\012"); /* no graphics */ 3916 tt_printf ("\033G0\012"); /* no graphics */
3898 return; 3917 return;
3899 } 3918 }
3900 /* swallow other graphics sequences until terminating ':' */ 3919 /* swallow other graphics sequences until terminating ':' */
3901 do 3920 do

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines