summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJochen Keil <jochen.keil@gmail.com>2012-08-08 19:54:22 +0200
committerJochen Keil <jochen.keil@gmail.com>2012-08-09 10:43:39 +0200
commit77ce9cbe7f8371aadf24713a6d700a436d983eaf (patch)
tree3a959d4785734a9e4c79b6cd846a571361e29c92 /src
parenta52c4a076807ae04db67894aebd741924ff9f926 (diff)
downloadxmobar-77ce9cbe7f8371aadf24713a6d700a436d983eaf.tar.gz
xmobar-77ce9cbe7f8371aadf24713a6d700a436d983eaf.tar.bz2
Move signal handler and data types to own module
This is necessary to make SignalType available for other modules without import loops. This also decoupels the modules and their functionality a bit more so this is generally a cleaner solution.
Diffstat (limited to 'src')
-rw-r--r--src/Signal.hs33
-rw-r--r--src/Xmobar.hs25
2 files changed, 34 insertions, 24 deletions
diff --git a/src/Signal.hs b/src/Signal.hs
new file mode 100644
index 0000000..3919d86
--- /dev/null
+++ b/src/Signal.hs
@@ -0,0 +1,33 @@
+{-# LANGUAGE DeriveDataTypeable #-}
+
+module Signal where
+
+import Data.Typeable (Typeable)
+import Control.Concurrent
+import Control.Exception hiding (handle)
+import System.Posix.Signals
+
+data WakeUp = WakeUp deriving (Show,Typeable)
+instance Exception WakeUp
+
+data SignalType = Wakeup
+ | Reposition
+ | ChangeScreen
+
+-- | Signal handling
+setupSignalHandler :: IO (MVar SignalType)
+setupSignalHandler = do
+ tid <- newEmptyMVar
+ installHandler sigUSR2 (Catch $ updatePosHandler tid) Nothing
+ installHandler sigUSR1 (Catch $ changeScreenHandler tid) Nothing
+ return tid
+
+updatePosHandler :: MVar SignalType -> IO ()
+updatePosHandler sig = do
+ putMVar sig Reposition
+ return ()
+
+changeScreenHandler :: MVar SignalType -> IO ()
+changeScreenHandler sig = do
+ putMVar sig ChangeScreen
+ return ()
diff --git a/src/Xmobar.hs b/src/Xmobar.hs
index 0b744de..6c2965c 100644
--- a/src/Xmobar.hs
+++ b/src/Xmobar.hs
@@ -39,7 +39,7 @@ import Control.Arrow ((&&&))
import Control.Monad.Reader
import Control.Concurrent
import Control.Concurrent.STM
-import Control.Exception hiding (handle)
+import Control.Exception (catch, SomeException(..))
import Data.Bits
import Config
@@ -70,11 +70,6 @@ data XConf =
runX :: XConf -> X () -> IO ()
runX xc f = runReaderT f xc
-data WakeUp = WakeUp deriving (Show,Typeable)
-instance Exception WakeUp
-
-data SignalType = Wakeup | Reposition | ChangeScreen
-
-- | Starts the main event loop and threads
startLoop :: XConf -> [[(Maybe ThreadId, TVar String)]] -> IO ()
startLoop xcfg@(XConf _ _ w _ _) vs = do
@@ -162,24 +157,6 @@ eventLoop tv xc@(XConf d _ w fs cfg) signal = do
return (ocfg {position = OnScreen 1 o})
--- | Signal handling
-setupSignalHandler :: IO (MVar SignalType)
-setupSignalHandler = do
- tid <- newEmptyMVar
- installHandler sigUSR2 (Catch $ updatePosHandler tid) Nothing
- installHandler sigUSR1 (Catch $ changeScreenHandler tid) Nothing
- return tid
-
-updatePosHandler :: MVar SignalType -> IO ()
-updatePosHandler sig = do
- putMVar sig Reposition
- return ()
-
-changeScreenHandler :: MVar SignalType -> IO ()
-changeScreenHandler sig = do
- putMVar sig ChangeScreen
- return ()
-
-- $command
-- | Runs a command as an independent thread and returns its thread id