summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2019-11-13 23:49:52 +0000
committerjao <jao@gnu.org>2019-11-14 00:35:46 +0000
commit6150993d0528b2a081b3d7e0b7e76732a611625d (patch)
tree7a7f914d61db6da89017f14eb386b3556c2ac397
parent74df93eaa2da360af6593fe473698d211370de15 (diff)
downloadxmobar-6150993d0528b2a081b3d7e0b7e76732a611625d.tar.gz
xmobar-6150993d0528b2a081b3d7e0b7e76732a611625d.tar.bz2
MPD monitor: host and port specifiable in config
-rw-r--r--changelog.md1
-rw-r--r--readme.md4
-rw-r--r--src/Xmobar/Plugins/Monitors/MPD.hs18
3 files changed, 18 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 2c3098c..97e866a 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,6 +2,7 @@
_New features_
+ - New options `--host` and `--port` for `MPD` monitor.
- New plugin `MailX` extending `Mail` with colors and prefix/suffix.
- New options `--lows`, `--mediums`, and `--highs` for `Battery`
to display an additional string depending on battery level (thanks
diff --git a/readme.md b/readme.md
index 10eb91b..903149d 100644
--- a/readme.md
+++ b/readme.md
@@ -1214,7 +1214,9 @@ following differences:
`-S` and `-Z`, with an string argument, to represent the playing,
stopped and paused states in the `statei` template field. The
environment variables `MPD_HOST` and `MPD_PORT` are used to
- configure the mpd server to communicate with. Also available:
+ configure the mpd server to communicate with, unless given in the
+ additional arguments `-p` (`--port`) and `-h` (`--host`). Also
+ available:
- `lapsed-icon-pattern`: dynamic string for current track position in `ipat`.
- Variables that can be used with the `-t`/`--template` argument:
`bar`, `vbar`, `ipat`, `state`, `statei`, `volume`, `length`,
diff --git a/src/Xmobar/Plugins/Monitors/MPD.hs b/src/Xmobar/Plugins/Monitors/MPD.hs
index b6d154a..cd08cda 100644
--- a/src/Xmobar/Plugins/Monitors/MPD.hs
+++ b/src/Xmobar/Plugins/Monitors/MPD.hs
@@ -34,6 +34,8 @@ data MOpts = MOpts
, mStopped :: String
, mPaused :: String
, mLapsedIconPattern :: Maybe IconPattern
+ , mPort :: Maybe String
+ , mHost :: Maybe String
}
defaultOpts :: MOpts
@@ -42,6 +44,8 @@ defaultOpts = MOpts
, mStopped = "><"
, mPaused = "||"
, mLapsedIconPattern = Nothing
+ , mPort = Nothing
+ , mHost = Nothing
}
options :: [OptDescr (MOpts -> MOpts)]
@@ -49,15 +53,20 @@ options =
[ Option "P" ["playing"] (ReqArg (\x o -> o { mPlaying = x }) "") ""
, Option "S" ["stopped"] (ReqArg (\x o -> o { mStopped = x }) "") ""
, Option "Z" ["paused"] (ReqArg (\x o -> o { mPaused = x }) "") ""
+ , Option "p" ["port"] (ReqArg (\x o -> o { mPort = Just x }) "") ""
+ , Option "h" ["host"] (ReqArg (\x o -> o { mHost = Just x }) "") ""
, Option "" ["lapsed-icon-pattern"] (ReqArg (\x o ->
o { mLapsedIconPattern = Just $ parseIconPattern x }) "") ""
]
+withMPD :: MOpts -> M.MPD a -> IO (M.Response a)
+withMPD opts = M.withMPD_ (mHost opts) (mPort opts)
+
runMPD :: [String] -> Monitor String
runMPD args = do
opts <- io $ mopts args
- status <- io $ M.withMPD M.status
- song <- io $ M.withMPD M.currentSong
+ status <- io $ withMPD opts M.status
+ song <- io $ withMPD opts M.currentSong
s <- parseMPD status song opts
parseTemplate s
@@ -69,8 +78,9 @@ mpdWait = do
_ -> return ()
mpdReady :: [String] -> Monitor Bool
-mpdReady _ = do
- response <- io $ M.withMPD M.ping
+mpdReady args = do
+ opts <- io $ mopts args
+ response <- io $ withMPD opts M.ping
case response of
Right _ -> return True
-- Only cases where MPD isn't responding is an issue; bogus information at