screen: Add screen.by_coords()
[awesome.git] / awesomerc.lua.in
blob3929d9fc2705358143ca480f3a09a99fe38f2d47
1 -- Standard awesome library
2 require("awful")
3 require("awful.autofocus")
4 require("awful.rules")
5 -- Widget and layout library
6 require("wibox")
7 -- Theme handling library
8 require("beautiful")
9 -- Notification library
10 require("naughty")
12 -- {{{ Error handling
13 -- Check if awesome encountered an error during startup and fell back to
14 -- another config (This code will only ever execute for the fallback config)
15 if awesome.startup_errors then
16 naughty.notify({ preset = naughty.config.presets.critical,
17 title = "Oops, there were errors during startup!",
18 text = awesome.startup_errors })
19 end
21 -- Handle runtime errors after startup
23 local in_error = false
24 awesome.connect_signal("debug::error", function (err)
25 -- Make sure we don't go into an endless error loop
26 if in_error then return end
27 in_error = true
29 naughty.notify({ preset = naughty.config.presets.critical,
30 title = "Oops, an error happened!",
31 text = err })
32 in_error = false
33 end)
34 end
35 -- }}}
37 -- {{{ Variable definitions
38 -- Themes define colours, icons, and wallpapers
39 beautiful.init("@AWESOME_THEMES_PATH@/default/theme.lua")
41 -- This is used later as the default terminal and editor to run.
42 terminal = "xterm"
43 editor = os.getenv("EDITOR") or "nano"
44 editor_cmd = terminal .. " -e " .. editor
46 -- Default modkey.
47 -- Usually, Mod4 is the key with a logo between Control and Alt.
48 -- If you do not like this or do not have such a key,
49 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
50 -- However, you can use another modifier like Mod1, but it may interact with others.
51 modkey = "Mod4"
53 -- Table of layouts to cover with awful.layout.inc, order matters.
54 layouts =
56 awful.layout.suit.floating,
57 awful.layout.suit.tile,
58 awful.layout.suit.tile.left,
59 awful.layout.suit.tile.bottom,
60 awful.layout.suit.tile.top,
61 awful.layout.suit.fair,
62 awful.layout.suit.fair.horizontal,
63 awful.layout.suit.spiral,
64 awful.layout.suit.spiral.dwindle,
65 awful.layout.suit.max,
66 awful.layout.suit.max.fullscreen,
67 awful.layout.suit.magnifier
69 -- }}}
71 -- {{{ Tags
72 -- Define a tag table which hold all screen tags.
73 tags = {}
74 for s = 1, screen.count() do
75 -- Each screen has its own tag table.
76 tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
77 end
78 -- }}}
80 -- {{{ Menu
81 -- Create a laucher widget and a main menu
82 myawesomemenu = {
83 { "manual", terminal .. " -e man awesome" },
84 { "edit config", editor_cmd .. " " .. awesome.conffile },
85 { "restart", awesome.restart },
86 { "quit", awesome.quit }
89 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
90 { "open terminal", terminal }
94 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
95 menu = mymainmenu })
96 -- }}}
98 -- {{{ Wibox
99 -- Create a textclock widget
100 mytextclock = awful.widget.textclock()
102 -- Create a wibox for each screen and add it
103 mywibox = {}
104 mypromptbox = {}
105 mylayoutbox = {}
106 mytaglist = {}
107 mytaglist.buttons = awful.util.table.join(
108 awful.button({ }, 1, awful.tag.viewonly),
109 awful.button({ modkey }, 1, awful.client.movetotag),
110 awful.button({ }, 3, awful.tag.viewtoggle),
111 awful.button({ modkey }, 3, awful.client.toggletag),
112 awful.button({ }, 4, awful.tag.viewnext),
113 awful.button({ }, 5, awful.tag.viewprev)
115 mytasklist = {}
116 mytasklist.buttons = awful.util.table.join(
117 awful.button({ }, 1, function (c)
118 if c == client.focus then
119 c.minimized = true
120 else
121 if not c:isvisible() then
122 awful.tag.viewonly(c:tags()[1])
124 -- This will also un-minimize
125 -- the client, if needed
126 client.focus = c
127 c:raise()
129 end),
130 awful.button({ }, 3, function ()
131 if instance then
132 instance:hide()
133 instance = nil
134 else
135 instance = awful.menu.clients({ width=250 })
137 end),
138 awful.button({ }, 4, function ()
139 awful.client.focus.byidx(1)
140 if client.focus then client.focus:raise() end
141 end),
142 awful.button({ }, 5, function ()
143 awful.client.focus.byidx(-1)
144 if client.focus then client.focus:raise() end
145 end))
147 for s = 1, screen.count() do
148 -- Create a promptbox for each screen
149 mypromptbox[s] = awful.widget.prompt()
150 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
151 -- We need one layoutbox per screen.
152 mylayoutbox[s] = awful.widget.layoutbox(s)
153 mylayoutbox[s]:buttons(awful.util.table.join(
154 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
155 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
156 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
157 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
158 -- Create a taglist widget
159 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
161 -- Create a tasklist widget
162 mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
164 -- Create the wibox
165 mywibox[s] = awful.wibox({ position = "top", screen = s })
167 -- Widgets that are aligned to the left
168 local left_layout = wibox.layout.fixed.horizontal()
169 left_layout:add(mylauncher)
170 left_layout:add(mytaglist[s])
171 left_layout:add(mypromptbox[s])
173 -- Widgets that are aligned to the right
174 local right_layout = wibox.layout.fixed.horizontal()
175 if s == 1 then right_layout:add(wibox.widget.systray()) end
176 right_layout:add(mytextclock)
177 right_layout:add(mylayoutbox[s])
179 -- Now bring it all together (with the tasklist in the middle)
180 local layout = wibox.layout.align.horizontal()
181 layout:set_left(left_layout)
182 layout:set_middle(mytasklist[s])
183 layout:set_right(right_layout)
185 mywibox[s]:set_widget(layout)
187 -- }}}
189 -- {{{ Mouse bindings
190 root.buttons(awful.util.table.join(
191 awful.button({ }, 3, function () mymainmenu:toggle() end),
192 awful.button({ }, 4, awful.tag.viewnext),
193 awful.button({ }, 5, awful.tag.viewprev)
195 -- }}}
197 -- {{{ Key bindings
198 globalkeys = awful.util.table.join(
199 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
200 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
201 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
203 awful.key({ modkey, }, "j",
204 function ()
205 awful.client.focus.byidx( 1)
206 if client.focus then client.focus:raise() end
207 end),
208 awful.key({ modkey, }, "k",
209 function ()
210 awful.client.focus.byidx(-1)
211 if client.focus then client.focus:raise() end
212 end),
213 awful.key({ modkey, }, "w", function () mymainmenu:show({keygrabber=true}) end),
215 -- Layout manipulation
216 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
217 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
218 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end),
219 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
220 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
221 awful.key({ modkey, }, "Tab",
222 function ()
223 awful.client.focus.history.previous()
224 if client.focus then
225 client.focus:raise()
227 end),
229 -- Standard program
230 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
231 awful.key({ modkey, "Control" }, "r", awesome.restart),
232 awful.key({ modkey, "Shift" }, "q", awesome.quit),
234 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
235 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
236 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
237 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
238 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
239 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
240 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
241 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
243 awful.key({ modkey, "Control" }, "n", awful.client.restore),
245 -- Prompt
246 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
248 awful.key({ modkey }, "x",
249 function ()
250 awful.prompt.run({ prompt = "Run Lua code: " },
251 mypromptbox[mouse.screen].widget,
252 awful.util.eval, nil,
253 awful.util.getdir("cache") .. "/history_eval")
254 end)
257 clientkeys = awful.util.table.join(
258 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
259 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
260 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
261 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
262 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
263 awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
264 awful.key({ modkey, }, "n",
265 function (c)
266 -- The client currently has the input focus, so it cannot be
267 -- minimized, since minimized clients can't have the focus.
268 c.minimized = true
269 end),
270 awful.key({ modkey, }, "m",
271 function (c)
272 c.maximized_horizontal = not c.maximized_horizontal
273 c.maximized_vertical = not c.maximized_vertical
274 end)
277 -- Compute the maximum number of digit we need, limited to 9
278 keynumber = 0
279 for s = 1, screen.count() do
280 keynumber = math.min(9, math.max(#tags[s], keynumber));
283 -- Bind all key numbers to tags.
284 -- Be careful: we use keycodes to make it works on any keyboard layout.
285 -- This should map on the top row of your keyboard, usually 1 to 9.
286 for i = 1, keynumber do
287 globalkeys = awful.util.table.join(globalkeys,
288 awful.key({ modkey }, "#" .. i + 9,
289 function ()
290 local screen = mouse.screen
291 if tags[screen][i] then
292 awful.tag.viewonly(tags[screen][i])
294 end),
295 awful.key({ modkey, "Control" }, "#" .. i + 9,
296 function ()
297 local screen = mouse.screen
298 if tags[screen][i] then
299 awful.tag.viewtoggle(tags[screen][i])
301 end),
302 awful.key({ modkey, "Shift" }, "#" .. i + 9,
303 function ()
304 if client.focus and tags[client.focus.screen][i] then
305 awful.client.movetotag(tags[client.focus.screen][i])
307 end),
308 awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
309 function ()
310 if client.focus and tags[client.focus.screen][i] then
311 awful.client.toggletag(tags[client.focus.screen][i])
313 end))
316 clientbuttons = awful.util.table.join(
317 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
318 awful.button({ modkey }, 1, awful.mouse.client.move),
319 awful.button({ modkey }, 3, awful.mouse.client.resize))
321 -- Set keys
322 root.keys(globalkeys)
323 -- }}}
325 -- {{{ Rules
326 awful.rules.rules = {
327 -- All clients will match this rule.
328 { rule = { },
329 properties = { border_width = beautiful.border_width,
330 border_color = beautiful.border_normal,
331 focus = true,
332 keys = clientkeys,
333 buttons = clientbuttons } },
334 { rule = { class = "MPlayer" },
335 properties = { floating = true } },
336 { rule = { class = "pinentry" },
337 properties = { floating = true } },
338 { rule = { class = "gimp" },
339 properties = { floating = true } },
340 -- Set Firefox to always map on tags number 2 of screen 1.
341 -- { rule = { class = "Firefox" },
342 -- properties = { tag = tags[1][2] } },
344 -- }}}
346 -- {{{ Signals
347 -- Signal function to execute when a new client appears.
348 client.connect_signal("manage", function (c, startup)
349 -- Enable sloppy focus
350 c:connect_signal("mouse::enter", function(c)
351 if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
352 and awful.client.focus.filter(c) then
353 client.focus = c
355 end)
357 if not startup then
358 -- Set the windows at the slave,
359 -- i.e. put it at the end of others instead of setting it master.
360 -- awful.client.setslave(c)
362 -- Put windows in a smart way, only if they does not set an initial position.
363 if not c.size_hints.user_position and not c.size_hints.program_position then
364 awful.placement.no_overlap(c)
365 awful.placement.no_offscreen(c)
368 end)
370 client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
371 client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
372 -- }}}