2014-09-22 07:22:18 +02:00
|
|
|
-- This helper module create a virtual margin object. This then used as a proxy
|
|
|
|
-- between the real wibox.widget.margins and the Radical menu.
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
2014-10-05 23:53:26 +02:00
|
|
|
local awful = require("awful")
|
2014-09-22 07:22:18 +02:00
|
|
|
local module = {}
|
|
|
|
|
2014-10-05 23:53:26 +02:00
|
|
|
local function reset_margins(margins)
|
|
|
|
local widget = margins.widget
|
|
|
|
if widget and margins.defaults then
|
|
|
|
for k,v in pairs(margins.defaults) do
|
|
|
|
local f = widget["set_"..k:lower()]
|
|
|
|
if f then
|
|
|
|
f(widget,v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function new(widget,defaults)
|
2014-10-18 05:52:26 +02:00
|
|
|
local mt = nil
|
|
|
|
mt = setmetatable({defaults=awful.util.table.join(defaults,{}),widget=widget,reset=reset_margins,
|
2014-10-05 23:53:26 +02:00
|
|
|
merge = function(values)
|
2014-09-22 07:22:18 +02:00
|
|
|
if values.left then
|
|
|
|
widget:set_left(values.left)
|
|
|
|
end
|
|
|
|
if values.right then
|
|
|
|
widget:set_right(values.right)
|
|
|
|
end
|
|
|
|
if values.top then
|
|
|
|
widget:set_top(values.top)
|
|
|
|
end
|
|
|
|
if values.bottom then
|
|
|
|
widget:set_bottom(values.bottom)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
},{__newindex = function(tab, key,value)
|
2014-10-18 05:52:26 +02:00
|
|
|
key = key:lower()
|
2014-10-05 23:53:26 +02:00
|
|
|
if key == "widget" then
|
|
|
|
rawset(tab,"widget",value)
|
|
|
|
reset_margins(tab)
|
|
|
|
elseif widget then
|
|
|
|
widget["set_"..key](widget,value)
|
|
|
|
else --TODO can't do this
|
2014-10-18 05:52:26 +02:00
|
|
|
mt.defaults[key] = value
|
2014-10-05 23:53:26 +02:00
|
|
|
end
|
2014-09-22 07:22:18 +02:00
|
|
|
end
|
|
|
|
,__index=function(table,key)
|
2014-10-05 23:53:26 +02:00
|
|
|
local w = rawget(table,"widget")
|
2014-10-18 05:52:26 +02:00
|
|
|
return w and w[key] or defaults[key] --widget["get_"..key](widget)
|
2014-10-05 23:53:26 +02:00
|
|
|
end})
|
|
|
|
|
|
|
|
reset_margins(mt)
|
|
|
|
|
2014-09-22 07:22:18 +02:00
|
|
|
return mt
|
|
|
|
end
|
|
|
|
|
2014-10-05 23:53:26 +02:00
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
2014-09-22 07:22:18 +02:00
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|