diff --git a/button.c b/button.c index 5a5c545b..b2dd5c97 100644 --- a/button.c +++ b/button.c @@ -83,8 +83,7 @@ luaA_button_new(lua_State *L) button->press = press; button->release = release; button->button = xbutton; - - luaA_setmodifiers(L, 2, &button->mod); + button->mod = luaA_tomodifiers(L, 2); return 1; } @@ -196,7 +195,8 @@ luaA_button_newindex(lua_State *L) button->button = luaL_checknumber(L, 3); break; case A_TK_MODIFIERS: - luaA_setmodifiers(L, 3, &button->mod); + button->mod = luaA_tomodifiers(L, 3); + break; default: break; } diff --git a/key.c b/key.c index 6eb46396..8b84a139 100644 --- a/key.c +++ b/key.c @@ -1046,7 +1046,7 @@ luaA_key_new(lua_State *L) k->press = press; k->release = release; - luaA_setmodifiers(L, 2, &k->mod); + k->mod = luaA_tomodifiers(L, 2); return 1; } @@ -1110,24 +1110,26 @@ luaA_pushmodifiers(lua_State *L, uint16_t modifiers) 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 ud The index of the table. - * \param mod Where to set the modifiers. + * \return The mask value. */ -void -luaA_setmodifiers(lua_State *L, int ud, uint16_t *mod) +uint16_t +luaA_tomodifiers(lua_State *L, int ud) { luaA_checktable(L, ud); ssize_t len = lua_objlen(L, ud); + uint16_t mod = XCB_NONE; for(int i = 1; i <= len; i++) { lua_rawgeti(L, ud, i); size_t 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); } + return mod; } /** Key object. @@ -1213,7 +1215,7 @@ luaA_key_newindex(lua_State *L) } break; case A_TK_MODIFIERS: - luaA_setmodifiers(L, 3, &k->mod); + k->mod = luaA_tomodifiers(L, 3); break; case A_TK_PRESS: luaA_registerfct(L, 3, &k->press); diff --git a/key.h b/key.h index 010ae462..f5d987d0 100644 --- a/key.h +++ b/key.h @@ -1,7 +1,7 @@ /* * key.h - Keybinding helpers * - * Copyright © 2008 Pierre Habouzit + * Copyright © 2009 Julien Danjou * * 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 @@ -49,6 +49,6 @@ int luaA_key_array_get(lua_State *, key_array_t *); void window_grabkeys(xcb_window_t, key_array_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