Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Standard awesome library
- require("awful")
- -- Theme handling library
- require("beautiful")
- -- Notification library
- require("naughty")
- -- Wicked widgets library
- require("wicked")
- awful.util.spawn("wmname LG3D") -- fool Java apps into working :)
- ---------------
- -- Variables --
- ---------------
- theme_path = "/home/baddog/.config/awesome/themes/default/theme.lua"
- icon_dir = "/home/baddog/.config/awesome/icons/"
- beautiful.init(theme_path)
- terminal = "urxvt"
- editor = os.getenv("EDITOR") or "vim"
- editor_cmd = terminal .. " -e " .. editor
- modkey = "Mod4"
- 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
- }
- floatapps =
- {
- ["Browser"] = true, -- firefox dialog windows
- ["Sonata"]= true,
- ["Dragon"] = true,
- ["MPlayer"] = true,
- ["VLC media player"] = true,
- ["gimp"] = true,
- ["pidgin"] = true
- }
- apptags =
- {
- -- ["Firefox"] = { screen = 1, tag = 2 },
- -- ["mocp"] = { screen = 2, tag = 4 },
- }
- use_titlebar = true
- ----------
- -- Tags --
- ----------
- tags = {}
- for s = 1, screen.count() do
- -- Each screen has its own tag table.
- tags[s] = {}
- -- Create 9 tags per screen.
- for tagnumber = 1, 9 do
- tags[s][tagnumber] = tag(tagnumber)
- -- Add tags to screen one by one
- tags[s][tagnumber].screen = s
- awful.layout.set(layouts[1], tags[s][tagnumber])
- end
- -- I'm sure you want to see at least one tag.
- tags[s][1].selected = true
- end
- ---------------
- -- Functions --
- ---------------
- function title(t)
- return '<span color="white"><b>'..t..': </b></span>'
- end
- function alert(a)
- return '<span color="orange"><b>'..a..'</b></span>'
- end
- function color(str, color)
- return '<span color="'..color..'">'..str..'</span>'
- end
- function dec2hex(s)
- s = string.format("%02x", s)
- return s
- end
- function gradient(min, max, val)
- val = tonumber(val)
- if (val > max) then val = max end
- if (val < min) then val = min end
- local v = val - min
- local d = (max - min) * 0.45
- local r, g
- if (v <= d) then
- r = 255 * math.pow(v / d, 0.7)
- g = 255
- else
- r = 255
- g = 255 - (255 * math.pow((v-d) / ((max - min)-d), 0.7))
- end
- return "#"..dec2hex(tostring(r))..dec2hex(tostring(g)).."00"
- end
- function cputemp(core)
- local command = "sensors | grep 'Core "..tostring(core).."'"
- local cpu = io.popen(command):read("*all")
- if (cpu == nil) then
- return ''
- end
- local pos = cpu:find('+')+1
- cpu = string.sub(cpu, pos, pos+3)
- return cpu
- end
- function log(var)
- local log = io.open("/home/scott/.awesome_log", "a")
- log:write(os.date("%c\t")..tostring(var).."\n")
- log:close()
- end
- -- For the volume widget/keybindings
- cardid = 0
- channel = "Master"
- 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("%d", volume)
- local val = tonumber(volume)
- status = string.match(status, "%[(o[^%]]*)%]")
- if string.find(status, "on", 1, true) then
- volume = volume .. "%"
- else
- volume = volume .. "M"
- end
- widget.text = title("VOL")..color(string.gsub(volume, ' ', ''), gradient(0, 100, val))
- 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)
- else
- io.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")
- volume("update", widget)
- end
- end
- -- For MPD widget/keybindings
- mpd_host = 'localhost' -- unused
- mpd_port = 6600 -- unused
- function mpd (mode, widget, image_widget)
- if mode == "update" then
- local fd = io.popen("mpc")
- local status = fd:read("*all")
- fd:close()
- if status:find("Connection refused") then
- widget.text = "Not running"
- image_widget.image = nil
- elseif status:find("playing") then
- current_song = status:match("[^\n]*") -- gets the first line
- widget.text = " "..awful.util.escape(current_song)
- image_widget.image = image(icon_dir.."robs/play.png")
- elseif status:find("paused") then
- current_song = status:match("[^\n]*") -- gets the first line
- widget.text = " "..awful.util.escape(current_song)
- image_widget.image = image(icon_dir.."robs/pause.png")
- else -- stopped
- widget.text = "Stopped"
- image_widget.image = nil
- end
- elseif mode == "toggle" then
- io.popen("mpc toggle")
- mpd("update", widget, image_widget)
- elseif mode == "stop" then
- io.popen("mpc stop")
- mpd("update", widget, image_widget)
- elseif mode == "next" then
- io.popen("mpc next")
- mpd("update", widget, image_widget)
- elseif mode == "prev" then
- io.popen("mpc prev")
- mpd("update", widget, image_widget)
- end
- end
- function amarok_dbus (method)
- return io.popen("qdbus org.kde.amarok /Player " .. method)
- end
- function amarok (mode, widget)
- if mode == "toggle" then
- amarok_dbus("Pause")
- elseif mode == "stop" then
- amarok_dbus("Stop")
- elseif mode == "next" then
- amarok_dbus("Next")
- elseif mode == "prev" then
- amarok_dbus("Prev")
- end
- local fd = io.popen("ruby /data/Code/Ruby/amarok2-np.rb -- --no-time")
- local status = fd:read("*all")
- fd:close()
- if status:match("^$") then
- widget.text = "Stopped"
- else
- widget.text = awful.util.escape(status:match("[^\n]*"))
- end
- end
- -------------
- -- Widgets --
- -------------
- -- Menu
- awesomemenu = {
- { "manual", terminal .. " -e man awesome" },
- { "edit config", editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua" },
- { "restart", awesome.restart },
- { "quit", awesome.quit }
- }
- mainmenu = awful.menu.new({ items = {
- { "open terminal", terminal },
- { "awesome", awesomemenu, beautiful.awesome_icon }
- }})
- menulauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),
- menu = mainmenu })
- -- Layout Box
- layoutbox = widget({ type = "imagebox", align = "right" })
- layoutbox: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) })
- -- Tag List
- taglist = awful.widget.taglist.new(1, awful.widget.taglist.label.all,
- { 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({ }, 4, awful.tag.viewnext),
- button({ }, 5, awful.tag.viewprev) })
- -- Prompt Box
- promptbox = widget({ type = "textbox", align = "left" })
- -- Status Monitors
- -- Volume
- tb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })
- 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)
- })
- volume("update", tb_volume)
- -- RAM Usage
- memwidget = widget({
- type = 'textbox',
- name = 'memwidget',
- align = 'right'
- })
- wicked.register(memwidget, wicked.widgets.mem, title("MEM")..'$2MB/$3MB')
- -- Net Usage
- nettitle = widget({ type = "textbox", name = "titlebox", align = "right" })
- -- I remove the space from the title because the image after it provides enough space
- nettitle.text = string.gsub(title("NET"), ': ', ':')
- netupiconbox = widget({ type = "imagebox", name = "netupiconbox", align = "right" })
- netupiconbox.image = image(icon_dir..'up.png')
- netupwidget = widget({
- type = 'textbox',
- name = 'netupwidget',
- align = 'right'
- })
- wicked.register(netupwidget, wicked.widgets.net, '${eth0 up_kb} KB', 1, nil, 3)
- netdowniconbox = widget({ type = "imagebox", name = "netdowniconbox", align = "right" })
- netdowniconbox.image = image(icon_dir..'down.png')
- netdownwidget = widget({
- type = 'textbox',
- name = 'netdownwidget',
- align = 'right'
- })
- wicked.register(netdownwidget, wicked.widgets.net, '${eth0 down_kb} KB', 1, nil, 3)
- -- CPU Usage
- cputextwidget = widget({
- type = 'textbox',
- name = 'cputextwidget',
- align = 'right'
- })
- wicked.register(cputextwidget, wicked.widgets.cpu, function(widget, args)
- cpuinfo = title("CPU")
- cpuinfo = color(cpuinfo..'['..args[2]..'%] ', gradient(0, 100, args[2]))
- cpuinfo = color(cpuinfo..'['..args[3]..'%] ', gradient(0, 100, args[3]))
- return cpuinfo
- end, 1, nil, 2)
- -- cpu graph
- cpugraphwidget = widget({
- type = 'graph',
- name = 'cpugraphwidget',
- align = 'right'
- })
- cpugraphwidget.height = 0.8
- cpugraphwidget.width = 60
- cpugraphwidget.bg = beautiful.bg_normal
- cpugraphwidget.border_color = beautiful.fg_normal
- cpugraphwidget.grow = 'left'
- cpugraphwidget:plot_properties_set('cpu', {
- fg = fg_normal,
- fg_center = beautiful.border_focus,
- fg_end = beautiful.border_normal,
- vertical_gradient = false
- })
- wicked.register(cpugraphwidget, wicked.widgets.cpu, '$1', 1, 'cpu')
- -- Load Average
- loadwidget = widget({
- type = 'textbox',
- name = 'loadwidget',
- align = 'right'
- })
- wicked.register(loadwidget, 'function', function (widget, args)
- -- Use /proc/loadavg to get the average system load on 1, 5 and 15 minute intervals
- local f = io.open('/proc/loadavg')
- local n = f:read()
- f:close()
- -- Find the third space
- local pos = n:find(' ', n:find(' ', n:find(' ')+1)+1)
- return title('LOAD')..n:sub(1,pos-1)
- end, 2)
- -- Filesystems
- fswidget = widget({
- type = 'textbox',
- name = 'fswidget',
- align = 'right'
- })
- wicked.register(fswidget, wicked.widgets.fs,
- title("FS")..color('/ [${/ used}|${/ size}]', "green")..color(' /data [${/data used}|${/data size}]',"yellow"),
- 10)
- -- MPD
- mpd_title = widget({ type = "textbox", align = "right" })
- mpd_title.text = title("MPD")
- mpd_image = widget({ type = "imagebox", align = "right" })
- mpd_text = widget({ type = "textbox", align = "right" })
- mpd("update", mpd_text, mpd_image)
- -- Amarok
- amarok_title = widget({ type = "textbox", align = "right" })
- amarok_title.text = title("MUSIC")
- amarok_text = widget({ type = "textbox", align = "right" })
- -- amarok("update", amarok_text)
- -- Clock
- clock = widget({ type = "textbox", align = "right" })
- wicked.register(clock, wicked.widgets.date, '%a %b %d, %H:%M')
- -- System Tray
- systray = widget({ type = "systray", align = "right" })
- -- Spacer
- spacer = widget({ type = "imagebox", name = "spacer", align = "right" })
- spacer.image = image(icon_dir..'spacer.png')
- -- create the wibox and assign widgets - only on screen one, at the bottom
- bottom_wibox = wibox({ position = "bottom", fg = beautiful.fg_normal,
- bg = beautiful.bg_normal })
- bottom_wibox.widgets =
- {
- menulauncher,
- taglist,
- promptbox,
- ----------
- mpd_title, mpd_image, mpd_text, spacer,
- -- amarok_title, amarok_text, spacer,
- --fswidget, spacer,
- nettitle,
- netupiconbox, netupwidget,
- netdowniconbox, netdownwidget, spacer,
- cputextwidget, cpugraphwidget, spacer,
- memwidget, spacer,
- tb_volume, spacer,
- clock, spacer,
- systray,
- loadaverage,
- layoutbox
- }
- bottom_wibox.screen = 1
- -- Task Lists - one per screen, at the top
- top_wibox = {}
- tasklist = {}
- for s=1, screen.count() do
- tasklist[s] = awful.widget.tasklist.new(
- function(c)
- return awful.widget.tasklist.label.currenttags(c, s)
- end,
- { button({ }, s,
- function (c)
- if not c:isvisible() then
- awful.tag.viewonly(c:tags()[s])
- end
- client.focus = c
- c:raise()
- end),
- button({ }, 3,
- function ()
- if instance then instance:hide() end
- instance = awful.menu.clients({ width=250 })
- 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)
- })
- top_wibox[s] = wibox({ position = "top", fg = beautiful.fg_normal,
- bg = beautiful.bg_normal })
- top_wibox[s].widgets = { tasklist[s] }
- top_wibox[s].screen = s
- end
- --------------------
- -- Mouse Bindings --
- --------------------
- root.buttons({
- button({ }, 3, function () mainmenu:toggle() end),
- button({ }, 4, awful.tag.viewnext),
- button({ }, 5, awful.tag.viewprev)
- })
- ------------------
- -- Key Bindings --
- ------------------
- globalkeys =
- {
- key({ modkey, }, "Left", awful.tag.viewprev ),
- key({ modkey, }, "Right", awful.tag.viewnext ),
- key({ modkey, }, "Escape", awful.tag.history.restore),
- 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),
- -- 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, }, "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 }, "F1",
- function ()
- awful.prompt.run({ prompt = "Run: " },
- promptbox,
- awful.util.spawn, awful.completion.bash,
- awful.util.getdir("cache") .. "/history")
- end),
- key({ modkey }, "F4",
- function ()
- awful.prompt.run({ prompt = "Run Lua code: " },
- promptbox,
- awful.util.eval, awful.prompt.bash,
- 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, "Shift" }, "c", 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),
- }
- -- Tag keybindings
- -- Compute the maximum number of digit we need, limited to 9
- keynumber = 0
- for s = 1, screen.count() do
- keynumber = math.min(9, math.max(#tags[s], keynumber));
- end
- for i = 1, keynumber do
- table.insert(globalkeys,
- key({ modkey }, i,
- function ()
- local screen = mouse.screen
- if tags[screen][i] then
- awful.tag.viewonly(tags[screen][i])
- end
- end))
- table.insert(globalkeys,
- key({ modkey, "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({ modkey, "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({ modkey, "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
- for i = 1, keynumber do
- table.insert(globalkeys, key({ modkey, "Shift" }, "F" .. i,
- function ()
- local screen = mouse.screen
- if tags[screen][i] then
- for k, c in pairs(awful.client.getmarked()) do
- awful.client.movetotag(tags[screen][i], c)
- end
- end
- end))
- end
- -- Volume keybidings
- table.insert(globalkeys, key({ }, "XF86AudioRaiseVolume", function () volume("up", tb_volume) end))
- table.insert(globalkeys, key({ }, "XF86AudioLowerVolume", function () volume("down", tb_volume) end))
- table.insert(globalkeys, key({ }, "XF86AudioMute", function () volume("mute", tb_volume) end))
- -- MPD keybindings
- table.insert(globalkeys, key({ }, "XF86AudioPlay", function () mpd("toggle", mpd_text, mpd_image) end))
- table.insert(globalkeys, key({ }, "XF86AudioStop", function () mpd("stop", mpd_text, mpd_image) end))
- table.insert(globalkeys, key({ }, "XF86AudioNext", function () mpd("next", mpd_text, mpd_image) end))
- table.insert(globalkeys, key({ }, "XF86AudioPrev", function () mpd("prev", mpd_text, mpd_image) end))
- -- Amarok keybindings
- -- table.insert(globalkeys, key({ }, "XF86AudioPlay", function () amarok("toggle", amarok_text) end))
- -- table.insert(globalkeys, key({ }, "XF86AudioStop", function () amarok("stop", amarok_text) end))
- -- table.insert(globalkeys, key({ }, "XF86AudioNext", function () amarok("next", amarok_text) end))
- -- table.insert(globalkeys, key({ }, "XF86AudioPrev", function () amarok("prev", amarok_text) 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
- 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
- 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)
- -- Hook function to execute when a new client appears.
- 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({
- button({ }, 1, function (c) client.focus = c; c:raise() end),
- button({ modkey }, 1, awful.mouse.client.move),
- button({ modkey }, 3, awful.mouse.client.resize)
- })
- -- 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] then
- awful.client.floating.set(c, floatapps[cls])
- elseif floatapps[inst] 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
- layoutbox.image = image(beautiful["layout_" .. layout])
- else
- layoutbox.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)
- -- Widget Hooks
- -- volume widget hook
- awful.hooks.timer.register(1, function () volume("update", tb_volume) end)
- -- MPD widget hook
- awful.hooks.timer.register(1, function () mpd("update", mpd_text, mpd_image) end)
- -- Amarok widget hook
- -- awful.hooks.timer.register(1, function () amarok("update", amarok_text) end)
Add Comment
Please, Sign In to add comment