summaryrefslogtreecommitdiff
path: root/pager.lua
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2021-02-25 16:40:20 +0100
committerAnton Khirnov <anton@khirnov.net>2021-02-25 16:40:20 +0100
commit00f1513a1c11bab7e4ac194628fb33b522fe2176 (patch)
treeb8d6b15991a07e97b062bd21a65781f2251aea29 /pager.lua
parent5e3f329292a187da34110393226bcb0e0ddf0001 (diff)
pager: granular page modification
Do not rebuild the entire page each time the client list changes, add/remove clients individually.
Diffstat (limited to 'pager.lua')
-rw-r--r--pager.lua87
1 files changed, 50 insertions, 37 deletions
diff --git a/pager.lua b/pager.lua
index 985122d..f4d3054 100644
--- a/pager.lua
+++ b/pager.lua
@@ -20,41 +20,48 @@ function Page:set_visible(visible, this_screen)
self.border:set_color(border_color)
end
-function Page:update()
+function Page:client_remove(client)
+ wgt = self._widgets[client]
+ if wgt then
+ self.client_container:remove_widgets(wgt)
+ end
+
+ self._widgets[client] = nil
+end
+
+function Page:client_add(client)
local font = beautiful.small_text_font or "sans 7"
- self.client_container:reset()
- for i, client in pairs(self.tag:clients()) do
- local text = client.name
-
- local bg_normal = beautiful.bg_normal or "#000000"
- local fg_normal = beautiful.fg_normal or "#ffffff"
- local bg_focus = beautiful.bg_focus or "#ffffff"
- local fg_focus = beautiful.fg_focus or "#000000"
-
- local tb = wibox.widget.textbox(text, true)
- local bg = wibox.container.background(tb, bg)
-
- tb:set_font(font)
-
- client:connect_signal("property::name", function() tb:set_text(client.name or "") end)
- client:connect_signal("focus",
- function(c)
- if c.screen == self.screen then
- bg:set_bg(bg_focus)
- bg:set_fg(fg_focus)
- end
- end)
- client:connect_signal("unfocus",
- function(c)
- if c.screen == self.screen then
- bg:set_bg(bg_normal)
- bg:set_fg(fg_normal)
- end
- end)
-
- self.client_container:add(bg)
- end
+ local text = client.name
+
+ local bg_normal = beautiful.bg_normal or "#000000"
+ local fg_normal = beautiful.fg_normal or "#ffffff"
+ local bg_focus = beautiful.bg_focus or "#ffffff"
+ local fg_focus = beautiful.fg_focus or "#000000"
+
+ local tb = wibox.widget.textbox(text, true)
+ local bg = wibox.container.background(tb, bg)
+
+ tb:set_font(font)
+
+ client:connect_signal("property::name", function() tb:set_text(client.name or "") end)
+ client:connect_signal("focus",
+ function(c)
+ if c.screen == self.screen then
+ bg:set_bg(bg_focus)
+ bg:set_fg(fg_focus)
+ end
+ end)
+ client:connect_signal("unfocus",
+ function(c)
+ if c.screen == self.screen then
+ bg:set_bg(bg_normal)
+ bg:set_fg(fg_normal)
+ end
+ end)
+
+ self.client_container:add(bg)
+ self._widgets[client] = bg
end
function Page:new(tag, width, height, screen)
@@ -74,12 +81,18 @@ function Page:new(tag, width, height, screen)
ret.border = margin
ret.tag = tag
ret.screen = screen
+ -- a table of mapping clients to their widgets
+ ret._widgets = {}
- tag:connect_signal('tagged', function (c) ret:update() end)
- tag:connect_signal('untagged', function (c) ret:update() end)
+ ret:set_visible(tag.selected, tag.screen == screen)
+
+ -- add initial clients
+ for i, client in pairs(tag:clients()) do
+ ret:client_add(client)
+ end
- ret:set_visible(false, false)
- ret:update()
+ tag:connect_signal('tagged', function (t, c) ret:client_add(c) end)
+ tag:connect_signal('untagged', function (t, c) ret:client_remove(c) end)
return ret
end