From 983d094c76c5ddb6fe7deeec2f977a981c057a8a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 5 Oct 2014 10:47:39 +0200 Subject: [PATCH] wibox.layout.base.rect_to_device_geometry: Fix for "weird" rotations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old code transformed the top-left and bottom-right corner of the rectangle to device space and calculated a rectangle based on these two points. However, if you rotate a rectangle by 45°, these two points will be directly above each other and thus the old code would calculate a width of 0. Fix this by transforming all four corners of the rectangle into device space and calculating a rectangle based on this. Signed-off-by: Uli Schlachter --- lib/wibox/layout/base.lua.in | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/wibox/layout/base.lua.in b/lib/wibox/layout/base.lua.in index d5f9f982..69c55510 100644 --- a/lib/wibox/layout/base.lua.in +++ b/lib/wibox/layout/base.lua.in @@ -13,15 +13,17 @@ local max = math.max -- wibox.layout.base local base = {} ---- Figure out the geometry in device coordinate space. This will break if --- someone rotates the coordinate space by a non-multiple of 90°. +--- Figure out the geometry in device coordinate space. This gives only tight +-- bounds if no rotations by non-multiples of 90° are used. function base.rect_to_device_geometry(cr, x, y, width, height) local x1, y1 = cr:user_to_device(x, y) - local x2, y2 = cr:user_to_device(x + width, y + height) - local x = min(x1, x2) - local y = min(y1, y2) - local width = max(x1, x2) - x - local height = max(y1, y2) - y + local x2, y2 = cr:user_to_device(x, y + height) + local x3, y3 = cr:user_to_device(x + width, y + height) + local x4, y4 = cr:user_to_device(x + width, y) + local x = min(x1, x2, x3, x4) + local y = min(y1, y2, y3, y4) + local width = max(x1, x2, x3, x4) - x + local height = max(y1, y2, y3, y4) - y return x, y, width, height end