lua: exports client.tags and tags.clients
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
3814103a1e
commit
9cb22b96eb
74
client.c
74
client.c
|
@ -947,48 +947,6 @@ client_setborder(client_t *c, int width)
|
||||||
globalconf.screens[c->screen].need_arrange = true;
|
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.
|
/** Kill a client.
|
||||||
* \param L The Lua VM state.
|
* \param L The Lua VM state.
|
||||||
*
|
*
|
||||||
|
@ -1106,6 +1064,8 @@ luaA_client_newindex(lua_State *L)
|
||||||
double d;
|
double d;
|
||||||
int i;
|
int i;
|
||||||
titlebar_t **t = NULL;
|
titlebar_t **t = NULL;
|
||||||
|
tag_array_t *tags;
|
||||||
|
tag_t **tag;
|
||||||
|
|
||||||
if((*c)->invalid)
|
if((*c)->invalid)
|
||||||
luaL_error(L, "client is invalid\n");
|
luaL_error(L, "client is invalid\n");
|
||||||
|
@ -1200,7 +1160,19 @@ luaA_client_newindex(lua_State *L)
|
||||||
titlebar_ref(t);
|
titlebar_ref(t);
|
||||||
titlebar_init(*c);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1228,6 +1200,7 @@ luaA_client_newindex(lua_State *L)
|
||||||
* \lfield coords The client coordinates.
|
* \lfield coords The client coordinates.
|
||||||
* \lfield titlebar The client titlebar.
|
* \lfield titlebar The client titlebar.
|
||||||
* \lfield urgent The client urgent state.
|
* \lfield urgent The client urgent state.
|
||||||
|
* \lfield tags The clients tags.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_client_index(lua_State *L)
|
luaA_client_index(lua_State *L)
|
||||||
|
@ -1239,6 +1212,8 @@ luaA_client_index(lua_State *L)
|
||||||
xutil_class_hint_t hint;
|
xutil_class_hint_t hint;
|
||||||
xcb_get_property_cookie_t prop_c;
|
xcb_get_property_cookie_t prop_c;
|
||||||
xcb_get_property_reply_t *prop_r = NULL;
|
xcb_get_property_reply_t *prop_r = NULL;
|
||||||
|
tag_array_t *tags;
|
||||||
|
int i;
|
||||||
|
|
||||||
if((*c)->invalid)
|
if((*c)->invalid)
|
||||||
luaL_error(L, "client is invalid\n");
|
luaL_error(L, "client is invalid\n");
|
||||||
|
@ -1316,6 +1291,17 @@ luaA_client_index(lua_State *L)
|
||||||
case A_TK_URGENT:
|
case A_TK_URGENT:
|
||||||
lua_pushboolean(L, (*c)->isurgent);
|
lua_pushboolean(L, (*c)->isurgent);
|
||||||
break;
|
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:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1332,8 +1318,6 @@ const struct luaL_reg awesome_client_methods[] =
|
||||||
};
|
};
|
||||||
const struct luaL_reg awesome_client_meta[] =
|
const struct luaL_reg awesome_client_meta[] =
|
||||||
{
|
{
|
||||||
{ "tag", luaA_client_tag },
|
|
||||||
{ "istagged", luaA_client_istagged },
|
|
||||||
{ "kill", luaA_client_kill },
|
{ "kill", luaA_client_kill },
|
||||||
{ "swap", luaA_client_swap },
|
{ "swap", luaA_client_swap },
|
||||||
{ "focus_set", luaA_client_focus_set },
|
{ "focus_set", luaA_client_focus_set },
|
||||||
|
|
|
@ -13,6 +13,7 @@ bottomleft
|
||||||
bottomright
|
bottomright
|
||||||
center
|
center
|
||||||
class
|
class
|
||||||
|
clients
|
||||||
color
|
color
|
||||||
coords
|
coords
|
||||||
fg
|
fg
|
||||||
|
|
|
@ -489,11 +489,8 @@ function client.movetotag(target, c)
|
||||||
local sel = c or capi.client.focus_get();
|
local sel = c or capi.client.focus_get();
|
||||||
-- Check that tag and client screen are identical
|
-- Check that tag and client screen are identical
|
||||||
if sel.screen ~= target.screen then return end
|
if sel.screen ~= target.screen then return end
|
||||||
local tags = capi.tag.get(sel.screen)
|
local tags = { target }
|
||||||
for k, t in pairs(tags) do
|
sel.tags = tags
|
||||||
sel:tag(t, false)
|
|
||||||
end
|
|
||||||
sel:tag(target, true)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Toggle a tag on a client.
|
--- Toggle a tag on a client.
|
||||||
|
@ -502,20 +499,14 @@ end
|
||||||
function client.toggletag(target, c)
|
function client.toggletag(target, c)
|
||||||
local sel = c or capi.client.focus_get();
|
local sel = c or capi.client.focus_get();
|
||||||
-- Check that tag and client screen are identical
|
-- Check that tag and client screen are identical
|
||||||
local toggle = false
|
if sel and sel.screen == target.screen then
|
||||||
if sel then
|
local tags = client.tags
|
||||||
if sel.screen ~= target.screen then return end
|
if tags[target] then
|
||||||
-- Count how many tags has the client
|
tags[target] = nil
|
||||||
-- an only toggle tag if the client has at least one tag other than target
|
else
|
||||||
for k, v in pairs(capi.tag.get(sel.screen)) do
|
tags[target] = target
|
||||||
if target ~= v and sel:istagged(v) then
|
|
||||||
toggle = true
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if toggle then
|
|
||||||
sel:tag(target, not sel:istagged(target))
|
|
||||||
end
|
end
|
||||||
|
sel.tags = tags
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1057,11 +1048,11 @@ function widget.taglist.label.all(t, args)
|
||||||
bg_color = bg_focus
|
bg_color = bg_focus
|
||||||
fg_color = fg_focus
|
fg_color = fg_focus
|
||||||
end
|
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\""
|
background = "resize=\"true\" image=\"@AWESOME_ICON_PATH@/taglist/squarefw.png\""
|
||||||
elseif bg_urgent and fg_urgent then
|
elseif bg_urgent and fg_urgent then
|
||||||
for k, c in pairs(capi.client.get()) do
|
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\""
|
background = "resize=\"true\" image=\"@AWESOME_ICON_PATH@/taglist/squarew.png\""
|
||||||
if c.urgent then
|
if c.urgent then
|
||||||
bg_color = bg_urgent
|
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
|
-- Only print client on the same screen as this widget
|
||||||
if c.screen ~= screen then return end
|
if c.screen ~= screen then return end
|
||||||
for k, t in pairs(capi.tag.get(screen)) do
|
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)
|
return widget_tasklist_label_common(c, args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
26
tag.c
26
tag.c
|
@ -318,6 +318,7 @@ luaA_tag_new(lua_State *L)
|
||||||
* \lfield mwfact Master width factor.
|
* \lfield mwfact Master width factor.
|
||||||
* \lfield nmaster Number of master windows.
|
* \lfield nmaster Number of master windows.
|
||||||
* \lfield ncol Number of column for slave windows.
|
* \lfield ncol Number of column for slave windows.
|
||||||
|
* \lfield clients The clients that has this tag set.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
luaA_tag_index(lua_State *L)
|
luaA_tag_index(lua_State *L)
|
||||||
|
@ -325,6 +326,8 @@ luaA_tag_index(lua_State *L)
|
||||||
size_t len;
|
size_t len;
|
||||||
tag_t **tag = luaA_checkudata(L, 1, "tag");
|
tag_t **tag = luaA_checkudata(L, 1, "tag");
|
||||||
const char *attr;
|
const char *attr;
|
||||||
|
client_array_t *clients;
|
||||||
|
int i;
|
||||||
|
|
||||||
if(luaA_usemetatable(L, 1, 2))
|
if(luaA_usemetatable(L, 1, 2))
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -356,6 +359,16 @@ luaA_tag_index(lua_State *L)
|
||||||
case A_TK_NCOL:
|
case A_TK_NCOL:
|
||||||
lua_pushnumber(L, (*tag)->ncol);
|
lua_pushnumber(L, (*tag)->ncol);
|
||||||
break;
|
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:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -376,6 +389,7 @@ luaA_tag_newindex(lua_State *L)
|
||||||
double d;
|
double d;
|
||||||
int i;
|
int i;
|
||||||
layout_t *l;
|
layout_t *l;
|
||||||
|
client_t **c;
|
||||||
|
|
||||||
switch(a_tokenize(attr, len))
|
switch(a_tokenize(attr, len))
|
||||||
{
|
{
|
||||||
|
@ -443,6 +457,18 @@ luaA_tag_newindex(lua_State *L)
|
||||||
else
|
else
|
||||||
luaL_error(L, "bad value, must be greater than 1");
|
luaL_error(L, "bad value, must be greater than 1");
|
||||||
break;
|
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:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue