From 77ce9cbe7f8371aadf24713a6d700a436d983eaf Mon Sep 17 00:00:00 2001 From: Jochen Keil Date: Wed, 8 Aug 2012 19:54:22 +0200 Subject: 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. --- src/Signal.hs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/Signal.hs (limited to 'src/Signal.hs') 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 () -- cgit v1.2.3