add support for keycode instead of only string

This commit is contained in:
Julien Danjou 2008-01-20 17:55:09 +01:00
parent bd8ede8d74
commit db3931c549
2 changed files with 16 additions and 2 deletions

View File

@ -312,6 +312,7 @@ Note: when there is no whitespace, quotes are optional.
<image> -> "/home/awesome/pics/icon.png" (path to image)
<integer> -> 1, 10, -3 (positive numbers are required mostly)
<key> -> a, 1, F10 (see /usr/include/X11/keysymdef.h w/o XK_ or 'xev')
or a keycode beginning with #
<mod> -> "Mod1", "Mod4", "Control" (modifiers)
<regex> -> regular expression
<string> -> "foo bar"

View File

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