-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrc.lua
798 lines (728 loc) · 19.1 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
-- ░█▄█░█▀█░█▀▄░█▀▀░█▀▀░█▀█░█▀█░█▀█░▀█▀░▀░█▀▀░░░█▀█░█░█░█▀▀░█▀▀░█▀█░█▄█░█▀▀
-- ░█░█░█░█░█▀▄░▀▀█░█▀▀░█░█░█▀█░█▀▀░░█░░░░▀▀█░░░█▀█░█▄█░█▀▀░▀▀█░█░█░█░█░█▀▀
-- ░▀░▀░▀▀▀░▀▀░░▀▀▀░▀▀▀░▀░▀░▀░▀░▀░░░▀▀▀░░░▀▀▀░░░▀░▀░▀░▀░▀▀▀░▀▀▀░▀▀▀░▀░▀░▀▀▀
-- >> The file that binds everything together.
local awesome = awesome
local client = client
local screen = screen
local decorations = {}
-- User variables and preferences
-- ===================================================================
user = {
terminal = "wezterm start --always-new-process",
floating_terminal = "wezterm start --class floating_terminal",
scratchpad_terminal = "wezterm start --class scratchpad",
editor = "wezterm start --class editor -e hx",
browser = "firefox",
file_manager = "pcmanfm",
term_filemanager = "wezterm start --class term_filemanager -e yazi",
visual_editor = "",
openweathermap_key = "d1b3b6a81db867259446b0863d5f9108",
openweathermap_city_id = {
"25.6", -- lat
"85.1167", -- lon
},
openweathermap_weather_units = "metric",
lock_screen_custom_password = "awesome",
app_launcher = "rofi -matching fuzzy -show drun",
}
-- Initialization
-- ===================================================================
local beautiful = require("beautiful")
-- Make dpi function global
dpi = beautiful.xresources.apply_dpi
-- Load AwesomeWM libraries
local gears = require("gears")
local gfs = require("gears.filesystem")
local awful = require("awful")
require("awful.autofocus")
-- Default notification library
local naughty = require("naughty")
-- Load theme
beautiful.init(gfs.get_configuration_dir() .. "themes/gruva/" .. "theme.lua")
-- Error handling
-- ===================================================================
naughty.connect_signal("request::display_error", function(message, startup)
naughty.notification({
urgency = "critical",
title = "Oops, an error happened" .. (startup and " during startup!" or "!"),
message = message,
})
end)
-- Features
-- ===================================================================
-- Load helper functions
local helpers = require("helpers")
-- Apps
apps = {
-- TODO: switchtotag not working?
browser = function()
awful.spawn(user.browser, { switchtotag = true })
end,
file_manager = function()
awful.spawn(user.file_manager, { floating = true })
end,
term_filemanager = function()
awful.spawn(user.term_filemanager, { floating = true })
end,
editor = function()
helpers.run_or_raise({ instance = "editor" }, false, user.editor, { switchtotag = true })
end,
visual_editor = function()
helpers.run_or_raise({ class = "" }, false, user.visual_editor, { switchtotag = true })
end,
volume = function()
helpers.run_or_raise({ class = "Pavucontrol" }, true, "pavucontrol")
end,
process_monitor = function()
helpers.run_or_raise(
{ instance = "bottom" },
false,
user.terminal .. " --class bottom -e btm",
{ switchtotag = true }
)
end,
screenshot_full = function()
awful.spawn.with_shell("maim -s | swappy -f -")
end,
screenshot_clipboard = function()
awful.spawn.with_shell("maim -s | xclip -selection clipboard -t image/png")
end,
clipboard = function()
awful.spawn.with_shell("clipmenu")
end,
emoji_picker = function()
awful.spawn("rofi -show emoji")
end,
}
-- Confuguration folder
require("themes/gruva")
-- Keybinds and mousebinds
local keys = require("keys")
-- Lock screen
-- Make sure to install lua-pam as described in the README or configure your
-- custom password in the 'user' section above
require("modules.lockscreen")
-- Window switcher
require("modules.window_switcher")
-- Notification center
require("modules.notification_center")
-- Daemons
-- Most widgets that display system/external info depend on evil.
-- Make sure to initialize it last in order to allow all widgets to connect to
-- their needed evil signals.
require("evil")
-- Get screen geometry
-- I am using a single screen setup and I assume that screen geometry will not
-- change during the session.
local screen_width = awful.screen.focused().geometry.width
local screen_height = awful.screen.focused().geometry.height
-- Layouts
-- ===================================================================
-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
awful.layout.suit.tile,
awful.layout.suit.floating,
awful.layout.suit.max,
--awful.layout.suit.spiral,
--awful.layout.suit.spiral.dwindle,
--awful.layout.suit.tile.top,
--awful.layout.suit.fair,
--awful.layout.suit.fair.horizontal,
--awful.layout.suit.tile.left,
--awful.layout.suit.tile.bottom,
--awful.layout.suit.max.fullscreen,
--awful.layout.suit.corner.nw,
--awful.layout.suit.magnifier,
--awful.layout.suit.corner.ne,
--awful.layout.suit.corner.sw,
--awful.layout.suit.corner.se,
}
-- Wallpaper
-- ===================================================================
local function set_wallpaper(s)
if beautiful.wallpaper then
local wallpaper = beautiful.wallpaper
-- If wallpaper is a function, call it with the screen
if type(wallpaper) == "function" then
wallpaper = wallpaper(s)
end
-- >> Method 1: Built in wallpaper function
gears.wallpaper.maximized(wallpaper, s, true)
-- >> Method 2: Set theme's wallpaper with feh
-- awful.spawn.with_shell("feh --bg-fill " .. wallpaper)
-- >> Method 3: Set last wallpaper with feh
-- awful.spawn.with_shell(os.getenv("HOME") .. "/.fehbg")
end
end
-- Set wallpaper
awful.screen.connect_for_each_screen(function(s)
set_wallpaper(s)
end)
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", set_wallpaper)
-- Tags
-- ===================================================================
awful.screen.connect_for_each_screen(function(s)
-- Each screen has its own tag table.
local l = awful.layout.suit -- Alias to save time :)
-- Tag layouts
local layouts = {
l.max,
l.max,
l.max,
l.max,
l.max,
l.max,
l.tile,
l.tile,
l.tile,
l.tile,
}
-- Tag names
local tagnames = beautiful.tagnames or { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }
-- Create all tags at once (without seperate configuration for each tag)
awful.tag(tagnames, s, layouts)
-- Create tags with seperate configuration for each tag
-- awful.tag.add(tagnames[1], {
-- layout = layouts[1],
-- screen = s,
-- master_width_factor = 0.6,
-- selected = true,
-- })
-- ...
end)
-- Determines how floating clients should be placed
local floating_client_placement = function(c)
-- If the layout is floating or there are no other visible
-- clients, center client
if awful.layout.get(mouse.screen) ~= awful.layout.suit.floating or #mouse.screen.clients == 1 then
return awful.placement.centered(c, { honor_padding = true, honor_workarea = true })
end
-- Else use this placement
local p = awful.placement.no_overlap + awful.placement.no_offscreen
return p(c, { honor_padding = true, honor_workarea = true, margins = beautiful.useless_gap * 2 })
end
local centered_client_placement = function(c)
return gears.timer.delayed_call(function()
awful.placement.centered(c, { honor_padding = true, honor_workarea = true })
end)
end
-- Rules
-- ===================================================================
-- Rules to apply to new clients (through the "manage" signal).
awful.rules.rules = {
{
-- All clients will match this rule.
rule = {},
properties = {
border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = awful.client.focus.filter,
raise = true,
keys = keys.clientkeys,
buttons = keys.clientbuttons,
screen = awful.screen.focused,
size_hints_honor = false,
honor_workarea = true,
honor_padding = true,
maximized = false,
titlebars_enabled = beautiful.titlebars_enabled,
maximized_horizontal = false,
maximized_vertical = false,
placement = floating_client_placement,
},
},
-- Floating clients
{
rule_any = {
instance = {
"floating_terminal",
"Devtools", -- Firefox devtools
},
class = {
"Gpick",
"Lxappearance",
"Nm-connection-editor",
"File-roller",
"fst",
"Nvidia-settings",
},
name = {
"Event Tester", -- xev
"MetaMask Notification",
"Picture in picture",
},
role = {
"AlarmWindow",
"pop-up",
"GtkFileChooserDialog",
"conversation",
},
type = {
"dialog",
},
},
properties = { floating = true },
},
-- Fullscreen clients
{
rule_any = {
class = {
"dota2",
"dontstarve_steam",
},
instance = {
"synthetik.exe",
},
},
properties = { fullscreen = true },
},
-- Centered clients
{
rule_any = {
type = {
"dialog",
},
class = {
"Steam",
"discord",
"music",
"scratchpad",
},
instance = {
"music",
"scratchpad",
},
role = {
"GtkFileChooserDialog",
"conversation",
},
},
properties = { placement = centered_client_placement },
},
-- Titlebars ON (explicitly)
{
rule_any = {
type = {
"dialog",
},
role = {
"conversation",
},
},
callback = function(c)
decorations.show(c)
end,
},
-- "Needy": Clients that steal focus when they are urgent
{
rule_any = {
class = {
"TelegramDesktop",
"firefox",
"Nightly",
},
type = {
"dialog",
},
},
callback = function(c)
c:connect_signal("property::urgent", function()
if c.urgent then
c:jump_to()
end
end)
end,
},
-- Fixed terminal geometry for floating terminals
{
rule_any = {
class = {
"Alacritty",
"Termite",
"mpvtube",
"kitty",
"st-256color",
"st",
"URxvt",
},
},
properties = { width = screen_width * 0.45, height = screen_height * 0.5 },
},
-- File chooser dialog
{
rule_any = { role = { "GtkFileChooserDialog" } },
properties = { floating = true, width = screen_width * 0.55, height = screen_height * 0.65 },
},
-- Pavucontrol
{
rule_any = { class = { "Pavucontrol" } },
properties = { floating = true, width = screen_width * 0.45, height = screen_height * 0.8 },
},
-- Galculator
{
rule_any = { class = { "Galculator" } },
except_any = { type = { "dialog" } },
properties = { floating = true, width = screen_width * 0.2, height = screen_height * 0.4 },
},
-- File managers
{
rule_any = {
class = {
"Pcmanfm",
"Nemo",
"Thunar",
},
},
except_any = {
type = { "dialog" },
},
properties = { floating = true, width = screen_width * 0.45, height = screen_height * 0.55 },
},
-- Scratchpad
{
rule_any = {
instance = {
"scratchpad",
"markdown_input",
},
class = {
"scratchpad",
"markdown_input",
},
},
properties = {
skip_taskbar = false,
floating = true,
ontop = false,
minimized = true,
sticky = false,
width = screen_width * 0.7,
height = screen_height * 0.75,
},
},
-- Music clients (usually a terminal running ncmpcpp)
{
rule_any = {
class = {
"music",
},
instance = {
"music",
},
},
properties = {
floating = true,
width = screen_width * 0.45,
height = screen_height * 0.50,
},
},
-- Image viewers
{
rule_any = {
class = {
"feh",
"Sxiv",
},
},
properties = {
floating = true,
width = screen_width * 0.7,
height = screen_height * 0.75,
},
callback = function(c)
awful.placement.centered(c, { honor_padding = true, honor_workarea = true })
end,
},
-- Steam guard
{
rule = { name = "Steam Guard - Computer Authorization Required" },
properties = { floating = true },
-- Such a stubborn window, centering it does not work
-- callback = function(c)
-- gears.timer.delayed_call(function()
-- awful.placement.centered(c,{honor_padding = true, honor_workarea=true})
-- end)
-- end
},
-- MPV
{
rule = { class = "mpv" },
properties = {},
callback = function(c)
-- Make it floating, ontop and move it out of the way if the current tag is maximized
if awful.layout.get(awful.screen.focused()) == awful.layout.suit.max then
c.floating = true
c.ontop = true
c.width = screen_width * 0.30
c.height = screen_height * 0.35
awful.placement.bottom_right(c, {
honor_padding = true,
honor_workarea = true,
margins = { bottom = beautiful.useless_gap * 2, right = beautiful.useless_gap * 2 },
})
end
-- Restore `ontop` after fullscreen is disabled
-- Sorta tries to fix: https://github.com/awesomeWM/awesome/issues/667
c:connect_signal("property::fullscreen", function()
if not c.fullscreen then
c.ontop = true
end
end)
end,
},
-- Start application on specific workspace
-- ===================================================================
-- Browsing
{
rule_any = {
class = {
"firefox",
"Nightly",
"Vivaldi-stable",
},
},
except_any = {
role = { "GtkFileChooserDialog" },
instance = { "Toolkit" },
type = { "dialog" },
},
properties = { screen = 1, tag = awful.screen.focused().tags[1] },
},
-- Editing
{
rule_any = {
class = {
"^editor$",
"VSCodium",
},
},
properties = { screen = 1, tag = awful.screen.focused().tags[2] },
},
-- Games
{
rule_any = {
class = {
"Wine",
},
instance = {},
},
properties = { screen = 1, tag = awful.screen.focused().tags[3] },
},
-- Chatting
{
rule_any = {
class = {
"discord",
"Signal",
"Slack",
"zoom",
},
},
properties = { screen = 1, tag = awful.screen.focused().tags[4] },
},
-- System monitoring
{
rule_any = {
class = {
"htop",
"bottom",
},
instance = {
"htop",
"bottom",
},
},
properties = { screen = 1, tag = awful.screen.focused().tags[5] },
},
-- Image editing
{
rule_any = {
class = {
"Gimp",
},
},
properties = { screen = 1, tag = awful.screen.focused().tags[6] },
},
-- Mail
{
rule_any = {
class = {
"email",
},
instance = {
"email",
},
},
properties = { screen = 1, tag = awful.screen.focused().tags[7] },
},
-- Game clients/launchers
{
rule_any = {
class = {
"Steam",
"battle.net.exe",
"Lutris",
},
name = {
"Steam",
},
},
properties = { screen = 1, tag = awful.screen.focused().tags[8] },
},
-- Miscellaneous
-- All clients that I want out of my way when they are running
{
rule_any = {
class = {
"torrent",
"Transmission",
"Deluge",
"VirtualBox Manager",
"KeePassXC",
},
instance = {
"torrent",
"qemu",
},
},
except_any = {
type = { "dialog" },
},
properties = { screen = 1, tag = awful.screen.focused().tags[10] },
},
}
-- Signals
-- ===================================================================
if beautiful.border_width > 0 then
client.connect_signal("focus", function(c)
c.border_color = beautiful.border_focus
end)
client.connect_signal("unfocus", function(c)
c.border_color = beautiful.border_normal
end)
end
-- Set mouse resize mode (live or after)
awful.mouse.resize.set_mode("live")
-- Restore geometry for floating clients
-- (for example after swapping from tiling mode to floating mode)
tag.connect_signal("property::layout", function(t)
for k, c in ipairs(t:clients()) do
if awful.layout.get(mouse.screen) == awful.layout.suit.floating then
local cgeo = awful.client.property.get(c, "floating_geometry")
if cgeo then
c:geometry(awful.client.property.get(c, "floating_geometry"))
end
end
end
end)
client.connect_signal("manage", function(c)
if awful.layout.get(mouse.screen) == awful.layout.suit.floating then
awful.client.property.set(c, "floating_geometry", c:geometry())
end
end)
client.connect_signal("property::geometry", function(c)
if awful.layout.get(mouse.screen) == awful.layout.suit.floating then
awful.client.property.set(c, "floating_geometry", c:geometry())
end
end)
-- When switching to a tag with urgent clients, raise them.
-- This fixes the issue (visual mismatch) where after switching to
-- a tag which includes an urgent client, the urgent client is
-- unfocused but still covers all other windows (even the currently
-- focused window).
awful.tag.attached_connect_signal(s, "property::selected", function()
local urgent_clients = function(c)
return awful.rules.match(c, { urgent = true })
end
for c in awful.client.iterate(urgent_clients) do
if c.first_tag == mouse.screen.selected_tag then
client.focus = c
end
end
end)
-- Enable sloppy focus, so that focus follows mouse.
-- client.connect_signal("mouse::enter", function(c)
-- c:activate { context = "mouse_enter", raise = false }
-- end)
-- Raise focused clients automatically
client.connect_signal("focus", function(c)
c:raise()
end)
-- Focus all urgent clients automatically
-- client.connect_signal("property::urgent", function(c)
-- if c.urgent then
-- c.minimized = false
-- c:jump_to()
-- end
-- end)
-- Disable ontop when the client is not floating, and restore ontop if needed
-- when the client is floating again
-- I never want a non floating client to be ontop.
client.connect_signal("property::floating", function(c)
if c.floating then
if c.restore_ontop then
c.ontop = c.restore_ontop
end
else
c.restore_ontop = c.ontop
c.ontop = false
end
end)
-- Hide all windows when a splash is shown
awesome.connect_signal("widgets::splash::visibility", function(vis)
local t = screen.primary.selected_tag
if vis then
for idx, c in ipairs(t:clients()) do
c.hidden = true
end
else
for idx, c in ipairs(t:clients()) do
c.hidden = false
end
end
end)
-- Decorations
-- ===================================================================
local wibox = require("wibox")
-- Apply rounded corners to clients if needed
if beautiful.border_radius and beautiful.border_radius > 0 then
client.connect_signal("manage", function(c, startup)
if not c.fullscreen and not c.maximized then
c.shape = helpers.rrect(beautiful.border_radius)
end
end)
-- Fullscreen and maximized clients should not have rounded corners
local function no_round_corners(c)
if c.fullscreen or c.maximized then
c.shape = gears.shape.rectangle
else
c.shape = helpers.rrect(beautiful.border_radius)
end
end
client.connect_signal("property::fullscreen", no_round_corners)
client.connect_signal("property::maximized", no_round_corners)
beautiful.snap_shape = helpers.rrect(beautiful.border_radius * 2)
else
beautiful.snap_shape = gears.shape.rectangle
end
function decorations.show(c)
if not c.custom_decoration or not c.custom_decoration[beautiful.titlebar_position] then
awful.titlebar.show(c, beautiful.titlebar_position)
end
end
-- Dummy titlebar
client.connect_signal("request::titlebars", function(c)
awful.titlebar(c)
end)
-- Startup apps
-- ===================================================================
-- Spawn once
-- awful.spawn.once({}, false)
-- With shell
-- awful.spawn.with_shell({}, false)
-- Garbage collection
-- ===================================================================
collectgarbage("setpause", 110)
collectgarbage("setstepmul", 1000)