Hi,
i made some small changes to awful/menu.lua. Menus should be easier to
use with the keyboard this way.
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.
I hope someone likes it
Matthias
diff --git a/lib/awful/menu.lua.in b/lib/awful/menu.lua.in
index a13bd5e..5284d73 100644
--- a/lib/awful/menu.lua.in
+++ b/lib/awful/menu.lua.in
@@ -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.