-- awesome 3 configuration file -- Include awesome library, with lots of useful function! require("awful") require("awful.autofocus") require("awful.rules") require("vicious") require("beautiful") terminal = "x-terminal-emulator" lock = 'xscreensaver-command -lock' beautiful.init(awful.util.getdir("config").."/theme") -- {{{ Modkeys modkey = "Mod4" shift = "Shift" alt = "Mod1" control = "Control" k_n = {} k_m = {modkey} k_ms = {modkey, shift} k_ma = {modkey, alt} k_mc = {modkey, control} k_mcs = {modkey, control, shift} k_a = {alt} k_ac = {alt, control} k_c = {control} k_cs = {control, shift} k_s = {shift} -- }}} -- {{{ Markup helper functions -- Inline markup is a tad ugly, so use these functions -- to dynamically create markup. function fg(color, text) return ''..text..'' end function heading(text) return fg(beautiful.fg_focus, text) end -- }}} -- {{{ Tags tags = {} for s = 1, screen.count() do -- Each screen has its own tag table. local p = {} for i = 1, 10 do table.insert(p, "work-"..i) end tags[s] = awful.tag(p, s, awful.layout.suit.tile) end -- Get the screen number we're on local mtag = { } function mtag.getn(idx, s) return tags[s or mouse.screen][idx] end function mtag.viewonly (idx, s) local t = mtag.getn(idx, s) if t then awful.tag.viewonly(t) end end function mtag.viewtoggle (idx, s) local t = mtag.getn(idx, s) if t then awful.tag.viewtoggle(t) end end function mtag.isoccupied(s, t) local clients = (t and t:clients()) or {} return #clients > 0 end function mtag.occupied(s) local p = {} if not s then s = mouse.screen end for t in pairs(tags[s]) do t = tags[s][t] if mtag.isoccupied(s, t) then table.insert(p, t) end end return p end function mtag.getnext(s) if s == nil then s = mouse.screen end local p = mtag.occupied(s) local curtag = awful.tag.selected() local t = 0 -- Get tag # if mtag.isoccupied(s, curtag) then for x in pairs(p) do if curtag == p[x] then t = x end end end local lasto = 1 local o = 0 for x in pairs(tags[s]) do if curtag == tags[s][x] then o = x end if mtag.isoccupied(s, tags[s][x]) then lasto = x end end -- Now: t is # in non-empty, o is # in all if o == table.maxn(tags[s]) then -- We're the last tag, create a new one if t == 0 then -- We're empty, go to first return tags[s][1] else -- We're occupied, create new return newtag() end else if t == 0 then -- We're empty, check if we're last if o > lasto then -- We're also later than the last non-empty -- Wrap to first return tags[s][1] else -- Nevermind, get the next return tags[s][o+1] end else -- Return next tag return tags[s][o+1] end end end function mtag.next(s) awful.tag.viewonly(mtag.getnext(s)) end function mtag.movetonext(s) local t = mtag.getnext(s) awful.client.movetotag(t) awful.tag.viewonly(t) end function mtag.getprev(s) if s == nil then s = mouse.screen end local p = mtag.occupied(s) local curtag = awful.tag.selected() local t = 0 -- Get tag # if mtag.isoccupied(s, curtag) then for x in pairs(p) do if curtag == p[x] then t = x end end end local lasto = 1 local o = 0 for x in pairs(tags[s]) do if curtag == tags[s][x] then o = x end if mtag.isoccupied(s, tags[s][x]) then lasto = x end end -- Now: t is # in non-empty, o is # in all if o == 1 then -- We're the very first tag, wrap around return p[ table.maxn(p) ] else -- We're not first, just go prev return tags[s][o-1] end end function mtag.prev(s) awful.tag.viewonly(mtag.getprev(s)) end function mtag.movetoprev(s) local t = mtag.getprev(s) awful.client.movetotag(t) awful.tag.viewonly(t) end -- }}} -- {{{ Widgets function make_imagebox(fname, w, h, bg) local icon = image(fname) local ib = widget { type = 'imagebox' } local i = image.argb32(w, h, nil) if not bg then bg = beautiful.bg_normal end i:draw_rectangle(0, 0, w, h, true, bg) i:insert(icon, math.floor((w - icon.width) / 2), math.floor((h - icon.height) / 2)) ib.image = i return ib end -- {{{ Taglist maintaglist = {} maintaglist.buttons = awful.util.table.join( awful.button(k_n, 1, awful.tag.viewonly), awful.button(k_s, 1, awful.client.toggletag) ) maintaglist.label = awful.widget.taglist.label.noempty -- }}} -- {{{ Prompt box mypromptbox = awful.widget.prompt{ layout = awful.widget.layout.horizontal.leftright } -- }}} -- {{{ Load Average Widget loadwidget = widget({ type = 'textbox' }) load_update = function() -- Use /proc/loadavg to get the average system load on 1, 5 and 15 minute intervals local f = io.open('/proc/loadavg') local n = f:read() f:close() -- Find the third space local pos = n:find(' ', n:find(' ', n:find(' ')+1)+1) loadwidget.text = heading('Load')..': '..n:sub(1,pos-1) end load_update() t = timer { timeout = 10 } t:add_signal("timeout", load_update) t:start() -- }}} -- {{{ CPU Widgets cpuiconwidget = nil -- make_imagebox(os.getenv("HOME")..'/tmp/famfamfam/computer.png', 18, 18) cputextwidget = widget({ type = 'textbox' }) cpugraphwidget = awful.widget.graph{ width = 40, height = 16, layout = awful.widget.layout.horizontal.rightleft } cpugraphwidget:set_background_color('#333333') cpugraphwidget:set_border_color('#0a0a0a') cpugraphwidget:set_gradient_colors({ '#285577', '#285577', '#AEC6D8' }) vicious.register(cputextwidget, vicious.widgets.cpu, function (widget, args) local r = tonumber(args[1]) local percent = args[1]..'%' if r < 10 then percent = '0'..percent end if r < 25 then percent = fg('green', percent) elseif r < 50 then percent = fg('yellow', percent) elseif r < 75 then percent = fg('orange', percent) else percent = fg('red', percent) end for s = 1, screen.count() do cpugraphwidget:add_value(r / 100) end return ' '..percent..' ' end, 2) -- }}} -- {{{ Memory Usage Widget memiconwidget = nil -- make_imagebox(os.getenv("HOME")..'/tmp/famfamfam/bricks.png', 18, 18) memtextwidget = widget({ type = 'textbox' }) memtextwidget.text = heading('MEM')..': ' vicious.register(memtextwidget, vicious.widgets.mem, function (widget, args) -- Add extra preceding zeroes when needed local r = tonumber(args[1]) local percent = args[1]..'%' if r < 10 then percent = '0'..percent end if r < 50 then percent = fg('green', percent) elseif r < 80 then percent = fg('orange', percent) else percent = fg('red', percent) end return ' '..percent..' '..args[2]..'M' end, 2) -- }}} -- {{{ spacers rspacer = widget({ type = 'textbox' }) rspacer.text = " │ " -- }}} -- {{{ Clock clockwidget = widget({ type = "textbox" }) vicious.register(clockwidget, vicious.widgets.date, fg("#dddddd", "%a %d %b - %H:%M"), 10) -- }}} -- {{{ Statusbar mainstatusbar = {} mysystray = widget({ type = "systray" }) for s = 1, screen.count() do local lr_layout = awful.widget.layout.horizontal.leftright local rl_layout = awful.widget.layout.horizontal.rightleft mainstatusbar[s] = awful.wibox{ position = "top", height = 18, screen = s } mainstatusbar[s].widgets = { { awful.widget.taglist(s, maintaglist.label, maintaglist.buttons), mypromptbox.widget, layout = lr_layout }, s == 1 and mysystray or nil, s == 1 and rspacer or nil, clockwidget, rspacer, memtextwidget, memiconwidget, rspacer, cpugraphwidget.widget, cputextwidget, cpuiconwidget, rspacer, loadwidget, rspacer, layout = awful.widget.layout.horizontal.rightleft } end -- }}} -- }}} -- {{{ Keys ---- {{{ Global keys local hist = os.getenv("HOME") .. "/.cache/awesome/history" globalkeys = awful.util.table.join( -- Mod+{A/S}: Switch to prev/next tag awful.key(k_m, "Left", mtag.prev), awful.key(k_m, "Right", mtag.next), -- Mod+Shift+{A/S}: Move window to Prev/Next tag awful.key(k_ms, "Left", mtag.movetoprev), awful.key(k_ms, "Right", mtag.movetonext), -- Mod+Shift_{E/D}: move window to next/prev screen awful.key(k_mc, "Right", function() local s = mouse.screen + 1 while s > screen.count() do s = s - screen.count() end client.focus.screen = s end), awful.key(k_mc, "Left", function() local s = mouse.screen - 1 while s < 1 do s = s + screen.count() end client.focus.screen = s end), -- Focus Prev/Next window awful.key(k_m, "j", function () awful.client.focus.byidx(1) if client.focus then client.focus:raise() end end), awful.key(k_m, "k", function () awful.client.focus.byidx(-1) if client.focus then client.focus:raise() end end), -- Swap window with the Prev/Next one awful.key(k_ms, "j", function () awful.client.swap.byidx(1) end), awful.key(k_ms, "k", function () awful.client.swap.byidx(-1) end), -- Mod+{E/D}: Switch to next/previous screen awful.key(k_m, "Tab", function () awful.screen.focus_relative(1) end), awful.key(k_ms, "Tab", function () awful.screen.focus_relative(-1) end), -- Mod+Enter: Launch a new terminal awful.key(k_m, "e", function() awful.util.spawn("firefox") end), awful.key(k_m, "Return", function() awful.util.spawn(terminal) end), awful.key(k_ac, "r", awesome.restart), awful.key(k_m, "F12", function() awful.util.spawn(lock) end), awful.key({}, "#148", function() awful.util.spawn("kcalc") end), -- Layout manipulation awful.key(k_m, "l", function () awful.tag.incmwfact(0.05) end), awful.key(k_m, "h", function () awful.tag.incmwfact(-0.05) end), awful.key(k_ms, "h", function () awful.tag.incnmaster(1) end), awful.key(k_ms, "l", function () awful.tag.incnmaster(-1) end), awful.key(k_mc, "h", function () awful.tag.incncol(1) end), awful.key(k_mc, "l", function () awful.tag.incncol(-1) end), -- Menu awful.key(k_m, "r", function () mypromptbox:run() end), awful.key(k_m, "F4", function () awful.prompt.run({ prompt = "Run Lua code: " }, mypromptbox.widget, awful.util.eval, nil, awful.util.getdir("cache").."/lua_commands") end), awful.key({}, "#192", function() mtag.viewonly(1) end), awful.key({}, "#193", function() mtag.viewonly(2) end), awful.key({}, "#194", function() mtag.viewonly(3) end), awful.key({}, "#195", function() mtag.viewonly(4) end), awful.key({}, "#196", function() mtag.viewonly(5) end) ) -- Mod+#: Switch to tag -- Mod+Shift+#: Toggle tag display -- Mod+Control+#: Move client to tag -- Mod+Alt+#: Toggle client on tag for i = 1, 10 do globalkeys = awful.util.table.join( globalkeys, awful.key(k_m, i % 10, function() mtag.viewonly(i) end), awful.key(k_ms, i % 10, function() mtag.viewtoggle(i) end), awful.key(k_mc, i % 10, function () if client.focus and tags[client.focus.screen][i] then awful.client.movetotag(tags[client.focus.screen][i]) end end), awful.key(k_mcs, i % 10, function () if client.focus and tags[client.focus.screen][i] then awful.client.toggletag(tags[client.focus.screen][i]) end end) ) end ---- }}} ---- {{{ Client hotkeys / buttons local clientkeys = awful.util.table.join( awful.key(k_m, "i", function (c) if mypromptbox.widget.text then mypromptbox.widget.text = "" else mypromptbox.widget.text = "Class: " .. c.class .. " Instance: ".. c.instance end end), -- Client manipulation awful.key(k_m, "c", function (c) c:kill() end), awful.key(k_m, "o", awful.client.floating.toggle), awful.key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end) ) local clientbuttons = awful.util.table.join( awful.button({ }, 1, function (c) client.focus = c; c:raise() end), awful.button(k_a, 1, awful.mouse.client.move), awful.button(k_a, 3, awful.mouse.client.resize) ) ---- }}} root.keys(globalkeys) -- }}} -- {{{ Rules awful.rules.rules = { -- All clients will match this rule. { rule = { }, properties = { border_width = beautiful.border_width, border_color = beautiful.border_normal, focus = true, keys = clientkeys, buttons = clientbuttons, size_hints_honor = false, } }, { rule = { class = "MPlayer" }, properties = { floating = true } }, { rule = { class = "pinentry" }, properties = { floating = true } }, -- Set Firefox to always map on tags number 2 of screen 1. -- { rule = { class = "Firefox" }, -- properties = { tag = tags[1][2] } }, } -- }}} -- {{{ Signals client.add_signal("focus", function (c) if not awful.client.ismarked(c) then c.border_color = beautiful.border_focus end end) client.add_signal("unfocus", function (c) if not awful.client.ismarked(c) then c.border_color = beautiful.border_normal end end) client.add_signal("manage", function (c, startup) -- Enable sloppy focus c:add_signal("mouse::enter", function(c) client.focus = c end) -- Focus new clients client.focus = c end) function warp_mouse(screen) local c = client.focus if c then local o = awful.mouse.client_under_pointer() if not o or o ~= c then local g = c:geometry() mouse.coords { x = g.x + 5, y = g.y + 5 } end end end for s = 1, screen.count() do -- screen[s]:add_signal("arrange", warp_mouse) end -- }}} awful.util.spawn("xkbcomp -w 0 -R/usr/share/X11/xkb /home/madcoder/.Xkeyboard :0")