Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/awesome/rc.lua
987 views
1
-- Standard awesome library
2
require("awful")
3
require("awful.autofocus")
4
require("awful.rules")
5
-- Theme handling library
6
require("beautiful")
7
-- Notification library
8
require("naughty")
9
require("vicious")
10
require("eminent")
11
-- {{{ Variable definitions
12
-- Themes define colours, icons, and wallpapers
13
beautiful.init("/usr/share/awesome/themes/zenburn/theme.lua")
14
15
-- This is used later as the default terminal and editor to run.
16
terminal = "urxvt"
17
editor = "emacs -nw"
18
editor_cmd = terminal .. " -e " .. editor
19
20
-- Default modkey.
21
-- Usually, Mod4 is the key with a logo between Control and Alt.
22
-- If you do not like this or do not have such a key,
23
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
24
-- However, you can use another modifier like Mod1, but it may interact with others.
25
modkey = "Mod1"
26
27
-- Table of layouts to cover with awful.layout.inc, order matters.
28
layouts =
29
{
30
awful.layout.suit.floating,
31
awful.layout.suit.tile,
32
awful.layout.suit.tile.left,
33
awful.layout.suit.tile.bottom,
34
awful.layout.suit.tile.top,
35
awful.layout.suit.fair,
36
awful.layout.suit.fair.horizontal,
37
awful.layout.suit.spiral,
38
awful.layout.suit.spiral.dwindle,
39
awful.layout.suit.max,
40
awful.layout.suit.max.fullscreen,
41
awful.layout.suit.magnifier
42
}
43
-- }}}
44
45
-- {{{ Tags
46
tags = {
47
names = { "term", "www", "emacs", "docs", "mess", "mail", "rss", "chat" },
48
layout = { layouts[2], layouts[1], layouts[1], layouts[4], layouts[1],
49
layouts[6], layouts[6], layouts[5], layouts[6]
50
}}
51
52
for s = 1, screen.count() do
53
tags[s] = awful.tag(tags.names, s, tags.layout)
54
end
55
-- }}}
56
57
-- {{{ Menu
58
-- Create a laucher widget and a main menu
59
separator = widget({ type = "imagebox" })
60
separator.image = image(beautiful.widget_sep)
61
62
myawesomemenu = {
63
{ "manual", terminal .. " -e man awesome" },
64
{ "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
65
{ "restart", awesome.restart },
66
{ "quit", awesome.quit }
67
}
68
69
mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
70
{ "open terminal", terminal }
71
}
72
})
73
74
-- }}}
75
76
-- {{{ Wibox
77
-- Create a textclock widget
78
-- {{{ Reusable separator
79
separator = widget({ type = "imagebox" })
80
separator.image = image(beautiful.widget_sep)
81
-- }}}
82
mytextclock = awful.widget.textclock({ align = "right" })
83
84
-- Initialize widget
85
memwidget = widget({ type = "textbox" })
86
-- Register widget
87
vicious.register(memwidget, vicious.widgets.mem, "Memory: $1% ($2MB/$3MB)", 13)
88
89
-- Initialize widget
90
cpuwidget = widget({ type = "textbox" })
91
-- Register widget
92
vicious.register(cpuwidget, vicious.widgets.cpu, "$1%")
93
94
-- Create a systray
95
mysystray = widget({ type = "systray" })
96
97
-- Create a wibox for each screen and add it
98
mywibox = {}
99
mywibox2 = {}
100
mypromptbox = {}
101
mylayoutbox = {}
102
mytaglist = {}
103
mytaglist.buttons = awful.util.table.join(
104
awful.button({ }, 1, awful.tag.viewonly),
105
awful.button({ modkey }, 1, awful.client.movetotag),
106
awful.button({ }, 3, awful.tag.viewtoggle),
107
awful.button({ modkey }, 3, awful.client.toggletag),
108
awful.button({ }, 4, awful.tag.viewnext),
109
awful.button({ }, 5, awful.tag.viewprev)
110
)
111
mytasklist = {}
112
mytasklist.buttons = awful.util.table.join(
113
awful.button({ }, 1, function (c)
114
if not c:isvisible() then
115
awful.tag.viewonly(c:tags()[1])
116
end
117
client.focus = c
118
c:raise()
119
end),
120
awful.button({ }, 3, function ()
121
if instance then
122
instance:hide()
123
instance = nil
124
else
125
instance = awful.menu.clients({ width=250 })
126
end
127
end),
128
awful.button({ }, 4, function ()
129
awful.client.focus.byidx(1)
130
if client.focus then client.focus:raise() end
131
end),
132
awful.button({ }, 5, function ()
133
awful.client.focus.byidx(-1)
134
if client.focus then client.focus:raise() end
135
end))
136
137
for s = 1, screen.count() do
138
-- Create a promptbox for each screen
139
mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
140
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
141
-- We need one layoutbox per screen.
142
mylayoutbox[s] = awful.widget.layoutbox(s)
143
mylayoutbox[s]:buttons(awful.util.table.join(
144
awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
145
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
146
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
147
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
148
-- Create a taglist widget
149
mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
150
151
-- Create a tasklist widget
152
mytasklist[s] = awful.widget.tasklist(function(c)
153
return awful.widget.tasklist.label.currenttags(c, s)
154
end, mytasklist.buttons)
155
156
-- Create the wibox
157
mywibox[s] = awful.wibox({ position = "top", screen = s })
158
mywibox2[s] = awful.wibox({ position = "bottom", screen = s })
159
160
-- Add widgets to the wibox - order matters
161
mywibox[s].widgets = {
162
{
163
mytaglist[s],
164
mypromptbox[s],
165
layout = awful.widget.layout.horizontal.leftright
166
},
167
mylayoutbox[s],
168
mytextclock,
169
s == 1 and mysystray or nil,
170
mytasklist[s],
171
layout = awful.widget.layout.horizontal.rightleft
172
}
173
mywibox2[s].widgets = {
174
{
175
memwidget
176
}
177
}
178
end
179
-- }}}
180
181
-- {{{ Mouse bindings
182
root.buttons(awful.util.table.join(
183
awful.button({ }, 3, function () mymainmenu:toggle() end),
184
awful.button({ }, 4, awful.tag.viewnext),
185
awful.button({ }, 5, awful.tag.viewprev)
186
))
187
-- }}}
188
189
-- {{{ Key bindings
190
globalkeys = awful.util.table.join(
191
awful.key({ modkey, }, "Left", awful.tag.viewprev ),
192
awful.key({ modkey, }, "Right", awful.tag.viewnext ),
193
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
194
195
awful.key({ modkey, }, "j",
196
function ()
197
awful.client.focus.byidx( 1)
198
if client.focus then client.focus:raise() end
199
end),
200
awful.key({ modkey, }, "k",
201
function ()
202
awful.client.focus.byidx(-1)
203
if client.focus then client.focus:raise() end
204
end),
205
awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
206
207
-- Layout manipulation
208
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
209
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
210
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
211
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
212
awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
213
awful.key({ modkey, }, "Tab",
214
function ()
215
awful.client.focus.history.previous()
216
if client.focus then
217
client.focus:raise()
218
end
219
end),
220
221
-- Standard program
222
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
223
awful.key({ modkey, "Control" }, "r", awesome.restart),
224
awful.key({ modkey, "Shift" }, "q", awesome.quit),
225
226
awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
227
awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
228
awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
229
awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
230
awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
231
awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
232
awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
233
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
234
235
-- Prompt
236
awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
237
238
awful.key({ modkey }, "x",
239
function ()
240
awful.prompt.run({ prompt = "Run Lua code: " },
241
mypromptbox[mouse.screen].widget,
242
awful.util.eval, nil,
243
awful.util.getdir("cache") .. "/history_eval")
244
end)
245
)
246
247
clientkeys = awful.util.table.join(
248
awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
249
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
250
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
251
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
252
awful.key({ modkey, }, "o", awful.client.movetoscreen ),
253
awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
254
awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
255
awful.key({ modkey, }, "n", function (c) c.minimized = not c.minimized end),
256
awful.key({ modkey, }, "m",
257
function (c)
258
c.maximized_horizontal = not c.maximized_horizontal
259
c.maximized_vertical = not c.maximized_vertical
260
end)
261
)
262
263
-- Compute the maximum number of digit we need, limited to 9
264
keynumber = 0
265
for s = 1, screen.count() do
266
keynumber = math.min(9, math.max(#tags[s], keynumber));
267
end
268
269
-- Bind all key numbers to tags.
270
-- Be careful: we use keycodes to make it works on any keyboard layout.
271
-- This should map on the top row of your keyboard, usually 1 to 9.
272
for i = 1, keynumber do
273
globalkeys = awful.util.table.join(globalkeys,
274
awful.key({ modkey }, "#" .. i + 9,
275
function ()
276
local screen = mouse.screen
277
if tags[screen][i] then
278
awful.tag.viewonly(tags[screen][i])
279
end
280
end),
281
awful.key({ modkey, "Control" }, "#" .. i + 9,
282
function ()
283
local screen = mouse.screen
284
if tags[screen][i] then
285
awful.tag.viewtoggle(tags[screen][i])
286
end
287
end),
288
awful.key({ modkey, "Shift" }, "#" .. i + 9,
289
function ()
290
if client.focus and tags[client.focus.screen][i] then
291
awful.client.movetotag(tags[client.focus.screen][i])
292
end
293
end),
294
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
295
function ()
296
if client.focus and tags[client.focus.screen][i] then
297
awful.client.toggletag(tags[client.focus.screen][i])
298
end
299
end))
300
end
301
302
clientbuttons = awful.util.table.join(
303
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
304
awful.button({ modkey }, 1, awful.mouse.client.move),
305
awful.button({ modkey }, 3, awful.mouse.client.resize))
306
307
-- Set keys
308
root.keys(globalkeys)
309
-- }}}
310
311
-- {{{ Rules
312
awful.rules.rules = {
313
-- All clients will match this rule.
314
{ rule = { },
315
properties = { border_width = beautiful.border_width,
316
border_color = beautiful.border_normal,
317
focus = true,
318
keys = clientkeys,
319
buttons = clientbuttons } },
320
{ rule = { class = "MPlayer" },
321
properties = { floating = true } },
322
{ rule = { class = "pinentry" },
323
properties = { floating = true } },
324
{ rule = { class = "gimp" },
325
properties = { floating = true } },
326
-- Set Firefox to always map on tags number 2 of screen 1.
327
-- { rule = { class = "Firefox" },
328
-- properties = { tag = tags[1][2] } },
329
}
330
-- }}}
331
332
-- {{{ Signals
333
-- Signal function to execute when a new client appears.
334
client.add_signal("manage", function (c, startup)
335
-- Add a titlebar
336
-- awful.titlebar.add(c, { modkey = modkey })
337
338
-- Enable sloppy focus
339
c:add_signal("mouse::enter", function(c)
340
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
341
and awful.client.focus.filter(c) then
342
client.focus = c
343
end
344
end)
345
346
if not startup then
347
-- Set the windows at the slave,
348
-- i.e. put it at the end of others instead of setting it master.
349
-- awful.client.setslave(c)
350
351
-- Put windows in a smart way, only if they does not set an initial position.
352
if not c.size_hints.user_position and not c.size_hints.program_position then
353
awful.placement.no_overlap(c)
354
awful.placement.no_offscreen(c)
355
end
356
end
357
end)
358
359
client.add_signal("focus", function(c) c.border_color = beautiful.border_focus end)
360
client.add_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
361
-- }}}
362
363