From 68f0883a44f395297eb20ccc4eda3445d189ca30 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 2 Jan 2017 17:20:41 +0100 Subject: [PATCH 1/3] menubar: Refactor initialisation No functional changes intended. I just like things more like this. Signed-off-by: Uli Schlachter --- lib/menubar/init.lua | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 10ad65c2..fc9d204c 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -93,9 +93,7 @@ local current_item = 1 local previous_item = nil local current_category = nil local shownitems = nil -local instance = { prompt = nil, - widget = nil, - wibox = nil } +local instance = nil local common_args = { w = wibox.layout.fixed.horizontal(), data = setmetatable({}, { __mode = 'kv' }) } @@ -347,19 +345,6 @@ local function menulist_update(query, scr) get_current_page(shownitems, query, scr)) end ---- Create the menubar wibox and widgets. --- @tparam[opt] screen scr Screen. -local function initialize(scr) - instance.wibox = wibox({}) - instance.widget = menubar.get(scr) - instance.wibox.ontop = true - instance.prompt = awful.widget.prompt() - local layout = wibox.layout.fixed.horizontal() - layout:add(instance.prompt) - layout:add(instance.widget) - instance.wibox:set_widget(layout) -end - --- Refresh menubar's cache by reloading .desktop files. -- @tparam[opt] screen scr Screen. function menubar.refresh(scr) @@ -416,9 +401,19 @@ end --- Show the menubar on the given screen. -- @param scr Screen. function menubar.show(scr) - if not instance.wibox then - initialize(scr) - elseif instance.wibox.visible then -- Menu already shown, exit + if not instance then + instance = { + wibox = wibox({ ontop = true }), + widget = menubar.get(scr), + prompt = awful.widget.prompt(), + } + local layout = wibox.layout.fixed.horizontal() + layout:add(instance.prompt) + layout:add(instance.widget) + instance.wibox:set_widget(layout) + end + + if instance.wibox.visible then -- Menu already shown, exit return elseif not menubar.cache_entries then menubar.refresh(scr) From 7f3ff5f26faa74f721bea0e6bb577ce205a5652b Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 2 Jan 2017 17:21:10 +0100 Subject: [PATCH 2/3] menubar: Fix hide() When hide() was called without any calls to shown() before, an error would occur. Signed-off-by: Uli Schlachter --- lib/menubar/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index fc9d204c..77eee8c6 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -451,7 +451,9 @@ end --- Hide the menubar. function menubar.hide() - instance.wibox.visible = false + if instance then + instance.wibox.visible = false + end end --- Get a menubar wibox. From dadf8463bdf15e0cc2a3b01531b97278e3c5915a Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Mon, 2 Jan 2017 17:23:20 +0100 Subject: [PATCH 3/3] menubar: Fix refresh without show When menubar.refresh() is called, it tries to update the menubar widget. The call chain looks like this: menulist_update -> common.list_update -> get_current_page. get_current_page then tries to query information about the size of the menubar. Since there is not much point in this, just skip the whole callback in this case. Side note: What is the point of menubar.get()? It seems quite useless to me. Signed-off-by: Uli Schlachter --- lib/menubar/init.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/menubar/init.lua b/lib/menubar/init.lua index 77eee8c6..d081d7f2 100644 --- a/lib/menubar/init.lua +++ b/lib/menubar/init.lua @@ -350,7 +350,9 @@ end function menubar.refresh(scr) menubar.menu_gen.generate(function(entries) menubar.menu_entries = entries - menulist_update(nil, scr) + if instance then + menulist_update(nil, scr) + end end) end