key: change setmodifiers to tomodifiers
This is more Lua compliant. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
5c775b06c0
commit
5eadbc0116
6
button.c
6
button.c
|
@ -83,8 +83,7 @@ luaA_button_new(lua_State *L)
|
||||||
button->press = press;
|
button->press = press;
|
||||||
button->release = release;
|
button->release = release;
|
||||||
button->button = xbutton;
|
button->button = xbutton;
|
||||||
|
button->mod = luaA_tomodifiers(L, 2);
|
||||||
luaA_setmodifiers(L, 2, &button->mod);
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -196,7 +195,8 @@ luaA_button_newindex(lua_State *L)
|
||||||
button->button = luaL_checknumber(L, 3);
|
button->button = luaL_checknumber(L, 3);
|
||||||
break;
|
break;
|
||||||
case A_TK_MODIFIERS:
|
case A_TK_MODIFIERS:
|
||||||
luaA_setmodifiers(L, 3, &button->mod);
|
button->mod = luaA_tomodifiers(L, 3);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
16
key.c
16
key.c
|
@ -1046,7 +1046,7 @@ luaA_key_new(lua_State *L)
|
||||||
k->press = press;
|
k->press = press;
|
||||||
k->release = release;
|
k->release = release;
|
||||||
|
|
||||||
luaA_setmodifiers(L, 2, &k->mod);
|
k->mod = luaA_tomodifiers(L, 2);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1110,24 +1110,26 @@ luaA_pushmodifiers(lua_State *L, uint16_t modifiers)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Take a modifier table from the stack and set modifiers in mod.
|
/** Take a modifier table from the stack and return modifiers mask.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
* \param ud The index of the table.
|
* \param ud The index of the table.
|
||||||
* \param mod Where to set the modifiers.
|
* \return The mask value.
|
||||||
*/
|
*/
|
||||||
void
|
uint16_t
|
||||||
luaA_setmodifiers(lua_State *L, int ud, uint16_t *mod)
|
luaA_tomodifiers(lua_State *L, int ud)
|
||||||
{
|
{
|
||||||
luaA_checktable(L, ud);
|
luaA_checktable(L, ud);
|
||||||
ssize_t len = lua_objlen(L, ud);
|
ssize_t len = lua_objlen(L, ud);
|
||||||
|
uint16_t mod = XCB_NONE;
|
||||||
for(int i = 1; i <= len; i++)
|
for(int i = 1; i <= len; i++)
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, ud, i);
|
lua_rawgeti(L, ud, i);
|
||||||
size_t blen;
|
size_t blen;
|
||||||
const char *key = luaL_checklstring(L, -1, &blen);
|
const char *key = luaL_checklstring(L, -1, &blen);
|
||||||
*mod |= xutil_key_mask_fromstr(key, blen);
|
mod |= xutil_key_mask_fromstr(key, blen);
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Key object.
|
/** Key object.
|
||||||
|
@ -1213,7 +1215,7 @@ luaA_key_newindex(lua_State *L)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case A_TK_MODIFIERS:
|
case A_TK_MODIFIERS:
|
||||||
luaA_setmodifiers(L, 3, &k->mod);
|
k->mod = luaA_tomodifiers(L, 3);
|
||||||
break;
|
break;
|
||||||
case A_TK_PRESS:
|
case A_TK_PRESS:
|
||||||
luaA_registerfct(L, 3, &k->press);
|
luaA_registerfct(L, 3, &k->press);
|
||||||
|
|
4
key.h
4
key.h
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* key.h - Keybinding helpers
|
* key.h - Keybinding helpers
|
||||||
*
|
*
|
||||||
* Copyright © 2008 Pierre Habouzit <madcoder@debian.org>
|
* Copyright © 2009 Julien Danjou <julien@danjou.info>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -49,6 +49,6 @@ int luaA_key_array_get(lua_State *, key_array_t *);
|
||||||
|
|
||||||
void window_grabkeys(xcb_window_t, key_array_t *);
|
void window_grabkeys(xcb_window_t, key_array_t *);
|
||||||
int luaA_pushmodifiers(lua_State *, uint16_t);
|
int luaA_pushmodifiers(lua_State *, uint16_t);
|
||||||
void luaA_setmodifiers(lua_State *, int, uint16_t *);
|
uint16_t luaA_tomodifiers(lua_State *L, int ud);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue