2013-05-11 21:02:42 +02:00
|
|
|
local setmetatable = setmetatable
|
2016-02-21 08:34:05 +01:00
|
|
|
local base = require( "radical.base" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local beautiful = require( "beautiful" )
|
|
|
|
local layout = require( "radical.layout" )
|
|
|
|
local arrow_style = require( "radical.style.arrow" )
|
|
|
|
local smart_wibox = require( "radical.smart_wibox" )
|
|
|
|
local common = require( "radical.common" )
|
2013-05-11 21:02:42 +02:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
local capi, module = { keygrabber = keygrabber },{}
|
2013-05-11 21:02:42 +02:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
local function set_visible(i, value)
|
|
|
|
local w, pg = i.w, i.private_data.parent_geometry
|
2016-02-11 07:36:50 +01:00
|
|
|
|
2016-03-16 08:33:18 +01:00
|
|
|
if value and pg then
|
2016-03-14 22:52:28 +01:00
|
|
|
w:move_by_parent(pg, "widget")
|
2014-03-26 21:18:59 +01:00
|
|
|
end
|
2014-02-02 06:35:50 +01:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
w.visible = value
|
2014-02-02 06:35:50 +01:00
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
if not value and (not pg or not pg.is_menu) then
|
|
|
|
capi.keygrabber.stop()
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-29 22:01:14 +02:00
|
|
|
local function new(args)
|
|
|
|
args = args or {}
|
|
|
|
args.internal = args.internal or {}
|
|
|
|
args.internal.setup_item = args.internal.setup_item or common.setup_item
|
|
|
|
args.style = args.style or beautiful.menu_default_style or arrow_style
|
|
|
|
local data = base(args)
|
|
|
|
|
|
|
|
data:connect_signal("parent_geometry::changed", function()
|
|
|
|
args.internal.w:move_by_parent(data.parent_geometry, "widget")
|
|
|
|
end)
|
|
|
|
|
2016-02-21 08:34:05 +01:00
|
|
|
local internal = data._internal
|
|
|
|
|
|
|
|
-- Create the layout
|
|
|
|
data.layout = data.layout or layout.vertical
|
|
|
|
|
|
|
|
internal.layout = data.layout(data)
|
2016-06-24 06:46:41 +02:00
|
|
|
internal.margin = wibox.container.margin(internal.layout)
|
2016-02-21 08:34:05 +01:00
|
|
|
|
|
|
|
-- Init
|
|
|
|
internal.w = smart_wibox(internal.margin, {
|
|
|
|
visible = false ,
|
|
|
|
ontop = true ,
|
|
|
|
opacity = data.opacity ,
|
|
|
|
bg = data.bg ,
|
|
|
|
fg = data.fg ,
|
2016-03-15 08:55:20 +01:00
|
|
|
preferred_positions = {"right", "left" },
|
2016-02-21 08:34:05 +01:00
|
|
|
border_color = data.border_color
|
|
|
|
or beautiful.menu_outline_color
|
|
|
|
or beautiful.menu_border_color
|
|
|
|
or beautiful.fg_normal
|
|
|
|
})
|
|
|
|
|
|
|
|
-- Accessors
|
|
|
|
data.get_wibox = function() return internal.w end
|
|
|
|
data.get_visible = function() return internal.private_data.visible end
|
|
|
|
data.get_margins = common.get_margins
|
|
|
|
internal.set_visible = set_visible
|
|
|
|
|
|
|
|
-- Support remove, swap, insert, append...
|
|
|
|
common.setup_item_move_events(data)
|
|
|
|
|
|
|
|
-- Init the style
|
2016-06-29 22:01:14 +02:00
|
|
|
args.style(data)
|
2016-02-21 08:34:05 +01:00
|
|
|
|
2016-06-29 22:01:14 +02:00
|
|
|
return data
|
2013-05-11 21:02:42 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
2016-02-21 08:34:05 +01:00
|
|
|
-- kate: space-indent on; indent-width 4; replace-tabs on;
|