Created
March 10, 2009 16:33
-
-
Save kdwinter/76971 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
------------------------------------------------------------------------------------- | |
--{{{ Imports | |
-- Load default libraries | |
require("awful") | |
require("beautiful") | |
-- Naughty | |
require("naughty") | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Initialize some stuff | |
tags = {} | |
statusbar = {} | |
promptbox = {} | |
taglist = {} | |
tasklist = {} | |
layoutbox = {} | |
globalKeys = {} | |
clientKeys = {} | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Variables | |
modMask = "Mod4" | |
-- Default apps | |
term = "urxvtc" | |
browser = "firefox" | |
fileManager = "thunar" | |
themePath = awful.util.getdir("config").."/themes/default" | |
beautiful.init(themePath) | |
-- The layouts we will use | |
layouts = | |
{ | |
awful.layout.suit.tile, | |
awful.layout.suit.tile.bottom, | |
awful.layout.suit.floating, | |
awful.layout.suit.fair.horizontal | |
} | |
-- Apps that should be forced floating | |
floatApps = { ["MPlayer"] = true | |
, ["Gimp"] = true | |
-- , ["Mirage"] = true | |
} | |
appTags = { ["Firefox"] = { screen = 1, tag = 2 } | |
, ["Gimp"] = { screen = 1, tag = 3 } | |
} | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ functions | |
function set_bg(bgcolor, text) | |
if text then | |
return '<span background="'..bgcolor..'">'..text..'</span>' | |
end | |
end | |
function set_fg(fgcolor, text) | |
if text then | |
return '<span color="'..fgcolor..'">'..text..'</span>' | |
end | |
end | |
function set_font(font, text) | |
if text then | |
return '<span font_desc="'..font..'">'..text..'</span>' | |
end | |
end | |
function loadavg() | |
local palette = | |
{ | |
"#888888", | |
"#999988", | |
"#AAAA88", | |
"#BBBB88", | |
"#CCCC88", | |
"#CCBB88", | |
"#CCAA88", | |
"#DD9988", | |
"#EE8888", | |
"#FF4444", | |
} | |
local loadavg = io.open('/proc/loadavg') | |
if loadavg then | |
local txt = loadavg:read('*all') | |
loadavg:close() | |
if type(txt) == 'string' then | |
local one, five, ten = txt:match("^([%d%.]+)%s+([%d%.]+)%s+([%d%.]+)%s+") | |
if type(one) == 'string' then | |
loadtext = string.format('%.2f %.2f %.2f', one, five, ten) | |
end | |
local current_avg = tonumber(one) | |
if type(current_avg) == "number" then | |
local index = math.min(math.floor(current_avg * (#palette-1)) + 1, #palette) | |
colors = palette[index] | |
end | |
end | |
end | |
loadwidget.text = spacer..set_fg(colors, loadtext)..spacer..set_fg('#4C4C4C', '|') | |
end | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Tags | |
for s = 1, screen.count() do | |
tags[s] = {} | |
for tagnumber = 1, 9 do | |
tags[s][tagnumber] = tag(tagnumber) | |
tags[s][tagnumber].screen = s | |
awful.layout.set(layouts[1], tags[s][tagnumber]) | |
end | |
-- Select at least one tag | |
tags[s][1].selected = true | |
end | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Menu | |
-- Submenu | |
awesomemenu = { { "Edit config" , term.." -e vim "..awful.util.getdir("config").."/rc.lua" } | |
, { "Restart" , awesome.restart } | |
, { "Quit" , awesome.quit } | |
} | |
-- Mainmenu | |
mainmenu = awful.menu.new({ items = { { "Terminal" , term } | |
, { "Firefox" , browser } | |
, { "Thunar" , fileManager } | |
, { "Gvim" , "gvim" } | |
, { "Gimp" , "gimp" } | |
, { "Screen" , term.." -e screen -RR" } | |
, { "Ncmpcpp" , term.." -e ncmpcpp" } | |
, { "Awesome" , awesomemenu } | |
} | |
}) | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Widgets | |
-- Please note the functions feeding some of the widgets are found in functions.lua | |
-- Simple spacer we can use to cleaner code | |
spacer = " " | |
-- Create the clock widget | |
clockwidget = widget({ type = "textbox", align = "right" }) | |
loadwidget = widget({ type = 'textbox', align = 'right' }) | |
loadavg() | |
-- Create a system tray | |
systray = widget({ type = "systray", align = "right" }) | |
-- Initialize which buttons do what when clicking the taglist | |
taglist.buttons = { button({ } , 1, awful.tag.viewonly) | |
, button({ modMask } , 1, awful.client.movetotag) | |
, button({ } , 3, function (tag) tag.selected = not tag.selected end) | |
, button({ modMask } , 3, awful.client.toggletag) | |
, button({ } , 4, awful.tag.viewnext) | |
, button({ } , 5, awful.tag.viewprev) | |
} | |
-- Initialize which buttons do what when clicking the tasklist | |
tasklist.buttons = { button({ } , 1, function (c) client.focus = c; c:raise() end) | |
, button({ } , 3, function () awful.menu.clients({ width=250 }) end) | |
, button({ } , 4, function () awful.client.focus.byidx(1) end) | |
, button({ } , 5, function () awful.client.focus.byidx(-1) end) | |
} | |
-- From here on, everything gets created for every screen | |
for s = 1, screen.count() do | |
-- Promptbox (pops up with mod+r) | |
promptbox[s] = widget({ type = "textbox", align = "left" }) | |
-- Layouticon for the current tag | |
layoutbox[s] = widget({ type = "imagebox", align = "left" }) | |
layoutbox[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 the taglist | |
taglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, taglist.buttons) | |
-- Create the tasklist | |
tasklist[s] = awful.widget.tasklist.new(function(c) | |
if c == client.focus then | |
return spacer..setFocusFg(c.name)..spacer | |
end | |
end, tasklist.buttons) | |
-- Finally, create the statusbar (called wibox), and set its properties | |
statusbar[s] = wibox({ position = "top" | |
, height = "16" | |
, fg = beautiful.fg_normal | |
, bg = beautiful.bg_normal | |
-- , border_color = beautiful.border_normal | |
-- , border_width = beautiful.border_width | |
}) | |
-- Add our widgets to the wibox | |
statusbar[s].widgets = { layoutbox[s] | |
, taglist[s] | |
, tasklist[s] | |
, promptbox[s] | |
, loadwidget | |
, clockwidget | |
, s == 1 and systray or nil | |
} | |
-- Add it to each screen | |
statusbar[s].screen = s | |
end | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Bindings | |
-- What happens when we click the desktop | |
root.buttons({ | |
button({ } , 3 , function () mainmenu:toggle() end), | |
button({ } , 4 , awful.tag.viewnext), | |
button({ } , 5 , awful.tag.viewprev) | |
}) | |
keynumber = 9 | |
for i = 1, keynumber do | |
table.insert(globalKeys, | |
key({ modMask }, i, | |
function () | |
local screen = mouse.screen | |
if tags[screen][i] then | |
awful.tag.viewonly(tags[screen][i]) | |
end | |
end)) | |
table.insert(globalKeys, | |
key({ modMask, "Control" }, i, | |
function () | |
local screen = mouse.screen | |
if tags[screen][i] then | |
tags[screen][i].selected = not tags[screen][i].selected | |
end | |
end)) | |
table.insert(globalKeys, | |
key({ modMask, "Shift" }, i, | |
function () | |
if client.focus and tags[client.focus.screen][i] then | |
awful.client.movetotag(tags[client.focus.screen][i]) | |
end | |
end)) | |
table.insert(globalKeys, | |
key({ modMask, "Control", "Shift" }, i, | |
function () | |
if client.focus and tags[client.focus.screen][i] then | |
awful.client.toggletag(tags[client.focus.screen][i]) | |
end | |
end)) | |
end | |
-- These should be straightforward... | |
table.insert(globalKeys, key({ modMask }, "o", awful.client.movetoscreen)) | |
table.insert(globalKeys, key({ modMask }, "s", function() awful.screen.focus(1) end)) | |
table.insert(globalKeys, key({ modMask } , "Left" , awful.tag.viewprev)) | |
table.insert(globalKeys, key({ modMask } , "Right" , awful.tag.viewnext)) | |
table.insert(globalKeys, key({ modMask } , "x" , function () awful.util.spawn(term) end)) | |
table.insert(globalKeys, key({ modMask } , "f" , function () awful.util.spawn(browser) end)) | |
table.insert(globalKeys, key({ modMask } , "t" , function () awful.util.spawn(fileManager) end)) | |
table.insert(globalKeys, key({ modMask, "Control" } , "r" , function () promptbox[mouse.screen].text = awful.util.escape(awful.util.restart()) end)) | |
table.insert(globalKeys, key({ modMask, "Shift" } , "q" , awesome.quit)) | |
table.insert(globalKeys, key({ modMask } , "m" , awful.client.maximize)) | |
table.insert(globalKeys, key({ modMask } , "c" , function () client.focus:kill() end)) | |
table.insert(globalKeys, key({ modMask } , "j" , function () awful.client.focus.byidx(1); client.focus:raise() end)) | |
table.insert(globalKeys, key({ modMask } , "k" , function () awful.client.focus.byidx(-1); client.focus:raise() end)) | |
table.insert(globalKeys, key({ modMask, "Control" } , "space" , awful.client.togglefloating)) | |
table.insert(globalKeys, key({ modMask, "Control" } , "Return" , function () client.focus:swap(awful.client.master()) end)) | |
table.insert(globalKeys, key({ modMask } , "Tab" , awful.client.focus.history.previous)) | |
table.insert(globalKeys, key({ modMask } , "u" , awful.client.urgent.jumpto)) | |
table.insert(globalKeys, key({ modMask, "Shift" } , "r" , function () client.focus:redraw() end)) | |
table.insert(globalKeys, key({ modMask } , "l" , function () awful.tag.incmwfact(0.025) end)) | |
table.insert(globalKeys, key({ modMask } , "h" , function () awful.tag.incmwfact(-0.025) end)) | |
table.insert(globalKeys, key({ modMask, "Shift" } , "h" , function () awful.tag.incnmaster(1) end)) | |
table.insert(globalKeys, key({ modMask, "Shift" } , "l" , function () awful.tag.incnmaster(-1) end)) | |
table.insert(globalKeys, key({ modMask, "Control" } , "h" , function () awful.tag.incncol(1) end)) | |
table.insert(globalKeys, key({ modMask, "Control" } , "l" , function () awful.tag.incncol(-1) end)) | |
table.insert(globalKeys, key({ modMask } , "space" , function () awful.layout.inc(layouts, 1) end)) | |
table.insert(globalKeys, key({ modMask, "Shift" } , "space" , function () awful.layout.inc(layouts, -1) end)) | |
table.insert(globalKeys, key({ modMask } , "r" , function () awful.prompt.run({ prompt = "Run: " }, promptbox[mouse.screen], awful.util.spawn, awful.completion.bash, awful.util.getdir("cache").."/history") end)) | |
table.insert(globalKeys, key({ } , "#160" , function () awful.util.spawn("dvol -t") end)) | |
table.insert(globalKeys, key({ } , "#174" , function () awful.util.spawn("dvol -d 2") end)) | |
table.insert(globalKeys, key({ } , "#176" , function () awful.util.spawn("dvol -i 2") end)) | |
table.insert(globalKeys, key({ } , "#162" , function () awful.util.spawn("mpc toggle") end)) | |
table.insert(globalKeys, key({ } , "#164" , function () awful.util.spawn("mpc stop") end)) | |
table.insert(globalKeys, key({ } , "#153" , function () awful.util.spawn("mpc next") end)) | |
table.insert(globalKeys, key({ } , "#144" , function () awful.util.spawn("mpc prev") end)) | |
table.insert(globalKeys, key({ } , "#159" , function () awful.util.spawn("urxvtc -e ncmpcpp") end)) | |
-- Set keys | |
root.keys(globalKeys) | |
--}}} | |
------------------------------------------------------------------------------------- | |
--{{{ Hooks | |
-- Gets executed when focusing a client | |
awful.hooks.focus.register(function (c) | |
if not awful.client.ismarked(c) then | |
c.border_color = beautiful.border_focus | |
end | |
end) | |
-- Gets executed when unfocusing a client | |
awful.hooks.unfocus.register(function (c) | |
if not awful.client.ismarked(c) then | |
c.border_color = beautiful.border_normal | |
end | |
end) | |
-- Gets executed when marking a client | |
awful.hooks.marked.register(function (c) | |
c.border_color = beautiful.border_marked | |
end) | |
-- Gets executed when unmarking a client | |
awful.hooks.unmarked.register(function (c) | |
c.border_color = beautiful.border_focus | |
end) | |
-- Gets executed when the mouse enters a client | |
awful.hooks.mouse_enter.register(function (c) | |
if awful.client.focus.filter(c) then | |
client.focus = c | |
end | |
end) | |
-- Gets executed when a new client appears | |
awful.hooks.manage.register(function (c) | |
if not startup and awful.client.focus.filter(c) then | |
c.screen = mouse.screen | |
end | |
-- Add mouse binds | |
c:buttons({ button({ } , 1 , function (c) client.focus = c; c:raise() end) | |
, button({ modMask } , 1 , awful.mouse.client.move) | |
, button({ modMask } , 3 , awful.mouse.client.resize) | |
}) | |
-- 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] then | |
c.floating = floatApps[cls] | |
elseif floatApps[inst] then | |
c.floating = 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 | |
client.focus = c | |
-- Prevent new clients from becoming master | |
awful.client.setslave(c) | |
-- Inogre size hints usually given out by terminals (prevent gaps between windows) | |
c.size_hints_honor = false | |
-- c.honorsizehints = false | |
end) | |
-- Gets exeucted when arranging the screen (as in, tag switch, new client, etc) | |
awful.hooks.arrange.register(function (screen) | |
-- Update the layoutbox image | |
local layout = awful.layout.getname(awful.layout.get(screen)) | |
if layout and beautiful["layout_"..layout] then | |
layoutbox[screen].image = image(beautiful["layout_"..layout]) | |
else | |
layoutbox[screen].image = nil | |
end | |
-- Give focus to the latest client in history if no window has focus | |
if not client.focus then | |
local c = awful.client.focus.history.get(screen, 0) | |
if c then client.focus = c end | |
end | |
end) | |
-- Timed hooks for the widget functions | |
-- 1 second | |
awful.hooks.timer.register(1, function () | |
clockwidget.text = ' '..os.date('%d/%m/%Y, %T')..' ' | |
end) | |
-- 20 seconds | |
awful.hooks.timer.register(20, function() | |
loadavg() | |
end) | |
--}}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment