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>'
45 for s = 1, screen.count() do
46 -- Each screen has its own tag table.
49 table.insert(p, "work-"..i)
51 tags[s] = awful.tag(p, s, awful.layout.suit.tile)
54 -- Get the screen number we're on
56 function mtag.getn(idx, s)
57 return tags[s or mouse.screen][idx]
59 function mtag.viewonly (idx, s)
60 local t = mtag.getn(idx, s)
61 if t then awful.tag.viewonly(t) end
63 function mtag.viewtoggle (idx, s)
64 local t = mtag.getn(idx, s)
65 if t then awful.tag.viewtoggle(t) end
67 function mtag.isoccupied(s, t)
68 local clients = (t and t:clients()) or {}
71 function mtag.occupied(s)
74 if not s then s = mouse.screen end
75 for t in pairs(tags[s]) do
77 if mtag.isoccupied(s, t) then table.insert(p, t) end
81 function mtag.getnext(s)
82 if s == nil then s = mouse.screen end
84 local p = mtag.occupied(s)
85 local curtag = awful.tag.selected()
90 if mtag.isoccupied(s, curtag) then
92 if curtag == p[x] then t = x end
99 for x in pairs(tags[s]) do
100 if curtag == tags[s][x] then o = x end
101 if mtag.isoccupied(s, tags[s][x]) then lasto = x end
104 -- Now: t is # in non-empty, o is # in all
105 if o == table.maxn(tags[s]) then
106 -- We're the last tag, create a new one
108 -- We're empty, go to first
111 -- We're occupied, create new
116 -- We're empty, check if we're last
118 -- We're also later than the last non-empty
122 -- Nevermind, get the next
131 function mtag.next(s)
132 awful.tag.viewonly(mtag.getnext(s))
134 function mtag.movetonext(s)
135 local t = mtag.getnext(s)
136 awful.client.movetotag(t)
137 awful.tag.viewonly(t)
139 function mtag.getprev(s)
140 if s == nil then s = mouse.screen end
142 local p = mtag.occupied(s)
143 local curtag = awful.tag.selected()
148 if mtag.isoccupied(s, curtag) then
150 if curtag == p[x] then t = x end
157 for x in pairs(tags[s]) do
158 if curtag == tags[s][x] then o = x end
159 if mtag.isoccupied(s, tags[s][x]) then lasto = x end
162 -- Now: t is # in non-empty, o is # in all
164 -- We're the very first tag, wrap around
165 return p[ table.maxn(p) ]
167 -- We're not first, just go prev
171 function mtag.prev(s)
172 awful.tag.viewonly(mtag.getprev(s))
174 function mtag.movetoprev(s)
175 local t = mtag.getprev(s)
176 awful.client.movetotag(t)
177 awful.tag.viewonly(t)
184 local icondir = awful.util.getdir("config").."/icons/"
186 function make_icon(fname, left, right, h, bg)
187 local icon = image(icondir..fname)
188 local ib = widget { type = 'imagebox' }
189 local w = left + icon.width + right
190 local i = image.argb32(w, h, nil)
192 i:draw_rectangle(0, 0, w, h, true, beautiful.bg_normal)
193 i:insert(icon, left, math.floor((h - icon.height) / 2))
202 maintaglist.buttons = awful.util.table.join(
203 awful.button(k_n, 1, awful.tag.viewonly),
204 awful.button(k_s, 1, awful.client.toggletag)
206 maintaglist.label = awful.widget.taglist.label.noempty
211 mypromptbox = awful.widget.prompt{
212 layout = awful.widget.layout.horizontal.leftright
218 cpuicon = make_icon('cpu.png', 16, 4, 16)
220 cputextwidget = widget({ type = 'textbox' })
222 vicious.register(cputextwidget, vicious.widgets.cpu,
223 function (widget, args)
224 local r = tonumber(args[1])
225 local percent = args[1]..'%'
227 percent = '0'..percent
230 percent = fg(theme.fg_focus, percent)
232 percent = fg('yellow', percent)
234 percent = fg('orange', percent)
236 percent = fg('#ff4040', percent)
242 -- {{{ Memory Usage Widget
244 memicon = make_icon('mem.png', 16, 4, 16)
246 memtextwidget = widget({ type = 'textbox' })
248 vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args)
249 -- Add extra preceding zeroes when needed
250 local r = tonumber(args[1])
251 local percent = args[1]..'%'
253 percent = '0'..percent
256 percent = fg(theme.fg_focus, percent)
258 percent = fg('orange', percent)
260 percent = fg('red', percent)
262 return percent..' '..args[2]..'M'
268 clockicon = make_icon('clock.png', 16, 4, 16)
270 clockwidget = widget({ type = "textbox" })
271 vicious.register(clockwidget, vicious.widgets.date,
272 fg(theme.fg_focus, "%H:%M") .. " %a %d %b ", 10)
278 for s = 1, screen.count() do
279 local lr_layout = awful.widget.layout.horizontal.leftright
280 local rl_layout = awful.widget.layout.horizontal.rightleft
282 mainstatusbar[s] = awful.wibox{ position = "top", height = 16, screen = s }
284 mainstatusbar[s].widgets = {
286 awful.widget.taglist(s, maintaglist.label, maintaglist.buttons),
290 s == 1 and widget{ type = 'systray' } or nil,
291 clockwidget, clockicon,
292 memtextwidget, memicon,
293 cputextwidget, cpuicon,
294 layout = awful.widget.layout.horizontal.rightleft
303 globalkeys = awful.util.table.join(
304 -- Mod+{A/S}: Switch to prev/next tag
305 awful.key(k_m, "Left", mtag.prev),
306 awful.key(k_m, "Right", mtag.next),
308 -- Mod+Shift+{A/S}: Move window to Prev/Next tag
309 awful.key(k_ms, "Left", mtag.movetoprev),
310 awful.key(k_ms, "Right", mtag.movetonext),
312 -- Mod+Shift_{E/D}: move window to next/prev screen
313 awful.key(k_mc, "Right", function()
314 client.focus.screen = awful.util.cycle(screen.count(), mouse.screen + 1)
316 awful.key(k_mc, "Left", function()
317 client.focus.screen = awful.util.cycle(screen.count(), mouse.screen - 1)
321 -- Focus Prev/Next window
324 awful.client.focus.byidx(1)
325 if client.focus then client.focus:raise() end
329 awful.client.focus.byidx(-1)
330 if client.focus then client.focus:raise() end
333 -- Swap window with the Prev/Next one
334 awful.key(k_ms, "j", function () awful.client.swap.byidx(1) end),
335 awful.key(k_ms, "k", function () awful.client.swap.byidx(-1) end),
337 -- Mod+{E/D}: Switch to next/previous screen
338 awful.key(k_m, "Tab", function () awful.screen.focus_relative(1) end),
339 awful.key(k_ms, "Tab", function () awful.screen.focus_relative(-1) end),
341 -- Mod+Enter: Launch a new terminal
342 awful.key(k_m, "e", function() awful.util.spawn("firefox") end),
343 awful.key(k_m, "Return", function() awful.util.spawn(terminal) end),
344 awful.key(k_ac, "r", awesome.restart),
345 awful.key(k_m, "F12", function() awful.util.spawn(lock) end),
346 awful.key({}, "#148", function() awful.util.spawn("kcalc") end),
348 -- Layout manipulation
349 awful.key(k_m, "l", function () awful.tag.incmwfact(0.05) end),
350 awful.key(k_m, "h", function () awful.tag.incmwfact(-0.05) end),
351 awful.key(k_ms, "h", function () awful.tag.incnmaster(1) end),
352 awful.key(k_ms, "l", function () awful.tag.incnmaster(-1) end),
353 awful.key(k_mc, "h", function () awful.tag.incncol(1) end),
354 awful.key(k_mc, "l", function () awful.tag.incncol(-1) end),
357 awful.key(k_m, "r", function () mypromptbox:run() end),
360 awful.prompt.run({ prompt = "Run Lua code: " },
362 awful.util.eval, nil,
363 awful.util.getdir("cache").."/lua_commands")
366 awful.key({}, "#192", function() mtag.viewonly(1) end),
367 awful.key({}, "#193", function() mtag.viewonly(2) end),
368 awful.key({}, "#194", function() mtag.viewonly(3) end),
369 awful.key({}, "#195", function() mtag.viewonly(4) end),
370 awful.key({}, "#196", function() mtag.viewonly(5) end)
373 -- Mod+#: Switch to tag
374 -- Mod+Shift+#: Toggle tag display
375 -- Mod+Control+#: Move client to tag
376 -- Mod+Alt+#: Toggle client on tag
379 globalkeys = awful.util.table.join(
381 awful.key(k_m, i % 10, function() mtag.viewonly(i) end),
382 awful.key(k_ms, i % 10, function() mtag.viewtoggle(i) end),
383 awful.key(k_mc, i % 10,
385 if client.focus and tags[client.focus.screen][i] then
386 awful.client.movetotag(tags[client.focus.screen][i])
389 awful.key(k_mcs, i % 10,
391 if client.focus and tags[client.focus.screen][i] then
392 awful.client.toggletag(tags[client.focus.screen][i])
399 ---- {{{ Client hotkeys / buttons
401 local clientkeys = awful.util.table.join(
402 awful.key(k_m, "i", function (c)
403 if mypromptbox.widget.text then
404 mypromptbox.widget.text = ""
406 mypromptbox.widget.text = "Class: " .. c.class .. " Instance: ".. c.instance
410 -- Client manipulation
411 awful.key(k_m, "c", function (c) c:kill() end),
412 awful.key(k_m, "o", awful.client.floating.toggle),
413 awful.key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end)
416 local clientbuttons = awful.util.table.join(
417 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
418 awful.button(k_a, 1, awful.mouse.client.move),
419 awful.button(k_a, 3, awful.mouse.client.resize)
424 root.keys(globalkeys)
428 awful.rules.rules = {
429 -- All clients will match this rule.
433 border_width = beautiful.border_width,
434 border_color = beautiful.border_normal,
437 buttons = clientbuttons,
438 size_hints_honor = false,
441 { rule = { class = "MPlayer" }, properties = { floating = true } },
442 { rule = { class = "pinentry" }, properties = { floating = true } },
443 -- Set Firefox to always map on tags number 2 of screen 1.
444 -- { rule = { class = "Firefox" },
445 -- properties = { tag = tags[1][2] } },
451 function warp_mouse(c)
452 local o = awful.mouse.client_under_pointer()
453 if not o or o ~= c then
454 local g = c:geometry()
455 mouse.coords({ x = g.x + 5, y = g.y + 5 }, true)
459 client.add_signal("focus", function (c)
460 if not awful.client.ismarked(c) then
461 c.border_color = beautiful.border_focus
466 client.add_signal("unfocus", function (c)
467 if not awful.client.ismarked(c) then
468 c.border_color = beautiful.border_normal
472 client.add_signal("manage", function (c, startup)
473 c:add_signal("mouse::enter", function(c) client.focus = c end)
476 for s = 1, screen.count() do
477 screen[s]:add_signal("arrange", function ()
478 if client.focus and client.focus.screen == s then
479 warp_mouse(client.focus)
486 awful.util.spawn("xkbcomp -w 0 -R/usr/share/X11/xkb /home/madcoder/.Xkeyboard :0")
487 awful.util.spawn("xsetroot -cursor_name left_ptr")