-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathP.hs
58 lines (42 loc) · 1.46 KB
/
P.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{-# OPTIONS -fglasgow-exts #-}
module P where
import Graphics.X11.Xlib hiding (refreshKeyboardMapping)
import Graphics.X11.Xlib.Extras
import Control.Monad.Reader
import Control.Monad.State
import System.IO
--import Operations
import qualified WindowSplit as W
data PState = PState
{ windowState :: !W.WindowCtx
, dimensions :: !(Position,Position)
, xineScreens :: ![Rectangle] }
deriving (Show)
data PConf = PConf
{ display :: Display
, rootWin :: !Window
, wmDelete :: !Atom
, wmProtocols :: !Atom }
deriving (Show)
newtype P a = P (ReaderT PConf (StateT PState IO) a)
deriving (Functor, Monad, MonadIO,
MonadState PState, MonadReader PConf)
debugP = io
runP :: PConf -> PState -> P a -> IO ()
runP c st (P a) = runStateT (runReaderT a c) st >> return ()
whenM :: (Monad m) => m Bool -> m () -> m ()
whenM a f = a >>= \b -> when b f
whenJust :: (Monad m) => Maybe a -> (a -> m ()) -> m ()
whenJust mg f = maybe (return ()) f mg
trace :: (MonadIO m) => String -> m ()
trace msg = liftIO $! do hPutStrLn stderr msg; hFlush stderr
io :: IO a -> P a
io = liftIO
-- ---------------------------------------------------------------------
-- Convenient wrappers to state -- some from xmonad 0.2
-- | Run a monad action with the current display
withDisplay :: (Display -> P a) -> P a
withDisplay f = asks display >>= f
-- | True if the given window is the root window
isRoot :: Window -> P Bool
isRoot w = liftM (w==) (asks rootWin)