-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc.lua
1664 lines (1549 loc) · 58.3 KB
/
rc.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
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local menubar = require("menubar")
local hotkeys_popup = require("awful.hotkeys_popup").widget
local common = require("awful.widget.common")
local lain = require("lain")
-- Custom libraries
--local weather = require("weather")
local dpi = require("beautiful").xresources.apply_dpi
-- {{{ Notifications position and border width
naughty.config.presets.normal.position = "top_right"
naughty.config.icon_dirs = {os.getenv("HOME") .. "/.config/awesome/themes/icons/"}
naughty.config.icon_formats = {"png", "svg"}
naughty.config.presets.normal.font = "Monospace Regular 11"
naughty.config.presets.normal.bg = "#222222"
naughty.config.presets.normal.fg = "#999999"
naughty.config.presets.normal.width = 300
-- }}}
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
naughty.notify({ preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!",
text = awesome.startup_errors })
end
awesome.connect_signal("exit",
function()
awful.spawn("pkill telegram-cli")
end
)
-- Handle runtime errors after startup
do
local in_error = false
awesome.connect_signal("debug::error", function (err)
-- Make sure we don't go into an endless error loop
if in_error then return end
in_error = true
naughty.notify({ preset = naughty.config.presets.critical,
title = "Oops, an error happened!",
text = tostring(err) })
in_error = false
end)
end
-- }}}
-- {{ Markup helper
markup = lain.util.markup
-- {{
-- {{ Custom functions
-- Custom verticaltag and verticaltask are here for custom highlighting. By default there is no such a vertical line in the right of tag name and an active client's icon.
function verticaltag(w, buttons, label, data, objects)
w:reset()
for i, o in ipairs(objects) do
local cache = data[o]
local ib, tb, bgb, m, ah, bgt, ms
if cache then
ib = cache.ib
tb = cache.tb
bgb = cache.bgb
m = cache.m
ah = cache.ah
bgt = cache.bgt
ms = cache.ms
else
ib = wibox.widget.imagebox()
tb = wibox.widget.textbox()
bgb = wibox.container.background()
bgt = wibox.container.background()
ah = wibox.layout.align.horizontal()
ibm = wibox.container.margin(ib, dpi(4))
ah:set_middle(tb)
ah:set_left(ibm)
ah:set_expand("none")
bgt:set_widget(ah)
ms = wibox.container.margin(bgt, 0, 2, 0, 0)
m = wibox.container.margin(ms, 0, 0, 0, 2)
bgb:set_bg(beautiful.bg_normal)
bgb:set_widget(m)
bgb:buttons(common.create_buttons(buttons, o))
data[o] = {
ib = ib,
tb = tb,
bgb = bgb,
m = m,
ah = ah,
bgt = bgt,
ms = ms,
ibm = ibm
}
end
local text, bg, bg_image, icon, args = label(o)
args = args or {}
--if not pcall(tb.set_markup, tb, markup(beautiful.text_dark, text)) then
-- tb:set_markup("<i><Invalid text></i>")
--end
--if bg_image == "light" then
-- tb:set_markup(markup(beautiful.text_light, text))
--end
--bgt:set_bg(bg)
if bg == beautiful.taglist_bg_focus then
ms:set_color(beautiful.fg_focus)
else
ms:set_color(beautiful.bg_normal)
end
-- The text might be invalid, so use pcall.
if text == nil or text == "" then
tbm:set_margins(0)
else
if not tb:set_markup_silently(text) then
tb:set_markup("<i><Invalid text></i>")
end
end
bgb:set_bg(bg)
if type(bg_image) == "function" then
-- TODO: Why does this pass nil as an argument?
bg_image = bg_image(tb,o,nil,objects,i)
end
bgb:set_bgimage(bg_image)
--if icon then
-- ib:set_image(icon)
--else
-- imb:set_margins(0)
--end
w:add(bgb)
end
end
function verticaltask(w, buttons, label, data, objects)
-- update the widgets, creating them if needed
w:reset()
for i, o in ipairs(objects) do
local cache = data[o]
local ib, tb, bgb, tbm, ibm, l
if cache then
ib = cache.ib
tb = cache.tb
bgb = cache.bgb
tbm = cache.tbm
ibm = cache.ibm
else
ib = wibox.widget.imagebox()
tb = wibox.widget.textbox()
bgb = wibox.container.background()
tbm = wibox.container.margin(tb, 0, 0, 0, 0)
ibm = wibox.container.margin(ib, 3, 3, 3, 3)
l = wibox.layout.fixed.vertical()
-- All of this is added in a fixed widget
l:fill_space(true)
l:add(ibm)
-- And all of this gets a background
bgb = wibox.container.margin(l, 0, 2, 0, 0)
bgb:set_widget(l)
bgb:buttons(common.create_buttons(buttons, o))
data[o] = {
ib = ib,
tb = tb,
bgb = bgb,
tbm = tbm,
ibm = ibm,
}
end
local text, bg, bg_image, icon, args = label(o, tb)
bgb:set_color(bg)
if icon then
ib:set_image(icon)
else
ib:set_image(beautiful.generic_icon)
end
w:add(bgb)
end
end
function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
-- END OF CUSTOM FUNCTIONS}}}
-- {{{ Variable definitions
-- Themes define colours, icons, font and wallpapers.
--beautiful.init(awful.util.get_themes_dir() .. "default/theme.lua")
beautiful.init("~/.config/awesome/themes/theme.lua")
-- This is used later as the default terminal and editor to run.
terminal = "xterm"
editor = os.getenv("EDITOR") or "vim"
editor_cmd = terminal .. " -e " .. editor
-- Custom variables
-- {{ Autostart
function run_once(cmd)
findme = cmd
firstspace = cmd:find(" ")
if firstspace then
findme = cmd:sub(0, firstspace-1)
end
awful.spawn.with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || (" .. cmd .. ")")
end
--awful.util.spawn_with_shell("xset s +dpms")
--awful.util.spawn_with_shell("wmctrl -x -a conky || conky")
run_once("setxkbmap -layout 'us,ru' -option grp:caps_toggle -option grp_led:caps")
--run_once("nextcloud")
--run_once("telegram-cli -dERDC -P 23911 &")
run_once("light -S 30")
run_once("xcmenu --primary --clipboard --daemon")
run_once("redshift -o")
run_once("xrdb -merge " .. os.getenv("HOME") .. "/.Xresources")
--run_once("xfce4-power-manager")
run_once("xcompmgr")
if awesome.hostname == "arch" then
DPMS=600
run_once("numlockx on")
run_once("xautolock -time 10 -locker 'systemctl suspend' -detectsleep &")
run_once("xset s off")
run_once("xset -dpms")
suspend = "enabled"
elseif awesome.hostname == "laptop" then
run_once(os.getenv("HOME") .. "/.bin/disable_touch.sh")
run_once("syndaemon -i 0.5 -t -K -R -d")
run_once("xautolock -time 5 -locker 'systemctl suspend' -detectsleep &")
DPMS=180
suspend = "enabled"
--xset = true -- true=battery(180s), false=AC(300s) it's being set inside battery widget callback function
lock = true -- 1=enabled, 0=disabled
elseif awesome.hostname == "acer" then
DPMS=180
suspend = "enabled"
run_once("xset s " .. DPMS)
end
--}}
-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with others.
modkey = "Mod4"
-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
awful.layout.suit.floating,
awful.layout.suit.tile,
-- awful.layout.suit.tile.left,
-- awful.layout.suit.tile.bottom,
-- awful.layout.suit.tile.top,
-- awful.layout.suit.fair,
-- awful.layout.suit.fair.horizontal,
-- awful.layout.suit.spiral,
-- awful.layout.suit.spiral.dwindle,
-- awful.layout.suit.max,
-- awful.layout.suit.max.fullscreen,
-- awful.layout.suit.magnifier,
-- awful.layout.suit.corner.nw,
-- awful.layout.suit.corner.ne,
-- awful.layout.suit.corner.sw,
-- awful.layout.suit.corner.se,
}
-- }}}
-- {{{ Helper functions
local function client_menu_toggle_fn()
local instance = nil
return function ()
if instance and instance.wibox.visible then
instance:hide()
instance = nil
else
instance = awful.menu.clients({ theme = { width = 100 } })
end
end
end
function b_notify()
brt = io.popen("light")
brt = brt:read("*a")
brt = math.floor(tonumber(brt)/5+0.5)*5
local icon = nil
if brt == 10 then
icon = "notification-display-brightness-off"
elseif brt <= 35 then
icon = "notification-display-brightness-low"
elseif brt <= 60 then
icon = "notification-display-brightness-medium"
elseif brt <= 85 then
icon = "notification-display-brightness-high"
else
icon = "notification-display-brightness-full"
end
return brt, icon
end
function translate()
awful.spawn.easy_async(os.getenv("HOME") .. "/.config/awesome/bin/trans.py", function(stdout, stderr, reason, exit_code)
naughty.notify({ title = "Translation", text = string.gsub(stdout, "\n$", ""), icon = "dict" })
end)
end
-- }}}
-- {{{ Launchers
-- {{{ Menu
myawesomemenu = {
{ "hotkeys", function() return false, hotkeys_popup.show_help end},
{ "manual", terminal .. " -e man awesome" },
{ "edit config", editor_cmd .. " " .. awesome.conffile },
{ "restart", awesome.restart },
{ "quit", function() awesome.quit() end}
}
powerMenu = {
{ "Logout", awesome.quit },
{ "Suspend", "systemctl suspend" },
{ "Hibernate", "systemctl hibernate" },
{ "Reboot", "systemctl reboot" },
{ "Shutdown", "systemctl poweroff" }
}
internetMenu = {
{ "Internet Nusha", "env GTK2_RC_FILES=/home/speranza/.gtkrc-2.0-light palemoon -P Nusha" },
{ "Transmission", "transmission-remote-gtk"},
{ "Skype", "skype" },
{ "Telegram", "telegram-desktop" },
{ "Mutt", terminal .. " -e mutt"},
{ "Weechat", terminal .. " -class WEECHAT -e ssh server -t 'LANG=en_US.UTF-8 exec tmux a -t weechat'"},
}
toolsMenu = {
{ "Calculator", "speedcrunch" },
{ "TodoMachine", terminal .. " -e todotxt-machine" },
{ "QOwnNotes", "QOwnNotes" },
}
officeMenu = {
{ "Writer", "libreoffice --writer"},
{ "Calc", "libreoffice --calc"},
}
workMenu = {
{ "DBeaver", "dbeaver"},
{ "Cutecom", "cutecom"},
}
mymainmenu = awful.menu({
items = {
{ "Files", "thunar" },
{ "Tools", toolsMenu },
{ "Office", officeMenu },
{ "Internet", internetMenu },
{ "Work", workMenu },
{ "Awesome", myawesomemenu, beautiful.awesome_icon },
{ "Power", powerMenu },
}
})
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
--app_folders = { "/usr/share/applications/", "~/.local/share/applications/" }
-- }}}
-- Keyboard map indicator and switcher
kbdwidget = awful.widget.keyboardlayout:new()
kbdwidget.widget.align = "center"
-- {{{ Custom widgets
paleLauncher = wibox.container.margin()
paleLauncher:setup {
{
{
image = beautiful.palemoon_icon,
widget = wibox.widget.imagebox,
resize = true,
forced_height = 32,
buttons = gears.table.join(
awful.button({ }, 1, function ()
local pm = false
local pm_c
for _, c in pairs(awful.screen.focused().all_clients) do
if c.class == "Pale moon" then
pm = true
pm_c = c
end
end
if pm then
client.focus = pm_c
pm_c:raise()
pm_c.first_tag:view_only()
else
awful.spawn("env GTK2_RC_FILES=/home/speranza/.gtkrc-2.0-light palemoon --no-remote -P Nusha")
end
end)
)
},
id = "root",
widget = wibox.container.margin,
left=5
},
id="right",
right=2,
color=theme.bg_normal,
widget=wibox.container.margin
}
thunarLauncher = wibox.container.margin()
thunarLauncher:setup {
{
{
image = beautiful.thunar_icon,
widget = wibox.widget.imagebox,
resize = true,
forced_height = 32,
buttons = gears.table.join(
awful.button({ }, 1, function ()
local t = false
local t_c
for _, c in pairs(awful.screen.focused().all_clients) do
if c.class == "Thunar" then
t = true
t_c = c
end
end
if t then
client.focus = t_c
t_c:raise()
t_c.first_tag:view_only()
else
awful.spawn("env GTK2_RC_FILES=/home/speranza/.gtkrc-2.0-light thunar")
end
end)
)
},
id = "root",
widget = wibox.container.margin,
left=5
},
id="right",
right=2,
color=theme.bg_normal,
widget=wibox.container.margin
}
if awesome.hostname ~= "laptop" then
paleLauncher.visible = false
thunarLauncher.visible = false
end
--- mail widget
mailwidget = wibox.container.margin()
mailwidget_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn(terminal .. " -e mutt") end)
)
mailwidget:setup {
{
{
id = "text",
text = "@",
align = "center",
widget = wibox.widget.textbox
},
id = "bgd",
buttons = mailwidget_buttons,
widget = wibox.container.background
},
id = "root",
layout = wibox.layout.fixed.vertical
}
mailwidget.root.bgd.forced_height=18
mailwidget.top = 0
mailwidget_tip = awful.tooltip({ objects = { mailwidget }})
mailwidgettimer = gears.timer({ timeout = 10 })
pr_mail = 0
wrk_mail = 0
telegram = 0
mailwidget_tip:set_text("MAIL\nPrivate\t\t" .. pr_mail .. "\n" .. "Work\t\t" .. wrk_mail .. "\nTELEGRAM\nDenis\t\t" .. telegram)
mailwidgettimer:connect_signal("timeout",
function()
if ( pr_mail > 0 or wrk_mail > 0) then
mailwidget.root.bgd:set_bg(theme.bg_urgent)
mailwidget.root.bgd.text:set_text(pr_mail+wrk_mail)
mailwidget_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn(terminal .. " -e mutt") end)
)
mailwidget.root.bgd:buttons(mailwidget_buttons)
else
mailwidget.root.bgd:set_bg(theme.bg_normal)
mailwidget.root.bgd.text:set_text("@")
mailwidget_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn(terminal .. " -e mutt") end)
)
mailwidget.root.bgd:buttons(mailwidget_buttons)
end
if ( telegram > 0 ) then
mailwidget.root.bgd:set_bg("#009DFF")
mailwidget.root.bgd.text:set_text(telegram)
mailwidget_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn("telegram-desktop") end)
)
mailwidget.root.bgd:buttons(mailwidget_buttons)
end
mailwidget_tip:set_text("MAIL\nPrivate\t" .. pr_mail .. "\n" .. "Work\t" .. wrk_mail .. "\nTELEGRAM\nDenis\t" .. telegram)
end
)
mailwidgettimer:start()
-- Weather widget
--weather_widget = wibox.container.margin()
--i, w, t, h, wd, ws, c, u = getweather()
--if i == nil then i, w, t, h, wd, ws, c, u = "", "na", "N/A", "na", "na", "na", "na", "na" end
--weather_buttons = gears.table.join(
-- awful.button({ }, 1, function ()
-- i, w, t, h, wd, ws, c, u = getweather()
-- awful.spawn(terminal .. " -hold -class CURL -e curl http://wttr.in/"..c)
-- end)
-- )
--weather_widget:setup {
-- {
-- {
-- id = "text",
-- text = "w: "..t.."°",
-- align = "center",
-- widget = wibox.widget.textbox
-- },
-- id = "bgd",
-- buttons = weather_buttons,
-- widget = wibox.container.background
-- },
-- id = "root",
-- layout = wibox.layout.fixed.vertical
--}
--weather_widget.top = 0
--weather_widget_tip = awful.tooltip({ objects = { weather_widget }})
--weatherwidgettimer = gears.timer({ timeout = 3600 })
--weather_widget_tip:set_text("WEATHER @ "..c.."\nCondition:\t" .. w .. "\nHuminidity:\t" .. h .. "\nWind\t\t" .. wd .. " / " .. ws.." m/s\nUpdated:\t"..u)
--weatherwidgettimer:connect_signal("timeout",
-- function()
-- --mailwidget_tip:set_text("MAIL\nPrivate\t" .. pr_mail .. "\n" .. "Work\t" .. wrk_mail .. "\nTELEGRAM\nDenis\t" .. telegram)
--
-- i, w, t, h, wd, ws, c, u = getweather()
-- end
--)
--weatherwidgettimer:start()
--
--- VPN widget
vpn_widget = wibox.container.margin()
vpn_buttons = gears.table.join(
awful.button({ }, 1, function ()
awful.spawn("networkmanager_dmenu")
end)
)
vpn_widget:setup {
{
{
id = "text",
text = "VPN",
align = "center",
widget = wibox.widget.textbox
},
id = "bgd",
buttons = vpn_buttons,
widget = wibox.container.background
},
id = "root",
layout = wibox.layout.fixed.vertical
}
vpn_widget.top = 0
vpn_widget.visible = false
vpnwidgettimer = gears.timer({ timeout = 10 })
vpnwidgettimer:connect_signal("timeout",
function()
awful.spawn.with_line_callback(os.getenv("HOME").."/.config/awesome/bin/helpers.sh vpn", {
stdout = function(line)
vpn = line
end})
if vpn == "1" then
vpn_widget.visible = true
else
vpn_widget.visible = false
end
end
)
vpnwidgettimer:start()
-- Background processes widget
bg_widget = wibox.container.margin()
bgds = {}
bg_buttons = gears.table.join(
awful.button({ }, 1, function ()
awful.menu(bgds):show()
end)
)
bg_widget:setup {
{
{
id = "text",
text = "BGND",
align = "center",
widget = wibox.widget.textbox
},
id = "bgd",
buttons = bg_buttons,
widget = wibox.container.background
},
id = "root",
layout = wibox.layout.fixed.vertical
}
bg_widget.top = 0
bg_widget.visible = false
bg_widgettimer = gears.timer({ timeout = 10 })
bg_widgettimer:connect_signal("timeout",
function()
procs = {"test.sh", "fill.sh"}
bgds={}
for i, c in pairs(procs) do
awful.spawn.easy_async("/usr/bin/pgrep "..c, function(stdout, stderr, reason, exit_code)
if exit_code == 0 then
table.insert(bgds, {"Kill "..c,
function()
awful.spawn("pkill "..c)
end
})
end
if next(bgds) ~= nil then
bg_widget.visible = true
else
bg_widget.visible = false
end
end)
end
end
)
bg_widgettimer:start()
-- Volume widget stuff
step = 3 -- is used in key bindings on order to notify properly
function volume(action)
local mixer
local alsa_channel = vlm.channel
if action == "+" or action == "-" then
if volume_now.status == "off" then
act = "toggle"
else
act = step .. "%" .. action
end
elseif action == "toggle" then
act = action
end
mixer = io.popen("amixer -q sset " .. alsa_channel .. " " .. act)
end
volnotify = {}
volnotify.id = nil
function volnotify:notify(vol)
if not awesome.startup then
local icn = nil
if vol == "M" then
txt = 'Volume muted'
icn = "notification-audio-volume-muted"
else
txt = 'Volume: ' .. vol .. '%'
if tonumber(vol) == 0 then
icn = "notification-audio-volume-off"
elseif (tonumber(vol) <= 33) then
icn = "notification-audio-volume-low"
elseif (tonumber(vol) <= 66) then
icn = "notification-audio-volume-medium"
elseif (tonumber(vol) <= 100) then
icn = "notification-audio-volume-high"
end
end
self.id = naughty.notify({ text = txt, replaces_id = self.id, icon = icn}).id
end
end
my_volume = wibox.container.margin()
my_volume.top = 0
vlm = lain.widget.alsa({timeout=1,
settings = function()
if not awesome.startup then
if volume_now.status == "off" then
widget:set_markup(markup(beautiful.fg_urgent,"♫M"))
else
widget:set_markup(markup(beautiful.text_light,"♫" .. volume_now.level .. "%"))
end
if volume_now.level == "100" then
widget:set_markup(markup(beautiful.fg_urgent,"♫" .. "MAX"))
end
widget:set_align("center")
end
end
})
my_volume:setup {
id = "vlm",
widget = vlm.widget
}
my_volume:buttons(gears.table.join(
awful.button({ }, 1, function () volume("toggle") end),
awful.button({ }, 4, function () volume("+") end),
awful.button({ }, 5, function () volume("-") end)
))
-- Memory widget
mmr = lain.widget.mem{
settings = function()
if (math.floor(mem_now.used) *1.048576) >= 1000 then
displ_mem = round(mem_now.used / 1024 * 1.048576, 1) .. "G"
else
displ_mem = math.floor(mem_now.used * 1.048676)
end
widget:set_text("☢" .. displ_mem)
end
}
my_mem = wibox.container.margin(
wibox.widget {
align = "center",
widget = mmr.widget
})
my_mem.top = 0
-- Battery widget stuff
my_bat = wibox.container.margin()
my_bat.top = 0
my_bat_tip = awful.tooltip({ objects = {my_bat}})
my_bat.visible = true
--local ff_tabs = os.getenv("HOME") .. "/.config/awesome/bin/helpers.sh firefox_tabs"
local pm_tabs = os.getenv("HOME") .. "/.config/awesome/bin/helpers.sh pm_tabs"
DPMS = 0
sleep = 0
check_tabs = {"youtube.com", "192.168.1.10"}
tabs = {}
luakit_yt = false
fullscreenClient = false
redshift = true
btt = lain.widget.bat({
timeout = 60,
settings=function()
if awesome.hostname ~= "arch" then
widget:set_text("b: " .. bat_now.perc .. "%")
if bat_now.perc == 100 then
widget:set_text("b: " .. " F")
end
else
bat_now.ac_status = 0
widget:set_text("⚕")
end
widget:set_align("center")
triggerTab = false
if suspend ~= "manually" then
if awesome.startup then
if bat_now.ac_status == 1 then
xset = true
else
xset = false
end
else
awful.spawn.with_line_callback(pm_tabs, {
stdout = function(line)
tabs = line
loadstring(tabs)()
end})
end
local apps = {"Vlc", "Deadbeef", "mpv"}
local roles = {"CallWindow"} --Skype's call window
local clients = client.get()
local i = 0
for _, clientsValue in pairs(clients) do
for _, appsValue in pairs(apps) do
if clientsValue.class == appsValue then
i = i + 1
end
end
if clientsValue.fullscreen then
fullscreenClient = true
break
else
fullscreenClient = false
end
for _, rolesValue in pairs(roles) do
if clientsValue.role == rolesValue then
i = i + 1
end
end
end
if fullscreenClient and redshift then
awful.spawn("redshift -x >/dev/null 2>&1")
redshift = false
elseif not fullscreenClient and not redshift then
awful.spawn("redshift -o >/dev/null 2>&1")
redshift = true
end
for _, checkTab in pairs(check_tabs) do
for _,currTab in pairs(tabs) do
if currTab == checkTab then
triggerTab = true
end
end
end
if i > 0 or triggerTab or luakit_yt or fullscreenClient and suspend == "enabled" then
awful.spawn("xset -dpms")
awful.spawn("xset s off")
awful.spawn("xautolock -disable")
suspend = "disabled"
my_bat.root.bgd:set_bg("#7A4000")
my_bat_tip:set_text("DPMS\t" .. suspend .. "\nSleep\t" .. suspend)
elseif i == 0 and not triggerTab and not luakit_yt and not fullscreenClient and suspend == "disabled" then
awful.spawn("xautolock -enable")
awful.spawn("xset +dpms")
--awful.spawn("xset s " .. DPMS)
suspend = "enabled"
my_bat.root.bgd:set_bg(theme.bg_normal)
my_bat_tip:set_text("DPMS\t" .. string.format("%.0f", DPMS/60) .. " min\nSleep\t" .. sleep)
-- end
end
if suspend == "enabled" then
if bat_now.ac_status == 1 and xset then -- transition from battery to ac
DPMS=300
awful.spawn("xset -dpms")
--awful.spawn("xset s " .. DPMS)
awful.spawn("xautolock -disable")
sleep="disabled"
xset = false
if not awesome.startup then
naughty.notify({text = "Power connected"})
end
my_bat_tip:set_text("DPMS\t" .. string.format("%.0f", DPMS/60) .. " min\nSleep\t" .. sleep)
elseif bat_now.ac_status == 0 and not xset then --transition from ac to battery
DPMS=180
awful.spawn("xset +dpms")
--awful.spawn("xset s " .. DPMS)
awful.spawn("xautolock -enable")
sleep="5 min"
xset = true
if not awesome.startup then
naughty.notify({text = "Power disconnected"})
end
my_bat_tip:set_text("DPMS\t" .. string.format("%.0f", DPMS/60) .. " min\nSleep\t" .. sleep)
end
end
end
bat_notification_low_preset = {fg = "#ffffff",bg = "#ff0000", title = "Battery low", text = "Plug the cable!"}
bat_notification_critical_preset = {fg = "#202020",bg = "#CDCDCD", title = "Battery exhausted", text = "Shutdown imminent"}
end
})
my_bat:setup {
{
{
id = "lain_bat",
widget = btt.widget
},
id = "bgd",
widget = wibox.container.background
},
id = "root",
layout = wibox.layout.fixed.vertical
}
my_bat.root.bgd.forced_height=25
my_bat:buttons(gears.table.join(
awful.button({ }, 1, function() --click to disable suspend
if suspend == "enabled" then
awful.spawn("xset -dpms")
awful.spawn("xautolock -disable")
suspend = "manually"
my_bat.root.bgd:set_bg("#7A4000")
my_bat_tip:set_text("DPMS\t" .. suspend .. "\nSleep\t" .. suspend)
else
awful.spawn("xset +dpms")
--awful.spawn("xset s " .. DPMS)
awful.spawn("xautolock -enable")
suspend = "enabled"
my_bat.root.bgd:set_bg(theme.bg_normal)
my_bat_tip:set_text("DPMS\t" .. string.format("%.0f", DPMS/60) .. " min\nSleep\t" .. sleep)
end
end)
))
-- Systray widget
systray = wibox.container.margin()
systray:setup {
id = "sstr",
widget = wibox.widget.systray()
}
systray.sstr:set_horizontal(false)
if awesome.hostname == "arch" then
systray.left = 13
systray.right = 13
elseif awesome.hostname == "laptop" then
systray.left = 14
systray.right = 14
end
-- Server monitoring widget
awful.widget.watch('bash -c "cat $HOME/.bin/temp/server_status"', 300, function(widget, stdout)
local avg_bg = theme.bg_normal
local temp_bg = theme.bg_normal
local hdd_bg = theme.bg_normal
local upd_bg = theme.bg_normal
local ram_bg = theme.bg_normal
srv_mon.root.right:set_color(theme.bg_normal)
local lines = {}
for line in stdout:gmatch("[^\r\n]+") do
lines[#lines + 1] = line
end
if tonumber(lines[5]) > 10 then
upd_bg = "#2943FF"
srv_mon.root.right:set_color(upd_bg)
srv_mon_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn(terminal .. " -e ssh server -t pacaur -Syu --noedit --noconfirm; exit 0") end)
)
srv_mon.root.right:buttons(srv_mon_buttons)
end
if tonumber(string.match(lines[3], "%d+")) > 65 then
temp_bg = "#800000"
srv_mon.root.right:set_color(temp_bg)
end
if tonumber(string.match(lines[7], "%d+")) > 999 then
ram_bg = "#A52A2A"
srv_mon.root.right:set_color(ram_bg)
end
local root, home, backup = string.match(lines[4], "^(%d+)%% (%d+)%% (%d+)%%")
if tonumber(root) > 80 or tonumber(home) > 80 or tonumber(backup) > 80 then
hdd_bg = "#739300"
srv_mon.root.right:set_color(hdd_bg)
end
local five_min_load = string.match(lines[2], "^%d+.%d+, (%d+).%d+")
if tonumber(five_min_load) >= 1 then
avg_bg = "#FF0000"
srv_mon.root.right:set_color(avg_bg)
end
srv_tip:set_markup("SERVER\n" .. lines[1].."<span background='" .. avg_bg .. "'>\nAverage load:\t\t" .. lines[2] .. "</span><span background='"..temp_bg .. "'>\nTemperature:\t\t" .. lines[3] .. "</span><span background='".. hdd_bg .. "'>\nRoot/Home/Backup usage:\t" .. lines[4] .. "</span><span background='" .. upd_bg .. "'>\nUpdates pending:\t".. lines[5] .. "</span>\nWashing:\t\t" .. lines[6]..":00".."<span background='" .. ram_bg.."'>\nRAM:\t\t\t"..lines[7].."</span>\nUpdated at:\t\t" ..lines[8])
end)
awful.widget.watch('bash -c "cat $HOME/.bin/temp/local_status"', 300, function(widget, stdout)
local avg_bg = theme.bg_normal
local temp_bg = theme.bg_normal
local hdd_bg = theme.bg_normal
local upd_bg = theme.bg_normal
local ram_bg = theme.bg_normal
srv_mon.root.right_loc:set_color(theme.bg_normal)
local lines = {}
for line in stdout:gmatch("[^\r\n]+") do
lines[#lines + 1] = line
end
if tonumber(lines[3]) > 10 then
upd_bg = "#2943FF"
srv_mon.root.right_loc:set_color(upd_bg)
srv_mon_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn(terminal .. " -e pacaur -Syu --noedit --noconfirm; exit 0") end)
)
srv_mon.root.right_loc:buttons(srv_mon_buttons)
end
if tonumber(string.match(lines[5], "%d+")) > 65 then
temp_bg = "#800000"
srv_mon.root.right_loc:set_color(temp_bg)
end
local root, home = string.match(lines[4], "^(%d+)%% (%d+)%%")
if tonumber(root) > 80 or tonumber(home) > 80 then
hdd_bg = "#739300"
srv_mon.root.right_loc:set_color(hdd_bg)
srv_mon_buttons = gears.table.join(
awful.button({ }, 1, function () awful.spawn(terminal .. " -e ncdu /") end)
)
srv_mon.root.right_loc:buttons(srv_mon_buttons)
end
local five_min_load = string.match(lines[2], "^%d+.%d+, (%d+).%d+")