[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
{
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);
}

View File

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

View File

@ -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 */

View File

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