summaryrefslogtreecommitdiffhomepage
path: root/src/Xmobar/App/EventLoop.hs
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-01-28 03:45:03 +0000
committerjao <jao@gnu.org>2022-01-29 06:42:29 +0000
commit06e5c61ff84bae540ce16ca17abb94c703546acd (patch)
treea7e2befda7fe0b263f7e2e92e4d6ef5aaf191655 /src/Xmobar/App/EventLoop.hs
parentf3cf53bad93d290130a13cf4e56df54b51d5c174 (diff)
downloadxmobar-06e5c61ff84bae540ce16ca17abb94c703546acd.tar.gz
xmobar-06e5c61ff84bae540ce16ca17abb94c703546acd.tar.bz2
Xmobar.App.CommandThreads
Diffstat (limited to 'src/Xmobar/App/EventLoop.hs')
-rw-r--r--src/Xmobar/App/EventLoop.hs59
1 files changed, 12 insertions, 47 deletions
diff --git a/src/Xmobar/App/EventLoop.hs b/src/Xmobar/App/EventLoop.hs
index f046647..1764b1d 100644
--- a/src/Xmobar/App/EventLoop.hs
+++ b/src/Xmobar/App/EventLoop.hs
@@ -16,13 +16,7 @@
--
------------------------------------------------------------------------------
-
-module Xmobar.App.EventLoop
- ( startLoop
- , startCommand
- , newRefreshLock
- , refreshLock
- ) where
+module Xmobar.App.EventLoop (startLoop) where
import Prelude hiding (lookup)
import Graphics.X11.Xlib hiding (textExtents, textWidth)
@@ -33,18 +27,22 @@ import Graphics.X11.Xrandr
import Control.Arrow ((&&&))
import Control.Monad.Reader
import Control.Concurrent
-import Control.Concurrent.Async (Async, async)
+import Control.Concurrent.Async (Async)
import Control.Concurrent.STM
-import Control.Exception (bracket_, handle, SomeException(..))
+import Control.Exception (handle, SomeException(..))
import Data.Bits
import Data.Map hiding (foldr, map, filter)
import Data.Maybe (fromJust, isJust)
import qualified Data.List.NonEmpty as NE
import Xmobar.System.Signal
-import Xmobar.Config.Types (persistent, position, iconRoot, Config, Align(..), XPosition(..))
-import Xmobar.Run.Exec
-import Xmobar.Run.Runnable
+import Xmobar.Config.Types (persistent
+ , position
+ , iconRoot
+ , Config
+ , Align(..)
+ , XPosition(..))
+
import Xmobar.X11.Actions
import Xmobar.X11.Parsers
import Xmobar.X11.Window
@@ -54,6 +52,8 @@ import Xmobar.X11.Bitmap as Bitmap
import Xmobar.X11.Types
import Xmobar.System.Utils (safeIndex)
+import Xmobar.App.CommandThreads (refreshLockT)
+
#ifndef THREADED_RUNTIME
import Xmobar.X11.Events(nextEvent')
#endif
@@ -69,22 +69,6 @@ import Xmobar.System.DBus
runX :: XConf -> X () -> IO ()
runX xc f = runReaderT f xc
-newRefreshLock :: IO (TMVar ())
-newRefreshLock = newTMVarIO ()
-
-refreshLock :: TMVar () -> IO a -> IO a
-refreshLock var = bracket_ lock unlock
- where
- lock = atomically $ takeTMVar var
- unlock = atomically $ putTMVar var ()
-
-refreshLockT :: TMVar () -> STM a -> STM a
-refreshLockT var action = do
- takeTMVar var
- r <- action
- putTMVar var ()
- return r
-
-- | Starts the main event loop and threads
startLoop :: XConf
-> TMVar SignalType
@@ -230,25 +214,6 @@ eventLoop tv xc@(XConf d r w fs vos is cfg) as signal = do
filter (\(_, from, to) -> x >= from && x <= to) as
eventLoop tv xc as signal
--- $command
-
--- | Runs a command as an independent thread and returns its Async handles
--- and the TVar the command will be writing to.
-startCommand :: TMVar SignalType
- -> (Runnable,String,String)
- -> IO ([Async ()], TVar String)
-startCommand sig (com,s,ss)
- | alias com == "" = do var <- newTVarIO is
- atomically $ writeTVar var (s ++ ss)
- return ([], var)
- | otherwise = do var <- newTVarIO is
- let cb str = atomically $ writeTVar var (s ++ str ++ ss)
- a1 <- async $ start com cb
- a2 <- async $ trigger com $ maybe (return ())
- (atomically . putTMVar sig)
- return ([a1, a2], var)
- where is = s ++ "Updating..." ++ ss
-
updateString :: Config
-> TVar [String]
-> IO [[(Widget, TextRenderInfo, Int, Maybe [Action])]]