From eb8378749bd8cfe5ff32bfde4ad07a7e30660989 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 4 Jun 2008 17:54:52 +0200 Subject: [PATCH] [titlebar] Add titlebar_client_get() Signed-off-by: Julien Danjou --- client.c | 7 +++---- titlebar.c | 35 ++++++++++++++++++++++++++++++++++- titlebar.h | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/client.c b/client.c index db5ab84e..47342945 100644 --- a/client.c +++ b/client.c @@ -1131,12 +1131,11 @@ luaA_client_name_set(lua_State *L) static int luaA_client_titlebar_set(lua_State *L) { - client_t *cl, **c = luaL_checkudata(L, 1, "client"); + client_t **c = luaL_checkudata(L, 1, "client"); titlebar_t **t = luaL_checkudata(L, 2, "titlebar"); - for(cl = globalconf.clients; cl; cl = cl->next) - if(cl->titlebar == *t) - luaL_error(L, "titlebar is already used by another client"); + if(client_getbytitlebar(*t)) + luaL_error(L, "titlebar is already used by another client"); /* If client had a titlebar, unref it */ if((*c)->titlebar) diff --git a/titlebar.c b/titlebar.c index 272285ab..5ae5bae0 100644 --- a/titlebar.c +++ b/titlebar.c @@ -32,8 +32,24 @@ extern awesome_t globalconf; +/** Get a client by its titlebar. + * \param titlebar The titlebar. + * \return A client. + */ +client_t * +client_getbytitlebar(titlebar_t *titlebar) +{ + client_t *c; + + for(c = globalconf.clients; c; c = c->next) + if(c->titlebar == titlebar) + return c; + + return NULL; +} + /** Get a client by its titlebar window. - * \param The window. + * \param win The window. * \return A client. */ client_t * @@ -478,6 +494,22 @@ luaA_titlebar_widget_get(lua_State *L) return 1; } +/** Get the client which the titlebar is attached to. That is a the same as + * checking if every clients's titlebar is equal to titlebar. + * \return A client if the titlebar is attached, nil otherwise. + */ +static int +luaA_titlebar_client_get(lua_State *L) +{ + titlebar_t **titlebar = luaL_checkudata(L, 1, "titlebar"); + client_t *c; + + if((c = client_getbytitlebar(*titlebar))) + return luaA_client_userdata_new(c); + + return 0; +} + /** Create a new titlebar userdata. * \param t The titlebar. */ @@ -524,6 +556,7 @@ const struct luaL_reg awesome_titlebar_meta[] = { { "widget_add", luaA_titlebar_widget_add }, { "widget_get", luaA_titlebar_widget_get }, + { "client_get", luaA_titlebar_client_get }, { "__eq", luaA_titlebar_eq }, { "__gc", luaA_titlebar_gc }, { "__tostring", luaA_titlebar_tostring }, diff --git a/titlebar.h b/titlebar.h index ecf77287..9763d0d5 100644 --- a/titlebar.h +++ b/titlebar.h @@ -24,6 +24,7 @@ #include "structs.h" +client_t * client_getbytitlebar(titlebar_t *); client_t * client_getbytitlebarwin(xcb_window_t); void titlebar_draw(client_t *); void titlebar_update_geometry_floating(client_t *);