From cf3c81fa9e0693868c2440387c05ae6a917ccb18 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 27 Feb 2016 13:55:34 +0100 Subject: [PATCH] Implement :set_children() sanely everywhere This makes the code use the existing functions for setting widgets. That way, all the sanity checks that the existing functions have are applied for this code as well. I just spent half an hour tracking down a bug where a boolean ended up as a "widget" in a fixed layout. The symptom was that while drawing the widget, an error happened. Via this change, the error would instead be flagged while constructing the widget. Signed-off-by: Uli Schlachter --- lib/wibox/layout/align.lua | 8 +++----- lib/wibox/layout/constraint.lua | 3 +-- lib/wibox/layout/fixed.lua | 8 +++++--- lib/wibox/layout/margin.lua | 3 +-- lib/wibox/layout/mirror.lua | 3 +-- lib/wibox/layout/rotate.lua | 3 +-- lib/wibox/layout/scroll.lua | 3 +-- lib/wibox/widget/background.lua | 3 +-- 8 files changed, 14 insertions(+), 20 deletions(-) diff --git a/lib/wibox/layout/align.lua b/lib/wibox/layout/align.lua index 069f4674b..258acb892 100644 --- a/lib/wibox/layout/align.lua +++ b/lib/wibox/layout/align.lua @@ -175,11 +175,9 @@ end -- This layout only accept three children, all others will be ignored -- @tparam table children A table composed of valid widgets function align:set_children(children) - if not children then return self:reset() end - self.first = children[1] - self.second = children[2] - self.third = children[3] - self:emit_signal("widget::layout_changed") + self:set_first(children[1]) + self:set_second(children[2]) + self:set_third(children[3]) end --- Fit the align layout into the given space. The align layout will diff --git a/lib/wibox/layout/constraint.lua b/lib/wibox/layout/constraint.lua index 99177c1bd..e355e5e4b 100644 --- a/lib/wibox/layout/constraint.lua +++ b/lib/wibox/layout/constraint.lua @@ -54,8 +54,7 @@ end -- This layout only accept one children, all others will be ignored -- @tparam table children A table composed of valid widgets function constraint:set_children(children) - self.widget = children and children[1] - self:emit_signal("widget::layout_changed") + self:set_widget(children[1]) end --- Set the strategy to use for the constraining. Valid values are 'max', diff --git a/lib/wibox/layout/fixed.lua b/lib/wibox/layout/fixed.lua index f2de84b8f..ecc704dc6 100644 --- a/lib/wibox/layout/fixed.lua +++ b/lib/wibox/layout/fixed.lua @@ -5,6 +5,7 @@ -- @classmod wibox.layout.fixed --------------------------------------------------------------------------- +local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1) local base = require("wibox.widget.base") local table = table local pairs = pairs @@ -110,9 +111,10 @@ end --- Replace the layout children -- @tparam table children A table composed of valid widgets function fixed:set_children(children) - if not children then return self:reset() end - self.widgets = children - self:emit_signal("widget::layout_changed") + self:reset() + if #children > 0 then + self:add(unpack(children)) + end end --- Replace the first instance of `widget` in the layout with `widget2` diff --git a/lib/wibox/layout/margin.lua b/lib/wibox/layout/margin.lua index e7629a106..9a8a8b2cd 100644 --- a/lib/wibox/layout/margin.lua +++ b/lib/wibox/layout/margin.lua @@ -82,8 +82,7 @@ end -- This layout only accept one children, all others will be ignored -- @tparam table children A table composed of valid widgets function margin:set_children(children) - self.widget = children and children[1] - self:emit_signal("widget::layout_changed") + self:set_widget(children[1]) end --- Set all the margins to val. diff --git a/lib/wibox/layout/mirror.lua b/lib/wibox/layout/mirror.lua index 616bb1537..9559d3401 100644 --- a/lib/wibox/layout/mirror.lua +++ b/lib/wibox/layout/mirror.lua @@ -68,8 +68,7 @@ end -- This layout only accept one children, all others will be ignored -- @tparam table children A table composed of valid widgets function mirror:set_children(children) - self.widget = children and children[1] - self:emit_signal("widget::layout_changed") + self:set_widget(children[1]) end --- Reset this layout. The widget will be removed and the axes reset. diff --git a/lib/wibox/layout/rotate.lua b/lib/wibox/layout/rotate.lua index 8de9ef7bf..46e60b8e0 100644 --- a/lib/wibox/layout/rotate.lua +++ b/lib/wibox/layout/rotate.lua @@ -76,8 +76,7 @@ end -- This layout only accept one children, all others will be ignored -- @tparam table children A table composed of valid widgets function rotate:set_children(children) - self.widget = children and children[1] - self:emit_signal("widget::layout_changed") + self:set_widget(children[1]) end --- Reset this layout. The widget will be removed and the rotation reset. diff --git a/lib/wibox/layout/scroll.lua b/lib/wibox/layout/scroll.lua index 1af8f94eb..850fee4b0 100644 --- a/lib/wibox/layout/scroll.lua +++ b/lib/wibox/layout/scroll.lua @@ -267,8 +267,7 @@ end -- This layout only accept one children, all others will be ignored -- @tparam table children A table composed of valid widgets function scroll:set_children(children) - self.widget = children and children[1] - self:emit_signal("widget::layout_changed") + self:set_widget(children[1]) end --- Specify the expand mode that is used for extra space. diff --git a/lib/wibox/widget/background.lua b/lib/wibox/widget/background.lua index 274d80243..7d547124a 100644 --- a/lib/wibox/widget/background.lua +++ b/lib/wibox/widget/background.lua @@ -109,8 +109,7 @@ end -- This layout only accept one children, all others will be ignored -- @tparam table children A table composed of valid widgets function background:set_children(children) - self.widget = children and children[1] - self:emit_signal("widget::layout_changed") + self:set_widget(children[1]) end --- Set the background to use