My Awesome WM config

This is my rc.lua (with Shifty support):

Do not forget to check and correct the marked words if you deem it necessary.



require("awful")

require("beautiful")
require("naughty")
require("shifty")
require("wicked")
--Invaders must die! :)
require("invaders")

-- Create a battery widget
batterywidget = widget({type = "textbox", name = "batterywidget", align = "right" })
batteryicon = widget({ type = "imagebox", align = "right" })

-- useful for debugging, marks the beginning of rc.lua exec
print("Entered rc.lua: " .. os.time())
-- {{{ Variable definitions
--here is my theme:
--http://thenixer.blogspot.com/2009/08/my-awesome-wm-theme.html
theme_path = ".config/awesome/themes/mytheme"
-- Actually load theme
beautiful.init(theme_path)
-- This is used later as the default terminal and editor to run.
browser = "chromium-browser"
--mail = "thunderbird"
terminal = "urxvt"
editor = os.getenv("EDITOR") or "vim"
editor_cmd = terminal .. " -e " .. editor
FM = "pcmanfm"

-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with others.
modkey = "Mod4"

-- Autorun programs
autorun = true
autorunApps =
{
"xcompmgr",
"eval `cat .fehbg`",
"pcmanfm -d",
"glipper-old",
"ck-launch-session blueman-applet",
"gsynaptics-init",
}
if autorun then
for app = 1, #autorunApps do
awful.util.spawn(autorunApps[app])
end
end

function mcabber_mess()
--mcabber_message_num.sh is here:
--http://thebosha.blogspot.com/2009/08/number-of-unread-mcabber-messages-in.html
local filedescriptor = io.popen('~/.scripts/mcabber_message_num.sh')
local value = nil
if filedescriptor ~= nil then
value = filedescriptor:read()
end
filedescriptor:close()
if value == nil then
return '0 msg.'
else
return value
end
--local value = filedescriptor:read()
--filedescriptor:close()

--return value
end

getmcabbermessnum = widget({
type = 'textbox',
name = 'getmcabbermessnum',
align = 'right'})

wicked.register(
getmcabbermessnum,
mcabber_mess,
" $1 ")

space = widget({
type = 'textbox',
name = 'space',
align = 'right'})
space.text = ' '

--sound widget code
--you must setup your card ID and ALSA channels
cardid = 0
channel = "LineOut"
mutechannel = "iSpeaker"
function volume (mode, widget)
if mode == "update" then
local fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)
local status = fd:read("*all")
fd:close()
local volume = string.match(status, "(%d?%d?%d)%%")
volume = string.format("% 3d", volume)
status = string.match(status, "%[(o[^%]]*)%]")
if string.find(status, "on", 1, true) then
volume = volume .. "%"
else
volume = volume .. "M"
end
widget.text = volume
elseif mode == "up" then
io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")
volume("update", widget)
elseif mode == "down" then
io.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")
volume("update", widget)
elseif mode == "mpd_toggle" then
io.popen("mpc toggle"):read("*all")
volume("update", widget)
elseif mode == "moc_toggle" then
io.popen("mocp -G"):read("*all")
volume("update", widget)
else
io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
io.popen("amixer -c " .. cardid .. " sset " .. mutechannel .. " toggle"):read("*all")
volume("update", widget)
end
end

tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
--right mouse button — play/pause MOC
--middle mouse button — play/pause ncmpcpp (MPD client)
tb_volume:buttons({
button({ }, 4, function () volume("up", tb_volume) end),
button({ }, 5, function () volume("down", tb_volume) end),
button({ }, 1, function () volume("mute", tb_volume) end),
button({ }, 2, function () volume("mpd_toggle", tb_volume) end),
button({ }, 3, function () volume("moc_toggle", tb_volume) end)
})
volume("update", tb_volume)

--battery monitor code (added_by_me)
function batteryInfo(adapter)
spacer = " "
local fcur = io.open("/sys/class/power_supply/"..adapter.."/charge_now")
local fcap = io.open("/sys/class/power_supply/"..adapter.."/charge_full")
local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")
local cur = fcur:read()
local cap = fcap:read()
local sta = fsta:read()
local battery = math.floor(cur * 100 / cap)
if sta:match("Charging") then
dir = "↑"
--battery = "A/C ("..battery..")"
battery = ""..battery..""
elseif sta:match("Discharging") then
dir = "↓"
if tonumber(battery) > 25 and tonumber(battery) <>
battery = battery
elseif tonumber(battery) <>
if tonumber(battery) <>
naughty.notify({ title = "Battery Warning"
, text = "Battery low!"..spacer..battery.."%"..spacer.."left!"
, timeout = 5
, position = "top_right"
, fg = beautiful.fg_focus
, bg = beautiful.bg_focus
})
end
battery = battery
else
battery = battery
end
else
dir = "↕"
battery = "A/C"
end
batterywidget.text = dir..battery
fcur:close()
fcap:close()
fsta:close()
end

-- Create a textbox widget
clock = widget({ type = "textbox", align = "right" })
-- Set the default text in textbox
clock.text = " "

-- Table of layouts to cover with awful.layout.inc, order matters.
layouts =
{
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.max,
awful.layout.suit.max.fullscreen,
--awful.layout.suit.magnifier,
awful.layout.suit.floating
}
-- Define if we want to use titlebar on all applications.
use_titlebar = false
-- }}}

