2013-07-21 10:15:56 +02:00
|
|
|
local base = require( "radical.base" )
|
|
|
|
local print = print
|
|
|
|
local unpack = unpack
|
|
|
|
local debug = debug
|
|
|
|
local type = type
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
local color = require( "gears.color" )
|
|
|
|
local wibox = require( "wibox" )
|
|
|
|
local beautiful = require( "beautiful" )
|
|
|
|
local cairo = require( "lgi" ).cairo
|
|
|
|
local awful = require( "awful" )
|
|
|
|
local util = require( "awful.util" )
|
|
|
|
local button = require( "awful.button" )
|
|
|
|
local layout = require( "radical.layout" )
|
|
|
|
local checkbox = require( "radical.widgets.checkbox" )
|
|
|
|
local classic_style = require( "radical.style.classic" )
|
|
|
|
|
|
|
|
local capi,module = { mouse = mouse , screen = screen , keygrabber = keygrabber },{}
|
|
|
|
|
|
|
|
local function setup_drawable(data)
|
|
|
|
local internal = data._internal
|
2014-03-05 06:12:48 +01:00
|
|
|
local private_data = internal.private_data
|
2014-02-02 06:35:50 +01:00
|
|
|
|
|
|
|
-- An embeded menu can only be visible if the parent is
|
2014-03-05 06:12:48 +01:00
|
|
|
data.get_visible = function() return data._embeded_parent and data._embeded_parent.visible or false end --Let the parent handle that
|
|
|
|
data.set_visible = function(_,v) if data._embeded_parent then data._embeded_parent.visible = v end end
|
2014-02-02 06:35:50 +01:00
|
|
|
|
|
|
|
-- Enumate geometry --BUG this is fake, but better than nothing
|
2014-03-22 04:20:50 +01:00
|
|
|
data.get_width = function() return data._embeded_parent and (data._embeded_parent.width --[[+ (internal.current_width or 0)]])end
|
|
|
|
data.get_y = function() return data._embeded_parent and (data._embeded_parent.y--[[ + (internal.current_y or 0)]]) end
|
|
|
|
data.get_x = function() return data._embeded_parent and (data._embeded_parent.x--[[ + (internal.current_x or 0)]]) end
|
2013-07-21 10:15:56 +02:00
|
|
|
if not data.layout then
|
|
|
|
data.layout = layout.vertical
|
|
|
|
end
|
|
|
|
internal.layout = data.layout(data)
|
|
|
|
data.width,data.height = data._internal.layout:fit()
|
2014-02-02 06:35:50 +01:00
|
|
|
data.margins={left=0,right=0,bottom=0,top=0}
|
2014-03-19 04:52:19 +01:00
|
|
|
internal.layout:connect_signal("mouse::enter",function(_,geo)
|
2014-03-22 04:20:50 +01:00
|
|
|
-- internal.current_x = geo.x
|
|
|
|
-- internal.current_y = geo.y
|
|
|
|
-- internal.current_width = geo.width
|
|
|
|
if data._embeded_parent._current_item then
|
|
|
|
data._embeded_parent._current_item.state[base.item_flags.SELECTED] = nil
|
|
|
|
data._embeded_parent._current_item.selected = false
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
internal.layout:connect_signal("mouse::leave",function(_,geo)
|
|
|
|
if data._current_item then
|
|
|
|
data._current_item.selected = false
|
|
|
|
data._current_item.state[base.item_flags.SELECTED] = nil
|
|
|
|
end
|
2014-03-19 04:52:19 +01:00
|
|
|
end)
|
2013-07-21 10:15:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function setup_item(data,item,args)
|
|
|
|
local f = (data._internal.layout.setup_item) or (layout.vertical.setup_item)
|
|
|
|
f(data._internal.layout,data,item,args)
|
|
|
|
local buttons = {}
|
|
|
|
for i=1,10 do
|
|
|
|
if args["button"..i] then
|
2014-02-17 05:55:44 +01:00
|
|
|
buttons[i] = args["button"..i]
|
2013-07-21 10:15:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
if not buttons[3] then --Hide on right click
|
2014-02-17 05:55:44 +01:00
|
|
|
buttons[3] = function()
|
2013-07-21 10:15:56 +02:00
|
|
|
data.visible = false
|
|
|
|
if data.parent_geometry and data.parent_geometry.is_menu then
|
|
|
|
data.parent_geometry.visible = false
|
|
|
|
end
|
2014-02-17 05:55:44 +01:00
|
|
|
end
|
2013-07-21 10:15:56 +02:00
|
|
|
end
|
|
|
|
if not buttons[4] then
|
2014-02-17 05:55:44 +01:00
|
|
|
buttons[4] = function()
|
2013-07-21 10:15:56 +02:00
|
|
|
data:scroll_up()
|
2014-02-17 05:55:44 +01:00
|
|
|
end
|
2013-07-21 10:15:56 +02:00
|
|
|
end
|
|
|
|
if not buttons[5] then
|
2014-02-17 05:55:44 +01:00
|
|
|
buttons[5] = function()
|
2013-07-21 10:15:56 +02:00
|
|
|
data:scroll_down()
|
2014-02-17 05:55:44 +01:00
|
|
|
end
|
2013-07-21 10:15:56 +02:00
|
|
|
end
|
2014-02-17 05:55:44 +01:00
|
|
|
|
2014-02-20 04:16:59 +01:00
|
|
|
item:connect_signal("button::release",function(_m,_i,button_id,mods)
|
2014-02-17 05:55:44 +01:00
|
|
|
if #mods == 0 and buttons[button_id] then
|
2014-02-17 07:11:35 +01:00
|
|
|
buttons[button_id](_m,_i,mods)
|
2014-02-17 05:55:44 +01:00
|
|
|
end
|
|
|
|
end)
|
2014-03-19 04:52:19 +01:00
|
|
|
|
2014-03-22 04:20:50 +01:00
|
|
|
item.widget:connect_signal("mouse::enter",function(_,geo)
|
|
|
|
item.y = geo.y
|
|
|
|
end)
|
2013-07-21 10:15:56 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local function new(args)
|
|
|
|
local args = args or {}
|
|
|
|
args.internal = args.internal or {}
|
|
|
|
args.internal.setup_drawable = args.internal.setup_drawable or setup_drawable
|
|
|
|
args.internal.setup_item = args.internal.setup_item or setup_item
|
|
|
|
args.style = args.style or classic_style
|
|
|
|
local ret = base(args)
|
|
|
|
ret:connect_signal("clear::menu",function(_,vis)
|
2013-07-23 08:12:19 +02:00
|
|
|
local l = ret._internal.content_layout or ret._internal.layout
|
|
|
|
l:reset()
|
2013-07-21 10:15:56 +02:00
|
|
|
end)
|
|
|
|
ret:connect_signal("_hidden::changed",function(_,item)
|
|
|
|
item.widget:emit_signal("widget::updated")
|
|
|
|
end)
|
|
|
|
return ret
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(module, { __call = function(_, ...) return new(...) end })
|
|
|
|
-- kate: space-indent on; indent-width 2; replace-tabs on;
|