From 98aea7c88bd0b2042bd520b270314b06c1d4adc1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 10 Jun 2021 19:06:09 +0200 Subject: pager: scale vertically with available space --- pager.lua | 33 ++++++++++++++++----------------- rc.lua | 2 +- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/pager.lua b/pager.lua index cb1eddb..be5a15a 100644 --- a/pager.lua +++ b/pager.lua @@ -102,7 +102,7 @@ function Page:client_add(c) self._widgets[c] = bg end -function Page:new(tag, width, height, screen) +function Page:new(tag, screen) local ret = setmetatable({}, self) self.__index = self @@ -113,8 +113,6 @@ function Page:new(tag, width, height, screen) margin:set_top(border_width) margin:set_bottom(border_width) - ret.widget = wibox.container.constraint(margin, 'exact', width, height) - ret.client_container = client_container ret.border = margin ret.tag = tag @@ -122,6 +120,9 @@ function Page:new(tag, width, height, screen) -- a table of mapping clients to their widgets ret._widgets = {} + -- top-level widget containing the page + ret.widget = margin + ret:set_visible(tag.selected, tag.screen == screen) -- add initial clients @@ -137,7 +138,7 @@ end local PagerDesk = {} -function PagerDesk:new(desktop, screen, width, height) +function PagerDesk:new(desktop, screen) local ret = setmetatable({}, self) self.__index = self @@ -165,18 +166,17 @@ function PagerDesk:new(desktop, screen, width, height) local title_container = wibox.container.background(title_bar, title_normal_bg) title_container:set_fg(title_normal_fg) - ret.widget = wibox.layout.fixed.vertical(title_container) - - local nb_pages = #desktop.pages - local page_height = height / nb_pages + local pages_container = wibox.layout.flex.vertical() ret.pages = {} - for i = 1, nb_pages do - local page = desktop.pages[i] - ret.pages[i] = Page:new(page, width, page_height, screen) - ret.widget:add(ret.pages[i].widget) + for i = 1, #desktop.pages do + ret.pages[i] = Page:new(desktop.pages[i], screen) + pages_container:add(ret.pages[i].widget) end + -- top-level widget containing the desktop + ret.widget = wibox.layout.align.vertical(title_container, pages_container) + desktop:connect_signal("page:view", function(desktop, s, page_idx) if s == ret.screen then @@ -210,24 +210,23 @@ local Pager = {} function Pager:set_desktop(desktop) if self._desktops[desktop] == nil then - self._desktops[desktop] = PagerDesk:new(desktop, self.screen, - self.width, self.height) + self._desktops[desktop] = PagerDesk:new(desktop, self.screen) end self.widget:set_widget(self._desktops[desktop].widget) end -function Pager:new(screen, width, height) +function Pager:new(screen) local ret = setmetatable({}, self) self.__index = self + -- this is merely a placeholder for switching between + -- PagerDesk widgets ret.widget = wibox.container.constraint() ret._desktops = {} ret.screen = screen - ret.width = width - ret.height = height return ret end diff --git a/rc.lua b/rc.lua index a36ce88..c71df5d 100644 --- a/rc.lua +++ b/rc.lua @@ -88,7 +88,7 @@ for s in screen do awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end))) -- Create a tasklist widget - local pgr = pager.Pager:new(s, 128, 800) + local pgr = pager.Pager:new(s) pgr:set_desktop(wsp.desktops[s.index]) wsp.signals:connect_signal("desktop:view", -- cgit v1.2.3