From e513f7149000dfec4549d0d9f0a3add647e06c95 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Jun 2012 00:36:23 -0400 Subject: Add runM variant which takes a blocking call This allows monitors to define update times other than time-based. --- src/Plugins/Monitors/Common.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Plugins/Monitors/Common.hs b/src/Plugins/Monitors/Common.hs index c9f0843..7fcab1f 100644 --- a/src/Plugins/Monitors/Common.hs +++ b/src/Plugins/Monitors/Common.hs @@ -23,6 +23,7 @@ module Plugins.Monitors.Common ( , getConfigValue , mkMConfig , runM + , runMB , io -- * Parsers -- $parsers @@ -207,9 +208,13 @@ doConfigOptions (o:oo) = runM :: [String] -> IO MConfig -> ([String] -> Monitor String) -> Int -> (String -> IO ()) -> IO () -runM args conf action r cb = handle (cb . showException) loop +runM args conf action r = runMB args conf action (tenthSeconds r) + +runMB :: [String] -> IO MConfig -> ([String] -> Monitor String) + -> IO () -> (String -> IO ()) -> IO () +runMB args conf action wait cb = handle (cb . showException) loop where ac = doArgs args action - loop = conf >>= runReaderT ac >>= cb >> tenthSeconds r >> loop + loop = conf >>= runReaderT ac >>= cb >> wait >> loop showException :: SomeException -> String showException = ("error: "++) . show . flip asTypeOf undefined -- cgit v1.2.3 From 4d0d5880b8e151084e6dfb27cc6d51d68609b048 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Jun 2012 00:46:04 -0400 Subject: Add a blocking call for MPD based on events --- src/Plugins/Monitors/MPD.hs | 11 ++++++++++- xmobar.cabal | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Plugins/Monitors/MPD.hs b/src/Plugins/Monitors/MPD.hs index cc40a56..cb3acdf 100644 --- a/src/Plugins/Monitors/MPD.hs +++ b/src/Plugins/Monitors/MPD.hs @@ -12,7 +12,7 @@ -- ----------------------------------------------------------------------------- -module Plugins.Monitors.MPD ( mpdConfig, runMPD ) where +module Plugins.Monitors.MPD ( mpdConfig, runMPD, mpdWait ) where import Plugins.Monitors.Common import System.Console.GetOpt @@ -55,6 +55,15 @@ runMPD args = do s <- parseMPD status song opts parseTemplate s +mpdWait :: IO () +mpdWait = M.withMPD idle >> return () + where +#if defined LIBMPD_07 + idle = M.idle +#else + idle = M.idle [M.PlayerS, M.MixerS] +#endif + mopts :: [String] -> IO MOpts mopts argv = case getOpt Permute options argv of diff --git a/xmobar.cabal b/xmobar.cabal index 71ea524..02e618f 100644 --- a/xmobar.cabal +++ b/xmobar.cabal @@ -49,6 +49,10 @@ flag with_mpd description: MPD support. Needs libmpd installed. default: False +flag with_mpd_07 + description: MPD 0.7.* support. + default: False + flag all_extensions description: Includes all optional extensions. default: False @@ -146,9 +150,13 @@ executable xmobar cpp-options: -DIWLIB if flag(with_mpd) || flag(all_extensions) - build-depends: libmpd == 0.7.* other-modules: Plugins.Monitors.MPD cpp-options: -DLIBMPD + if flag(with_mpd_07) + build-depends: libmpd == 0.7.* + cpp-options: -DLIBMPD_07 + else + build-depends: libmpd == 0.8.* if flag(with_alsa) || flag(all_extensions) build-depends: alsa-mixer == 0.1.* -- cgit v1.2.3 From 0f8e3e7cf4afb28a9ed8c1922f8090c67d4714f1 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Sat, 9 Jun 2012 00:47:08 -0400 Subject: Add the AutoMPD monitor --- src/Plugins/Monitors.hs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Plugins/Monitors.hs b/src/Plugins/Monitors.hs index 9f17699..a531e26 100644 --- a/src/Plugins/Monitors.hs +++ b/src/Plugins/Monitors.hs @@ -19,7 +19,7 @@ module Plugins.Monitors where import Plugins -import Plugins.Monitors.Common ( runM ) +import Plugins.Monitors.Common ( runM, runMB ) import Plugins.Monitors.Weather import Plugins.Monitors.Net import Plugins.Monitors.Mem @@ -71,6 +71,7 @@ data Monitors = Weather Station Args Rate #endif #ifdef LIBMPD | MPD Args Rate + | AutoMPD Args #endif #ifdef ALSA | Volume String String Args Rate @@ -115,6 +116,7 @@ instance Exec Monitors where #endif #ifdef LIBMPD alias (MPD _ _) = "mpd" + alias (AutoMPD _) = "autompd" #endif #ifdef ALSA alias (Volume m c _ _) = m ++ ":" ++ c @@ -147,6 +149,7 @@ instance Exec Monitors where #endif #ifdef LIBMPD start (MPD a r) = runM a mpdConfig runMPD r + start (AutoMPD a) = runMB a mpdConfig runMPD mpdWait #endif #ifdef ALSA start (Volume m c a r) = runM a volumeConfig (runVolume m c) r -- cgit v1.2.3