[keys] Store KeySym, not KeyCode

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-04-18 14:57:52 +02:00
parent cbef649a2d
commit bbb1b233ca
4 changed files with 24 additions and 20 deletions

View File

@ -48,7 +48,7 @@ extern cfg_opt_t awesome_opts[];
typedef struct typedef struct
{ {
const char *name; const char *name;
KeyCode keycode; KeySym keysym;
} KeyMod; } KeyMod;
/** Link a name to a mouse button symbol */ /** Link a name to a mouse button symbol */
@ -67,7 +67,7 @@ extern const name_func_link_t FloatingPlacementList[];
* \param keyname Key name * \param keyname Key name
* \return Key mask or 0 if not found * \return Key mask or 0 if not found
*/ */
static KeyCode static KeySym
key_mask_lookup(const char *keyname) key_mask_lookup(const char *keyname)
{ {
/** List of keyname and corresponding X11 mask codes */ /** List of keyname and corresponding X11 mask codes */
@ -88,7 +88,7 @@ key_mask_lookup(const char *keyname)
if(keyname) if(keyname)
for(i = 0; KeyModList[i].name; i++) for(i = 0; KeyModList[i].name; i++)
if(!a_strcmp(keyname, KeyModList[i].name)) if(!a_strcmp(keyname, KeyModList[i].name))
return KeyModList[i].keycode; return KeyModList[i].keysym;
return 0; return 0;
} }
@ -165,18 +165,18 @@ set_key_info(Key *key, cfg_t *cfg)
warn("unknown command %s\n", cfg_getstr(cfg, "command")); warn("unknown command %s\n", cfg_getstr(cfg, "command"));
} }
static KeyCode static KeySym
key_to_keycode(char *str) key_to_keysym(char *str)
{ {
KeyCode kc; KeyCode kc;
int ikc; int ikc;
if(a_strncmp(str, "#", 1)) if(a_strncmp(str, "#", 1))
return XKeysymToKeycode(globalconf.display, XStringToKeysym(str)); return XStringToKeysym(str);
ikc = atoi(str + 1); ikc = atoi(str + 1);
memcpy(&kc, &ikc, sizeof(KeyCode)); memcpy(&kc, &ikc, sizeof(KeyCode));
return kc; return XKeycodeToKeysym(globalconf.display, kc, 0);
} }
static Key * static Key *
@ -191,7 +191,7 @@ section_keys(cfg_t *cfg_keys)
key = p_new(Key, 1); key = p_new(Key, 1);
cfgkeytmp = cfg_getnsec(cfg_keys, "key", i); cfgkeytmp = cfg_getnsec(cfg_keys, "key", i);
set_key_info(key, cfgkeytmp); 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->arg = a_strdup(cfg_getstr(cfgkeytmp, "arg"));
key_list_push(&head, key); key_list_push(&head, key);
} }
@ -210,7 +210,7 @@ section_keys(cfg_t *cfg_keys)
{ {
key = p_new(Key, 1); key = p_new(Key, 1);
set_key_info(key, cfgkeytmp); 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->arg = a_strdup(cfg_getnstr(cfgkeytmp, "arglist", j));
key_list_push(&head, key); key_list_push(&head, key);
} }

View File

@ -334,6 +334,7 @@ event_handle_keypress(XEvent *e)
int screen, x, y, d; int screen, x, y, d;
unsigned int m; unsigned int m;
XKeyEvent *ev = &e->xkey; XKeyEvent *ev = &e->xkey;
KeySym keysym;
Window dummy; Window dummy;
Key *k; Key *k;
@ -349,8 +350,10 @@ event_handle_keypress(XEvent *e)
break; break;
} }
keysym = XKeycodeToKeysym(globalconf.display, (KeyCode) ev->keycode, 0);
for(k = globalconf.keys; k; k = k->next) 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 && CLEANMASK(k->mod) == CLEANMASK(ev->state))
k->func(screen, k->arg); k->func(screen, k->arg);
} }

View File

@ -80,7 +80,7 @@ typedef struct Key Key;
struct Key struct Key
{ {
unsigned long mod; unsigned long mod;
KeyCode keycode; KeySym keysym;
Uicb *func; Uicb *func;
char *arg; char *arg;
/** Next and previous keys */ /** Next and previous keys */

View File

@ -157,20 +157,21 @@ void
window_root_grabkeys(int phys_screen) window_root_grabkeys(int phys_screen)
{ {
Key *k; Key *k;
KeyCode kc;
XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen)); XUngrabKey(globalconf.display, AnyKey, AnyModifier, RootWindow(globalconf.display, phys_screen));
for(k = globalconf.keys; k; k = k->next) 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, XGrabKey(globalconf.display, kc, k->mod,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(globalconf.display, k->keycode, k->mod | LockMask, XGrabKey(globalconf.display, kc, k->mod | LockMask,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask, XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
XGrabKey(globalconf.display, k->keycode, k->mod | globalconf.numlockmask | LockMask, XGrabKey(globalconf.display, kc, k->mod | globalconf.numlockmask | LockMask,
RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync); RootWindow(globalconf.display, phys_screen), True, GrabModeAsync, GrabModeAsync);
} }
} }