xutil: use token for keys

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-10-01 11:09:57 +02:00
parent 85b05def68
commit 031726c9b9
5 changed files with 30 additions and 33 deletions

View File

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

View File

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

View File

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

View File

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

View File

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