diff options
Diffstat (limited to 'src/Plugins/Monitors/MPD.hs')
-rw-r--r-- | src/Plugins/Monitors/MPD.hs | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/Plugins/Monitors/MPD.hs b/src/Plugins/Monitors/MPD.hs index ac976f2..5e02587 100644 --- a/src/Plugins/Monitors/MPD.hs +++ b/src/Plugins/Monitors/MPD.hs @@ -15,6 +15,7 @@ module Plugins.Monitors.MPD ( mpdConfig, runMPD, mpdWait, mpdReady ) where import Data.List +import Data.Maybe (fromMaybe) import Plugins.Monitors.Common import System.Console.GetOpt import qualified Network.MPD as M @@ -22,7 +23,7 @@ import Control.Concurrent (threadDelay) mpdConfig :: IO MConfig mpdConfig = mkMConfig "MPD: <state>" - [ "bar", "vbar", "state", "statei", "volume", "length" + [ "bar", "vbar", "ipat", "state", "statei", "volume", "length" , "lapsed", "remaining", "plength", "ppos", "file" , "name", "artist", "composer", "performer" , "album", "title", "track", "genre" @@ -32,6 +33,7 @@ data MOpts = MOpts { mPlaying :: String , mStopped :: String , mPaused :: String + , mLapsedIconPattern :: Maybe IconPattern } defaultOpts :: MOpts @@ -39,6 +41,7 @@ defaultOpts = MOpts { mPlaying = ">>" , mStopped = "><" , mPaused = "||" + , mLapsedIconPattern = Nothing } options :: [OptDescr (MOpts -> MOpts)] @@ -46,6 +49,8 @@ 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 "" ["lapsed-icon-pattern"] (ReqArg (\x o -> + o { mLapsedIconPattern = Just $ parseIconPattern x }) "") "" ] runMPD :: [String] -> Monitor String @@ -71,7 +76,7 @@ mpdReady _ = do -- Only cases where MPD isn't responding is an issue; bogus information at -- least won't hold xmobar up. Left M.NoMPD -> return False - Left M.TimedOut -> return False + Left (M.ConnectionError _) -> return False Left _ -> return True mopts :: [String] -> IO MOpts @@ -87,12 +92,13 @@ parseMPD (Right st) song opts = do songData <- parseSong song bar <- showPercentBar (100 * b) b vbar <- showVerticalBar (100 * b) b - return $ [bar, vbar, ss, si, vol, len, lap, remain, plen, ppos] ++ songData + ipat <- showIconPattern (mLapsedIconPattern opts) b + return $ [bar, vbar, ipat, ss, si, vol, len, lap, remain, plen, ppos] ++ songData where s = M.stState st ss = show s si = stateGlyph s opts - vol = int2str $ M.stVolume st - (p, t) = M.stTime st + vol = int2str $ fromMaybe 0 (M.stVolume st) + (p, t) = fromMaybe (0, 0) (M.stTime st) [lap, len, remain] = map showTime [floor p, t, max 0 (t - floor p)] b = if t > 0 then realToFrac $ p / fromIntegral t else 0 plen = int2str $ M.stPlaylistLength st |