From 87813a5597ae7e13e94ef866d63f5ba66beb7cc9 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 26 Mar 2016 01:40:59 -0400 Subject: [PATCH 1/2] layout.margin: Avoid unneeded redraw --- lib/wibox/layout/margin.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/wibox/layout/margin.lua b/lib/wibox/layout/margin.lua index 9a8a8b2cd..0b94099c3 100644 --- a/lib/wibox/layout/margin.lua +++ b/lib/wibox/layout/margin.lua @@ -87,6 +87,13 @@ end --- Set all the margins to val. function margin:set_margins(val) + if self.left == val and + self.right == val and + self.top == val and + self.bottom == val then + return + end + self.left = val self.right = val self.top = val @@ -142,6 +149,7 @@ end -- Create setters for each direction for _, v in pairs({ "left", "right", "top", "bottom" }) do margin["set_" .. v] = function(layout, val) + if layout[v] == val then return end layout[v] = val layout:emit_signal("widget::layout_changed") end From 35ece57a78bad6ac4243c0d0026141938d3ad719 Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sat, 26 Mar 2016 01:46:47 -0400 Subject: [PATCH 2/2] layout.margin: Fix the documentation --- lib/wibox/layout/margin.lua | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/wibox/layout/margin.lua b/lib/wibox/layout/margin.lua index 0b94099c3..11448bc00 100644 --- a/lib/wibox/layout/margin.lua +++ b/lib/wibox/layout/margin.lua @@ -14,7 +14,7 @@ local cairo = require("lgi").cairo local margin = { mt = {} } ---- Draw a margin layout +-- Draw a margin layout function margin:draw(_, cr, width, height) local x = self.left local y = self.top @@ -35,7 +35,7 @@ function margin:draw(_, cr, width, height) end end ---- Layout a margin layout +-- Layout a margin layout function margin:layout(_, width, height) if self.widget then local x = self.left @@ -47,7 +47,7 @@ function margin:layout(_, width, height) end end ---- Fit a margin layout into the given space +-- Fit a margin layout into the given space function margin:fit(context, width, height) local extra_w = self.left + self.right local extra_h = self.top + self.bottom @@ -72,13 +72,13 @@ function margin:set_widget(widget) self:emit_signal("widget::layout_changed") end ---- Get the number of children element +-- Get the number of children element -- @treturn table The children function margin:get_children() return {self.widget} end ---- Replace the layout children +-- Replace the layout children -- 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) @@ -86,6 +86,7 @@ function margin:set_children(children) end --- Set all the margins to val. +-- @tparam number val The margin value function margin:set_margins(val) if self.left == val and self.right == val and @@ -101,7 +102,8 @@ function margin:set_margins(val) self:emit_signal("widget::layout_changed") end ---- Set the margins color to color +--- Set the margins color to create a border. +-- @param color A color used to fill the margin. function margin:set_color(color) self.color = color and gcolor(color) self:emit_signal("widget::redraw_needed")