luaa: Add a way to query the currently pressed modifiers.

This will make awful.key.execute less unreliable
This commit is contained in:
Emmanuel Lepage Vallee 2019-01-21 00:50:35 -05:00
parent 6f2b7435c3
commit 5e6b02274e
1 changed files with 31 additions and 0 deletions

31
luaa.c
View File

@ -508,6 +508,31 @@ static int luaA_get_modifiers(lua_State *L)
return 0; return 0;
} }
/* Undocumented */
/*
* A table with the currently active modifier names.
*
* @tfield table _active_modifiers
*/
static int luaA_get_active_modifiers(lua_State *L)
{
int count = 1;
lua_newtable(L);
for (int i = XCB_MAP_INDEX_SHIFT; i <= XCB_MAP_INDEX_5; i++) {
const int active = xkb_state_mod_index_is_active (globalconf.xkb_state, i,
XKB_STATE_MODS_DEPRESSED | XKB_STATE_MODS_EFFECTIVE
);
if (active) {
lua_pushstring(L, get_modifier_name(i));
lua_rawseti(L,-2, count++);
}
}
return 0;
}
/** /**
* The version of awesome. * The version of awesome.
@ -598,6 +623,12 @@ luaA_awesome_index(lua_State *L)
return 1; return 1;
} }
if(A_STREQ(buf, "_active_modifiers"))
{
luaA_get_active_modifiers(L);
return 1;
}
if(A_STREQ(buf, "startup_errors")) if(A_STREQ(buf, "startup_errors"))
{ {
if (globalconf.startup_errors.len == 0) if (globalconf.startup_errors.len == 0)