From 79394c09653c4a44f97923e5d198efc116137186 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 23 Jul 2016 17:24:11 -0400 Subject: [PATCH] widgets: Apply attributes before adding the widgets For example, some layouts may place the widgets in a different order depending on some attreibutes. --- lib/wibox/widget/base.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index e498875b..07a72fb5 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -436,6 +436,19 @@ local function drill(ids, content) -- Clear the internal attributes attributes.id, attributes.layout, attributes.widget = nil, nil, nil + -- Set layouts attributes, this has to be done before the widgets are added + -- because it might affect the output. + for attr, val in pairs(attributes) do + if l["set_"..attr] then + l["set_"..attr](l, val) + elseif type(l[attr]) == "function" then + l[attr](l, val) + else + l[attr] = val + 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 @@ -459,17 +472,6 @@ local function drill(ids, content) -- Replace all children (if any) with the new ones l:set_children(widgets) - -- Set layouts attributes - for attr, val in pairs(attributes) do - if l["set_"..attr] then - l["set_"..attr](l, val) - elseif type(l[attr]) == "function" then - l[attr](l, val) - else - l[attr] = val - end - end - return l, id end