lua: exports client.tags and tags.clients

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-08-07 16:37:58 +02:00
parent 3814103a1e
commit 9cb22b96eb
4 changed files with 68 additions and 66 deletions

View File

@ -947,48 +947,6 @@ client_setborder(client_t *c, int width)
globalconf.screens[c->screen].need_arrange = true;
}
/** Tag a client with a specified tag.
* \param L The Lua VM state.
* \luastack
* \lvalue A client.
* \lparam A tag object.
* \lparam A boolean value: true to add this tag to clients, false to remove.
*/
static int
luaA_client_tag(lua_State *L)
{
client_t **c = luaA_checkudata(L, 1, "client");
tag_t **tag = luaA_checkudata(L, 2, "tag");
bool tag_the_client = luaA_checkboolean(L, 3);
if((*tag)->screen != (*c)->screen)
luaL_error(L, "tag and client are on different screens");
if(tag_the_client)
tag_client(*c, *tag);
else
untag_client(*c, *tag);
return 0;
}
/** Check if a client is tagged with the specified tag.
* \param L The Lua VM state.
* \luastack
* \lvalue A client.
* \lparam A tag object.
* \lreturn A boolean value, true if the client is tagged with this tag, false
* otherwise.
*/
static int
luaA_client_istagged(lua_State *L)
{
client_t **c = luaA_checkudata(L, 1, "client");
tag_t **tag = luaA_checkudata(L, 2, "tag");
lua_pushboolean(L, is_client_tagged(*c, *tag));
return 1;
}
/** Kill a client.
* \param L The Lua VM state.
*
@ -1106,6 +1064,8 @@ 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");
@ -1200,7 +1160,19 @@ luaA_client_newindex(lua_State *L)
titlebar_ref(t);
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;
@ -1228,6 +1200,7 @@ 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.
*/
static int
luaA_client_index(lua_State *L)
@ -1239,6 +1212,8 @@ 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");
@ -1316,6 +1291,17 @@ 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;
}
@ -1332,8 +1318,6 @@ const struct luaL_reg awesome_client_methods[] =
};
const struct luaL_reg awesome_client_meta[] =
{
{ "tag", luaA_client_tag },
{ "istagged", luaA_client_istagged },
{ "kill", luaA_client_kill },
{ "swap", luaA_client_swap },
{ "focus_set", luaA_client_focus_set },

View File

@ -13,6 +13,7 @@ bottomleft
bottomright
center
class
clients
color
coords
fg

View File

@ -489,11 +489,8 @@ function client.movetotag(target, c)
local sel = c or capi.client.focus_get();
-- Check that tag and client screen are identical
if sel.screen ~= target.screen then return end
local tags = capi.tag.get(sel.screen)
for k, t in pairs(tags) do
sel:tag(t, false)
end
sel:tag(target, true)
local tags = { target }
sel.tags = tags
end
--- Toggle a tag on a client.
@ -502,20 +499,14 @@ end
function client.toggletag(target, c)
local sel = c or capi.client.focus_get();
-- Check that tag and client screen are identical
local toggle = false
if sel then
if sel.screen ~= target.screen then return end
-- Count how many tags has the client
-- an only toggle tag if the client has at least one tag other than target
for k, v in pairs(capi.tag.get(sel.screen)) do
if target ~= v and sel:istagged(v) then
toggle = true
break
end
end
if toggle then
sel:tag(target, not sel:istagged(target))
if sel and sel.screen == target.screen then
local tags = client.tags
if tags[target] then
tags[target] = nil
else
tags[target] = target
end
sel.tags = tags
end
end
@ -1057,11 +1048,11 @@ function widget.taglist.label.all(t, args)
bg_color = bg_focus
fg_color = fg_focus
end
if sel and sel:istagged(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(capi.client.get()) do
if c:istagged(t) then
if c.tags[t] then
background = "resize=\"true\" image=\"@AWESOME_ICON_PATH@/taglist/squarew.png\""
if c.urgent then
bg_color = bg_urgent
@ -1148,7 +1139,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 pairs(capi.tag.get(screen)) do
if t.selected and c:istagged(t) then
if t.selected and c.tags[t] then
return widget_tasklist_label_common(c, args)
end
end

26
tag.c
View File

@ -318,6 +318,7 @@ luaA_tag_new(lua_State *L)
* \lfield mwfact Master width factor.
* \lfield nmaster Number of master windows.
* \lfield ncol Number of column for slave windows.
* \lfield clients The clients that has this tag set.
*/
static int
luaA_tag_index(lua_State *L)
@ -325,6 +326,8 @@ luaA_tag_index(lua_State *L)
size_t len;
tag_t **tag = luaA_checkudata(L, 1, "tag");
const char *attr;
client_array_t *clients;
int i;
if(luaA_usemetatable(L, 1, 2))
return 1;
@ -356,6 +359,16 @@ luaA_tag_index(lua_State *L)
case A_TK_NCOL:
lua_pushnumber(L, (*tag)->ncol);
break;
case A_TK_CLIENTS:
clients = &(*tag)->clients;
luaA_otable_new(L);
for(i = 0; i < clients->len; i++)
{
luaA_client_userdata_new(L, clients->tab[i]);
luaA_client_userdata_new(L, clients->tab[i]);
lua_rawset(L, -3);
}
break;
default:
return 0;
}
@ -376,6 +389,7 @@ luaA_tag_newindex(lua_State *L)
double d;
int i;
layout_t *l;
client_t **c;
switch(a_tokenize(attr, len))
{
@ -443,6 +457,18 @@ luaA_tag_newindex(lua_State *L)
else
luaL_error(L, "bad value, must be greater than 1");
break;
case A_TK_CLIENTS:
luaA_checktable(L, 3);
for(i = 0; i < (*tag)->clients.len; i++)
untag_client((*tag)->clients.tab[i], *tag);
lua_pushnil(L);
while(lua_next(L, 3))
{
c = luaA_checkudata(L, -1, "client");
tag_client(*c, *tag);
lua_pop(L, 1);
}
break;
default:
return 0;
}