Add 'add_key_binding' method (fix issue #5)

This commit is contained in:
Emmanuel Lepage Vallee 2014-01-14 23:19:49 -05:00
parent 27a5970277
commit c3d38932f4
2 changed files with 18 additions and 2 deletions

View File

@ -44,6 +44,9 @@ The most simple kind of menus, contexts one, can be created like this:
-- To add the menu to a widget:
local mytextbox = wibox.widget.textbox()
mytextbox:set_menu(menu,3) -- 3 = right mouse button, 1 = left mouse button
-- To add a key binding on a "box" menu (and every other types)
menu:add_key_binding({"Mod4"},",")
```
In this example, a simple 3 item menu is created with a dynamically generated
@ -54,6 +57,10 @@ them once and passing the submenu object to the "sub_menu" item property.
`:set_menu` can also take a lazy-loading function instead of a
menu. The second parameter is not mandatory, the default is `1`.
`:add_key_binding` will add a key binding. It can also take a function as 3rd
parameter. However, it wont correctly place "context" menu as it have no idea
where you expect them. It work better with "box" menus.
### Menu types
The current valid types are:

View File

@ -4,9 +4,10 @@ local type,string = type,string
local print,unpack = print, unpack
local beautiful = require( "beautiful" )
local util = require( "awful.util" )
local aw_key = require( "awful.key" )
local object = require( "radical.object" )
local capi = { mouse = mouse, screen = screen , keygrabber = keygrabber }
local capi = { mouse = mouse, screen = screen , keygrabber = keygrabber, root=root, }
local module = {
arrow_type = {
@ -250,6 +251,14 @@ local function add_embeded_menu(data,menu)
menu._embeded_parent = data
end
local function add_key_binding(data,mod,key,func)
print("\n\n\nCAT",mod,key,func)
capi.root.keys(util.table.join(capi.root.keys(),aw_key(mod or {}, key, func and func() or function ()
print("bob")
data.visible = not data.visible
end)))
end
---------------------------------MENU HANDLING----------------------------------
local function new(args)
@ -326,7 +335,7 @@ local function new(args)
autogen_signals = true,
})
internal.get_map,internal.set_map,internal.private_data = get_map,set_map,private_data
data.add_item,data.add_widget,data.add_embeded_menu,data._internal = add_item,add_widget,add_embeded_menu,internal
data.add_item,data.add_widget,data.add_embeded_menu,data._internal,data.add_key_binding = add_item,add_widget,add_embeded_menu,internal,add_key_binding
set_map.parent_geometry = function(value)
private_data.parent_geometry = value
if data._internal.get_direction then