From 349b75994f7687fb2bc32b06dfe3c77efe1f8aeb Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Wed, 26 Dec 2018 23:34:17 -0500 Subject: [PATCH] titlebar/wibox: Support widget definition in set_widget. So now it is mostly identical to `:setup()` beside some legacy difference in how the get_children_by_id is implemented. --- lib/awful/titlebar.lua | 13 +++++++++++++ lib/wibox/drawable.lua | 3 ++- lib/wibox/init.lua | 4 +++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/awful/titlebar.lua b/lib/awful/titlebar.lua index 91edcf74..1b9ae4c4 100644 --- a/lib/awful/titlebar.lua +++ b/lib/awful/titlebar.lua @@ -492,6 +492,18 @@ local function load_titlebars(c, hide_all, keep) return true end +local function get_children_by_id(self, name) + --TODO v5: Move the ID management to the hierarchy. + if self._drawable._widget + and self._drawable._widget._private + and self._drawable._widget._private.by_id then + return self._drawable.widget._private.by_id[name] + end + + return {} +end + + --- Get a client's titlebar. -- @tparam client c The client for which a titlebar is wanted. -- @tparam[opt={}] table args A table with extra arguments for the titlebar. @@ -556,6 +568,7 @@ local function new(c, args) -- Handle declarative/recursive widget container ret.setup = base.widget.setup + ret.get_children_by_id = get_children_by_id c._private = c._private or {} c._private.titlebars = bars diff --git a/lib/wibox/drawable.lua b/lib/wibox/drawable.lua index b9a82c62..f24832f3 100644 --- a/lib/wibox/drawable.lua +++ b/lib/wibox/drawable.lua @@ -13,6 +13,7 @@ local capi = { screen = screen } local beautiful = require("beautiful") +local base = require("wibox.widget.base") local cairo = require("lgi").cairo local color = require("gears.color") local object = require("gears.object") @@ -226,7 +227,7 @@ end --- Set the widget that the drawable displays function drawable:set_widget(widget) - self._widget = widget + self._widget = base.make_widget_from_value(widget) -- Make sure the widget gets drawn self._need_relayout = true diff --git a/lib/wibox/init.lua b/lib/wibox/init.lua index 3f68d5cb..1f4c7ff5 100644 --- a/lib/wibox/init.lua +++ b/lib/wibox/init.lua @@ -39,7 +39,8 @@ local force_forward = { --@DOC_wibox_COMMON@ function wibox:set_widget(widget) - self._drawable:set_widget(widget) + local w = base.make_widget_from_value(widget) + self._drawable:set_widget(w) end function wibox:get_widget() @@ -202,6 +203,7 @@ end function wibox:get_children_by_id(name) --TODO v5: Move the ID management to the hierarchy. if rawget(self, "_by_id") then + --TODO v5: Remove this, it's `if` nearly dead code, keep the `elseif` return rawget(self, "_by_id")[name] elseif self._drawable.widget and self._drawable.widget._private