2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Uli Schlachter
|
|
|
|
-- @copyright 2010 Uli Schlachter
|
|
|
|
-- @release @AWESOME_VERSION@
|
2015-02-25 11:18:53 +01:00
|
|
|
-- @classmod wibox.widget.systray
|
2010-10-06 12:42:56 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local wbase = require("wibox.widget.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
|
2013-02-16 22:14:08 +01:00
|
|
|
local abs = math.abs
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2012-06-12 15:55:10 +02:00
|
|
|
local systray = { mt = {} }
|
2010-10-06 12:42:56 +02:00
|
|
|
|
|
|
|
local horizontal = true
|
2010-10-07 11:54:45 +02:00
|
|
|
local base_size = nil
|
2014-04-02 15:25:03 +02:00
|
|
|
local reverse = false
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2015-08-08 13:18:54 +02:00
|
|
|
function systray:draw(context, cr, width, height)
|
2015-07-25 15:52:53 +02:00
|
|
|
local x, y, _, _ = wbase.rect_to_device_geometry(cr, 0, 0, width, height)
|
2010-10-06 12:42:56 +02:00
|
|
|
local num_entries = capi.awesome.systray()
|
2012-11-27 22:55:42 +01:00
|
|
|
local bg = beautiful.bg_systray or beautiful.bg_normal or "#000000"
|
2014-05-10 06:08:42 +02:00
|
|
|
local spacing = beautiful.systray_icon_spacing or 0
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2015-10-10 20:30:08 +02:00
|
|
|
if context and not context.wibox then
|
|
|
|
error("The systray widget can only be placed inside a wibox.")
|
|
|
|
end
|
|
|
|
|
2013-02-16 22:14:08 +01:00
|
|
|
-- 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)
|
|
|
|
|
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
|
2013-02-16 22:14:08 +01:00
|
|
|
is_rotated = not is_rotated
|
2010-10-06 12:42:56 +02:00
|
|
|
else
|
|
|
|
ortho, in_dir = width, height
|
|
|
|
end
|
|
|
|
if ortho * num_entries <= in_dir then
|
|
|
|
base = ortho
|
|
|
|
else
|
|
|
|
base = in_dir / num_entries
|
|
|
|
end
|
2015-08-08 13:18:54 +02:00
|
|
|
capi.awesome.systray(context.wibox.drawin, math.ceil(x), math.ceil(y),
|
2015-05-28 15:50:36 +02:00
|
|
|
base, is_rotated, bg, reverse, spacing)
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2015-08-08 13:43:35 +02:00
|
|
|
function systray:fit(context, width, height)
|
2010-10-06 12:42:56 +02:00
|
|
|
local num_entries = capi.awesome.systray()
|
2010-10-07 11:54:45 +02:00
|
|
|
local base = base_size
|
2014-05-10 06:08:42 +02:00
|
|
|
local spacing = beautiful.systray_icon_spacing or 0
|
2014-05-11 17:24:01 +02:00
|
|
|
if num_entries == 0 then
|
|
|
|
return 0, 0
|
|
|
|
end
|
2010-10-07 11:54:45 +02:00
|
|
|
if base == nil then
|
|
|
|
if width < height then
|
|
|
|
base = width
|
|
|
|
else
|
|
|
|
base = height
|
|
|
|
end
|
|
|
|
end
|
2014-05-10 06:08:42 +02:00
|
|
|
base = base + spacing
|
2010-10-06 12:42:56 +02:00
|
|
|
if horizontal then
|
2014-05-10 06:08:42 +02:00
|
|
|
return base * num_entries - spacing, base
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
2014-05-10 06:08:42 +02:00
|
|
|
return base, base * num_entries - spacing
|
2010-10-06 12:42:56 +02:00
|
|
|
end
|
|
|
|
|
2014-04-02 15:25:03 +02:00
|
|
|
local function new(revers)
|
2010-10-06 12:42:56 +02:00
|
|
|
local ret = wbase.make_widget()
|
|
|
|
|
2012-06-12 15:55:10 +02:00
|
|
|
ret.fit = systray.fit
|
|
|
|
ret.draw = systray.draw
|
2010-10-06 12:42:56 +02:00
|
|
|
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
|
2014-04-02 15:25:03 +02:00
|
|
|
ret.set_reverse = function(revers) reverse = revers end
|
|
|
|
|
|
|
|
if revers then
|
|
|
|
ret:set_reverse(true)
|
|
|
|
end
|
2010-10-06 12:42:56 +02:00
|
|
|
|
|
|
|
capi.awesome.connect_signal("systray::update", function()
|
2015-06-14 16:37:07 +02:00
|
|
|
ret:emit_signal("widget::layout_changed")
|
2015-11-29 12:33:13 +01:00
|
|
|
ret:emit_signal("widget::redraw_needed")
|
2010-10-06 12:42:56 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
2012-06-12 15:55:10 +02:00
|
|
|
function systray.mt:__call(...)
|
|
|
|
return new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(systray, systray.mt)
|
2010-10-06 12:42:56 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|