diff --git a/client.c b/client.c index f35dfe10..90a7a784 100644 --- a/client.c +++ b/client.c @@ -1155,6 +1155,20 @@ luaA_client_titlebar_set(lua_State *L) return 0; } +/** Get the titlebar of a client. + * \return A titlebar or nil if the client has no titlebar. + */ +static int +luaA_client_titlebar_get(lua_State *L) +{ + client_t **c = luaL_checkudata(L, 1, "client"); + + if((*c)->titlebar) + return luaA_titlebar_userdata_new((*c)->titlebar); + + return 0; +} + /** Stop managing a client. */ static int @@ -1184,6 +1198,7 @@ const struct luaL_reg awesome_client_methods[] = const struct luaL_reg awesome_client_meta[] = { { "titlebar_set", luaA_client_titlebar_set }, + { "titlebar_get", luaA_client_titlebar_get }, { "name_get", luaA_client_name_get }, { "name_set", luaA_client_name_set }, { "screen_set", luaA_client_screen_set }, diff --git a/titlebar.c b/titlebar.c index 075a3617..cbd9a2d2 100644 --- a/titlebar.c +++ b/titlebar.c @@ -478,6 +478,18 @@ luaA_titlebar_widget_get(lua_State *L) return 1; } +/** Create a new titlebar userdata. + * \param t The titlebar. + */ +int +luaA_titlebar_userdata_new(titlebar_t *t) +{ + titlebar_t **tb = lua_newuserdata(globalconf.L, sizeof(titlebar_t *)); + *tb = t; + titlebar_ref(tb); + return luaA_settype(globalconf.L, "titlebar"); +} + static int luaA_titlebar_gc(lua_State *L) { diff --git a/titlebar.h b/titlebar.h index 26a35b24..ecf77287 100644 --- a/titlebar.h +++ b/titlebar.h @@ -30,6 +30,8 @@ void titlebar_update_geometry_floating(client_t *); void titlebar_update_geometry(client_t *, area_t); void titlebar_init(client_t *); +int luaA_titlebar_userdata_new(titlebar_t *); + /** Add the titlebar geometry to a geometry. * \param t the titlebar * \param geometry the geometry diff --git a/widget.c b/widget.c index 80362874..7ae3d9bf 100644 --- a/widget.c +++ b/widget.c @@ -299,8 +299,7 @@ widget_invalidate_bywidget(widget_t *widget) int luaA_widget_userdata_new(widget_t *widget) { - widget_t **w; - w = lua_newuserdata(globalconf.L, sizeof(widget_t *)); + widget_t **w = lua_newuserdata(globalconf.L, sizeof(widget_t *)); *w = widget; widget_ref(w); return luaA_settype(globalconf.L, "widget");