mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Sync OpenBSD patchset 151:
Tidy up keys: use an enum for the key codes, and remove the macros which just wrap flag sets/clears/tests.
This commit is contained in:
parent
94e2339842
commit
a734488a4b
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-next-window.c,v 1.18 2009-07-14 06:43:32 nicm Exp $ */
|
||||
/* $Id: cmd-next-window.c,v 1.19 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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');
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-previous-window.c,v 1.18 2009-07-14 06:43:32 nicm Exp $ */
|
||||
/* $Id: cmd-previous-window.c,v 1.19 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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');
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-resize-pane.c,v 1.9 2009-07-20 15:42:05 tcunha Exp $ */
|
||||
/* $Id: cmd-resize-pane.c,v 1.10 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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");
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-rotate-window.c,v 1.7 2009-07-20 15:42:05 tcunha Exp $ */
|
||||
/* $Id: cmd-rotate-window.c,v 1.8 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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');
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: cmd-select-layout.c,v 1.5 2009-07-20 15:42:05 tcunha Exp $ */
|
||||
/* $Id: cmd-select-layout.c,v 1.6 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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;
|
||||
}
|
||||
|
52
input-keys.c
52
input-keys.c
@ -1,4 +1,4 @@
|
||||
/* $Id: input-keys.c,v 1.27 2009-05-04 17:58:26 nicm Exp $ */
|
||||
/* $Id: input-keys.c,v 1.28 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $Id: key-bindings.c,v 1.77 2009-07-20 15:42:05 tcunha Exp $ */
|
||||
/* $Id: key-bindings.c,v 1.78 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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;
|
||||
|
20
key-string.c
20
key-string.c
@ -1,4 +1,4 @@
|
||||
/* $Id: key-string.c,v 1.18 2009-07-14 06:38:14 nicm Exp $ */
|
||||
/* $Id: key-string.c,v 1.19 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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);
|
||||
|
16
mode-key.c
16
mode-key.c
@ -1,4 +1,4 @@
|
||||
/* $Id: mode-key.c,v 1.13 2009-07-14 06:39:10 nicm Exp $ */
|
||||
/* $Id: mode-key.c,v 1.14 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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:
|
||||
|
129
tmux.h
129
tmux.h
@ -1,4 +1,4 @@
|
||||
/* $Id: tmux.h,v 1.374 2009-07-20 16:07:23 tcunha Exp $ */
|
||||
/* $Id: tmux.h,v 1.375 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -101,79 +101,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 {
|
||||
|
43
tty-keys.c
43
tty-keys.c
@ -1,4 +1,4 @@
|
||||
/* $Id: tty-keys.c,v 1.27 2009-05-04 18:05:23 nicm Exp $ */
|
||||
/* $Id: tty-keys.c,v 1.28 2009-07-22 16:24:59 tcunha Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user