summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Plugins/Monitors/Common
diff options
context:
space:
mode:
authorTomas Janousek <tomi@nomi.cz>2019-08-13 22:37:01 +0200
committerTomas Janousek <tomi@nomi.cz>2020-02-22 18:13:35 +0000
commit2a71487437ca4afed6f35acc1e16c2e03bfc053c (patch)
treee7fba202b0554f9c9dca5b14d8e87cac3a50f697 /src/Xmobar/Plugins/Monitors/Common
parent8403251f2bff2d803f2e4f3d55b363673570c3c7 (diff)
downloadxmobar-2a71487437ca4afed6f35acc1e16c2e03bfc053c.tar.gz
xmobar-2a71487437ca4afed6f35acc1e16c2e03bfc053c.tar.bz2
Refactor code from tenthSeconds to doEveryTenthSeconds
A preparation for timer coalescing: tenthSeconds is just a sleep whereas doEveryTenthSeconds enables using a central timer and waiting for all monitors to update before refreshing the window. This commit is just a simple refactor, the actual timer coalescing code comes later.
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Common')
-rw-r--r--src/Xmobar/Plugins/Monitors/Common/Run.hs19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Common/Run.hs b/src/Xmobar/Plugins/Monitors/Common/Run.hs
index a73a6fb..3baa7aa 100644
--- a/src/Xmobar/Plugins/Monitors/Common/Run.hs
+++ b/src/Xmobar/Plugins/Monitors/Common/Run.hs
@@ -19,6 +19,8 @@ module Xmobar.Plugins.Monitors.Common.Run ( runM
, runMD
, runMB
, runMBD
+ , runML
+ , runMLD
, getArgvs
) where
@@ -28,7 +30,7 @@ import Control.Monad.Reader
import System.Console.GetOpt
import Xmobar.Plugins.Monitors.Common.Types
-import Xmobar.Run.Exec (tenthSeconds)
+import Xmobar.Run.Exec (doEveryTenthSeconds)
options :: [OptDescr Opts]
options =
@@ -108,11 +110,11 @@ doConfigOptions (o:oo) =
runM :: [String] -> IO MConfig -> ([String] -> Monitor String) -> Int
-> (String -> IO ()) -> IO ()
-runM args conf action r = runMB args conf action (tenthSeconds r)
+runM args conf action r = runML args conf action (doEveryTenthSeconds r)
runMD :: [String] -> IO MConfig -> ([String] -> Monitor String) -> Int
-> ([String] -> Monitor Bool) -> (String -> IO ()) -> IO ()
-runMD args conf action r = runMBD args conf action (tenthSeconds r)
+runMD args conf action r = runMLD args conf action (doEveryTenthSeconds r)
runMB :: [String] -> IO MConfig -> ([String] -> Monitor String) -> IO ()
-> (String -> IO ()) -> IO ()
@@ -124,5 +126,16 @@ runMBD args conf action wait detect cb = handle (cb . showException) loop
where ac = doArgs args action detect
loop = conf >>= runReaderT ac >>= cb >> wait >> loop
+runML :: [String] -> IO MConfig -> ([String] -> Monitor String)
+ -> (IO () -> IO ()) -> (String -> IO ()) -> IO ()
+runML args conf action looper = runMLD args conf action looper (\_ -> return True)
+
+runMLD :: [String] -> IO MConfig -> ([String] -> Monitor String)
+ -> (IO () -> IO ()) -> ([String] -> Monitor Bool) -> (String -> IO ())
+ -> IO ()
+runMLD args conf action looper detect cb = handle (cb . showException) loop
+ where ac = doArgs args action detect
+ loop = looper $ conf >>= runReaderT ac >>= cb
+
showException :: SomeException -> String
showException = ("error: "++) . show . flip asTypeOf undefined