1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
------------------------------------
-- Author: Marco Candrian --
-- Copyright 2009 Marco Candrian --
------------------------------------
local io = io
local pairs = pairs
local print = print
local setmetatable = setmetatable
local tonumber = tonumber
local type = type
local os = {
date = os.date,
getenv = os.getenv
}
local capi = {
widget = widget,
mouse = mouse,
screen = screen
}
local awful = require("awful")
local beautiful = require("beautiful")
local naughty = require("naughty")
local lib = {
hooks = require("obvious.lib.hooks"),
markup = require("obvious.lib.markup")
}
module("obvious.loadavg")
local initialized = false
local defaults = { }
defaults.shorttimer = 5 -- loadavg won't change faster it seems anyway
defaults.longtimer = 60
defaults.prefix = ""
defaults.suffix = ""
defaults.command = "xterm -e top"
local settings = { }
for key, value in pairs(defaults) do
settings[key] = value
end
local widget = capi.widget({
type = "textbox",
name = "loadavg",
align = "right"
})
widget:buttons(awful.util.table.join(
awful.button({ }, 1, function ()
awful.util.spawn(settings.command)
end)
))
-- update interval
function set_shorttimer(e)
settings.shorttimer = e or defaults.shorttimer
end
-- command to issue on Button1 click
function set_command(e)
settings.command = e or defaults.command
end
-- prefix to the data - e.g. using pango 'text markup language'
function set_prefix(e)
settings.prefix = e or defaults.prefix
end
-- suffix to the data
function set_suffix(e)
settings.suffix = e or defaults.suffix
end
local function update ()
local f = io.open("/proc/loadavg")
local loadavg
loadavg = f:read(14)
f:close()
widget.text = settings.prefix .. loadavg .. settings.suffix
end
setmetatable(_M, { __call = function ()
update()
if not initialized then
lib.hooks.timer.register(settings.shorttimer, settings.longtimer, update)
lib.hooks.timer.start(update)
initialized = true
end
return widget
end })
|