Please bear with us as we work to restore functionality to dotfiles.org.
trapd00r
/Awesome 3 - rc.lua
--------------------------------
-- ^_^ ---
--------------------------------
require("awful")
--require("wicked")
--require("beautiful")
--{{{ Custom Variables
terminal = "exec urxvt"
menu = "dmenu"
modkey = "Mod4"
theme_path = "lol/"
fonts = {normal = "Cure 4"}
bg = {normal = "#000000", focus = "#000000", focus_choices = {"#000000", "#000000", "#000000"}, urgent = "#000000"}
fg = {normal = "#ffffff", focus = "#6797FF", urgent = "#1A63FF"}
border = bg
mainBarHeight = 13
tagnames = {"MAIN", "DEV", "WEB", "IM", "SYS1", "SYS2", "SYS3", "SYS4", "SYS5" ,"SYS6", "TRASH"}
layouts = {"tile", "tileleft", "tilebottom", "tiletop", "floating"}
defaultLayout = layouts[1]
-- tagRules = { ---compare the wm_class and name of the client
-- ["midori"] = "web",
-- ["firefox"] = "web", --firefox
-- ["pebrot"] = "im",
-- ["epdfview"] = "doc",
-- ["irssi"] = "im",
-- }
floatingRules = { --wm class again
["gimp"] = true,
["phun.bin"] = true
}
---}}}
awesome.font_set(fonts['normal'])
awesome.colors_set({ fg = fg['normal'], bg = bg['normal'] })
-- beautiful.init(theme_path)
-- awful.beautiful.register(beautiful)
---{{{ Utility Variables and Functions
--VARIABLES
tagsByName = {}
tagsByNumber = {}
tagsActive = {}
tagsUrgent = {}
currentTag = nil
lastTag = nil
tempCoords = nil
--FUNCTIONS
function colourise(text, fgcolour, bgcolour) --british spelling ftw
return "" .. text .. ""
end
function textBox(nameIn, alignIn, defaultText)
temp = widget({
type = "textbox", name = nameIn, align = alignIn
})
temp.text = defaultText
return temp
end
function imageBox(nameIn, pathIn, alignIn, resize)
return textBox(nameIn, alignIn, "")
end
function clientRules(c)
local screen = mouse.screen
for class,tag in pairs(tagRules) do
if c.class:lower():find(class) or c.name:lower():find(class) then
if tagsByName[screen][tag] then
awful.client.movetotag(tagsByName[screen][tag], c)
end
end
end
for class,bool in pairs(floatingRules) do
if c.class:lower():find(class) and bool then
c.floating = true
end
end
end
function tagBack()
awful.tag.viewonly(lastTag)
end
function setStatusText(text)
statustext.text = text
end
function joinTables(t1, t2)
for k,v in ipairs(t2) do table.insert(t1, v) end return t1
end
---}}}
---{{{ Setup Tags
for s = 1, screen.count() do
tagsByName[s] = {}
tagsByNumber[s] = {}
for tagnumber = 1, #tagnames do
tagsByName[s][tagnames[tagnumber]] = tag({name = tagnames[tagnumber], layout = defaultLayout})
tagsByNumber[s][tagnumber] = tagsByName[s][tagnames[tagnumber]]
tagsByNumber[s][tagnumber].mwfact = 0.618033988769
tagsByNumber[s][tagnumber].screen = s
tagsByNumber[s][tagnumber].layout = "tilebottom"
end
tagsByNumber[s][1].selected = true
end
--special for im tag
tagsByName[1]['IM'].layout = "tileleft"
tagsByName[1]['IM'].mwfact = 0.2
---}}}
---{{{ Widgets
--ARCHBOX
archicon = imageBox("archicon", "/home/ben/Pictures/awesome-arch-red.png", "left", "true")
archicon:mouse_add(mouse({ }, 1, function () awful.spawn("exec /home/ben/builds/PyShutdown/PowerDown.py") end ))
--TAGLIST
taglist = widget({type = "taglist", name = "taglist", height=30 })
taglist:mouse_add(
mouse({}, 1, function (object, tag) awful.tag.viewonly(tag) end)
)
function taglist.label(t)
local bg_color
local fg_color
local background = ''
if t.selected then
local choice = math.random(1,3)
bg_color = bg['focus_choices'][choice]
fg_color = fg['focus']
end
local sel = client.focus
if sel and sel:tags()[t] then
background = "resize=\"true\" image=\"/usr/share/awesome/icons/taglist/squarefw.png\""
else
for k, c in pairs(client.get()) do
if c:tags()[t] then
background = "resize=\"true\" image=\"/usr/share/awesome/icons/taglist/squarew.png\""
if c.urgent then
bg_color = bg['urgent']
fg_color = fg['urgent']
end
end
end
end
if bg_color and fg_color then
text = " "..t.name.." "
else
text = " "..t.name .. " "
end
return text
end
--LAUNCHBOXEN
launchboxen = {}
function launchboxen:add(image, command)
local index = #self + 1
self[index] = imageBox("launchbox" .. index, image, "left", "true")
self[index]:mouse_add(mouse({ }, 1, function () awful.spawn(command) end))
end
launchboxen:add("/usr/share/pixmaps/firefox.png", "exec firefox")
launchboxen:add("/usr/share/icons/hicolor/32x32/apps/pidgin.png", "exec pidgin")
launchboxen:add("/usr/share/pixmaps/loemu.png", "exec loemu")
--CLOCK ICON
clockicon = imageBox("clockicon", "/usr/share/icons/bw2vista/scalable/emblems/emblem-urgent.png", "right", "false")
--CLOCK TEXT
clocktext = textBox("clock", "right", "ThE tImE")
function clocktextUpdate ()
clocktext.text = " " .. os.date("%a, %b %d %I:%M%p") .. " "
end
awful.hooks.timer.register(10, clocktextUpdate)
---NOTEO
noteo = textBox("noteo", "left", "")
---}}}
---{{{Statusbar
statusbars = {}
for s = 1, screen.count() do
statusbars[s] = statusbar({
position = "bottom", name = "statusbar" .. s,
fg = fg['normal'], bg = bg['normal'],
height = mainBarHeight
})
---add widgets
local widgetlist = {
archicon,
taglist,
}
for index = 1, #launchboxen do
table.insert(widgetlist, launchboxen[index])
end
joinTables(widgetlist, {
noteo,
clockicon,
clocktext
})
statusbars[s]:widgets(widgetlist)
statusbars[s].screen = s
end
bottombar = statusbar ({position = "top", height = 10, name = "bottombar"})
bottombar:widgets({(widget({ type = "systray", name = "systray", align = "right" }))})
bottombar.screen = 1
---}}}
---{{{Keybindings
--AWESOME
keybinding({ modkey, "Control" }, "r", awesome.restart):add()
keybinding({ modkey, "Shift" }, "q", awesome.quit):add()
--TAG CONTROL
keynumber = 0
for s = 1, screen.count() do
keynumber = math.min(9, math.max(#tagsByNumber[s], keynumber));
end
for i = 1, keynumber do
keybinding({ modkey }, i,
function ()
local screen = mouse.screen
if tagsByNumber[screen][i] then
awful.tag.viewonly(tagsByNumber[screen][i])
end
end):add()
keybinding({ modkey, "Control" }, i,
function ()
local screen = mouse.screen
if tagsByNumber[screen][i] then
tagsByNumber[screen][i].selected = not tagsByNumber[screen][i].selected
end
end):add()
keybinding({ modkey, "Shift" }, i,
function ()
local screen = mouse.screen
if tagsByNumber[screen][i] then
awful.client.movetotag(tagsByNumber[screen][i])
end
end):add()
keybinding({ modkey, "Control", "Shift" }, i,
function ()
local screen = mouse.screen
if tagsByNumber[screen][i] then
awful.client.toggletag(tagsByNumber[screen][i])
end
end):add()
end
keybinding({ modkey }, "Left", awful.tag.viewprev):add()
keybinding({ modkey }, "Right", awful.tag.viewnext):add()
keybinding({ modkey }, "Up", tagBack):add()
--CLIENT MANIPULATION
keybinding({ modkey, "Control" }, "space", awful.client.togglefloating):add()
keybinding({ "Mod1" }, "F4", function () client.focus:kill() end):add()
--LAYOUT MANIPULATION
keybinding({ modkey }, "space", function () awful.layout.inc(layouts, 1) end):add()
keybinding({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end):add()
keybinding({ modkey }, "m", function() awful.tag.incnmaster(1) end):add()
keybinding({ modkey, "Shift" }, "m", function() awful.tag.incnmaster(-1) end):add()
---PROGRAM MANIPULATION
keybinding({ "Mod1" }, "grave", function () awful.spawn(menu) end):add()
keybinding({ modkey }, "grave", function ()
awful.tag.viewonly(tagsByName[mouse.screen]["terms"])
awful.spawn(terminal)
end):add()
keybinding({ "Mod4" }, "e", function () awful.spawn("exec dmenu") end):add()
keybinding({ "Mod4" }, "p", function () awful.spawn("exec mpc next") end):add()
keybinding({ "Mod4" }, "r", function () awful.spawn("exec urxvt") end):add()
keybinding({ "Mod4" }, "n", function () awful.spawn("exec mpc --format 'np: [[%artist%] - [%title%] - #[[%album%] ##[%track%]#]]|[%file%]' | head -n 1 | xclip") end):add()
---}}}
---{{{Hooks
--FOCUS HOOK
function hook_focus(c)
if not awful.client.ismarked(c) then
c.border_color = border['focus']
end
c.opacity = 1.0
end
--UNFOCUS HOOK
function hook_unfocus(c)
if not awful.client.ismarked(c) then
c.border_color = border['normal']
end
c.opacity = 1.0
end
--MARKED HOOK
function hook_marked(c)
c.border_color = border_marked
end
--UNMARKED HOOK
function hook_unmarked(c)
c.border_color = border_focus
end
--MOUSEOVER HOOK
function hook_mouseover(c)
-- Sloppy focus, but disabled for magnifier layout
if awful.layout.get(c.screen) ~= "magnifier" then
client.focus = c
end
end
--MANAGE HOOK
function hook_manage(c)
-- Add mouse bindings
c:mouse_add(mouse({ }, 1, function (c) client.focus = c; c:raise() end))
c:mouse_add(mouse({ modkey }, 1, function (c) c:mouse_move() end))
c:mouse_add(mouse({ modkey }, 3, function (c) c:mouse_resize() end))
-- Setup borders
c.border_width = 1
c.border_color = border['normal']
client.focus = c
-- Client rules
clientRules(c)
-- Honor size hints
c.honorsizehints = true
end
--ARRANGE HOOK
function hook_arrange(screen)
tag = awful.tag.selected(mouse.screen)
if currentTag ~= tag then
lastTag = currentTag
currentTag = tag
end
end
--SETUP HOOKS
awful.hooks.focus.register(hook_focus)
awful.hooks.unfocus.register(hook_unfocus)
awful.hooks.marked.register(hook_marked)
awful.hooks.unmarked.register(hook_unmarked)
awful.hooks.manage.register(hook_manage)
awful.hooks.mouseover.register(hook_mouseover)
awful.hooks.arrange.register(hook_arrange)
---}}}