-- awesome 3 configuration file -- Include awesome library, with lots of useful function! require("awful") require("eminent") require("wicked") require("beautiful") function table.append(t, ...) for _, v in ipairs({...}) do table.insert(t, v) end end 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 = { button(k_n, 1, awful.tag.viewonly), button(k_s, 1, awful.client.toggletag) } -- }}} -- {{{ Widgets -- {{{ Load Averages Widget loadwidget = widget({ type = 'textbox', name = 'gpuwidget', align = 'right' }) wicked.register(loadwidget, 'function', function (widget, args) -- 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) return heading('Load')..': '..n:sub(1,pos-1) end, 2) -- }}} -- {{{ CPU Usage Widget cputextwidget = widget({ type = 'textbox', name = 'cputextwidget', align = 'right' }) cputextwidget.text = heading('CPU')..': 00% ' wicked.register(cputextwidget, '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 return heading('CPU')..': '..percent..' ' end, 2) -- }}} -- {{{ CPU Graph Widget cpugraphwidget = widget({ type = 'graph', name = 'cpugraphwidget', align = 'right' }) cpugraphwidget.height = 0.85 cpugraphwidget.width = 45 cpugraphwidget.bg = '#333333' cpugraphwidget.border_color = '#0a0a0a' cpugraphwidget.grow = 'right' cpugraphwidget:plot_properties_set('cpu', { fg = '#AEC6D8', fg_center = '#285577', fg_end = '#285577', vertical_gradient = false }) wicked.register(cpugraphwidget, 'cpu', '$1', 2, 'cpu') -- }}} -- {{{ Memory Usage Widget memtextwidget = widget({ type = 'textbox', name = 'memtextwidget', align = 'right' }) memtextwidget.text = heading('MEM')..': ' wicked.register(memtextwidget, '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) -- }}} -- {{{ Battery widget --[[ batterywidget = widget({ type = 'textbox', name = 'batterywidget', align = 'right' }) function batterywidget_update() local v = io.popen("powersave -b|sed -ne 's/.*Remaining percent: \\(.*\\)/\\1/p'"):read() local r = tonumber(v) percent = v if r < 10 then percent = fg('red', percent) elseif r < 25 then percent = fg('orange', percent) else percent = fg('green', percent) end batterywidget.text = heading('BAT')..': '..percent end batterywidget_update() awful.hooks.timer.register(30, batterywidget_update) --]] -- }}} -- {{{ spacers rspacer = widget({ type = 'textbox', name = 'rspacer', align = 'right' }) rspacer.text = " │ " -- }}} -- {{{ Clock clockwidget = widget({ type = "textbox", name = "clockwidget", align = "right" }) clock_update = function() clockwidget.text = fg("#dddddd", os.date("%a %d %b - %H:%M")) end clock_update() awful.hooks.timer.register(10, clock_update) -- }}} mymenubox = widget{ type = "textbox", name = "mytextbox", align = "left" } -- mysystray = widget{ type = "systray", name = "mysystray", align = "right" } -- {{{ Statusbar mainstatusbar = {} for s = 1, screen.count() do mainstatusbar[s] = wibox{ position = "top", height = 18, name = "mainstatusbar" .. s, } mainstatusbar[s].widgets = { awful.widget.taglist.new(s, awful.widget.taglist.label.noempty, maintaglist.buttons), maintaglist, mymenubox, rspacer, loadwidget, rspacer, cputextwidget, cpugraphwidget, rspacer, memtextwidget, rspacer, clockwidget, s == 1 and rspacer or nil, s == 1 and mysystray or nil, } mainstatusbar[s].screen = s end -- }}} -- }}} -- {{{ Keys ---- {{{ Global keys local hist = os.getenv("HOME") .. "/.cache/awesome/history" globalkeys = { -- Mod+{A/S}: Switch to prev/next tag key(k_m, "Left", eminent.tag.prev), key(k_m, "Right", eminent.tag.next), -- Mod+Shift+{A/S}: Move window to Prev/Next tag key(k_ms, "Left", function() awful.client.movetotag(eminent.tag.getprev()) eminent.tag.prev() end), 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 key(k_mc, "Right", function() local s = getscreen() + 1 while s > screen.count() do s = s-screen.count() end client_movetoscreen(s) end), 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 key(k_m, "j", function () awful.client.focus.byidx(1) if client.focus then client.focus:raise() end end), 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 key(k_ms, "j", function () awful.client.swap.byidx(1) end), key(k_ms, "k", function () awful.client.swap.byidx(-1) end), -- Mod+{E/D}: Switch to next/previous screen key(k_m, "Tab", function () awful.screen.focus(1) end), key(k_ms, "Tab", function () awful.screen.focus(-1) end), -- Mod+Enter: Launch a new terminal key(k_m, "e", function() awful.util.spawn("firefox") end), key(k_m, "Return", function() awful.util.spawn(terminal) end), key(k_ac, "r", awesome.restart), key(k_m, "F12", function() awful.util.spawn(lock) end), key({}, "#148", function() awful.util.spawn("kcalc") end), -- Layout manipulation key(k_m, "l", function () awful.tag.incmwfact(0.05) end), key(k_m, "h", function () awful.tag.incmwfact(-0.05) end), key(k_ms, "h", function () awful.tag.incnmaster(1) end), key(k_ms, "l", function () awful.tag.incnmaster(-1) end), key(k_mc, "h", function () awful.tag.incncol(1) end), key(k_mc, "l", function () awful.tag.incncol(-1) end), -- Menu key(k_m, "r", function () awful.prompt.run({ prompt = "Run: " }, mymenubox, awful.util.spawn, awful.completion.bash, awful.util.getdir("cache").."/commands") end), key(k_m, "F4", function () awful.prompt.run({ prompt = "Run Lua code: " }, mymenubox, awful.util.eval, awful.prompt.bash, awful.util.getdir("cache").."/lua_commands") end), key({}, "#192", function() eminent.tag.goto(1, nil, true) end), key({}, "#193", function() eminent.tag.goto(2, nil, true) end), key({}, "#194", function() eminent.tag.goto(3, nil, true) end), key({}, "#195", function() eminent.tag.goto(4, nil, true) end), 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 table.append(globalkeys, key(k_m, i % 10, function() eminent.tag.goto(i, nil, true) end), 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), 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 = { 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 key(k_m, "c", function (c) c:kill() end), key(k_m, "o", awful.client.floating.toggle), key(k_m, "t", awful.client.togglemarked), key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end) } ---- }}} root.keys(globalkeys) -- }}} -- {{{ Hooks awful.hooks.focus.register(function (c) if not awful.client.ismarked(c) then c.border_color = beautiful.border_focus end end) awful.hooks.unfocus.register(function (c) if not awful.client.ismarked(c) then c.border_color = beautiful.border_normal end end) awful.hooks.marked.register(function (c) c.border_color = beautiful.border_marked end) awful.hooks.unmarked.register(function (c) c.border_color = beautiful.border_focus end) -- Hook function to execute when the mouse enters a client. awful.hooks.mouse_enter.register(function (c) -- Sloppy focus client.focus = c end) awful.hooks.manage.register(function (c, startup) if not startup and awful.client.focus.filter(c) then c.screen = mouse.screen end -- Add mouse bindings c:buttons{ button({ }, 1, function (c) client.focus = c; c:raise() end), button(k_a, 1, awful.mouse.client.move), button(k_a, 3, awful.mouse.client.resize) } -- Create border c.border_width = beautiful.border_width c.border_color = beautiful.border_normal -- Make certain windows floating local name = c.name:lower() if name:find('pinentry') or name:find('kcalc') 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) awful.hooks.arrange.register(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 ~/.Xkeyboard :0")