diff options
author | Tiago Cunha <tcunha@gmx.com> | 2010-09-07 13:21:18 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2010-09-07 13:21:18 +0000 |
commit | afcc29a51d88745d8163fd7f53f596bb9a2a041f (patch) | |
tree | f6c3bf1149a58df30e9acdfd237e0a51654ab311 | |
parent | 33df467d40dbb4852e760ce84f594645b0b587a5 (diff) |
Sync OpenBSD patchset 757:
Simplify xterm modifier detection by treating as a bitmask + 1. Spotted
by and diff from Emanuele Giaquinta.
-rw-r--r-- | xterm-keys.c | 57 |
1 files changed, 20 insertions, 37 deletions
diff --git a/xterm-keys.c b/xterm-keys.c index 096489d8..9f98c7c5 100644 --- a/xterm-keys.c +++ b/xterm-keys.c @@ -1,4 +1,4 @@ -/* $Id: xterm-keys.c,v 1.5 2009-12-04 22:14:47 tcunha Exp $ */ +/* $Id: xterm-keys.c,v 1.6 2010-09-07 13:21:18 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -114,27 +114,21 @@ int xterm_keys_modifiers(const char *template, const char *buf, size_t len) { size_t idx; + int param, modifiers; idx = strcspn(template, "_"); if (idx >= len) return (0); - switch (buf[idx]) { - case '2': - return (KEYC_SHIFT); - case '3': - return (KEYC_ESCAPE); - case '4': - return (KEYC_SHIFT|KEYC_ESCAPE); - case '5': - return (KEYC_CTRL); - case '6': - return (KEYC_SHIFT|KEYC_CTRL); - case '7': - return (KEYC_ESCAPE|KEYC_CTRL); - case '8': - return (KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL); - } - return (0); + param = buf[idx] - '1'; + + modifiers = 0; + if (param & 1) + modifiers |= KEYC_SHIFT; + if (param & 2) + modifiers |= KEYC_ESCAPE; + if (param & 4) + modifiers |= KEYC_CTRL; + return (modifiers); } /* @@ -171,30 +165,19 @@ xterm_keys_lookup(int key) int modifiers; char *out; -#define KEY_MODIFIERS(key, modifiers) \ - (((key) & (KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL)) == (modifiers)) - modifiers = 0; - if (KEY_MODIFIERS(key, KEYC_SHIFT)) - modifiers = 2; - else if (KEY_MODIFIERS(key, KEYC_ESCAPE)) - modifiers = 3; - else if (KEY_MODIFIERS(key, KEYC_SHIFT|KEYC_ESCAPE)) - modifiers = 4; - else if (KEY_MODIFIERS(key, KEYC_CTRL)) - modifiers = 5; - else if (KEY_MODIFIERS(key, KEYC_SHIFT|KEYC_CTRL)) - modifiers = 6; - else if (KEY_MODIFIERS(key, KEYC_ESCAPE|KEYC_CTRL)) - modifiers = 7; - else if (KEY_MODIFIERS(key, KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL)) - modifiers = 8; -#undef KEY_MODIFIERS + modifiers = 1; + if (key & KEYC_SHIFT) + modifiers += 1; + if (key & KEYC_ESCAPE) + modifiers += 2; + if (key & KEYC_CTRL) + modifiers += 4; /* * If the key has no modifiers, return NULL and let it fall through to * the normal lookup. */ - if (modifiers == 0) + if (modifiers == 1) return (NULL); /* Otherwise, find the key in the table. */ |