1 -- awesome 3 configuration file
3 -- Include awesome library, with lots of useful function!
5 require("awful.autofocus")
11 lock = 'xscreensaver-command -lock'
12 lock = 'gnome-screensaver-command --lock'
13 beautiful.init(awful.util.getdir("config").."/theme")
23 k_ms = {modkey, shift}
25 k_mc = {modkey, control}
26 k_mcs = {modkey, control, shift}
30 k_cs = {control, shift}
34 -- {{{ Markup helper functions
35 -- Inline markup is a tad ugly, so use these functions
36 -- to dynamically create markup.
37 function fg(color, text)
38 return '<span color="'..color..'">'..text..'</span>'
46 for s = 1, screen.count() do
47 -- Each screen has its own tag table.
50 table.insert(p, "work-"..i)
52 tags[s] = awful.tag(p, s, awful.layout.suit.tile)
55 -- Get the screen number we're on
57 function mtag.getn(idx, s)
58 return tags[s or mouse.screen][idx]
60 function mtag.viewonly (idx, s)
61 local t = mtag.getn(idx, s)
62 if t then awful.tag.viewonly(t) end
64 function mtag.viewtoggle (idx, s)
65 local t = mtag.getn(idx, s)
66 if t then awful.tag.viewtoggle(t) end
68 function mtag.isoccupied(s, t)
69 local clients = (t and t:clients()) or {}
72 function mtag.occupied(s)
75 if not s then s = mouse.screen end
76 for t in pairs(tags[s]) do
78 if mtag.isoccupied(s, t) then table.insert(p, t) end
82 function mtag.getnext(s)
83 if s == nil then s = mouse.screen end
85 local p = mtag.occupied(s)
86 local curtag = awful.tag.selected()
91 if mtag.isoccupied(s, curtag) then
93 if curtag == p[x] then t = x end
100 for x in pairs(tags[s]) do
101 if curtag == tags[s][x] then o = x end
102 if mtag.isoccupied(s, tags[s][x]) then lasto = x end
105 -- Now: t is # in non-empty, o is # in all
106 if o == table.maxn(tags[s]) then
107 -- We're the last tag, create a new one
109 -- We're empty, go to first
112 -- We're occupied, create new
117 -- We're empty, check if we're last
119 -- We're also later than the last non-empty
123 -- Nevermind, get the next
132 function mtag.next(s)
133 awful.tag.viewonly(mtag.getnext(s))
135 function mtag.movetonext(s)
136 local t = mtag.getnext(s)
137 awful.client.movetotag(t)
138 awful.tag.viewonly(t)
140 function mtag.getprev(s)
141 if s == nil then s = mouse.screen end
143 local p = mtag.occupied(s)
144 local curtag = awful.tag.selected()
149 if mtag.isoccupied(s, curtag) then
151 if curtag == p[x] then t = x end
158 for x in pairs(tags[s]) do
159 if curtag == tags[s][x] then o = x end
160 if mtag.isoccupied(s, tags[s][x]) then lasto = x end
163 -- Now: t is # in non-empty, o is # in all
165 -- We're the very first tag, wrap around
166 return p[ table.maxn(p) ]
168 -- We're not first, just go prev
172 function mtag.prev(s)
173 awful.tag.viewonly(mtag.getprev(s))
175 function mtag.movetoprev(s)
176 local t = mtag.getprev(s)
177 awful.client.movetotag(t)
178 awful.tag.viewonly(t)
185 local icondir = awful.util.getdir("config").."/icons/"
187 function make_icon(fname, left, right, h, bg)
188 local icon = image(icondir..fname)
189 local ib = widget { type = 'imagebox' }
190 local w = left + icon.width + right
191 local i = image.argb32(w, h, nil)
193 i:draw_rectangle(0, 0, w, h, true, beautiful.bg_normal)
194 i:insert(icon, left, math.floor((h - icon.height) / 2))
200 function draw_dashes_h(img, x, y, on, off, len, color)
201 for i = 0, len, on + off do
202 img:draw_line(x + i, y, x + i + on - 1, y, color)
206 function draw_dashes_v(img, x, y, on, off, len, color)
207 for i = 0, len, on + off do
208 img:draw_line(x, y + i, x, y + i + on - 1, color)
218 maintaglist.buttons = awful.util.table.join(
219 awful.button(k_n, 1, awful.tag.viewonly),
220 awful.button(k_s, 1, awful.client.toggletag)
222 maintaglist.label = awful.widget.taglist.label.noempty
227 mypromptbox = awful.widget.prompt{
228 layout = awful.widget.layout.horizontal.leftright
234 local cpuwidgets = {}
235 for i = 1, io.popen("grep -c ^cpu /proc/stat"):read("*n") do
238 cpu.widget = widget{ type = 'imagebox' }
239 cpu.update = function(cpu, value)
243 color = beautiful.fg_focus
244 elseif value < 50 then
246 elseif value < 75 then
252 if cpu.color == color then return end
253 local img = image.argb32(11, 16, nil)
254 draw_dashes_h(img, 0, 4, 2, 1, 7, color)
255 draw_dashes_h(img, 0, 11, 2, 1, 7, color)
256 draw_dashes_v(img, 0, 4, 2, 1, 7, color)
257 draw_dashes_v(img, 7, 4, 2, 1, 7, color)
258 img:draw_rectangle(2, 6, 4, 4, true, color)
259 cpu.widget.image = img
262 table.insert(mywidgets, cpu.widget)
266 cputextwidget = widget{ type = 'textbox' }
268 vicious.register(cputextwidget, vicious.widgets.cpu,
269 function (widget, args)
270 local r = tonumber(args[1])
271 local percent = args[1]..'%'
274 cpuwidgets[i]:update(args[i])
278 percent = '0'..percent
281 percent = fg(beautiful.fg_focus, percent)
283 percent = fg('yellow', percent)
285 percent = fg('orange', percent)
287 percent = fg('red', percent)
292 table.insert(mywidgets, cputextwidget)
295 -- {{{ Memory Usage Widget
297 table.insert(mywidgets, make_icon('mem.png', 16, 4, 16))
299 memtextwidget = widget{ type = 'textbox' }
301 vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args)
302 -- Add extra preceding zeroes when needed
303 local r = tonumber(args[1])
304 local percent = args[1]..'%'
306 percent = '0'..percent
309 percent = fg(beautiful.fg_focus, percent)
311 percent = fg('orange', percent)
313 percent = fg('red', percent)
315 return percent..' '..args[2]..'M'
318 table.insert(mywidgets, memtextwidget)
323 table.insert(mywidgets, make_icon('clock.png', 16, 4, 16))
325 clockwidget = widget{ type = "textbox" }
326 vicious.register(clockwidget, vicious.widgets.date,
327 fg(theme.fg_focus, "%H:%M") .. " %a %d %b ", 10)
329 table.insert(mywidgets, clockwidget)
334 for s = 1, screen.count() do
337 awful.widget.taglist(s, maintaglist.label, maintaglist.buttons),
339 layout = awful.widget.layout.horizontal.leftright
344 table.insert(tab, widget{ type = 'systray' })
346 for i = #mywidgets, 1, -1 do
347 table.insert(tab, mywidgets[i])
349 tab["layout"] = awful.widget.layout.horizontal.rightleft
350 awful.wibox{ position = "top", height = 16, screen = s }.widgets = tab
358 globalkeys = awful.util.table.join(
359 -- Mod+{A/S}: Switch to prev/next tag
360 awful.key(k_m, "Left", mtag.prev),
361 awful.key(k_m, "Right", mtag.next),
363 -- Mod+Shift+{A/S}: Move window to Prev/Next tag
364 awful.key(k_ms, "Left", mtag.movetoprev),
365 awful.key(k_ms, "Right", mtag.movetonext),
367 -- Mod+Shift_{E/D}: move window to next/prev screen
368 awful.key(k_mc, "Right", function()
369 client.focus.screen = awful.util.cycle(screen.count(), mouse.screen + 1)
371 awful.key(k_mc, "Left", function()
372 client.focus.screen = awful.util.cycle(screen.count(), mouse.screen - 1)
376 -- Focus Prev/Next window
379 awful.client.focus.byidx(1)
380 if client.focus then client.focus:raise() end
384 awful.client.focus.byidx(-1)
385 if client.focus then client.focus:raise() end
388 -- Swap window with the Prev/Next one
389 awful.key(k_ms, "j", function () awful.client.swap.byidx(1) end),
390 awful.key(k_ms, "k", function () awful.client.swap.byidx(-1) end),
392 -- Mod+{E/D}: Switch to next/previous screen
393 awful.key(k_m, "Tab", function ()
394 awful.screen.focus_relative(1)
395 coords = mouse.coords();
396 mouse.coords({ x = coords.x + 5, y = coords.y + 5}, true)
398 awful.key(k_ms, "Tab", function ()
399 awful.screen.focus_relative(-1)
400 coords = mouse.coords()
401 mouse.coords({ x = coords.x + 5, y = coords.y + 5}, true)
404 -- Mod+Enter: Launch a new terminal
405 awful.key(k_m, "e", function() awful.util.spawn("chromium") end),
406 awful.key(k_m, "Return", function() awful.util.spawn(terminal) end),
407 awful.key(k_ac, "r", awesome.restart),
408 awful.key(k_m, "F12", function() awful.util.spawn(lock) end),
409 awful.key({}, "#148", function() awful.util.spawn("kcalc") end),
411 -- Layout manipulation
412 awful.key(k_m, "l", function () awful.tag.incmwfact(0.05) end),
413 awful.key(k_m, "h", function () awful.tag.incmwfact(-0.05) end),
414 awful.key(k_ms, "h", function () awful.tag.incnmaster(1) end),
415 awful.key(k_ms, "l", function () awful.tag.incnmaster(-1) end),
416 awful.key(k_mc, "h", function () awful.tag.incncol(1) end),
417 awful.key(k_mc, "l", function () awful.tag.incncol(-1) end),
420 awful.key(k_m, "r", function () mypromptbox:run() end),
423 awful.prompt.run({ prompt = "Run Lua code: " },
425 awful.util.eval, nil,
426 awful.util.getdir("cache").."/lua_commands")
429 awful.key({}, "#192", function() mtag.viewonly(1) end),
430 awful.key({}, "#193", function() mtag.viewonly(2) end),
431 awful.key({}, "#194", function() mtag.viewonly(3) end),
432 awful.key({}, "#195", function() mtag.viewonly(4) end),
433 awful.key({}, "#196", function() mtag.viewonly(5) end)
436 -- Mod+#: Switch to tag
437 -- Mod+Shift+#: Toggle tag display
438 -- Mod+Control+#: Move client to tag
439 -- Mod+Alt+#: Toggle client on tag
442 globalkeys = awful.util.table.join(
444 awful.key(k_m, i % 10, function() mtag.viewonly(i) end),
445 awful.key(k_ms, i % 10, function() mtag.viewtoggle(i) end),
446 awful.key(k_mc, i % 10,
448 if client.focus and tags[client.focus.screen][i] then
449 awful.client.movetotag(tags[client.focus.screen][i])
452 awful.key(k_mcs, i % 10,
454 if client.focus and tags[client.focus.screen][i] then
455 awful.client.toggletag(tags[client.focus.screen][i])
462 ---- {{{ Client hotkeys / buttons
464 local clientkeys = awful.util.table.join(
465 awful.key(k_m, "i", function (c)
466 if mypromptbox.widget.text then
467 mypromptbox.widget.text = ""
469 mypromptbox.widget.text = "Class: " .. c.class .. " Instance: ".. c.instance .. " Name: " .. c.name
473 -- Client manipulation
474 awful.key(k_m, "c", function (c) c:kill() end),
475 awful.key(k_m, "o", awful.client.floating.toggle),
476 awful.key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end)
479 local clientbuttons = awful.util.table.join(
480 awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
481 awful.button(k_a, 1, awful.mouse.client.move),
482 awful.button(k_a, 3, awful.mouse.client.resize)
487 root.keys(globalkeys)
491 awful.rules.rules = {
492 -- All clients will match this rule.
496 border_width = beautiful.border_width,
497 border_color = beautiful.border_normal,
500 buttons = clientbuttons,
501 size_hints_honor = false,
504 { rule = { class = "MPlayer" }, properties = { floating = true } },
505 { rule = { class = "pinentry" }, properties = { floating = true } },
506 { rule = { class = "Claws-mail", name = "[no subject] - Compose message" },
507 properties = { maximized_vertical = true, floating = true, x = 0 } },
513 client.add_signal("focus", function (c)
514 if not awful.client.ismarked(c) then
515 c.border_color = beautiful.border_focus
519 client.add_signal("unfocus", function (c)
520 if not awful.client.ismarked(c) then
521 c.border_color = beautiful.border_normal
525 client.add_signal("manage", function (c, startup)
526 c:add_signal("mouse::enter", function(c) client.focus = c end)
531 awful.util.spawn("xkbcomp -w 0 -R/usr/share/X11/xkb /home/madcoder/.Xkeyboard :0")
532 awful.util.spawn("xsetroot -cursor_name left_ptr")