From db3931c5496653885e41b5edf20dc2b42ad64955 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 20 Jan 2008 17:55:09 +0100 Subject: [PATCH] add support for keycode instead of only string --- awesomerc.1.txt | 1 + config.c | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/awesomerc.1.txt b/awesomerc.1.txt index d3331f353..5a479c60f 100644 --- a/awesomerc.1.txt +++ b/awesomerc.1.txt @@ -312,6 +312,7 @@ Note: when there is no whitespace, quotes are optional. -> "/home/awesome/pics/icon.png" (path to image) -> 1, 10, -3 (positive numbers are required mostly) -> a, 1, F10 (see /usr/include/X11/keysymdef.h w/o XK_ or 'xev') + or a keycode beginning with # -> "Mod1", "Mod4", "Control" (modifiers) -> regular expression -> "foo bar" diff --git a/config.c b/config.c index dcf5de029..3ba5fb726 100644 --- a/config.c +++ b/config.c @@ -168,6 +168,19 @@ set_key_info(Key *key, cfg_t *cfg) warn("unknown command %s\n", cfg_getstr(cfg, "command")); } +static KeySym +key_to_keysym(char *str) +{ + KeyCode kc; + int ikc; + + if(a_strncmp(str, "#", 1)) + return XStringToKeysym(str); + + ikc = atoi(str + 1); + memcpy(&kc, &ikc, sizeof(KeyCode)); + return XKeycodeToKeysym(globalconf.display, kc, 0); +} static Key * section_keys(cfg_t *cfg_keys) @@ -181,7 +194,7 @@ section_keys(cfg_t *cfg_keys) key = p_new(Key, 1); cfgkeytmp = cfg_getnsec(cfg_keys, "key", i); set_key_info(key, cfgkeytmp); - key->keysym = XStringToKeysym(cfg_getstr(cfgkeytmp, "key")); + key->keysym = key_to_keysym(cfg_getstr(cfgkeytmp, "key")); key->arg = a_strdup(cfg_getstr(cfgkeytmp, "arg")); key_list_push(&head, key); } @@ -200,7 +213,7 @@ section_keys(cfg_t *cfg_keys) { key = p_new(Key, 1); set_key_info(key, cfgkeytmp); - key->keysym = XStringToKeysym(cfg_getnstr(cfgkeytmp, "keylist", j)); + key->keysym = key_to_keysym(cfg_getnstr(cfgkeytmp, "keylist", j)); key->arg = a_strdup(cfg_getnstr(cfgkeytmp, "arglist", j)); key_list_push(&head, key); }