--{{{ SHIFTY: configured tags
shifty.config.tags = {
["Main"] = { layout = awful.layout.suit.tile.left, mwfact=0.60, exclusive = false, position = 1, init = true, screen = 1, slave = false, nopopup = true, } ,
["Web"] = { layout = awful.layout.suit.max, mwfact=0.50, exclusive = false, position = 2, init = false, screen = 1, slave = false, nopopup = true },
["Chat"] = { layout = awful.layout.suit.tile, mwfact=0.10, exclusive = false, position = 3, init = false, screen = 1, slave = false, nopopup = true },
["Med"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.60, exclusive = false, position = 4, init = false, screen = 1, slave = false, nopopup = true },
["Code"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.60, exclusive = false, position = 5, init = false, screen = 1, slave = false, nopopup = true },
["Term"] = { layout = awful.layout.suit.tile.top, mwfact=0.60, exclusive = false, position = 6, init = true, screen = 1, slave = false, nopopup = true },
["Vim"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.60, exclusive = false, position = 7, init = false, screen = 1, slave = false, nopopup = true },
["Files"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.50, exclusive = false, position = 8, init = false, screen = 1, slave = false, nopopup = true },
["Notes"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.50, exclusive = false, position = 9, init = false, screen = 1, slave = false, nopopup = true },
}
--}}}
--{{{ SHIFTY: application matching rules
-- order here matters, early rules will be applied first
shifty.config.apps = {
{ match = { "psi", } , tag = "Chat" },
{ match = { "chrome", "firefox", } , tag = "Web", } ,
{ match = { "pcmanfm", } , tag = "Files", } ,
{ match = { "geany", } , tag = "Code", } ,
{ match = { "wpa_gui", "OpenOffice.*", "epdfview", } , tag = "Main", } ,
{ match = { "gpodder", "smplayer", "sonata", "ncmpcpp", "gnome-alsamixer"} , tag = "Med", } ,
{ match = { "leafpad" } , tag = "Notes", },
{ match = { terminal } , tag = "Term" },
{ match = { "gvim", } , tag = "Vim" },
{ match = { "gqview", } , tag = "Main" },
--{ match = { terminal } , honorsizehints = false, slave = false, tag = "term" }
}
--}}}
--{{{ SHIFTY: default tag creation rules
-- parameter description
-- * floatBars : if floating clients should always have a titlebar
-- * guess_name : wether shifty should try and guess tag names when creating new (unconfigured) tags
-- * guess_position: as above, but for position parameter
-- * run : function to exec when shifty creates a new tag
-- * remember_index: ?
-- * all other parameters (e.g. layout, mwfact) follow awesome's tag API
shifty.config.defaults={
layout = awful.layout.suit.tile.bottom,
ncol = 1,
mwfact = 0.60,
floatBars=false,
guess_name=true,
guess_position=true,
run = function(tag)
local stitle = "Shifty Created: "
stitle = stitle .. (awful.tag.getproperty(tag,"position") or shifty.tag2index(mouse.screen,tag))
stitle = stitle .. " : "..tag.name
naughty.notify({ text = stitle })
end,
}
--}}}
-- {{{ Wibox
-- Create a textbox widget
clock = widget({ type = "textbox", align = "right" })
-- Create a laucher widget and a main menu
myinternetmenu = {
{ "Firefox", "firefox" },
{ "Chrome", "chromium-browser" },
{ "Psi", "psi" },
{ "Gpodder", "gpodder"},
{ "NMap", "gksudo nmapfe" },
{ "Skype", "skype" }
}

myofficemenu = {
{ "EPDFView", "epdfview" },
{ "Office Base", "soffice -base" },
{ "Office Calc", "soffice -calc" },
{ "Office Draw", "soffice -draw" },
{ "Office Temlate", "soffice slog:5500" },
{ "Office Impress", "soffice -impress" },
{ "Office Math", "soffice -math" },
{ "Office Writer", "soffice- writer" },
}

mymediamenu = {
{ "Mixer", "gnome-alsamixer"},
{ "Sonata", "sonata" },
{ "SMPlayer", "smplayer" },
{ "VLC", "vlc" },
{ "wxCam", "wxcam" },
{ "Sound Converter", "soundconverter" },
}

mygraphicsmenu = {
{ "GQView", "gqview" },
{ "GIMP", "gimp" },
{ "XSane", "xsane" },
}

mygamesmenu = {
{ "XMoto", ".scripts/game_xmoto.sh" },
{ "Duke 3D", ".scripts/game_eduke32.sh" },
{ "Frozen Bubble", "frozen-bubble" },
{ "Invaders", invaders.run },
{ "XBL", "xbl" },
}

mycodemenu = {
{ "Geany", "geany" },
{ "gVim", "gvim" },
}

myothermenu = {
{ "Leafpad", "leafpad" },
{ "XArchiver", "xarchiver" },
{ "LXAppearance", "lxappearance" },
{ "Dia", "dia" },
{ "Disk Usage", "xdiskusage" },
{ "HP Toolbox", "hp-toolbox" },
}

mymainmenu = awful.menu.new({ items = { { " Internet", myinternetmenu },
{ " Media", mymediamenu },
{ " Graphics", mygraphicsmenu },
{ "Office", myofficemenu },
{ "Code", mycodemenu },
{ "Other", myothermenu },
{ "Games", mygamesmenu },
{ " ", separator },
{ "Terminal", terminal },
{ "KeePassX", "keepassx" },
{ "File manager", FM }
}
})

mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
menu = mymainmenu })
-- Create a systray
mysystray = widget({ type = "systray", align = "right" })
-- Create a wibox for each screen and add it
topwibox = {}
botttopwibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),
button({ modkey }, 1, awful.client.movetotag),
button({ }, 3, function (tag) tag.selected = not tag.selected end),
button({ modkey }, 3, awful.client.toggletag),
button({ }, 5, awful.tag.viewnext),
button({ }, 4, awful.tag.viewprev) }
mytasklist = {}
mytasklist.buttons = { button({ }, 1, function (c)
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
client.focus = c
c:raise()
end),
button({ }, 3, function () if instance then instance:hide() instance = nil else instance = awful.menu.clients({ width=250 }) end end),
button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
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] = widget({ type = "textbox", align = "left" })
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
mylayoutbox[s] = widget({ type = "imagebox", align = "right" })
mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),
button({ }, 3, function () awful.layout.inc(layouts, -1) end),
button({ }, 4, function () awful.layout.inc(layouts, 1) end),
button({ }, 5, function () awful.layout.inc(layouts, -1) end) })
-- Create a taglist widget
mytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)
-- Create a tasklist widget
mytasklist[s] = awful.widget.tasklist.new(function(c)
return awful.widget.tasklist.label.currenttags(c, s)
end, mytasklist.buttons)
-- Create the wibox
topwibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
topwibox[s].widgets = {
mylauncher,
mytaglist[s],
mypromptbox[s],
space,
tb_volume,
space,
getmcabbermessnum,
space,
batterywidget,
space,
clock,
--space,
s == 1 and mysystray or nil,
mylayoutbox[s]
}
topwibox[s].screen = s
--you may enable bottom panel
--bottwibox[s] = wibox({ position = "bottom", fg = beautiful.fg_normal, bg = beautiful.bg_normal })
--bottwibox[s].widgets = {

--mytasklist[s],
--space,
--s == 1 and mysystray or nil,
-- }
--bottwibox[s].screen = s
end
-- }}}
--{{{ SHIFTY: initialize shifty
-- the assignment of shifty.taglist must always be after its actually initialized
-- with awful.widget.taglist.new()
shifty.taglist = mytaglist
shifty.init()
--}}}
-- {{{ Key bindings
globalkeys =
{
-- TAGS
key({ modkey, }, "x", awful.tag.viewprev ),
key({ modkey, }, "Left", awful.tag.viewprev ),
key({ modkey, }, "c", awful.tag.viewnext ),
key({ modkey, }, "Right", awful.tag.viewnext ),
key({ modkey, }, "Escape", awful.tag.history.restore),
-- SHIFTY: keybindings specific to shifty
key({ modkey, "Shift" }, "d", shifty.del), -- delete a tag
key({ modkey, "Shift" }, "n", shifty.send_prev),-- move client to prev tag
key({ modkey }, "n", shifty.send_next),-- move client to next tag
key({ modkey,"Control"}, "n", function()
shifty.tagtoscr(awful.util.cycle(screen.count(), mouse.screen +1))
end),-- move client to next tag
key({ modkey }, "a", shifty.add), -- creat a new tag
key({ modkey, }, "r", shifty.rename), -- rename a tag
key({ modkey, "Shift" }, "a", -- nopopup new tag
function()
shifty.add({ nopopup = true })
end),
key({ modkey, }, "j",
function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
key({ modkey, }, "k",
function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
key({ modkey, }, "z", function () mymainmenu:show(true) end),
-- Layout manipulation
key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),
key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),
key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),
key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),
key({ modkey, }, "u", awful.client.urgent.jumpto),
key({ modkey, }, "Tab",
function ()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
-- Standard program
key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
key({ modkey, "Control" }, "r", awesome.restart),
key({ modkey, "Shift" }, "q", awesome.quit),
key({ modkey }, "F6", function () awful.util.spawn('xkill') end),
key({ modkey }, "F3", function () awful.util.spawn('transset-df -p --inc .05 &') end),
key({ modkey }, "F4", function () awful.util.spawn('transset-df -p --dec .05 &') end),
key({ modkey }, "F10", function () awful.util.spawn('ncmpcpp toggle &') end),
key({ modkey }, "F8", function () awful.util.spawn('ncmpcpp volume -1 &') end),
key({ modkey }, "F9", function () awful.util.spawn('ncmpcpp volume +1 &') end),
key({ modkey }, "]", function () awful.util.spawn('ncmpcpp next &') end),
key({ modkey }, "[", function () awful.util.spawn('ncmpcpp prev &') end),
key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),
key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),
key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),
-- Prompt
key({ modkey }, "F2",
function ()
awful.prompt.run({ prompt = "Run: " },
mypromptbox[mouse.screen],
awful.util.spawn, awful.completion.shell,
awful.util.getdir("cache") .. "/history")
end),
key({ modkey }, "p",
function ()
awful.prompt.run({ prompt = "Run Lua code: " },
mypromptbox[mouse.screen],
awful.util.eval, nil,
awful.util.getdir("cache") .. "/history_eval")
end),
}
--{{{ Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on them
clientkeys =
{
key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
key({ modkey, }, "q", function (c) c:kill() end),
key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
key({ modkey, }, "o", awful.client.movetoscreen ),
key({ modkey, "Shift" }, "r", function (c) c:redraw() end),
key({ modkey }, "t", awful.client.togglemarked),
key({ modkey,}, "m",
function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end),
}
-- SHIFTY: assign client keys to shifty for use in
-- match() function (manage hook)
shifty.config.clientkeys = clientkeys
shifty.config.modkey = modkey
--}}}
-- Compute the maximum number of digit we need, limited to 9
for i=1, ( shifty.config.maxtags or 9 ) do
table.insert(globalkeys, key({ modkey }, i,
function ()
local t = awful.tag.viewonly(shifty.getpos(i))
end))
table.insert(globalkeys, key({ modkey, "Control" }, i,
function ()
local t = shifty.getpos(i)
t.selected = not t.selected
end))
table.insert(globalkeys, key({ modkey, "Control", "Shift" }, i,
function ()
if client.focus then
awful.client.toggletag(shifty.getpos(i))
end
end))
-- move clients to other tags
table.insert(globalkeys, key({ modkey, "Shift" }, i,
function ()
if client.focus then
t = shifty.getpos(i)
awful.client.movetotag(t)
awful.tag.viewonly(t)
end
end))
end
-- Set keys
root.keys(globalkeys)
-- }}}
-- {{{ Hooks
-- Hook function to execute when focusing a client.
awful.hooks.focus.register(function (c)
if not awful.client.ismarked(c) then
c.border_color = beautiful.border_focus
--c.opacity = 1
end
end)
-- Hook function to execute when unfocusing a client.
awful.hooks.unfocus.register(function (c)
if not awful.client.ismarked(c) then
c.border_color = beautiful.border_normal
--c.opacity = 0.9
end
end)
-- Hook function to execute when marking a client
awful.hooks.marked.register(function (c)
c.border_color = beautiful.border_marked
end)
-- Hook function to execute when unmarking a client.
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, but disabled for magnifier layout
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c) then
client.focus = c
end
end)
--[[ Placeholder: for end users who want to customize the behavior
-- of new client appearances.
--
-- Otherwise shifty.lua provides a manage hook already.
--
awful.hooks.manage.register(function (c, startup)
end) --]]--
awful.hooks.manage.register(function (c, startup)
-- If we are not managing this application at startup,
-- move it to the screen where the mouse is.
-- We only do it for filtered windows (i.e. no dock, etc).
if not startup and awful.client.focus.filter(c) then
c.screen = mouse.screen
end

if use_titlebar then
-- Add a titlebar
awful.titlebar.add(c, { modkey = modkey })
end
-- Add mouse bindings
c:buttons(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),
awful.button({ modkey }, 2, function (c) c:kill() end)
))
-- New client may not receive focus
-- if they're not focusable, so set border anyway.
c.border_width = beautiful.border_width
c.border_color = beautiful.border_normal

