diff options
author | 2020-02-19 14:25:00 +0000 | |
---|---|---|
committer | 2020-02-19 14:25:00 +0000 | |
commit | b44a6ab906e8b32c4719e057e9158f2df53e5bed (patch) | |
tree | 8470af9fe371bde6195965fecae094b0f1dcffb3 /usr.bin/tmux/key-string.c | |
parent | document new option combo (diff) | |
download | wireguard-openbsd-b44a6ab906e8b32c4719e057e9158f2df53e5bed.tar.xz wireguard-openbsd-b44a6ab906e8b32c4719e057e9158f2df53e5bed.zip |
A few fixes to make modifier keys and dragging work - need to remove the
modifiers before checking for the dragging marker key, and apply them
before looking up the end key. Also fix key-to-string with modifiers for
special keys.
Diffstat (limited to 'usr.bin/tmux/key-string.c')
-rw-r--r-- | usr.bin/tmux/key-string.c | 128 |
1 files changed, 80 insertions, 48 deletions
diff --git a/usr.bin/tmux/key-string.c b/usr.bin/tmux/key-string.c index bd6b4b8f662..bba1708449a 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.52 2019/11/14 07:55:01 nicm Exp $ */ +/* $OpenBSD: key-string.c,v 1.53 2020/02/19 14:25:00 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -242,53 +242,90 @@ key_string_lookup_string(const char *string) const char * key_string_lookup_key(key_code key) { - static char out[32]; - char tmp[8]; - u_int i; - struct utf8_data ud; - size_t off; + static char out[32]; + char tmp[8]; + const char *s; + u_int i; + struct utf8_data ud; + size_t off; *out = '\0'; + /* Literal keys are themselves. */ + if (key & KEYC_LITERAL) { + snprintf(out, sizeof out, "%c", (int)(key & 0xff)); + return (out); + } + + /* Fill in the modifiers. */ + if (key & KEYC_CTRL) + strlcat(out, "C-", sizeof out); + if (key & KEYC_ESCAPE) + strlcat(out, "M-", sizeof out); + if (key & KEYC_SHIFT) + strlcat(out, "S-", sizeof out); + key &= KEYC_MASK_KEY; + /* Handle no key. */ if (key == KEYC_NONE) return ("None"); /* Handle special keys. */ - if (key == KEYC_UNKNOWN) - return ("Unknown"); - if (key == KEYC_ANY) - return ("Any"); - if (key == KEYC_FOCUS_IN) - return ("FocusIn"); - if (key == KEYC_FOCUS_OUT) - return ("FocusOut"); - if (key == KEYC_PASTE_START) - return ("PasteStart"); - if (key == KEYC_PASTE_END) - return ("PasteEnd"); - if (key == KEYC_MOUSE) - return ("Mouse"); - if (key == KEYC_DRAGGING) - return ("Dragging"); - if (key == KEYC_MOUSEMOVE_PANE) - return ("MouseMovePane"); - if (key == KEYC_MOUSEMOVE_STATUS) - return ("MouseMoveStatus"); - if (key == KEYC_MOUSEMOVE_STATUS_LEFT) - return ("MouseMoveStatusLeft"); - if (key == KEYC_MOUSEMOVE_STATUS_RIGHT) - return ("MouseMoveStatusRight"); - if (key == KEYC_MOUSEMOVE_BORDER) - return ("MouseMoveBorder"); - if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) { - snprintf(out, sizeof out, "User%u", (u_int)(key - KEYC_USER)); - return (out); + if (key == KEYC_UNKNOWN) { + s = "Unknown"; + goto append; } - - /* Literal keys are themselves. */ - if (key & KEYC_LITERAL) { - snprintf(out, sizeof out, "%c", (int)(key & 0xff)); + if (key == KEYC_ANY) { + s = "Any"; + goto append; + } + if (key == KEYC_FOCUS_IN) { + s = "FocusIn"; + goto append; + } + if (key == KEYC_FOCUS_OUT) { + s = "FocusOut"; + goto append; + } + if (key == KEYC_PASTE_START) { + s = "PasteStart"; + goto append; + } + if (key == KEYC_PASTE_END) { + s = "PasteEnd"; + goto append; + } + if (key == KEYC_MOUSE) { + s = "Mouse"; + goto append; + } + if (key == KEYC_DRAGGING) { + s = "Dragging"; + goto append; + } + if (key == KEYC_MOUSEMOVE_PANE) { + s = "MouseMovePane"; + goto append; + } + if (key == KEYC_MOUSEMOVE_STATUS) { + s = "MouseMoveStatus"; + goto append; + } + if (key == KEYC_MOUSEMOVE_STATUS_LEFT) { + s = "MouseMoveStatusLeft"; + goto append; + } + if (key == KEYC_MOUSEMOVE_STATUS_RIGHT) { + s = "MouseMoveStatusRight"; + goto append; + } + if (key == KEYC_MOUSEMOVE_BORDER) { + s = "MouseMoveBorder"; + goto append; + } + if (key >= KEYC_USER && key < KEYC_USER + KEYC_NUSER) { + snprintf(tmp, sizeof tmp, "User%u", (u_int)(key - KEYC_USER)); + strlcat(out, tmp, sizeof out); return (out); } @@ -301,15 +338,6 @@ key_string_lookup_key(key_code key) if ((key & KEYC_MASK_KEY) == 0) key = ' ' | KEYC_CTRL | (key & KEYC_MASK_MOD); - /* Fill in the modifiers. */ - if (key & KEYC_CTRL) - strlcat(out, "C-", sizeof out); - if (key & KEYC_ESCAPE) - strlcat(out, "M-", sizeof out); - if (key & KEYC_SHIFT) - strlcat(out, "S-", sizeof out); - key &= KEYC_MASK_KEY; - /* Try the key against the string table. */ for (i = 0; i < nitems(key_string_table); i++) { if (key == key_string_table[i].key) @@ -352,4 +380,8 @@ key_string_lookup_key(key_code key) strlcat(out, tmp, sizeof out); return (out); + +append: + strlcat(out, s, sizeof out); + return (out); } |