From 221294bf2659f6bf72ce34f0e73772dd174ea1bb Mon Sep 17 00:00:00 2001 From: Bart Trojanowski Date: Sat, 15 Sep 2007 13:51:51 -0400 Subject: [PATCH] record widgets in a table, remove from /rbar entries that we don't have widget objects for --- core/wmii.lua | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/core/wmii.lua b/core/wmii.lua index 27e200b..422d592 100644 --- a/core/wmii.lua +++ b/core/wmii.lua @@ -910,6 +910,10 @@ function run_event_loop () update_displayed_tags () + log("wmii: updating rbar") + + update_displayed_widgets () + log("wmii: updating active keys") update_active_keys () @@ -928,6 +932,7 @@ end -- ------------------------------------------------------------------------ -- widget template widget = {} +widgets = {} -- ------------------------------------------------------------------------ -- create a widget object and add it to the wmii /rbar @@ -951,6 +956,8 @@ function widget:new (name, fn) self.__index = self self.__gc = function (o) o:hide() end + widgets[name] = o + o:show() return o end @@ -958,8 +965,8 @@ end -- ------------------------------------------------------------------------ -- stop and destroy the timer function widget:delete () + widgets[self.name] = nil self:hide() - -- TBD end -- ------------------------------------------------------------------------ @@ -985,6 +992,33 @@ function widget:hide () end -- ------------------------------------------------------------------------ +-- remove all /rbar entries that we don't have widget objects for +function update_displayed_widgets () + -- colours for /rbar + local nc = get_ctl("normcolors") or "" + + -- build up a table of existing tags in the /lbar + local old = {} + local s + for s in wmixp:idir ("/rbar") do + old[s.name] = 1 + end + + -- for all actual widgets in use we want to remove them from the old list + local i,v + for i,v in pairs(widgets) do + old[v.name] = nil + end + + -- anything left in the old table should be removed now + for i,v in pairs(old) do + if v then + remove("/rbar/"..i) + end + end +end + +-- ------------------------------------------------------------------------ -- create a new program and for each line it generates call the callback function -- returns fd which can be passed to kill_exec() function add_exec (command, callback) -- 2.11.4.GIT