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.
This commit is contained in:
Emmanuel Lepage Vallee 2018-12-26 23:34:17 -05:00
parent 249f11ec82
commit 349b75994f
3 changed files with 18 additions and 2 deletions

View File

@ -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

View File

@ -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

View File

@ -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