Skip to content

Instantly share code, notes, and snippets.

@EgonSpengler
Last active June 26, 2016 00:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EgonSpengler/8662532 to your computer and use it in GitHub Desktop.
Save EgonSpengler/8662532 to your computer and use it in GitHub Desktop.
--[[
Egon's Personal Awesome Config
Updated 2014/2/1
]]
local gears = require("gears")
local awful = require("awful")
local wibox = require("wibox")
local beautiful = require("beautiful")
local naughty = require("naughty")
local menubar = require("menubar")
local lain = require("lain")
local APW = require("apw/widget")
vicious = require("vicious")
awful.rules = require("awful.rules")
require("awful.autofocus")
require('freedesktop.utils')
require('freedesktop.menu')
-- {{{ Error handling
if awesome.startup_errors then
naughty.notify({ preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!",
text = awesome.startup_errors })
end
do
local in_error = false
awesome.connect_signal("debug::error", function (err)
-- Make sure we don't go into an endless error loop
if in_error then return end
in_error = true
naughty.notify({ preset = naughty.config.presets.critical,
title = "Oops, an error happened!",
text = err })
in_error = false
end)
end
-- }}}
-- {{{ Variable definitions
beautiful.init("/home/egon/.config/awesome/themes/egon/themenew.lua")
terminal = "urxvt"
editor = os.getenv("EDITOR") or "vi"
editor_cmd = terminal .. " -e " .. editor
modkey = "Mod4"
lain.layout.centerfair.nmaster = 3
lain.layout.centerfair.ncol = 1
-- Table of layouts to cover with awful.layout.inc, order matters.
local layouts =
{
lain.layout.centerfair,
--lain.layout.uselessfair,
--awful.layout.suit.floating,
--awful.layout.suit.tile,
awful.layout.suit.tile.left,
--awful.layout.suit.tile.bottom,
--awful.layout.suit.tile.top,
--awful.layout.suit.fair,
--awful.layout.suit.fair.horizontal,
--awful.layout.suit.spiral,
--awful.layout.suit.spiral.dwindle,
awful.layout.suit.max,
--awful.layout.suit.max.fullscreen,
--awful.layout.suit.magnifier
}
-- }}}
-- {{{ Tags
tags = {
names = { "E", "G", "O", "N", "L", "I", "N", "U", "X"},
layout = {layouts[2], layouts[2], layouts[2], layouts[2], layouts[2],
layouts[2], layouts[2], layouts[2], layouts[2] }
}
for s = 1, screen.count() do
-- Each screen has its own tag table.
tags[s] = awful.tag(tags.names, s, tags.layout)
end
-- }}}
-- {{{ Menu
-- Create a laucher widget and a main menu
-- Blank entry added because I kept accidentally logging out
-- while trying to restart the WM to test theme changes
myawesomemenu = {
{ "terminal", terminal },
{ "edit config", "subl3 " .. awesome.conffile },
{ "restart", awesome.restart },
{ "", },
{ "logout", awesome.quit },
{ "shutdown", terminal .. " -e shutdown -h now" }
}
menu_items = freedesktop.menu.new()
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}
mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },
{ "applications", menu_items}
}
})
mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
menu = mymainmenu })
menubar.utils.terminal = terminal
-- }}}
-- Spacer to spread out widgets
spacer = wibox.widget.textbox()
spacer:set_markup(" ")
separator = wibox.widget.textbox()
separator:set_markup("|")
separator:set_font("Arial 7")
textclock = awful.widget.textclock(" %a %b %d, %I:%M ", 30)
mytextclock = wibox.layout.flex.horizontal()
mytextclock:add(textclock)
mytextclock:set_max_widget_size(92, 16)
-- Battery
baticon = wibox.widget.imagebox(beautiful.bat)
batbar = awful.widget.progressbar()
batbar:set_color(beautiful.bat_fg)
batbar:set_width(55)
batbar:set_ticks(true)
batbar:set_ticks_size(6)
batbar:set_background_color(beautiful.bg_normal)
batmargin = wibox.layout.margin(batbar, 2, 7)
batmargin:set_top(5)
batmargin:set_bottom(5)
batupd = lain.widgets.bat({
settings = function()
if bat_now.perc == "N/A" then
bat_perc = 100
baticon:set_image(beautiful.ac)
else
bat_perc = tonumber(bat_now.perc)
if bat_perc > 50 then
batbar:set_color(beautiful.bat_fg)
baticon:set_image(beautiful.bat)
elseif bat_perc > 15 then
baticon:set_image(beautiful.bat_low)
else
batbar:set_color("#EA9A9A")
baticon:set_image(beautiful.bat_no)
end
end
batbar:set_value(bat_perc / 100)
end
})
batwidget = wibox.widget.background(batmargin)
batwidget:set_bgimage(beautiful.battery_bg)
-- PulseAudio Control Widget
volicon = wibox.widget.imagebox(beautiful.speaker_high)
pulseMargin = wibox.layout.margin(APW, 2, 7)
pulseMargin:set_top(5)
pulseMargin:set_bottom(5)
pulseBar = wibox.widget.background(pulseMargin)
pulseBar:set_bgimage(beautiful.volume_bg)
-- RAM meter
memicon = wibox.widget.imagebox(beautiful.ram)
memwidget = awful.widget.progressbar()
memwidget:set_width(55)
memwidget:set_ticks(true)
memwidget:set_ticks_size(6)
memwidget:set_background_color(beautiful.bg_normal)
memwidget:set_color(beautiful.mem_fg)
vicious.register(memwidget, vicious.widgets.mem, "$1", 13)
memmargin = wibox.layout.margin(memwidget, 2, 7)
memmargin:set_top(5)
memmargin:set_bottom(5)
memwidget = wibox.widget.background(memmargin)
memwidget:set_bgimage(beautiful.ram_bg)
-- CPU meter
cpuicon = wibox.widget.imagebox(beautiful.cpu)
cpuwidget = awful.widget.progressbar()
cpuwidget:set_width(55)
cpuwidget:set_ticks(true)
cpuwidget:set_ticks_size(6)
cpuwidget:set_background_color(beautiful.bg_normal)
cpuwidget:set_color(beautiful.cpu_fg)
vicious.register(cpuwidget, vicious.widgets.cpu, "$1")
cpumargin = wibox.layout.margin(cpuwidget, 2, 7)
cpumargin:set_top(5)
cpumargin:set_bottom(5)
cpuwidget = wibox.widget.background(cpumargin)
cpuwidget:set_bgimage(beautiful.cpu_bg)
-- Wifi icon and network manager starter
wifiicon = wibox.widget.imagebox(beautiful.wifi)
wifiicon:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.util.spawn("wicd-client -n") end))
)
--wifiicon = awful.widget.button(beautiful.wifi)
-- Create a wibox for each screen and add it
mywibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ }, 3, awful.tag.viewtoggle),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
)
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
awful.button({ }, 1, function (c)
if c == client.focus then
c.minimized = true
else
-- Without this, the following
-- :isvisible() makes no sense
c.minimized = false
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
-- This will also un-minimize
-- the client, if needed
client.focus = c
c:raise()
end
end),
awful.button({ }, 3, function ()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({ width=250 })
end
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end))
for s = 1, screen.count() do
-- Create a promptbox for each screen
mypromptbox[s] = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
mylayoutbox[s] = awful.widget.layoutbox(s)
mylayoutbox[s]:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
-- Create a taglist widget
mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
-- Create a tasklist widget
mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
-- Create the wibox
mywibox[s] = awful.wibox({ position = "top", screen = s })
-- Widgets that are aligned to the left
local left_layout = wibox.layout.fixed.horizontal()
-- left_layout:add(mylauncher)
left_layout:add(mytaglist[s])
left_layout:add(mylauncher)
left_layout:add(mypromptbox[s])
-- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal()
right_layout:add(cpuicon)
right_layout:add(cpuwidget)
right_layout:add(spacer)
right_layout:add(separator)
right_layout:add(spacer)
right_layout:add(memicon)
right_layout:add(memwidget)
right_layout:add(spacer)
right_layout:add(separator)
right_layout:add(spacer)
right_layout:add(baticon)
right_layout:add(batwidget)
right_layout:add(spacer)
right_layout:add(separator)
right_layout:add(spacer)
right_layout:add(volicon)
right_layout:add(pulseBar)
right_layout:add(spacer)
right_layout:add(separator)
right_layout:add(spacer)
right_layout:add(wifiicon)
right_layout:add(spacer)
right_layout:add(spacer)
right_layout:add(spacer)
right_layout:add(mytextclock)
--Uncomment this line for a system tray on primary screen
--if s == 1 then right_layout:add(wibox.widget.systray()) end
right_layout:add(spacer)
right_layout:add(mylayoutbox[s])
-- Now bring it all together (with the tasklist in the middle)
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_middle(mytasklist[s])
layout:set_right(right_layout)
mywibox[s]:set_widget(layout)
end
-- }}}
-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
awful.button({ }, 3, function () mymainmenu:toggle() end),
awful.button({ }, 4, awful.tag.viewnext),
awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}
-- {{{ Key bindings
globalkeys = awful.util.table.join(
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
awful.key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "k",
function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
awful.key({ modkey, }, "e", function () awful.screen.focus_relative( 1) end),
awful.key({ modkey, }, "w", function () awful.screen.focus_relative(-1) end),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
awful.key({ modkey, }, "b", function () mywibox[mouse.screen].visible = not mywibox[mouse.screen].visible end),
awful.key({ modkey, }, "Tab",
function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
-- Standard program
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
awful.key({ modkey, "Control" }, "r", awesome.restart),
awful.key({ modkey, "Control" }, "q", awesome.quit),
awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(1) end),
awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
-- Prompt
awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end),
-- Menubar
awful.key({ modkey }, "p", function() menubar.show() end),
-- Volume control
awful.key({ }, "XF86AudioRaiseVolume", APW.Up),
awful.key({ }, "XF86AudioLowerVolume", APW.Down),
awful.key({ }, "XF86AudioMute", APW.ToggleMute)
)
clientkeys = awful.util.table.join(
awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
awful.key({ modkey, }, "q", function (c) c:kill() end),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "o", awful.client.movetoscreen ),
awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
awful.key({ modkey, }, "m",
function (c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end),
awful.key({ modkey, }, "s",
function (c)
c.sticky = not c.sticky
end)
)
-- Bind all key numbers to tags.
-- Be careful: we use keycodes to make it works on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, 9 do
globalkeys = awful.util.table.join(globalkeys,
awful.key({ modkey }, "#" .. i + 9,
function ()
local screen = mouse.screen
local tag = awful.tag.gettags(screen)[i]
if tag then
awful.tag.viewonly(tag)
end
end),
awful.key({ modkey, "Control" }, "#" .. i + 9,
function ()
local screen = mouse.screen
local tag = awful.tag.gettags(screen)[i]
if tag then
awful.tag.viewtoggle(tag)
end
end),
awful.key({ modkey, "Shift" }, "#" .. i + 9,
function ()
local tag = awful.tag.gettags(client.focus.screen)[i]
if client.focus and tag then
awful.client.movetotag(tag)
end
end),
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9,
function ()
local tag = awful.tag.gettags(client.focus.screen)[i]
if client.focus and tag then
awful.client.toggletag(tag)
end
end))
end
clientbuttons = awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize))
-- Set keys
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 = awful.client.focus.filter,
keys = clientkeys,
size_hints_honor = false,
buttons = clientbuttons } },
{ rule = { class = "MPlayer" },
properties = { floating = true } },
{ rule = { class = "pinentry" },
properties = { floating = true } },
{ rule = { class = "gimp" },
properties = { floating = true } },
}
-- }}}
-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
if not startup then
-- Put windows in a smart way, only if they do not set an initial position.
if not c.size_hints.user_position and not c.size_hints.program_position then
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
end
local titlebars_enabled = false
if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
-- buttons for the titlebar
local buttons = awful.util.table.join(
awful.button({ }, 1, function()
client.focus = c
c:raise()
awful.mouse.client.move(c)
end),
awful.button({ }, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end)
)
-- Widgets that are aligned to the left
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(awful.titlebar.widget.iconwidget(c))
left_layout:buttons(buttons)
-- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal()
right_layout:add(awful.titlebar.widget.floatingbutton(c))
right_layout:add(awful.titlebar.widget.maximizedbutton(c))
right_layout:add(awful.titlebar.widget.stickybutton(c))
right_layout:add(awful.titlebar.widget.ontopbutton(c))
right_layout:add(awful.titlebar.widget.closebutton(c))
-- The title goes in the middle
local middle_layout = wibox.layout.flex.horizontal()
local title = awful.titlebar.widget.titlewidget(c)
title:set_align("center")
middle_layout:add(title)
middle_layout:buttons(buttons)
-- Now bring it all together
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_right(right_layout)
layout:set_middle(middle_layout)
awful.titlebar(c):set_widget(layout)
end
end)
-- No border if maximized or the only window showing.
-- Set own_window_type override in .conkyrc or it will be counted as a client
for s = 1, screen.count() do screen[s]:add_signal("arrange", function ()
local clients = awful.client.visible(s)
for _, c in pairs(clients) do
if c.maximized_horizontal and c.maximized_vertical then
c.border_width = 0
elseif #clients == 1 then
c.border_width = 0
else
c.border_width = beautiful.border_width
end
end
end)
end
client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}
-- Update volume widget every 5 seconds in case volume is adjusted elsewhere
APWTimer = timer({ timeout = 5 })
APWTimer:connect_signal("timeout", APW.Update)
APWTimer:start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment