client.get: add `stacked` argument

Fixes https://github.com/awesomeWM/awesome/issues/178.
This commit is contained in:
Daniel Hahler 2015-07-23 16:41:16 +02:00
parent 08b78f537a
commit 0c55b2edec
1 changed files with 26 additions and 8 deletions

View File

@ -1391,8 +1391,10 @@ client_kill(client_t *c)
/** Get all clients into a table. /** Get all clients into a table.
* *
* @param[opt] screen A screen number. * @tparam[opt] integer screen A screen number to filter clients on.
* @return A table with all clients. * @tparam[opt] boolean stacked Return clients in stacking order? (ordered from
* top to bottom).
* @treturn table A table with clients.
* @function get * @function get
*/ */
static int static int
@ -1400,17 +1402,33 @@ luaA_client_get(lua_State *L)
{ {
int i = 1; int i = 1;
screen_t *screen = NULL; screen_t *screen = NULL;
bool stacked = false;
if(!lua_isnoneornil(L, 1)) if(!lua_isnoneornil(L, 1))
screen = luaA_checkscreen(L, 1); screen = luaA_checkscreen(L, 1);
if(!lua_isnoneornil(L, 2))
stacked = luaA_checkboolean(L, 2);
lua_newtable(L); lua_newtable(L);
foreach(c, globalconf.clients) if(stacked)
if(screen == NULL || (*c)->screen == screen) {
{ foreach_reverse(c, globalconf.stack)
luaA_object_push(L, *c); if(screen == NULL || (*c)->screen == screen)
lua_rawseti(L, -2, i++); {
} luaA_object_push(L, *c);
lua_rawseti(L, -2, i++);
}
}
else
{
foreach(c, globalconf.clients)
if(screen == NULL || (*c)->screen == screen)
{
luaA_object_push(L, *c);
lua_rawseti(L, -2, i++);
}
}
return 1; return 1;
} }