From 5e6b02274eb03f84cf75d502b798ff135e1751ad Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Mon, 21 Jan 2019 00:50:35 -0500 Subject: [PATCH] luaa: Add a way to query the currently pressed modifiers. This will make awful.key.execute less unreliable --- luaa.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/luaa.c b/luaa.c index 981c196b..bfe8eee3 100644 --- a/luaa.c +++ b/luaa.c @@ -508,6 +508,31 @@ static int luaA_get_modifiers(lua_State *L) 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. @@ -598,6 +623,12 @@ luaA_awesome_index(lua_State *L) return 1; } + if(A_STREQ(buf, "_active_modifiers")) + { + luaA_get_active_modifiers(L); + return 1; + } + if(A_STREQ(buf, "startup_errors")) { if (globalconf.startup_errors.len == 0)