From ec5ec642c37f39da6caa1958c23ddf353e356c10 Mon Sep 17 00:00:00 2001 From: Ari Breitkreuz Date: Tue, 21 Apr 2020 17:44:23 +0200 Subject: [PATCH 1/3] Add match_empty option to menubar --- lib/menubar/init.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 34877d45..7f350dd9 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -90,6 +90,10 @@ menubar.cache_entries = true -- @tfield[opt=true] boolean show_categories menubar.show_categories = true +--- When false will hide results if the current query is empty +-- @tfield[opt=true] boolean match_empty +menubar.match_empty = true + --- Specifies the geometry of the menubar. This is a table with the keys -- x, y, width and height. Missing values are replaced via the screen's -- geometry. However, missing height is replaced by the font size. @@ -310,7 +314,7 @@ local function menulist_update(scr) end -- Add the applications according to their name and cmdline - for _, v in ipairs(menubar.menu_entries) do + local add_entry = function(v) v.focused = false if not current_category or v.category == current_category then @@ -342,6 +346,14 @@ local function menulist_update(scr) end end + -- Add entries if required + if query ~= "" or menubar.match_empty then + for _, v in ipairs(menubar.menu_entries) do + add_entry(v) + end + end + + local function compare_counts(a, b) if a.prio == b.prio then return a.weight > b.weight From 30911a3959c8f173b1a374c64ac6f3cde9b3d672 Mon Sep 17 00:00:00 2001 From: Ari Breitkreuz Date: Tue, 21 Apr 2020 17:47:41 +0200 Subject: [PATCH 2/3] Rename v to entry in add_entry loop --- lib/menubar/init.lua | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 7f350dd9..18382ac4 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -314,34 +314,34 @@ local function menulist_update(scr) end -- Add the applications according to their name and cmdline - local add_entry = function(v) - v.focused = false - if not current_category or v.category == current_category then + local add_entry = function(entry) + entry.focused = false + if not current_category or entry.category == current_category then -- check if the query matches either the name or the commandline -- of some entry - if string.match(v.name, pattern) - or string.match(v.cmdline, pattern) then + if string.match(entry.name, pattern) + or string.match(entry.cmdline, pattern) then - v.weight = 0 - v.prio = PRIO_NONE + entry.weight = 0 + entry.prio = PRIO_NONE -- get use count from count_table if present -- and use it as weight - if string.len(pattern) > 0 and count_table[v.name] ~= nil then - v.weight = tonumber(count_table[v.name]) + if string.len(pattern) > 0 and count_table[entry.name] ~= nil then + entry.weight = tonumber(count_table[entry.name]) end -- check for prefix match - if string.match(v.name, "^" .. pattern) - or string.match(v.cmdline, "^" .. pattern) then + if string.match(entry.name, "^" .. pattern) + or string.match(entry.cmdline, "^" .. pattern) then -- increase default priority - v.prio = PRIO_NONE + 1 + entry.prio = PRIO_NONE + 1 else - v.prio = PRIO_NONE + entry.prio = PRIO_NONE end - table.insert (command_list, v) + table.insert (command_list, entry) end end end From 2e6c911821617778a6a3114d46c78925c7bcf6c6 Mon Sep 17 00:00:00 2001 From: Ari Breitkreuz Date: Fri, 24 Apr 2020 14:48:17 +0200 Subject: [PATCH 3/3] Add test for menubar.match_empty --- tests/test-menubar.lua | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tests/test-menubar.lua b/tests/test-menubar.lua index 0eb5d43e..8e64418b 100644 --- a/tests/test-menubar.lua +++ b/tests/test-menubar.lua @@ -37,22 +37,33 @@ do end end +local show_menubar_and_hide = function(count) + -- Just show the menubar and hide it. + -- TODO: Write a proper test. But for the mean time this is better than + -- nothing (and tells us when errors are thrown). + + if count == 1 then + menubar.show() + end + + -- Test that the async population of the menubar is done + if menubar_refreshed then + menubar.hide() + awesome.sync() + return true + end +end + runner.run_steps { function(count) - -- Just show the menubar and hide it. - -- TODO: Write a proper test. But for the mean time this is better than - -- nothing (and tells us when errors are thrown). + -- Show and hide with defaults + return show_menubar_and_hide(count) + end, - if count == 1 then - menubar.show() - end - - -- Test that the async population of the menubar is done - if menubar_refreshed then - menubar.hide() - awesome.sync() - return true - end + function(count) + -- Show and hide with match_empty set to false + menubar.match_empty = false + return show_menubar_and_hide(count) end, function()