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