summaryrefslogtreecommitdiff
path: root/src/bin/keyin.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2014-09-21 18:27:23 +0200
committerBoris Faure <billiob@gmail.com>2014-09-21 23:46:49 +0200
commit671fe7967b613c51b9de670a5955dbc9fe3f3f6f (patch)
tree4fcd5f6abc3d10c8fe1aa2fdbff262bfd74de073 /src/bin/keyin.c
parenta61c34999597113929bd477e891b0042ed89d130 (diff)
generate tty_keys.h from xterm itself
Script gen_tty_keys.sh is heavily based on the script escapes.sh by Egmont Koblinger. Closes T1564
Diffstat (limited to 'src/bin/keyin.c')
-rw-r--r--src/bin/keyin.c550
1 files changed, 114 insertions, 436 deletions
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index 5d045bc..d2f230c 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -8,14 +8,30 @@
8#include "termcmd.h" 8#include "termcmd.h"
9#include "keyin.h" 9#include "keyin.h"
10 10
11typedef struct _Keyout Keyout; 11typedef struct _Tty_Key Tty_Key;
12typedef struct _Key_Values Key_Values;
12 13
13struct _Keyout 14struct _s {
15 char *s;
16 ssize_t len;
17};
18
19struct _Key_Values {
20 struct _s plain;
21 struct _s alt;
22 struct _s ctrl;
23 struct _s ctrl_alt;
24 struct _s shift;
25 struct _s shift_alt;
26 struct _s shift_ctrl;
27 struct _s shift_ctrl_alt;
28};
29struct _Tty_Key
14{ 30{
15 const char *in; 31 char *key;
16 const char *out; 32 int key_len;
17 int inlen; 33 Key_Values default_mode;
18 int outlen; 34 Key_Values cursor;
19}; 35};
20 36
21typedef struct _Key_Binding Key_Binding; 37typedef struct _Key_Binding Key_Binding;
@@ -36,386 +52,46 @@ static Eina_Hash *_key_bindings = NULL;
36 52
37/* {{{ Keys to TTY */ 53/* {{{ Keys to TTY */
38 54
39#define KEY(in, out) {in, out, sizeof(in) - 1, sizeof(out) - 1}
40
41static const Keyout crlf_keyout[] =
42{
43 KEY("Return", "\r\n"),
44
45 KEY(NULL, "END")
46};
47
48static const Keyout nocrlf_keyout[] =
49{
50 KEY("Return", "\r"),
51
52 KEY(NULL, "END")
53};
54
55static const Keyout appcur_keyout[] =
56{
57 KEY("Left", "\033OD"),
58 KEY("Right", "\033OC"),
59 KEY("Up", "\033OA"),
60 KEY("Down", "\033OB"),
61 KEY("Home", "\033OH"),
62 KEY("End", "\033OF"),
63//// why did i change these?
64// KEY("Home", "\033[7~"),
65// KEY("End", "\033[8~"),
66 KEY("F1", "\033OP"),
67 KEY("F2", "\033OQ"),
68 KEY("F3", "\033OR"),
69 KEY("F4", "\033OS"),
70
71 KEY(NULL, "END")
72};
73
74static const Keyout ctrl_keyout[] =
75{
76 KEY("Left", "\033[1;5D"),
77 KEY("Right", "\033[1;5C"),
78 KEY("Up", "\033[1;5A"),
79 KEY("Down", "\033[1;5B"),
80 KEY("Home", "\033[1;5H"),
81 KEY("End", "\033[1;5F"),
82 KEY("Insert", "\033[2;5~"),
83 KEY("Delete", "\033[3;5~"),
84 KEY("Prior", "\033[5;5~"),
85 KEY("Next", "\033[6;5~"),
86 KEY("F1", "\033[O5P"),
87 KEY("F2", "\033[O5Q"),
88 KEY("F3", "\033[O5R"),
89 KEY("F4", "\033[O5S"),
90 KEY("F5", "\033[15;5~"),
91 KEY("F6", "\033[17;5~"),
92 KEY("F7", "\033[18;5~"),
93 KEY("F8", "\033[19;5~"),
94 KEY("F9", "\033[20;5~"),
95 KEY("F10", "\033[21;5~"),
96 KEY("F11", "\033[23;5~"),
97 KEY("F12", "\033[24;5~"),
98 KEY("F13", "\033[25;5~"),
99 KEY("F14", "\033[26;5~"),
100 KEY("F15", "\033[28;5~"),
101 KEY("F16", "\033[29;5~"),
102 KEY("F17", "\033[31;5~"),
103 KEY("F18", "\033[32;5~"),
104 KEY("F19", "\033[33;5~"),
105 KEY("F20", "\033[34;5~"),
106 KEY("F21", "\033[35;5~"),
107 KEY("F22", "\033[36;5~"),
108 KEY("F23", "\033[37;5~"),
109 KEY("F24", "\033[38;5~"),
110 KEY("F25", "\033[39;5~"),
111 KEY("F26", "\033[40;5~"),
112 KEY("F27", "\033[41;5~"),
113 KEY("F28", "\033[42;5~"),
114 KEY("F29", "\033[43;5~"),
115 KEY("F30", "\033[44;5~"),
116 KEY("F31", "\033[45;5~"),
117 KEY("F32", "\033[46;5~"),
118 KEY("F33", "\033[47;5~"),
119 KEY("F34", "\033[48;5~"),
120 KEY("F35", "\033[49;5~"),
121
122 KEY(NULL, "END")
123};
124
125static const Keyout ctrl_shift_keyout[] =
126{
127 KEY("Left", "\033[1;6D"),
128 KEY("Right", "\033[1;6C"),
129 KEY("Up", "\033[1;6A"),
130 KEY("Down", "\033[1;6B"),
131 KEY("Home", "\033[1;6H"),
132 KEY("End", "\033[1;6F"),
133 KEY("Insert", "\033[2;6~"),
134 KEY("Delete", "\033[3;6~"),
135 KEY("Prior", "\033[5;6~"),
136 KEY("Next", "\033[6;6~"),
137
138 KEY("F1", "\033[O6P"),
139 KEY("F2", "\033[O6Q"),
140 KEY("F3", "\033[O6R"),
141 KEY("F4", "\033[O6S"),
142 KEY("F5", "\033[15;6~"),
143 KEY("F6", "\033[17;6~"),
144 KEY("F7", "\033[18;6~"),
145 KEY("F8", "\033[19;6~"),
146 KEY("F9", "\033[20;6~"),
147 KEY("F10", "\033[21;6~"),
148 KEY("F11", "\033[23;6~"),
149 KEY("F12", "\033[24;6~"),
150 KEY("F13", "\033[25;6~"),
151 KEY("F14", "\033[26;6~"),
152 KEY("F15", "\033[28;6~"),
153 KEY("F16", "\033[29;6~"),
154 KEY("F17", "\033[31;6~"),
155 KEY("F18", "\033[32;6~"),
156 KEY("F19", "\033[33;6~"),
157 KEY("F20", "\033[34;6~"),
158 KEY("F21", "\033[35;6~"),
159 KEY("F22", "\033[36;6~"),
160 KEY("F23", "\033[37;6~"),
161 KEY("F24", "\033[38;6~"),
162 KEY("F25", "\033[39;6~"),
163 KEY("F26", "\033[40;6~"),
164 KEY("F27", "\033[41;6~"),
165 KEY("F28", "\033[42;6~"),
166 KEY("F29", "\033[43;6~"),
167 KEY("F30", "\033[44;6~"),
168 KEY("F31", "\033[45;6~"),
169 KEY("F32", "\033[46;6~"),
170 KEY("F33", "\033[47;6~"),
171 KEY("F34", "\033[48;6~"),
172 KEY("F35", "\033[49;6~"),
173
174 KEY(NULL, "END")
175};
176
177static const Keyout shift_keyout[] =
178{
179 KEY("Left", "\033[1;2D"),
180 KEY("Right", "\033[1;2C"),
181 KEY("Up", "\033[1;2A"),
182 KEY("Down", "\033[1;2B"),
183 KEY("Home", "\033[1;2H"),
184 KEY("End", "\033[1;2F"),
185 KEY("Insert", "\033[2;2~"),
186 KEY("Delete", "\033[3;2~"),
187 KEY("Prior", "\033[5;2~"),
188 KEY("Next", "\033[6;2~"),
189
190 KEY("Tab", "\033[Z"),
191 KEY("ISO_Left_Tab", "\033[Z"),
192 KEY("F1", "\033[1;2P"),
193 KEY("F2", "\033[1;2Q"),
194 KEY("F3", "\033[1;2R"),
195 KEY("F4", "\033[1;2S"),
196 KEY("F5", "\033[15;2~"),
197 KEY("F6", "\033[17;2~"),
198 KEY("F7", "\033[18;2~"),
199 KEY("F8", "\033[19;2~"),
200 KEY("F9", "\033[20;2~"),
201 KEY("F10", "\033[21;2~"),
202 KEY("F11", "\033[23;2~"),
203 KEY("F12", "\033[24;2~"),
204 KEY("F13", "\033[25;2~"),
205 KEY("F14", "\033[26;2~"),
206 KEY("F15", "\033[28;2~"),
207 KEY("F16", "\033[29;2~"),
208 KEY("F17", "\033[31;2~"),
209 KEY("F18", "\033[32;2~"),
210 KEY("F19", "\033[33;2~"),
211 KEY("F20", "\033[34;2~"),
212 KEY("F21", "\033[35;2~"),
213 KEY("F22", "\033[36;2~"),
214 KEY("F23", "\033[37;2~"),
215 KEY("F24", "\033[38;2~"),
216 KEY("F25", "\033[39;2~"),
217 KEY("F26", "\033[40;2~"),
218 KEY("F27", "\033[41;2~"),
219 KEY("F28", "\033[42;2~"),
220 KEY("F29", "\033[43;2~"),
221 KEY("F30", "\033[44;2~"),
222 KEY("F31", "\033[45;2~"),
223 KEY("F32", "\033[46;2~"),
224 KEY("F33", "\033[47;2~"),
225 KEY("F34", "\033[48;2~"),
226 KEY("F35", "\033[49;2~"),
227
228 KEY(NULL, "END")
229};
230
231static const Keyout alt_keyout[] =
232{
233 KEY("Left", "\033[1;3D"),
234 KEY("Right", "\033[1;3C"),
235 KEY("Up", "\033[1;3A"),
236 KEY("Down", "\033[1;3B"),
237 KEY("End", "\033[1;3F"),
238 KEY("BackSpace", "\033\b"),
239 KEY("Return", "\033\015"),
240 KEY("space", "\033\040"),
241 KEY("Home", "\033[1;3H"),
242 KEY("End", "\033[1;3F"),
243 KEY("Prior", "\033[5;3~"),
244 KEY("Next", "\033[6;3~"),
245 KEY("Insert", "\033[2;3~"),
246 KEY("Delete", "\033[3;3~"),
247 KEY("Menu", "\033[29;3~"),
248 KEY("Find", "\033[1;3~"),
249 KEY("Help", "\033[28;3~"),
250 KEY("Execute", "\033[3;3~"),
251 KEY("Select", "\033[4;3~"),
252 KEY("F1", "\033[O3P"),
253 KEY("F2", "\033[O3Q"),
254 KEY("F3", "\033[O3R"),
255 KEY("F4", "\033[O3S"),
256 KEY("F5", "\033[15;3~"),
257 KEY("F6", "\033[17;3~"),
258 KEY("F7", "\033[18;3~"),
259 KEY("F8", "\033[19;3~"),
260 KEY("F9", "\033[20;3~"),
261 KEY("F10", "\033[21;3~"),
262 KEY("F11", "\033[23;3~"),
263 KEY("F12", "\033[24;3~"),
264 KEY("F13", "\033[25;3~"),
265 KEY("F14", "\033[26;3~"),
266 KEY("F15", "\033[28;3~"),
267 KEY("F16", "\033[29;3~"),
268 KEY("F17", "\033[31;3~"),
269 KEY("F18", "\033[32;3~"),
270 KEY("F19", "\033[33;3~"),
271 KEY("F20", "\033[34;3~"),
272 KEY("F21", "\033[35;3~"),
273 KEY("F22", "\033[36;3~"),
274 KEY("F23", "\033[37;3~"),
275 KEY("F24", "\033[38;3~"),
276 KEY("F25", "\033[39;3~"),
277 KEY("F26", "\033[40;3~"),
278 KEY("F27", "\033[41;3~"),
279 KEY("F28", "\033[42;3~"),
280 KEY("F29", "\033[43;3~"),
281 KEY("F30", "\033[44;3~"),
282 KEY("F31", "\033[45;3~"),
283 KEY("F32", "\033[46;3~"),
284 KEY("F33", "\033[47;3~"),
285 KEY("F34", "\033[48;3~"),
286 KEY("F35", "\033[49;3~"),
287
288 KEY(NULL, "END")
289};
290
291static const Keyout keyout[] =
292{
293// KEY("BackSpace", "\177"),
294 KEY("BackSpace", "\b"),
295 KEY("Left", "\033[D"),
296 KEY("Right", "\033[C"),
297 KEY("Up", "\033[A"),
298 KEY("Down", "\033[B"),
299// KEY("Tab", "\t"),
300// KEY("ISO_Left_Tab", "\t"),
301 KEY("Home", "\033[H"),
302 KEY("End", "\033[F"),
303 KEY("Prior", "\033[5~"),
304 KEY("Next", "\033[6~"),
305 KEY("Insert", "\033[2~"),
306 KEY("Delete", "\033[3~"),
307 KEY("Menu", "\033[29~"),
308 KEY("Find", "\033[1~"),
309 KEY("Help", "\033[28~"),
310 KEY("Execute", "\033[3~"),
311 KEY("Select", "\033[4~"),
312 KEY("F1", "\033OP"),
313 KEY("F2", "\033OQ"),
314 KEY("F3", "\033OR"),
315 KEY("F4", "\033OS"),
316 KEY("F5", "\033[15~"),
317 KEY("F6", "\033[17~"),
318 KEY("F7", "\033[18~"),
319 KEY("F8", "\033[19~"),
320 KEY("F9", "\033[20~"),
321 KEY("F10", "\033[21~"),
322 KEY("F11", "\033[23~"),
323 KEY("F12", "\033[24~"),
324 KEY("F13", "\033[25~"),
325 KEY("F14", "\033[26~"),
326 KEY("F15", "\033[28~"),
327 KEY("F16", "\033[29~"),
328 KEY("F17", "\033[31~"),
329 KEY("F18", "\033[32~"),
330 KEY("F19", "\033[33~"),
331 KEY("F20", "\033[34~"),
332 KEY("F21", "\033[35~"),
333 KEY("F22", "\033[36~"),
334 KEY("F23", "\033[37~"),
335 KEY("F24", "\033[38~"),
336 KEY("F25", "\033[39~"),
337 KEY("F26", "\033[40~"),
338 KEY("F27", "\033[41~"),
339 KEY("F28", "\033[42~"),
340 KEY("F29", "\033[43~"),
341 KEY("F30", "\033[44~"),
342 KEY("F31", "\033[45~"),
343 KEY("F32", "\033[46~"),
344 KEY("F33", "\033[47~"),
345 KEY("F34", "\033[48~"),
346 KEY("F35", "\033[49~"),
347/*
348 KEY("KP_F1", "\033OP"),
349 KEY("KP_F2", "\033OQ"),
350 KEY("KP_F3", "\033OR"),
351 KEY("KP_F4", "\033OS"),
352 KEY("KP_Begin", "\033Ou"),
353 KEY("KP_Multiply", "\033Oj"),
354 KEY("KP_Add", "\033Ok"),
355 KEY("KP_Separator", "\033Ol"),
356 KEY("KP_Subtract", "\033Om"),
357 KEY("KP_Decimal", "\033On"),
358 KEY("KP_Divide", "\033Oo"),
359 KEY("KP_0", "\033Op"),
360 KEY("KP_1", "\033Oq"),
361 KEY("KP_2", "\033Or"),
362 KEY("KP_3", "\033Os"),
363 KEY("KP_4", "\033Ot"),
364 KEY("KP_5", "\033Ou"),
365 KEY("KP_6", "\033Ov"),
366 KEY("KP_7", "\033Ow"),
367 KEY("KP_8", "\033Ox"),
368 KEY("KP_9", "\033Oy"),
369 */
370 KEY(NULL, "END")
371};
372
373static const Keyout kp_keyout[] =
374{
375 KEY("KP_Left", "\033[D"),
376 KEY("KP_Right", "\033[C"),
377 KEY("KP_Up", "\033[A"),
378 KEY("KP_Down", "\033[B"),
379 KEY("KP_Home", "\033[H"),
380 KEY("KP_End", "\033[F"),
381 KEY("KP_Prior", "\033[5~"),
382 KEY("KP_Next", "\033[6~"),
383 KEY("KP_Insert", "\033[2~"),
384 KEY("KP_Delete", "\033[3~"),
385 KEY("KP_Enter", "\r"),
386 KEY(NULL, "END")
387};
388
389static const Keyout kps_keyout[] =
390{
391 KEY("KP_Left", "\033Ot"),
392 KEY("KP_Right", "\033Ov"),
393 KEY("KP_Up", "\033Ox"),
394 KEY("KP_Down", "\033Or"),
395 KEY("KP_Home", "\033Ow"),
396 KEY("KP_End", "\033Oq"),
397 KEY("KP_Prior", "\033Oy"),
398 KEY("KP_Next", "\033Os"),
399 KEY("KP_Insert", "\033Op"),
400 KEY("KP_Delete", "\033On"),
401 KEY("KP_Enter", "\033OM"),
402
403 KEY(NULL, "END")
404};
405
406static Eina_Bool 55static Eina_Bool
407_key_try(Termpty *ty, const Keyout *map, const Evas_Event_Key_Down *ev) 56_key_try(Termpty *ty, const Tty_Key *map, int len, const Evas_Event_Key_Down *ev,
57 int alt, int shift, int ctrl)
408{ 58{
409 int i, inlen; 59 int i, inlen;
410
411 if (!ev->key) return EINA_FALSE;
412 60
413 inlen = strlen(ev->key); 61 inlen = strlen(ev->key);
414 for (i = 0; map[i].in; i++) 62 for (i = 0; i < len; i++)
415 { 63 {
416 if ((inlen == map[i].inlen) && (!memcmp(ev->key, map[i].in, inlen))) 64 if ((inlen == map[i].key_len) && (!memcmp(ev->key, map[i].key, inlen)))
417 { 65 {
418 termpty_write(ty, map[i].out, map[i].outlen); 66 const struct _s *s;
67 const Key_Values *kv;
68
69 if (!ty->state.appcursor)
70 {
71 kv = &map[i].default_mode;
72 }
73 else
74 {
75 kv = &map[i].cursor;
76 }
77 if (!alt && !ctrl && !shift)
78 s = &kv->plain;
79 else if (alt && !ctrl && !shift)
80 s = &kv->alt;
81 else if (!alt && ctrl && !shift)
82 s = &kv->ctrl;
83 else if (alt && ctrl && !shift)
84 s = &kv->ctrl_alt;
85 else if (!alt && !ctrl && shift)
86 s = &kv->shift;
87 else if (!alt && !ctrl && shift)
88 s = &kv->shift_alt;
89 else if (!alt && !ctrl && shift)
90 s = &kv->shift_ctrl;
91 else if (alt && ctrl && shift)
92 s = &kv->shift_ctrl_alt;
93
94 termpty_write(ty, s->s, s->len);
419 return EINA_TRUE; 95 return EINA_TRUE;
420 } 96 }
421 } 97 }
@@ -434,21 +110,75 @@ keyin_compose_seq_reset(Keys_Handler *khdl)
434 khdl->composing = EINA_FALSE; 110 khdl->composing = EINA_FALSE;
435} 111}
436 112
113#include "tty_keys.h"
114
437static void 115static void
438_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev, 116_handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
439 int alt, int shift, int ctrl) 117 int alt, int shift, int ctrl)
440{ 118{
441 if (!alt) 119 if (!ev->key)
120 return;
121
122 if (!strcmp(ev->key, "BackSpace"))
123 {
124 if (ty->state.send_bs)
125 {
126 termpty_write(ty, "\b", 1);
127 return;
128 }
129 else
130 {
131 Config *cfg = termpty_config_get(ty);
132
133 if (cfg->erase_is_del)
134 {
135 termpty_write(ty, "\177", sizeof("\177") - 1);
136 }
137 else
138 {
139 termpty_write(ty, "\b", sizeof("\b") - 1);
140 }
141 return;
142 }
143 }
144 if (!strcmp(ev->key, "Return"))
442 { 145 {
443 if (ty->state.crlf) 146 if (ty->state.crlf)
444 { 147 {
445 if (_key_try(ty, crlf_keyout, ev)) return; 148 termpty_write(ty, "\r\n", sizeof("\r\n") - 1);
149 return;
446 } 150 }
447 else 151 else
448 { 152 {
449 if (_key_try(ty, nocrlf_keyout, ev)) return; 153 termpty_write(ty, "\r", sizeof("\r") - 1);
154 return;
450 } 155 }
451 } 156 }
157 if (ev->key && ev->key[0] == 'K' && ev->key[1] == 'k')
158 {
159 if (!evas_key_lock_is_set(ev->locks, "Num_Lock"))
160 {
161 if (ty->state.alt_kp)
162 {
163 if (_key_try(ty, tty_keys,
164 sizeof(tty_keys_kp_app)/sizeof(tty_keys_kp_app[0]),
165 ev, alt, shift, ctrl))
166 return;
167 }
168 else
169 {
170 if (_key_try(ty, tty_keys,
171 sizeof(tty_keys_kp_plain)/sizeof(tty_keys_kp_plain[0]),
172 ev, alt, shift, ctrl))
173 return;
174 }
175 }
176 }
177 else
178 if (_key_try(ty, tty_keys, sizeof(tty_keys)/sizeof(tty_keys[0]), ev,
179 alt, shift, ctrl))
180 return;
181#if 0
452 if ( 182 if (
453 ((ty->state.alt_kp) && (shift)) 183 ((ty->state.alt_kp) && (shift))
454// || ((!ty->state.alt_kp) && 184// || ((!ty->state.alt_kp) &&
@@ -485,60 +215,8 @@ _handle_key_to_pty(Termpty *ty, const Evas_Event_Key_Down *ev,
485 if (_key_try(ty, ctrl_shift_keyout, ev)) return; 215 if (_key_try(ty, ctrl_shift_keyout, ev)) return;
486 } 216 }
487 } 217 }
488 else if (shift) 218#endif
489 {
490 if (_key_try(ty, shift_keyout, ev)) return;
491 }
492
493 else if (alt)
494 {
495 if (_key_try(ty, alt_keyout, ev)) return;
496 if (ev->key[0] > 0 && ev->key[1] == '\0')
497 {
498 char echo[2];
499 /* xterm and rxvt differ here about their default options: */
500 /* xterm, altSendsEscape off
501
502 echo[0] = ev->key[0] | 0x80;
503 termpty_write(ty, echo, 1);
504 */
505
506 /* rxvt, with meta8 off, chose it because of utf-8 */
507 echo[0] = 033;
508 echo[1] = ev->key[0];
509 termpty_write(ty, echo, 2);
510 return;
511 }
512 }
513
514 if (ty->state.appcursor)
515 {
516 if (_key_try(ty, appcur_keyout, ev)) return;
517 }
518
519 if (!strcmp(ev->key, "BackSpace"))
520 {
521 if (ty->state.send_bs)
522 {
523 termpty_write(ty, "\b", 1);
524 return;
525 }
526 else
527 {
528 Config *cfg = termpty_config_get(ty);
529 219
530 if (cfg->erase_is_del)
531 {
532 termpty_write(ty, "\177", sizeof("\177") - 1);
533 }
534 else
535 {
536 termpty_write(ty, "\b", sizeof("\b") - 1);
537 }
538 return;
539 }
540 }
541 if (_key_try(ty, keyout, ev)) return;
542 if (ev->string) 220 if (ev->string)
543 { 221 {
544 if ((ev->string[0]) && (!ev->string[1])) 222 if ((ev->string[0]) && (!ev->string[1]))