local M = {} local awful = require("awful") local beautiful = require("beautiful") local wibox = require("wibox") local Page = {} function Page:set_active(active) local border_color = nil if active then border_color = beautiful.border_focus or '#ffffff' else border_color = beautiful.border_normal or '#000000' end self.border:set_color(border_color) end function Page:update() 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.pager.init_data.screen then bg:set_bg(bg_focus) bg:set_fg(fg_focus) end end) client:connect_signal("unfocus", function(c) if c.screen == self.pager.init_data.screen then bg:set_bg(bg_normal) bg:set_fg(fg_normal) end end) self.client_container:add(bg) end end function Page:new(tag, index, width, height, pager) local ret = setmetatable({}, self) self.__index = self local client_container = wibox.layout.flex.vertical() local border_width = beautiful.border_width or 1 local margin = wibox.container.margin(client_container) 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 ret.pager = pager tag:connect_signal('tagged', function (c) ret:update() end) tag:connect_signal('untagged', function (c) ret:update() end) ret:set_active(false) ret:update() return ret end local function pager_set_active(self, screen, page_idx) if self.init_data.screen == screen then if self.active_page then self.active_page:set_active(false) end self.pages[page_idx]:set_active(true) self.active_page = self.pages[page_idx] end end local function pager_set_desktop(self, desktop) if self._desktop == desktop then print('same desktop') return end local init_data = self.init_data print("pager " .. init_data.screen.index .. " set desktop") self.widget:reset() self.active_page = nil self.pages = {} local nb_pages = #desktop.pages local page_height = self.init_data.height / nb_pages local title = wibox.widget.textbox(desktop.name, false) title:set_align("center") local title_bg = beautiful.bg_focus or "#ffffff" local title_fg = beautiful.fg_focus or "#000000" local title_container = wibox.container.background(title, title_bg) title_container:set_fg(title_fg) desktop:connect_signal("desktop:name", function(desktop, name) title:set_text(name) end) self.widget:add(title_container) for i = 1, nb_pages do local page = desktop.pages[i] self.pages[i] = Page:new(page, i, self.init_data.width, page_height, self) self.widget:add(self.pages[i].widget) end desktop:connect_signal("page:view", function(desktop, s, page_idx) pager_set_active(self, s, page_idx) end) self._desktop = desktop end local Pager = {} function Pager:new(screen, width, height) local ret = setmetatable({}, self) self.__index = self ret.widget = wibox.layout.fixed.vertical() ret.init_data = { screen = screen, width = width, height = height } ret.set_desktop = pager_set_desktop return ret end M.Pager = Pager return M