client: Add API to query all icons

This adds c.icon_sizes which is a table containing the width and height
of each available icon. With c:get_icon(i), Lua can query the i-th icon
as a lightuserdata.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2017-03-06 16:18:15 +01:00 committed by Daniel Hahler
parent f2cb8d8eb9
commit 9992fd6b1a
1 changed files with 62 additions and 0 deletions

View File

@ -381,6 +381,19 @@
* @param surface * @param surface
*/ */
/**
* The available sizes of client icons. This is a table where each entry
* contains the width and height of an icon.
*
* **Signal:**
*
* * *property::icon*
*
* @property icon_sizes
* @tparam table sizes
* @see `get_icon`
*/
/** /**
* Client screen. * Client screen.
* *
@ -3425,6 +3438,50 @@ luaA_client_keys(lua_State *L)
return luaA_key_array_get(L, 1, keys); return luaA_key_array_get(L, 1, keys);
} }
static int
luaA_client_get_icon_sizes(lua_State *L)
{
int index = 1;
client_t *c = luaA_checkudata(L, 1, &client_class);
lua_newtable(L);
foreach (s, c->icons) {
/* Create a table { width, height } and append it to the table */
lua_createtable(L, 2, 0);
lua_pushinteger(L, cairo_image_surface_get_width(*s));
lua_rawseti(L, -2, 1);
lua_pushinteger(L, cairo_image_surface_get_height(*s));
lua_rawseti(L, -2, 2);
lua_rawseti(L, -2, index++);
}
return 1;
}
/** Get the client's n-th icon.
*
* **Signal:**
*
* * *property::icon*
*
* @tparam interger index The index in the list of icons to get.
* @treturn surface A lightuserdata for a cairo surface. This reference must be
* destroyed!
* @function get_icon
*/
static int
luaA_client_get_some_icon(lua_State *L)
{
client_t *c = luaA_checkudata(L, 1, &client_class);
int index = luaL_checkinteger(L, 2);
luaL_argcheck(L, (index >= 1 && index <= c->icons.len), 2,
"invalid icon index");
lua_pushlightuserdata(L, cairo_surface_reference(c->icons.tab[index-1]));
return 1;
}
static int static int
client_tostring(lua_State *L, client_t *c) client_tostring(lua_State *L, client_t *c)
{ {
@ -3510,6 +3567,7 @@ client_class_setup(lua_State *L)
{ "titlebar_right", luaA_client_titlebar_right }, { "titlebar_right", luaA_client_titlebar_right },
{ "titlebar_bottom", luaA_client_titlebar_bottom }, { "titlebar_bottom", luaA_client_titlebar_bottom },
{ "titlebar_left", luaA_client_titlebar_left }, { "titlebar_left", luaA_client_titlebar_left },
{ "get_icon", luaA_client_get_some_icon },
{ NULL, NULL } { NULL, NULL }
}; };
@ -3608,6 +3666,10 @@ client_class_setup(lua_State *L)
(lua_class_propfunc_t) luaA_client_set_icon, (lua_class_propfunc_t) luaA_client_set_icon,
(lua_class_propfunc_t) luaA_client_get_icon, (lua_class_propfunc_t) luaA_client_get_icon,
(lua_class_propfunc_t) luaA_client_set_icon); (lua_class_propfunc_t) luaA_client_set_icon);
luaA_class_add_property(&client_class, "icon_sizes",
NULL,
(lua_class_propfunc_t) luaA_client_get_icon_sizes,
NULL);
luaA_class_add_property(&client_class, "ontop", luaA_class_add_property(&client_class, "ontop",
(lua_class_propfunc_t) luaA_client_set_ontop, (lua_class_propfunc_t) luaA_client_set_ontop,
(lua_class_propfunc_t) luaA_client_get_ontop, (lua_class_propfunc_t) luaA_client_get_ontop,