Hello everybody, I did some enhancements over the previous patchset. This now grew into 5 patches :p. Every patch is based on current git/master, so it should apply well. They have lengthy commit messages, which should explain everything.
Hope it is good now. Cheers, Ignas A.
>From d7039f909a3e385c9ef70daafa2cec39d2976947 Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Fri, 4 May 2012 23:06:53 +0100 Subject: [PATCH 1/5] Menubar: Cleanup the environment grabbing All of the capi should be in a capi table. This make the code more consistent. Also, it is not worth importing awful.prompt as a different variable as it is used only once. Calling it awful.prompt make the code clearer as there are other variables called prompt. Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 27 +++++++++++++++------------ 1 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 32c4218..43647bc 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -5,22 +5,25 @@ --------------------------------------------------------------------------- -- Grab environment we need -local capi = { client = client, - screen = screen } -local setmetatable = setmetatable +local capi = { + client = client, + mouse = mouse, + screen = screen +} +local awful = require("awful") +local common = require("awful.widget.common") +local theme = require("beautiful") +local menu_gen = require("menubar.menu_gen") +local wibox = require("wibox") + +-- Standard lua local pairs = pairs local ipairs = ipairs local table = table -local theme = require("beautiful") -local menu_gen = require("menubar.menu_gen") -local prompt = require("awful.prompt") -local awful = require("awful") -local common = require("awful.widget.common") local tonumber = tonumber local string = string -local mouse = mouse local math = math -local wibox = require("wibox") +local setmetatable = setmetatable module("menubar") @@ -226,7 +229,7 @@ function show(scr) end -- Set position and size - scr = scr or mouse.screen or 1 + scr = scr or capi.mouse.screen or 1 local scrgeom = capi.screen[scr].workarea instance.wibox:geometry({x = geometry.x or scrgeom.x, y = geometry.y or scrgeom.y, @@ -236,7 +239,7 @@ function show(scr) current_item = 1 current_category = nil menulist_update() - prompt.run({ prompt = "Run app: " }, instance.prompt.widget, function(s) end, + awful.prompt.run({ prompt = "Run app: " }, instance.prompt.widget, function(s) end, nil, awful.util.getdir("cache") .. "/history_menu", nil, hide, menulist_update, prompt_keypressed_callback) -- 1.7.8.5
>From 44846b9ccf888460c4adc4cdc5253590076564a7 Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Fri, 4 May 2012 22:51:09 +0100 Subject: [PATCH 2/5] Menubar: Match for command names as well. Enabling matching the command name of the menubar entries with the query, which improves the flexibility of the widget. The functionality works as follows: You want to run GIMP, which has a name of "GNU Image Manipulation Program". Previously by typing in gimp one would have <no matches>, but now it will match GIMP entry. Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 43647bc..3e96c30 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -136,12 +136,14 @@ local function menulist_update(query) end end - -- Add the applications + -- Add the applications according to their name and cmdline for i, v in ipairs(menu_entries) do v.focused = false if not current_category or v.category == current_category then - if string.match(v.name, nocase(query)) then - if string.match(v.name, "^" .. nocase(query)) then + if string.match(v.name, nocase(query)) + or string.match(v.cmdline, nocase(query)) then + if string.match(v.name, "^" .. nocase(query)) + or string.match(v.cmdline, "^" .. nocase(query)) then table.insert(shownitems, v) else table.insert(match_inside, v) -- 1.7.8.5
>From e0c0371373a6947c4da085b0211dd2885c527679 Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Fri, 4 May 2012 23:07:51 +0100 Subject: [PATCH 3/5] Menubar: 'Run query: ' item addition. This adds a 'Run query: ' item to the end of the list, which makes it always non-empty. This is useful, when the program is not in the list of menubar entries (e.g. it does not have a .desktop file). Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 3e96c30..09e1922 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -93,9 +93,6 @@ end -- @param o The menu item. -- @return if the function processed the callback, new awful.prompt command, new awful.prompt prompt text. local function perform_action(o) - if not o or o.empty then - return true - end if o.key then current_category = o.key local new_prompt = shownitems[current_item].name .. ": " @@ -157,15 +154,13 @@ local function menulist_update(query) table.insert(shownitems, v) end - if #shownitems > 0 then - if current_item > #shownitems then - current_item = #shownitems - end - shownitems[current_item].focused = true - else - table.insert(shownitems, { name = "<no matches>", icon = nil, - empty = true }) + -- Insert a run item value as the last choice + table.insert(shownitems, { name = "Run query: " .. query, cmdline = query, icon = nil }) + + if current_item > #shownitems then + current_item = #shownitems end + shownitems[current_item].focused = true common.list_update(common_args.w, nil, label, common_args.data, -- 1.7.8.5
>From 1ee47920dd69cc2e7e31193f0e64a24f518d2a17 Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Fri, 4 May 2012 23:08:45 +0100 Subject: [PATCH 4/5] Menubar: Add navigation and execution keybindings. This adds more navigation keybindings ('Home' and 'End'), which select the first and the last entry from the list respectively. Also, it adds two more keybindings: 'Ctrl+Enter' - Run the query (no need to press End and then Enter) 'Ctrl+Alt+Enter' - Run query in the terminal (sometimes there are terminal applications which one wants to run, e.g. ncmpcpp) Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 15 +++++++++++++++ 1 files changed, 15 insertions(+), 0 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 09e1922..2d8d742 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -14,6 +14,7 @@ local awful = require("awful") local common = require("awful.widget.common") local theme = require("beautiful") local menu_gen = require("menubar.menu_gen") +local menu_utils = require("menubar.utils") local wibox = require("wibox") -- Standard lua @@ -208,7 +209,21 @@ local function prompt_keypressed_callback(mod, key, comm) current_item = previous_item return true, nil, "Run app: " end + elseif key == "Home" then + current_item = 1 + return true + elseif key == "End" then + current_item = #shownitems + return true elseif key == "Return" then + if mod.Control then + current_item = #shownitems + if mod.Mod1 then + -- add a terminal to the cmdline + shownitems[current_item].cmdline = menu_utils.terminal + .. " -e " .. shownitems[current_item].cmdline + end + end return perform_action(shownitems[current_item]) end return false -- 1.7.8.5
>From 25f28aae3b202e22d43bd5795f24aee1f254997a Mon Sep 17 00:00:00 2001 From: "Ignas Anikevicius (gns_ank)" <[email protected]> Date: Fri, 4 May 2012 23:09:03 +0100 Subject: [PATCH 5/5] Menubar: Add shell completion to menubar Since we can search for commands in menubar and easily execute almost any program now, we can definitely make use of awful.shell.completion, which is enabled with this commit. Signed-off-by: Ignas Anikevicius (gns_ank) <[email protected]> --- lib/menubar/init.lua.in | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/menubar/init.lua.in b/lib/menubar/init.lua.in index 2d8d742..67d2030 100644 --- a/lib/menubar/init.lua.in +++ b/lib/menubar/init.lua.in @@ -251,10 +251,12 @@ function show(scr) current_item = 1 current_category = nil menulist_update() - awful.prompt.run({ prompt = "Run app: " }, instance.prompt.widget, function(s) end, - nil, awful.util.getdir("cache") .. "/history_menu", nil, hide, - menulist_update, - prompt_keypressed_callback) + awful.prompt.run({ prompt = ": " }, instance.prompt.widget, + function(s) end, -- exe_callback function set to do nothing + awful.completion.shell, -- completion_callback + awful.util.getdir("cache") .. "/history_menu", + nil, hide, menulist_update, prompt_keypressed_callback + ) instance.wibox.visible = true end -- 1.7.8.5
