diff --git a/config.c b/config.c index 6cf142c47..cd9673214 100644 --- a/config.c +++ b/config.c @@ -48,7 +48,7 @@ extern cfg_opt_t awesome_opts[]; typedef struct { const char *name; - KeyCode keycode; + KeySym keysym; } KeyMod; /** Link a name to a mouse button symbol */ @@ -67,7 +67,7 @@ extern const name_func_link_t FloatingPlacementList[]; * \param keyname Key name * \return Key mask or 0 if not found */ -static KeyCode +static KeySym key_mask_lookup(const char *keyname) { /** List of keyname and corresponding X11 mask codes */ @@ -88,7 +88,7 @@ key_mask_lookup(const char *keyname) if(keyname) for(i = 0; KeyModList[i].name; i++) if(!a_strcmp(keyname, KeyModList[i].name)) - return KeyModList[i].keycode; + return KeyModList[i].keysym; return 0; } @@ -165,18 +165,18 @@ set_key_info(Key *key, cfg_t *cfg) warn("unknown command %s\n", cfg_getstr(cfg, "command")); } -static KeyCode -key_to_keycode(char *str) +static KeySym +key_to_keysym(char *str) { KeyCode kc; int ikc; if(a_strncmp(str, "#", 1)) - return XKeysymToKeycode(globalconf.display, XStringToKeysym(str)); + return XStringToKeysym(str); ikc = atoi(str + 1); memcpy(&kc, &ikc, sizeof(KeyCode)); - return kc; + return XKeycodeToKeysym(globalconf.display, kc, 0); } static Key * @@ -191,7 +191,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->keycode = key_to_keycode(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); } @@ -210,7 +210,7 @@ section_keys(cfg_t *cfg_keys) { key = p_new(Key, 1); set_key_info(key, cfgkeytmp); - key->keycode = key_to_keycode(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); } diff --git a/event.c b/event.c index 433b20400..26485c3f2 100644 --- a/event.c +++ b/event.c @@ -334,6 +334,7 @@ event_handle_keypress(XEvent *e) int screen, x, y, d; unsigned int m; XKeyEvent *ev = &e->xkey; + KeySym keysym; Window dummy; Key *k; @@ -349,8 +350,10 @@ event_handle_keypress(XEvent *e) break; } + keysym = XKeycodeToKeysym(globalconf.display, (KeyCode) ev->keycode, 0); + for(k = globalconf.keys; k; k = k->next) - if(ev->keycode == k->keycode && + if(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 464117bc1..0af8c705e 100644 --- a/structs.h +++ b/structs.h @@ -80,7 +80,7 @@ typedef struct Key Key; struct Key { unsigned long mod; - KeyCode keycode; + KeySym keysym; Uicb *func; char *arg; /** Next and previous keys */ diff --git a/window.c b/window.c index 4bcc30827..83a7e5c62 100644 --- a/window.c +++ b/window.c @@ -157,20 +157,21 @@ void window_root_grabkeys(int phys_screen) { Key *k; + KeyCode kc; XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen)); for(k = globalconf.keys; k; k = k->next) - if(k->keycode) + if(k->keysym && (kc = XKeysymToKeycode(globalconf.display, k->keysym))) { - XGrabKey(globalconf.display, k->keycode, k->mod, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | LockMask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); - XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask | LockMask, - RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, kc, k->mod, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, kc, k->mod | LockMask, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); + XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask | LockMask, + RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); } }