1 -- awesome 3 configuration file
3 -- Include awesome library, with lots of useful function!
5 require("awful.autofocus")
10 terminal = "x-terminal-emulator"
11 lock = 'xscreensaver-command -lock'
12 beautiful.init(awful.util.getdir("config").."/theme")
22 k_ms = {modkey, shift}
24 k_mc = {modkey, control}
25 k_mcs = {modkey, control, shift}
29 k_cs = {control, shift}
33 -- {{{ Markup helper functions
34 -- Inline markup is a tad ugly, so use these functions
35 -- to dynamically create markup.
36 function fg(color, text)
37 return '<span color="'..color..'">'..text..'</span>'
40 function heading(text)
41 return fg(beautiful.fg_focus, text)
49 for s = 1, screen.count() do
50 -- Each screen has its own tag table.
53 table.insert(p, "work-"..i)
55 tags[s] = awful.tag(p, s, awful.layout.suit.tile)
58 -- Get the screen number we're on
60 local sel = client.focus
61 return (sel and sel.screen) or mouse.screen
65 function mtag.getn(idx, s)
66 return tags[s or getscreen()][idx]
68 function mtag.viewonly (idx, s)
69 local t = mtag.getn(idx, s)
70 if t then awful.tag.viewonly(t) end
72 function mtag.viewtoggle (idx, s)
73 local t = mtag.getn(idx, s)
74 if t then awful.tag.viewtoggle(t) end
76 function mtag.isoccupied(s, t)
77 local clients = (t and t:clients()) or {}
80 function mtag.occupied(s)
83 if not s then s = getscreen() end
84 for t in pairs(tags[s]) do
86 if mtag.isoccupied(s, t) then table.insert(p, t) end
90 function mtag.getnext(s)
91 if s == nil then s = getscreen() end
93 local p = mtag.occupied(s)
94 local curtag = awful.tag.selected()
99 if mtag.isoccupied(s, curtag) then
101 if curtag == p[x] then t = x end
108 for x in pairs(tags[s]) do
109 if curtag == tags[s][x] then o = x end
110 if mtag.isoccupied(s, tags[s][x]) then lasto = x end
113 -- Now: t is # in non-empty, o is # in all
114 if o == table.maxn(tags[s]) then
115 -- We're the last tag, create a new one
117 -- We're empty, go to first
120 -- We're occupied, create new
125 -- We're empty, check if we're last
127 -- We're also later than the last non-empty
131 -- Nevermind, get the next
140 function mtag.next(s)
141 awful.tag.viewonly(mtag.getnext(s))
143 function mtag.movetonext(s)
144 local t = mtag.getnext(s)
145 awful.client.movetotag(t)
146 awful.tag.viewonly(t)
148 function mtag.getprev(s)
149 if s == nil then s = getscreen() end
151 local p = mtag.occupied(s)
152 local curtag = awful.tag.selected()
157 if mtag.isoccupied(s, curtag) then
159 if curtag == p[x] then t = x end
166 for x in pairs(tags[s]) do
167 if curtag == tags[s][x] then o = x end
168 if mtag.isoccupied(s, tags[s][x]) then lasto = x end
171 -- Now: t is # in non-empty, o is # in all
173 -- We're the very first tag, wrap around
174 return p[ table.maxn(p) ]
176 -- We're not first, just go prev
180 function mtag.prev(s)
181 awful.tag.viewonly(mtag.getprev(s))
183 function mtag.movetoprev(s)
184 local t = mtag.getprev(s)
185 awful.client.movetotag(t)
186 awful.tag.viewonly(t)
196 maintaglist.buttons = awful.util.table.join(
197 awful.button(k_n, 1, awful.tag.viewonly),
198 awful.button(k_s, 1, awful.client.toggletag)
202 -- {{{ Load Average Widget
204 loadwidget = widget({ type = 'textbox' })
205 load_update = function()
206 -- Use /proc/loadavg to get the average system load on 1, 5 and 15 minute intervals
207 local f = io.open('/proc/loadavg')
211 -- Find the third space
212 local pos = n:find(' ', n:find(' ', n:find(' ')+1)+1)
214 loadwidget.text = heading('Load')..': '..n:sub(1,pos-1)
218 t = timer { timeout = 10 }
219 t:add_signal("timeout", load_update)
223 -- {{{ CPU Usage Widget
225 cputextwidget = widget({ type = 'textbox' })
226 cpugraphwidget = awful.widget.graph{
227 width = 40, height = 16,
228 layout = awful.widget.layout.horizontal.rightleft
230 cpugraphwidget:set_background_color('#333333')
231 cpugraphwidget:set_border_color('#0a0a0a')
232 cpugraphwidget:set_gradient_colors({ '#285577', '#285577', '#AEC6D8' })
234 vicious.register(cputextwidget, vicious.widgets.cpu,
235 function (widget, args)
236 local r = tonumber(args[1])
237 local percent = args[1]..'%'
239 percent = '0'..percent
242 percent = fg('green', percent)
244 percent = fg('yellow', percent)
246 percent = fg('orange', percent)
248 percent = fg('red', percent)
250 -- cpugraphwidget:add_value(r / 100)
251 return heading('CPU')..': '..percent..' '
255 -- {{{ CPU Graph Widget
258 -- {{{ Memory Usage Widget
260 memtextwidget = widget({ type = 'textbox' })
262 memtextwidget.text = heading('MEM')..': '
263 vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args)
264 -- Add extra preceding zeroes when needed
265 local r = tonumber(args[1])
266 local percent = args[1]..'%'
268 percent = '0'..percent
271 percent = fg('green', percent)
273 percent = fg('orange', percent)
275 percent = fg('red', percent)
277 return heading('MEM')..': '..percent..' '..args[2]..'M'
283 rspacer = widget({ type = 'textbox' })
289 clockwidget = widget({ type = "textbox" })
290 vicious.register(clockwidget, vicious.widgets.date, fg("#dddddd", "%a %d %b - %H:%M"), 10)
294 mymenubox = widget{ type = "textbox" }
299 mysystray = widget({ type = "systray" })
301 for s = 1, screen.count() do
302 mainstatusbar[s] = awful.wibox{ position = "top", height = 18, screen = s }
304 mainstatusbar[s].widgets = {
306 awful.widget.taglist(s, awful.widget.taglist.label.noempty, maintaglist.buttons),
308 awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright }),
309 layout = awful.widget.layout.horizontal.leftright
311 s == 1 and mysystray or nil,
312 s == 1 and rspacer or nil,
313 clockwidget, rspacer,
314 memtextwidget, rspacer,
315 cpugraphwidget, cputextwidget, rspacer,
317 layout = awful.widget.layout.horizontal.rightleft
326 local hist = os.getenv("HOME") .. "/.cache/awesome/history"
327 globalkeys = awful.util.table.join(
328 -- Mod+{A/S}: Switch to prev/next tag
329 awful.key(k_m, "Left", mtag.prev),
330 awful.key(k_m, "Right", mtag.next),
332 -- Mod+Shift+{A/S}: Move window to Prev/Next tag
333 awful.key(k_ms, "Left", mtag.movetoprev),
334 awful.key(k_ms, "Right", mtag.movetonext),
336 -- Mod+Shift_{E/D}: move window to next/prev screen
337 awful.key(k_mc, "Right", function()
338 local s = getscreen() + 1
339 while s > screen.count() do s = s - screen.count() end
340 client.focus.screen = s
342 awful.key(k_mc, "Left", function()
343 local s = getscreen() - 1
344 while s < 1 do s = s + screen.count() end
345 client.focus.screen = s
349 -- Focus Prev/Next window
352 awful.client.focus.byidx(1)
353 if client.focus then client.focus:raise() end
357 awful.client.focus.byidx(-1)
358 if client.focus then client.focus:raise() end
361 -- Swap window with the Prev/Next one
362 awful.key(k_ms, "j", function () awful.client.swap.byidx(1) end),
363 awful.key(k_ms, "k", function () awful.client.swap.byidx(-1) end),
365 -- Mod+{E/D}: Switch to next/previous screen
366 awful.key(k_m, "Tab", function () awful.screen.focus_relative(1) end),
367 awful.key(k_ms, "Tab", function () awful.screen.focus_relative(-1) end),
369 -- Mod+Enter: Launch a new terminal
370 awful.key(k_m, "e", function() awful.util.spawn("firefox") end),
371 awful.key(k_m, "Return", function() awful.util.spawn(terminal) end),
372 awful.key(k_ac, "r", awesome.restart),
373 awful.key(k_m, "F12", function() awful.util.spawn(lock) end),
374 awful.key({}, "#148", function() awful.util.spawn("kcalc") end),
376 -- Layout manipulation
377 awful.key(k_m, "l", function () awful.tag.incmwfact(0.05) end),
378 awful.key(k_m, "h", function () awful.tag.incmwfact(-0.05) end),
379 awful.key(k_ms, "h", function () awful.tag.incnmaster(1) end),
380 awful.key(k_ms, "l", function () awful.tag.incnmaster(-1) end),
381 awful.key(k_mc, "h", function () awful.tag.incncol(1) end),
382 awful.key(k_mc, "l", function () awful.tag.incncol(-1) end),
387 awful.prompt.run({ prompt = "Run: " },
390 awful.completion.shell,
391 awful.util.getdir("cache").."/commands")
395 awful.prompt.run({ prompt = "Run Lua code: " },
399 awful.util.getdir("cache").."/lua_commands")
402 awful.key({}, "#192", function() mtag.viewonly(1) end),
403 awful.key({}, "#193", function() mtag.viewonly(2) end),
404 awful.key({}, "#194", function() mtag.viewonly(3) end),
405 awful.key({}, "#195", function() mtag.viewonly(4) end),
406 awful.key({}, "#196", function() mtag.viewonly(5) end)
409 -- Mod+#: Switch to tag
410 -- Mod+Shift+#: Toggle tag display
411 -- Mod+Control+#: Move client to tag
412 -- Mod+Alt+#: Toggle client on tag
415 globalkeys = awful.util.table.join(
417 awful.key(k_m, i % 10, function() mtag.viewonly(i) end),
418 awful.key(k_ms, i % 10, function() mtag.viewtoggle(i) end),
419 awful.key(k_mc, i % 10,
421 if client.focus and tags[client.focus.screen][i] then
422 awful.client.movetotag(tags[client.focus.screen][i])
425 awful.key(k_mcs, i % 10,
427 if client.focus and tags[client.focus.screen][i] then
428 awful.client.toggletag(tags[client.focus.screen][i])
435 ---- {{{ Client hotkeys / buttons
437 local clientkeys = awful.util.table.join(
438 awful.key(k_m, "i", function (c)
439 if mymenubox.text then
442 mymenubox.text = "Class: " .. c.class .. " Instance: ".. c.instance
446 -- Client manipulation
447 awful.key(k_m, "c", function (c) c:kill() end),
448 awful.key(k_m, "o", awful.client.floating.toggle),
449 awful.key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end)
452 local clientbuttons = awful.util.table.join(
453 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
454 awful.button(k_a, 1, awful.mouse.client.move),
455 awful.button(k_a, 3, awful.mouse.client.resize)
460 root.keys(globalkeys)
464 awful.rules.rules = {
465 -- All clients will match this rule.
469 border_width = beautiful.border_width,
470 border_color = beautiful.border_normal,
473 buttons = clientbuttons,
474 size_hints_honor = false,
477 { rule = { class = "MPlayer" }, properties = { floating = true } },
478 { rule = { class = "pinentry" }, properties = { floating = true } },
479 -- Set Firefox to always map on tags number 2 of screen 1.
480 -- { rule = { class = "Firefox" },
481 -- properties = { tag = tags[1][2] } },
487 client.add_signal("focus", function (c)
488 if not awful.client.ismarked(c) then
489 c.border_color = beautiful.border_focus
493 client.add_signal("unfocus", function (c)
494 if not awful.client.ismarked(c) then
495 c.border_color = beautiful.border_normal
499 client.add_signal("manage", function (c, startup)
500 -- Enable sloppy focus
501 c:add_signal("mouse::enter", function(c)
509 function warp_mouse(screen)
510 local c = client.focus
513 local o = awful.mouse.client_under_pointer()
514 if not o or o ~= c then
515 local g = c:geometry()
516 mouse.coords { x = g.x + 5, y = g.y + 5 }
521 for s = 1, screen.count() do
522 -- screen[s]:add_signal("arrange", warp_mouse)
527 awful.util.spawn("xkbcomp -w 0 -R/usr/share/X11/xkb /home/madcoder/.Xkeyboard :0")