1 -- awesome 3 configuration file
3 -- Include awesome library, with lots of useful function!
9 function table.append(t, ...)
10 for _, v in ipairs({...}) do
15 terminal = "x-terminal-emulator"
16 lock = 'xscreensaver-command -lock'
17 beautiful.init(awful.util.getdir("config").."/theme")
27 k_ms = {modkey, shift}
29 k_mc = {modkey, control}
33 k_cs = {control, shift}
38 -- {{{ Markup helper functions
39 -- Inline markup is a tad ugly, so use these functions
40 -- to dynamically create markup.
41 function fg(color, text)
42 return '<span color="'..color..'">'..text..'</span>'
45 function heading(text)
46 return fg(beautiful.fg_focus, text)
51 -- Toggle whether we're viewing a tag
52 function tag_toggleview(tag)
53 tag:view(not tag:isselected())
56 -- Get the screen number we're on
58 local sel = client.focus
59 return (sel and sel.screen) or mouse.screen
62 -- Move current client to a specific screen
63 function client_movetoscreen(i)
64 client.focus.screen = i
70 for s = 1, screen.count() do
73 eminent.tag.name(i, s, 'work-'..i)
81 maintaglist.buttons = {
82 button(k_n, 1, awful.tag.viewonly),
83 button(k_s, 1, awful.client.toggletag)
89 -- {{{ Load Averages Widget
97 wicked.register(loadwidget, 'function', function (widget, args)
98 -- Use /proc/loadavg to get the average system load on 1, 5 and 15 minute intervals
99 local f = io.open('/proc/loadavg')
103 -- Find the third space
104 local pos = n:find(' ', n:find(' ', n:find(' ')+1)+1)
106 return heading('Load')..': '..n:sub(1,pos-1)
111 -- {{{ CPU Usage Widget
113 cputextwidget = widget({
115 name = 'cputextwidget',
119 cputextwidget.text = heading('CPU')..': 00% '
120 wicked.register(cputextwidget, 'cpu', function (widget, args)
121 local r = tonumber(args[1])
122 local percent = args[1]..'%'
124 percent = '0'..percent
127 percent = fg('green', percent)
129 percent = fg('yellow', percent)
131 percent = fg('orange', percent)
133 percent = fg('red', percent)
135 return heading('CPU')..': '..percent..' '
139 -- {{{ CPU Graph Widget
141 cpugraphwidget = widget({
143 name = 'cpugraphwidget',
147 cpugraphwidget.height = 0.85
148 cpugraphwidget.width = 45
149 cpugraphwidget.bg = '#333333'
150 cpugraphwidget.border_color = '#0a0a0a'
151 cpugraphwidget.grow = 'right'
153 cpugraphwidget:plot_properties_set('cpu', {
155 fg_center = '#285577',
157 vertical_gradient = false
160 wicked.register(cpugraphwidget, 'cpu', '$1', 2, 'cpu')
163 -- {{{ Memory Usage Widget
165 memtextwidget = widget({
167 name = 'memtextwidget',
171 memtextwidget.text = heading('MEM')..': '
172 wicked.register(memtextwidget, 'mem', function (widget, args)
173 -- Add extra preceding zeroes when needed
174 local r = tonumber(args[1])
175 local percent = args[1]..'%'
177 percent = '0'..percent
180 percent = fg('green', percent)
182 percent = fg('orange', percent)
184 percent = fg('red', percent)
186 return heading('MEM')..': '..percent..' '..args[2]..'M'
190 -- {{{ Battery widget
192 batterywidget = widget({
194 name = 'batterywidget',
198 function batterywidget_update()
199 local v = io.popen("powersave -b|sed -ne 's/.*Remaining percent: \\(.*\\)/\\1/p'"):read()
200 local r = tonumber(v)
204 percent = fg('red', percent)
206 percent = fg('orange', percent)
208 percent = fg('green', percent)
210 batterywidget.text = heading('BAT')..': '..percent
212 batterywidget_update()
213 awful.hooks.timer.register(30, batterywidget_update)
218 rspacer = widget({ type = 'textbox', name = 'rspacer', align = 'right' })
223 clockwidget = widget({ type = "textbox", name = "clockwidget", align = "right" })
224 clock_update = function()
225 clockwidget.text = fg("#dddddd", os.date("%a %d %b - %H:%M"))
228 awful.hooks.timer.register(10, clock_update)
232 mymenubox = widget{ type = "textbox", name = "mytextbox", align = "left" }
233 -- mysystray = widget{ type = "systray", name = "mysystray", align = "right" }
239 for s = 1, screen.count() do
240 mainstatusbar[s] = wibox{
243 name = "mainstatusbar" .. s,
246 mainstatusbar[s].widgets = {
247 awful.widget.taglist.new(s, awful.widget.taglist.label.noempty, maintaglist.buttons),
252 rspacer, cputextwidget, cpugraphwidget,
253 rspacer, memtextwidget,
254 rspacer, clockwidget,
255 s == 1 and rspacer or nil,
256 s == 1 and mysystray or nil,
258 mainstatusbar[s].screen = s
267 local hist = os.getenv("HOME") .. "/.cache/awesome/history"
269 -- Mod+{A/S}: Switch to prev/next tag
270 key(k_m, "Left", eminent.tag.prev),
271 key(k_m, "Right", eminent.tag.next),
273 -- Mod+Shift+{A/S}: Move window to Prev/Next tag
274 key(k_ms, "Left", function()
275 awful.client.movetotag(eminent.tag.getprev())
278 key(k_ms, "Right", function()
279 awful.client.movetotag(eminent.tag.getnext())
283 -- Mod+Shift_{E/D}: move window to next/prev screen
284 key(k_mc, "Right", function()
285 local s = getscreen() + 1
286 while s > screen.count() do
289 client_movetoscreen(s)
291 key(k_mc, "Left", function()
292 local s = getscreen() - 1
296 client_movetoscreen(s)
300 -- Focus Prev/Next window
303 awful.client.focus.byidx(1)
304 if client.focus then client.focus:raise() end
308 awful.client.focus.byidx(-1)
309 if client.focus then client.focus:raise() end
312 -- Swap window with the Prev/Next one
313 key(k_ms, "j", function () awful.client.swap.byidx(1) end),
314 key(k_ms, "k", function () awful.client.swap.byidx(-1) end),
316 -- Mod+{E/D}: Switch to next/previous screen
317 key(k_m, "Tab", function () awful.screen.focus(1) end),
318 key(k_ms, "Tab", function () awful.screen.focus(-1) end),
320 -- Mod+Enter: Launch a new terminal
321 key(k_m, "e", function() awful.util.spawn("firefox") end),
322 key(k_m, "Return", function() awful.util.spawn(terminal) end),
323 key(k_ac, "r", awesome.restart),
324 key(k_m, "F12", function() awful.util.spawn(lock) end),
326 -- Layout manipulation
327 key(k_m, "l", function () awful.tag.incmwfact(0.05) end),
328 key(k_m, "h", function () awful.tag.incmwfact(-0.05) end),
329 key(k_ms, "h", function () awful.tag.incnmaster(1) end),
330 key(k_ms, "l", function () awful.tag.incnmaster(-1) end),
331 key(k_mc, "h", function () awful.tag.incncol(1) end),
332 key(k_mc, "l", function () awful.tag.incncol(-1) end),
337 awful.prompt.run({ prompt = "Run: " },
340 awful.completion.bash,
341 awful.util.getdir("cache").."/commands")
345 awful.prompt.run({ prompt = "Run Lua code: " },
349 awful.util.getdir("cache").."/lua_commands")
353 -- Mod+#: Switch to tag
354 -- Mod+Shift+#: Toggle tag display
355 -- Mod+Control+#: Move client to tag
356 -- Mod+Alt+#: Toggle client on tag
359 table.append(globalkeys,
362 eminent.tag.goto(i, nil, true)
367 local t = eminent.tag.getn(i, nil, true)
368 if t ~= nil then t.selected = not t.selected end
372 local t = eminent.tag.getn(i, nil, true)
373 if t ~= nil then awful.client.movetotag(t) end
379 ---- {{{ Client hotkeys
382 key(k_m, "i", function (c)
383 if mymenubox.text then
386 mymenubox.text = "Class: " .. c.class .. " Instance: ".. c.instance
390 -- Client manipulation
391 key(k_m, "c", function (c) c:kill() end),
392 key(k_m, "o", awful.client.floating.toggle),
393 key(k_m, "t", awful.client.togglemarked),
394 key(k_m, "F11", function (c) c.fullscreen = not c.fullscreen end)
399 root.keys(globalkeys)
403 awful.hooks.focus.register(function (c)
404 if not awful.client.ismarked(c) then
405 c.border_color = beautiful.border_focus
409 awful.hooks.unfocus.register(function (c)
410 if not awful.client.ismarked(c) then
411 c.border_color = beautiful.border_normal
415 awful.hooks.marked.register(function (c)
416 c.border_color = beautiful.border_marked
419 awful.hooks.unmarked.register(function (c)
420 c.border_color = beautiful.border_focus
423 -- Hook function to execute when the mouse enters a client.
424 awful.hooks.mouse_enter.register(function (c)
429 awful.hooks.manage.register(function (c, startup)
430 if not startup and awful.client.focus.filter(c) then
431 c.screen = mouse.screen
434 -- Add mouse bindings
436 button({ }, 1, function (c) client.focus = c; c:raise() end),
437 button(k_a, 1, awful.mouse.client.move),
438 button(k_a, 3, awful.mouse.client.resize)
442 c.border_width = beautiful.border_width
443 c.border_color = beautiful.border_normal
445 -- Make certain windows floating
446 local name = c.name:lower()
447 if name:find('pinentry') then
454 c.size_hints_honor = false
457 -- Hook function to execute when arranging the screen
458 -- (tag switch, new client, etc)
459 awful.hooks.arrange.register(function (screen)
460 local sel = client.focus
462 sel = awful.client.focus.history.get(screen, 0)
463 if sel then client.focus = sel end
467 local m_c = mouse.coords()
469 if m_c.x < sel.x - 1 or m_c.x > sel.x + sel.width + 1 or
470 m_c.y < sel.y - 1 or m_c.y > sel.y + sel.height + 1 then
471 if #m_c.buttons == 0 then
472 mouse.coords{x = sel.x + 5, y = sel.y + 5}