-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwi.lua
executable file
·356 lines (308 loc) · 9.65 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
--[[=============================================================================
# FileName: wi.lua
# Desc:
# Author: Lee Meng
# Email: [email protected]
# HomePage: http://leaveboy.is-programmer.com/
# Version: 0.0.1
# LastChange: 2013-01-07 17:21:57
# History:
=============================================================================]]
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local vicious = require("vicious")
local naughty = require("naughty")
--local cal = require("utils.cal")
local lain = require("lain")
markup = lain.util.markup
height = 12
graphwidth = 50
graphheight = height
pctwidth = 40
cpu_low = theme.colors.green
cpu_mid = theme.colors.magenta
cpu_high = theme.colors.red
fg_widget = theme.colors.base1
bg_widget = theme.colors.base3
fg_em = theme.colors.base1
bg_em = theme.colors.orange
-- {{{ SPACERS
space = wibox.widget.textbox()
space:set_text(" ")
comma = wibox.widget.textbox()
comma:set_markup(",")
pipe = wibox.widget.textbox()
pipe:set_markup(markup(fg_widget,'┋'))
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 temperature
cpuicon = wibox.widget.imagebox()
cpuicon:set_image(beautiful.widget_cpu)
tzswidget = wibox.widget.textbox()
vicious.register(tzswidget, vicious.widgets.thermal, "$1°C", 19, "thermal_zone0")
-- 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
--vicious.register(cpupct2, vicious.widgets.cpu, "$4%", 2)
--end
-- Core 0 graph
cpugraph0 = awful.widget.graph()
cpugraph0:set_width(graphwidth):set_height(graphheight)
cpugraph0:set_border_color(nil)
cpugraph0:set_border_color(fg_widget)
cpugraph0:set_background_color(bg_widget)
cpugraph0:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, cpu_low },
{ 0.50, cpu_mid },
{ 1, cpu_high }
}})
vicious.register(cpugraph0, vicious.widgets.cpu, "$1")
-- Core 1 graph
cpugraph1 = awful.widget.graph()
cpugraph1:set_width(graphwidth):set_height(graphheight)
cpugraph1:set_border_color(nil)
cpugraph1:set_border_color(fg_widget)
cpugraph1:set_background_color(bg_widget)
cpugraph1:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, cpu_low },
{ 0.50, cpu_mid },
{ 1, cpu_high }
}})
vicious.register(cpugraph1, vicious.widgets.cpu, "$2")
-- Core 2 graph
cpugraph2 = awful.widget.graph()
cpugraph2:set_width(graphwidth):set_height(graphheight)
cpugraph2:set_border_color(nil)
cpugraph2:set_border_color(fg_widget)
cpugraph2:set_background_color(bg_widget)
cpugraph2:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, cpu_low },
{ 0.50, cpu_mid },
{ 1, cpu_high }
}})
vicious.register(cpugraph2, vicious.widgets.cpu, "$3")
-- Core 3 graph
cpugraph3 = awful.widget.graph()
cpugraph3:set_width(graphwidth):set_height(graphheight)
cpugraph3:set_border_color(nil)
cpugraph3:set_border_color(fg_widget)
cpugraph3:set_background_color(bg_widget)
cpugraph3:set_color({
type = "linear",
from = { 0, graphheight },
to = { 0, 0 },
stops = {
{ 0, cpu_low },
{ 0.50, cpu_mid },
{ 1, cpu_high }
}})
vicious.register(cpugraph3, vicious.widgets.cpu, "$4")
-- }}}
-- {{{ MEMORY
vicious.cache(vicious.widgets.mem)
-- Ram used
memicon = wibox.widget.imagebox()
memicon:set_image(beautiful.widget_ram)
memused = wibox.widget.textbox()
vicious.register(memused, vicious.widgets.mem,markup(bg_em,"$2MB $1%") .. markup(fg_em,"♻") .. markup(bg_em,"$5% $6M"), 5)
cputest = wibox.widget {
{
max_value = 1,
value = 0.33,
widget = wibox.widget.progressbar,
},
forced_height = 100,
forced_width = 20,
direction = 'east',
layout = wibox.container.rotate,
}
-- {{{ FILESYSTEM
-- Cache
vicious.cache(vicious.widgets.fs)
-- Root used
--rootfsused = wibox.widget.textbox()
--vicious.register(rootfsused, vicious.widgets.fs,markup(fg_em,"FS:") .. markup(bg_em,"${/ used_gb}GB ${/ used_p}%"), 97)
---- }}}
-- {{{ DISK DIO
-- Cache
vicious.cache(vicious.widgets.dio)
-- Read and Write
dioicon = wibox.widget.imagebox()
dioicon:set_image(beautiful.widget_disk)
diowidget = wibox.widget.textbox()
vicious.register(diowidget, vicious.widgets.dio,markup("green","${sda write_kb}K") .. markup("orange","${sda read_kb}K"),1)
-- }}}
-- {{{ UPTIME
vicious.cache(vicious.widgets.uptime)
uptimewidget = wibox.widget.textbox()
vicious.register(uptimewidget, vicious.widgets.uptime, "♨$1-$2:$3", 60)
uptimewidget:buttons(awful.util.table.join(awful.button({ }, 1,
function()
local f = io.popen("uptime")
p = f:read("*a")
naughty.notify { text = markup(fg_em,p), timeout = 5, hover_timeout = 0.5 }
end)))
-- }}}
-- {{{ MPD
mpdicon = wibox.widget.imagebox()
mpdicon:set_image(beautiful.widget_mpd)
mpdwidget = wibox.widget.textbox()
vicious.register(mpdwidget, vicious.widgets.mpd,
function(widget, args)
if args["{state}"] == "Stop" then
mpdicon:set_image(beautiful.widget_mpd)
return markup(bg_em,"")
elseif args["{state}"] == "Pause" then
mpdicon:set_image(beautiful.widget_mpd)
return markup(bg_em,"") .. args["{Artist}"]..'∙'.. args["{Title}"]
else
mpdicon:set_image(beautiful.widget_mpdplay)
return markup(bg_em,"") .. args["{Artist}"]..'∙'.. args["{Title}"]
end
end, 3)
mpdwidget:buttons(awful.util.table.join(awful.button({ }, 1,
function()
local f = io.popen("mpc")
p = f:read("*a")
naughty.notify { text = markup(fg_em,p), timeout = 5, hover_timeout = 0.5 }
end)))
mpdicon:buttons(mpdwidget:buttons())
-- }}}
-- {{{ NETWORK
vicious.cache(vicious.widgets.net)
neticon = wibox.widget.imagebox()
neticon:set_image(beautiful.widget_net)
netwidget = wibox.widget.textbox()
vicious.register(netwidget, vicious.widgets.net, markup("green","${wlp3s0 down_kb}K")..markup("orange","${wlp3s0 up_kb}K"), 1)
-- {{{ CLOCK
mytextclock = awful.widget.textclock("%a %R",1)
-- {{{ WEATHER
weather = wibox.widget.textbox()
vicious.register(weather, vicious.widgets.weather,"${weather} ${tempc}°C",1800, "ZUUU")
weather:buttons(awful.util.table.join(awful.button({ }, 1, function()
vicious.force({ weather, })
end)))
-- }}}
-- {{{ PACMAN
pacicon = wibox.widget.imagebox()
pacicon:set_image(beautiful.widget_pac)
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
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 = markup(fg_em,pac_updates), timeout = 5, hover_timeout = 0.5 }
end
pacwidget:buttons(awful.util.table.join(awful.button({ }, 1, popup_pac)))
pacicon:buttons(pacwidget:buttons())
-- }}}
-- {{{ VOLUME
vicious.cache(vicious.widgets.volume)
volicon = wibox.widget.imagebox()
volicon:set_image(beautiful.widget_vol)
volpct = wibox.widget.textbox()
vicious.register(volpct, vicious.widgets.volume, "$1%", nil, "Master")
volicon:buttons(awful.util.table.join(
awful.button({ }, 1,
function() awful.util.spawn_with_shell("amixer sset Master toggle") end),
awful.button({ }, 4,
function() awful.util.spawn_with_shell("amixer sset Master,0 5%+") end),
awful.button({ }, 5,
function() awful.util.spawn_with_shell("amixer sset Master,0 5%-") end)
))
volpct:buttons(volicon:buttons())
volspace:buttons(volicon:buttons())
-- }}}
-- {{{ BATTERY
local bat_state = ""
local bat_charge = 0
local bat_time = 0
local blink = true
baticon = wibox.widget.imagebox()
baticon:set_image(beautiful.widget_batfull)
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 > 90 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)
elseif bat_charge > 3 then
baticon:set_image(beautiful.widget_batempty)
naughty.notify { text = markup(fg_em,"Charge :")..("Less 10%\n") .. markup(fg_em,"State :")..("Hibernate at 3%"),
timeout = 2, hover_timeout = 0.5 }
else
awful.util.spawn_with_shell("pm-hibernate")
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")
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 = markup(fg_em,"Charge : ") .. bat_charge .. "%\n" .. markup(fg_em,"State : ") .. state ..
" (" .. bat_time .. ")", timeout = 5, hover_timeout = 10 }
end
batpct:buttons(awful.util.table.join(awful.button({ }, 1, popup_bat)))
baticon:buttons(batpct:buttons())
-- }}}