diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 913e3a735..2245ad540 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -13,7 +13,9 @@ center class client color +Control coords +Ctrl east fg flex @@ -35,8 +37,14 @@ label layout left line +Lock machine minimize +Mod1 +Mod2 +Mod3 +Mod4 +Mod5 mouse_enter mouse_leave mwfact @@ -58,6 +66,7 @@ screen selected shadow shadow_offset +Shift show_icons sizehints south diff --git a/common/xutil.c b/common/xutil.c index 22f4fcde1..8f262b4b3 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -333,39 +333,22 @@ xutil_error_init(const xcb_generic_error_t *e, xutil_error_t *err) return true; } -/** Link a name to a key symbol */ -typedef struct -{ - const char *name; - xcb_keysym_t keysym; -} keymod_t; - xcb_keysym_t -xutil_key_mask_fromstr(const char *keyname) +xutil_key_mask_fromstr(const char *keyname, size_t len) { - /** List of keyname and corresponding X11 mask codes */ - static const keymod_t KeyModList[] = + switch(a_tokenize(keyname, len)) { - { "Shift", XCB_MOD_MASK_SHIFT }, - { "Lock", XCB_MOD_MASK_LOCK }, - { "Control", XCB_MOD_MASK_CONTROL }, - { "Ctrl", XCB_MOD_MASK_CONTROL }, - { "Mod1", XCB_MOD_MASK_1 }, - { "Mod2", XCB_MOD_MASK_2 }, - { "Mod3", XCB_MOD_MASK_3 }, - { "Mod4", XCB_MOD_MASK_4 }, - { "Mod5", XCB_MOD_MASK_5 }, - { NULL, XCB_NO_SYMBOL } - }; - int i; - - if(keyname) - for(i = 0; KeyModList[i].name; i++) - if(!a_strcmp(keyname, KeyModList[i].name)) - return KeyModList[i].keysym; - - return XCB_NO_SYMBOL; - + case A_TK_SHIFT: return XCB_MOD_MASK_SHIFT; + case A_TK_LOCK: return XCB_MOD_MASK_LOCK; + case A_TK_CTRL: + case A_TK_CONTROL: return XCB_MOD_MASK_CONTROL; + case A_TK_MOD1: return XCB_MOD_MASK_1; + case A_TK_MOD2: return XCB_MOD_MASK_2; + case A_TK_MOD3: return XCB_MOD_MASK_3; + case A_TK_MOD4: return XCB_MOD_MASK_4; + case A_TK_MOD5: return XCB_MOD_MASK_5; + default: return XCB_NO_SYMBOL; + } } /** Permit to use mouse with many more buttons */ diff --git a/common/xutil.h b/common/xutil.h index 46640e977..cec59aa37 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -112,7 +112,7 @@ typedef struct } xutil_error_t; bool xutil_error_init(const xcb_generic_error_t *, xutil_error_t *); -xcb_keysym_t xutil_key_mask_fromstr(const char *); +xcb_keysym_t xutil_key_mask_fromstr(const char *, size_t); unsigned int xutil_button_fromint(int); xcb_cursor_t xutil_cursor_new(xcb_connection_t *, unsigned int); diff --git a/keybinding.c b/keybinding.c index ec88a2b09..154f9371b 100644 --- a/keybinding.c +++ b/keybinding.c @@ -348,8 +348,10 @@ luaA_keybinding_new(lua_State *L) len = lua_objlen(L, 2); for(i = 1; i <= len; i++) { + size_t blen; lua_rawgeti(L, 2, i); - k->mod |= xutil_key_mask_fromstr(luaL_checkstring(L, -1)); + key = luaL_checklstring(L, -1, &blen); + k->mod |= xutil_key_mask_fromstr(key, blen); } return luaA_keybinding_userdata_new(L, k); diff --git a/mouse.c b/mouse.c index 8a60e2d21..ccaa23ca2 100644 --- a/mouse.c +++ b/mouse.c @@ -1078,8 +1078,11 @@ luaA_button_new(lua_State *L) len = lua_objlen(L, 2); for(i = 1; i <= len; i++) { + size_t blen; + const char *buf; lua_rawgeti(L, 2, i); - button->mod |= xutil_key_mask_fromstr(luaL_checkstring(L, -1)); + buf = luaL_checklstring(L, -1, &blen); + button->mod |= xutil_key_mask_fromstr(buf, blen); } return luaA_button_userdata_new(L, button);