-
Notifications
You must be signed in to change notification settings - Fork 0
/
widgets.lua
300 lines (279 loc) · 8.6 KB
/
widgets.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
local v_contrib = require("vicious.contrib")
local vicious = require("vicious")
local gears = require("gears")
require("blingbling")
line_graph = require("blingbling.linegraph")
progress_graph= require("blingbling.progress_graph")
require("iwlist")
require("markup")
local naughty = require("naughty")
local cal = require("cal")
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local asyncshell = require("asyncshell")
awful.util = require("awful.util")
local lain = require("lain")
markup = lain.util.markup
white = beautiful.fg_focus
gray = beautiful.fg_normal
local exec = awful.util.spawn
local sexec = awful.util.spawn_with_shell
--{{
spr = wibox.widget.textbox(' ')
arrl = wibox.widget.imagebox()
arrl:set_image(beautiful.arrl)
arrl_dl = wibox.widget.imagebox()
arrl_dl:set_image(beautiful.arrl_dl)
arrl_ld = wibox.widget.imagebox()
arrl_ld:set_image(beautiful.arrl_ld)
--}}
-- {{{ Создание виджета разделителя
separator = wibox.widget.textbox()
separator:set_markup("<span color='#31ff31'font='Terminus 10'> ⁝ </span>")
-- }}}
-- {{{ Виджет батареи
baticon = wibox.widget.imagebox()
baticon:set_image(beautiful.widget_battery)
batwidget = wibox.widget.textbox()
vicious.register(batwidget, vicious.widgets.bat,
function (widget,args)
return args[2] .. "%"
end,
120, "BAT0")
baticonbg = wibox.widget.background(baticon, "#313131")
batwidgetbg = wibox.widget.background(batwidget, "#313131")
-- }}}
-- {{{ Видежет отображения раскладки, для работы требудется kbdd
kbdwidget = wibox.widget.textbox()
kbdwidget.border_width = 0
kbdwidget.fit = function(widget, width, height)
local _, h = wibox.widget.textbox.fit(widget, width, height)
return 24, h
end
kbdwidget.border_color = beautiful.fg_normal
kbdwidget:set_text( " En" )
dbus.request_name("session", "ru.gentoo.kbdd")
dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'")
dbus.connect_signal("ru.gentoo.kbdd",
function(...)
local data = {...}
local layout = data[2]
lts = {[0] = " En", [1] = " Ru"}
kbdwidget:set_text(lts[layout])
end)
kbdwidgetbg = wibox.widget.background(kbdwidget, "#313131")
-- }}}
-- {{{ Виджет управления громкостью
-- TODO запилить свой виджет отображения громкости. который будет работаеть без таймера
volicon = wibox.widget.imagebox()
volicon:set_image(beautiful.widget_vol)
volwidget = wibox.widget.textbox()
vicious.cache(vicious.widgets.volume)
-- Регистрация виджета
vicious.register(volwidget, vicious.widgets.volume,
function (widget,args)
local label = { ["♫"] = "on", ["♩"] = "off" }
if label[args[2]] == "off" then
return "m"
end
return args[1] .. "%"
end,
10, "Master")
-- }}}
-- {{{ Виджет отображающий время и календарь
datewidget = wibox.widget.textbox()
lain.widgets.calendar:attach(datewidget, { font_size = 10 })
vicious.register(datewidget, vicious.widgets.date, " %R ", 60)
datewidgetbg = wibox.widget.background(datewidget, "#313131")
-- }}}
-- {{{ Загрузка и температура процессора
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")
cpuiconbg = wibox.widget.background(cpuicon, "#313131")
tzswidgetbg = wibox.widget.background(tzswidget, "#313131")
cpu_graph = line_graph({
height = 12,
width = 100,
show_text = false,
background_color = "#313131",
h_margin = 0,
v_margin = 0,
graph_line_color="#FF000000"
})
vicious.register(cpu_graph, vicious.widgets.cpu,'$1',5)
-- }}}
--
-- {{{ Использование памяти
memicon = wibox.widget.imagebox()
memicon:set_image(beautiful.widget_mem)
memwidget = line_graph({
height = 12,
width = 100,
v_margin = 0,
h_margin = 0,
graph_line_color = "#FF000000",
show_text = false,
background_color = "#00000044"
})
vicious.register(memwidget, vicious.widgets.mem, '$1', 5)
-- }}}
-- {{{ Загрука сети
-- TODO запилить несолько интерфейсов
-- FIXME пофиксить отображение если ни один из контролируемых интерфейсов не поднят
dnicon = wibox.widget.imagebox()
upicon = wibox.widget.imagebox()
dnicon:set_image(beautiful.widget_net)
upicon:set_image(beautiful.widget_netup)
network = wibox.widget.textbox()
vicious.register(network, vicious.widgets.net,
'<span color="#CC9393">${wlan0 up_kb} Kb/s</span> : <span color="#7F9F7F">${wlan0 down_kb} Kb/s</span>', 5)
network:buttons( awful.util.table.join(
awful.button({}, 1,
function()
naughty.notify({text = 'test'})
end),
awful.button({ }, 3, function () vicious.force{wifiwidget} end)
))
-- }}}
-- {{{ Температура HDD
--hddtempicon = wibox.widget.imagebox()
--hddtempicon:set_image(beautiful.widget_temp)
--hddtempwidget = wibox.widget.textbox()
--vicious.register(hddtempwidget, vicious.widgets.hddtemp, "${/dev/sda}°C", 30)
--}}}
--hddtempiconbg = wibox.widget.background(hddtempicon, "#313131")
--hddtempwidgetbg = wibox.widget.background(hddtempwidget, "#313131")
--{{{ Gmail уведомления о почте
gmailicon = wibox.widget.imagebox()
gmailicon:set_image(beautiful.widget_mail)
gmail = wibox.widget.textbox()
gmail:set_text( "?" )
local function gmail_callback(f)
text = f:read()
if text ~= nil then
if text ~= "0" and text ~= "?" then
gmail:set_markup( "<span color='red'><b>".. text .."</b></span>")
else
gmail:set_text(text)
end
else
gmail:set_text('N')
end
end
gmail.timer = timer{timeout=120}
gmail.timer:connect_signal("timeout", function ()
asyncshell.request('/home/serg/.config/awesome/gmail.py', function(f) gmail_callback(f) end)
end)
gmail.timer:start()
--}}}
-- {{{ Состояние файловой системы
fs_home = progress_graph({
height=12,
graph_line_color = "#00000000",
width=65,
show_text=true,
text_color="#ffffffff",
background_text_color="#00000000",
graph_background_color = "#1A1A1A",
v_margin=0,
h_margin=2,
horizontal=true,
label=" /home",
font = "Snap",
font_size=10
})
vicious.register(fs_home, vicious.widgets.fs, "${/home used_p}", 120)
--
fs_root = progress_graph({
height=12,
width=65,
show_text=true,
graph_line_color = "#00000000",
text_color="#ffffffff",
background_text_color="#00000000",
background_color = "#313131",
background_border = "#000000",
graph_background_color = "#313131",
horizontal=true,
v_margin=0,
label=" /root",
font = "Snap",
font_size= 10
})
vicious.register(fs_root, vicious.widgets.fs, "${/ used_p}", 120)
-- }}}
-- {{ Wifi
wifi_icon = wibox.widget.imagebox()
wifi_icon:set_image(beautiful.widget_netw)
wifi_widget = wibox.widget.textbox()
wifi_widgetbg = wibox.widget.background(wifi_widget, "#313131")
wifi_iconbg = wibox.widget.background(wifi_icon, "#313131")
vicious.register(wifi_widget, vicious.widgets.wifi,
function(widget, args)
local quality = 0
local result = ""
if args["{ssid}"] ~= 'N/A' then
if args["{linp}"] > 0 then
quality = args["{link}"] / args["{linp}"] * 100
end
result = ("%s: %.1f%%"):format(args["{ssid}"], quality)
else
result = "n/a"
end
return result
end,
7, "wlan0")
wifi_icon:buttons( wifi_widget:buttons( awful.util.table.join(
awful.button({}, 1,
function()
local networks = iwlist.scan_networks()
if #networks > 0 then
local msg = {}
for i, ap in ipairs(networks) do
local line = "<b>ESSID:</b> %s <b>MAC:</b> %s <b>Qual.:</b> %.2f%% <b>%s</b>"
local enc = iwlist.get_encryption(ap)
msg[i] = line:format(ap.essid, ap.address, ap.quality, enc)
end
naughty.notify({text = table.concat(msg, "\n")})
else
end
end),
awful.button({ }, 3, function () vicious.force{wifiwidget} end)
)))
-- }}
local vol_info = nil
function set_volume(flag)
if flag then
exec("amixer set Master 2%+")
else
exec("amixer set Master 2%-")
end
fd = io.popen("amixer sget Master")
status = fd:read("*all")
fd:close()
local volume = tonumber(string.match(status, "(%d?%d?%d)%%"))
local pgbar = "["
for i = 0, 99, 1 do
if i < volume then
pgbar = pgbar .. "|"
else
pgbar = pgbar .. "."
end
end
pgbar = pgbar .. "]"
volume = 'Volume ' .. volume .. '%'
if vol_info ~= nil then
vol_info = naughty.notify({
text = pgbar,
title = volume ,
replaces_id = vol_info.id
})
else
vol_info = naughty.notify({ text = pgbar,
title = volume
})
end
end