-
Notifications
You must be signed in to change notification settings - Fork 0
/
rc.lua
347 lines (301 loc) · 10.7 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
-- Capture variables
local awesome = _G.awesome
local client = _G.client
local root = _G.root
local tag = _G.tag
local screen = _G.screen
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
-- Theme handling library
local beautiful = require("beautiful")
beautiful.init(gears.filesystem.get_configuration_dir() .. "themes/default/theme.lua")
local dpi = require("beautiful.xresources").apply_dpi
-- Widget and layout library
local wibox = require("wibox")
-- Notification library
local naughty = require("naughty")
naughty.config.defaults['icon_size'] = 64
-- User library
local cosy = require("cosy")
local global = require("global")
local rules = require("rules")
local bindings = require("bindings")
local layout = require("layout")
local d = require("cosy.dbg")
awesome.set_preferred_icon_size(global.panel_size)
-- {{{ 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 = "Errors during startup",
text = awesome.startup_errors,
})
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 = "An error occured",
text = tostring(err),
})
in_error = false
end)
end
-- }}}
-- {{{ Variable definitions
local floatgeoms = {}
-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
awful.layout.suit.tile,
awful.layout.suit.max,
layout.popup,
awful.layout.suit.tile.left,
awful.layout.suit.fair,
awful.layout.suit.floating,
-- awful.layout.suit.magnifier,
-- awful.layout.suit.tile.bottom,
-- awful.layout.suit.tile.top,
-- awful.layout.suit.fair.horizontal,
-- awful.layout.suit.spiral,
-- awful.layout.suit.spiral.dwindle,
-- awful.layout.suit.corner.nw,
-- awful.layout.suit.corner.ne,
-- awful.layout.suit.corner.sw,
-- awful.layout.suit.corner.se,
}
-- }}}
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", cosy.util.set_wallpaper)
-- Keyboard map indicator and switcher
local keyboardlayout = awful.widget.keyboardlayout()
function _G.construct_panel(s)
s.cava = cosy.widget.desktop.cava(
s,
{
bars = 100,
enable_interpolation = true,
size = global.panel_size,
position = global.panel_position,
update_time = 0.05
})
local panel_offset = {
x = global.panel_position == "left" and global.panel_size or 0,
y = global.panel_position == "top" and global.panel_size or 0,
}
s.rings = cosy.widget.desktop.rings(s, { x = panel_offset.x + 25, y = panel_offset.y + 20 })
-- Create an imagebox widget which will contain an icon indicating which layout we're using.
-- We need one layoutbox per screen.
s.layoutbox = awful.widget.layoutbox(s)
s.layoutbox:buttons(gears.table.join(
awful.button({ }, 1, function () awful.layout.inc( 1) end),
awful.button({ }, 3, function () awful.layout.inc(-1) end),
awful.button({ }, 4, function () awful.layout.inc( 1) end),
awful.button({ }, 5, function () awful.layout.inc(-1) end)))
local focus_gradient = gears.color.create_linear_pattern({
type = "linear",
from = {0, 0},
to = {global.panel_size, 0},
stops = { {0, beautiful.bg_focus.."f0"}, {1, beautiful.bg_focus.."00"} }
})
local panel_orientation =
(global.panel_position == "left" or global.panel_position == "right")
and "vertical"
or "horizontal"
-- Create a taglist widget
s.taglist = awful.widget.taglist {
screen = s,
filter = awful.widget.taglist.filter.noempty,
buttons = bindings.taglist_mouse,
style = {
align = "center",
bg_normal = beautiful.bg_normal .. "a0",
bg_focus = focus_gradient,
bg_urgent = beautiful.bg_urgent .. "00",
},
layout = wibox.layout.fixed[panel_orientation](),
}
-- Create a tasklist widget
s.tasklist = awful.widget.tasklist {
screen = s,
filter = awful.widget.tasklist.filter.currenttags,
buttons = bindings.tasklist_mouse,
style = {
align = "center",
disable_task_name = true,
bg_normal = "#00000000",
bg_focus = focus_gradient,
bg_urgent = beautiful.bg_urgent .. "00",
},
layout = wibox.layout.fixed[panel_orientation]()
}
s.systray = wibox.widget.systray()
-- remove old panel
if s.panel then s.panel:remove() end
local panel_properties = {
screen = s,
position = global.panel_position,
bg = beautiful.bg_normal .. "a0", -- bg with alpha
}
if global.panel_position == "left" or global.panel_position == "right" then
panel_properties.width = global.panel_size
else
panel_properties.height = global.panel_size
end
-- create new panel
s.panel = awful.wibar(panel_properties)
-- Add widgets to the wibox
s.panel:setup {
layout = wibox.layout.align[panel_orientation],
{ -- Left widgets
layout = wibox.layout.fixed[panel_orientation],
s.taglist,
},
s.tasklist, -- Middle widget
{ -- Right widgets
layout = wibox.layout.fixed[panel_orientation],
cosy.widget.panel.volume({
indicator_width = dpi(2),
indicator_offset = dpi(5),
}),
cosy.widget.panel.battery({}),
keyboardlayout,
s.systray,
cosy.widget.textclock,
s.layoutbox,
},
}
end
awful.screen.connect_for_each_screen(function(s)
-- Wallpaper
cosy.util.set_wallpaper(s)
-- Each screen has its own tag table.
awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
_G.construct_panel(s)
end)
-- {{{ Set bindings
root.buttons(bindings.mouse.global)
root.keys(bindings.keyboard.global)
-- }}}
awful.rules.rules = rules
-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c)
-- Set the windows at the slave,
if not awesome.startup then awful.client.setslave(c) end
-- Set floating if slave window is created on popup layout
-- TODO: Consider if more elegant solution is possible
if awful.layout.get(c.screen) == layout.popup
and cosy.util.table_count(c.first_tag:clients()) > 1
then
c.floating = true
awful.placement.no_offscreen(c)
end
-- Save floating client geometry
if cosy.util.client_free_floating(c) then
floatgeoms[c.window] = c:geometry()
end
if awesome.startup
and not c.size_hints.user_position
and not c.size_hints.program_position
then
-- Prevent clients from being unreachable after screen count changes.
awful.placement.no_offscreen(c)
end
end)
-- FIXME: Exclude titlebar from geometry
-- XXX: There seems to be a weird behavior with property::floating signal. It is not sent when maximized and fullscreen
-- property changes of clients originally created on other than floating tag layouts and sent otherwise
client.connect_signal("property::floating", function(c)
if cosy.util.client_free_floating(c) then
c:geometry(floatgeoms[c.window])
end
cosy.util.manage_titlebar(c)
end)
tag.connect_signal("property::layout", function(t)
for _, c in pairs(t:clients()) do
if cosy.util.client_free_floating(c) then
c:geometry(floatgeoms[c.window])
end
cosy.util.manage_titlebar(c)
end
end)
client.connect_signal("property::geometry", function(c)
if cosy.util.client_free_floating(c) then
floatgeoms[c.window] = c:geometry()
end
end)
client.connect_signal("unmanage", function(c)
floatgeoms[c.window] = nil
awful.client.focus.byidx(-1)
end)
-- Add a titlebar if titlebars_enabled is set to true in the rules.
client.connect_signal("request::titlebars", function(c)
-- buttons for the titlebar
local buttons = gears.table.join(
awful.button({ }, 1, function()
client.focus = c
c:raise()
awful.mouse.client.move(c)
end),
awful.button({ }, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end)
)
awful.titlebar(c) : setup {
{ -- Left
awful.titlebar.widget.iconwidget(c),
buttons = buttons,
layout = wibox.layout.fixed.horizontal
},
{ -- Middle
{ -- Title
align = "center",
widget = awful.titlebar.widget.titlewidget(c)
},
buttons = buttons,
layout = wibox.layout.flex.horizontal
},
{ -- Right
awful.titlebar.widget.floatingbutton (c),
awful.titlebar.widget.stickybutton (c),
awful.titlebar.widget.ontopbutton (c),
awful.titlebar.widget.minimizebutton (c),
awful.titlebar.widget.maximizedbutton(c),
awful.titlebar.widget.closebutton (c),
layout = wibox.layout.fixed.horizontal()
},
layout = wibox.layout.align.horizontal
}
-- Hide titlebar if client is not floating
local l = awful.layout.get(c.screen)
if not (c.floating or l == awful.layout.suit.floating) then
awful.titlebar.hide(c)
end
end)
-- Enable sloppy focus, so that focus follows mouse.
client.connect_signal("mouse::enter", function(c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c) then
client.focus = c
end
end)
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)
-- }}}
-- {{{ Startup applications
awful.spawn.spawn("setxkbmap -layout us,ru -variant colemak, -option 'grp:toggle'")
awful.spawn.once("picom --experimental-backends")
awful.spawn.once("nm-applet")
awful.spawn.once("telegram-desktop")
-- }}}