… | |
… | |
415 | rxvt_term::key_press (XKeyEvent &ev) |
415 | rxvt_term::key_press (XKeyEvent &ev) |
416 | { |
416 | { |
417 | int ctrl, meta, shft, len; |
417 | int ctrl, meta, shft, len; |
418 | KeySym keysym; |
418 | KeySym keysym; |
419 | int valid_keysym; |
419 | int valid_keysym; |
420 | char rkbuf[KBUFSZ]; |
420 | char rkbuf[KBUFSZ + 1]; |
421 | char *kbuf = rkbuf + 1; |
421 | char *kbuf = rkbuf + 1; |
422 | |
422 | |
423 | #if ISO_14755 |
423 | #if ISO_14755 |
424 | if (iso14755buf & ISO_14755_52) |
424 | if (iso14755buf & ISO_14755_52) |
425 | return; |
425 | return; |
… | |
… | |
496 | valid_keysym = keysym != NoSymbol; |
496 | valid_keysym = keysym != NoSymbol; |
497 | } |
497 | } |
498 | |
498 | |
499 | if (valid_keysym) |
499 | if (valid_keysym) |
500 | { |
500 | { |
|
|
501 | if (keysym >= 0xFF00 && keysym <= 0xFFFF) |
|
|
502 | { |
|
|
503 | bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; |
|
|
504 | unsigned int newlen = 1; |
|
|
505 | |
|
|
506 | if (ev.state & ModNumLockMask) |
|
|
507 | kp = false; |
|
|
508 | |
|
|
509 | keysym = translate_keypad (keysym, kp); |
|
|
510 | |
|
|
511 | switch (keysym) |
|
|
512 | { |
|
|
513 | #ifndef NO_BACKSPACE_KEY |
|
|
514 | case XK_BackSpace: |
|
|
515 | if (priv_modes & PrivMode_HaveBackSpace) |
|
|
516 | { |
|
|
517 | kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) |
|
|
518 | ^ !!ctrl) ? '\b' : '\177'; |
|
|
519 | kbuf[1] = '\0'; |
|
|
520 | } |
|
|
521 | else |
|
|
522 | strcpy (kbuf, rs[Rs_backspace_key]); |
|
|
523 | break; |
|
|
524 | #endif |
|
|
525 | #ifndef NO_DELETE_KEY |
|
|
526 | case XK_Delete: |
|
|
527 | strcpy (kbuf, rs[Rs_delete_key]); |
|
|
528 | break; |
|
|
529 | #endif |
|
|
530 | case XK_Tab: |
|
|
531 | if (shft) |
|
|
532 | strcpy (kbuf, "\033[Z"); |
|
|
533 | else |
|
|
534 | { |
|
|
535 | #ifdef CTRL_TAB_MAKES_META |
|
|
536 | if (ctrl) |
|
|
537 | meta = 1; |
|
|
538 | #endif |
|
|
539 | #ifdef MOD4_TAB_MAKES_META |
|
|
540 | if (ev.state & Mod4Mask) |
|
|
541 | meta = 1; |
|
|
542 | #endif |
|
|
543 | newlen = 0; |
|
|
544 | } |
|
|
545 | break; |
|
|
546 | |
|
|
547 | case XK_Up: /* "\033[A" */ |
|
|
548 | case XK_Down: /* "\033[B" */ |
|
|
549 | case XK_Right: /* "\033[C" */ |
|
|
550 | case XK_Left: /* "\033[D" */ |
|
|
551 | strcpy (kbuf, "\033[Z"); |
|
|
552 | kbuf[2] = "DACB"[keysym - XK_Left]; |
|
|
553 | /* do Shift first */ |
|
|
554 | if (shft) |
|
|
555 | kbuf[2] = "dacb"[keysym - XK_Left]; |
|
|
556 | else if (ctrl) |
|
|
557 | { |
|
|
558 | kbuf[1] = 'O'; |
|
|
559 | kbuf[2] = "dacb"[keysym - XK_Left]; |
|
|
560 | } |
|
|
561 | else if (priv_modes & PrivMode_aplCUR) |
|
|
562 | kbuf[1] = 'O'; |
|
|
563 | break; |
|
|
564 | |
|
|
565 | case XK_KP_Enter: |
|
|
566 | /* allow shift to override */ |
|
|
567 | if (kp) |
|
|
568 | { |
|
|
569 | strcpy (kbuf, "\033OM"); |
|
|
570 | break; |
|
|
571 | } |
|
|
572 | |
|
|
573 | /* FALLTHROUGH */ |
|
|
574 | |
|
|
575 | case XK_Return: |
|
|
576 | if (priv_modes & PrivMode_LFNL) |
|
|
577 | { |
|
|
578 | kbuf[0] = '\015'; |
|
|
579 | kbuf[1] = '\012'; |
|
|
580 | kbuf[2] = '\0'; |
|
|
581 | } |
|
|
582 | else |
|
|
583 | { |
|
|
584 | kbuf[0] = '\015'; |
|
|
585 | kbuf[1] = '\0'; |
|
|
586 | } |
|
|
587 | break; |
|
|
588 | |
|
|
589 | case XK_KP_F1: /* "\033OP" */ |
|
|
590 | case XK_KP_F2: /* "\033OQ" */ |
|
|
591 | case XK_KP_F3: /* "\033OR" */ |
|
|
592 | case XK_KP_F4: /* "\033OS" */ |
|
|
593 | strcpy (kbuf, "\033OP"); |
|
|
594 | kbuf[2] += (keysym - XK_KP_F1); |
|
|
595 | break; |
|
|
596 | |
|
|
597 | case XK_KP_Multiply: /* "\033Oj" : "*" */ |
|
|
598 | case XK_KP_Add: /* "\033Ok" : "+" */ |
|
|
599 | case XK_KP_Separator: /* "\033Ol" : "," */ |
|
|
600 | case XK_KP_Subtract: /* "\033Om" : "-" */ |
|
|
601 | case XK_KP_Decimal: /* "\033On" : "." */ |
|
|
602 | case XK_KP_Divide: /* "\033Oo" : "/" */ |
|
|
603 | case XK_KP_0: /* "\033Op" : "0" */ |
|
|
604 | case XK_KP_1: /* "\033Oq" : "1" */ |
|
|
605 | case XK_KP_2: /* "\033Or" : "2" */ |
|
|
606 | case XK_KP_3: /* "\033Os" : "3" */ |
|
|
607 | case XK_KP_4: /* "\033Ot" : "4" */ |
|
|
608 | case XK_KP_5: /* "\033Ou" : "5" */ |
|
|
609 | case XK_KP_6: /* "\033Ov" : "6" */ |
|
|
610 | case XK_KP_7: /* "\033Ow" : "7" */ |
|
|
611 | case XK_KP_8: /* "\033Ox" : "8" */ |
|
|
612 | case XK_KP_9: /* "\033Oy" : "9" */ |
|
|
613 | /* allow shift to override */ |
|
|
614 | if (kp) |
|
|
615 | { |
|
|
616 | strcpy (kbuf, "\033Oj"); |
|
|
617 | kbuf[2] += (keysym - XK_KP_Multiply); |
|
|
618 | } |
|
|
619 | else |
|
|
620 | { |
|
|
621 | kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); |
|
|
622 | kbuf[1] = '\0'; |
|
|
623 | } |
|
|
624 | break; |
|
|
625 | |
|
|
626 | default: |
|
|
627 | { |
|
|
628 | int param = map_function_key (keysym); |
|
|
629 | if (param > 0) |
|
|
630 | sprintf (kbuf,"\033[%d~", param); |
|
|
631 | else |
|
|
632 | newlen = 0; |
|
|
633 | } |
|
|
634 | break; |
|
|
635 | } |
|
|
636 | |
|
|
637 | if (newlen) |
|
|
638 | len = strlen (kbuf); |
|
|
639 | |
|
|
640 | if (len > 0) |
|
|
641 | { |
|
|
642 | /* |
|
|
643 | * pass Shift/Control indicators for function keys ending with `~' |
|
|
644 | * |
|
|
645 | * eg, |
|
|
646 | * Prior = "ESC[5~" |
|
|
647 | * Shift+Prior = "ESC[5$" |
|
|
648 | * Ctrl+Prior = "ESC[5^" |
|
|
649 | * Ctrl+Shift+Prior = "ESC[5@" |
|
|
650 | */ |
|
|
651 | if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') |
|
|
652 | kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); |
|
|
653 | |
|
|
654 | /* |
|
|
655 | * Pass meta for all function keys, if 'meta' option set |
|
|
656 | */ |
|
|
657 | #ifdef META8_OPTION |
|
|
658 | if (meta && (meta_char == 0x80)) |
|
|
659 | kbuf[len - 1] |= 0x80; |
|
|
660 | #endif |
|
|
661 | } |
|
|
662 | |
|
|
663 | } |
|
|
664 | else if (ctrl && keysym == XK_minus) |
|
|
665 | { |
|
|
666 | len = 1; |
|
|
667 | kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ |
|
|
668 | } |
|
|
669 | else if (keysym == XK_ISO_Left_Tab) |
|
|
670 | { |
|
|
671 | strcpy (kbuf, "\033[Z"); |
|
|
672 | len = 3; |
|
|
673 | } |
|
|
674 | else |
|
|
675 | { |
|
|
676 | #ifdef META8_OPTION |
|
|
677 | /* set 8-bit on */ |
|
|
678 | if (meta && (meta_char == 0x80)) |
|
|
679 | { |
|
|
680 | char *ch; |
|
|
681 | |
|
|
682 | for (ch = kbuf; ch < kbuf + len; ch++) |
|
|
683 | *ch |= 0x80; |
|
|
684 | |
|
|
685 | meta = 0; |
|
|
686 | } |
|
|
687 | #endif |
|
|
688 | /* nil */ ; |
|
|
689 | } |
|
|
690 | } |
|
|
691 | |
|
|
692 | /* escape prefix */ |
|
|
693 | if (len && meta |
|
|
694 | #ifdef META8_OPTION |
|
|
695 | && meta_char == C0_ESC |
|
|
696 | #endif |
|
|
697 | ) |
|
|
698 | { |
|
|
699 | *--kbuf = C0_ESC; |
|
|
700 | len++; |
|
|
701 | } |
|
|
702 | |
|
|
703 | if (valid_keysym) |
|
|
704 | { |
501 | #ifdef KEYSYM_RESOURCE |
705 | #ifdef KEYSYM_RESOURCE |
502 | if (keyboard->dispatch (this, keysym, ev.state)) |
706 | if (keyboard->dispatch (this, keysym, ev.state, kbuf, len)) |
503 | return; |
707 | return; |
504 | #endif |
708 | #endif |
505 | |
709 | |
506 | if (saveLines) |
710 | if (saveLines) |
507 | { |
711 | { |
… | |
… | |
665 | { |
869 | { |
666 | scr_printscreen (ctrl | shft); |
870 | scr_printscreen (ctrl | shft); |
667 | return; |
871 | return; |
668 | } |
872 | } |
669 | #endif |
873 | #endif |
670 | |
|
|
671 | if (keysym >= 0xFF00 && keysym <= 0xFFFF) |
|
|
672 | { |
|
|
673 | bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; |
|
|
674 | unsigned int newlen = 1; |
|
|
675 | |
|
|
676 | if (ev.state & ModNumLockMask) |
|
|
677 | kp = false; |
|
|
678 | |
|
|
679 | keysym = translate_keypad (keysym, kp); |
|
|
680 | |
|
|
681 | switch (keysym) |
|
|
682 | { |
|
|
683 | #ifndef NO_BACKSPACE_KEY |
|
|
684 | case XK_BackSpace: |
|
|
685 | if (priv_modes & PrivMode_HaveBackSpace) |
|
|
686 | { |
|
|
687 | kbuf[0] = (!! (priv_modes & PrivMode_BackSpace) |
|
|
688 | ^ !!ctrl) ? '\b' : '\177'; |
|
|
689 | kbuf[1] = '\0'; |
|
|
690 | } |
|
|
691 | else |
|
|
692 | strcpy (kbuf, rs[Rs_backspace_key]); |
|
|
693 | break; |
|
|
694 | #endif |
|
|
695 | #ifndef NO_DELETE_KEY |
|
|
696 | case XK_Delete: |
|
|
697 | strcpy (kbuf, rs[Rs_delete_key]); |
|
|
698 | break; |
|
|
699 | #endif |
|
|
700 | case XK_Tab: |
|
|
701 | if (shft) |
|
|
702 | strcpy (kbuf, "\033[Z"); |
|
|
703 | else |
|
|
704 | { |
|
|
705 | #ifdef CTRL_TAB_MAKES_META |
|
|
706 | if (ctrl) |
|
|
707 | meta = 1; |
|
|
708 | #endif |
|
|
709 | #ifdef MOD4_TAB_MAKES_META |
|
|
710 | if (ev.state & Mod4Mask) |
|
|
711 | meta = 1; |
|
|
712 | #endif |
|
|
713 | newlen = 0; |
|
|
714 | } |
|
|
715 | break; |
|
|
716 | |
|
|
717 | case XK_Up: /* "\033[A" */ |
|
|
718 | case XK_Down: /* "\033[B" */ |
|
|
719 | case XK_Right: /* "\033[C" */ |
|
|
720 | case XK_Left: /* "\033[D" */ |
|
|
721 | strcpy (kbuf, "\033[Z"); |
|
|
722 | kbuf[2] = "DACB"[keysym - XK_Left]; |
|
|
723 | /* do Shift first */ |
|
|
724 | if (shft) |
|
|
725 | kbuf[2] = "dacb"[keysym - XK_Left]; |
|
|
726 | else if (ctrl) |
|
|
727 | { |
|
|
728 | kbuf[1] = 'O'; |
|
|
729 | kbuf[2] = "dacb"[keysym - XK_Left]; |
|
|
730 | } |
|
|
731 | else if (priv_modes & PrivMode_aplCUR) |
|
|
732 | kbuf[1] = 'O'; |
|
|
733 | break; |
|
|
734 | |
|
|
735 | case XK_KP_Enter: |
|
|
736 | /* allow shift to override */ |
|
|
737 | if (kp) |
|
|
738 | { |
|
|
739 | strcpy (kbuf, "\033OM"); |
|
|
740 | break; |
|
|
741 | } |
|
|
742 | |
|
|
743 | /* FALLTHROUGH */ |
|
|
744 | |
|
|
745 | case XK_Return: |
|
|
746 | if (priv_modes & PrivMode_LFNL) |
|
|
747 | { |
|
|
748 | kbuf[0] = '\015'; |
|
|
749 | kbuf[1] = '\012'; |
|
|
750 | kbuf[2] = '\0'; |
|
|
751 | } |
|
|
752 | else |
|
|
753 | { |
|
|
754 | kbuf[0] = '\015'; |
|
|
755 | kbuf[1] = '\0'; |
|
|
756 | } |
|
|
757 | break; |
|
|
758 | |
|
|
759 | case XK_KP_F1: /* "\033OP" */ |
|
|
760 | case XK_KP_F2: /* "\033OQ" */ |
|
|
761 | case XK_KP_F3: /* "\033OR" */ |
|
|
762 | case XK_KP_F4: /* "\033OS" */ |
|
|
763 | strcpy (kbuf, "\033OP"); |
|
|
764 | kbuf[2] += (keysym - XK_KP_F1); |
|
|
765 | break; |
|
|
766 | |
|
|
767 | case XK_KP_Multiply: /* "\033Oj" : "*" */ |
|
|
768 | case XK_KP_Add: /* "\033Ok" : "+" */ |
|
|
769 | case XK_KP_Separator: /* "\033Ol" : "," */ |
|
|
770 | case XK_KP_Subtract: /* "\033Om" : "-" */ |
|
|
771 | case XK_KP_Decimal: /* "\033On" : "." */ |
|
|
772 | case XK_KP_Divide: /* "\033Oo" : "/" */ |
|
|
773 | case XK_KP_0: /* "\033Op" : "0" */ |
|
|
774 | case XK_KP_1: /* "\033Oq" : "1" */ |
|
|
775 | case XK_KP_2: /* "\033Or" : "2" */ |
|
|
776 | case XK_KP_3: /* "\033Os" : "3" */ |
|
|
777 | case XK_KP_4: /* "\033Ot" : "4" */ |
|
|
778 | case XK_KP_5: /* "\033Ou" : "5" */ |
|
|
779 | case XK_KP_6: /* "\033Ov" : "6" */ |
|
|
780 | case XK_KP_7: /* "\033Ow" : "7" */ |
|
|
781 | case XK_KP_8: /* "\033Ox" : "8" */ |
|
|
782 | case XK_KP_9: /* "\033Oy" : "9" */ |
|
|
783 | /* allow shift to override */ |
|
|
784 | if (kp) |
|
|
785 | { |
|
|
786 | strcpy (kbuf, "\033Oj"); |
|
|
787 | kbuf[2] += (keysym - XK_KP_Multiply); |
|
|
788 | } |
|
|
789 | else |
|
|
790 | { |
|
|
791 | kbuf[0] = ('*' + (keysym - XK_KP_Multiply)); |
|
|
792 | kbuf[1] = '\0'; |
|
|
793 | } |
|
|
794 | break; |
|
|
795 | |
|
|
796 | default: |
|
|
797 | { |
|
|
798 | int param = map_function_key (keysym); |
|
|
799 | if (param > 0) |
|
|
800 | sprintf (kbuf,"\033[%d~", param); |
|
|
801 | else |
|
|
802 | newlen = 0; |
|
|
803 | } |
|
|
804 | break; |
|
|
805 | } |
|
|
806 | |
|
|
807 | if (newlen) |
|
|
808 | len = strlen (kbuf); |
|
|
809 | |
|
|
810 | if (len > 0) |
|
|
811 | { |
|
|
812 | /* |
|
|
813 | * pass Shift/Control indicators for function keys ending with `~' |
|
|
814 | * |
|
|
815 | * eg, |
|
|
816 | * Prior = "ESC[5~" |
|
|
817 | * Shift+Prior = "ESC[5$" |
|
|
818 | * Ctrl+Prior = "ESC[5^" |
|
|
819 | * Ctrl+Shift+Prior = "ESC[5@" |
|
|
820 | */ |
|
|
821 | if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') |
|
|
822 | kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); |
|
|
823 | |
|
|
824 | /* |
|
|
825 | * Pass meta for all function keys, if 'meta' option set |
|
|
826 | */ |
|
|
827 | #ifdef META8_OPTION |
|
|
828 | if (meta && (meta_char == 0x80)) |
|
|
829 | kbuf[len - 1] |= 0x80; |
|
|
830 | #endif |
|
|
831 | } |
|
|
832 | |
|
|
833 | } |
|
|
834 | else if (ctrl && keysym == XK_minus) |
|
|
835 | { |
|
|
836 | len = 1; |
|
|
837 | kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ |
|
|
838 | } |
|
|
839 | else if (keysym == XK_ISO_Left_Tab) |
|
|
840 | { |
|
|
841 | strcpy (kbuf, "\033[Z"); |
|
|
842 | len = 3; |
|
|
843 | } |
|
|
844 | else |
|
|
845 | { |
|
|
846 | #ifdef META8_OPTION |
|
|
847 | /* set 8-bit on */ |
|
|
848 | if (meta && (meta_char == 0x80)) |
|
|
849 | { |
|
|
850 | char *ch; |
|
|
851 | |
|
|
852 | for (ch = kbuf; ch < kbuf + len; ch++) |
|
|
853 | *ch |= 0x80; |
|
|
854 | |
|
|
855 | meta = 0; |
|
|
856 | } |
|
|
857 | #endif |
|
|
858 | /* nil */ ; |
|
|
859 | } |
|
|
860 | } |
|
|
861 | |
|
|
862 | /* escape prefix */ |
|
|
863 | if (len && meta |
|
|
864 | #ifdef META8_OPTION |
|
|
865 | && meta_char == C0_ESC |
|
|
866 | #endif |
|
|
867 | ) |
|
|
868 | { |
|
|
869 | *--kbuf = C0_ESC; |
|
|
870 | len++; |
|
|
871 | } |
874 | } |
872 | |
875 | |
873 | if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) |
876 | if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) |
874 | return; |
877 | return; |
875 | |
878 | |