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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
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.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
end
function Page:new(tag, width, height, screen)
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.screen = screen
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 PagerDesk = {}
function PagerDesk:new(desktop, screen, width, height)
local ret = setmetatable({}, self)
self.__index = self
local title_desk = wibox.widget.textbox()
local function set_title(desktop)
title_desk:set_text(string.format("[%d] %s", desktop.idx, desktop.name))
end
desktop:connect_signal("desktop:name", set_title)
set_title(desktop)
local title_page = wibox.widget.textbox()
local title_bar = wibox.layout.ratio.horizontal()
title_bar:set_spacing(10)
title_bar:set_spacing_widget(wibox.widget.separator())
title_bar:add(title_desk, title_page)
title_bar:set_ratio(1, 0.75)
local title_bg = beautiful.bg_focus or "#ffffff"
local title_fg = beautiful.fg_focus or "#000000"
local title_container = wibox.container.background(title_bar, title_bg)
title_container:set_fg(title_fg)
ret.widget = wibox.layout.fixed.vertical(title_container)
local nb_pages = #desktop.pages
local page_height = height / nb_pages
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)
end
desktop:connect_signal("page:view",
function(desktop, s, page_idx)
if s == ret.screen then
ret:_set_active(page_idx)
title_page:set_text(string.format("%d", page_idx))
end
end)
ret.desktop = desktop
ret.screen = screen
ret.active_page_idx = nil
return ret
end
function PagerDesk:_set_active(page_idx)
if self.active_page_idx then
self.pages[self.active_page_idx]:set_active(false)
end
self.pages[page_idx]:set_active(true)
self.active_page_idx = page_idx
end
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)
end
self.widget:set_widget(self._desktops[desktop].widget)
end
function Pager:new(screen, width, height)
local ret = setmetatable({}, self)
self.__index = self
ret.widget = wibox.container.constraint()
ret._desktops = {}
ret.screen = screen
ret.width = width
ret.height = height
return ret
end
M.Pager = Pager
return M
|