1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
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.widget.background(tb, bg)
tb:set_font(font)
client:connect_signal("property::name", function() tb:set_text(client.name) 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.layout.margin(client_container)
margin:set_top(border_width)
margin:set_bottom(border_width)
ret.widget = wibox.layout.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)
init_data = self.init_data
print("pager " .. init_data.screen .. " set desktop")
self:reset()
self.init_data = init_data
self.set_desktop = pager_set_desktop
self.active_page = nil
self.pages = {}
self.desktop = desktop
local nb_pages = #self.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.widget.background(title, title_bg)
title_container:set_fg(title_fg)
self.desktop:connect_signal("desktop:name",
function(desktop, name)
title:set_text(name)
end)
self:add(title_container)
for i = 1, nb_pages do
local page = self.desktop.pages[i]
self.pages[i] = Page:new(page, i, self.init_data.width, page_height, self)
self:add(self.pages[i].widget)
end
self.desktop:connect_signal("page:view",
function(desktop, s, page_idx)
pager_set_active(self, s, page_idx) end)
end
local Pager = {}
function Pager:new(screen, width, height)
local pager = wibox.layout.fixed.vertical()
pager.init_data = { screen = screen, width = width, height = height }
pager.set_desktop = pager_set_desktop
return pager
end
M.Pager = Pager
return M
|