-
Notifications
You must be signed in to change notification settings - Fork 0
/
panel.lua
340 lines (306 loc) · 9.79 KB
/
panel.lua
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
--! @file panel.lua
--
-- @brief Quick hack to get panels on awesomewm.
--
-- @author Perry Hargrave
-- @date 2011-09-28
--
local pairs = pairs
local setmetatable = setmetatable
local awful = require('awful')
local tag = require('awful.tag')
local capi = {
client = client,
mouse = mouse,
widget = widget,
image = image,
-- timer = timer
}
local beautiful = require('beautiful')
local obvious = require("obvious")
local menu = require('menu')
local battery2 = require('battery2')
module('panel')
local panels = {}
local id = {}
function id:new(t)
local n = #id + 1
id[n] = t or {}
id[n].id = n
return #id
end
setmetatable(id,
{
__call = function(t, ...) return id:new(...) end
})
clock = {}
function clock:new(s, args)
local args = args or {}
ck = awful.widget.textclock({align = args.align or 'right'}, " 🕒 %d %b %H:%M")
-- utc_offset = function(tz)
-- local f = io.popen('LANG=C TZ='..tz..' date +"%z"')
-- local l = f:read("*a")
-- f:close()
-- return trim(l)
-- end, --utc_offset
tooltip = awful.tooltip({
objects = { ck },
timer_function = function()
local now = os.time()
local utcdate = os.date("!*t", now)
local mtv_t = os.time(utcdate) - (8*3600)
local ny_t = os.time(utcdate) - (5*3600)
local timez = os.date("MTV (PDT): %d %b %Y, %I:%M%P\n", mtv_t)
.. os.date("New York (EST): %d %b %Y, %I:%M%P\n", ny_t)
return timez
end,
})
id(ck)
return ck
end
setmetatable(clock,
{
__call = function(t, ...) return clock:new(...) end
})
layoutinfo = {}
function layoutinfo:new(s, args)
local screen = s or 1
local args = args or {}
args.type = "textbox"
local w = capi.widget(args)
local function layout_name(scr)
local pretty_names = {}
pretty_names.tile = "[tile]"
pretty_names.tileleft = "[l-tl]"
pretty_names.tilebottom = "[b-tl]"
pretty_names.tiletop = "[t-tl]"
pretty_names.fairv = "[vair]"
pretty_names.fairh = "[hair]"
pretty_names.spiral = "[spir]"
pretty_names.dwindle = "[dwin]"
pretty_names.max = "[maxx]"
pretty_names.fullscreen = "[Full]"
pretty_names.magnifier = "[Magn]"
pretty_names.floating = "[flt*]"
pretty_names.mylayout = "[*my*]"
pretty_names.cascadebrowse = "[cscb]"
pretty_names.centerwork = "[cntr]"
pretty_names.termfair = "[term]"
local l = awful.layout.getname(awful.layout.get(scr))
return pretty_names[l] or l
end
w.text = layout_name(1)
local function update_on_tag_selection(tag)
w.text = layout_name(tag.screen)
end
tag.attached_add_signal(screen, "property::selected", update_on_tag_selection)
tag.attached_add_signal(screen, "property::layout", update_on_tag_selection)
id(w)
return w
end
setmetatable(layoutinfo,
{
__call = function(t, ...) return layoutinfo:new(...) end
})
layoutbox = {}
function layoutbox:new(s, args)
local args = args or {}
-- Make closures for the different directions
local lf = function(i)
return function() awful.layout.inc(args.layouts, i) end
end
local buttons = awful.util.table.join(awful.button({}, 1, lf(1)),
awful.button({}, 3, lf(-1)),
awful.button({}, 4, lf(1)),
awful.button({}, 5, lf(-1)))
local lbox = awful.widget.layoutbox(s)
lbox:buttons(buttons)
id(lbox)
return lbox
end
setmetatable(layoutbox,
{
__call = function(t, ...) return layoutbox:new(...) end
})
taglist = {}
function taglist:new(s, args)
local mk = args.modkey or 'Mod4'
local buttons = awful.util.table.join(
awful.button({}, 1, awful.tag.viewonly),
awful.button({mk}, 1, awful.client.movetotag),
awful.button({}, 3, awful.tag.viewtoggle),
awful.button({mk}, 3, function(t) menu.create.tags(nil, t) end),
awful.button({"Shift"}, 1, awful.client.toggletag),
awful.button({}, 4, awful.tag.viewnext),
awful.button({}, 5, awful.tag.viewprev)
)
buttons = args.buttons or buttons
local tl = awful.widget.taglist(s,
function (t, args)
if not args then args = {} end
args.bg_occupied = "#000000"
return awful.widget.taglist.label.all(t, args)
end,
buttons)
taglist[s] = tl
id(tl)
return tl
end
setmetatable(taglist,
{
__call = function(t, ...) return taglist:new(...) end
})
prompt = {}
function prompt:new(s, args)
local args = args or {}
local layout = args.layout or awful.widget.layout.horizontal.leftright
local p = awful.widget.prompt({layout = layout})
id(p)
prompt[s] = p
return p
end
function prompt:get(s)
return prompt[s or capi.mouse.screen]
end
setmetatable(prompt,
{
__call = function(t, ...) return prompt:new(...) end
})
tasklist = {}
function tasklist:new(s, args)
local buttons = awful.util.table.join(
awful.button({},
1,
function (c)
if c == capi.client.focus then
c.minimized = true
else
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
-- This will also un-minimize
-- the client, if needed
capi.client.focus = c
c:raise()
end
end),
awful.button({},
3,
function (c)
if instance then
instance:hide()
instance = nil
else
instance = menu.create.clients(nil, c)
end
end),
awful.button({},
4,
function ()
awful.client.focus.byidx(1)
if capi.client.focus then
capi.client.focus:raise()
end
end),
awful.button({},
5,
function ()
awful.client.focus.byidx(-1)
if capi.client.focus then
capi.client.focus:raise()
end
end))
local labeler = function(c)
local text, bg, image, icon = awful.widget.tasklist.label.currenttags(c, s)
if not text then return end
-- text = "<span style='border: 1px solid white'>" .. c.name .. "</span>"
if capi.client.focus ~= c then
bg = beautiful.tasklist_bg
end
local ico
if not c.icon then
ico = capi.image(beautiful.widget_cpu)
else
ico = c.icon
end
return text, bg, image, ico
end
local tl = awful.widget.tasklist(labeler, buttons)
id(tl)
return tl
end
setmetatable(tasklist,
{
__call = function(t, ...) return tasklist:new(...) end
})
systray = {}
function systray:new(s, args)
local st = capi.widget({type='systray'})
id(st)
return st
end
setmetatable(systray,
{
__call = function(t, ...) return systray:new(...) end
})
function new(t, args)
local s = args.s or 1
args.position = args.position or 'top'
local p = {}
if args.layouts then
lb = layoutbox(s, args)
end
p.widgets = {
taglist = taglist(s, args),
prompt = prompt(s),
layoutinfo = layoutinfo(s),
layoutbox = (args.layouts and layoutbox(s, args)) or nil,
clock = clock(s, args),
systray = (s == 1 and systray(s, args)) or nil,
tasklist = tasklist(s, args)
}
p.wb = awful.wibox({position = args.position, screen = s, height=20})
p.wb.widgets = {
{
p.widgets.taglist,
p.widgets.prompt,
layout = awful.widget.layout.horizontal.leftright
},
p.widgets.clock,
battery2(),
p.widgets.layoutinfo,
p.widgets.layoutbox,
p.widgets.systray,
p.widgets.tasklist,
layout = awful.widget.layout.horizontal.rightleft
}
id(p)
if not panels[s] then panels[s] = {} end
panels[s][#panels[s] + 1] = p
return p
end
DEFAULT = {
s = 1,
modkey = 'Mod4',
position = 'top'
}
get = {}
function get.by_screen(s)
return panels[s]
end
function get.by_id(i)
return id[i]
end
function get.by_position(p, s)
local s = s or capi.mouse.screen
local r = {}
for k, v in pairs(panels[s]) do
if p == v.position then table.insert(r, v) end
end
return r
end
setmetatable(_M,
{
__index = panels,
__call = new,
})