-
Notifications
You must be signed in to change notification settings - Fork 8
/
wi.lua
463 lines (404 loc) · 12.6 KB
/
wi.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
-----------------------
-- AwesomeWM widgets --
-- version 3.5 --
-- <tdy@gmx.com> --
-----------------------
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local vicious = require("vicious")
local naughty = require("naughty")
graphwidth = 120
graphheight = 20
pctwidth = 40
netwidth = 50
mpdwidth = 365
-- {{{ Spacers
space = wibox.widget.textbox()
space:set_text(" ")
comma = wibox.widget.textbox()
comma:set_markup(",")
pipe = wibox.widget.textbox()
pipe:set_markup("<span color='" .. beautiful.bg_em .. "'>|</span>")
tab = wibox.widget.textbox()
tab:set_text(" ")
volspace = wibox.widget.textbox()
volspace:set_text(" ")
-- }}}
-- {{{ Processor
-- Cache
vicious.cache(vicious.widgets.cpu)
vicious.cache(vicious.widgets.cpuinf)
-- Core 0 freq
cpufreq = wibox.widget.textbox()
vicious.register(cpufreq, vicious.widgets.cpuinf,
function(widget, args)
return string.format("<span color='" .. beautiful.fg_em ..
"'>cpu</span>%1.1fGHz", args["{cpu0 ghz}"])
end, 3000)
-- Core 0 graph
cpugraph0 = awful.widget.graph()
cpugraph0:set_width(graphwidth):set_height(graphheight)
cpugraph0:set_border_color(nil)
cpugraph0:set_border_color(beautiful.bg_widget)
cpugraph0:set_background_color(beautiful.bg_widget)
cpugraph0:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget } } })
vicious.register(cpugraph0, vicious.widgets.cpu, "$2")
-- Core 0 %
cpupct0 = wibox.widget.textbox()
cpupct0.fit =
function(box, w, h)
local w, h = wibox.widget.textbox.fit(box, w, h)
return math.max(pctwidth, w), h
end
vicious.register(cpupct0, vicious.widgets.cpu, "$2%", 2)
-- Core 1 graph
cpugraph1 = awful.widget.graph()
cpugraph1:set_width(graphwidth):set_height(graphheight)
cpugraph1:set_border_color(nil)
cpugraph1:set_border_color(beautiful.bg_widget)
cpugraph1:set_background_color(beautiful.bg_widget)
cpugraph1:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget }
}})
vicious.register(cpugraph1, vicious.widgets.cpu, "$3")
-- Core 1 %
cpupct1 = wibox.widget.textbox()
cpupct1.fit =
function(box, w, h)
local w, h = wibox.widget.textbox.fit(box, w, h)
return math.max(pctwidth, w), h
end
vicious.register(cpupct1, vicious.widgets.cpu, "$3%", 2)
-- Core 2 graph
cpugraph2 = awful.widget.graph()
cpugraph2:set_width(graphwidth):set_height(graphheight)
cpugraph2:set_border_color(nil)
cpugraph2:set_border_color(beautiful.bg_widget)
cpugraph2:set_background_color(beautiful.bg_widget)
cpugraph2:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget } } })
vicious.register(cpugraph2, vicious.widgets.cpu, "$4")
-- Core 2 %
cpupct2 = wibox.widget.textbox()
cpupct2.fit =
function(box, w, h)
local w, h = wibox.widget.textbox.fit(box, w, h)
return math.max(pctwidth, w), h
end
vicious.register(cpupct2, vicious.widgets.cpu, "$4%", 2)
-- }}}
-- {{{ Memory
-- Cache
vicious.cache(vicious.widgets.mem)
-- RAM used
memused = wibox.widget.textbox()
vicious.register(memused, vicious.widgets.mem,
"<span color='" .. beautiful.fg_em .. "'>ram</span>$2MB", 5)
-- RAM bar
membar = awful.widget.progressbar()
membar:set_vertical(false):set_width(graphwidth):set_height(graphheight)
membar:set_ticks(false):set_ticks_size(2)
membar:set_border_color(nil)
membar:set_background_color(beautiful.bg_widget)
membar:set_color({
type = "linear",
from = { 0, 0 },
to = { graphwidth, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget } } })
vicious.register(membar, vicious.widgets.mem, "$1", 13)
-- RAM %
mempct = wibox.widget.textbox()
mempct.width = pctwidth
vicious.register(mempct, vicious.widgets.mem, "$1%", 5)
-- {{{ Filesystem
-- Cache
vicious.cache(vicious.widgets.fs)
-- Root used
rootfsused = wibox.widget.textbox()
vicious.register(rootfsused, vicious.widgets.fs,
"<span color='" .. beautiful.fg_em .. "'>ssd</span>${/ used_gb}GB", 97)
-- Root bar
rootfsbar = awful.widget.progressbar()
rootfsbar:set_vertical(false):set_width(graphwidth):set_height(graphheight)
rootfsbar:set_ticks(false):set_ticks_size(2)
rootfsbar:set_border_color(nil)
rootfsbar:set_background_color(beautiful.bg_widget)
rootfsbar:set_color({
type = "linear",
from = { 0, 0 },
to = { graphwidth, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget } } })
vicious.register(rootfsbar, vicious.widgets.fs, "${/ used_p}", 97)
-- Root %
rootfspct = wibox.widget.textbox()
rootfspct.width = pctwidth
vicious.register(rootfspct, vicious.widgets.fs, "${/ used_p}%", 97)
-- }}}
-- {{{ Network
-- Cache
vicious.cache(vicious.widgets.net)
-- TX graph
txgraph = awful.widget.graph()
txgraph:set_width(graphwidth):set_height(graphheight)
txgraph:set_border_color(nil)
txgraph:set_background_color(beautiful.bg_widget)
txgraph:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget } } })
vicious.register(txgraph, vicious.widgets.net, "${eth0 up_kb}")
-- TX total
txwidget = wibox.widget.textbox()
vicious.register(txwidget, vicious.widgets.net,
"<span color='" .. beautiful.fg_em .. "'>tx</span>${eth0 tx_mb}MB", 19)
-- TX speed
txwidget = wibox.widget.textbox()
txwidget.fit =
function(box, w, h)
local w, h = wibox.widget.textbox.fit(box, w, h)
return math.max(netwidth, w), h
end
vicious.register(txwidget, vicious.widgets.net, "${eth0 up_kb}", 2)
-- RX graph
rxgraph = awful.widget.graph()
rxgraph:set_width(graphwidth):set_height(graphheight)
rxgraph:set_border_color(nil)
rxgraph:set_background_color(beautiful.bg_widget)
rxgraph:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, beautiful.fg_widget },
{ 0.25, beautiful.fg_center_widget },
{ 1, beautiful.fg_end_widget } } })
vicious.register(rxgraph, vicious.widgets.net, "${eth0 down_kb}")
-- RX total
rxwidget = wibox.widget.textbox()
vicious.register(rxwidget, vicious.widgets.net,
"<span color='" .. beautiful.fg_em .. "'>rx</span>${eth0 rx_mb}MB", 17)
-- RX speed
rxwidget = wibox.widget.textbox()
rxwidget.fit =
function(box, w, h)
local w, h = wibox.widget.textbox.fit(box, w, h)
return math.max(netwidth, w), h
end
vicious.register(rxwidget, vicious.widgets.net, "${eth0 down_kb}", 2)
-- }}}
-- {{{ Weather
weather = wibox.widget.textbox()
vicious.register(weather, vicious.widgets.weather,
"<span color='" .. beautiful.fg_em .. "'>${sky}</span> @ ${tempf}°F on",
1501, "XXXX")
weather:buttons(awful.util.table.join(awful.button({ }, 1,
function() vicious.force({ weather }) end)))
-- }}}
-- {{{ Pacman
-- Icon
pacicon = wibox.widget.imagebox()
pacicon:set_image(beautiful.widget_pac)
-- Upgrades
pacwidget = wibox.widget.textbox()
vicious.register(pacwidget, vicious.widgets.pkg,
function(widget, args)
if args[1] > 0 then
pacicon:set_image(beautiful.widget_pacnew)
else
pacicon:set_image(beautiful.widget_pac)
end
return args[1]
end, 1801, "Arch S") -- Arch S for ignorepkg
-- Buttons
function popup_pac()
local pac_updates = ""
local f = io.popen("pacman -Sup --dbpath /tmp/pacsync")
if f then
pac_updates = f:read("*a"):match(".*/(.*)-.*\n$")
end
f:close()
if not pac_updates then pac_updates = "System is up to date" end
naughty.notify { text = pac_updates }
end
pacwidget:buttons(awful.util.table.join(awful.button({ }, 1, popup_pac)))
pacicon:buttons(pacwidget:buttons())
-- }}}
-- {{{ Pianobar
-- Icon
mpdicon = wibox.widget.imagebox()
mpdicon:set_image(beautiful.widget_mpd)
-- Song info
mpdwidget = wibox.widget.textbox()
vicious.register(mpdwidget, vicious.widgets.mpd,
function(widget, args)
mpdicon:set_image(beautiful.widget_play)
local bg = beautiful.bg_focus
local italic = ""
local like = ""
local color = beautiful.fg_focus
local f = io.popen("pgrep pianobar")
if f:read("*line") then
f = io.open(os.getenv("HOME") .. "/.config/pianobar/isplaying")
play_or_pause = f:read("*line")
f:close()
-- Current song
f = io.open(os.getenv("HOME") .. "/.config/pianobar/nowplaying")
text = f:read("*line"):match("(.*)")
f:close()
-- Awaiting song
if text:match(" - $") then text = "..." end
-- Loved song
if text:find("%(like%)") then like = "💕" end
-- Ampersands
if text:find("&") then text = text:gsub("&","and") end
-- Paused
if play_or_pause == "0" then
if text:len() > 35 then mpdwidget.width = mpdwidth end
italic = "font_style='italic'"
mpdicon:set_image(beautiful.widget_pause)
info = like .. awful.util.escape(text:gsub("%(like%)",""))
else
mpdwidget.width = 0
local helpers = require("vicious.helpers")
info = like ..
awful.util.escape(helpers.scroll(text:gsub("%(like%)",""), 30, mpdwidget))
end
else
-- Stopped
mpdwidget.width = 0
mpdicon:set_image(beautiful.widget_mpd)
bg = beautiful.bg_normal
color = beautiful.fg_normal
info = "..."
end
return "<span color='" .. color .. "' background='" .. bg ..
"' " .. italic .. ">" .. info .. "</span>"
end, 3)
-- Buttons
mpdwidget:buttons(awful.util.table.join(
awful.button({ }, 1,
function()
local f = io.popen("pgrep pianobar")
p = f:read("*a"):match("([0-9]*)")
if p == "" then
awful.util.spawn(pianobar_screen, false)
else
awful.util.spawn(pianobar_toggle, false)
end
end),
awful.button({ modkey }, 1, function() awful.util.spawn(pianobar_upcoming, false) end),
awful.button({ }, 2, function() awful.util.spawn(pianobar_quit, false) end),
awful.button({ }, 3, function() awful.util.spawn(pianobar_station, false) end),
awful.button({ }, 4, function() awful.util.spawn(pianobar_next, false) end),
awful.button({ }, 5, function() awful.util.spawn(pianobar_history, false) end)))
mpdicon:buttons(mpdwidget:buttons())
-- }}}
-- {{{ Volume
-- Cache
vicious.cache(vicious.widgets.volume)
-- Icon
volicon = wibox.widget.imagebox()
volicon:set_image(beautiful.widget_vol)
-- Volume %
volpct = wibox.widget.textbox()
vicious.register(volpct, vicious.widgets.volume, "$1%", nil, "Master")
-- Buttons
volicon:buttons(awful.util.table.join(
awful.button({ }, 1,
function() awful.util.spawn("amixer -q set Master toggle", false) end),
awful.button({ }, 4,
function() awful.util.spawn("amixer -q set Master 3+% unmute", false) end),
awful.button({ }, 5,
function() awful.util.spawn("amixer -q set Master 3-% unmute", false) end)))
volpct:buttons(volicon:buttons())
volspace:buttons(volicon:buttons())
-- }}}
-- {{{ Battery
-- Battery attributes
local bat_state = ""
local bat_charge = 0
local bat_time = 0
local blink = true
-- Icon
baticon = wibox.widget.imagebox()
baticon:set_image(beautiful.widget_batfull)
-- Charge %
batpct = wibox.widget.textbox()
vicious.register(batpct, vicious.widgets.bat,
function(widget, args)
bat_state = args[1]
bat_charge = args[2]
bat_time = args[3]
if args[1] == "-" then
if bat_charge > 70 then
baticon:set_image(beautiful.widget_batfull)
elseif bat_charge > 30 then
baticon:set_image(beautiful.widget_batmed)
elseif bat_charge > 10 then
baticon:set_image(beautiful.widget_batlow)
else
baticon:set_image(beautiful.widget_batempty)
end
else
baticon:set_image(beautiful.widget_ac)
if args[1] == "+" then
blink = not blink
if blink then
baticon:set_image(beautiful.widget_acblink)
end
end
end
return args[2] .. "%"
end, nil, "BAT0")
-- Buttons
function popup_bat()
local state = ""
if bat_state == "↯" then
state = "Full"
elseif bat_state == "↯" then
state = "Charged"
elseif bat_state == "+" then
state = "Charging"
elseif bat_state == "-" then
state = "Discharging"
elseif bat_state == "⌁" then
state = "Not charging"
else
state = "Unknown"
end
naughty.notify { text = "Charge : " .. bat_charge .. "%\nState : " .. state ..
" (" .. bat_time .. ")", timeout = 5, hover_timeout = 0.5 }
end
batpct:buttons(awful.util.table.join(awful.button({ }, 1, popup_bat)))
baticon:buttons(batpct:buttons())
-- }}}