summaryrefslogtreecommitdiffstats
path: root/key-string.c
diff options
context:
space:
mode:
authornicm <nicm>2020-02-19 14:25:00 +0000
committernicm <nicm>2020-02-19 14:25:00 +0000
commitb20753f2a302d07829549dfbd249bd210374fec4 (patch)
treebc975a68e6e539a227a6fc94b584bdcf5d85578b /key-string.c
parenta1f6bd55b652cd1658a005f96bbb667d637fe347 (diff)
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 'key-string.c')
-rw-r--r--key-string.c126
1 files changed, 79 insertions, 47 deletions
diff --git a/key-string.c b/key-string.c
index 0505623e..d2b31e03 100644
--- a/key-string.c
+++ b/key-string.c
@@ -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);
}