-
Notifications
You must be signed in to change notification settings - Fork 1
/
wi.lua
387 lines (335 loc) · 10.9 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
-----------------------
-- AwesomeWM widgets --
-- version 3.5 --
-----------------------
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("|")
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("cpu%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)
-- }}}
-- Initialize widget
cpuwidget = wibox.widget.textbox()
-- Register widget
vicious.register(cpuwidget, vicious.widgets.cpu, "$1%")
cpuicon = wibox.widget.imagebox()
cpuicon:set_image("/home/guerre/.config/awesome/icons/cpu.png")
-- {{{ Memory
-- Cache
vicious.cache(vicious.widgets.mem)
-- RAM used
memused = wibox.widget.textbox()
vicious.register(memused, vicious.widgets.mem,"$2MB", 5)
memicon = wibox.widget.imagebox()
memicon:set_image("/home/guerre/.config/awesome/icons/mem.png")
-- }}}
-- {{{ 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,
"${sky} @ ${tempf}°F on",
1501, "XXXX")
weather:buttons(awful.util.table.join(awful.button({ }, 1,
function() vicious.force({ weather }) end)))
-- }}}
-- -- {{{ 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("/home/guerre/.config/awesome/icons/vol.png")
-- 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 2+% unmute", false) end),
awful.button({ }, 5,
function() awful.util.spawn("amixer -q set Master 2-% 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("/home/guerre/.config/awesome/icons/bat.png")
-- 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("/home/guerre/.config/awesome/icons/bat.png")
elseif bat_charge > 30 then
baticon:set_image("/home/guerre/.config/awesome/icons/bat-low.png")
elseif bat_charge > 10 then
baticon:set_image("/home/guerre/.config/awesome/icons/bat-empty.png")
else
baticon:set_image("/home/guerre/.config/awesome/icons/bat-empty.png")
end
else
baticon:set_image("/home/guerre/.config/awesome/icons/ac.png")
if args[1] == "+" then
blink = not blink
if blink then
baticon:set_image("/home/guerre/.config/awesome/icons/ac.png")
end
end
end
return args[2] .. "%" .. " " .. bat_time
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())
-- }}}