{-# LANGUAGE LambdaCase #-}
module XMonad.Hooks.ManageHelpers (
Side(..),
composeOne,
(-?>), (/=?), (<==?), (</=?), (-->>), (-?>>),
currentWs,
windowTag,
isInProperty,
isKDETrayWindow,
isFullscreen,
isDialog,
pid,
transientTo,
maybeToDefinite,
MaybeManageHook,
transience,
transience',
clientLeader,
sameBy,
shiftToSame,
shiftToSame',
doRectFloat,
doFullFloat,
doCenterFloat,
doSideFloat,
doFloatAt,
doFloatDep,
doHideIgnore,
doSink,
doLower,
doRaise,
doFocus,
Match,
) where
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
import XMonad.Util.WindowProperties (getProp32s)
import System.Posix (ProcessID)
data Side = SC | NC | CE | CW | SE | SW | NE | NW | C
deriving (ReadPrec [Side]
ReadPrec Side
Int -> ReadS Side
ReadS [Side]
(Int -> ReadS Side)
-> ReadS [Side] -> ReadPrec Side -> ReadPrec [Side] -> Read Side
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Side]
$creadListPrec :: ReadPrec [Side]
readPrec :: ReadPrec Side
$creadPrec :: ReadPrec Side
readList :: ReadS [Side]
$creadList :: ReadS [Side]
readsPrec :: Int -> ReadS Side
$creadsPrec :: Int -> ReadS Side
Read, Int -> Side -> ShowS
[Side] -> ShowS
Side -> String
(Int -> Side -> ShowS)
-> (Side -> String) -> ([Side] -> ShowS) -> Show Side
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Side] -> ShowS
$cshowList :: [Side] -> ShowS
show :: Side -> String
$cshow :: Side -> String
showsPrec :: Int -> Side -> ShowS
$cshowsPrec :: Int -> Side -> ShowS
Show, Side -> Side -> Bool
(Side -> Side -> Bool) -> (Side -> Side -> Bool) -> Eq Side
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Side -> Side -> Bool
$c/= :: Side -> Side -> Bool
== :: Side -> Side -> Bool
$c== :: Side -> Side -> Bool
Eq)
type MaybeManageHook = Query (Maybe (Endo WindowSet))
data Match a = Match Bool a
composeOne :: (Monoid a, Monad m) => [m (Maybe a)] -> m a
composeOne :: [m (Maybe a)] -> m a
composeOne = (m (Maybe a) -> m a -> m a) -> m a -> [m (Maybe a)] -> m a
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr m (Maybe a) -> m a -> m a
forall (m :: * -> *) b. Monad m => m (Maybe b) -> m b -> m b
try (a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty)
where
try :: m (Maybe b) -> m b -> m b
try m (Maybe b)
q m b
z = do
Maybe b
x <- m (Maybe b)
q
m b -> (b -> m b) -> Maybe b -> m b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe m b
z b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe b
x
infixr 0 -?>, -->>, -?>>
(/=?) :: (Eq a, Functor m) => m a -> a -> m Bool
m a
q /=? :: m a -> a -> m Bool
/=? a
x = (a -> Bool) -> m a -> m Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
x) m a
q
(<==?) :: (Eq a, Functor m) => m a -> a -> m (Match a)
m a
q <==? :: m a -> a -> m (Match a)
<==? a
x = (a -> Match a) -> m a -> m (Match a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> Match a
forall a. Eq a => a -> a -> Match a
`eq` a
x) m a
q
where
eq :: a -> a -> Match a
eq a
q' a
x' = Bool -> a -> Match a
forall a. Bool -> a -> Match a
Match (a
q' a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
x') a
q'
(</=?) :: (Eq a, Functor m) => m a -> a -> m (Match a)
m a
q </=? :: m a -> a -> m (Match a)
</=? a
x = (a -> Match a) -> m a -> m (Match a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> a -> Match a
forall a. Eq a => a -> a -> Match a
`neq` a
x) m a
q
where
neq :: a -> a -> Match a
neq a
q' a
x' = Bool -> a -> Match a
forall a. Bool -> a -> Match a
Match (a
q' a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
x') a
q'
(-?>) :: (Functor m, Monad m) => m Bool -> m a -> m (Maybe a)
m Bool
p -?> :: m Bool -> m a -> m (Maybe a)
-?> m a
f = do
Bool
x <- m Bool
p
if Bool
x then (a -> Maybe a) -> m a -> m (Maybe a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> Maybe a
forall a. a -> Maybe a
Just m a
f else Maybe a -> m (Maybe a)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe a
forall a. Maybe a
Nothing
(-->>) :: (Monoid b, Monad m) => m (Match a) -> (a -> m b) -> m b
m (Match a)
p -->> :: m (Match a) -> (a -> m b) -> m b
-->> a -> m b
f = do
Match Bool
b a
m <- m (Match a)
p
if Bool
b then a -> m b
f a
m else b -> m b
forall (m :: * -> *) a. Monad m => a -> m a
return b
forall a. Monoid a => a
mempty
(-?>>) :: (Functor m, Monad m) => m (Match a) -> (a -> m b) -> m (Maybe b)
m (Match a)
p -?>> :: m (Match a) -> (a -> m b) -> m (Maybe b)
-?>> a -> m b
f = do
Match Bool
b a
m <- m (Match a)
p
if Bool
b then (b -> Maybe b) -> m b -> m (Maybe b)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap b -> Maybe b
forall a. a -> Maybe a
Just (a -> m b
f a
m) else Maybe b -> m (Maybe b)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe b
forall a. Maybe a
Nothing
currentWs :: Query WorkspaceId
currentWs :: Query String
currentWs = X String -> Query String
forall a. X a -> Query a
liftX ((WindowSet -> X String) -> X String
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X String) -> X String)
-> (WindowSet -> X String) -> X String
forall a b. (a -> b) -> a -> b
$ String -> X String
forall (m :: * -> *) a. Monad m => a -> m a
return (String -> X String)
-> (WindowSet -> String) -> WindowSet -> X String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> String
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag)
windowTag :: Query (Maybe WorkspaceId)
windowTag :: Query (Maybe String)
windowTag = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Maybe String)) -> Query (Maybe String)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X (Maybe String) -> Query (Maybe String)
forall a. X a -> Query a
liftX (X (Maybe String) -> Query (Maybe String))
-> X (Maybe String) -> Query (Maybe String)
forall a b. (a -> b) -> a -> b
$ (WindowSet -> X (Maybe String)) -> X (Maybe String)
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X (Maybe String)) -> X (Maybe String))
-> (WindowSet -> X (Maybe String)) -> X (Maybe String)
forall a b. (a -> b) -> a -> b
$ Maybe String -> X (Maybe String)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe String -> X (Maybe String))
-> (WindowSet -> Maybe String) -> WindowSet -> X (Maybe String)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WindowSet -> Maybe String
forall a i l s sd. Eq a => a -> StackSet i l a s sd -> Maybe i
W.findTag Window
w
isKDETrayWindow :: Query Bool
isKDETrayWindow :: Query Bool
isKDETrayWindow = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window -> (Window -> Query Bool) -> Query Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X Bool -> Query Bool
forall a. X a -> Query a
liftX (X Bool -> Query Bool) -> X Bool -> Query Bool
forall a b. (a -> b) -> a -> b
$ do
Maybe [CLong]
r <- String -> Window -> X (Maybe [CLong])
getProp32s String
"_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR" Window
w
Bool -> X Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> X Bool) -> Bool -> X Bool
forall a b. (a -> b) -> a -> b
$ case Maybe [CLong]
r of
Just [CLong
_] -> Bool
True
Maybe [CLong]
_ -> Bool
False
isInProperty :: String -> String -> Query Bool
isInProperty :: String -> String -> Query Bool
isInProperty String
p String
v = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window -> (Window -> Query Bool) -> Query Bool
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X Bool -> Query Bool
forall a. X a -> Query a
liftX (X Bool -> Query Bool) -> X Bool -> Query Bool
forall a b. (a -> b) -> a -> b
$ do
Window
va <- String -> X Window
getAtom String
v
Maybe [CLong]
r <- String -> Window -> X (Maybe [CLong])
getProp32s String
p Window
w
Bool -> X Bool
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> X Bool) -> Bool -> X Bool
forall a b. (a -> b) -> a -> b
$ case Maybe [CLong]
r of
Just [CLong]
xs -> Window -> CLong
forall a b. (Integral a, Num b) => a -> b
fromIntegral Window
va CLong -> [CLong] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CLong]
xs
Maybe [CLong]
_ -> Bool
False
isFullscreen :: Query Bool
isFullscreen :: Query Bool
isFullscreen = String -> String -> Query Bool
isInProperty String
"_NET_WM_STATE" String
"_NET_WM_STATE_FULLSCREEN"
isDialog :: Query Bool
isDialog :: Query Bool
isDialog = String -> String -> Query Bool
isInProperty String
"_NET_WM_WINDOW_TYPE" String
"_NET_WM_WINDOW_TYPE_DIALOG"
pid :: Query (Maybe ProcessID)
pid :: Query (Maybe ProcessID)
pid = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Maybe ProcessID)) -> Query (Maybe ProcessID)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X (Maybe ProcessID) -> Query (Maybe ProcessID)
forall a. X a -> Query a
liftX (X (Maybe ProcessID) -> Query (Maybe ProcessID))
-> X (Maybe ProcessID) -> Query (Maybe ProcessID)
forall a b. (a -> b) -> a -> b
$ String -> Window -> X (Maybe [CLong])
getProp32s String
"_NET_WM_PID" Window
w X (Maybe [CLong])
-> (Maybe [CLong] -> Maybe ProcessID) -> X (Maybe ProcessID)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
Just [CLong
x] -> ProcessID -> Maybe ProcessID
forall a. a -> Maybe a
Just (CLong -> ProcessID
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
x)
Maybe [CLong]
_ -> Maybe ProcessID
forall a. Maybe a
Nothing
transientTo :: Query (Maybe Window)
transientTo :: Query (Maybe Window)
transientTo = do
Window
w <- Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask
Display
d <- (X Display -> Query Display
forall a. X a -> Query a
liftX (X Display -> Query Display)
-> ((XConf -> Display) -> X Display)
-> (XConf -> Display)
-> Query Display
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (XConf -> Display) -> X Display
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks) XConf -> Display
display
IO (Maybe Window) -> Query (Maybe Window)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe Window) -> Query (Maybe Window))
-> IO (Maybe Window) -> Query (Maybe Window)
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO (Maybe Window)
getTransientForHint Display
d Window
w
transience :: MaybeManageHook
transience :: MaybeManageHook
transience = Query (Maybe Window)
transientTo Query (Maybe Window)
-> Maybe Window -> Query (Match (Maybe Window))
forall a (m :: * -> *).
(Eq a, Functor m) =>
m a -> a -> m (Match a)
</=? Maybe Window
forall a. Maybe a
Nothing Query (Match (Maybe Window))
-> (Maybe Window -> Query (Endo WindowSet)) -> MaybeManageHook
forall (m :: * -> *) a b.
(Functor m, Monad m) =>
m (Match a) -> (a -> m b) -> m (Maybe b)
-?>> Query (Endo WindowSet)
-> (Window -> Query (Endo WindowSet))
-> Maybe Window
-> Query (Endo WindowSet)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Query (Endo WindowSet)
forall a. Monoid a => a
idHook Window -> Query (Endo WindowSet)
doShiftTo
transience' :: ManageHook
transience' :: Query (Endo WindowSet)
transience' = MaybeManageHook -> Query (Endo WindowSet)
forall a (m :: * -> *). (Monoid a, Functor m) => m (Maybe a) -> m a
maybeToDefinite MaybeManageHook
transience
clientLeader :: Query (Maybe Window)
clientLeader :: Query (Maybe Window)
clientLeader = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Maybe Window)) -> Query (Maybe Window)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X (Maybe Window) -> Query (Maybe Window)
forall a. X a -> Query a
liftX (X (Maybe Window) -> Query (Maybe Window))
-> X (Maybe Window) -> Query (Maybe Window)
forall a b. (a -> b) -> a -> b
$ String -> Window -> X (Maybe [CLong])
getProp32s String
"WM_CLIENT_LEADER" Window
w X (Maybe [CLong])
-> (Maybe [CLong] -> Maybe Window) -> X (Maybe Window)
forall (f :: * -> *) a b. Functor f => f a -> (a -> b) -> f b
<&> \case
Just [CLong
x] -> Window -> Maybe Window
forall a. a -> Maybe a
Just (CLong -> Window
forall a b. (Integral a, Num b) => a -> b
fromIntegral CLong
x)
Maybe [CLong]
_ -> Maybe Window
forall a. Maybe a
Nothing
sameBy :: Eq prop => Query (Maybe prop) -> Query [Window]
sameBy :: Query (Maybe prop) -> Query [Window]
sameBy Query (Maybe prop)
prop = Query (Maybe prop)
prop Query (Maybe prop)
-> (Maybe prop -> Query [Window]) -> Query [Window]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \case
Maybe prop
Nothing -> [Window] -> Query [Window]
forall (f :: * -> *) a. Applicative f => a -> f a
pure []
Maybe prop
propVal -> Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window -> (Window -> Query [Window]) -> Query [Window]
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X [Window] -> Query [Window]
forall a. X a -> Query a
liftX (X [Window] -> Query [Window])
-> ((WindowSet -> X [Window]) -> X [Window])
-> (WindowSet -> X [Window])
-> Query [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WindowSet -> X [Window]) -> X [Window]
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X [Window]) -> Query [Window])
-> (WindowSet -> X [Window]) -> Query [Window]
forall a b. (a -> b) -> a -> b
$ \WindowSet
s ->
(Window -> X Bool) -> [Window] -> X [Window]
forall (m :: * -> *) a.
Applicative m =>
(a -> m Bool) -> [a] -> m [a]
filterM ((Maybe prop -> Bool) -> X (Maybe prop) -> X Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Maybe prop
propVal Maybe prop -> Maybe prop -> Bool
forall a. Eq a => a -> a -> Bool
==) (X (Maybe prop) -> X Bool)
-> (Window -> X (Maybe prop)) -> Window -> X Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query (Maybe prop) -> Window -> X (Maybe prop)
forall a. Query a -> Window -> X a
runQuery Query (Maybe prop)
prop) (WindowSet -> [Window]
forall a i l s sd. Eq a => StackSet i l a s sd -> [a]
W.allWindows WindowSet
s [Window] -> [Window] -> [Window]
forall a. Eq a => [a] -> [a] -> [a]
\\ [Window
w])
shiftToSame :: Eq prop => Query (Maybe prop) -> MaybeManageHook
shiftToSame :: Query (Maybe prop) -> MaybeManageHook
shiftToSame Query (Maybe prop)
prop = Query (Maybe prop) -> Query [Window]
forall prop. Eq prop => Query (Maybe prop) -> Query [Window]
sameBy Query (Maybe prop)
prop Query [Window] -> [Window] -> Query (Match [Window])
forall a (m :: * -> *).
(Eq a, Functor m) =>
m a -> a -> m (Match a)
</=? [] Query (Match [Window])
-> ([Window] -> Query (Endo WindowSet)) -> MaybeManageHook
forall (m :: * -> *) a b.
(Functor m, Monad m) =>
m (Match a) -> (a -> m b) -> m (Maybe b)
-?>> Query (Endo WindowSet)
-> (Window -> Query (Endo WindowSet))
-> Maybe Window
-> Query (Endo WindowSet)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Query (Endo WindowSet)
forall a. Monoid a => a
idHook Window -> Query (Endo WindowSet)
doShiftTo (Maybe Window -> Query (Endo WindowSet))
-> ([Window] -> Maybe Window) -> [Window] -> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Window] -> Maybe Window
forall a. [a] -> Maybe a
listToMaybe
shiftToSame' :: Eq prop => Query (Maybe prop) -> ManageHook
shiftToSame' :: Query (Maybe prop) -> Query (Endo WindowSet)
shiftToSame' = MaybeManageHook -> Query (Endo WindowSet)
forall a (m :: * -> *). (Monoid a, Functor m) => m (Maybe a) -> m a
maybeToDefinite (MaybeManageHook -> Query (Endo WindowSet))
-> (Query (Maybe prop) -> MaybeManageHook)
-> Query (Maybe prop)
-> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query (Maybe prop) -> MaybeManageHook
forall prop. Eq prop => Query (Maybe prop) -> MaybeManageHook
shiftToSame
maybeToDefinite :: (Monoid a, Functor m) => m (Maybe a) -> m a
maybeToDefinite :: m (Maybe a) -> m a
maybeToDefinite = (Maybe a -> a) -> m (Maybe a) -> m a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a -> Maybe a -> a
forall a. a -> Maybe a -> a
fromMaybe a
forall a. Monoid a => a
mempty)
doShiftTo :: Window -> ManageHook
doShiftTo :: Window -> Query (Endo WindowSet)
doShiftTo Window
target = (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF ((WindowSet -> WindowSet) -> Query (Endo WindowSet))
-> (Window -> WindowSet -> WindowSet)
-> Window
-> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WindowSet -> WindowSet
forall s i l sd.
(Eq s, Eq i) =>
Window -> StackSet i l Window s sd -> StackSet i l Window s sd
shiftTo (Window -> Query (Endo WindowSet))
-> Query Window -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask
where shiftTo :: Window -> StackSet i l Window s sd -> StackSet i l Window s sd
shiftTo Window
w StackSet i l Window s sd
s = StackSet i l Window s sd
-> (i -> StackSet i l Window s sd)
-> Maybe i
-> StackSet i l Window s sd
forall b a. b -> (a -> b) -> Maybe a -> b
maybe StackSet i l Window s sd
s (\i
t -> i -> Window -> StackSet i l Window s sd -> StackSet i l Window s sd
forall a s i l sd.
(Ord a, Eq s, Eq i) =>
i -> a -> StackSet i l a s sd -> StackSet i l a s sd
W.shiftWin i
t Window
w StackSet i l Window s sd
s) (Window -> StackSet i l Window s sd -> Maybe i
forall a i l s sd. Eq a => a -> StackSet i l a s sd -> Maybe i
W.findTag Window
target StackSet i l Window s sd
s)
doRectFloat :: W.RationalRect
-> ManageHook
doRectFloat :: RationalRect -> Query (Endo WindowSet)
doRectFloat RationalRect
r = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF (Window -> RationalRect -> WindowSet -> WindowSet
forall a i l s sd.
Ord a =>
a -> RationalRect -> StackSet i l a s sd -> StackSet i l a s sd
W.float Window
w RationalRect
r)
doFullFloat :: ManageHook
doFullFloat :: Query (Endo WindowSet)
doFullFloat = RationalRect -> Query (Endo WindowSet)
doRectFloat (RationalRect -> Query (Endo WindowSet))
-> RationalRect -> Query (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ Rational -> Rational -> Rational -> Rational -> RationalRect
W.RationalRect Rational
0 Rational
0 Rational
1 Rational
1
doFloatDep :: (W.RationalRect -> W.RationalRect) -> ManageHook
doFloatDep :: (RationalRect -> RationalRect) -> Query (Endo WindowSet)
doFloatDep RationalRect -> RationalRect
move = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF ((WindowSet -> WindowSet) -> Query (Endo WindowSet))
-> ((ScreenId, RationalRect) -> WindowSet -> WindowSet)
-> (ScreenId, RationalRect)
-> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> RationalRect -> WindowSet -> WindowSet
forall a i l s sd.
Ord a =>
a -> RationalRect -> StackSet i l a s sd -> StackSet i l a s sd
W.float Window
w (RationalRect -> WindowSet -> WindowSet)
-> ((ScreenId, RationalRect) -> RationalRect)
-> (ScreenId, RationalRect)
-> WindowSet
-> WindowSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RationalRect -> RationalRect
move (RationalRect -> RationalRect)
-> ((ScreenId, RationalRect) -> RationalRect)
-> (ScreenId, RationalRect)
-> RationalRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScreenId, RationalRect) -> RationalRect
forall a b. (a, b) -> b
snd ((ScreenId, RationalRect) -> Query (Endo WindowSet))
-> Query (ScreenId, RationalRect) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< X (ScreenId, RationalRect) -> Query (ScreenId, RationalRect)
forall a. X a -> Query a
liftX (Window -> X (ScreenId, RationalRect)
floatLocation Window
w)
doFloatAt :: Rational -> Rational -> ManageHook
doFloatAt :: Rational -> Rational -> Query (Endo WindowSet)
doFloatAt Rational
x Rational
y = (RationalRect -> RationalRect) -> Query (Endo WindowSet)
doFloatDep RationalRect -> RationalRect
move
where
move :: RationalRect -> RationalRect
move (W.RationalRect Rational
_ Rational
_ Rational
w Rational
h) = Rational -> Rational -> Rational -> Rational -> RationalRect
W.RationalRect Rational
x Rational
y Rational
w Rational
h
doSideFloat :: Side -> ManageHook
doSideFloat :: Side -> Query (Endo WindowSet)
doSideFloat Side
side = (RationalRect -> RationalRect) -> Query (Endo WindowSet)
doFloatDep RationalRect -> RationalRect
move
where
move :: RationalRect -> RationalRect
move (W.RationalRect Rational
_ Rational
_ Rational
w Rational
h) = Rational -> Rational -> Rational -> Rational -> RationalRect
W.RationalRect Rational
cx Rational
cy Rational
w Rational
h
where cx :: Rational
cx
| Side
side Side -> [Side] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Side
SC,Side
C ,Side
NC] = (Rational
1Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
-Rational
w)Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/Rational
2
| Side
side Side -> [Side] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Side
SW,Side
CW,Side
NW] = Rational
0
| Bool
otherwise = Rational
1Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
-Rational
w
cy :: Rational
cy
| Side
side Side -> [Side] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Side
CE,Side
C ,Side
CW] = (Rational
1Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
-Rational
h)Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/Rational
2
| Side
side Side -> [Side] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Side
NE,Side
NC,Side
NW] = Rational
0
| Bool
otherwise = Rational
1Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
-Rational
h
doCenterFloat :: ManageHook
doCenterFloat :: Query (Endo WindowSet)
doCenterFloat = Side -> Query (Endo WindowSet)
doSideFloat Side
C
doHideIgnore :: ManageHook
doHideIgnore :: Query (Endo WindowSet)
doHideIgnore = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X () -> Query ()
forall a. X a -> Query a
liftX (Window -> X ()
hide Window
w) Query () -> Query (Endo WindowSet) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF (Window -> WindowSet -> WindowSet
forall a i l s sd.
Ord a =>
a -> StackSet i l a s sd -> StackSet i l a s sd
W.delete Window
w)
doSink :: ManageHook
doSink :: Query (Endo WindowSet)
doSink = (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF ((WindowSet -> WindowSet) -> Query (Endo WindowSet))
-> (Window -> WindowSet -> WindowSet)
-> Window
-> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WindowSet -> WindowSet
forall a i l s sd.
Ord a =>
a -> StackSet i l a s sd -> StackSet i l a s sd
W.sink (Window -> Query (Endo WindowSet))
-> Query Window -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask
doLower :: ManageHook
doLower :: Query (Endo WindowSet)
doLower = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X (Endo WindowSet) -> Query (Endo WindowSet)
forall a. X a -> Query a
liftX (X (Endo WindowSet) -> Query (Endo WindowSet))
-> X (Endo WindowSet) -> Query (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ (Display -> X (Endo WindowSet)) -> X (Endo WindowSet)
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X (Endo WindowSet)) -> X (Endo WindowSet))
-> (Display -> X (Endo WindowSet)) -> X (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ \Display
dpy -> IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Display -> Window -> IO ()
lowerWindow Display
dpy Window
w) X () -> X (Endo WindowSet) -> X (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> X (Endo WindowSet)
forall a. Monoid a => a
mempty
doRaise :: ManageHook
doRaise :: Query (Endo WindowSet)
doRaise = Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask Query Window
-> (Window -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> X (Endo WindowSet) -> Query (Endo WindowSet)
forall a. X a -> Query a
liftX (X (Endo WindowSet) -> Query (Endo WindowSet))
-> X (Endo WindowSet) -> Query (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ (Display -> X (Endo WindowSet)) -> X (Endo WindowSet)
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X (Endo WindowSet)) -> X (Endo WindowSet))
-> (Display -> X (Endo WindowSet)) -> X (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ \Display
dpy -> IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (Display -> Window -> IO ()
raiseWindow Display
dpy Window
w) X () -> X (Endo WindowSet) -> X (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> X (Endo WindowSet)
forall a. Monoid a => a
mempty
doFocus :: ManageHook
doFocus :: Query (Endo WindowSet)
doFocus = (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF ((WindowSet -> WindowSet) -> Query (Endo WindowSet))
-> (Window -> WindowSet -> WindowSet)
-> Window
-> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WindowSet -> WindowSet
forall s a i l sd.
(Eq s, Eq a, Eq i) =>
a -> StackSet i l a s sd -> StackSet i l a s sd
W.focusWindow (Window -> Query (Endo WindowSet))
-> Query Window -> Query (Endo WindowSet)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Query Window
forall r (m :: * -> *). MonadReader r m => m r
ask