2012-07-06 14:19:54 +02:00
|
|
|
-- Widgets
|
|
|
|
|
|
|
|
require("vicious")
|
2012-07-15 22:22:38 +02:00
|
|
|
local icons = loadrc("icons", "vbe/icons")
|
2012-07-06 14:19:54 +02:00
|
|
|
|
2012-07-29 16:36:31 +02:00
|
|
|
-- Separators
|
|
|
|
local sepopen = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
sepopen.image = image(beautiful.icons .. "/widgets/left.png")
|
2012-07-29 16:36:31 +02:00
|
|
|
local sepclose = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
sepclose.image = image(beautiful.icons .. "/widgets/right.png")
|
2012-07-29 16:36:31 +02:00
|
|
|
local spacer = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
spacer.image = image(beautiful.icons .. "/widgets/spacer.png")
|
2012-07-06 14:19:54 +02:00
|
|
|
|
|
|
|
-- Date
|
|
|
|
local datewidget = widget({ type = "textbox" })
|
2012-07-30 00:08:37 +02:00
|
|
|
local dateformat = "%H:%M"
|
|
|
|
if screen.count() > 1 then dateformat = "%a %d/%m, " .. dateformat end
|
2012-07-06 14:19:54 +02:00
|
|
|
vicious.register(datewidget, vicious.widgets.date,
|
2012-07-30 00:08:37 +02:00
|
|
|
'<span color="' .. beautiful.fg_widget_clock .. '">' ..
|
|
|
|
dateformat .. '</span>', 61)
|
2012-07-29 16:36:31 +02:00
|
|
|
local dateicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
dateicon.image = image(beautiful.icons .. "/widgets/clock.png")
|
2012-07-30 00:08:37 +02:00
|
|
|
local cal = (
|
|
|
|
function()
|
|
|
|
local calendar = nil
|
|
|
|
local offset = 0
|
|
|
|
|
|
|
|
local remove_calendar = function()
|
|
|
|
if calendar ~= nil then
|
|
|
|
naughty.destroy(calendar)
|
|
|
|
calendar = nil
|
|
|
|
offset = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local add_calendar = function(inc_offset)
|
|
|
|
local save_offset = offset
|
|
|
|
remove_calendar()
|
|
|
|
offset = save_offset + inc_offset
|
|
|
|
local datespec = os.date("*t")
|
|
|
|
datespec = datespec.year * 12 + datespec.month - 1 + offset
|
|
|
|
datespec = (datespec % 12 + 1) .. " " .. math.floor(datespec / 12)
|
|
|
|
local cal = awful.util.pread("ncal -w -m " .. datespec)
|
|
|
|
-- Highlight the current date and month
|
2012-08-01 10:28:30 +02:00
|
|
|
cal = cal:gsub("_.([%d ])",
|
2012-07-30 00:08:37 +02:00
|
|
|
string.format('<span color="%s">%%1</span>',
|
|
|
|
beautiful.fg_widget_clock))
|
|
|
|
cal = cal:gsub("^( +[^ ]+ [0-9]+) *",
|
|
|
|
string.format('<span color="%s">%%1</span>',
|
|
|
|
beautiful.fg_widget_clock))
|
|
|
|
-- Turn anything other than days in labels
|
2012-08-01 10:28:30 +02:00
|
|
|
cal = cal:gsub("(\n[^%d ]+)",
|
2012-07-30 00:08:37 +02:00
|
|
|
string.format('<span color="%s">%%1</span>',
|
|
|
|
beautiful.fg_widget_label))
|
|
|
|
cal = cal:gsub("([%d ]+)\n?$",
|
|
|
|
string.format('<span color="%s">%%1</span>',
|
|
|
|
beautiful.fg_widget_label))
|
|
|
|
calendar = naughty.notify(
|
|
|
|
{
|
|
|
|
text = string.format('<span font="%s">%s</span>',
|
|
|
|
"Terminus 8",
|
|
|
|
cal:gsub(" +\n","\n")),
|
|
|
|
timeout = 0, hover_timeout = 0.5,
|
|
|
|
width = 160,
|
2012-07-31 07:00:20 +02:00
|
|
|
screen = mouse.screen,
|
2012-07-30 00:08:37 +02:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
return { add = add_calendar,
|
|
|
|
rem = remove_calendar }
|
|
|
|
end)()
|
|
|
|
|
|
|
|
datewidget:add_signal("mouse::enter", function() cal.add(0) end)
|
|
|
|
datewidget:add_signal("mouse::leave", cal.rem)
|
|
|
|
datewidget:buttons(awful.util.table.join(
|
|
|
|
awful.button({ }, 3, function() cal.add(-1) end),
|
|
|
|
awful.button({ }, 1, function() cal.add(1) end)))
|
2012-07-06 14:19:54 +02:00
|
|
|
|
|
|
|
-- CPU usage
|
|
|
|
local cpuwidget = widget({ type = "textbox" })
|
2012-07-07 09:18:09 +02:00
|
|
|
vicious.register(cpuwidget, vicious.widgets.cpu,
|
2012-07-06 14:19:54 +02:00
|
|
|
function (widget, args)
|
2012-07-29 16:36:31 +02:00
|
|
|
return string.format('<span color="' .. beautiful.fg_widget_value .. '">%2d%%</span>',
|
2012-07-07 09:18:09 +02:00
|
|
|
args[1])
|
2012-07-29 20:10:13 +02:00
|
|
|
end, 7)
|
2012-07-29 16:36:31 +02:00
|
|
|
local cpuicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
cpuicon.image = image(beautiful.icons .. "/widgets/cpu.png")
|
2012-07-06 14:19:54 +02:00
|
|
|
|
|
|
|
-- Battery
|
2012-07-10 22:40:57 +02:00
|
|
|
local batwidget = { widget = "" }
|
2012-07-06 14:19:54 +02:00
|
|
|
if config.hostname == "guybrush" then
|
2012-07-10 22:40:57 +02:00
|
|
|
batwidget.widget = widget({ type = "textbox" })
|
|
|
|
vicious.register(batwidget.widget, vicious.widgets.bat,
|
2012-07-07 15:17:00 +02:00
|
|
|
function (widget, args)
|
|
|
|
local color = beautiful.fg_widget_value
|
|
|
|
local current = args[2]
|
2012-07-10 22:12:00 +02:00
|
|
|
if current < 10 and args[1] == "-" then
|
2012-07-07 15:17:00 +02:00
|
|
|
color = beautiful.fg_widget_value_important
|
2012-07-10 22:12:00 +02:00
|
|
|
-- Maybe we want to display a small warning?
|
2012-07-10 22:40:57 +02:00
|
|
|
if current ~= batwidget.lastwarn then
|
|
|
|
batwidget.lastid = naughty.notify(
|
|
|
|
{ title = "Battery low!",
|
|
|
|
preset = naughty.config.presets.critical,
|
2012-07-25 18:31:31 +02:00
|
|
|
timeout = 20,
|
2012-07-10 22:40:57 +02:00
|
|
|
text = "Battery level is currently " ..
|
|
|
|
current .. "%.\n" .. args[3] ..
|
|
|
|
" left before running out of power.",
|
2012-07-15 22:22:38 +02:00
|
|
|
icon = icons.lookup({name = "battery-caution",
|
|
|
|
type = "status"}),
|
2012-07-10 22:40:57 +02:00
|
|
|
replaces_id = batwidget.lastid }).id
|
|
|
|
batwidget.lastwarn = current
|
2012-07-10 22:12:00 +02:00
|
|
|
end
|
2012-07-07 15:17:00 +02:00
|
|
|
end
|
2012-07-29 17:33:46 +02:00
|
|
|
return string.format('<span color="' .. color ..
|
|
|
|
'">%s%d%%</span>', args[1], current)
|
2012-07-07 15:17:00 +02:00
|
|
|
end,
|
2012-07-29 20:10:13 +02:00
|
|
|
59, "BAT1")
|
2012-07-06 14:19:54 +02:00
|
|
|
end
|
2012-07-29 16:59:33 +02:00
|
|
|
local baticon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
baticon.image = image(beautiful.icons .. "/widgets/bat.png")
|
2012-07-06 14:19:54 +02:00
|
|
|
|
2012-07-07 20:17:47 +02:00
|
|
|
-- Network
|
2012-07-29 16:36:31 +02:00
|
|
|
local netup = widget({ type = "textbox" })
|
|
|
|
local netdown = widget({ type = "textbox" })
|
|
|
|
local netupicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
netupicon.image = image(beautiful.icons .. "/widgets/up.png")
|
2012-07-29 16:36:31 +02:00
|
|
|
local netdownicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
netdownicon.image = image(beautiful.icons .. "/widgets/down.png")
|
2012-07-29 16:36:31 +02:00
|
|
|
|
2012-07-07 20:17:47 +02:00
|
|
|
local netgraph = awful.widget.graph()
|
2012-07-29 16:36:31 +02:00
|
|
|
netgraph:set_width(80):set_height(16)
|
2012-07-07 20:17:47 +02:00
|
|
|
netgraph:set_stack(true):set_scale(true)
|
|
|
|
netgraph:set_border_color(beautiful.fg_widget_border)
|
2012-07-29 16:43:04 +02:00
|
|
|
netgraph:set_stack_colors({ "#EF8171", "#cfefb3" })
|
|
|
|
netgraph:set_background_color("#00000033")
|
2012-07-29 16:36:31 +02:00
|
|
|
vicious.register(netup, vicious.widgets.net,
|
2012-07-07 20:17:47 +02:00
|
|
|
function (widget, args)
|
|
|
|
-- We sum up/down value for all interfaces
|
|
|
|
local up = 0
|
|
|
|
local down = 0
|
|
|
|
local iface
|
|
|
|
for name, value in pairs(args) do
|
|
|
|
iface = name:match("^{(%S+) down_b}$")
|
|
|
|
if iface and iface ~= "lo" then down = down + value end
|
|
|
|
iface = name:match("^{(%S+) up_b}$")
|
|
|
|
if iface and iface ~= "lo" then up = up + value end
|
|
|
|
end
|
|
|
|
-- Update the graph
|
|
|
|
netgraph:add_value(up, 1)
|
|
|
|
netgraph:add_value(down, 2)
|
|
|
|
-- Format the string representation
|
|
|
|
local format = function(val)
|
|
|
|
if val > 500000 then
|
|
|
|
return string.format("%.1f MB", val/1000000.)
|
|
|
|
elseif val > 500 then
|
|
|
|
return string.format("%.1f KB", val/1000.)
|
|
|
|
end
|
|
|
|
return string.format("%d B", val)
|
|
|
|
end
|
2012-07-29 16:36:31 +02:00
|
|
|
-- Down
|
|
|
|
netdown.text = string.format('<span color="' .. beautiful.fg_widget_value ..
|
|
|
|
'">%08s</span>', format(down))
|
|
|
|
-- Up
|
|
|
|
return string.format('<span color="' .. beautiful.fg_widget_value ..
|
|
|
|
'">%08s</span>', format(up))
|
2012-07-07 20:17:47 +02:00
|
|
|
end, 3)
|
|
|
|
|
2012-07-06 14:19:54 +02:00
|
|
|
-- Memory usage
|
|
|
|
local memwidget = widget({ type = "textbox" })
|
|
|
|
vicious.register(memwidget, vicious.widgets.mem,
|
2012-07-29 16:36:31 +02:00
|
|
|
'<span color="' .. beautiful.fg_widget_value .. '">$1%</span>',
|
2012-07-29 20:10:13 +02:00
|
|
|
19)
|
2012-07-29 16:36:31 +02:00
|
|
|
local memicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
memicon.image = image(beautiful.icons .. "/widgets/mem.png")
|
2012-07-06 14:19:54 +02:00
|
|
|
|
|
|
|
-- Volume level
|
2012-07-29 16:36:31 +02:00
|
|
|
local volicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
volicon.image = image(beautiful.icons .. "/widgets/vol.png")
|
2012-07-06 14:19:54 +02:00
|
|
|
local volwidget = widget({ type = "textbox" })
|
|
|
|
vicious.register(volwidget, vicious.widgets.volume,
|
2012-07-29 15:43:22 +02:00
|
|
|
'<span color="' .. beautiful.fg_widget_value .. '">$2 $1%</span>',
|
2012-07-29 20:10:13 +02:00
|
|
|
17, "Master")
|
2012-07-14 16:37:32 +02:00
|
|
|
volume = loadrc("volume", "vbe/volume")
|
2012-07-06 14:19:54 +02:00
|
|
|
volwidget:buttons(awful.util.table.join(
|
2012-07-14 16:29:19 +02:00
|
|
|
awful.button({ }, 1, volume.mixer),
|
|
|
|
awful.button({ }, 3, volume.toggle),
|
|
|
|
awful.button({ }, 4, volume.increase),
|
|
|
|
awful.button({ }, 5, volume.decrease)))
|
2012-07-06 14:19:54 +02:00
|
|
|
|
2012-07-07 10:23:53 +02:00
|
|
|
-- File systems
|
2012-12-13 08:29:33 +01:00
|
|
|
local fs = { "/",
|
|
|
|
"/home",
|
|
|
|
"/var",
|
|
|
|
"/usr",
|
|
|
|
"/tmp",
|
|
|
|
"/var/cache/build",
|
|
|
|
"/var/lib/mongodb",
|
|
|
|
"/var/lib/systems" }
|
2012-07-29 16:36:31 +02:00
|
|
|
local fsicon = widget({ type = "imagebox" })
|
2012-07-31 07:03:22 +02:00
|
|
|
fsicon.image = image(beautiful.icons .. "/widgets/disk.png")
|
2012-07-07 10:23:53 +02:00
|
|
|
local fswidget = widget({ type = "textbox" })
|
|
|
|
vicious.register(fswidget, vicious.widgets.fs,
|
|
|
|
function (widget, args)
|
|
|
|
local result = ""
|
2012-12-13 08:29:33 +01:00
|
|
|
for _, path in pairs(fs) do
|
2012-07-07 10:23:53 +02:00
|
|
|
local used = args["{" .. path .. " used_p}"]
|
|
|
|
local color = beautiful.fg_widget_value
|
|
|
|
if used then
|
|
|
|
if used > 90 then
|
|
|
|
color = beautiful.fg_widget_value_important
|
|
|
|
end
|
2012-12-13 08:29:33 +01:00
|
|
|
local name = string.gsub(path, "[%w/]*/(%w+)", "%1")
|
|
|
|
if name == "/" then name = "root" end
|
2012-07-07 10:23:53 +02:00
|
|
|
result = string.format(
|
2012-07-29 15:43:22 +02:00
|
|
|
'%s%s<span color="' .. beautiful.fg_widget_label .. '">%s: </span>' ..
|
|
|
|
'<span color="' .. color .. '">%2d%%</span>',
|
2012-07-29 16:36:31 +02:00
|
|
|
result, #result > 0 and " " or "", name, used)
|
2012-07-07 10:23:53 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return result
|
2012-07-29 20:10:13 +02:00
|
|
|
end, 53)
|
2012-07-07 10:23:53 +02:00
|
|
|
|
2012-07-06 14:19:54 +02:00
|
|
|
local systray = widget({ type = "systray" })
|
|
|
|
|
2012-07-07 09:18:09 +02:00
|
|
|
-- Wibox initialisation
|
2012-07-06 14:19:54 +02:00
|
|
|
local wibox = {}
|
|
|
|
local promptbox = {}
|
|
|
|
local layoutbox = {}
|
|
|
|
|
|
|
|
local taglist = {}
|
|
|
|
local tasklist = {}
|
|
|
|
tasklist.buttons = awful.util.table.join(
|
|
|
|
awful.button({ }, 1, function (c)
|
|
|
|
if c == client.focus then
|
|
|
|
c.minimized = true
|
|
|
|
else
|
|
|
|
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))
|
|
|
|
|
|
|
|
for s = 1, screen.count() do
|
|
|
|
promptbox[s] = awful.widget.prompt({ layout = awful.widget.layout.horizontal.leftright })
|
|
|
|
layoutbox[s] = awful.widget.layoutbox(s)
|
2012-07-09 22:31:31 +02:00
|
|
|
tasklist[s] = awful.widget.tasklist(
|
|
|
|
function(c)
|
2012-07-29 20:41:58 +02:00
|
|
|
local title, color, _, icon = awful.widget.tasklist.label.currenttags(c, s)
|
|
|
|
return title, color, nil, icon
|
2012-07-09 22:31:31 +02:00
|
|
|
end, tasklist.buttons)
|
|
|
|
|
2012-07-06 14:19:54 +02:00
|
|
|
-- Create the taglist
|
2012-09-08 22:47:35 +02:00
|
|
|
taglist[s] = awful.widget.taglist.new(s,
|
|
|
|
awful.widget.taglist.label.all)
|
2012-07-06 14:19:54 +02:00
|
|
|
-- Create the wibox
|
|
|
|
wibox[s] = awful.wibox({ screen = s,
|
|
|
|
fg = beautiful.fg_normal,
|
|
|
|
bg = beautiful.bg_widget,
|
|
|
|
position = "top",
|
2012-07-29 16:36:31 +02:00
|
|
|
height = 16,
|
2012-07-06 14:19:54 +02:00
|
|
|
})
|
|
|
|
-- Add widgets to the wibox
|
2012-07-07 11:13:47 +02:00
|
|
|
local on = function(n, what)
|
|
|
|
if s == n or n > screen.count() then return what end
|
2012-07-07 10:21:40 +02:00
|
|
|
return ""
|
2012-07-06 14:19:54 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
wibox[s].widgets = {
|
|
|
|
{
|
2012-07-29 22:40:29 +02:00
|
|
|
screen.count() > 1 and sepopen or "",
|
2012-07-29 16:36:31 +02:00
|
|
|
taglist[s],
|
2012-07-29 22:40:29 +02:00
|
|
|
screen.count() > 1 and spacer or "",
|
|
|
|
layoutbox[s],
|
|
|
|
screen.count() > 1 and sepclose or "",
|
2012-07-29 16:36:31 +02:00
|
|
|
promptbox[s],
|
2012-07-06 14:19:54 +02:00
|
|
|
layout = awful.widget.layout.horizontal.leftright
|
|
|
|
},
|
2012-07-29 16:36:31 +02:00
|
|
|
on(1, systray),
|
2012-07-29 20:41:58 +02:00
|
|
|
sepclose, datewidget, screen.count() > 1 and dateicon or "", spacer,
|
2012-08-15 13:46:40 +02:00
|
|
|
on(2, volwidget), screen.count() > 1 and on(2, volicon) or "", on(2, spacer),
|
2012-07-29 20:41:58 +02:00
|
|
|
|
|
|
|
on(2, batwidget.widget),
|
2012-08-15 13:46:40 +02:00
|
|
|
on(2, batwidget.widget ~= "" and baticon or ""),
|
2012-07-29 20:41:58 +02:00
|
|
|
on(2, batwidget.widget ~= "" and spacer or ""),
|
|
|
|
|
|
|
|
on(2, fswidget), screen.count() > 1 and on(2, fsicon) or "",
|
|
|
|
screen.count() > 1 and on(2, sepopen) or on(2, spacer),
|
|
|
|
|
|
|
|
screen.count() > 1 and on(1, netgraph.widget) or "",
|
|
|
|
on(1, netdownicon), on(1, netdown),
|
|
|
|
on(1, netupicon), on(1, netup), on(1, spacer),
|
|
|
|
|
2012-07-29 16:36:31 +02:00
|
|
|
on(1, memwidget), on(1, memicon), on(1, spacer),
|
|
|
|
on(1, cpuwidget), on(1, cpuicon), on(1, sepopen),
|
|
|
|
tasklist[s],
|
2012-07-06 14:19:54 +02:00
|
|
|
layout = awful.widget.layout.horizontal.rightleft }
|
|
|
|
end
|
|
|
|
|
|
|
|
config.keys.global = awful.util.table.join(
|
|
|
|
config.keys.global,
|
2012-07-14 21:21:52 +02:00
|
|
|
awful.key({ modkey }, "r", function () promptbox[mouse.screen]:run() end,
|
|
|
|
"Prompt for a command"))
|
2012-09-08 22:47:35 +02:00
|
|
|
|
|
|
|
config.taglist = taglist
|