diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2012-08-13 15:11:55 +0200 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2012-08-13 15:12:11 +0200 |
commit | 359769944a8cb0ac80537458af0e49cc8f68d01b (patch) | |
tree | 484068988be1571b25ff0a81c7e74cb9cd579325 /src/Signal.hs | |
parent | 73837127825529d44e2e0d4ed440da0d7b180020 (diff) | |
parent | 05f268c3a831325f65a662c6ccdff75a1c441d83 (diff) | |
download | xmobar-359769944a8cb0ac80537458af0e49cc8f68d01b.tar.gz xmobar-359769944a8cb0ac80537458af0e49cc8f68d01b.tar.bz2 |
Merge for pull request #53
Diffstat (limited to 'src/Signal.hs')
-rw-r--r-- | src/Signal.hs | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/Signal.hs b/src/Signal.hs new file mode 100644 index 0000000..3c341f9 --- /dev/null +++ b/src/Signal.hs @@ -0,0 +1,70 @@ +{-# LANGUAGE DeriveDataTypeable, CPP #-} + +----------------------------------------------------------------------------- +-- | +-- Module : Signal +-- Copyright : (c) Andrea Rosatto +-- : (c) Jose A. Ortega Ruiz +-- : (c) Jochen Keil +-- License : BSD-style (see LICENSE) +-- +-- Maintainer : Jose A. Ortega Ruiz <jao@gnu.org> +-- Stability : unstable +-- Portability : unportable +-- +-- Signal handling, including DBUS when available +-- +----------------------------------------------------------------------------- + +module Signal where + +import Data.Typeable (Typeable) +import Control.Concurrent +import Control.Exception hiding (handle) +import System.Posix.Signals + +#ifdef DBUS +import DBus (IsVariant(..)) +import Control.Monad ((>=>)) + +import Plugins.Utils (safeHead) +#endif + +data WakeUp = WakeUp deriving (Show,Typeable) +instance Exception WakeUp + +data SignalType = Wakeup + | Reposition + | ChangeScreen + | Hide + | Reveal + | Toggle + | TogglePersistent + deriving (Read, Show) + +#ifdef DBUS +instance IsVariant SignalType where + toVariant = toVariant . show + fromVariant = fromVariant >=> parseSignalType +#endif + +parseSignalType :: String -> Maybe SignalType +parseSignalType = fmap fst . safeHead . reads + +-- | 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 () |