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