-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.lua
288 lines (263 loc) Β· 10 KB
/
main.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
-- Standard awesome library
local wibox = require("wibox")
local gears = require("gears")
local awful = require("awful")
local menubar = require("menubar")
naughty = require("naughty")
log = require("log")
scheduler = require('scheduler')
private = require('private')
vista = require('vista')
require("awful.autofocus")
local beautiful = require('beautiful')
local utility = require("utility")
local cmd = utility.cmd
userdir = utility.pslurp("echo $HOME", "*line")
local quake = require("quake")
local currencies = require("currencies")
local dict = require("dict")
local minitray = require('minitray')
local statusbar = require('statusbar')
local lustrous = require('lustrous')
local smartmenu = require('smartmenu')
local rulez = require('rulez')
-- Map useful functions outside
calc = utility.calc
money = currencies.recalc
conv = utility.conversion
-- Autorun programs
local autorunApps = {
"setxkbmap -layout 'us,ua,ru' -variant ',winkeys,winkeys' -option grp:menu_toggle -option compose:ralt",
'sleep 2; xkbset m; xmodmap ~/.xmodmap'
}
local runOnceApps = {
'hexchat',
'mpd',
'xrdb -merge ~/.Xresources',
'mpdscribble',
'kbdd',
'/usr/bin/avfsd -o intr -o sync_read ' .. userdir .. '/.avfs',
'megasync',
'xscreensaver -no-splash',
'pulseaudio --start',
'redshift -l 60.8:10.7 -m vidmode -t 6500:5000',
}
utility.autorun(autorunApps, runOnceApps)
-- Theme initialization
lustrous.init(private.user.loc)
utility.load_theme("devotion")
-- Configure screens
vista.setup {
{ rule = { name = "LVDS1" },
properties = { secondary = true } },
{ rule = { name = "eDP1" },
properties = { secondary = true } },
{ rule = { name = "VGA1" },
properties = { primary = true } },
{ rule = { name = "DP1" },
properties = { primary = true } },
{ rule = { ratio = "1.6" },
properties = { wallpaper = beautiful.wallpapers[1] } },
{ rule = { ratio = "1.61+" },
properties = { wallpaper = beautiful.wallpapers[2] } },
{ rule = {},
properties = { wallpaper = beautiful.wallpapers[1],
statusbar = { position = "right", width = vista.scale(58) } } } }
-- Wallpaper
for s = 1, screen.count() do
gears.wallpaper.maximized(vista[s].wallpaper, s, true)
end
-- Default system software
software = { terminal = "urxvt",
terminal_cmd = "urxvt -e ",
terminal_quake = "urxvt",
editor = "ec",
editor_cmd = "ec ",
browser = "chromium",
browser_cmd = "chromium " }
-- Table of layouts to cover with awful.layout.inc, order matters.
layouts = {
awful.layout.suit.floating,
awful.layout.suit.tile,
awful.layout.suit.tile.bottom,
awful.layout.suit.max.fullscreen,
}
-- Tags
tags = {}
do
local f, t, b, fs = layouts[1], layouts[2], layouts[3], layouts[4]
for s = 1, screen.count() do
tags[s] = awful.tag(
{ " π ", " π ", " π ", " π ", " π ", " π "}, s,
{ f , f , f , f , f , f })
end
end
-- Statusbar
for s = 1, screen.count() do
statusbar.create(s, vista[s].statusbar)
end
-- Configure menubar
menubar.cache_entries = true
menubar.app_folders = { "/usr/share/applications/",
awful.util.getdir("config") .. "/scripts/" }
menubar.show_categories = false
-- Interact with snap script
function snap(filename)
naughty.notify { title = "Screenshot captured: " .. filename:match(".+/(.+)"),
text = "Left click to upload",
timeout = 10,
icon_size = 200,
icon = filename,
run = function(notif)
asyncshell.request("imgurbash " .. filename,
function(f)
local t = utility.slurp(f, "*line")
os.execute("echo " .. t .. " | xclip")
naughty.notify { title = "Image uploaded",
text = t }
end )
naughty.destroy(notif)
end }
end
-- Key bindings
globalkeys = utility.keymap(
-- Tag/client navigation
"M-Left", function() utility.view_non_empty(-1) end,
"M-Right", function() utility.view_non_empty(1) end,
"M-Tab", awful.tag.history.restore,
"M-Up", function() awful.client.focus.byidx(1) utility.refocus() end,
"M-Down", function() awful.client.focus.byidx(-1) utility.refocus() end,
"M-j", function() awful.client.focus.byidx(1) utility.refocus() end,
"M-k", function() awful.client.focus.byidx(-1) utility.refocus() end,
"M-d", function() utility.view_first_empty() end,
"M-u", awful.client.urgent.jumpto,
"M-i", function() vista.jump_cursor() end,
"M-Tab", function() awful.client.focus.history.previous() utility.refocus() end,
"M-C-n", awful.client.restore,
-- Application launching
"XF86Launch1", function() utility.spawn_in_terminal("ncmpc") end,
"Scroll_Lock", smartmenu.show,
"XF86LaunchB", smartmenu.show,
"M-p", function() menubar.show() end,
"M-=", dict.lookup_word,
"Print", function() awful.util.spawn("snap " .. os.date("%Y%m%d_%H%M%S")) end,
"M-Return", function ()
quake.toggle({ terminal = software.terminal_quake,
name = "URxvt",
height = 0.5,
skip_taskbar = true,
ontop = true })
end,
"M-r", function ()
local promptbox = statusbar[mouse.screen].widgets.prompt
awful.prompt.run({ prompt = promptbox.prompt },
promptbox.widget,
function (...)
local result = awful.util.spawn(...)
if type(result) == "string" then
promptbox.widget:set_text(result)
end
end,
awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end,
"M-x", function ()
awful.prompt.run({ prompt = "Run Lua code: " },
statusbar[mouse.screen].widgets.prompt.widget,
awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval")
end,
-- Miscellaneous
"XF86ScreenSaver", cmd(userdir .. "/scripts/screenlock"),
"XF86MonBrightnessDown", cmd("xbacklight -" .. rc.xbacklight_step),
"XF86MonBrightnessUp", cmd("xbacklight +" .. rc.xbacklight_step),
"XF86AudioLowerVolume", function() statusbar[mouse.screen].widgets.vol:dec() end,
"XF86AudioRaiseVolume", function() statusbar[mouse.screen].widgets.vol:inc() end,
"XF86AudioMute", function() statusbar[mouse.screen].widgets.vol:toggle() end,
rc.keys.lock, cmd("xscreensaver-command -lock"),
"M-l", minitray.toggle,
"M-space", function()
awful.layout.inc(layouts, 1)
naughty.notify { title = "Layout changed", timeout = 2,
text = "Current layout: " .. awful.layout.get(mouse.screen).name }
end,
"M-b", function()
statusbar[mouse.screen].wibox.visible = not statusbar[mouse.screen].wibox.visible
end
)
clientkeys = utility.keymap(
"M-f", function (c) c.fullscreen = not c.fullscreen end,
"M-S-c", function (c) c:kill() end,
"M-C-space", awful.client.floating.toggle,
"M-o", function(c) vista.movetoscreen(c, nil, true) end,
"M-S-o", vista.movetoscreen,
"M-q", rulez.remember,
"M-t", function (c) c.ontop = not c.ontop end,
"M-n", function (c) c.minimized = true end,
"M-m", function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end
)
-- Compute the maximum number of digit we need, limited to 9
local keynumber = 0
for s = 1, screen.count() do
keynumber = math.min(9, math.max(#tags[s], keynumber));
end
-- Bind all key numbers to tags.
for i = 1, keynumber do
globalkeys = utility.keymap(
globalkeys,
"M-#" .. i + 9, function ()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewonly(tags[screen][i])
end
end,
"M-C-#" .. i + 9, function ()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewtoggle(tags[screen][i])
end
end,
"M-S-#" .. i + 9, function ()
if client.focus and tags[client.focus.screen][i] then
awful.client.movetotag(tags[client.focus.screen][i])
end
end
)
end
clientbuttons = utility.keymap(
"LMB", function (c) client.focus = c; c:raise() end,
"M-LMB", awful.mouse.client.move,
"M-RMB", awful.mouse.client.resize)
statusbar[1].widgets.mpd:append_global_keys()
root.keys(globalkeys)
-- Rules
rulez.init({ { rule = { },
properties = { border_width = beautiful.border_width,
border_color = beautiful.border_normal,
size_hints_honor = false,
focus = true,
keys = clientkeys,
buttons = clientbuttons } } })
-- Signals
client.connect_signal("manage",
function (c, startup)
-- Enable sloppy focus
-- c: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)
if not startup then
-- Put windows in a smart way, only if they does not set an initial position.
if not c.size_hints.user_position and not c.size_hints.program_position then
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
end
end)
scheduler.start()