From 7bc3ec4c357f21e5c730f604a07c44f7c7b6ca43 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 10 Mar 2021 19:39:47 +0100 Subject: [PATCH] Fix composite widgets with top level container When wrapping container widgets to create reusable composite widgets, `drill` will be called twice on the same widget definition. The first call happens within the wrapping function and applies the children widgets fine. The second call happens when the composite widget is used, but since there are no children widgets defined, the call to `set_children` sets the existing child to `nil` instead. Fixes #3213. Signed-off-by: Lucas Schwiderski --- lib/wibox/widget/base.lua | 44 ++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index 904f5adc..57123c71 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -533,32 +533,34 @@ local function drill(ids, content) end end - -- Add all widgets. - for k = 1, max do - -- ipairs cannot be used on sparse tables. - local v, id2, e = widgets[k], id, nil - if v then - -- It is another declarative container, parse it. - if (not v.is_widget) and (v.widget or v.layout) then - e, id2 = drill(ids, v) - widgets[k] = e - elseif (not v.is_widget) and is_callable(v) then - widgets[k] = v() - end - base.check_widget(widgets[k]) + if widgets and max > 0 then + -- Add all widgets. + for k = 1, max do + -- ipairs cannot be used on sparse tables. + local v, id2, e = widgets[k], id, nil + if v then + -- It is another declarative container, parse it. + if (not v.is_widget) and (v.widget or v.layout) then + e, id2 = drill(ids, v) + widgets[k] = e + elseif (not v.is_widget) and is_callable(v) then + widgets[k] = v() + end + base.check_widget(widgets[k]) - -- Place the widget in the access table. - if id2 then - l [id2] = e - ids[id2] = ids[id2] or {} - table.insert(ids[id2], e) + -- Place the widget in the access table. + if id2 then + l [id2] = e + ids[id2] = ids[id2] or {} + table.insert(ids[id2], e) + end end end - end - -- Replace all children (if any) with the new ones. - if widgets then + + -- Replace all children (if any) with the new ones. l:set_children(widgets) end + return l, id end