-- awesome 3 configuration file -- Include awesome library, with lots of useful function! require("awful") require("eminent") 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_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 -- }}} -- {{{ Functions -- Toggle whether we're viewing a tag function tag_toggleview(tag) tag:view(not tag:isselected()) end -- Get the screen number we're on function getscreen() local sel = client.focus return (sel and sel.screen) or mouse.screen end -- Move current client to a specific screen function client_movetoscreen(i) client.focus.screen = i end -- }}} -- {{{ Set tag names for s = 1, screen.count() do eminent.newtag(s, 5) for i = 1, 10 do eminent.tag.name(i, s, 'work-'..i) end 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) ) -- }}} -- {{{ Widgets -- {{{ 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 Usage Widget 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 cpugraphwidget:add_value(r / 100) return heading('CPU')..': '..percent..' ' end, 2) -- }}} -- {{{ CPU Graph Widget -- }}} -- {{{ Memory Usage Widget 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 heading('MEM')..': '..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) -- }}} mymenubox = widget{ type = "textbox" } -- {{{ Statusbar mainstatusbar = {} for s = 1, screen.count() do mainstatusbar[s] = awful.wibox{ position = "top", height = 18, screen = s } mainstatusbar[s].widgets = { { awful.widget.taglist(s, awful.widget.taglist.label.noempty, maintaglist.buttons), maintaglist, awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright }), layout = awful.widget.layout.horizontal.leftright }, clockwidget, rspacer, memtextwidget, rspacer, cpugraphwidget, cputextwidget, 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", eminent.tag.prev), awful.key(k_m, "Right", eminent.tag.next), -- Mod+Shift+{A/S}: Move window to Prev/Next tag awful.key(k_ms, "Left", function() awful.client.movetotag(eminent.tag.getprev()) eminent.tag.prev() end), awful.key(k_ms, "Right", function() awful.client.movetotag(eminent.tag.getnext()) eminent.tag.next() end), -- Mod+Shift_{E/D}: move window to next/prev screen awful.key(k_mc, "Right", function() local s = getscreen() + 1 while s > screen.count() do s = s-screen.count() end client_movetoscreen(s) end), awful.key(k_mc, "Left", function() local s = getscreen() - 1 while s < 1 do s = s+screen.count() end client_movetoscreen(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(1) end), awful.key(k_ms, "Tab", function () awful.screen.focus(-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 () awful.prompt.run({ prompt = "Run: " }, mymenubox, awful.util.spawn, awful.completion.shell, awful.util.getdir("cache").."/commands") end), awful.key(k_m, "F4", function () awful.prompt.run({ prompt = "Run Lua code: " }, mymenubox, awful.util.eval, awful.prompt.shell, awful.util.getdir("cache").."/lua_commands") end), awful.key({}, "#192", function() eminent.tag.goto(1, nil, true) end), awful.key({}, "#193", function() eminent.tag.goto(2, nil, true) end), awful.key({}, "#194", function() eminent.tag.goto(3, nil, true) end), awful.key({}, "#195", function() eminent.tag.goto(4, nil, true) end), awful.key({}, "#196", function() eminent.tag.goto(5, nil, true) 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() eminent.tag.goto(i, nil, true) end), awful.key(k_ms, i % 10, function () local t = eminent.tag.getn(i, nil, true) if t ~= nil then t.selected = not t.selected end end), awful.key(k_mc, i % 10, function () local t = eminent.tag.getn(i, nil, true) if t ~= nil then awful.client.movetotag(t) end end) ) end ---- }}} ---- {{{ Client hotkeys clientkeys = awful.util.table.join( awful.key(k_m, "i", function (c) if mymenubox.text then mymenubox.text = "" else mymenubox.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, "t", awful.client.togglemarked), awful.key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end) ) ---- }}} root.keys(globalkeys) -- }}} -- {{{ 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("marked", function (c) c.border_color = beautiful.border_marked end) client.add_signal("unmarked", function (c) c.border_color = beautiful.border_focus end) client.add_signal("manage", function (c, startup) if not startup and awful.client.focus.filter(c) then c.screen = mouse.screen end -- Add mouse bindings c:buttons(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) )) -- Enable sloppy focus c:add_signal("mouse::enter", function(c) client.focus = c end) -- Create border c.border_width = beautiful.border_width c.border_color = beautiful.border_normal -- Make certain windows floating local class = c.class:lower() if class:find('pinentry') or class:find('kcalc') or class:find('gajim') then c.floating = true end -- Focus new clients client.focus = c c:keys(clientkeys) c.size_hints_honor = false end) -- Hook function to execute when arranging the screen -- (tag switch, new client, etc) client.add_signal("arrange", function (screen) local sel = client.focus if not sel then sel = awful.client.focus.history.get(screen, 0) if not sel then return end client.focus = sel end local o = mouse.object_under_pointer() if not o or (type(o) == "client" and o ~= sel) then local g = sel:geometry() mouse.coords { x = g.x + 5, y = g.y + 5 } end end) -- }}} awful.util.spawn("xkbcomp -w 0 -R/usr/share/X11/xkb /home/madcoder/.Xkeyboard :0")