summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/Run
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/Run
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/Run')
-rw-r--r--src/Xmobar/Run/Command.hs2
-rw-r--r--src/Xmobar/Run/Exec.hs8
2 files changed, 7 insertions, 3 deletions
diff --git a/src/Xmobar/Run/Command.hs b/src/Xmobar/Run/Command.hs
index 0953132..e6153c1 100644
--- a/src/Xmobar/Run/Command.hs
+++ b/src/Xmobar/Run/Command.hs
@@ -41,7 +41,7 @@ instance Exec Command where
start (Com p as al r) cb =
start (ComX p as ("Could not execute command " ++ p) al r) cb
start (ComX prog args msg _ r) cb = if r > 0 then go else exec
- where go = exec >> tenthSeconds r >> go
+ where go = doEveryTenthSeconds r exec
exec = do
(i,o,e,p) <- runInteractiveProcess prog args Nothing Nothing
exit <- waitForProcess p
diff --git a/src/Xmobar/Run/Exec.hs b/src/Xmobar/Run/Exec.hs
index c8fcb9e..db7e7b4 100644
--- a/src/Xmobar/Run/Exec.hs
+++ b/src/Xmobar/Run/Exec.hs
@@ -17,7 +17,7 @@
--
-----------------------------------------------------------------------------
-module Xmobar.Run.Exec (Exec (..), tenthSeconds) where
+module Xmobar.Run.Exec (Exec (..), tenthSeconds, doEveryTenthSeconds) where
import Prelude
import Data.Char
@@ -34,6 +34,10 @@ tenthSeconds s | s >= x = do threadDelay (x * 100000)
| otherwise = threadDelay (s * 100000)
where x = (maxBound :: Int) `div` 100000
+doEveryTenthSeconds :: Int -> IO () -> IO ()
+doEveryTenthSeconds r action = go
+ where go = action >> tenthSeconds r >> go
+
class Show e => Exec e where
alias :: e -> String
alias e = takeWhile (not . isSpace) $ show e
@@ -43,6 +47,6 @@ class Show e => Exec e where
run _ = return ""
start :: e -> (String -> IO ()) -> IO ()
start e cb = go
- where go = run e >>= cb >> tenthSeconds (rate e) >> go
+ where go = doEveryTenthSeconds (rate e) $ run e >>= cb
trigger :: e -> (Maybe SignalType -> IO ()) -> IO ()
trigger _ sh = sh Nothing