From f859131bf33139671d4381d6fe1183e2686e18a0 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 16 Feb 2013 22:14:08 +0100 Subject: [PATCH] wibox.widget.systray: Properly work when rotated (FS#1115) The systray widget's fit() function worked in the (rotated) user coordinate space while the draw() function used device coordinates (unrotated). This meant that width and height were swapped up in the calculations and the systray ended up being way too small. Fix this by making the draw() function use user coordinates, too. This means that it needs some new magic to detect a rotated coordinate space. This, in turn, means that the systray is now automatically rotated when you put it into a rotate layout. This might cause some minor breakage because people no longer need to call :set_horizontal() on the widgets. Thanks a lot to Alexander Gehrke for his help! Signed-off-by: Uli Schlachter --- lib/wibox/widget/systray.lua.in | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/wibox/widget/systray.lua.in b/lib/wibox/widget/systray.lua.in index f6cb6378..325482d9 100644 --- a/lib/wibox/widget/systray.lua.in +++ b/lib/wibox/widget/systray.lua.in @@ -10,6 +10,7 @@ local beautiful = require("beautiful") local capi = { awesome = awesome } local setmetatable = setmetatable local error = error +local abs = math.abs --- wibox.widget.systray local systray = { mt = {} } @@ -19,13 +20,18 @@ local horizontal = true local base_size = nil function systray:draw(wibox, cr, width, height) - local x, y, width, height = lbase.rect_to_device_geometry(cr, 0, 0, width, height) + local x, y, _, _ = lbase.rect_to_device_geometry(cr, 0, 0, width, height) local num_entries = capi.awesome.systray() local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000" + -- Figure out if the cairo context is rotated + local dir_x, dir_y = cr:user_to_device_distance(1, 0) + local is_rotated = abs(dir_x) < abs(dir_y) + local in_dir, ortho, base if horizontal then in_dir, ortho = width, height + is_rotated = not is_rotated else ortho, in_dir = width, height end @@ -34,7 +40,7 @@ function systray:draw(wibox, cr, width, height) else base = in_dir / num_entries end - capi.awesome.systray(wibox.drawin, x, y, base, horizontal, bg) + capi.awesome.systray(wibox.drawin, x, y, base, is_rotated, bg) end function systray:fit(width, height)