awful.client.toggletag: Use tag.getscreen()
[awesome.git] / awesomerc.lua.in
blob440bf7656b614651699fa39139b41772e3617420
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, 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 local layouts =
58 awful.layout.suit.floating,
59 awful.layout.suit.tile,
60 awful.layout.suit.tile.left,
61 awful.layout.suit.tile.bottom,
62 awful.layout.suit.tile.top,
63 awful.layout.suit.fair,
64 awful.layout.suit.fair.horizontal,
65 awful.layout.suit.spiral,
66 awful.layout.suit.spiral.dwindle,
67 awful.layout.suit.max,
68 awful.layout.suit.max.fullscreen,
69 awful.layout.suit.magnifier
71 -- }}}
73 -- {{{ Wallpaper
74 if beautiful.wallpaper then
75 for s = 1, screen.count() do
76 gears.wallpaper.maximized(beautiful.wallpaper, s, true)
77 end
78 end
79 -- }}}
81 -- {{{ Tags
82 -- Define a tag table which hold all screen tags.
83 tags = {}
84 for s = 1, screen.count() do
85 -- Each screen has its own tag table.
86 tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
87 end
88 -- }}}
90 -- {{{ Menu
91 -- Create a laucher widget and a main menu
92 myawesomemenu = {
93 { "manual", terminal .. " -e man awesome" },
94 { "edit config", editor_cmd .. " " .. awesome.conffile },
95 { "restart", awesome.restart },
96 { "quit", awesome.quit }
99 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
100 { "open terminal", terminal }
104 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
105 menu = mymainmenu })
107 -- Menubar configuration
108 menubar.utils.terminal = terminal -- Set the terminal for applications that require it
109 -- }}}
111 -- {{{ Wibox
112 -- Create a textclock widget
113 mytextclock = awful.widget.textclock()
115 -- Create a wibox for each screen and add it
116 mywibox = {}
117 mypromptbox = {}
118 mylayoutbox = {}
119 mytaglist = {}
120 mytaglist.buttons = awful.util.table.join(
121 awful.button({ }, 1, awful.tag.viewonly),
122 awful.button({ modkey }, 1, awful.client.movetotag),
123 awful.button({ }, 3, awful.tag.viewtoggle),
124 awful.button({ modkey }, 3, awful.client.toggletag),
125 awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
126 awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
128 mytasklist = {}
129 mytasklist.buttons = awful.util.table.join(
130 awful.button({ }, 1, function (c)
131 if c == client.focus then
132 c.minimized = true
133 else
134 -- Without this, the following
135 -- :isvisible() makes no sense
136 c.minimized = false
137 if not c:isvisible() then
138 awful.tag.viewonly(c:tags()[1])
140 -- This will also un-minimize
141 -- the client, if needed
142 client.focus = c
143 c:raise()
145 end),
146 awful.button({ }, 3, function ()
147 if instance then
148 instance:hide()
149 instance = nil
150 else
151 instance = awful.menu.clients({ width=250 })
153 end),
154 awful.button({ }, 4, function ()
155 awful.client.focus.byidx(1)
156 if client.focus then client.focus:raise() end
157 end),
158 awful.button({ }, 5, function ()
159 awful.client.focus.byidx(-1)
160 if client.focus then client.focus:raise() end
161 end))
163 for s = 1, screen.count() do
164 -- Create a promptbox for each screen
165 mypromptbox[s] = awful.widget.prompt()
166 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
167 -- We need one layoutbox per screen.
168 mylayoutbox[s] = awful.widget.layoutbox(s)
169 mylayoutbox[s]:buttons(awful.util.table.join(
170 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
171 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
172 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
173 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
174 -- Create a taglist widget
175 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
177 -- Create a tasklist widget
178 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
180 -- Create the wibox
181 mywibox[s] = awful.wibox({ position = "top", screen = s })
183 -- Widgets that are aligned to the left
184 local left_layout = wibox.layout.fixed.horizontal()
185 left_layout:add(mylauncher)
186 left_layout:add(mytaglist[s])
187 left_layout:add(mypromptbox[s])
189 -- Widgets that are aligned to the right
190 local right_layout = wibox.layout.fixed.horizontal()
191 if s == 1 then right_layout:add(wibox.widget.systray()) end
192 right_layout:add(mytextclock)
193 right_layout:add(mylayoutbox[s])
195 -- Now bring it all together (with the tasklist in the middle)
196 local layout = wibox.layout.align.horizontal()
197 layout:set_left(left_layout)
198 layout:set_middle(mytasklist[s])
199 layout:set_right(right_layout)
201 mywibox[s]:set_widget(layout)
203 -- }}}
205 -- {{{ Mouse bindings
206 root.buttons(awful.util.table.join(
207 awful.button({ }, 3, function () mymainmenu:toggle() end),
208 awful.button({ }, 4, awful.tag.viewnext),
209 awful.button({ }, 5, awful.tag.viewprev)
211 -- }}}
213 -- {{{ Key bindings
214 globalkeys = awful.util.table.join(
215 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
216 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
217 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
219 awful.key({ modkey, }, "j",
220 function ()
221 awful.client.focus.byidx( 1)
222 if client.focus then client.focus:raise() end
223 end),
224 awful.key({ modkey, }, "k",
225 function ()
226 awful.client.focus.byidx(-1)
227 if client.focus then client.focus:raise() end
228 end),
229 awful.key({ modkey, }, "w", function () mymainmenu:show() end),
231 -- Layout manipulation
232 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
233 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
234 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
235 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
236 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
237 awful.key({ modkey, }, "Tab",
238 function ()
239 awful.client.focus.history.previous()
240 if client.focus then
241 client.focus:raise()
243 end),
245 -- Standard program
246 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
247 awful.key({ modkey, "Control" }, "r", awesome.restart),
248 awful.key({ modkey, "Shift" }, "q", awesome.quit),
250 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
251 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
252 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
253 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
254 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
255 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
256 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
257 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
259 awful.key({ modkey, "Control" }, "n", awful.client.restore),
261 -- Prompt
262 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
264 awful.key({ modkey }, "x",
265 function ()
266 awful.prompt.run({ prompt = "Run Lua code: " },
267 mypromptbox[mouse.screen].widget,
268 awful.util.eval, nil,
269 awful.util.getdir("cache") .. "/history_eval")
270 end),
271 -- Menubar
272 awful.key({ modkey }, "p", function() menubar.show() end)
275 clientkeys = awful.util.table.join(
276 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
277 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
278 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
279 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
280 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
281 awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
282 awful.key({ modkey, }, "n",
283 function (c)
284 -- The client currently has the input focus, so it cannot be
285 -- minimized, since minimized clients can't have the focus.
286 c.minimized = true
287 end),
288 awful.key({ modkey, }, "m",
289 function (c)
290 c.maximized_horizontal = not c.maximized_horizontal
291 c.maximized_vertical = not c.maximized_vertical
292 end)
295 -- Compute the maximum number of digit we need, limited to 9
296 keynumber = 0
297 for s = 1, screen.count() do
298 keynumber = math.min(9, math.max(#tags[s], keynumber))
301 -- Bind all key numbers to tags.
302 -- Be careful: we use keycodes to make it works on any keyboard layout.
303 -- This should map on the top row of your keyboard, usually 1 to 9.
304 for i = 1, keynumber do
305 globalkeys = awful.util.table.join(globalkeys,
306 awful.key({ modkey }, "#" .. i + 9,
307 function ()
308 local screen = mouse.screen
309 if tags[screen][i] then
310 awful.tag.viewonly(tags[screen][i])
312 end),
313 awful.key({ modkey, "Control" }, "#" .. i + 9,
314 function ()
315 local screen = mouse.screen
316 if tags[screen][i] then
317 awful.tag.viewtoggle(tags[screen][i])
319 end),
320 awful.key({ modkey, "Shift" }, "#" .. i + 9,
321 function ()
322 if client.focus and tags[client.focus.screen][i] then
323 awful.client.movetotag(tags[client.focus.screen][i])
325 end),
326 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
327 function ()
328 if client.focus and tags[client.focus.screen][i] then
329 awful.client.toggletag(tags[client.focus.screen][i])
331 end))
334 clientbuttons = awful.util.table.join(
335 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
336 awful.button({ modkey }, 1, awful.mouse.client.move),
337 awful.button({ modkey }, 3, awful.mouse.client.resize))
339 -- Set keys
340 root.keys(globalkeys)
341 -- }}}
343 -- {{{ Rules
344 awful.rules.rules = {
345 -- All clients will match this rule.
346 { rule = { },
347 properties = { border_width = beautiful.border_width,
348 border_color = beautiful.border_normal,
349 focus = awful.client.focus.filter,
350 keys = clientkeys,
351 buttons = clientbuttons } },
352 { rule = { class = "MPlayer" },
353 properties = { floating = true } },
354 { rule = { class = "pinentry" },
355 properties = { floating = true } },
356 { rule = { class = "gimp" },
357 properties = { floating = true } },
358 -- Set Firefox to always map on tags number 2 of screen 1.
359 -- { rule = { class = "Firefox" },
360 -- properties = { tag = tags[1][2] } },
362 -- }}}
364 -- {{{ Signals
365 -- Signal function to execute when a new client appears.
366 client.connect_signal("manage", function (c, startup)
367 -- Enable sloppy focus
368 c:connect_signal("mouse::enter", function(c)
369 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
370 and awful.client.focus.filter(c) then
371 client.focus = c
373 end)
375 if not startup then
376 -- Set the windows at the slave,
377 -- i.e. put it at the end of others instead of setting it master.
378 -- awful.client.setslave(c)
380 -- Put windows in a smart way, only if they does not set an initial position.
381 if not c.size_hints.user_position and not c.size_hints.program_position then
382 awful.placement.no_overlap(c)
383 awful.placement.no_offscreen(c)
387 local titlebars_enabled = false
388 if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
389 -- Widgets that are aligned to the left
390 local left_layout = wibox.layout.fixed.horizontal()
391 left_layout:add(awful.titlebar.widget.iconwidget(c))
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))
401 -- The title goes in the middle
402 local title = awful.titlebar.widget.titlewidget(c)
403 title:buttons(awful.util.table.join(
404 awful.button({ }, 1, function()
405 client.focus = c
406 c:raise()
407 awful.mouse.client.move(c)
408 end),
409 awful.button({ }, 3, function()
410 client.focus = c
411 c:raise()
412 awful.mouse.client.resize(c)
413 end)
416 -- Now bring it all together
417 local layout = wibox.layout.align.horizontal()
418 layout:set_left(left_layout)
419 layout:set_right(right_layout)
420 layout:set_middle(title)
422 awful.titlebar(c):set_widget(layout)
424 end)
426 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
427 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
428 -- }}}