Mercurial > vim
annotate src/libvterm/src/keyboard.c @ 18279:e8d1f3209dcd v8.1.2134
patch 8.1.2134: modifier keys are not always recognized
Commit: https://github.com/vim/vim/commit/6a0299d8f4c7a64c64d60a6bb39cfe6eaf892247
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 10 21:14:03 2019 +0200
patch 8.1.2134: modifier keys are not always recognized
Problem: Modifier keys are not always recognized.
Solution: Handle key codes generated by xterm with modifyOtherKeys set.
Add this to libvterm so we can debug it.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 10 Oct 2019 21:15:04 +0200 |
parents | 811a12a78164 |
children | ffadba5f898c |
rev | line source |
---|---|
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 #include "vterm_internal.h" |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 #include <stdio.h> |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 #include "utf8.h" |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
7 int vterm_is_modify_other_keys(VTerm *vt) |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
8 { |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
9 return vt->state->mode.modify_other_keys; |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
10 } |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
11 |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
12 |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 void vterm_keyboard_unichar(VTerm *vt, uint32_t c, VTermModifier mod) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 int needs_CSIu; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 |
18279
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
17 if (vt->state->mode.modify_other_keys && mod != 0) { |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
18 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "27;%d;%d~", mod+1, c); |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
19 return; |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
20 } |
e8d1f3209dcd
patch 8.1.2134: modifier keys are not always recognized
Bram Moolenaar <Bram@vim.org>
parents:
17777
diff
changeset
|
21 |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
22 // The shift modifier is never important for Unicode characters |
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
23 // apart from Space |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 if(c != ' ') |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
25 mod &= ~VTERM_MOD_SHIFT; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
26 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
27 if(mod == 0) { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
28 // Normal text - ignore just shift |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
29 char str[6]; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
30 int seqlen = fill_utf8(c, str); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 vterm_push_output_bytes(vt, str, seqlen); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
32 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
33 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
34 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 switch(c) { |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
36 // Special Ctrl- letters that can't be represented elsewise |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 case 'i': case 'j': case 'm': case '[': |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 needs_CSIu = 1; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 break; |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
40 // Ctrl-\ ] ^ _ don't need CSUu |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 case '\\': case ']': case '^': case '_': |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
42 needs_CSIu = 0; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
43 break; |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
44 // Shift-space needs CSIu |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
45 case ' ': |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
46 needs_CSIu = !!(mod & VTERM_MOD_SHIFT); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
47 break; |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
48 // All other characters needs CSIu except for letters a-z |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
49 default: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
50 needs_CSIu = (c < 'a' || c > 'z'); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
51 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
52 |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
53 // ALT we can just prefix with ESC; anything else requires CSI u |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
54 if(needs_CSIu && (mod & ~VTERM_MOD_ALT)) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
55 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%du", c, mod+1); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
56 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
57 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
58 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
59 if(mod & VTERM_MOD_CTRL) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
60 c &= 0x1f; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
61 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
62 vterm_push_output_sprintf(vt, "%s%c", mod & VTERM_MOD_ALT ? ESC_S : "", c); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
63 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
64 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
65 typedef struct { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
66 enum { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
67 KEYCODE_NONE, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
68 KEYCODE_LITERAL, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
69 KEYCODE_TAB, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
70 KEYCODE_ENTER, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
71 KEYCODE_SS3, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
72 KEYCODE_CSI, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
73 KEYCODE_CSI_CURSOR, |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
74 KEYCODE_CSINUM, |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
75 KEYCODE_KEYPAD, |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
76 } type; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
77 char literal; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
78 int csinum; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
79 } keycodes_s; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
80 |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
81 // Order here must be exactly the same as VTermKey enum! |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
82 static keycodes_s keycodes[] = { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
83 { KEYCODE_NONE, 0, 0 }, // NONE |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
84 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
85 { KEYCODE_ENTER, '\r', 0 }, // ENTER |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
86 { KEYCODE_TAB, '\t', 0 }, // TAB |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
87 { KEYCODE_LITERAL, '\x7f', 0 }, // BACKSPACE == ASCII DEL |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
88 { KEYCODE_LITERAL, '\x1b', 0 }, // ESCAPE |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
89 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
90 { KEYCODE_CSI_CURSOR, 'A', 0 }, // UP |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
91 { KEYCODE_CSI_CURSOR, 'B', 0 }, // DOWN |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
92 { KEYCODE_CSI_CURSOR, 'D', 0 }, // LEFT |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
93 { KEYCODE_CSI_CURSOR, 'C', 0 }, // RIGHT |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
94 |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
95 { KEYCODE_CSINUM, '~', 2 }, // INS |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
96 { KEYCODE_CSINUM, '~', 3 }, // DEL |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
97 { KEYCODE_CSI_CURSOR, 'H', 0 }, // HOME |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
98 { KEYCODE_CSI_CURSOR, 'F', 0 }, // END |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
99 { KEYCODE_CSINUM, '~', 5 }, // PAGEUP |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
100 { KEYCODE_CSINUM, '~', 6 }, // PAGEDOWN |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
101 }; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
102 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
103 static keycodes_s keycodes_fn[] = { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
104 { KEYCODE_NONE, 0, 0 }, // F0 - shouldn't happen |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
105 { KEYCODE_CSI_CURSOR, 'P', 0 }, // F1 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
106 { KEYCODE_CSI_CURSOR, 'Q', 0 }, // F2 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
107 { KEYCODE_CSI_CURSOR, 'R', 0 }, // F3 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
108 { KEYCODE_CSI_CURSOR, 'S', 0 }, // F4 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
109 { KEYCODE_CSINUM, '~', 15 }, // F5 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
110 { KEYCODE_CSINUM, '~', 17 }, // F6 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
111 { KEYCODE_CSINUM, '~', 18 }, // F7 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
112 { KEYCODE_CSINUM, '~', 19 }, // F8 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
113 { KEYCODE_CSINUM, '~', 20 }, // F9 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
114 { KEYCODE_CSINUM, '~', 21 }, // F10 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
115 { KEYCODE_CSINUM, '~', 23 }, // F11 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
116 { KEYCODE_CSINUM, '~', 24 }, // F12 |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
117 }; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
118 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
119 static keycodes_s keycodes_kp[] = { |
13770
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
120 { KEYCODE_KEYPAD, '0', 'p' }, // KP_0 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
121 { KEYCODE_KEYPAD, '1', 'q' }, // KP_1 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
122 { KEYCODE_KEYPAD, '2', 'r' }, // KP_2 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
123 { KEYCODE_KEYPAD, '3', 's' }, // KP_3 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
124 { KEYCODE_KEYPAD, '4', 't' }, // KP_4 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
125 { KEYCODE_KEYPAD, '5', 'u' }, // KP_5 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
126 { KEYCODE_KEYPAD, '6', 'v' }, // KP_6 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
127 { KEYCODE_KEYPAD, '7', 'w' }, // KP_7 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
128 { KEYCODE_KEYPAD, '8', 'x' }, // KP_8 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
129 { KEYCODE_KEYPAD, '9', 'y' }, // KP_9 |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
130 { KEYCODE_KEYPAD, '*', 'j' }, // KP_MULT |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
131 { KEYCODE_KEYPAD, '+', 'k' }, // KP_PLUS |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
132 { KEYCODE_KEYPAD, ',', 'l' }, // KP_COMMA |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
133 { KEYCODE_KEYPAD, '-', 'm' }, // KP_MINUS |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
134 { KEYCODE_KEYPAD, '.', 'n' }, // KP_PERIOD |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
135 { KEYCODE_KEYPAD, '/', 'o' }, // KP_DIVIDE |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
136 { KEYCODE_KEYPAD, '\n', 'M' }, // KP_ENTER |
2449b6ce1456
patch 8.0.1757: unnecessary changes in libvterm
Christian Brabandt <cb@256bit.org>
parents:
11761
diff
changeset
|
137 { KEYCODE_KEYPAD, '=', 'X' }, // KP_EQUAL |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
138 }; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
139 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
140 void vterm_keyboard_key(VTerm *vt, VTermKey key, VTermModifier mod) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
141 { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
142 keycodes_s k; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
143 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
144 if(key == VTERM_KEY_NONE) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
145 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
146 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
147 if(key < VTERM_KEY_FUNCTION_0) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
148 if(key >= sizeof(keycodes)/sizeof(keycodes[0])) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
149 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
150 k = keycodes[key]; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
151 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
152 else if(key >= VTERM_KEY_FUNCTION_0 && key <= VTERM_KEY_FUNCTION_MAX) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
153 if((key - VTERM_KEY_FUNCTION_0) >= sizeof(keycodes_fn)/sizeof(keycodes_fn[0])) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
154 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
155 k = keycodes_fn[key - VTERM_KEY_FUNCTION_0]; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
156 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
157 else if(key >= VTERM_KEY_KP_0) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
158 if((key - VTERM_KEY_KP_0) >= sizeof(keycodes_kp)/sizeof(keycodes_kp[0])) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
159 return; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
160 k = keycodes_kp[key - VTERM_KEY_KP_0]; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
161 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
162 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
163 switch(k.type) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
164 case KEYCODE_NONE: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
165 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
166 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
167 case KEYCODE_TAB: |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
168 // Shift-Tab is CSI Z but plain Tab is 0x09 |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
169 if(mod == VTERM_MOD_SHIFT) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
170 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "Z"); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
171 else if(mod & VTERM_MOD_SHIFT) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
172 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "1;%dZ", mod+1); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
173 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
174 goto case_LITERAL; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
175 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
176 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
177 case KEYCODE_ENTER: |
17777
811a12a78164
patch 8.1.1885: comments in libvterm are inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
13770
diff
changeset
|
178 // Enter is CRLF in newline mode, but just LF in linefeed |
11621
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
179 if(vt->state->mode.newline) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
180 vterm_push_output_sprintf(vt, "\r\n"); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
181 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
182 goto case_LITERAL; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
183 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
184 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
185 case KEYCODE_LITERAL: case_LITERAL: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
186 if(mod & (VTERM_MOD_SHIFT|VTERM_MOD_CTRL)) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
187 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%du", k.literal, mod+1); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
188 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
189 vterm_push_output_sprintf(vt, mod & VTERM_MOD_ALT ? ESC_S "%c" : "%c", k.literal); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
190 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
191 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
192 case KEYCODE_SS3: case_SS3: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
193 if(mod == 0) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
194 vterm_push_output_sprintf_ctrl(vt, C1_SS3, "%c", k.literal); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
195 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
196 goto case_CSI; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
197 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
198 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
199 case KEYCODE_CSI: case_CSI: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
200 if(mod == 0) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
201 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%c", k.literal); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
202 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
203 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "1;%d%c", mod + 1, k.literal); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
204 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
205 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 case KEYCODE_CSINUM: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 if(mod == 0) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
208 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d%c", k.csinum, k.literal); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
209 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
210 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "%d;%d%c", k.csinum, mod + 1, k.literal); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
211 break; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
212 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 case KEYCODE_CSI_CURSOR: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
214 if(vt->state->mode.cursor) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
215 goto case_SS3; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
216 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
217 goto case_CSI; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
218 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 case KEYCODE_KEYPAD: |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
220 if(vt->state->mode.keypad) { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
221 k.literal = k.csinum; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 goto case_SS3; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
223 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
224 else |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
225 goto case_LITERAL; |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
226 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
228 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
229 void vterm_keyboard_start_paste(VTerm *vt) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
230 { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
231 if(vt->state->mode.bracketpaste) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
232 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "200~"); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 } |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
234 |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 void vterm_keyboard_end_paste(VTerm *vt) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 { |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 if(vt->state->mode.bracketpaste) |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
238 vterm_push_output_sprintf_ctrl(vt, C1_CSI, "201~"); |
b8299e742f41
patch 8.0.0693: no terminal emulator support
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 } |