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
150
151
152
153
|
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 Pager = {}
function Pager:_set_active(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
function Pager:set_desktop(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)
self:_set_active(s, page_idx) end)
self._desktop = desktop
end
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 }
return ret
end
M.Pager = Pager
return M
|