diff options
author | jao <jao@gnu.org> | 2019-01-27 23:11:26 +0000 |
---|---|---|
committer | jao <jao@gnu.org> | 2019-01-27 23:11:26 +0000 |
commit | 78bcb8c73ffb1b09b379ea0bbd7e68f2d84e187e (patch) | |
tree | 5a3f867a99ab809e8e852b57940f6b1fe23e1e26 /src/lib | |
parent | 52611915c9bbf2fcb57e36195797fad223fc6350 (diff) | |
download | xmobar-config-78bcb8c73ffb1b09b379ea0bbd7e68f2d84e187e.tar.gz xmobar-config-78bcb8c73ffb1b09b379ea0bbd7e68f2d84e187e.tar.bz2 |
Monitor combiners (eventually to xmobar)
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Monitors.hs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/lib/Monitors.hs b/src/lib/Monitors.hs index 15900e5..fb51893 100644 --- a/src/lib/Monitors.hs +++ b/src/lib/Monitors.hs @@ -2,6 +2,39 @@ module Monitors where import Xmobar import Config +import Control.Concurrent +import Control.Concurrent.Async (async) +import Control.Concurrent.STM + +data CombinedMonitor a b = CombinedMonitor a b (String -> String -> String) + +instance (Show a, Show b) => Show (CombinedMonitor a b) where + show (CombinedMonitor a b _) = "Alt (" ++ show a ++ ") (" ++ show b ++ ")" + +instance (Read a, Read b) => Read (CombinedMonitor a b) where + readsPrec _ = undefined + +instance (Exec a, Exec b) => Exec (CombinedMonitor a b) where + alias (CombinedMonitor a b _) = (alias a) ++ "_" ++ (alias b) + rate (CombinedMonitor a b _) = min (rate a) (rate b) + start (CombinedMonitor a b comb) cb + = startMonitors a b (\s t -> cb $ comb s t) + +startMonitors a b cmb = do + sta <- atomically $ newTVar "" + stb <- atomically $ newTVar "" + _ <- async $ start a (\x -> atomically $ writeTVar sta x) + _ <- async $ start b (\x -> atomically $ writeTVar stb x) + go sta stb cmb + where go sta' stb' cmb' = do + s <- atomically $ readTVar sta' + t <- atomically $ readTVar stb' + cmb' s t + tenthSeconds $ min (rate b) (rate a) + go sta' stb' cmb' + +altMonitor a b = CombinedMonitor a b (\s t -> if null s then t else s) +concatMonitor sep a b = CombinedMonitor a b (\s t -> s ++ sep ++ t) topProc p = TopProc (p <~> ["-t" , "<mboth3> <mboth2> <mboth1> \ \ยท <both3> <both2> <both1>" |