[config] Store keysym or keycode (FS#64)

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-05-02 11:12:53 +02:00
parent 73dee91a28
commit 6623668b6f
4 changed files with 17 additions and 12 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

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

View File

@ -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);