From 725938fb85290ca67ab50e27f9cacb870ff56c63 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Tue, 21 Jul 2009 17:57:29 +0000 Subject: [PATCH] Tidy up keys: use an enum for the key codes, and remove the macros which just wrap flag sets/clears/tests. --- cmd-next-window.c | 2 +- cmd-previous-window.c | 2 +- cmd-resize-pane.c | 18 +++--- cmd-rotate-window.c | 2 +- cmd-select-layout.c | 10 ++-- input-keys.c | 50 ++++++++--------- key-bindings.c | 30 +++++----- key-string.c | 18 +++--- mode-key.c | 14 ++--- tmux.h | 127 +++++++++++++++++++----------------------- tty-keys.c | 41 ++++++-------- 11 files changed, 149 insertions(+), 165 deletions(-) diff --git a/cmd-next-window.c b/cmd-next-window.c index f0f8d18e..b7608f33 100644 --- a/cmd-next-window.c +++ b/cmd-next-window.c @@ -48,7 +48,7 @@ cmd_next_window_init(struct cmd *self, int key) cmd_target_init(self, key); data = self->data; - if (key == KEYC_ADDESC('n')) + if (key == ('n' | KEYC_ESCAPE)) data->chflags |= CMD_CHFLAG('a'); } diff --git a/cmd-previous-window.c b/cmd-previous-window.c index 2c5088b2..6b26704e 100644 --- a/cmd-previous-window.c +++ b/cmd-previous-window.c @@ -48,7 +48,7 @@ cmd_previous_window_init(struct cmd *self, int key) cmd_target_init(self, key); data = self->data; - if (key == KEYC_ADDESC('p')) + if (key == ('p' | KEYC_ESCAPE)) data->chflags |= CMD_CHFLAG('a'); } diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 5e9f67e3..b0ea214c 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -51,28 +51,28 @@ cmd_resize_pane_init(struct cmd *self, int key) cmd_pane_init(self, key); data = self->data; - if (key == KEYC_ADDCTL(KEYC_UP)) + if (key == (KEYC_UP | KEYC_CTRL)) data->chflags |= CMD_CHFLAG('U'); - if (key == KEYC_ADDCTL(KEYC_DOWN)) + if (key == (KEYC_DOWN | KEYC_CTRL)) data->chflags |= CMD_CHFLAG('D'); - if (key == KEYC_ADDCTL(KEYC_LEFT)) + if (key == (KEYC_LEFT | KEYC_CTRL)) data->chflags |= CMD_CHFLAG('L'); - if (key == KEYC_ADDCTL(KEYC_RIGHT)) + if (key == (KEYC_RIGHT | KEYC_CTRL)) data->chflags |= CMD_CHFLAG('R'); - - if (key == KEYC_ADDESC(KEYC_UP)) { + + if (key == (KEYC_UP | KEYC_ESCAPE)) { data->chflags |= CMD_CHFLAG('U'); data->arg = xstrdup("5"); } - if (key == KEYC_ADDESC(KEYC_DOWN)) { + if (key == (KEYC_DOWN | KEYC_ESCAPE)) { data->chflags |= CMD_CHFLAG('D'); data->arg = xstrdup("5"); } - if (key == KEYC_ADDESC(KEYC_LEFT)) { + if (key == (KEYC_LEFT | KEYC_ESCAPE)) { data->chflags |= CMD_CHFLAG('L'); data->arg = xstrdup("5"); } - if (key == KEYC_ADDESC(KEYC_RIGHT)) { + if (key == (KEYC_RIGHT | KEYC_ESCAPE)) { data->chflags |= CMD_CHFLAG('R'); data->arg = xstrdup("5"); } diff --git a/cmd-rotate-window.c b/cmd-rotate-window.c index c69fa8d1..c12345d6 100644 --- a/cmd-rotate-window.c +++ b/cmd-rotate-window.c @@ -48,7 +48,7 @@ cmd_rotate_window_init(struct cmd *self, int key) cmd_target_init(self, key); data = self->data; - if (key == KEYC_ADDESC('o')) + if (key == ('o' | KEYC_ESCAPE)) data->chflags |= CMD_CHFLAG('D'); } diff --git a/cmd-select-layout.c b/cmd-select-layout.c index 953cb69f..6329a9b7 100644 --- a/cmd-select-layout.c +++ b/cmd-select-layout.c @@ -49,16 +49,16 @@ cmd_select_layout_init(struct cmd *self, int key) data = self->data; switch (key) { - case KEYC_ADDESC('1'): + case ('1' | KEYC_ESCAPE): data->arg = xstrdup("even-horizontal"); break; - case KEYC_ADDESC('2'): + case ('2' | KEYC_ESCAPE): data->arg = xstrdup("even-vertical"); - break; - case KEYC_ADDESC('3'): + break; + case ('3' | KEYC_ESCAPE): data->arg = xstrdup("main-horizontal"); break; - case KEYC_ADDESC('4'): + case ('4' | KEYC_ESCAPE): data->arg = xstrdup("main-vertical"); break; } diff --git a/input-keys.c b/input-keys.c index 24c0bbaa..0afe6e47 100644 --- a/input-keys.c +++ b/input-keys.c @@ -66,16 +66,16 @@ struct input_key_ent input_keys[] = { { KEYC_BTAB, "\033[Z", INPUTKEY_CTRL }, /* Arrow keys. Cursor versions must come first. */ - { KEYC_ADDCTL(KEYC_UP), "\033Oa", 0 }, - { KEYC_ADDCTL(KEYC_DOWN), "\033Ob", 0 }, - { KEYC_ADDCTL(KEYC_RIGHT), "\033Oc", 0 }, - { KEYC_ADDCTL(KEYC_LEFT), "\033Od", 0 }, - - { KEYC_ADDSFT(KEYC_UP), "\033[a", 0 }, - { KEYC_ADDSFT(KEYC_DOWN), "\033[b", 0 }, - { KEYC_ADDSFT(KEYC_RIGHT), "\033[c", 0 }, - { KEYC_ADDSFT(KEYC_LEFT), "\033[d", 0 }, - + { KEYC_UP | KEYC_CTRL, "\033Oa", 0 }, + { KEYC_DOWN | KEYC_CTRL, "\033Ob", 0 }, + { KEYC_RIGHT | KEYC_CTRL, "\033Oc", 0 }, + { KEYC_LEFT | KEYC_CTRL, "\033Od", 0 }, + + { KEYC_UP | KEYC_SHIFT, "\033[a", 0 }, + { KEYC_DOWN | KEYC_SHIFT, "\033[b", 0 }, + { KEYC_RIGHT | KEYC_SHIFT, "\033[c", 0 }, + { KEYC_LEFT | KEYC_SHIFT, "\033[d", 0 }, + { KEYC_UP, "\033OA", INPUTKEY_CURSOR }, { KEYC_DOWN, "\033OB", INPUTKEY_CURSOR }, { KEYC_RIGHT, "\033OC", INPUTKEY_CURSOR }, @@ -133,10 +133,10 @@ input_key(struct window_pane *wp, int key) log_debug2("writing key 0x%x", key); - if (key != KEYC_NONE && KEYC_REMOVEESC(key) < KEYC_OFFSET) { - if (KEYC_ISESC(key)) + if (key != KEYC_NONE && (key & ~KEYC_ESCAPE) < 0x100) { + if (key & KEYC_ESCAPE) buffer_write8(wp->out, '\033'); - buffer_write8(wp->out, (uint8_t) KEYC_REMOVEESC(key)); + buffer_write8(wp->out, (uint8_t) (key & ~KEYC_ESCAPE)); return; } @@ -150,11 +150,11 @@ input_key(struct window_pane *wp, int key) !(wp->screen->mode & MODE_KCURSOR)) continue; - if (KEYC_ISESC(key) && KEYC_ADDESC(ike->key) == key) + if ((key & KEYC_ESCAPE) && (ike->key | KEYC_ESCAPE) == key) break; - if (KEYC_ISSFT(key) && KEYC_ADDSFT(ike->key) == key) + if ((key & KEYC_SHIFT) && (ike->key | KEYC_SHIFT) == key) break; - if (KEYC_ISCTL(key) && KEYC_ADDCTL(ike->key) == key) { + if ((key & KEYC_CTRL) && (ike->key | KEYC_CTRL) == key) { if (ike->flags & INPUTKEY_CTRL) break; } @@ -176,19 +176,19 @@ input_key(struct window_pane *wp, int key) xterm_keys = options_get_number(&wp->window->options, "xterm-keys"); if (xterm_keys && ike->flags & INPUTKEY_XTERM) { ch = '\0'; - if (KEYC_ISSFT(key) && KEYC_ISESC(key) && KEYC_ISCTL(key)) + if (key & (KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL)) ch = '8'; - else if (KEYC_ISESC(key) && KEYC_ISCTL(key)) + else if (key & (KEYC_ESCAPE|KEYC_CTRL)) ch = '7'; - else if (KEYC_ISSFT(key) && KEYC_ISCTL(key)) + else if (key & (KEYC_SHIFT|KEYC_CTRL)) ch = '6'; - else if (KEYC_ISCTL(key)) + else if (key & KEYC_CTRL) ch = '5'; - else if (KEYC_ISSFT(key) && KEYC_ISESC(key)) + else if (key & (KEYC_SHIFT|KEYC_ESCAPE)) ch = '4'; - else if (KEYC_ISESC(key)) + else if (key & KEYC_ESCAPE) ch = '3'; - else if (KEYC_ISSFT(key)) + else if (key & KEYC_SHIFT) ch = '2'; if (ch != '\0') { buffer_write(wp->out, ike->data, dlen - 1); @@ -204,9 +204,9 @@ input_key(struct window_pane *wp, int key) * Not in xterm mode. Prefix a \033 for escape, and set bit 5 of the * last byte for ctrl. */ - if (KEYC_ISESC(key)) + if (key & KEYC_ESCAPE) buffer_write8(wp->out, '\033'); - if (KEYC_ISCTL(key) && ike->flags & INPUTKEY_CTRL) { + if (key & KEYC_CTRL && ike->flags & INPUTKEY_CTRL) { buffer_write(wp->out, ike->data, dlen - 1); buffer_write8(wp->out, ike->data[dlen - 1] ^ 0x20); return; diff --git a/key-bindings.c b/key-bindings.c index 66ed4927..d37e23b3 100644 --- a/key-bindings.c +++ b/key-bindings.c @@ -133,24 +133,24 @@ key_bindings_init(void) { '{', 0, &cmd_swap_pane_entry }, { '}', 0, &cmd_swap_pane_entry }, { '\002', 0, &cmd_send_prefix_entry }, - { KEYC_ADDESC('1'), 0, &cmd_select_layout_entry }, - { KEYC_ADDESC('2'), 0, &cmd_select_layout_entry }, - { KEYC_ADDESC('3'), 0, &cmd_select_layout_entry }, - { KEYC_ADDESC('4'), 0, &cmd_select_layout_entry }, + { '1' | KEYC_ESCAPE, 0, &cmd_select_layout_entry }, + { '2' | KEYC_ESCAPE, 0, &cmd_select_layout_entry }, + { '3' | KEYC_ESCAPE, 0, &cmd_select_layout_entry }, + { '4' | KEYC_ESCAPE, 0, &cmd_select_layout_entry }, { KEYC_PPAGE, 0, &cmd_scroll_mode_entry }, - { KEYC_ADDESC('n'), 0, &cmd_next_window_entry }, - { KEYC_ADDESC('p'), 0, &cmd_previous_window_entry }, + { 'n' | KEYC_ESCAPE, 0, &cmd_next_window_entry }, + { 'p' | KEYC_ESCAPE, 0, &cmd_previous_window_entry }, { KEYC_UP, 0, &cmd_up_pane_entry }, { KEYC_DOWN, 0, &cmd_down_pane_entry }, - { KEYC_ADDESC(KEYC_UP), 1, &cmd_resize_pane_entry }, - { KEYC_ADDESC(KEYC_DOWN), 1, &cmd_resize_pane_entry }, - { KEYC_ADDESC(KEYC_LEFT), 1, &cmd_resize_pane_entry }, - { KEYC_ADDESC(KEYC_RIGHT),1, &cmd_resize_pane_entry }, - { KEYC_ADDCTL(KEYC_UP), 1, &cmd_resize_pane_entry }, - { KEYC_ADDCTL(KEYC_DOWN), 1, &cmd_resize_pane_entry }, - { KEYC_ADDCTL(KEYC_LEFT), 1, &cmd_resize_pane_entry }, - { KEYC_ADDCTL(KEYC_RIGHT),1, &cmd_resize_pane_entry }, - { KEYC_ADDESC('o'), 0, &cmd_rotate_window_entry }, + { KEYC_UP | KEYC_ESCAPE, 1, &cmd_resize_pane_entry }, + { KEYC_DOWN | KEYC_ESCAPE, 1, &cmd_resize_pane_entry }, + { KEYC_LEFT | KEYC_ESCAPE, 1, &cmd_resize_pane_entry }, + { KEYC_RIGHT | KEYC_ESCAPE, 1, &cmd_resize_pane_entry }, + { KEYC_UP | KEYC_CTRL, 1, &cmd_resize_pane_entry }, + { KEYC_DOWN | KEYC_CTRL, 1, &cmd_resize_pane_entry }, + { KEYC_LEFT | KEYC_CTRL, 1, &cmd_resize_pane_entry }, + { KEYC_RIGHT | KEYC_CTRL, 1, &cmd_resize_pane_entry }, + { 'o' | KEYC_ESCAPE, 0, &cmd_rotate_window_entry }, { '\017', 0, &cmd_rotate_window_entry }, }; u_int i; diff --git a/key-string.c b/key-string.c index cf146b98..d70fe69b 100644 --- a/key-string.c +++ b/key-string.c @@ -126,7 +126,7 @@ key_string_lookup_string(const char *string) } key = key_string_search_table(ptr); if (key != KEYC_NONE) - return (KEYC_ADDCTL(key)); + return (key | KEYC_CTRL); return (KEYC_NONE); } @@ -137,11 +137,11 @@ key_string_lookup_string(const char *string) if (ptr[1] == '\0') { if (ptr[0] < 32 || ptr[0] > 127) return (KEYC_NONE); - return (KEYC_ADDESC(ptr[0])); + return (ptr[0] | KEYC_ESCAPE); } key = key_string_lookup_string(ptr); if (key != KEYC_NONE) - return (KEYC_ADDESC(key)); + return (key | KEYC_ESCAPE); return (KEYC_NONE); } @@ -158,20 +158,20 @@ key_string_lookup_key(int key) if (key == 127) return (NULL); - if (KEYC_ISESC(key)) { - if ((s = key_string_lookup_key(KEYC_REMOVEESC(key))) == NULL) + if (key & KEYC_ESCAPE) { + if ((s = key_string_lookup_key(key & ~KEYC_ESCAPE)) == NULL) return (NULL); xsnprintf(tmp2, sizeof tmp2, "M-%s", s); return (tmp2); } - if (KEYC_ISCTL(key)) { - if ((s = key_string_lookup_key(KEYC_REMOVECTL(key))) == NULL) + if (key & KEYC_CTRL) { + if ((s = key_string_lookup_key(key & ~KEYC_CTRL)) == NULL) return (NULL); xsnprintf(tmp2, sizeof tmp2, "C-%s", s); return (tmp2); } - if (KEYC_ISSFT(key)) { - if ((s = key_string_lookup_key(KEYC_REMOVESFT(key))) == NULL) + if (key & KEYC_SHIFT) { + if ((s = key_string_lookup_key(key & ~KEYC_SHIFT)) == NULL) return (NULL); xsnprintf(tmp2, sizeof tmp2, "S-%s", s); return (tmp2); diff --git a/mode-key.c b/mode-key.c index 8f822cb0..508760bd 100644 --- a/mode-key.c +++ b/mode-key.c @@ -54,8 +54,8 @@ mode_key_lookup(struct mode_key_data *mdata, int key) enum mode_key_cmd mode_key_lookup_vi(struct mode_key_data *mdata, int key) { - if (KEYC_ISESC(key)) { - key = KEYC_REMOVEESC(key); + if (key & KEYC_ESCAPE) { + key &= ~KEYC_ESCAPE; if (mdata->flags & MODEKEY_CANEDIT) mdata->flags ^= MODEKEY_EDITMODE; } @@ -161,12 +161,12 @@ mode_key_lookup_emacs(struct mode_key_data *mdata, int key) return (MODEKEYCMD_CHOOSE); case '\001': return (MODEKEYCMD_STARTOFLINE); - case KEYC_ADDESC('m'): + case 'm' | KEYC_ESCAPE: return (MODEKEYCMD_BACKTOINDENTATION); case '\007': return (MODEKEYCMD_CLEARSELECTION); case '\027': - case KEYC_ADDESC('w'): + case 'w' | KEYC_ESCAPE: return (MODEKEYCMD_COPYSELECTION); case '\016': case KEYC_DOWN: @@ -183,14 +183,14 @@ mode_key_lookup_emacs(struct mode_key_data *mdata, int key) case '\026': case KEYC_NPAGE: return (MODEKEYCMD_NEXTPAGE); - case KEYC_ADDESC('f'): + case 'f' | KEYC_ESCAPE: return (MODEKEYCMD_NEXTWORD); case '\031': return (MODEKEYCMD_PASTE); - case KEYC_ADDESC('v'): + case 'v' | KEYC_ESCAPE: case KEYC_PPAGE: return (MODEKEYCMD_PREVIOUSPAGE); - case KEYC_ADDESC('b'): + case 'b' | KEYC_ESCAPE: return (MODEKEYCMD_PREVIOUSWORD); case '\006': case KEYC_RIGHT: diff --git a/tmux.h b/tmux.h index 37162f77..34a0fd9b 100644 --- a/tmux.h +++ b/tmux.h @@ -102,79 +102,68 @@ struct buffer { #define BELL_CURRENT 2 /* Key codes. ncurses defines KEY_*. Grrr. */ -#define KEYC_NONE 0x00ffff -#define KEYC_OFFSET 0x010000 -#define KEYC_ESCAPE 0x020000 -#define KEYC_CONTROL 0x080000 -#define KEYC_SHIFT 0x100000 +#define KEYC_NONE 0x0fff +#define KEYC_ESCAPE 0x2000 +#define KEYC_CTRL 0x4000 +#define KEYC_SHIFT 0x8000 -#define KEYC_ADDESC(k) ((k) | KEYC_ESCAPE) -#define KEYC_REMOVEESC(k) ((k) & ~KEYC_ESCAPE) -#define KEYC_ISESC(k) ((k) != KEYC_NONE && ((k) & KEYC_ESCAPE)) +enum key_code { + /* Mouse key. */ + KEYC_MOUSE = 0x1000, -#define KEYC_ADDCTL(k) ((k) | KEYC_CONTROL) -#define KEYC_REMOVECTL(k) ((k) & ~KEYC_CONTROL) -#define KEYC_ISCTL(k) ((k) != KEYC_NONE && ((k) & KEYC_CONTROL)) + /* Function keys. */ + KEYC_F1, + KEYC_F2, + KEYC_F3, + KEYC_F4, + KEYC_F5, + KEYC_F6, + KEYC_F7, + KEYC_F8, + KEYC_F9, + KEYC_F10, + KEYC_F11, + KEYC_F12, + KEYC_F13, + KEYC_F14, + KEYC_F15, + KEYC_F16, + KEYC_F17, + KEYC_F18, + KEYC_F19, + KEYC_F20, + KEYC_IC, + KEYC_DC, + KEYC_HOME, + KEYC_END, + KEYC_NPAGE, + KEYC_PPAGE, + KEYC_BTAB, -#define KEYC_ADDSFT(k) ((k) | KEYC_SHIFT) -#define KEYC_REMOVESFT(k) ((k) & ~KEYC_SHIFT) -#define KEYC_ISSFT(k) ((k) != KEYC_NONE && ((k) & KEYC_SHIFT)) + /* Arrow keys. */ + KEYC_UP, + KEYC_DOWN, + KEYC_LEFT, + KEYC_RIGHT, -/* Mouse key. */ -#define KEYC_MOUSE (KEYC_OFFSET + 0x00) - -/* Function keys. */ -#define KEYC_F1 (KEYC_OFFSET + 0x01) -#define KEYC_F2 (KEYC_OFFSET + 0x02) -#define KEYC_F3 (KEYC_OFFSET + 0x03) -#define KEYC_F4 (KEYC_OFFSET + 0x04) -#define KEYC_F5 (KEYC_OFFSET + 0x05) -#define KEYC_F6 (KEYC_OFFSET + 0x06) -#define KEYC_F7 (KEYC_OFFSET + 0x07) -#define KEYC_F8 (KEYC_OFFSET + 0x08) -#define KEYC_F9 (KEYC_OFFSET + 0x09) -#define KEYC_F10 (KEYC_OFFSET + 0x10) -#define KEYC_F11 (KEYC_OFFSET + 0x11) -#define KEYC_F12 (KEYC_OFFSET + 0x12) -#define KEYC_F13 (KEYC_OFFSET + 0x13) -#define KEYC_F14 (KEYC_OFFSET + 0x14) -#define KEYC_F15 (KEYC_OFFSET + 0x15) -#define KEYC_F16 (KEYC_OFFSET + 0x16) -#define KEYC_F17 (KEYC_OFFSET + 0x17) -#define KEYC_F18 (KEYC_OFFSET + 0x18) -#define KEYC_F19 (KEYC_OFFSET + 0x19) -#define KEYC_F20 (KEYC_OFFSET + 0x1a) -#define KEYC_IC (KEYC_OFFSET + 0x1b) -#define KEYC_DC (KEYC_OFFSET + 0x1c) -#define KEYC_HOME (KEYC_OFFSET + 0x1d) -#define KEYC_END (KEYC_OFFSET + 0x1e) -#define KEYC_NPAGE (KEYC_OFFSET + 0x1f) -#define KEYC_PPAGE (KEYC_OFFSET + 0x20) -#define KEYC_BTAB (KEYC_OFFSET + 0x21) - -/* Arrow keys. */ -#define KEYC_UP (KEYC_OFFSET + 0x50) -#define KEYC_DOWN (KEYC_OFFSET + 0x51) -#define KEYC_LEFT (KEYC_OFFSET + 0x52) -#define KEYC_RIGHT (KEYC_OFFSET + 0x53) - -/* Numeric keypad. Numbered from top-left, KPY_X. */ -#define KEYC_KP0_1 (KEYC_OFFSET + 0x100) -#define KEYC_KP0_2 (KEYC_OFFSET + 0x101) -#define KEYC_KP0_3 (KEYC_OFFSET + 0x102) -#define KEYC_KP1_0 (KEYC_OFFSET + 0x103) -#define KEYC_KP1_1 (KEYC_OFFSET + 0x104) -#define KEYC_KP1_2 (KEYC_OFFSET + 0x105) -#define KEYC_KP1_3 (KEYC_OFFSET + 0x106) -#define KEYC_KP2_0 (KEYC_OFFSET + 0x107) -#define KEYC_KP2_1 (KEYC_OFFSET + 0x108) -#define KEYC_KP2_2 (KEYC_OFFSET + 0x109) -#define KEYC_KP3_0 (KEYC_OFFSET + 0x10a) -#define KEYC_KP3_1 (KEYC_OFFSET + 0x10b) -#define KEYC_KP3_2 (KEYC_OFFSET + 0x10c) -#define KEYC_KP3_3 (KEYC_OFFSET + 0x10d) -#define KEYC_KP4_0 (KEYC_OFFSET + 0x10e) -#define KEYC_KP4_2 (KEYC_OFFSET + 0x10f) + /* Numeric keypad. Numbered from top-left, KPY_X. */ + KEYC_KP0_1, + KEYC_KP0_2, + KEYC_KP0_3, + KEYC_KP1_0, + KEYC_KP1_1, + KEYC_KP1_2, + KEYC_KP1_3, + KEYC_KP2_0, + KEYC_KP2_1, + KEYC_KP2_2, + KEYC_KP3_0, + KEYC_KP3_1, + KEYC_KP3_2, + KEYC_KP3_3, + KEYC_KP4_0, + KEYC_KP4_2, +}; /* Termcap codes. */ enum tty_code_code { diff --git a/tty-keys.c b/tty-keys.c index 3b8a3b45..5e207aa6 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -76,14 +76,14 @@ struct tty_key_ent tty_keys[] = { { 0, "\033[C", KEYC_RIGHT, TTYKEY_RAW }, { 0, "\033[D", KEYC_LEFT, TTYKEY_RAW }, - { 0, "\033Oa", KEYC_ADDCTL(KEYC_UP), TTYKEY_RAW }, - { 0, "\033Ob", KEYC_ADDCTL(KEYC_DOWN), TTYKEY_RAW }, - { 0, "\033Oc", KEYC_ADDCTL(KEYC_RIGHT), TTYKEY_RAW }, - { 0, "\033Od", KEYC_ADDCTL(KEYC_LEFT), TTYKEY_RAW }, - { 0, "\033[a", KEYC_ADDSFT(KEYC_UP), TTYKEY_RAW }, - { 0, "\033[b", KEYC_ADDSFT(KEYC_DOWN), TTYKEY_RAW }, - { 0, "\033[c", KEYC_ADDSFT(KEYC_RIGHT), TTYKEY_RAW }, - { 0, "\033[d", KEYC_ADDSFT(KEYC_LEFT), TTYKEY_RAW }, + { 0, "\033Oa", KEYC_UP | KEYC_CTRL, TTYKEY_RAW }, + { 0, "\033Ob", KEYC_DOWN | KEYC_CTRL, TTYKEY_RAW }, + { 0, "\033Oc", KEYC_RIGHT | KEYC_CTRL, TTYKEY_RAW }, + { 0, "\033Od", KEYC_LEFT | KEYC_CTRL, TTYKEY_RAW }, + { 0, "\033[a", KEYC_UP | KEYC_SHIFT, TTYKEY_RAW }, + { 0, "\033[b", KEYC_DOWN | KEYC_SHIFT, TTYKEY_RAW }, + { 0, "\033[c", KEYC_RIGHT | KEYC_SHIFT, TTYKEY_RAW }, + { 0, "\033[d", KEYC_LEFT | KEYC_SHIFT, TTYKEY_RAW }, { TTYC_KCUU1, NULL, KEYC_UP, TTYKEY_CTRL }, { TTYC_KCUD1, NULL, KEYC_DOWN, TTYKEY_CTRL }, @@ -179,7 +179,7 @@ tty_keys_init(struct tty *tty) if (strlcpy(tmp, s, sizeof tmp) >= sizeof tmp) continue; tmp[strlen(tmp) - 1] ^= 0x20; - tty_keys_add(tty, tmp + 1, KEYC_ADDCTL(tke->key), 0); + tty_keys_add(tty, tmp + 1, tke->key | KEYC_CTRL, 0); } } } @@ -289,7 +289,7 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse) /* Is there a normal key following? */ if (len != 0 && *buf != '\033') { buffer_remove(tty->in, 1); - *key = KEYC_ADDESC(buffer_read8(tty->in)); + *key = buffer_read8(tty->in) | KEYC_ESCAPE; goto found; } @@ -298,7 +298,7 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse) tk = tty_keys_find(tty, buf + 1, len - 1, &size); if (tk != NULL) { buffer_remove(tty->in, size + 2); - *key = KEYC_ADDESC(tk->key); + *key = tk->key | KEYC_ESCAPE; goto found; } } @@ -380,30 +380,25 @@ tty_keys_parse_xterm(struct tty *tty, char *buf, size_t len, size_t *size) switch (buf[4]) { case '8': - key = KEYC_ADDSFT(key); - key = KEYC_ADDESC(key); - key = KEYC_ADDCTL(key); + key |= KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL; break; case '7': - key = KEYC_ADDESC(key); - key = KEYC_ADDCTL(key); + key |= KEYC_ESCAPE|KEYC_CTRL; break; case '6': - key = KEYC_ADDSFT(key); - key = KEYC_ADDCTL(key); + key |= KEYC_SHIFT|KEYC_CTRL; break; case '5': - key = KEYC_ADDCTL(key); + key |= KEYC_CTRL; break; case '4': - key = KEYC_ADDSFT(key); - key = KEYC_ADDESC(key); + key |= KEYC_SHIFT|KEYC_ESCAPE; break; case '3': - key = KEYC_ADDESC(key); + key |= KEYC_ESCAPE; break; case '2': - key = KEYC_ADDSFT(key); + key |= KEYC_SHIFT; break; }