2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local wbase = require("wibox.widget.base")
|
|
|
|
local lbase = require("wibox.layout.base")
|
2010-10-17 09:24:59 +02:00
|
|
|
local beautiful = require("beautiful")
|
2010-10-06 12:42:56 +02:00
|
|
|
local capi = { awesome = awesome }
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local error = error
|
|
|
|
|
|
|
|
module("wibox.widget.systray")
|
|
|
|
|
|
|
|
local created_systray = false
|
|
|
|
local horizontal = true
|
2010-10-07 11:54:45 +02:00
|
|
|
local base_size = nil
|
2010-10-06 12:42:56 +02:00
|
|
|
|
|
|
|
function draw(box, wibox, cr, width, height)
|
|
|
|
local x, y, width, height = lbase.rect_to_device_geometry(cr, 0, 0, width, height)
|
|
|
|
local num_entries = capi.awesome.systray()
|
2010-10-17 09:24:59 +02:00
|
|
|
local bg = beautiful.bg_systray or beautiful.bg_normal
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2010-10-07 11:54:45 +02:00
|
|
|
local in_dir, ortho, base
|
2010-10-06 12:42:56 +02:00
|
|
|
if horizontal then
|
|
|
|
in_dir, ortho = width, height
|
|
|
|
else
|
|
|
|
ortho, in_dir = width, height
|
|
|
|
end
|
|
|
|
if ortho * num_entries <= in_dir then
|
|
|
|
base = ortho
|
|
|
|
else
|
|
|
|
base = in_dir / num_entries
|
|
|
|
end
|
2010-10-17 09:24:59 +02:00
|
|
|
capi.awesome.systray(wibox.drawin, x, y, base, horizontal, bg)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function fit(box, width, height)
|
|
|
|
local num_entries = capi.awesome.systray()
|
2010-10-07 11:54:45 +02:00
|
|
|
local base = base_size
|
|
|
|
if base == nil then
|
|
|
|
if width < height then
|
|
|
|
base = width
|
|
|
|
else
|
|
|
|
base = height
|
|
|
|
end
|
|
|
|
end
|
2010-10-06 12:42:56 +02:00
|
|
|
if horizontal then
|
2010-10-07 11:54:45 +02:00
|
|
|
return base * num_entries, base
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
2010-10-07 11:54:45 +02:00
|
|
|
return base, base * num_entries
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2010-10-07 11:54:45 +02:00
|
|
|
local function new()
|
2010-10-06 12:42:56 +02:00
|
|
|
local ret = wbase.make_widget()
|
|
|
|
|
|
|
|
if created_systray then
|
|
|
|
error("More than one systray created!")
|
|
|
|
end
|
|
|
|
created_systray = true
|
|
|
|
|
|
|
|
ret.fit = fit
|
|
|
|
ret.draw = draw
|
|
|
|
ret.set_base_size = function(_, size) base_size = size end
|
2010-10-07 11:54:45 +02:00
|
|
|
ret.set_horizontal = function(_, horiz) horizontal = horiz end
|
2010-10-06 12:42:56 +02:00
|
|
|
|
|
|
|
capi.awesome.connect_signal("systray::update", function()
|
|
|
|
ret:emit_signal("widget::updated")
|
|
|
|
end)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|