From d5cf6e0272650d8bb109357ec808f878946b7c14 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 14 Jul 2015 00:27:26 +0200 Subject: [PATCH] Add client.first_tag, as a shortcut for `c:tags()[1]` This is meant to be a faster alternative in case only the first tag is relevant/used. Closes https://github.com/awesomeWM/awesome/pull/294. --- awesomerc.lua | 2 +- lib/awful/client.lua | 2 +- lib/awful/menu.lua | 2 +- objects/client.c | 30 +++++++++++++++++++++++++++--- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/awesomerc.lua b/awesomerc.lua index e1f1831d..448a4dab 100755 --- a/awesomerc.lua +++ b/awesomerc.lua @@ -141,7 +141,7 @@ mytasklist.buttons = awful.util.table.join( -- :isvisible() makes no sense c.minimized = false if not c:isvisible() then - awful.tag.viewonly(c:tags()[1]) + awful.tag.viewonly(c.first_tag) end -- This will also un-minimize -- the client, if needed diff --git a/lib/awful/client.lua b/lib/awful/client.lua index fe7d1112..cbae3cb6 100644 --- a/lib/awful/client.lua +++ b/lib/awful/client.lua @@ -61,7 +61,7 @@ function client.jumpto(c, merge) end -- Try to make client visible, this also covers e.g. sticky - local t = c:tags()[1] + local t = c.first_tag if t and not c:isvisible() then if merge then t.selected = true diff --git a/lib/awful/menu.lua b/lib/awful/menu.lua index ab8d73ec..9a81bacf 100644 --- a/lib/awful/menu.lua +++ b/lib/awful/menu.lua @@ -613,7 +613,7 @@ end -- terms[i] = -- {c.name, -- function() --- awful.tag.viewonly(c:tags()[1]) +-- awful.tag.viewonly(c.first_tag) -- client.focus = c -- end, -- c.icon diff --git a/objects/client.c b/objects/client.c index 2c3c067e..e58d2b26 100644 --- a/objects/client.c +++ b/objects/client.c @@ -97,6 +97,7 @@ * @field shape_client_clip The client's clip shape as set by the program as a (native) cairo surface. * @field startup_id The FreeDesktop StartId. * @field valid If the client that this object refers to is still managed by awesome. + * @field first_tag The first tag of the client. Optimized form of `c:tags()[1]`. * @table client */ @@ -1559,9 +1560,11 @@ luaA_client_swap(lua_State *L) /** Access or set the client tags. * - * @param tags_table A table with tags to set, or none to get the current tags - * table. - * @return A table with all tags. + * Use the `first_tag` field to access the first tag of a client directly. + * + * @tparam table tags_table A table with tags to set, or `nil` to get the + * current tags. + * @treturn table A table with all tags. * @function tags */ static int @@ -1611,6 +1614,23 @@ luaA_client_tags(lua_State *L) return 1; } +/** Get the first tag of a client. + */ +static int +luaA_client_get_first_tag(lua_State *L) +{ + client_t *c = luaA_checkudata(L, 1, &client_class); + + foreach(tag, globalconf.tags) + if(is_client_tagged(c, *tag)) + { + luaA_object_push(L, *tag); + return 1; + } + + return 0; +} + /** Raise a client on top of others which are on the same layer. * * @function raise @@ -2639,6 +2659,10 @@ client_class_setup(lua_State *L) NULL, (lua_class_propfunc_t) luaA_client_get_client_shape_clip, NULL); + luaA_class_add_property(&client_class, "first_tag", + NULL, + (lua_class_propfunc_t) luaA_client_get_first_tag, + NULL); /** When a client gains focus. * @signal .focus