systray: Automatically fit into available space

Instead of having to set the systray's base size by hand, it now automatically
uses min(avail_width, avail_height) as its base size. That's way less surprising
for people.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-10-07 11:54:45 +02:00
parent 35c05abe29
commit 547f732b00
2 changed files with 16 additions and 9 deletions

View File

@ -141,7 +141,7 @@ for s = 1, screen.count() do
-- Widgets that are aligned to the right -- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal() local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray(true)) end if s == 1 then right_layout:add(wibox.widget.systray()) end
right_layout:add(mytextclock) right_layout:add(mytextclock)
right_layout:add(mylayoutbox[s]) right_layout:add(mylayoutbox[s])

View File

@ -14,14 +14,13 @@ module("wibox.widget.systray")
local created_systray = false local created_systray = false
local horizontal = true local horizontal = true
local base_size = 16 local base_size = nil
function draw(box, wibox, cr, width, height) function draw(box, wibox, cr, width, height)
local x, y, width, height = lbase.rect_to_device_geometry(cr, 0, 0, width, height) local x, y, width, height = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
local num_entries = capi.awesome.systray() local num_entries = capi.awesome.systray()
local width, height = width, height local in_dir, ortho, base
local in_dir, ortho, base_size
if horizontal then if horizontal then
in_dir, ortho = width, height in_dir, ortho = width, height
else else
@ -37,16 +36,23 @@ end
function fit(box, width, height) function fit(box, width, height)
local num_entries = capi.awesome.systray() local num_entries = capi.awesome.systray()
if horizontal then local base = base_size
return base_size * num_entries, base_size if base == nil then
if width < height then
base = width
else
base = height
end
end end
return base_size, base_size * num_entries if horizontal then
return base * num_entries, base
end
return base, base * num_entries
end end
local function new(horiz) local function new()
local ret = wbase.make_widget() local ret = wbase.make_widget()
horizontal = horiz
if created_systray then if created_systray then
error("More than one systray created!") error("More than one systray created!")
end end
@ -55,6 +61,7 @@ local function new(horiz)
ret.fit = fit ret.fit = fit
ret.draw = draw ret.draw = draw
ret.set_base_size = function(_, size) base_size = size end ret.set_base_size = function(_, size) base_size = size end
ret.set_horizontal = function(_, horiz) horizontal = horiz end
capi.awesome.connect_signal("systray::update", function() capi.awesome.connect_signal("systray::update", function()
ret:emit_signal("widget::updated") ret:emit_signal("widget::updated")