From f025409cd37b546b33744458723c244330960622 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 19 Jun 2019 18:18:06 +0200 Subject: [PATCH 1/3] wibox.container.margin: Do not produce negative sizes With draw_empty=false, :fit() can return 0,0. Then, when :layout() is called, it will compute negative widths and heights. This can then cause lots of problems later on. Avoid this by having :layout() return nothing instead of producing negative sizes. Fixes: https://github.com/awesomeWM/awesome/issues/2799 Signed-off-by: Uli Schlachter --- lib/wibox/container/margin.lua | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/wibox/container/margin.lua b/lib/wibox/container/margin.lua index 78d74cc1..71555237 100644 --- a/lib/wibox/container/margin.lua +++ b/lib/wibox/container/margin.lua @@ -44,7 +44,12 @@ function margin:layout(_, width, height) local w = self._private.right local h = self._private.bottom - return { base.place_widget_at(self._private.widget, x, y, width - x - w, height - y - h) } + local resulting_width = width - x - w + local resulting_height = height - y - h + + if resulting_width > 0 and resulting_height > 0 then + return { base.place_widget_at(self._private.widget, x, y, resulting_width, resulting_height) } + end end end From 2aa198a57b4a09fba0d9c9ad2e86e370bc9d8949 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 19 Jun 2019 18:20:09 +0200 Subject: [PATCH 2/3] wibox.widget.base.place_widget_*: Protect against negative sizes This commits adds assertions to catch negative width or height. Would-have-helped-with: https://github.com/awesomeWM/awesome/issues/2799 Signed-off-by: Uli Schlachter --- lib/wibox/widget/base.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/wibox/widget/base.lua b/lib/wibox/widget/base.lua index dc8bf5ff..d3958b2d 100644 --- a/lib/wibox/widget/base.lua +++ b/lib/wibox/widget/base.lua @@ -397,6 +397,8 @@ end -- @treturn table An opaque object that can be returned from `:layout()`. -- @staticfct wibox.widget.base.place_widget_via_matrix function base.place_widget_via_matrix(widget, mat, width, height) + assert(width >= 0, "A widget's width cannot be negative: " .. tostring(width)) + assert(height >= 0, "A widget's height cannot be negative: " .. tostring(height)) return { _widget = widget, _width = width, From a4dadde33553847bcf754e11c85457c83c81da20 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 19 Jun 2019 18:23:08 +0200 Subject: [PATCH 3/3] Fix wibox.hierarchy's empty_clip() This function checks if a given cairo context has an empty clip. It was written with the assumption that cairo_clip_extents() produces the x, y, width, height of the clip extents. However, that function actually produces x1, y1, x2, y2, where (x1, y1) and (x2, y2) are the corners of the rectangles. Due to the way the function is written, it will return non-zero numbers when there is a translation (cr:translate()). Thus, this function worked basically never. Fix this by checking if both points have the same X- or Y-coordinate. Signed-off-by: Uli Schlachter --- lib/wibox/hierarchy.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/wibox/hierarchy.lua b/lib/wibox/hierarchy.lua index a5edddfa..7dbeb73a 100644 --- a/lib/wibox/hierarchy.lua +++ b/lib/wibox/hierarchy.lua @@ -304,8 +304,8 @@ end --- Does the given cairo context have an empty clip (aka "no drawing possible")? local function empty_clip(cr) - local _, _, width, height = cr:clip_extents() - return width == 0 or height == 0 + local x1, y1, x2, y2 = cr:clip_extents() + return x2 - x1 == 0 or y2 - y1 == 0 end --- Draw a hierarchy to some cairo context.