From 6623668b6fc0d3eb641be2c09b889a1735b57adc Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 2 May 2008 11:12:53 +0200 Subject: [PATCH] [config] Store keysym or keycode (FS#64) Signed-off-by: Julien Danjou --- config.c | 24 ++++++++++++++---------- event.c | 2 +- structs.h | 1 + window.c | 2 +- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/config.c b/config.c index eb61404c..e060af10 100644 --- a/config.c +++ b/config.c @@ -165,18 +165,22 @@ set_key_info(Key *key, cfg_t *cfg) warn("unknown command %s\n", cfg_getstr(cfg, "command")); } -static KeySym -key_to_keysym(char *str) +static void +config_key_store(Key *key, 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); + if(!a_strlen(str)) + return; + else if(a_strncmp(str, "#", 1)) + key->keysym = XStringToKeysym(str); + else + { + ikc = atoi(str + 1); + memcpy(&kc, &ikc, sizeof(KeyCode)); + key->keycode = kc; + } } static Key * @@ -191,7 +195,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 = key_to_keysym(cfg_getstr(cfgkeytmp, "key")); + config_key_store(key, cfg_getstr(cfgkeytmp, "key")); key->arg = a_strdup(cfg_getstr(cfgkeytmp, "arg")); key_list_push(&head, key); } @@ -210,7 +214,7 @@ section_keys(cfg_t *cfg_keys) { key = p_new(Key, 1); set_key_info(key, cfgkeytmp); - key->keysym = key_to_keysym(cfg_getnstr(cfgkeytmp, "keylist", j)); + config_key_store(key, cfg_getnstr(cfgkeytmp, "keylist", j)); key->arg = a_strdup(cfg_getnstr(cfgkeytmp, "arglist", j)); key_list_push(&head, key); } diff --git a/event.c b/event.c index 26485c3f..d9011174 100644 --- a/event.c +++ b/event.c @@ -353,7 +353,7 @@ event_handle_keypress(XEvent *e) keysym = XKeycodeToKeysym(globalconf.display, (KeyCode) ev->keycode, 0); for(k = globalconf.keys; k; k = k->next) - if(keysym == k->keysym && + if((ev->keycode == k->keycode || keysym == k->keysym) && k->func && CLEANMASK(k->mod) == CLEANMASK(ev->state)) k->func(screen, k->arg); } diff --git a/structs.h b/structs.h index 0af8c705..65129415 100644 --- a/structs.h +++ b/structs.h @@ -81,6 +81,7 @@ struct Key { unsigned long mod; KeySym keysym; + KeyCode keycode; Uicb *func; char *arg; /** Next and previous keys */ diff --git a/window.c b/window.c index 83a7e5c6..048d87f5 100644 --- a/window.c +++ b/window.c @@ -162,7 +162,7 @@ window_root_grabkeys(int phys_screen) XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen)); for(k = globalconf.keys; k; k = k->next) - if(k->keysym && (kc = XKeysymToKeycode(globalconf.display, k->keysym))) + if((kc = k->keycode) || (k->keysym && (kc = XKeysymToKeycode(globalconf.display, k->keysym)))) { XGrabKey(globalconf.display, kc, k->mod, RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);