summaryrefslogtreecommitdiff
path: root/usr.bin/tmux
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-07-21 17:57:30 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-07-21 17:57:30 +0000
commite7796ea112614fab8a2d1f5ceee96df733f498cc (patch)
tree1f73d20ddb3d8313d62af366398cf245b5c28090 /usr.bin/tmux
parent73cb0c874fa1a730790bc919cef8d73e5d749f74 (diff)
Tidy up keys: use an enum for the key codes, and remove the macros which just
wrap flag sets/clears/tests.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r--usr.bin/tmux/cmd-next-window.c4
-rw-r--r--usr.bin/tmux/cmd-previous-window.c4
-rw-r--r--usr.bin/tmux/cmd-resize-pane.c20
-rw-r--r--usr.bin/tmux/cmd-rotate-window.c4
-rw-r--r--usr.bin/tmux/cmd-select-layout.c12
-rw-r--r--usr.bin/tmux/input-keys.c52
-rw-r--r--usr.bin/tmux/key-bindings.c32
-rw-r--r--usr.bin/tmux/key-string.c20
-rw-r--r--usr.bin/tmux/mode-key.c16
-rw-r--r--usr.bin/tmux/tmux.h137
-rw-r--r--usr.bin/tmux/tty-keys.c43
11 files changed, 164 insertions, 180 deletions
diff --git a/usr.bin/tmux/cmd-next-window.c b/usr.bin/tmux/cmd-next-window.c
index 7fd11e041cf..f3bfae17f6e 100644
--- a/usr.bin/tmux/cmd-next-window.c
+++ b/usr.bin/tmux/cmd-next-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-next-window.c,v 1.3 2009/07/13 23:11:35 nicm Exp $ */
+/* $OpenBSD: cmd-next-window.c,v 1.4 2009/07/21 17:57:29 nicm 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');
}
diff --git a/usr.bin/tmux/cmd-previous-window.c b/usr.bin/tmux/cmd-previous-window.c
index ba262e123dc..ae0abdcee50 100644
--- a/usr.bin/tmux/cmd-previous-window.c
+++ b/usr.bin/tmux/cmd-previous-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-previous-window.c,v 1.3 2009/07/13 23:11:35 nicm Exp $ */
+/* $OpenBSD: cmd-previous-window.c,v 1.4 2009/07/21 17:57:29 nicm 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');
}
diff --git a/usr.bin/tmux/cmd-resize-pane.c b/usr.bin/tmux/cmd-resize-pane.c
index 4a5c48a0eac..6e9377ad134 100644
--- a/usr.bin/tmux/cmd-resize-pane.c
+++ b/usr.bin/tmux/cmd-resize-pane.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-resize-pane.c,v 1.3 2009/07/19 13:21:40 nicm Exp $ */
+/* $OpenBSD: cmd-resize-pane.c,v 1.4 2009/07/21 17:57:29 nicm 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");
}
diff --git a/usr.bin/tmux/cmd-rotate-window.c b/usr.bin/tmux/cmd-rotate-window.c
index 1b8ec77f52e..d18f704d6d3 100644
--- a/usr.bin/tmux/cmd-rotate-window.c
+++ b/usr.bin/tmux/cmd-rotate-window.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-rotate-window.c,v 1.7 2009/07/19 13:21:40 nicm Exp $ */
+/* $OpenBSD: cmd-rotate-window.c,v 1.8 2009/07/21 17:57:29 nicm 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');
}
diff --git a/usr.bin/tmux/cmd-select-layout.c b/usr.bin/tmux/cmd-select-layout.c
index 70dfd1f6e17..0fbfa77f052 100644
--- a/usr.bin/tmux/cmd-select-layout.c
+++ b/usr.bin/tmux/cmd-select-layout.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-select-layout.c,v 1.3 2009/07/19 13:21:40 nicm Exp $ */
+/* $OpenBSD: cmd-select-layout.c,v 1.4 2009/07/21 17:57:29 nicm 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;
}
diff --git a/usr.bin/tmux/input-keys.c b/usr.bin/tmux/input-keys.c
index dc49f709d73..0e54ccf6673 100644
--- a/usr.bin/tmux/input-keys.c
+++ b/usr.bin/tmux/input-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: input-keys.c,v 1.1 2009/06/01 22:58:49 nicm Exp $ */
+/* $OpenBSD: input-keys.c,v 1.2 2009/07/21 17:57:29 nicm 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;
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index 79e7f5e6f25..ed15338c715 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.6 2009/07/19 13:21:40 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.7 2009/07/21 17:57:29 nicm 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;
diff --git a/usr.bin/tmux/key-string.c b/usr.bin/tmux/key-string.c
index 62dce29e9c1..73e6f983e2b 100644
--- a/usr.bin/tmux/key-string.c
+++ b/usr.bin/tmux/key-string.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-string.c,v 1.2 2009/07/14 06:56:30 nicm Exp $ */
+/* $OpenBSD: key-string.c,v 1.3 2009/07/21 17:57:29 nicm 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);
diff --git a/usr.bin/tmux/mode-key.c b/usr.bin/tmux/mode-key.c
index 79c3a473c50..2c274d71e39 100644
--- a/usr.bin/tmux/mode-key.c
+++ b/usr.bin/tmux/mode-key.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mode-key.c,v 1.2 2009/07/12 16:15:34 nicm Exp $ */
+/* $OpenBSD: mode-key.c,v 1.3 2009/07/21 17:57:29 nicm 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:
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index 3f22823be5a..76747eab938 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.40 2009/07/20 14:37:51 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.41 2009/07/21 17:57:29 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -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_ADDESC(k) ((k) | KEYC_ESCAPE)
-#define KEYC_REMOVEESC(k) ((k) & ~KEYC_ESCAPE)
-#define KEYC_ISESC(k) ((k) != KEYC_NONE && ((k) & KEYC_ESCAPE))
-
-#define KEYC_ADDCTL(k) ((k) | KEYC_CONTROL)
-#define KEYC_REMOVECTL(k) ((k) & ~KEYC_CONTROL)
-#define KEYC_ISCTL(k) ((k) != KEYC_NONE && ((k) & KEYC_CONTROL))
-
-#define KEYC_ADDSFT(k) ((k) | KEYC_SHIFT)
-#define KEYC_REMOVESFT(k) ((k) & ~KEYC_SHIFT)
-#define KEYC_ISSFT(k) ((k) != KEYC_NONE && ((k) & KEYC_SHIFT))
-
-/* 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)
+#define KEYC_NONE 0x0fff
+#define KEYC_ESCAPE 0x2000
+#define KEYC_CTRL 0x4000
+#define KEYC_SHIFT 0x8000
+
+enum key_code {
+ /* Mouse key. */
+ KEYC_MOUSE = 0x1000,
+
+ /* 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,
+
+ /* Arrow keys. */
+ KEYC_UP,
+ KEYC_DOWN,
+ KEYC_LEFT,
+ KEYC_RIGHT,
+
+ /* 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/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c
index 524da45bcf7..9d95a220663 100644
--- a/usr.bin/tmux/tty-keys.c
+++ b/usr.bin/tmux/tty-keys.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tty-keys.c,v 1.1 2009/06/01 22:58:49 nicm Exp $ */
+/* $OpenBSD: tty-keys.c,v 1.2 2009/07/21 17:57:29 nicm 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;
}