2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
|
|
|
-- Licensed under the GNU General Public License v2
|
2010-01-02 21:21:54 +01:00
|
|
|
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
|
2009-09-29 22:33:19 +02:00
|
|
|
---------------------------------------------------
|
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
|
2009-10-26 20:32:48 +01:00
|
|
|
local tonumber = tonumber
|
2010-10-19 21:23:06 +02:00
|
|
|
local math = { ceil = math.ceil }
|
2009-08-01 23:11:41 +02:00
|
|
|
local setmetatable = setmetatable
|
2010-10-29 17:50:13 +02:00
|
|
|
local helpers = require("vicious.helpers")
|
2010-03-05 00:24:43 +01:00
|
|
|
local io = {
|
2013-05-27 17:51:58 +02:00
|
|
|
open = io.open,
|
2010-03-05 00:24:43 +01:00
|
|
|
popen = io.popen
|
|
|
|
}
|
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 = {
|
2013-05-27 17:51:58 +02:00
|
|
|
find = string.find,
|
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
|
|
|
match = string.match
|
|
|
|
}
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
|
|
|
-- Wifi: provides wireless information for a requested interface
|
2012-06-15 18:07:05 +02:00
|
|
|
-- vicious.widgets.wifi
|
2017-01-25 17:56:50 +01:00
|
|
|
local wifi_linux = {}
|
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
|
|
|
|
|
|
|
|
2013-05-27 17:51:58 +02:00
|
|
|
-- {{{ Variable definitions
|
|
|
|
local iwconfig = "iwconfig"
|
|
|
|
local iwcpaths = { "/sbin", "/usr/sbin", "/usr/local/sbin", "/usr/bin" }
|
|
|
|
-- }}}
|
|
|
|
|
|
|
|
|
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
|
|
|
-- {{{ Wireless widget type
|
2010-03-14 03:37:40 +01:00
|
|
|
local function worker(format, warg)
|
|
|
|
if not warg then return end
|
|
|
|
|
2010-10-24 23:36:38 +02:00
|
|
|
-- Default values
|
|
|
|
local winfo = {
|
|
|
|
["{ssid}"] = "N/A",
|
|
|
|
["{mode}"] = "N/A",
|
|
|
|
["{chan}"] = 0,
|
|
|
|
["{rate}"] = 0,
|
|
|
|
["{link}"] = 0,
|
|
|
|
["{linp}"] = 0,
|
|
|
|
["{sign}"] = 0
|
|
|
|
}
|
|
|
|
|
2013-05-27 17:51:58 +02:00
|
|
|
-- Sbin paths aren't in user PATH, search for the binary
|
|
|
|
if iwconfig == "iwconfig" then
|
|
|
|
for _, p in ipairs(iwcpaths) do
|
|
|
|
local f = io.open(p .. "/iwconfig", "rb")
|
|
|
|
if f then
|
|
|
|
iwconfig = p .. "/iwconfig"
|
|
|
|
f:close()
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2010-03-05 00:24:43 +01:00
|
|
|
end
|
2013-05-27 17:51:58 +02:00
|
|
|
|
|
|
|
-- Get data from iwconfig where available
|
2014-11-12 23:43:24 +01:00
|
|
|
local f = io.popen(iwconfig .." ".. helpers.shellquote(warg) .. " 2>&1")
|
2010-03-05 00:10:25 +01:00
|
|
|
local iw = f:read("*all")
|
|
|
|
f:close()
|
|
|
|
|
|
|
|
-- iwconfig wasn't found, isn't executable, or non-wireless interface
|
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
|
|
|
if iw == nil or string.find(iw, "No such device") then
|
|
|
|
return winfo
|
|
|
|
end
|
|
|
|
|
2010-01-29 16:41:40 +01:00
|
|
|
-- Output differs from system to system, some stats can be
|
|
|
|
-- separated by =, and not all drivers report all stats
|
2009-10-04 00:54:27 +02:00
|
|
|
winfo["{ssid}"] = -- SSID can have almost anything in it
|
2010-10-29 17:50:13 +02:00
|
|
|
helpers.escape(string.match(iw, 'ESSID[=:]"(.-)"') or winfo["{ssid}"])
|
2009-10-04 00:54:27 +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
|
2009-10-26 20:32:48 +01:00
|
|
|
tonumber(string.match(iw, "Channel[=:]([%d]+)") or winfo["{chan}"])
|
2009-12-27 20:32:25 +01:00
|
|
|
winfo["{rate}"] = -- Bitrate can start with a space, we don't want to display Mb/s
|
|
|
|
tonumber(string.match(iw, "Bit Rate[=:]([%s]?[%d%.]*)") or winfo["{rate}"])
|
|
|
|
winfo["{link}"] = -- Link quality can contain a slash (32/70), match only the first number
|
2009-10-26 20:32:48 +01:00
|
|
|
tonumber(string.match(iw, "Link Quality[=:]([%d]+)") or winfo["{link}"])
|
2009-12-27 20:32:25 +01:00
|
|
|
winfo["{sign}"] = -- Signal level can be a negative value, don't display decibel notation
|
|
|
|
tonumber(string.match(iw, "Signal level[=:]([%-]?[%d]+)") or winfo["{sign}"])
|
2009-10-04 00:54:27 +02:00
|
|
|
|
2010-10-19 21:23:06 +02:00
|
|
|
-- Link quality percentage if quality was available
|
|
|
|
if winfo["{link}"] ~= 0 then winfo["{linp}"] = math.ceil(winfo["{link}"] / 0.7) end
|
|
|
|
|
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
|
|
|
return winfo
|
|
|
|
end
|
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
2017-01-25 17:56:50 +01:00
|
|
|
return setmetatable(wifi_linux, { __call = function(_, ...) return worker(...) end })
|