From cedeb2bb5ab1934ce3364d1fab22f9788de39b9e Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 1 Jul 2017 22:43:01 -0400 Subject: [PATCH] wibox: Add a `to_widget()` and `save_to_svg()` method. Take a wibox snapshot as a widget. It also add an helper to save it to a file. This is useful for debugging when called from `awesome-client` --- lib/wibox/init.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lib/wibox/init.lua b/lib/wibox/init.lua index f90284ac..aa027bcb 100644 --- a/lib/wibox/init.lua +++ b/lib/wibox/init.lua @@ -63,6 +63,37 @@ function wibox:find_widgets(x, y) return self._drawable:find_widgets(x, y) end +--- Create a widget that reflects the current state of this wibox. +-- @treturn widget A new widget. +function wibox:to_widget() + local bw = self.border_width or beautiful.border_width or 0 + return wibox.widget { + { + self:get_widget(), + margins = bw, + widget = wibox.container.margin + }, + bg = self.bg or beautiful.bg_normal or "#ffffff", + fg = self.fg or beautiful.fg_normal or "#000000", + shape_border_color = self.border_color or beautiful.border_color or "#000000", + shape_border_width = bw*2, + shape_clip = true, + shape = self._shape, + forced_width = self:geometry().width + 2*bw, + forced_height = self:geometry().height + 2*bw, + widget = wibox.container.background + } +end + +--- Save a screenshot of the wibox to `path`. +-- @tparam string path The path. +-- @tparam[opt=nil] table context A widget context. +function wibox:save_to_svg(path, context) + wibox.widget.draw_to_svg_file( + self:to_widget(), path, self:geometry().width, self:geometry().height, context + ) +end + function wibox:_apply_shape() local shape = self._shape