awful.menu: rewrite to be more object compliant
[awesome.git] / awesomerc.lua.in
blob597446e6d05f6ebf3594aa899f8cd4bc3fbd463f
1 -- Include awesome libraries, with lots of useful function!
2 require("awful")
3 require("beautiful")
5 -- {{{ Variable definitions
6 -- This is a file path to a theme file which will defines colors.
7 theme_path = "@AWESOME_THEMES_PATH@/default"
9 -- This is used later as the default terminal and editor to run.
10 terminal = "xterm"
11 editor = os.getenv("EDITOR") or "nano"
12 editor_cmd = terminal .. " -e " .. editor
14 -- Default modkey.
15 -- Usually, Mod4 is the key with a logo between Control and Alt.
16 -- If you do not like this or do not have such a key,
17 -- I suggest you to remap Mod4 to another key using xmodmap or other tools.
18 -- However, you can use another modifier like Mod1, but it may interact with others.
19 modkey = "Mod4"
21 -- Table of layouts to cover with awful.layout.inc, order matters.
22 layouts =
24 "tile",
25 "tileleft",
26 "tilebottom",
27 "tiletop",
28 "fairh",
29 "fairv",
30 "magnifier",
31 "max",
32 "fullscreen",
33 "spiral",
34 "dwindle",
35 "floating"
38 -- Table of clients that should be set floating. The index may be either
39 -- the application class or instance. The instance is useful when running
40 -- a console app in a terminal like (Music on Console)
41 -- xterm -name mocp -e mocp
42 floatapps =
44 -- by class
45 ["MPlayer"] = true,
46 ["pinentry"] = true,
47 ["gimp"] = true,
48 -- by instance
49 ["mocp"] = true
52 -- Applications to be moved to a pre-defined tag by class or instance.
53 -- Use the screen and tags indices.
54 apptags =
56 -- ["Firefox"] = { screen = 1, tag = 2 },
57 -- ["mocp"] = { screen = 2, tag = 4 },
60 -- Define if we want to use titlebar on all applications.
61 use_titlebar = false
62 -- }}}
64 -- {{{ Initialization
65 -- Initialize theme (colors).
66 beautiful.init(theme_path)
68 -- Register theme in awful.
69 -- This allows to not pass plenty of arguments to each function
70 -- to inform it about colors we want it to draw.
71 awful.beautiful.register(beautiful)
72 -- }}}
74 -- {{{ Tags
75 -- Define tags table.
76 tags = {}
77 for s = 1, screen.count() do
78 -- Each screen has its own tag table.
79 tags[s] = {}
80 -- Create 9 tags per screen.
81 for tagnumber = 1, 9 do
82 tags[s][tagnumber] = tag({ name = tagnumber, layout = layouts[1] })
83 -- Add tags to screen one by one
84 tags[s][tagnumber].screen = s
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.new({ items = { { "awesome", myawesomemenu, "@AWESOME_ICON_PATH@/awesome16.png" },
106 { "open terminal", terminal }
110 mylauncher = awful.widget.launcher({ image = "@AWESOME_ICON_PATH@/awesome16.png",
111 menu = mymainmenu })
113 -- Create a systray
114 mysystray = widget({ type = "systray", align = "right" })
116 -- Create a wibox for each screen and add it
117 mywibox = {}
118 mypromptbox = {}
119 mylayoutbox = {}
120 mytaglist = {}
121 mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
122 button({ modkey }, 1, awful.client.movetotag),
123 button({ }, 3, function (tag) tag.selected = not tag.selected end),
124 button({ modkey }, 3, awful.client.toggletag),
125 button({ }, 4, awful.tag.viewnext),
126 button({ }, 5, awful.tag.viewprev) }
127 mytasklist = {}
128 mytasklist.buttons = { button({ }, 1, function (c) client.focus = c; c:raise() end),
129 button({ }, 3, function () awful.menu.clients({ width=250 }) end),
130 button({ }, 4, function () awful.client.focus.byidx(1) end),
131 button({ }, 5, function () awful.client.focus.byidx(-1) end) }
133 for s = 1, screen.count() do
134 -- Create a promptbox for each screen
135 mypromptbox[s] = widget({ type = "textbox", align = "left" })
136 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
137 -- We need one layoutbox per screen.
138 mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
139 mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
140 button({ }, 3, function () awful.layout.inc(layouts, -1) end),
141 button({ }, 4, function () awful.layout.inc(layouts, 1) end),
142 button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
143 -- Create a taglist widget
144 mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
146 -- Create a tasklist widget
147 mytasklist[s] = awful.widget.tasklist.new(function(c)
148 return awful.widget.tasklist.label.currenttags(c, s)
149 end, mytasklist.buttons)
151 -- Create the wibox
152 mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
153 -- Add widgets to the wibox - order matters
154 mywibox[s].widgets = { mylauncher,
155 mytaglist[s],
156 mytasklist[s],
157 mypromptbox[s],
158 mytextbox,
159 mylayoutbox[s],
160 s == 1 and mysystray or nil }
161 mywibox[s].screen = s
163 -- }}}
165 -- {{{ Mouse bindings
166 awesome.buttons({
167 button({ }, 3, function () mymainmenu:toggle() end),
168 button({ }, 4, awful.tag.viewnext),
169 button({ }, 5, awful.tag.viewprev)
171 -- }}}
173 -- {{{ Key bindings
175 -- Bind keyboard digits
176 -- Compute the maximum number of digit we need, limited to 9
177 keynumber = 0
178 for s = 1, screen.count() do
179 keynumber = math.min(9, math.max(#tags[s], keynumber));
182 for i = 1, keynumber do
183 keybinding({ modkey }, i,
184 function ()
185 local screen = mouse.screen
186 if tags[screen][i] then
187 awful.tag.viewonly(tags[screen][i])
189 end):add()
190 keybinding({ modkey, "Control" }, i,
191 function ()
192 local screen = mouse.screen
193 if tags[screen][i] then
194 tags[screen][i].selected = not tags[screen][i].selected
196 end):add()
197 keybinding({ modkey, "Shift" }, i,
198 function ()
199 if client.focus then
200 if tags[client.focus.screen][i] then
201 awful.client.movetotag(tags[client.focus.screen][i])
204 end):add()
205 keybinding({ modkey, "Control", "Shift" }, i,
206 function ()
207 if client.focus then
208 if tags[client.focus.screen][i] then
209 awful.client.toggletag(tags[client.focus.screen][i])
212 end):add()
215 keybinding({ modkey }, "Left", awful.tag.viewprev):add()
216 keybinding({ modkey }, "Right", awful.tag.viewnext):add()
217 keybinding({ modkey }, "Escape", awful.tag.history.restore):add()
219 -- Standard program
220 keybinding({ modkey }, "Return", function () awful.util.spawn(terminal) end):add()
222 keybinding({ modkey, "Control" }, "r", function ()
223 mypromptbox[mouse.screen].text =
224 awful.util.escape(awful.util.restart())
225 end):add()
226 keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
228 -- Client manipulation
229 keybinding({ modkey }, "m", awful.client.maximize):add()
230 keybinding({ modkey }, "f", function () client.focus.fullscreen = not client.focus.fullscreen end):add()
231 keybinding({ modkey, "Shift" }, "c", function () client.focus:kill() end):add()
232 keybinding({ modkey }, "j", function () awful.client.focus.byidx(1); client.focus:raise() end):add()
233 keybinding({ modkey }, "k", function () awful.client.focus.byidx(-1); client.focus:raise() end):add()
234 keybinding({ modkey, "Shift" }, "j", function () awful.client.swap(1) end):add()
235 keybinding({ modkey, "Shift" }, "k", function () awful.client.swap(-1) end):add()
236 keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
237 keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
238 keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
239 keybinding({ modkey, "Control" }, "Return", function () client.focus:swap(awful.client.master()) end):add()
240 keybinding({ modkey }, "o", awful.client.movetoscreen):add()
241 keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add()
242 keybinding({ modkey }, "u", awful.client.urgent.jumpto):add()
243 keybinding({ modkey, "Shift" }, "r", function () client.focus:redraw() end):add()
245 -- Layout manipulation
246 keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
247 keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
248 keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add()
249 keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add()
250 keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add()
251 keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add()
252 keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
253 keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
255 -- Prompt
256 keybinding({ modkey }, "F1", function ()
257 awful.prompt.run({ prompt = "Run: " }, mypromptbox[mouse.screen], awful.util.spawn, awful.completion.bash,
258 awful.util.getdir("cache") .. "/history")
259 end):add()
260 keybinding({ modkey }, "F4", function ()
261 awful.prompt.run({ prompt = "Run Lua code: " }, mypromptbox[mouse.screen], awful.util.eval, awful.prompt.bash,
262 awful.util.getdir("cache") .. "/history_eval")
263 end):add()
265 keybinding({ modkey, "Ctrl" }, "i", function ()
266 local s = mouse.screen
267 if mypromptbox[s].text then
268 mypromptbox[s].text = nil
269 else
270 mypromptbox[s].text = nil
271 if client.focus.class then
272 mypromptbox[s].text = "Class: " .. client.focus.class .. " "
274 if client.focus.instance then
275 mypromptbox[s].text = mypromptbox[s].text .. "Instance: ".. client.focus.instance .. " "
277 if client.focus.role then
278 mypromptbox[s].text = mypromptbox[s].text .. "Role: ".. client.focus.role
281 end):add()
283 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
284 keybinding({ modkey }, "t", awful.client.togglemarked):add()
286 for i = 1, keynumber do
287 keybinding({ modkey, "Shift" }, "F" .. i,
288 function ()
289 local screen = mouse.screen
290 if tags[screen][i] then
291 for k, c in pairs(awful.client.getmarked()) do
292 awful.client.movetotag(tags[screen][i], c)
295 end):add()
297 -- }}}
299 -- {{{ Hooks
300 -- Hook function to execute when focusing a client.
301 awful.hooks.focus.register(function (c)
302 if not awful.client.ismarked(c) then
303 c.border_color = beautiful.border_focus
305 end)
307 -- Hook function to execute when unfocusing a client.
308 awful.hooks.unfocus.register(function (c)
309 if not awful.client.ismarked(c) then
310 c.border_color = beautiful.border_normal
312 end)
314 -- Hook function to execute when marking a client
315 awful.hooks.marked.register(function (c)
316 c.border_color = beautiful.border_marked
317 end)
319 -- Hook function to execute when unmarking a client.
320 awful.hooks.unmarked.register(function (c)
321 c.border_color = beautiful.border_focus
322 end)
324 -- Hook function to execute when the mouse enters a client.
325 awful.hooks.mouse_enter.register(function (c)
326 -- Sloppy focus, but disabled for magnifier layout
327 if awful.layout.get(c.screen) ~= "magnifier"
328 and awful.client.focus.filter(c) then
329 client.focus = c
331 end)
333 -- Hook function to execute when a new client appears.
334 awful.hooks.manage.register(function (c)
335 if use_titlebar then
336 -- Add a titlebar
337 awful.titlebar.add(c, { modkey = modkey })
339 -- Add mouse bindings
340 c:buttons({
341 button({ }, 1, function (c) client.focus = c; c:raise() end),
342 button({ modkey }, 1, function (c) c:mouse_move() end),
343 button({ modkey }, 3, function (c) c:mouse_resize() end)
345 -- New client may not receive focus
346 -- if they're not focusable, so set border anyway.
347 c.border_width = beautiful.border_width
348 c.border_color = beautiful.border_normal
349 client.focus = c
351 -- Check if the application should be floating.
352 local cls = c.class
353 local inst = c.instance
354 if floatapps[cls] then
355 c.floating = floatapps[cls]
356 elseif floatapps[inst] then
357 c.floating = floatapps[inst]
360 -- Check application->screen/tag mappings.
361 local target
362 if apptags[cls] then
363 target = apptags[cls]
364 elseif apptags[inst] then
365 target = apptags[inst]
367 if target then
368 c.screen = target.screen
369 awful.client.movetotag(tags[target.screen][target.tag], c)
372 -- Set the windows at the slave,
373 -- i.e. put it at the end of others instead of setting it master.
374 -- awful.client.setslave(c)
376 -- Honor size hints: if you want to drop the gaps between windows, set this to false.
377 -- c.honorsizehints = false
378 end)
380 -- Hook function to execute when arranging the screen.
381 -- (tag switch, new client, etc)
382 awful.hooks.arrange.register(function (screen)
383 local layout = awful.layout.get(screen)
384 if layout then
385 mylayoutbox[screen].image = image("@AWESOME_ICON_PATH@/layouts/" .. layout .. "w.png")
386 else
387 mylayoutbox[screen].image = nil
390 -- Give focus to the latest client in history if no window has focus
391 -- or if the current window is a desktop or a dock one.
392 if not client.focus then
393 local c = awful.client.focus.history.get(screen, 0)
394 if c then client.focus = c end
397 -- Uncomment if you want mouse warping
398 --[[
399 if client.focus then
400 local c_c = client.focus:fullgeometry()
401 local m_c = mouse.coords()
403 if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
404 m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
405 if table.maxn(m_c.buttons) == 0 then
406 mouse.coords({ x = c_c.x + 5, y = c_c.y + 5})
411 end)
413 -- Hook called every second
414 awful.hooks.timer.register(1, function ()
415 -- For unix time_t lovers
416 mytextbox.text = " " .. os.time() .. " time_t "
417 -- Otherwise use:
418 -- mytextbox.text = " " .. os.date() .. " "
419 end)
420 -- }}}