From 38185b161a16552ba3fe683b429c10e0e620e72b Mon Sep 17 00:00:00 2001 From: Emmanuel Lepage Vallee Date: Sun, 15 May 2016 03:50:39 -0400 Subject: [PATCH] wibar: Add a remove function --- lib/awful/wibar.lua | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/awful/wibar.lua b/lib/awful/wibar.lua index 91b2bb5f..45602011 100644 --- a/lib/awful/wibar.lua +++ b/lib/awful/wibar.lua @@ -6,7 +6,7 @@ -- @author Emmanuel Lepage Vallee <elv1313@gmail.com> -- @copyright 2016 Emmanuel Lepage Vallee -- @release @AWESOME_VERSION@ --- @module awful.wibar +-- @classmod awful.wibar --------------------------------------------------------------------------- -- Grab environment we need @@ -165,6 +165,25 @@ local function set_stretch(w, value) attach(w, w.position) end +--- Remove a wibar. +-- @function remove +local function remove(self) + self.visible = false + + if self.detach_callback then + self.detach_callback() + self.detach_callback = nil + end + + for k, w in ipairs(wiboxes) do + if w == self then + table.remove(wiboxes, k) + end + end + + self._screen = nil +end + --- Get a wibox position if it has been set, or return top. -- @param wb The wibox -- @deprecated awful.wibar.get_position @@ -291,6 +310,7 @@ function awfulwibar.new(arg) local w = wibox(arg) w.screen = screen + w._screen = screen --HACK When a screen is removed, then getbycoords wont work w._stretch = arg.stretch == nil and has_to_stretch or arg.stretch w:add_signal("property::position") @@ -300,6 +320,7 @@ function awfulwibar.new(arg) w:add_signal("property::stretch") w.get_stretch = get_stretch w.set_stretch = set_stretch + w.remove = remove w.visible = true @@ -314,12 +335,8 @@ end capi.screen.connect_signal("removed", function(s) for _, wibar in ipairs(wiboxes) do - if wibar.screen == s then - if wibar.detach_callback then - wibar.detach_callback() - end - - wibar.visible = false + if wibar._screen == s then + wibar:remove() end end end)