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 <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2013-02-16 22:14:08 +01:00
parent f86a9c896c
commit f859131bf3
1 changed files with 8 additions and 2 deletions

View File

@ -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)