2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
|
|
|
-- * (c) 2009, Adrian C. <anrxc.sysphere.org>
|
|
|
|
---------------------------------------------------
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
|
|
|
|
-- {{{ Grab environment
|
|
|
|
local io = { popen = io.popen }
|
2009-08-01 23:11:41 +02:00
|
|
|
local setmetatable = setmetatable
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
local string = {
|
|
|
|
find = string.find,
|
|
|
|
match = string.match
|
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Wifi: provides wireless information for a requested interface
|
|
|
|
module("vicious.wifi")
|
|
|
|
|
|
|
|
|
|
|
|
-- {{{ Wireless widget type
|
2009-08-07 17:41:10 +02:00
|
|
|
local function worker(format, iface)
|
2009-09-14 17:25:23 +02:00
|
|
|
-- Get data from iwconfig (where available)
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
local f = io.popen("iwconfig " .. iface)
|
|
|
|
local iw = f:read("*all")
|
|
|
|
f:close()
|
|
|
|
|
2009-09-14 17:25:23 +02:00
|
|
|
-- Default values
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
local winfo = {
|
|
|
|
["{ssid}"] = "N/A",
|
|
|
|
["{mode}"] = "N/A",
|
|
|
|
["{chan}"] = "N/A",
|
|
|
|
["{rate}"] = "N/A",
|
|
|
|
["{link}"] = "N/A",
|
|
|
|
["{sign}"] = "N/A"
|
|
|
|
}
|
|
|
|
|
|
|
|
-- Check if iwconfig wasn't found, can't be executed or the
|
|
|
|
-- interface is not a wireless one
|
|
|
|
if iw == nil or string.find(iw, "No such device") then
|
|
|
|
return winfo
|
|
|
|
else
|
|
|
|
-- The output differs from system to system, some stats can
|
|
|
|
-- be separated by =, and not all drivers report all stats
|
|
|
|
winfo["{ssid}"] = -- SSID can have almost anything in it
|
2009-08-27 12:43:12 +02:00
|
|
|
string.match(iw, 'ESSID[=:]"([%w%p]+[%s]*[%w%p]*]*)"') or winfo["{ssid}"]
|
Import of vicious source tree.
Vicious is a modular widget library for 'awesome' window manager,
derived from the 'Wicked' widget library.
Summary of changes:
* Original wicked code modularized
* Widgets ported from Wicked:
- CPU, MEM, FS, NET, Date, Uptime, MPD
* CPU widget rewritten, uses pattern matching
* MEM widget rewritten, uses pattern matching
- Swap widget merged with MEM widget type
* FS widget rewritten, uses pattern matching
- Also fixed padding in the process
* NET widget rewritten, uses pattern matching
* MPD widget rewritten, a bit more versatile
* Removed deprecated helper functions
* Widgets written for Vicious:
- Thermal, Battery, Mbox, OrgMode, Volume, Entropy,
Disk I/O, System Load, Wireless, Pacman, Maildir
2009-07-29 17:59:32 +02:00
|
|
|
winfo["{mode}"] = -- Modes are simple, but also match the "-" in Ad-Hoc
|
|
|
|
string.match(iw, "Mode[=:]([%w%-]*)") or winfo["{mode}"]
|
|
|
|
winfo["{chan}"] = -- Channels are plain digits
|
|
|
|
string.match(iw, "Channel[=:]([%d]+)") or winfo["{chan}"]
|
|
|
|
winfo["{rate}"] = -- Bitrate can start with a space and we want to display Mb/s
|
|
|
|
string.match(iw, "Bit Rate[=:]([%s]?[%d%.]*[%s][%/%a]+)") or winfo["{rate}"]
|
|
|
|
-- winfo["{link}"] = -- Link quality can contain a slash: 32/100
|
|
|
|
-- string.match(iw, "Link Quality[=:]([%d]+[%/%d]*)") or winfo["{link}"]
|
|
|
|
winfo["{link}"] = -- * match only the first number, great data for a progressbar
|
|
|
|
string.match(iw, "Link Quality[=:]([%d]+)") or winfo["{link}"]
|
|
|
|
winfo["{sign}"] = -- Signal level can be a negative value, also display decibel notation
|
|
|
|
string.match(iw, "Signal level[=:]([%-%d]+[%s][%a]*)") or winfo["{sign}"]
|
|
|
|
end
|
|
|
|
|
|
|
|
return winfo
|
|
|
|
end
|
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
|
|
|
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
|