client: export tags as a function

That makes more sense.

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-13 17:49:57 +02:00
parent 3104969d03
commit 871285551d
2 changed files with 49 additions and 35 deletions

View File

@ -986,6 +986,49 @@ luaA_client_swap(lua_State *L)
return 0;
}
/** Access or set the client tags.
* \param L The Lua VM state.
* \return The number of elements pushed on stack.
* \lparam A table with tags to set, or none to get the current tags table.
* \return The clients tag.
*/
static int
luaA_client_tags(lua_State *L)
{
tag_array_t *tags;
tag_t **tag;
client_t **c = luaA_checkudata(L, 1, "client");
if(lua_gettop(L) == 2)
{
luaA_checktable(L, 2);
tags = &globalconf.screens[(*c)->screen].tags;
for(int i = 0; i < tags->len; i++)
untag_client(*c, tags->tab[i]);
lua_pushnil(L);
while(lua_next(L, 2))
{
tag = luaA_checkudata(L, -1, "tag");
tag_client(*c, *tag);
lua_pop(L, 1);
}
}
else
{
tags = &globalconf.screens[(*c)->screen].tags;
luaA_otable_new(L);
for(int i = 0; i < tags->len; i++)
if(is_client_tagged(*c, tags->tab[i]))
{
luaA_tag_userdata_new(L, tags->tab[i]);
luaA_tag_userdata_new(L, tags->tab[i]);
lua_rawset(L, -3);
}
}
return 1;
}
/** Focus a client (DEPRECATED).
* \param L The Lua VM state.
*
@ -1071,8 +1114,6 @@ luaA_client_newindex(lua_State *L)
double d;
int i;
titlebar_t **t = NULL;
tag_array_t *tags;
tag_t **tag;
if((*c)->invalid)
luaL_error(L, "client is invalid\n");
@ -1175,19 +1216,6 @@ luaA_client_newindex(lua_State *L)
titlebar_init(*c);
}
break;
case A_TK_TAGS:
luaA_checktable(L, 3);
tags = &globalconf.screens[(*c)->screen].tags;
for(i = 0; i < tags->len; i++)
untag_client(*c, tags->tab[i]);
lua_pushnil(L);
while(lua_next(L, 3))
{
tag = luaA_checkudata(L, -1, "tag");
tag_client(*c, *tag);
lua_pop(L, 1);
}
break;
default:
return 0;
}
@ -1216,7 +1244,6 @@ luaA_client_newindex(lua_State *L)
* \lfield coords The client coordinates.
* \lfield titlebar The client titlebar.
* \lfield urgent The client urgent state.
* \lfield tags The clients tags.
* \lfield focus The focused client.
*/
static int
@ -1231,8 +1258,6 @@ luaA_client_index(lua_State *L)
xutil_class_hint_t hint;
xcb_get_property_cookie_t prop_c;
xcb_get_property_reply_t *prop_r = NULL;
tag_array_t *tags;
int i;
if((*c)->invalid)
luaL_error(L, "client is invalid\n");
@ -1326,17 +1351,6 @@ luaA_client_index(lua_State *L)
case A_TK_URGENT:
lua_pushboolean(L, (*c)->isurgent);
break;
case A_TK_TAGS:
tags = &globalconf.screens[(*c)->screen].tags;
luaA_otable_new(L);
for(i = 0; i < tags->len; i++)
if(is_client_tagged(*c, tags->tab[i]))
{
luaA_tag_userdata_new(L, tags->tab[i]);
luaA_tag_userdata_new(L, tags->tab[i]);
lua_rawset(L, -3);
}
break;
default:
return 0;
}
@ -1404,6 +1418,7 @@ const struct luaL_reg awesome_client_methods[] =
};
const struct luaL_reg awesome_client_meta[] =
{
{ "tags", luaA_client_tags },
{ "kill", luaA_client_kill },
{ "swap", luaA_client_swap },
{ "focus_set", luaA_client_focus_set },

View File

@ -505,8 +505,7 @@ function client.movetotag(target, c)
if sel then
-- Check that tag and client screen are identical
if sel.screen ~= target.screen then return end
local tags = { target }
sel.tags = tags
sel:tags({ target })
end
end
@ -517,13 +516,13 @@ function client.toggletag(target, c)
local sel = c or capi.client.focus
-- Check that tag and client screen are identical
if sel and sel.screen == target.screen then
local tags = sel.tags
local tags = sel:tags()
if tags[target] then
tags[target] = nil
else
tags[target] = target
end
sel.tags = tags
sel:tags(tags)
end
end
@ -1151,7 +1150,7 @@ function widget.taglist.label.all(t, args)
bg_color = bg_focus
fg_color = fg_focus
end
if sel and sel.tags[t] then
if sel and sel:tags()[t] then
background = "resize=\"true\" image=\"@AWESOME_ICON_PATH@/taglist/squarefw.png\""
elseif bg_urgent and fg_urgent then
for k, c in pairs(t.clients) do
@ -1290,7 +1289,7 @@ function widget.tasklist.label.currenttags(c, screen, args)
-- Only print client on the same screen as this widget
if c.screen ~= screen then return end
for k, t in ipairs(capi.screen[screen].tags) do
if t.selected and c.tags[t] then
if t.selected and c:tags()[t] then
return widget_tasklist_label_common(c, args)
end
end