titlebar: fix modkey for buttons
[awesome.git] / awesomerc.lua.in
blobab01665e3aaeb19d88e1e048d9741f336c666788
1 -- Standard awesome library
2 require("awful")
3 -- Theme handling library
4 require("beautiful")
5 -- Notification library
6 require("naughty")
8 -- {{{ Variable definitions
9 -- Themes define colours, icons, and wallpapers
10 -- The default is a dark theme
11 theme_path = "@AWESOME_THEMES_PATH@/default/theme.lua"
12 -- Uncommment this for a lighter theme
13 -- theme_path = "@AWESOME_THEMES_PATH@/sky/theme.lua"
15 -- Actually load theme
16 beautiful.init(theme_path)
18 -- This is used later as the default terminal and editor to run.
19 terminal = "xterm"
20 editor = os.getenv("EDITOR") or "nano"
21 editor_cmd = terminal .. " -e " .. editor
23 -- Default modkey.
24 -- Usually, Mod4 is the key with a logo between Control and Alt.
25 -- If you do not like this or do not have such a key,
26 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
27 -- However, you can use another modifier like Mod1, but it may interact with others.
28 modkey = "Mod4"
30 -- Table of layouts to cover with awful.layout.inc, order matters.
31 layouts =
33 awful.layout.suit.tile,
34 awful.layout.suit.tile.left,
35 awful.layout.suit.tile.bottom,
36 awful.layout.suit.tile.top,
37 awful.layout.suit.fair,
38 awful.layout.suit.fair.horizontal,
39 awful.layout.suit.spiral,
40 awful.layout.suit.spiral.dwindle,
41 awful.layout.suit.max,
42 awful.layout.suit.max.fullscreen,
43 awful.layout.suit.magnifier,
44 awful.layout.suit.floating
47 -- Table of clients that should be set floating. The index may be either
48 -- the application class or instance. The instance is useful when running
49 -- a console app in a terminal like (Music on Console)
50 -- xterm -name mocp -e mocp
51 floatapps =
53 -- by class
54 ["MPlayer"] = true,
55 ["pinentry"] = true,
56 ["gimp"] = true,
57 -- by instance
58 ["mocp"] = true
61 -- Applications to be moved to a pre-defined tag by class or instance.
62 -- Use the screen and tags indices.
63 apptags =
65 -- ["Firefox"] = { screen = 1, tag = 2 },
66 -- ["mocp"] = { screen = 2, tag = 4 },
69 -- Define if we want to use titlebar on all applications.
70 use_titlebar = false
71 -- }}}
73 -- {{{ Tags
74 -- Define tags table.
75 tags = {}
76 for s = 1, screen.count() do
77 -- Each screen has its own tag table.
78 tags[s] = {}
79 -- Create 9 tags per screen.
80 for tagnumber = 1, 9 do
81 tags[s][tagnumber] = tag(tagnumber)
82 -- Add tags to screen one by one
83 tags[s][tagnumber].screen = s
84 awful.layout.set(layouts[1], tags[s][tagnumber])
85 end
86 -- I'm sure you want to see at least one tag.
87 tags[s][1].selected = true
88 end
89 -- }}}
91 -- {{{ Wibox
92 -- Create a textbox widget
93 mytextbox = widget({ type = "textbox", align = "right" })
94 -- Set the default text in textbox
95 mytextbox.text = "<b><small> " .. awesome.release .. " </small></b>"
97 -- Create a laucher widget and a main menu
98 myawesomemenu = {
99 { "manual", terminal .. " -e man awesome" },
100 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
101 { "restart", awesome.restart },
102 { "quit", awesome.quit }
105 mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
106 { "open terminal", terminal }
110 mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
111 menu = mymainmenu })
113 -- Create a systray
114 mysystray = widget({ type = "systray" })
116 -- Create a wibox for each screen and add it
117 mywibox = {}
118 mypromptbox = {}
119 mylayoutbox = {}
120 mytaglist = {}
121 mytaglist.buttons = awful.util.table.join(
122 awful.button({ }, 1, awful.tag.viewonly),
123 awful.button({ modkey }, 1, awful.client.movetotag),
124 awful.button({ }, 3, function (tag) tag.selected = not tag.selected end),
125 awful.button({ modkey }, 3, awful.client.toggletag),
126 awful.button({ }, 4, awful.tag.viewnext),
127 awful.button({ }, 5, awful.tag.viewprev)
129 mytasklist = {}
130 mytasklist.buttons = awful.util.table.join(
131 awful.button({ }, 1, function (c)
132 if not c:isvisible() then
133 awful.tag.viewonly(c:tags()[1])
135 client.focus = c
136 c:raise()
137 end),
138 awful.button({ }, 3, function ()
139 if instance then
140 instance:hide()
141 instance = nil
142 else
143 instance = awful.menu.clients({ width=250 })
145 end),
146 awful.button({ }, 4, function ()
147 awful.client.focus.byidx(1)
148 if client.focus then client.focus:raise() end
149 end),
150 awful.button({ }, 5, function ()
151 awful.client.focus.byidx(-1)
152 if client.focus then client.focus:raise() end
153 end))
155 for s = 1, screen.count() do
156 -- Create a promptbox for each screen
157 mypromptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.leftright })
158 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
159 -- We need one layoutbox per screen.
160 mylayoutbox[s] = awful.widget.layoutbox(s)
161 mylayoutbox[s].buttons = awful.util.table.join(
162 awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
163 awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
164 awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
165 awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end))
166 -- Create a taglist widget
167 mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
169 -- Create a tasklist widget
170 mytasklist[s] = awful.widget.tasklist(function(c)
171 return awful.widget.tasklist.label.currenttags(c, s)
172 end, mytasklist.buttons)
174 -- Create the wibox
175 mywibox[s] = awful.wibox({ position = "top", screen = s })
176 -- Add widgets to the wibox - order matters
177 mywibox[s].widgets = {
179 mylauncher,
180 mytaglist[s],
181 mypromptbox[s],
182 layout = awful.widget.layout.horizontal.leftright
184 mylayoutbox[s],
185 mytextbox,
186 s == 1 and mysystray or nil,
187 mytasklist[s],
188 layout = awful.widget.layout.horizontal.rightleft
191 -- }}}
193 -- {{{ Mouse bindings
194 root.buttons = awful.util.table.join(
195 awful.button({ }, 3, function () mymainmenu:toggle() end),
196 awful.button({ }, 4, awful.tag.viewnext),
197 awful.button({ }, 5, awful.tag.viewprev))
198 -- }}}
200 -- {{{ Key bindings
201 globalkeys = awful.util.table.join(
202 awful.key({ modkey, }, "Left", awful.tag.viewprev ),
203 awful.key({ modkey, }, "Right", awful.tag.viewnext ),
204 awful.key({ modkey, }, "Escape", awful.tag.history.restore),
206 awful.key({ modkey, }, "j",
207 function ()
208 awful.client.focus.byidx( 1)
209 if client.focus then client.focus:raise() end
210 end),
211 awful.key({ modkey, }, "k",
212 function ()
213 awful.client.focus.byidx(-1)
214 if client.focus then client.focus:raise() end
215 end),
216 awful.key({ modkey, }, "w", function () mymainmenu:show(true) end),
218 -- Layout manipulation
219 awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
220 awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
221 awful.key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
222 awful.key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
223 awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
224 awful.key({ modkey, }, "Tab",
225 function ()
226 awful.client.focus.history.previous()
227 if client.focus then
228 client.focus:raise()
230 end),
232 -- Standard program
233 awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
234 awful.key({ modkey, "Control" }, "r", awesome.restart),
235 awful.key({ modkey, "Shift" }, "q", awesome.quit),
237 awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
238 awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
239 awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
240 awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
241 awful.key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
242 awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
243 awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
244 awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
246 -- Prompt
247 awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
249 awful.key({ modkey }, "x",
250 function ()
251 awful.prompt.run({ prompt = "Run Lua code: " },
252 mypromptbox[mouse.screen].widget,
253 awful.util.eval, nil,
254 awful.util.getdir("cache") .. "/history_eval")
255 end)
258 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
259 clientkeys = awful.util.table.join(
260 awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
261 awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
262 awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
263 awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
264 awful.key({ modkey, }, "o", awful.client.movetoscreen ),
265 awful.key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
266 awful.key({ modkey }, "t", awful.client.togglemarked),
267 awful.key({ modkey,}, "m",
268 function (c)
269 c.maximized_horizontal = not c.maximized_horizontal
270 c.maximized_vertical = not c.maximized_vertical
271 end)
274 -- Compute the maximum number of digit we need, limited to 9
275 keynumber = 0
276 for s = 1, screen.count() do
277 keynumber = math.min(9, math.max(#tags[s], keynumber));
280 for i = 1, keynumber do
281 globalkeys = awful.util.table.join(globalkeys,
282 awful.key({ modkey }, i,
283 function ()
284 local screen = mouse.screen
285 if tags[screen][i] then
286 awful.tag.viewonly(tags[screen][i])
288 end),
289 awful.key({ modkey, "Control" }, i,
290 function ()
291 local screen = mouse.screen
292 if tags[screen][i] then
293 tags[screen][i].selected = not tags[screen][i].selected
295 end),
296 awful.key({ modkey, "Shift" }, i,
297 function ()
298 if client.focus and tags[client.focus.screen][i] then
299 awful.client.movetotag(tags[client.focus.screen][i])
301 end),
302 awful.key({ modkey, "Control", "Shift" }, i,
303 function ()
304 if client.focus and tags[client.focus.screen][i] then
305 awful.client.toggletag(tags[client.focus.screen][i])
307 end),
308 awful.key({ modkey, "Shift" }, "F" .. i,
309 function ()
310 local screen = mouse.screen
311 if tags[screen][i] then
312 for k, c in pairs(awful.client.getmarked()) do
313 awful.client.movetotag(tags[screen][i], c)
316 end))
319 -- Set keys
320 root.keys = globalkeys
321 -- }}}
323 -- {{{ Hooks
324 -- Hook function to execute when focusing a client.
325 awful.hooks.focus.register(function (c)
326 if not awful.client.ismarked(c) then
327 c.border_color = beautiful.border_focus
329 end)
331 -- Hook function to execute when unfocusing a client.
332 awful.hooks.unfocus.register(function (c)
333 if not awful.client.ismarked(c) then
334 c.border_color = beautiful.border_normal
336 end)
338 -- Hook function to execute when marking a client
339 awful.hooks.marked.register(function (c)
340 c.border_color = beautiful.border_marked
341 end)
343 -- Hook function to execute when unmarking a client.
344 awful.hooks.unmarked.register(function (c)
345 c.border_color = beautiful.border_focus
346 end)
348 -- Hook function to execute when the mouse enters a client.
349 awful.hooks.mouse_enter.register(function (c)
350 -- Sloppy focus, but disabled for magnifier layout
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 -- Hook function to execute when a new client appears.
358 awful.hooks.manage.register(function (c, startup)
359 -- If we are not managing this application at startup,
360 -- move it to the screen where the mouse is.
361 -- We only do it for filtered windows (i.e. no dock, etc).
362 if not startup and awful.client.focus.filter(c) then
363 c.screen = mouse.screen
366 if use_titlebar then
367 -- Add a titlebar
368 awful.titlebar.add(c, { modkey = modkey })
370 -- Add mouse bindings
371 c.buttons = awful.util.table.join(
372 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
373 awful.button({ modkey }, 1, awful.mouse.client.move),
374 awful.button({ modkey }, 3, awful.mouse.client.resize))
375 -- New client may not receive focus
376 -- if they're not focusable, so set border anyway.
377 c.border_width = beautiful.border_width
378 c.border_color = beautiful.border_normal
380 -- Check if the application should be floating.
381 local cls = c.class
382 local inst = c.instance
383 if floatapps[cls] ~= nil then
384 awful.client.floating.set(c, floatapps[cls])
385 elseif floatapps[inst] ~= nil then
386 awful.client.floating.set(c, floatapps[inst])
389 -- Check application->screen/tag mappings.
390 local target
391 if apptags[cls] then
392 target = apptags[cls]
393 elseif apptags[inst] then
394 target = apptags[inst]
396 if target then
397 c.screen = target.screen
398 awful.client.movetotag(tags[target.screen][target.tag], c)
401 -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
402 client.focus = c
404 -- Set key bindings
405 c.keys = clientkeys
407 -- Set the windows at the slave,
408 -- i.e. put it at the end of others instead of setting it master.
409 -- awful.client.setslave(c)
411 -- Honor size hints: if you want to drop the gaps between windows, set this to false.
412 -- c.size_hints_honor = false
413 end)
415 -- Hook function to execute when switching tag selection.
416 awful.hooks.tags.register(function (screen, tag, view)
417 -- Give focus to the latest client in history if no window has focus
418 -- or if the current window is a desktop or a dock one.
419 if not client.focus or not client.focus:isvisible() then
420 local c = awful.client.focus.history.get(screen, 0)
421 if c then client.focus = c end
423 end)
425 -- Hook called every minute
426 awful.hooks.timer.register(60, function ()
427 mytextbox.text = os.date(" %a %b %d, %H:%M ")
428 end)
429 -- }}}