beautiful: simplify data retrieval
[awesome.git] / awesomerc.lua.in
blob83a2d43cb5621c19e7deffd1ea8ca0b01592c20d
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"
12 -- Uncommment this for a lighter theme
13 -- theme_path = "@AWESOME_THEMES_PATH@/sky/theme"
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 "tile",
34 "tileleft",
35 "tilebottom",
36 "tiletop",
37 "fairh",
38 "fairv",
39 "magnifier",
40 "max",
41 "fullscreen",
42 "spiral",
43 "dwindle",
44 "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({ name = tagnumber, layout = layouts[1] })
82 -- Add tags to screen one by one
83 tags[s][tagnumber].screen = s
84 end
85 -- I'm sure you want to see at least one tag.
86 tags[s][1].selected = true
87 end
88 -- }}}
90 -- {{{ Wibox
91 -- Create a textbox widget
92 mytextbox = widget({ type = "textbox", align = "right" })
93 -- Set the default text in textbox
94 mytextbox.text = "<b><small> " .. AWESOME_RELEASE .. " </small></b>"
96 -- Create a laucher widget and a main menu
97 myawesomemenu = {
98 { "manual", terminal .. " -e man awesome" },
99 { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
100 { "restart", awesome.restart },
101 { "quit", awesome.quit }
104 mymainmenu = awful.menu.new({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
105 { "open terminal", terminal }
109 mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
110 menu = mymainmenu })
112 -- Create a systray
113 mysystray = widget({ type = "systray", align = "right" })
115 -- Create a wibox for each screen and add it
116 mywibox = {}
117 mypromptbox = {}
118 mylayoutbox = {}
119 mytaglist = {}
120 mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
121 button({ modkey }, 1, awful.client.movetotag),
122 button({ }, 3, function (tag) tag.selected = not tag.selected end),
123 button({ modkey }, 3, awful.client.toggletag),
124 button({ }, 4, awful.tag.viewnext),
125 button({ }, 5, awful.tag.viewprev) }
126 mytasklist = {}
127 mytasklist.buttons = { button({ }, 1, function (c) client.focus = c; c:raise() end),
128 button({ }, 3, function () awful.menu.clients({ width=250 }) end),
129 button({ }, 4, function () awful.client.focus.byidx(1) end),
130 button({ }, 5, function () awful.client.focus.byidx(-1) end) }
132 for s = 1, screen.count() do
133 -- Create a promptbox for each screen
134 mypromptbox[s] = widget({ type = "textbox", align = "left" })
135 -- Create an imagebox widget which will contains an icon indicating which layout we're using.
136 -- We need one layoutbox per screen.
137 mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
138 mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
139 button({ }, 3, function () awful.layout.inc(layouts, -1) end),
140 button({ }, 4, function () awful.layout.inc(layouts, 1) end),
141 button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
142 -- Create a taglist widget
143 mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
145 -- Create a tasklist widget
146 mytasklist[s] = awful.widget.tasklist.new(function(c)
147 return awful.widget.tasklist.label.currenttags(c, s)
148 end, mytasklist.buttons)
150 -- Create the wibox
151 mywibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
152 -- Add widgets to the wibox - order matters
153 mywibox[s].widgets = { mylauncher,
154 mytaglist[s],
155 mytasklist[s],
156 mypromptbox[s],
157 mytextbox,
158 mylayoutbox[s],
159 s == 1 and mysystray or nil }
160 mywibox[s].screen = s
162 -- }}}
164 -- {{{ Mouse bindings
165 awesome.buttons({
166 button({ }, 3, function () mymainmenu:toggle() end),
167 button({ }, 4, awful.tag.viewnext),
168 button({ }, 5, awful.tag.viewprev)
170 -- }}}
172 -- {{{ Key bindings
174 -- Bind keyboard digits
175 -- Compute the maximum number of digit we need, limited to 9
176 keynumber = 0
177 for s = 1, screen.count() do
178 keynumber = math.min(9, math.max(#tags[s], keynumber));
181 for i = 1, keynumber do
182 keybinding({ modkey }, i,
183 function ()
184 local screen = mouse.screen
185 if tags[screen][i] then
186 awful.tag.viewonly(tags[screen][i])
188 end):add()
189 keybinding({ modkey, "Control" }, i,
190 function ()
191 local screen = mouse.screen
192 if tags[screen][i] then
193 tags[screen][i].selected = not tags[screen][i].selected
195 end):add()
196 keybinding({ modkey, "Shift" }, i,
197 function ()
198 if client.focus and tags[client.focus.screen][i] then
199 awful.client.movetotag(tags[client.focus.screen][i])
201 end):add()
202 keybinding({ modkey, "Control", "Shift" }, i,
203 function ()
204 if client.focus and tags[client.focus.screen][i] then
205 awful.client.toggletag(tags[client.focus.screen][i])
207 end):add()
210 keybinding({ modkey }, "Left", awful.tag.viewprev):add()
211 keybinding({ modkey }, "Right", awful.tag.viewnext):add()
212 keybinding({ modkey }, "Escape", awful.tag.history.restore):add()
214 -- Standard program
215 keybinding({ modkey }, "Return", function () awful.util.spawn(terminal) end):add()
217 keybinding({ modkey, "Control" }, "r", function ()
218 mypromptbox[mouse.screen].text =
219 awful.util.escape(awful.util.restart())
220 end):add()
221 keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
223 -- Client manipulation
224 keybinding({ modkey }, "m", function () if client.focus then client.focus.maximized_horizontal = not client.focus.maximized_horizontal
225 client.focus.maximized_vertical = not client.focus.maximized_vertical end end):add()
226 keybinding({ modkey }, "f", function () if client.focus then client.focus.fullscreen = not client.focus.fullscreen end end):add()
227 keybinding({ modkey, "Shift" }, "c", function () if client.focus then client.focus:kill() end end):add()
228 keybinding({ modkey }, "j", function () awful.client.focus.byidx(1); if client.focus then client.focus:raise() end end):add()
229 keybinding({ modkey }, "k", function () awful.client.focus.byidx(-1); if client.focus then client.focus:raise() end end):add()
230 keybinding({ modkey, "Shift" }, "j", function () awful.client.swap.byidx(1) end):add()
231 keybinding({ modkey, "Shift" }, "k", function () awful.client.swap.byidx(-1) end):add()
232 keybinding({ modkey, "Control" }, "j", function () awful.screen.focus(1) end):add()
233 keybinding({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end):add()
234 keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
235 keybinding({ modkey, "Control" }, "Return", function () if client.focus then client.focus:swap(awful.client.getmaster()) end end):add()
236 keybinding({ modkey }, "o", awful.client.movetoscreen):add()
237 keybinding({ modkey }, "Tab", awful.client.focus.history.previous):add()
238 keybinding({ modkey }, "u", awful.client.urgent.jumpto):add()
239 keybinding({ modkey, "Shift" }, "r", function () if client.focus then client.focus:redraw() end end):add()
241 -- Layout manipulation
242 keybinding({ modkey }, "l", function () awful.tag.incmwfact(0.05) end):add()
243 keybinding({ modkey }, "h", function () awful.tag.incmwfact(-0.05) end):add()
244 keybinding({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end):add()
245 keybinding({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end):add()
246 keybinding({ modkey, "Control" }, "h", function () awful.tag.incncol(1) end):add()
247 keybinding({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end):add()
248 keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
249 keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
251 -- Prompt
252 keybinding({ modkey }, "F1", function ()
253 awful.prompt.run({ prompt = "Run: " }, mypromptbox[mouse.screen], awful.util.spawn, awful.completion.bash,
254 awful.util.getdir("cache") .. "/history")
255 end):add()
256 keybinding({ modkey }, "F4", function ()
257 awful.prompt.run({ prompt = "Run Lua code: " }, mypromptbox[mouse.screen], awful.util.eval, awful.prompt.bash,
258 awful.util.getdir("cache") .. "/history_eval")
259 end):add()
261 keybinding({ modkey, "Ctrl" }, "i", function ()
262 local s = mouse.screen
263 if mypromptbox[s].text then
264 mypromptbox[s].text = nil
265 elseif client.focus then
266 mypromptbox[s].text = nil
267 if client.focus.class then
268 mypromptbox[s].text = "Class: " .. client.focus.class .. " "
270 if client.focus.instance then
271 mypromptbox[s].text = mypromptbox[s].text .. "Instance: ".. client.focus.instance .. " "
273 if client.focus.role then
274 mypromptbox[s].text = mypromptbox[s].text .. "Role: ".. client.focus.role
277 end):add()
279 -- Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
280 keybinding({ modkey }, "t", awful.client.togglemarked):add()
282 for i = 1, keynumber do
283 keybinding({ modkey, "Shift" }, "F" .. i,
284 function ()
285 local screen = mouse.screen
286 if tags[screen][i] then
287 for k, c in pairs(awful.client.getmarked()) do
288 awful.client.movetotag(tags[screen][i], c)
291 end):add()
293 -- }}}
295 -- {{{ Hooks
296 -- Hook function to execute when focusing a client.
297 awful.hooks.focus.register(function (c)
298 if not awful.client.ismarked(c) then
299 c.border_color = beautiful.border_focus
301 end)
303 -- Hook function to execute when unfocusing a client.
304 awful.hooks.unfocus.register(function (c)
305 if not awful.client.ismarked(c) then
306 c.border_color = beautiful.border_normal
308 end)
310 -- Hook function to execute when marking a client
311 awful.hooks.marked.register(function (c)
312 c.border_color = beautiful.border_marked
313 end)
315 -- Hook function to execute when unmarking a client.
316 awful.hooks.unmarked.register(function (c)
317 c.border_color = beautiful.border_focus
318 end)
320 -- Hook function to execute when the mouse enters a client.
321 awful.hooks.mouse_enter.register(function (c)
322 -- Sloppy focus, but disabled for magnifier layout
323 if awful.layout.get(c.screen) ~= "magnifier"
324 and awful.client.focus.filter(c) then
325 client.focus = c
327 end)
329 -- Hook function to execute when a new client appears.
330 awful.hooks.manage.register(function (c)
331 if use_titlebar then
332 -- Add a titlebar
333 awful.titlebar.add(c, { modkey = modkey })
335 -- Add mouse bindings
336 c:buttons({
337 button({ }, 1, function (c) client.focus = c; c:raise() end),
338 button({ modkey }, 1, awful.mouse.client.move),
339 button({ modkey }, 3, awful.mouse.client.resize)
341 -- New client may not receive focus
342 -- if they're not focusable, so set border anyway.
343 c.border_width = beautiful.border_width
344 c.border_color = beautiful.border_normal
346 -- Check if the application should be floating.
347 local cls = c.class
348 local inst = c.instance
349 if floatapps[cls] then
350 c.floating = floatapps[cls]
351 elseif floatapps[inst] then
352 c.floating = floatapps[inst]
355 -- Check application->screen/tag mappings.
356 local target
357 if apptags[cls] then
358 target = apptags[cls]
359 elseif apptags[inst] then
360 target = apptags[inst]
362 if target then
363 c.screen = target.screen
364 awful.client.movetotag(tags[target.screen][target.tag], c)
367 -- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
368 client.focus = c
370 -- Set the windows at the slave,
371 -- i.e. put it at the end of others instead of setting it master.
372 -- awful.client.setslave(c)
374 -- Honor size hints: if you want to drop the gaps between windows, set this to false.
375 -- c.honorsizehints = false
376 end)
378 -- Hook function to execute when arranging the screen.
379 -- (tag switch, new client, etc)
380 awful.hooks.arrange.register(function (screen)
381 local layout = awful.layout.get(screen)
382 if layout then
383 mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
384 else
385 mylayoutbox[screen].image = nil
388 -- Give focus to the latest client in history if no window has focus
389 -- or if the current window is a desktop or a dock one.
390 if not client.focus then
391 local c = awful.client.focus.history.get(screen, 0)
392 if c then client.focus = c end
395 -- Uncomment if you want mouse warping
396 --[[
397 if client.focus then
398 local c_c = client.focus:fullgeometry()
399 local m_c = mouse.coords()
401 if m_c.x < c_c.x or m_c.x >= c_c.x + c_c.width or
402 m_c.y < c_c.y or m_c.y >= c_c.y + c_c.height then
403 if table.maxn(m_c.buttons) == 0 then
404 mouse.coords({ x = c_c.x + 5, y = c_c.y + 5})
409 end)
411 -- Hook called every second
412 awful.hooks.timer.register(1, function ()
413 -- For unix time_t lovers
414 mytextbox.text = " " .. os.time() .. " time_t "
415 -- Otherwise use:
416 -- mytextbox.text = " " .. os.date() .. " "
417 end)
418 -- }}}