]> git.rmz.io Git - dotfiles.git/blob - awesome/rc.lua
add awesome configs
[dotfiles.git] / awesome / rc.lua
1 -- Standard awesome library
2 gears = require("gears")
3 awful = require("awful")
4 awful.rules = require("awful.rules")
5 require("awful.autofocus")
6 -- Widget and layout library
7 wibox = require("wibox")
8 -- Theme handling library
9 beautiful = require("beautiful")
10 -- Notification library
11 naughty = require("naughty")
12 menubar = require("menubar")
13 -- Pulseaudio widget
14 --local APW = require("apw/widget")
15
16 -- {{{ Error handling
17 -- Check if awesome encountered an error during startup and fell back to
18 -- another config (This code will only ever execute for the fallback config)
19 if awesome.startup_errors then
20 naughty.notify({ preset = naughty.config.presets.critical,
21 title = "Oops, there were errors during startup!",
22 text = awesome.startup_errors })
23 end
24
25 -- Handle runtime errors after startup
26 do
27 local in_error = false
28 awesome.connect_signal("debug::error", function (err)
29 -- Make sure we don't go into an endless error loop
30 if in_error then return end
31 in_error = true
32
33 naughty.notify({ preset = naughty.config.presets.critical,
34 title = "Oops, an error happened!",
35 text = err })
36 in_error = false
37 end)
38 end
39 -- }}}
40
41 -- {{{ Variable definitions
42 -- Themes define colours, icons, and wallpapers
43 beautiful.init("/usr/share/awesome/themes/default/theme.lua")
44
45 -- This is used later as the default terminal and editor to run.
46 terminal = "konsole"
47 editor = os.getenv("EDITOR") or "vim"
48 editor_cmd = terminal .. " -e " .. editor
49
50 -- Default modkey.
51 -- Usually, Mod4 is the key with a logo between Control and Alt.
52 -- If you do not like this or do not have such a key,
53 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
54 -- However, you can use another modifier like Mod1, but it may interact with others.
55 modkey = "Mod4"
56
57 -- Tags
58 require("tags")
59
60 -- {{{ Wallpaper
61 if beautiful.wallpaper then
62 for s = 1, screen.count() do
63 gears.wallpaper.maximized(beautiful.wallpaper, s, true)
64 end
65 end
66 -- }}}
67
68 -- {{{ Menu
69 -- Create a laucher widget and a main menu
70 myawesomemenu = {
71 { "manual", terminal .. " -e man awesome" },
72 { "edit config", editor_cmd .. " " .. awesome.conffile },
73 { "restart", awesome.restart },
74 { "quit", awesome.quit }
75 }
76
77 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
78 { "open terminal", terminal }
79 }
80 })
81
82 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
83 menu = mymainmenu })
84
85 -- Menubar configuration
86 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
87 -- }}}
88
89 -- {{{ Wibox
90 -- Create a textclock widget
91 mytextclock = awful.widget.textclock()
92
93 -- Create a wibox for each screen and add it
94 mywibox = {}
95
96 -- Create a wibox for each screen and add it
97 mywibox = {}
98 mypromptbox = {}
99 mylayoutbox = {}
100 mytaglist = {}
101 mytaglist.buttons = awful.util.table.join(
102 awful.button({ }, 1, awful.tag.viewonly),
103 awful.button({ modkey }, 1, awful.client.movetotag),
104 awful.button({ }, 3, awful.tag.viewtoggle),
105 awful.button({ modkey }, 3, awful.client.toggletag),
106 awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
107 awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
108 )
109 mytasklist = {}
110 mytasklist.buttons = awful.util.table.join(
111 awful.button({ }, 1, function (c)
112 if c == client.focus then
113 c.minimized = true
114 else
115 -- Without this, the following
116 -- :isvisible() makes no sense
117 c.minimized = false
118 if not c:isvisible() then
119 awful.tag.viewonly(c:tags()[1])
120 end
121 -- This will also un-minimize
122 -- the client, if needed
123 client.focus = c
124 c:raise()
125 end
126 end),
127 awful.button({ }, 3, function ()
128 if instance then
129 instance:hide()
130 instance = nil
131 else
132 instance = awful.menu.clients({ width=250 })
133 end
134 end),
135 awful.button({ }, 4, function ()
136 awful.client.focus.byidx(1)
137 if client.focus then client.focus:raise() end
138 end),
139 awful.button({ }, 5, function ()
140 awful.client.focus.byidx(-1)
141 if client.focus then client.focus:raise() end
142 end))
143
144 for s = 1, screen.count() do
145 -- Create a promptbox for each screen
146 mypromptbox[s] = awful.widget.prompt()
147 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
148 -- We need one layoutbox per screen.
149 mylayoutbox[s] = awful.widget.layoutbox(s)
150 mylayoutbox[s]:buttons(awful.util.table.join(
151 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
152 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
153 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
154 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
155 -- Create a taglist widget
156 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
157
158 -- Create a tasklist widget
159 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
160
161 -- Create the wibox
162 mywibox[s] = awful.wibox({ position = "top", screen = s })
163
164 -- Widgets that are aligned to the left
165 local left_layout = wibox.layout.fixed.horizontal()
166 left_layout:add(mylauncher)
167 left_layout:add(mytaglist[s])
168 left_layout:add(mypromptbox[s])
169
170 -- Widgets that are aligned to the right
171 local right_layout = wibox.layout.fixed.horizontal()
172 if s == 1 then right_layout:add(wibox.widget.systray()) end
173 --right_layout:add(APW)
174 right_layout:add(mytextclock)
175 right_layout:add(mylayoutbox[s])
176
177 -- Now bring it all together (with the tasklist in the middle)
178 local layout = wibox.layout.align.horizontal()
179 layout:set_left(left_layout)
180 layout:set_middle(mytasklist[s])
181 layout:set_right(right_layout)
182
183 mywibox[s]:set_widget(layout)
184 end
185 -- }}}
186
187 -- {{{ Mouse bindings
188 root.buttons(awful.util.table.join(
189 awful.button({ }, 3, function () mymainmenu:toggle() end),
190 awful.button({ }, 4, awful.tag.viewnext),
191 awful.button({ }, 5, awful.tag.viewprev)
192 ))
193 -- }}}
194
195 -- {{{ Key bindings
196 globalkeys = awful.util.table.join(
197 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
198 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
199 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
200
201 awful.key({ modkey, }, "j",
202 function ()
203 awful.client.focus.byidx( 1)
204 if client.focus then client.focus:raise() end
205 end),
206 awful.key({ modkey, }, "k",
207 function ()
208 awful.client.focus.byidx(-1)
209 if client.focus then client.focus:raise() end
210 end),
211 awful.key({ modkey, }, "w", function () mymainmenu:show() end),
212
213 -- Layout manipulation
214 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
215 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
216 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
217 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
218 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
219 awful.key({ modkey, }, "Tab",
220 function ()
221 awful.client.focus.history.previous()
222 if client.focus then
223 client.focus:raise()
224 end
225 end),
226
227 -- Standard program
228 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
229 awful.key({ modkey, "Control" }, "r", awesome.restart),
230 awful.key({ modkey, "Shift" }, "q", awesome.quit),
231
232 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
233 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
234 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
235 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
236 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
237 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
238 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
239 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
240
241 awful.key({ modkey, "Control" }, "n", awful.client.restore),
242
243 -- Prompt
244 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
245
246 awful.key({ modkey }, "x",
247 function ()
248 awful.prompt.run({ prompt = "Run Lua code: " },
249 mypromptbox[mouse.screen].widget,
250 awful.util.eval, nil,
251 awful.util.getdir("cache") .. "/history_eval")
252 end),
253 -- Menubar
254 awful.key({ modkey }, "p", function() menubar.show() end)
255
256 -- Pulseaudio widget
257 --awful.key({ }, "XF86AudioRaiseVolume", APW.Up),
258 --awful.key({ }, "XF86AudioLowerVolume", APW.Down),
259 --awful.key({ }, "XF86AudioMute", APW.ToggleMute)
260 )
261
262 clientkeys = awful.util.table.join(
263 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
264 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
265 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
266 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
267 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
268 awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
269 awful.key({ modkey, }, "n",
270 function (c)
271 -- The client currently has the input focus, so it cannot be
272 -- minimized, since minimized clients can't have the focus.
273 c.minimized = true
274 end),
275 awful.key({ modkey, }, "m",
276 function (c)
277 c.maximized_horizontal = not c.maximized_horizontal
278 c.maximized_vertical = not c.maximized_vertical
279 end)
280 )
281
282 -- Bind all key numbers to tags.
283 -- Be careful: we use keycodes to make it works on any keyboard layout.
284 -- This should map on the top row of your keyboard, usually 1 to 9.
285 for i = 1, 9 do
286 globalkeys = awful.util.table.join(globalkeys,
287 awful.key({ modkey }, "#" .. i + 9,
288 function ()
289 local screen = mouse.screen
290 local tag = awful.tag.gettags(screen)[i]
291 if tag then
292 awful.tag.viewonly(tag)
293 end
294 end),
295 awful.key({ modkey, "Control" }, "#" .. i + 9,
296 function ()
297 local screen = mouse.screen
298 local tag = awful.tag.gettags(screen)[i]
299 if tag then
300 awful.tag.viewtoggle(tag)
301 end
302 end),
303 awful.key({ modkey, "Shift" }, "#" .. i + 9,
304 function ()
305 local tag = awful.tag.gettags(client.focus.screen)[i]
306 if client.focus and tag then
307 awful.client.movetotag(tag)
308 end
309 end),
310 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
311 function ()
312 local tag = awful.tag.gettags(client.focus.screen)[i]
313 if client.focus and tag then
314 awful.client.toggletag(tag)
315 end
316 end))
317 end
318
319 clientbuttons = awful.util.table.join(
320 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
321 awful.button({ modkey }, 1, awful.mouse.client.move),
322 awful.button({ modkey }, 3, awful.mouse.client.resize))
323
324 -- Set keys
325 root.keys(globalkeys)
326 -- }}}
327
328 -- {{{ Rules
329 awful.rules.rules = {
330 -- All clients will match this rule.
331 { rule = { },
332 properties = { border_width = beautiful.border_width,
333 border_color = beautiful.border_normal,
334 focus = awful.client.focus.filter,
335 keys = clientkeys,
336 buttons = clientbuttons } },
337 { rule = { class = "MPlayer" },
338 properties = { floating = true } },
339 { rule = { class = "pinentry" },
340 properties = { floating = true } },
341 { rule = { class = "gimp" },
342 properties = { floating = true } },
343 -- Set Firefox to always map on tags number 2 of screen 1.
344 -- { rule = { class = "Firefox" },
345 -- properties = { tag = tags[1][2] } },
346 }
347 -- }}}
348
349 -- {{{ Signals
350 -- Signal function to execute when a new client appears.
351 client.connect_signal("manage", function (c, startup)
352 -- Enable sloppy focus
353 c:connect_signal("mouse::enter", function(c)
354 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
355 and awful.client.focus.filter(c) then
356 client.focus = c
357 end
358 end)
359
360 if not startup then
361 -- Set the windows at the slave,
362 -- i.e. put it at the end of others instead of setting it master.
363 -- awful.client.setslave(c)
364
365 -- Put windows in a smart way, only if they does not set an initial position.
366 if not c.size_hints.user_position and not c.size_hints.program_position then
367 awful.placement.no_overlap(c)
368 awful.placement.no_offscreen(c)
369 end
370 end
371
372 local titlebars_enabled = false
373 if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
374 -- buttons for the titlebar
375 local buttons = awful.util.table.join(
376 awful.button({ }, 1, function()
377 client.focus = c
378 c:raise()
379 awful.mouse.client.move(c)
380 end),
381 awful.button({ }, 3, function()
382 client.focus = c
383 c:raise()
384 awful.mouse.client.resize(c)
385 end)
386 )
387
388 -- Widgets that are aligned to the left
389 local left_layout = wibox.layout.fixed.horizontal()
390 left_layout:add(awful.titlebar.widget.iconwidget(c))
391 left_layout:buttons(buttons)
392
393 -- Widgets that are aligned to the right
394 local right_layout = wibox.layout.fixed.horizontal()
395 right_layout:add(awful.titlebar.widget.floatingbutton(c))
396 right_layout:add(awful.titlebar.widget.maximizedbutton(c))
397 right_layout:add(awful.titlebar.widget.stickybutton(c))
398 right_layout:add(awful.titlebar.widget.ontopbutton(c))
399 right_layout:add(awful.titlebar.widget.closebutton(c))
400
401 -- The title goes in the middle
402 local middle_layout = wibox.layout.flex.horizontal()
403 local title = awful.titlebar.widget.titlewidget(c)
404 title:set_align("center")
405 middle_layout:add(title)
406 middle_layout:buttons(buttons)
407
408 -- Now bring it all together
409 local layout = wibox.layout.align.horizontal()
410 layout:set_left(left_layout)
411 layout:set_right(right_layout)
412 layout:set_middle(middle_layout)
413
414 awful.titlebar(c):set_widget(layout)
415 end
416 end)
417
418 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
419 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
420 -- }}}