diff --git a/common/tokenize.gperf b/common/tokenize.gperf index 018f3c6ca..19102d599 100644 --- a/common/tokenize.gperf +++ b/common/tokenize.gperf @@ -13,6 +13,7 @@ bottomleft bottomright center class +client clients color coords diff --git a/lib/awful.lua.in b/lib/awful.lua.in index 6009ab4f4..a49958c3f 100644 --- a/lib/awful.lua.in +++ b/lib/awful.lua.in @@ -1170,12 +1170,12 @@ function titlebar.add(c, args) tb:widget_add(capi.widget({ type = "appicon", name = "appicon", align = "left" })) local title = capi.widget({ type = "textbox", name = "title", align = "flex" }) - title:mouse_add(capi.mouse({ }, 1, function (t) t:client_get():mouse_move() end)) - title:mouse_add(capi.mouse({ args.modkey }, 3, function (t) t:client_get():mouse_resize() end)) + title:mouse_add(capi.mouse({ }, 1, function (t) t.client:mouse_move() end)) + title:mouse_add(capi.mouse({ args.modkey }, 3, function (t) t.client:mouse_resize() end)) tb:widget_add(title) local close_button= capi.widget({ type = "textbox", name = "close", align = "right" }) - close_button:mouse_add(capi.mouse({ }, 1, function (t) t:client_get():kill() end)) + close_button:mouse_add(capi.mouse({ }, 1, function (t) t.client:kill() end)) tb:widget_add(close_button) titlebar.update(c) diff --git a/titlebar.c b/titlebar.c index ec3e176f8..1b40cca2d 100644 --- a/titlebar.c +++ b/titlebar.c @@ -443,26 +443,6 @@ 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. - * \param L The Lua VM state. - * - * \luastack - * \lvalue A titlebar. - * \lreturn A client if the titlebar is attached, nil otherwise. - */ -static int -luaA_titlebar_client_get(lua_State *L) -{ - titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar"); - client_t *c; - - if((c = client_getbytitlebar(*titlebar))) - return luaA_client_userdata_new(L, c); - - return 0; -} - /** Titlebar newindex. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -473,11 +453,42 @@ luaA_titlebar_newindex(lua_State *L) size_t len; titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar"); const char *buf, *attr = luaL_checklstring(L, 2, &len); - client_t *c; + client_t *c = NULL, **newc; int i; switch(a_tokenize(attr, len)) { + case A_TK_CLIENT: + if(!lua_isnil(L, 3)) + newc = luaA_checkudata(L, 3, "client"); + else + newc = NULL; + + if(newc) + { + if((*newc)->titlebar) + { + simplewindow_delete(&(*newc)->titlebar->sw); + titlebar_unref(&(*newc)->titlebar); + globalconf.screens[(*newc)->screen].need_arrange = true; + } + /* Attach titlebar to client */ + (*newc)->titlebar = *titlebar; + titlebar_ref(titlebar); + titlebar_init(*newc); + c = *newc; + } + else + { + if((c = client_getbytitlebar(*titlebar))) + { + simplewindow_delete(&(*titlebar)->sw); + /* unref and NULL the ref */ + titlebar_unref(&c->titlebar); + globalconf.screens[c->screen].need_arrange = true; + } + } + break; case A_TK_ALIGN: if((buf = luaL_checklstring(L, 3, &len))) (*titlebar)->align = draw_align_fromstr(buf, len); @@ -514,7 +525,7 @@ luaA_titlebar_newindex(lua_State *L) return 0; } - if((c = client_getbytitlebar(*titlebar)) + if((c || (c = client_getbytitlebar(*titlebar))) && client_isvisible(c, c->screen)) globalconf.screens[c->screen].need_arrange = true; @@ -525,6 +536,7 @@ luaA_titlebar_newindex(lua_State *L) * \param L The Lua VM state. * \return The number of elements pushed on stack. * \luastack + * \lfield client The client attached to this titlebar. * \lfield align Alignment relative to the client. * \lfield border_width Border width. * \lfield border_color Border color. @@ -537,12 +549,18 @@ luaA_titlebar_index(lua_State *L) size_t len; titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar"); const char *attr = luaL_checklstring(L, 2, &len); + client_t *c; if(luaA_usemetatable(L, 1, 2)) return 1; switch(a_tokenize(attr, len)) { + case A_TK_CLIENT: + if((c = client_getbytitlebar(*titlebar))) + return luaA_client_userdata_new(L, c); + else + return 0; case A_TK_ALIGN: lua_pushstring(L, draw_align_tostr((*titlebar)->align)); break; @@ -591,7 +609,6 @@ const struct luaL_reg awesome_titlebar_meta[] = { "widget_add", luaA_titlebar_widget_add }, { "widget_remove", luaA_titlebar_widget_remove }, { "widget_get", luaA_titlebar_widget_get }, - { "client_get", luaA_titlebar_client_get }, { "__index", luaA_titlebar_index }, { "__newindex", luaA_titlebar_newindex }, { "__eq", luaA_titlebar_eq },