2019-09-14 05:33:40 +02:00
|
|
|
-- Wi-Fi widget type for GNU/Linux using iwconfig
|
|
|
|
-- Copyright (C) 2010 Adrian C. <anrxc@sysphere.org>
|
|
|
|
-- Copyright (C) 2017 mutlusun <mutlusun@github.com>
|
|
|
|
-- Copyright (C) 2018-2019 Nguyễn Gia Phong <vn.mcsinyx@gmail.com>
|
|
|
|
--
|
|
|
|
-- This file is part of Vicious.
|
|
|
|
--
|
|
|
|
-- Vicious is free software: you can redistribute it and/or modify
|
|
|
|
-- it under the terms of the GNU General Public License as
|
|
|
|
-- published by the Free Software Foundation, either version 2 of the
|
|
|
|
-- License, or (at your option) any later version.
|
|
|
|
--
|
|
|
|
-- Vicious is distributed in the hope that it will be useful,
|
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
-- GNU General Public License for more details.
|
|
|
|
--
|
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
|
-- along with Vicious. If not, see <https://www.gnu.org/licenses/>.
|
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
|
2019-05-29 16:45:28 +02:00
|
|
|
local type = type
|
2009-10-26 20:32:48 +01:00
|
|
|
local tonumber = tonumber
|
2019-05-29 16:45:28 +02:00
|
|
|
local math = { floor = math.floor }
|
|
|
|
|
|
|
|
local helpers = require"vicious.helpers"
|
|
|
|
local spawn = require"vicious.spawn"
|
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
|
|
|
-- }}}
|
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
-- Wifi: provides wireless information for a requested interface using iwconfig
|
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
|
|
|
|
|
|
|
-- {{{ Wireless widget type
|
2019-05-29 16:45:28 +02:00
|
|
|
local function parser(stdout, stderr, exitreason, exitcode)
|
|
|
|
local winfo = {}
|
|
|
|
-- Output differs from system to system, stats can be separated by
|
|
|
|
-- either = or :. Some stats may not be supported by driver.
|
|
|
|
-- SSID can have almost anything in it.
|
|
|
|
winfo["{ssid}"] = stdout:match'ESSID[=:]"(.-)"' or "N/A"
|
|
|
|
-- Modes are simple, but also match the "-" in Ad-Hoc
|
|
|
|
winfo["{mode}"] = stdout:match"Mode[=:]([%w%-]+)" or "N/A"
|
|
|
|
winfo["{chan}"] = tonumber(stdout:match"Channel[=:](%d+)" or 0)
|
|
|
|
winfo["{rate}"] = -- Bitrate without unit (Mb/s)
|
|
|
|
tonumber(stdout:match"Bit Rate[=:]%s?([%d%.]+)" or 0)
|
|
|
|
winfo["{freq}"] = -- Frequency in MHz (is output always in GHz?)
|
|
|
|
tonumber(stdout:match"Frequency[=:]%s?([%d%.]+)" or 0) * 1000
|
|
|
|
winfo["{txpw}"] = -- Transmission power in dBm
|
|
|
|
tonumber(stdout:match"Tx%-Power[=:](%d+)" or 0)
|
|
|
|
winfo["{link}"] = -- Link quality over 70
|
|
|
|
tonumber(stdout:match"Link Quality[=:](%d+)" or 0)
|
|
|
|
winfo["{linp}"] = -- Link quality percentage if quality was available
|
|
|
|
winfo["{link}"] ~= 0 and math.floor(winfo["{link}"]/0.7 + 0.5) or 0
|
|
|
|
-- Signal level without unit (dBm), can be negative value
|
|
|
|
winfo["{sign}"] = tonumber(stdout:match"Signal level[=:](%-?%d+)" or 0)
|
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
|
2019-05-29 16:45:28 +02:00
|
|
|
|
|
|
|
function wifi_linux.async(format, warg, callback)
|
|
|
|
if type(warg) ~= "string" then return callback{} end
|
|
|
|
spawn.easy_async_with_shell(
|
|
|
|
"PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin iwconfig " .. warg,
|
|
|
|
function (...) callback(parser(...)) end)
|
|
|
|
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
|
|
|
-- }}}
|
2009-08-01 23:11:41 +02:00
|
|
|
|
2019-05-29 16:45:28 +02:00
|
|
|
return helpers.setasyncall(wifi_linux)
|