API: missing warg should not break awesome

This commit is contained in:
Adrian C. (anrxc) 2010-03-14 03:37:40 +01:00
parent 237470c8f4
commit 4dad2e360c
15 changed files with 51 additions and 29 deletions

15
README
View File

@ -15,10 +15,10 @@ For now Vicious doesn't depend on any third party Lua libraries, to
make it easier to install and use. That means some system utilities
are used instead, where available:
- hddtemp: for the HDD Temperature widget type
- alsa-utils: for the Volume widget type
- wireless_tools: for the Wireless widget type
- curl: for widget types accessing network resources
- hddtemp for the HDD Temperature widget type
- alsa-utils for the Volume widget type
- wireless_tools for the Wireless widget type
- curl for widget types accessing network resources
Usage
@ -28,10 +28,9 @@ $XDG_CONFIG_HOME (usually ~/.config):
$ mv vicious $XDG_CONFIG_HOME/awesome/
Your first step should be editing init.lua to comment out all the
widget types you don't need from the "Configure widgets" list. It is
not required but I suggest you do so to avoid having useless modules
sitting in your memory.
If you want you can disable widgets you will not use, to avoid having
useless modules sitting in your memory. You can comment out any widget
type from the "Configure widgets" list in the widgets/init.lua file.
Then add the following to the top of your rc.lua:

View File

@ -20,9 +20,10 @@ module("vicious.widgets.bat")
-- {{{ Battery widget type
local function worker(format, batid)
-- Apple PMU and ACPI/procfs battery widgets are in the [contrib] branch
local battery = helpers.pathtotable("/sys/class/power_supply/" .. batid)
local function worker(format, warg)
if not warg then return end
local battery = helpers.pathtotable("/sys/class/power_supply/"..warg)
local battery_state = {
["Full\n"] = "",
["Unknown\n"] = "",

View File

@ -16,8 +16,10 @@ module("vicious.widgets.cpufreq")
-- {{{ CPU frequency widget type
local function worker(format, cpuid)
local cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..cpuid.."/cpufreq")
local function worker(format, warg)
if not warg then return end
local cpufreq = helpers.pathtotable("/sys/devices/system/cpu/"..warg.."/cpufreq")
local governor_state = {
["ondemand\n"] = "",
["powersave\n"] = "",

View File

@ -24,6 +24,8 @@ local unit = { ["s"] = 1, ["kb"] = 2, ["mb"] = 2048 }
-- {{{ Disk I/O widget type
local function worker(format, disk)
if not disk then return end
local disk_lines = { [disk] = {} }
local disk_stats = helpers.pathtotable("/sys/block/" .. disk)
local disk_queue = helpers.pathtotable("/sys/block/" .. disk .. "/queue")

View File

@ -21,12 +21,12 @@ module("vicious.widgets.fs")
local unit = { ["mb"] = 1024, ["gb"] = 1024^2 }
-- {{{ Filesystem widget type
local function worker(format, nfs)
local function worker(format, warg)
-- Fallback to listing local filesystems
if nfs then nfs = "" else nfs = "-l" end
if warg then warg = "" else warg = "-l" end
-- Get (non-localized)data from df
local f = io.popen("LC_ALL=C df -kP " .. nfs)
local f = io.popen("LC_ALL=C df -kP " .. warg)
local fs_info = {}
for line in f:lines() do -- Match: (size) (used)(avail)(use%) (mount)

View File

@ -16,12 +16,12 @@ module("vicious.widgets.hddtemp")
-- {{{ HDD Temperature widget type
local function worker(format, port)
-- Fallback to default hddtemp port
if port == nil then port = 7634 end
local function worker(format, warg)
-- Fallback to default hddtemp warg
if warg == nil then warg = 7634 end
-- Get info from the hddtemp daemon
local f = io.popen("curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:"..port)
local f = io.popen("curl --connect-timeout 1 -fsm 3 telnet://127.0.0.1:"..warg)
local hdd_temp = {}
for line in f:lines() do

View File

@ -18,9 +18,11 @@ module("vicious.widgets.mbox")
-- {{{ Mailbox widget type
local function worker(format, warg)
if type(warg) ~= "table" then mbox = warg end
if not warg then return end
-- mbox could be huge, get a 30kb chunk from EOF
-- * attachments could be much bigger than this
if type(warg) ~= "table" then mbox = warg end
-- * attachment could be much bigger than 30kb
local f = io.open(mbox or warg[1])
f:seek("end", -30720)
local txt = f:read("*all")

View File

@ -16,6 +16,8 @@ module("vicious.widgets.mboxc")
-- {{{ Mbox count widget type
local function worker(format, warg)
if not warg then return end
-- Initialise counters
local count = { old = 0, total = 0, new = 0 }

View File

@ -16,6 +16,8 @@ module("vicious.widgets.mdir")
-- {{{ Maildir widget type
local function worker(format, warg)
if not warg then return end
-- Initialise counters
local count = { new = 0, cur = 0 }

View File

@ -21,6 +21,8 @@ module("vicious.widgets.org")
-- {{{ OrgMode widget type
local function worker(format, warg)
if not warg then return end
-- Compute delays
local today = os.time{ year=os.date("%Y"), month=os.date("%m"), day=os.date("%d") }
local soon = today + 24 * 3600 * 3 -- 3 days ahead is close

View File

@ -15,7 +15,9 @@ module("vicious.widgets.pkg")
-- {{{ Packages widget type
local function worker(format, dist)
local function worker(format, warg)
if not warg then return end
-- Initialise counters
local updates = 0
local manager = {
@ -26,7 +28,7 @@ local function worker(format, dist)
}
-- Check if updates are available
local pkg = manager[dist]
local pkg = manager[warg]
local f = io.popen(pkg.cmd)
for line in f:lines() do

View File

@ -18,6 +18,8 @@ module("vicious.widgets.thermal")
-- {{{ Thermal widget type
local function worker(format, warg)
if not warg then return end
local zone = { -- Known temperature data sources
["sys"] = {"/sys/class/thermal/", file = "temp", div = 1000},
["core"] = {"/sys/devices/platform/", file = "temp1_input",div = 1000},

View File

@ -17,6 +17,8 @@ module("vicious.widgets.volume")
-- {{{ Volume widget type
local function worker(format, warg)
if not warg then return end
local mixer_state = {
["on"] = "", -- "",
["off"] = "" -- "M"

View File

@ -18,7 +18,9 @@ module("vicious.widgets.weather")
-- {{{ Weather widget type
local function worker(format, station)
local function worker(format, warg)
if not warg then return end
-- Default values
local weather = {
["{city}"] = "N/A",
@ -36,7 +38,7 @@ local function worker(format, station)
-- Get weather forceast by the station ICAO code, from:
-- * US National Oceanic and Atmospheric Administration
local noaa = "http://weather.noaa.gov/pub/data/observations/metar/decoded/"
local f = io.popen("curl --connect-timeout 1 -fsm 3 "..noaa..station..".TXT")
local f = io.popen("curl --connect-timeout 1 -fsm 3 "..noaa..warg..".TXT")
local ws = f:read("*all")
f:close()

View File

@ -22,7 +22,9 @@ module("vicious.widgets.wifi")
-- {{{ Wireless widget type
local function worker(format, iface)
local function worker(format, warg)
if not warg then return end
-- Default values
local winfo = {
["{ssid}"] = "N/A",
@ -41,7 +43,7 @@ local function worker(format, iface)
else
f:close()
end
local f = io.popen(iwconfig .." ".. iface .. " 2>&1")
local f = io.popen(iwconfig .." ".. warg .. " 2>&1")
local iw = f:read("*all")
f:close()