summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2018-11-21 20:52:03 +0000
committerjao <jao@gnu.org>2018-11-21 20:52:03 +0000
commitb1eb899495ed996200a9e99c33bcc8f5a4896af9 (patch)
tree8c1e1d2178ceaf8d1a66a6886f151320112e114e
parente9a9b580bc1a2d42da83a93741d1aab78a178644 (diff)
downloadxmobar-b1eb899495ed996200a9e99c33bcc8f5a4896af9.tar.gz
xmobar-b1eb899495ed996200a9e99c33bcc8f5a4896af9.tar.bz2
Wireless: simple auto-detection of interface name
-rw-r--r--changelog.md2
-rw-r--r--readme.md3
-rw-r--r--src/Plugins/Monitors/Wireless.hs12
3 files changed, 14 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index de7f14c..a2c16d9 100644
--- a/changelog.md
+++ b/changelog.md
@@ -6,6 +6,8 @@ _New features_
Daniel Schüssler.
- `ThermalZone` retries reading missing files, thanks to Reed Koser.
- `TopProc` ignores kernel threads (see also [issue #369]).
+ - `Wireless` simple autodetection of wirless interface name (if set
+ to "").
_Bug fixes_
diff --git a/readme.md b/readme.md
index 04d56ce..0cff8bf 100644
--- a/readme.md
+++ b/readme.md
@@ -769,8 +769,9 @@ something like:
### `Wireless Interface Args RefreshRate`
+- If set to "", the interface is looked up in /proc/net/wireless.
- Aliases to the interface name with the suffix "wi": thus, `Wireless
- "wlan0" []` can be used as `%wlan0wi%`
+ "wlan0" []` can be used as `%wlan0wi%`, and `Wireless "" []` as `%wi%`.
- Args: default monitor arguments, plus:
- `--quality-icon-pattern`: dynamic string for connection quality in `qualityipat`.
- Variables that can be used with the `-t`/`--template` argument:
diff --git a/src/Plugins/Monitors/Wireless.hs b/src/Plugins/Monitors/Wireless.hs
index eeef9a9..9397e50 100644
--- a/src/Plugins/Monitors/Wireless.hs
+++ b/src/Plugins/Monitors/Wireless.hs
@@ -42,12 +42,14 @@ parseOpts argv =
wirelessConfig :: IO MConfig
wirelessConfig =
- mkMConfig "<essid> <quality>" ["essid", "quality", "qualitybar", "qualityvbar", "qualityipat"]
+ mkMConfig "<essid> <quality>"
+ ["essid", "quality", "qualitybar", "qualityvbar", "qualityipat"]
runWireless :: String -> [String] -> Monitor String
runWireless iface args = do
opts <- io $ parseOpts args
- wi <- io $ getWirelessInfo iface
+ iface' <- if "" == iface then io findInterface else return iface
+ wi <- io $ getWirelessInfo iface'
na <- getConfigValue naString
let essid = wiEssid wi
qlty = fromIntegral $ wiQuality wi
@@ -60,3 +62,9 @@ runWireless iface args = do
qvb <- showVerticalBar qlty (qlty / 100)
qipat <- showIconPattern (qualityIconPattern opts) (qlty / 100)
parseTemplate [ep, q, qb, qvb, qipat]
+
+findInterface :: IO String
+findInterface = do
+ c <- readFile "/proc/net/wireless"
+ let nds = lines c
+ return $ if length nds > 2 then takeWhile (/= 'c') (nds!!2) else []