diff --git a/awesomerc.lua.in b/awesomerc.lua.in index 97b1ecd2f..65f1cea2f 100644 --- a/awesomerc.lua.in +++ b/awesomerc.lua.in @@ -55,7 +55,7 @@ apptags = } -- Define if we want to use titlebar on all applications. -use_titlebar = false +use_titlebar = true -- }}} -- {{{ Initialization diff --git a/lib/awful.lua.in b/lib/awful.lua.in index a49958c3f..de4e20f7c 100644 --- a/lib/awful.lua.in +++ b/lib/awful.lua.in @@ -1167,16 +1167,19 @@ function titlebar.add(c, args) if args.bg then targs.bg = args.bg end local tb = capi.titlebar(targs) - 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: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:kill() end)) - tb:widget_add(close_button) + + tb.widgets = + { + capi.widget({ type = "appicon", name = "appicon", align = "left" }), + title, + close_button + } titlebar.update(c) @@ -1187,21 +1190,27 @@ end -- @param c The client to update. function titlebar.update(c) if c.titlebar and titlebar.data[c] then - local widgets = c.titlebar:widget_get() - if widgets.title then - widgets.title.text = " " .. escape(c.name) + local widgets = c.titlebar.widgets + local title, close + for k, v in ipairs(widgets) do + if v.name == "title" then title = v end + if v.name == "close" then close = v end + if title and close then break end + end + if title then + title.text = " " .. escape(c.name) end if capi.client.focus_get() == c then c.titlebar.fg = titlebar.data[c].fg_focus c.titlebar.bg = titlebar.data[c].bg_focus - if widgets.close then - widgets.close.text = "" + if close then + close.text = "" end else c.titlebar.fg = titlebar.data[c].fg c.titlebar.bg = titlebar.data[c].bg - if widgets.close then - widgets.close.text = "" + if close then + close.text = "" end end end diff --git a/statusbar.c b/statusbar.c index 9aca6b25c..053e845cb 100644 --- a/statusbar.c +++ b/statusbar.c @@ -674,7 +674,6 @@ luaA_statusbar_newindex(lua_State *L) widget_ref(widget); lua_pop(L, 1); } - break; default: return 0; diff --git a/titlebar.c b/titlebar.c index 1b40cca2d..1ee6e4a42 100644 --- a/titlebar.c +++ b/titlebar.c @@ -349,100 +349,6 @@ luaA_titlebar_new(lua_State *L) return luaA_titlebar_userdata_new(globalconf.L, tb); } -/** Add a widget to a titlebar. - * \param L The Lua VM state. - * \return The number of value pushed. - * - * \luastack - * \lvalue A titlebar. - * \lparam A widget. - */ -static int -luaA_titlebar_widget_add(lua_State *L) -{ - titlebar_t **tb = luaA_checkudata(L, 1, "titlebar"); - widget_t **widget = luaA_checkudata(L, 2, "widget"); - widget_node_t *witer, *w; - - if((*widget)->type == systray_new) - luaL_error(L, "cannot add systray widget to titlebar"); - - /* check that there is not already a widget with that name in the titlebar */ - for(witer = (*tb)->widgets; witer; witer = witer->next) - if(witer->widget != *widget - && !a_strcmp(witer->widget->name, (*widget)->name)) - luaL_error(L, "a widget with name `%s' already on titlebar", witer->widget->name); - - w = p_new(widget_node_t, 1); - - w->widget = *widget; - widget_node_list_append(&(*tb)->widgets, w); - widget_ref(widget); - - (*tb)->need_update = true; - - return 0; -} - -/** Remove a widget from a titlebar. - * \param L The Lua VM State. - * - * \luastack - * \lvalue A statusbar. - * \lparam A widget. - */ -static int -luaA_titlebar_widget_remove(lua_State *L) -{ - titlebar_t **tb = luaA_checkudata(L, 1, "titlebar"); - widget_t **widget = luaA_checkudata(L, 2, "widget"); - widget_node_t *w, *wnext; - - for(w = (*tb)->widgets; w; w = wnext) - { - wnext = w->next; - if(w->widget == *widget) - { - if((*widget)->detach) - (*widget)->detach(*widget, *tb); - widget_unref(widget); - widget_node_list_detach(&(*tb)->widgets, w); - p_delete(&w); - (*tb)->need_update = true; - } - } - - return 0; -} - - -/** Get all widgets from a titlebar. - * \param L The Lua VM state. - * \return The number of value pushed. - * - * \luastack - * \lvalue A titlebar - * \lreturn A table with all widgets from the titlebar. - */ -static int -luaA_titlebar_widget_get(lua_State *L) -{ - titlebar_t **tb = luaA_checkudata(L, 1, "titlebar"); - widget_node_t *witer; - - lua_newtable(L); - - for(witer = (*tb)->widgets; witer; witer = witer->next) - { - luaA_widget_userdata_new(L, witer->widget); - /* ref again for the list */ - widget_ref(&witer->widget); - lua_setfield(L, -2, witer->widget->name); - } - - return 1; -} - /** Titlebar newindex. * \param L The Lua VM state. * \return The number of elements pushed on stack. @@ -455,6 +361,7 @@ luaA_titlebar_newindex(lua_State *L) const char *buf, *attr = luaL_checklstring(L, 2, &len); client_t *c = NULL, **newc; int i; + widget_node_t *witer; switch(a_tokenize(attr, len)) { @@ -521,6 +428,33 @@ luaA_titlebar_newindex(lua_State *L) globalconf.default_screen, buf, len)) (*titlebar)->need_update = true; return 0; + case A_TK_WIDGETS: + luaA_checktable(L, 3); + + /* remove all widgets */ + for(witer = (*titlebar)->widgets; witer; witer = (*titlebar)->widgets) + { + if(witer->widget->detach) + witer->widget->detach(witer->widget, *titlebar); + widget_unref(&witer->widget); + widget_node_list_detach(&(*titlebar)->widgets, witer); + p_delete(&witer); + } + + (*titlebar)->need_update = true; + + /* now read all widgets and add them */ + lua_pushnil(L); + while(lua_next(L, 3)) + { + widget_t **widget = luaA_checkudata(L, -1, "widget"); + widget_node_t *w = p_new(widget_node_t, 1); + w->widget = *widget; + widget_node_list_append(&(*titlebar)->widgets, w); + widget_ref(widget); + lua_pop(L, 1); + } + break; default: return 0; } @@ -550,6 +484,8 @@ luaA_titlebar_index(lua_State *L) titlebar_t **titlebar = luaA_checkudata(L, 1, "titlebar"); const char *attr = luaL_checklstring(L, 2, &len); client_t *c; + widget_node_t *witer; + int i = 0; if(luaA_usemetatable(L, 1, 2)) return 1; @@ -576,6 +512,14 @@ luaA_titlebar_index(lua_State *L) case A_TK_BG: luaA_pushcolor(L, &(*titlebar)->colors.bg); break; + case A_TK_WIDGETS: + lua_newtable(L); + for(witer = (*titlebar)->widgets; witer; witer = witer->next) + { + luaA_widget_userdata_new(L, witer->widget); + lua_rawseti(L, -2, ++i); + } + break; default: return 0; } @@ -606,9 +550,6 @@ const struct luaL_reg awesome_titlebar_methods[] = }; 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 }, { "__index", luaA_titlebar_index }, { "__newindex", luaA_titlebar_newindex }, { "__eq", luaA_titlebar_eq },