-- Check if the application should be floating.
local cls = c.class
local inst = c.instance
if floatapps[cls] ~= nil then
awful.client.floating.set(c, floatapps[cls])
elseif floatapps[inst] ~= nil then
awful.client.floating.set(c, floatapps[inst])
end

-- Check application->screen/tag mappings.
local target
if apptags[cls] then
target = apptags[cls]
elseif apptags[inst] then
target = apptags[inst]
end
if target then
c.screen = target.screen
awful.client.movetotag(tags[target.screen][target.tag], c)
end

-- Do this after tag mapping, so you don't see it on the wrong tag for a split second.
client.focus = c

-- Set key bindings
c:keys(clientkeys)

-- Set the windows at the slave,
-- i.e. put it at the end of others instead of setting it master.
-- awful.client.setslave(c)

-- Honor size hints: if you want to drop the gaps between windows, set this to false.
-- 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 layout = awful.layout.getname(awful.layout.get(screen))
if layout and beautiful["layout_" ..layout] then
mylayoutbox[screen].image = image(beautiful["layout_" .. layout])
else
mylayoutbox[screen].image = nil
end
-- Give focus to the latest client in history if no window has focus
-- or if the current window is a desktop or a dock one.
if not client.focus then
local c = awful.client.focus.history.get(screen, 0)
if c then client.focus = c end
end
end)

-- Hooks (added by me)
awful.hooks.timer.register(10, function() batteryInfo("BAT0") end)
awful.hooks.timer.register(10, function() getmcabbermessnum.text = mcabber_mess() end)
--you may edit clock.text for your needs
awful.hooks.timer.register(20, function () clock.text = os.date("%u:%d-%H:%M") end)
awful.hooks.timer.register(10, function () volume("update", tb_volume) end)
-- }}}


Share/Save/Bookmark