From 87070cadac7adc42eea6b80d6932061eb4f972a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Schr=C3=B6der?= Date: Thu, 26 Nov 2009 12:47:39 +0100 Subject: [PATCH] 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 --- lib/awful/menu.lua.in | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/awful/menu.lua.in b/lib/awful/menu.lua.in index a13bd5ee..82657a22 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 ""..l.."" + 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.