awful.menu: support for access keys
You can define a menuitem like before: awful.menu({ items = { { "&awesome", myawesomemenu, beautiful.awesome_icon }, { "open &terminal", terminal }, }) and the letters following the ampersand in itemname can be used as access key. (at least former fvwm users might find this familiar) When there are submenus open awesome ascends during the search from the current menu to the top level menu. The access key is shown underlined. There is no warning for multiple used keys, only the first one found gets the price. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
4299c5b184
commit
b38569913c
|
@ -8,6 +8,7 @@
|
|||
-- Grab environment we need
|
||||
local pairs = pairs
|
||||
local table = table
|
||||
local string = string
|
||||
local type = type
|
||||
local setmetatable = setmetatable
|
||||
local wibox = wibox
|
||||
|
@ -153,6 +154,18 @@ local function item_enter(menu, num, mouse_event)
|
|||
end
|
||||
end
|
||||
|
||||
local function check_access_key(menu, key)
|
||||
for i, item in pairs(menu.items) do
|
||||
if item.akey == key then
|
||||
exec(menu, i)
|
||||
return
|
||||
end
|
||||
end
|
||||
if menu.parent then
|
||||
check_access_key(menu.parent, key)
|
||||
end
|
||||
end
|
||||
|
||||
local function grabber(mod, key, event)
|
||||
if event == "release" then
|
||||
return true
|
||||
|
@ -171,6 +184,8 @@ local function grabber(mod, key, event)
|
|||
cur_menu:hide()
|
||||
elseif util.table.hasitem(menu_keys.close, key) then
|
||||
get_parents(cur_menu):hide()
|
||||
else
|
||||
check_access_key(cur_menu, key)
|
||||
end
|
||||
|
||||
return true
|
||||
|
@ -192,7 +207,11 @@ local function add_item(data, num, item_info)
|
|||
|
||||
-- Create the item label widget
|
||||
local label = widget({ type = "textbox" })
|
||||
label.text = item_info[1]
|
||||
local key = ''
|
||||
label.text = string.gsub(item_info[1], "&(%w)", function (l)
|
||||
key= string.lower(l)
|
||||
return "<u>"..l.."</u>"
|
||||
end, 1)
|
||||
-- Set icon if needed
|
||||
local iconbox
|
||||
if item_info[3] then
|
||||
|
@ -245,7 +264,7 @@ local function add_item(data, num, item_info)
|
|||
item.height = label:extents().height + 2
|
||||
item.ontop = true
|
||||
|
||||
return { wibox = item, cmd = item_info[2] }
|
||||
return { wibox = item, akey= key, cmd = item_info[2] }
|
||||
end
|
||||
|
||||
--- Build a popup menu with running clients and shows it.
|
||||
|
|
Loading…
Reference in New Issue