diff --git a/lib/wibox/layout/align.lua b/lib/wibox/layout/align.lua index 7d5cff06..bc7635cd 100644 --- a/lib/wibox/layout/align.lua +++ b/lib/wibox/layout/align.lua @@ -10,6 +10,7 @@ local table = table local pairs = pairs local type = type local floor = math.floor +local util = require("awful.util") local base = require("wibox.widget.base") local align = {} @@ -164,6 +165,12 @@ function align:set_third(widget) self:emit_signal("widget::layout_changed") end +--- Get all children of this layout +-- @treturn table a list of all widgets +function align:get_children() + return util.from_sparse {self.first, self.second, self.third} +end + --- Fit the align layout into the given space. The align layout will -- ask for the sum of the sizes of its sub-widgets in its direction -- and the largest sized sub widget in the other direction. diff --git a/lib/wibox/layout/constraint.lua b/lib/wibox/layout/constraint.lua index 2e9a39ba..32aa06a5 100644 --- a/lib/wibox/layout/constraint.lua +++ b/lib/wibox/layout/constraint.lua @@ -44,6 +44,12 @@ function constraint:set_widget(widget) self:emit_signal("widget::layout_changed") end +--- Get the number of children element +-- @treturn table The children +function constraint:get_children() + return {self.widget} +end + --- Set the strategy to use for the constraining. Valid values are 'max', -- 'min' or 'exact'. Throws an error on invalid values. function constraint:set_strategy(val) diff --git a/lib/wibox/layout/margin.lua b/lib/wibox/layout/margin.lua index 9994ec66..1666f85f 100644 --- a/lib/wibox/layout/margin.lua +++ b/lib/wibox/layout/margin.lua @@ -72,6 +72,12 @@ function margin:set_widget(widget) self:emit_signal("widget::layout_changed") end +--- Get the number of children element +-- @treturn table The children +function margin:get_children() + return {self.widget} +end + --- Set all the margins to val. function margin:set_margins(val) self.left = val diff --git a/lib/wibox/layout/mirror.lua b/lib/wibox/layout/mirror.lua index 24408151..c98e407f 100644 --- a/lib/wibox/layout/mirror.lua +++ b/lib/wibox/layout/mirror.lua @@ -58,6 +58,12 @@ function mirror:set_widget(widget) self:emit_signal("widget::layout_changed") end +--- Get the number of children element +-- @treturn table The children +function mirror:get_children() + return {self.widget} +end + --- Reset this layout. The widget will be removed and the axes reset. function mirror:reset() self.horizontal = false diff --git a/lib/wibox/layout/rotate.lua b/lib/wibox/layout/rotate.lua index e1c803f1..5d5d3b66 100644 --- a/lib/wibox/layout/rotate.lua +++ b/lib/wibox/layout/rotate.lua @@ -66,6 +66,12 @@ function rotate:set_widget(widget) self:emit_signal("widget::layout_changed") end +--- Get the number of children element +-- @treturn table The children +function rotate:get_children() + return {self.widget} +end + --- Reset this layout. The widget will be removed and the rotation reset. function rotate:reset() self.direction = nil diff --git a/lib/wibox/layout/scroll.lua b/lib/wibox/layout/scroll.lua index a153f49d..44165ea5 100644 --- a/lib/wibox/layout/scroll.lua +++ b/lib/wibox/layout/scroll.lua @@ -261,6 +261,12 @@ function scroll:set_widget(widget) self:emit_signal("widget::redraw_needed") end +--- Get the number of children element +-- @treturn table The children +function scroll:get_children() + return {self.widget} +end + --- Specify the expand mode that is used for extra space. -- @tparam boolean expand If true, the widget is expanded to include the extra -- space. If false, the extra space is simply left empty. diff --git a/lib/wibox/widget/background.lua b/lib/wibox/widget/background.lua index 333c1c6e..cbe2e711 100644 --- a/lib/wibox/widget/background.lua +++ b/lib/wibox/widget/background.lua @@ -69,6 +69,12 @@ function background:set_widget(widget) self:emit_signal("widget::layout_changed") end +--- Get the number of children element +-- @treturn table The children +function background:get_children() + return {self.widget} +end + --- Set the background to use function background:set_bg(bg) if bg then diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index 3290acf0..d79642df 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -73,6 +73,32 @@ function base.widget:set_height(s) end end +--- Get all direct children widgets +-- This method should be re-implemented by the relevant widgets +-- @treturn table The children +function base.widget:get_children() + return {} +end + +-- It could have been merged into `get_all_children`, but it's not necessary +local function digg_children(ret, tlw) + for k, w in ipairs(tlw:get_children()) do + table.insert(ret, w) + digg_children(ret, w) + end +end + +--- Get all direct and indirect children widgets +-- This will scan all containers recursively to find widgets +-- Warning: This method it prone to stack overflow id the widget, or any of its +-- children, contain (directly or indirectly) itself. +-- @treturn table The children +function base.widget:get_all_children() + local ret = {} + digg_children(ret, self) + return ret +end + -- }}} -- {{{ Caches