module XMonad.Actions.FloatSnap (
Direction2D(..),
snapMove,
snapGrow,
snapShrink,
snapMagicMove,
snapMagicResize,
snapMagicMouseResize,
afterDrag,
ifClick,
ifClick') where
import XMonad
import Control.Applicative((<$>))
import Data.List (sort)
import Data.Maybe (listToMaybe,fromJust,isNothing)
import qualified XMonad.StackSet as W
import qualified Data.Set as S
import XMonad.Hooks.ManageDocks (calcGap)
import XMonad.Util.Types (Direction2D(..))
import XMonad.Actions.AfterDrag
snapMagicMouseResize
:: Rational
-> Maybe Int
-> Maybe Int
-> Window
-> X ()
snapMagicMouseResize :: Rational -> Maybe Int -> Maybe Int -> Window -> X ()
snapMagicMouseResize middle :: Rational
middle collidedist :: Maybe Int
collidedist snapdist :: Maybe Int
snapdist w :: Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \d :: Display
d -> do
WindowAttributes
wa <- IO WindowAttributes -> X WindowAttributes
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO WindowAttributes -> X WindowAttributes)
-> IO WindowAttributes -> X WindowAttributes
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d Window
w
(_, _, _, px :: CInt
px, py :: CInt
py, _, _, _) <- IO (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier))
-> IO (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
-> X (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
forall a b. (a -> b) -> a -> b
$ Display
-> Window
-> IO (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
queryPointer Display
d Window
w
let x :: Rational
x = (CInt -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
px Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- WindowAttributes -> Rational
wx WindowAttributes
wa)Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/(WindowAttributes -> Rational
ww WindowAttributes
wa)
y :: Rational
y = (CInt -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
py Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- WindowAttributes -> Rational
wy WindowAttributes
wa)Rational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/(WindowAttributes -> Rational
wh WindowAttributes
wa)
ml :: [Direction2D]
ml = if Rational
x Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
<= (0.5 Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- Rational
middleRational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/2) then [Direction2D
L] else []
mr :: [Direction2D]
mr = if Rational
x Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
> (0.5 Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ Rational
middleRational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/2) then [Direction2D
R] else []
mu :: [Direction2D]
mu = if Rational
y Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
<= (0.5 Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- Rational
middleRational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/2) then [Direction2D
U] else []
md :: [Direction2D]
md = if Rational
y Rational -> Rational -> Bool
forall a. Ord a => a -> a -> Bool
> (0.5 Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ Rational
middleRational -> Rational -> Rational
forall a. Fractional a => a -> a -> a
/2) then [Direction2D
D] else []
mdir :: [Direction2D]
mdir = [Direction2D]
ml[Direction2D] -> [Direction2D] -> [Direction2D]
forall a. [a] -> [a] -> [a]
++[Direction2D]
mr[Direction2D] -> [Direction2D] -> [Direction2D]
forall a. [a] -> [a] -> [a]
++[Direction2D]
mu[Direction2D] -> [Direction2D] -> [Direction2D]
forall a. [a] -> [a] -> [a]
++[Direction2D]
md
dir :: [Direction2D]
dir = if [Direction2D]
mdir [Direction2D] -> [Direction2D] -> Bool
forall a. Eq a => a -> a -> Bool
== []
then [Direction2D
L,Direction2D
R,Direction2D
U,Direction2D
D]
else [Direction2D]
mdir
[Direction2D] -> Maybe Int -> Maybe Int -> Window -> X ()
snapMagicResize [Direction2D]
dir Maybe Int
collidedist Maybe Int
snapdist Window
w
where
wx :: WindowAttributes -> Rational
wx = CInt -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Rational)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_x
wy :: WindowAttributes -> Rational
wy = CInt -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Rational)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_y
ww :: WindowAttributes -> Rational
ww = CInt -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Rational)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_width
wh :: WindowAttributes -> Rational
wh = CInt -> Rational
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Rational)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Rational
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_height
snapMagicResize
:: [Direction2D]
-> Maybe Int
-> Maybe Int
-> Window
-> X ()
snapMagicResize :: [Direction2D] -> Maybe Int -> Maybe Int -> Window -> X ()
snapMagicResize dir :: [Direction2D]
dir collidedist :: Maybe Int
collidedist snapdist :: Maybe Int
snapdist w :: Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \d :: Display
d -> do
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO ()
raiseWindow Display
d Window
w
WindowAttributes
wa <- IO WindowAttributes -> X WindowAttributes
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO WindowAttributes -> X WindowAttributes)
-> IO WindowAttributes -> X WindowAttributes
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d Window
w
(xbegin :: Int
xbegin,xend :: Int
xend) <- Bool -> Display -> WindowAttributes -> X (Int, Int)
handleAxis Bool
True Display
d WindowAttributes
wa
(ybegin :: Int
ybegin,yend :: Int
yend) <- Bool -> Display -> WindowAttributes -> X (Int, Int)
handleAxis Bool
False Display
d WindowAttributes
wa
let xbegin' :: Int
xbegin' = if Direction2D
L Direction2D -> [Direction2D] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Direction2D]
dir then Int
xbegin else (WindowAttributes -> Int
wx WindowAttributes
wa)
xend' :: Int
xend' = if Direction2D
R Direction2D -> [Direction2D] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Direction2D]
dir then Int
xend else (WindowAttributes -> Int
wx WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
ww WindowAttributes
wa)
ybegin' :: Int
ybegin' = if Direction2D
U Direction2D -> [Direction2D] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Direction2D]
dir then Int
ybegin else (WindowAttributes -> Int
wy WindowAttributes
wa)
yend' :: Int
yend' = if Direction2D
D Direction2D -> [Direction2D] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Direction2D]
dir then Int
yend else (WindowAttributes -> Int
wy WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wh WindowAttributes
wa)
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Position) -> Int -> Position
forall a b. (a -> b) -> a -> b
$ Int
xbegin') (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Position) -> Int -> Position
forall a b. (a -> b) -> a -> b
$ Int
ybegin')
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Dimension -> Dimension -> IO ()
resizeWindow Display
d Window
w (Int -> Dimension
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Dimension) -> Int -> Dimension
forall a b. (a -> b) -> a -> b
$ Int
xend' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
xbegin') (Int -> Dimension
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Dimension) -> Int -> Dimension
forall a b. (a -> b) -> a -> b
$ Int
yend' Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
ybegin')
Window -> X ()
float Window
w
where
wx :: WindowAttributes -> Int
wx = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_x
wy :: WindowAttributes -> Int
wy = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_y
ww :: WindowAttributes -> Int
ww = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_width
wh :: WindowAttributes -> Int
wh = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_height
handleAxis :: Bool -> Display -> WindowAttributes -> X (Int, Int)
handleAxis horiz :: Bool
horiz d :: Display
d wa :: WindowAttributes
wa = do
((mbl :: Maybe Int
mbl,mbr :: Maybe Int
mbr,bs :: Bool
bs),(mfl :: Maybe Int
mfl,mfr :: Maybe Int
mfr,fs :: Bool
fs)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
horiz Maybe Int
collidedist Display
d Window
w
let begin :: Int
begin = if Bool
bs
then WindowAttributes -> Int
wpos WindowAttributes
wa
else case (Maybe Int
mbl,Maybe Int
mbr) of
(Just bl :: Int
bl,Just br :: Int
br) -> if WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bl Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
br Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa then Int
bl else Int
br
(Just bl :: Int
bl,Nothing) -> Int
bl
(Nothing,Just br :: Int
br) -> Int
br
(Nothing,Nothing) -> WindowAttributes -> Int
wpos WindowAttributes
wa
end :: Int
end = if Bool
fs
then WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
wa
else case (if Maybe Int
mflMaybe Int -> Maybe Int -> Bool
forall a. Eq a => a -> a -> Bool
==(Int -> Maybe Int
forall a. a -> Maybe a
Just Int
begin) then Maybe Int
forall a. Maybe a
Nothing else Maybe Int
mfl,Maybe Int
mfr) of
(Just fl :: Int
fl,Just fr :: Int
fr) -> if WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fl Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
fr Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa then Int
fl else Int
fr
(Just fl :: Int
fl,Nothing) -> Int
fl
(Nothing,Just fr :: Int
fr) -> Int
fr
(Nothing,Nothing) -> WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
wa
begin' :: Int
begin' = if Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Int
snapdist Bool -> Bool -> Bool
|| Int -> Int
forall a. Num a => a -> a
abs (Int
begin Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust Maybe Int
snapdist then Int
begin else (WindowAttributes -> Int
wpos WindowAttributes
wa)
end' :: Int
end' = if Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Int
snapdist Bool -> Bool -> Bool
|| Int -> Int
forall a. Num a => a -> a
abs (Int
end Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust Maybe Int
snapdist then Int
end else (WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
wa)
(Int, Int) -> X (Int, Int)
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
begin',Int
end')
where
(wpos :: WindowAttributes -> Int
wpos, wdim :: WindowAttributes -> Int
wdim, _, _) = Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
constructors Bool
horiz
snapMagicMove
:: Maybe Int
-> Maybe Int
-> Window
-> X ()
snapMagicMove :: Maybe Int -> Maybe Int -> Window -> X ()
snapMagicMove collidedist :: Maybe Int
collidedist snapdist :: Maybe Int
snapdist w :: Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \d :: Display
d -> do
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO ()
raiseWindow Display
d Window
w
WindowAttributes
wa <- IO WindowAttributes -> X WindowAttributes
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO WindowAttributes -> X WindowAttributes)
-> IO WindowAttributes -> X WindowAttributes
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d Window
w
Int
nx <- Bool -> Display -> WindowAttributes -> X Int
handleAxis Bool
True Display
d WindowAttributes
wa
Int
ny <- Bool -> Display -> WindowAttributes -> X Int
handleAxis Bool
False Display
d WindowAttributes
wa
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nx) (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ny)
Window -> X ()
float Window
w
where
handleAxis :: Bool -> Display -> WindowAttributes -> X Int
handleAxis horiz :: Bool
horiz d :: Display
d wa :: WindowAttributes
wa = do
((mbl :: Maybe Int
mbl,mbr :: Maybe Int
mbr,bs :: Bool
bs),(mfl :: Maybe Int
mfl,mfr :: Maybe Int
mfr,fs :: Bool
fs)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
horiz Maybe Int
collidedist Display
d Window
w
Int -> X Int
forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> X Int) -> Int -> X Int
forall a b. (a -> b) -> a -> b
$ if Bool
bs Bool -> Bool -> Bool
|| Bool
fs
then WindowAttributes -> Int
wpos WindowAttributes
wa
else let b :: Int
b = case (Maybe Int
mbl,Maybe Int
mbr) of
(Just bl :: Int
bl,Just br :: Int
br) -> if WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
bl Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
br Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa then Int
bl else Int
br
(Just bl :: Int
bl,Nothing) -> Int
bl
(Nothing,Just br :: Int
br) -> Int
br
(Nothing,Nothing) -> WindowAttributes -> Int
wpos WindowAttributes
wa
f :: Int
f = case (Maybe Int
mfl,Maybe Int
mfr) of
(Just fl :: Int
fl,Just fr :: Int
fr) -> if WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
fl Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
fr Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa then Int
fl else Int
fr
(Just fl :: Int
fl,Nothing) -> Int
fl
(Nothing,Just fr :: Int
fr) -> Int
fr
(Nothing,Nothing) -> WindowAttributes -> Int
wpos WindowAttributes
wa
newpos :: Int
newpos = if Int -> Int
forall a. Num a => a -> a
abs (Int
b Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int -> Int
forall a. Num a => a -> a
abs (Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa) then Int
b else (Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa)
in if Maybe Int -> Bool
forall a. Maybe a -> Bool
isNothing Maybe Int
snapdist Bool -> Bool -> Bool
|| Int -> Int
forall a. Num a => a -> a
abs (Int
newpos Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wpos WindowAttributes
wa) Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Maybe Int -> Int
forall a. HasCallStack => Maybe a -> a
fromJust Maybe Int
snapdist then Int
newpos else (WindowAttributes -> Int
wpos WindowAttributes
wa)
where
(wpos :: WindowAttributes -> Int
wpos, wdim :: WindowAttributes -> Int
wdim, _, _) = Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
constructors Bool
horiz
snapMove
:: Direction2D
-> Maybe Int
-> Window
-> X ()
snapMove :: Direction2D -> Maybe Int -> Window -> X ()
snapMove L = Bool -> Bool -> Maybe Int -> Window -> X ()
doSnapMove Bool
True Bool
True
snapMove R = Bool -> Bool -> Maybe Int -> Window -> X ()
doSnapMove Bool
True Bool
False
snapMove U = Bool -> Bool -> Maybe Int -> Window -> X ()
doSnapMove Bool
False Bool
True
snapMove D = Bool -> Bool -> Maybe Int -> Window -> X ()
doSnapMove Bool
False Bool
False
doSnapMove :: Bool -> Bool -> Maybe Int -> Window -> X ()
doSnapMove :: Bool -> Bool -> Maybe Int -> Window -> X ()
doSnapMove horiz :: Bool
horiz rev :: Bool
rev collidedist :: Maybe Int
collidedist w :: Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \d :: Display
d -> do
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO ()
raiseWindow Display
d Window
w
WindowAttributes
wa <- IO WindowAttributes -> X WindowAttributes
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO WindowAttributes -> X WindowAttributes)
-> IO WindowAttributes -> X WindowAttributes
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d Window
w
((bl :: Maybe Int
bl,br :: Maybe Int
br,_),(fl :: Maybe Int
fl,fr :: Maybe Int
fr,_)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
horiz Maybe Int
collidedist Display
d Window
w
let (mb :: Maybe Int
mb,mf :: Maybe Int
mf) = if Bool
rev then (Maybe Int
bl,Maybe Int
fl)
else (Maybe Int
br,Maybe Int
fr)
newpos :: Position
newpos = Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Position) -> Int -> Position
forall a b. (a -> b) -> a -> b
$ case (Maybe Int
mb,Maybe Int
mf) of
(Just b :: Int
b,Nothing) -> Int
b
(Nothing,Just f :: Int
f) -> Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa
(Just b :: Int
b,Just f :: Int
f) -> if Bool
rev Bool -> Bool -> Bool
forall a. Eq a => a -> a -> Bool
/= (Int
b Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa)
then Int
b
else Int
f Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wdim WindowAttributes
wa
_ -> WindowAttributes -> Int
wpos WindowAttributes
wa
if Bool
horiz then IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w Position
newpos (CInt -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Position) -> CInt -> Position
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_y WindowAttributes
wa)
else IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w (CInt -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (CInt -> Position) -> CInt -> Position
forall a b. (a -> b) -> a -> b
$ WindowAttributes -> CInt
wa_x WindowAttributes
wa) Position
newpos
Window -> X ()
float Window
w
where
(wpos :: WindowAttributes -> Int
wpos, wdim :: WindowAttributes -> Int
wdim, _, _) = Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
constructors Bool
horiz
snapGrow
:: Direction2D
-> Maybe Int
-> Window
-> X ()
snapGrow :: Direction2D -> Maybe Int -> Window -> X ()
snapGrow = Bool -> Direction2D -> Maybe Int -> Window -> X ()
snapResize Bool
True
snapShrink
:: Direction2D
-> Maybe Int
-> Window
-> X ()
snapShrink :: Direction2D -> Maybe Int -> Window -> X ()
snapShrink = Bool -> Direction2D -> Maybe Int -> Window -> X ()
snapResize Bool
False
snapResize :: Bool -> Direction2D -> Maybe Int -> Window -> X ()
snapResize :: Bool -> Direction2D -> Maybe Int -> Window -> X ()
snapResize grow :: Bool
grow dir :: Direction2D
dir collidedist :: Maybe Int
collidedist w :: Window
w = X Bool -> X () -> X ()
whenX (Window -> X Bool
isClient Window
w) (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \d :: Display
d -> do
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO ()
raiseWindow Display
d Window
w
WindowAttributes
wa <- IO WindowAttributes -> X WindowAttributes
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO WindowAttributes -> X WindowAttributes)
-> IO WindowAttributes -> X WindowAttributes
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d Window
w
Maybe (Int, Int, Int, Int)
mr <- case Direction2D
dir of
L -> do ((mg :: Maybe Int
mg,ms :: Maybe Int
ms,_),(_,_,_)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
True Maybe Int
collidedist Display
d Window
w
Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int)))
-> Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall a b. (a -> b) -> a -> b
$ case (if Bool
grow then Maybe Int
mg else Maybe Int
ms) of
Just v :: Int
v -> (Int, Int, Int, Int) -> Maybe (Int, Int, Int, Int)
forall a. a -> Maybe a
Just (Int
v, WindowAttributes -> Int
wy WindowAttributes
wa, WindowAttributes -> Int
ww WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wx WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
v, WindowAttributes -> Int
wh WindowAttributes
wa)
_ -> Maybe (Int, Int, Int, Int)
forall a. Maybe a
Nothing
R -> do ((_,_,_),(ms :: Maybe Int
ms,mg :: Maybe Int
mg,_)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
True Maybe Int
collidedist Display
d Window
w
Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int)))
-> Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall a b. (a -> b) -> a -> b
$ case (if Bool
grow then Maybe Int
mg else Maybe Int
ms) of
Just v :: Int
v -> (Int, Int, Int, Int) -> Maybe (Int, Int, Int, Int)
forall a. a -> Maybe a
Just (WindowAttributes -> Int
wx WindowAttributes
wa, WindowAttributes -> Int
wy WindowAttributes
wa, Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wx WindowAttributes
wa, WindowAttributes -> Int
wh WindowAttributes
wa)
_ -> Maybe (Int, Int, Int, Int)
forall a. Maybe a
Nothing
U -> do ((mg :: Maybe Int
mg,ms :: Maybe Int
ms,_),(_,_,_)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
False Maybe Int
collidedist Display
d Window
w
Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int)))
-> Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall a b. (a -> b) -> a -> b
$ case (if Bool
grow then Maybe Int
mg else Maybe Int
ms) of
Just v :: Int
v -> (Int, Int, Int, Int) -> Maybe (Int, Int, Int, Int)
forall a. a -> Maybe a
Just (WindowAttributes -> Int
wx WindowAttributes
wa, Int
v, WindowAttributes -> Int
ww WindowAttributes
wa, WindowAttributes -> Int
wh WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wy WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
v)
_ -> Maybe (Int, Int, Int, Int)
forall a. Maybe a
Nothing
D -> do ((_,_,_),(ms :: Maybe Int
ms,mg :: Maybe Int
mg,_)) <- Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap Bool
False Maybe Int
collidedist Display
d Window
w
Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int)))
-> Maybe (Int, Int, Int, Int) -> X (Maybe (Int, Int, Int, Int))
forall a b. (a -> b) -> a -> b
$ case (if Bool
grow then Maybe Int
mg else Maybe Int
ms) of
Just v :: Int
v -> (Int, Int, Int, Int) -> Maybe (Int, Int, Int, Int)
forall a. a -> Maybe a
Just (WindowAttributes -> Int
wx WindowAttributes
wa, WindowAttributes -> Int
wy WindowAttributes
wa, WindowAttributes -> Int
ww WindowAttributes
wa, Int
v Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wy WindowAttributes
wa)
_ -> Maybe (Int, Int, Int, Int)
forall a. Maybe a
Nothing
case Maybe (Int, Int, Int, Int)
mr of
Nothing -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Just (nx :: Int
nx,ny :: Int
ny,nw :: Int
nw,nh :: Int
nh) -> if Int
nwInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>0 Bool -> Bool -> Bool
&& Int
nhInt -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>0 then do IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Position -> Position -> IO ()
moveWindow Display
d Window
w (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nx) (Int -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
ny)
IO () -> X ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> X ()) -> IO () -> X ()
forall a b. (a -> b) -> a -> b
$ Display -> Window -> Dimension -> Dimension -> IO ()
resizeWindow Display
d Window
w (Int -> Dimension
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nw) (Int -> Dimension
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
nh)
else () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Window -> X ()
float Window
w
where
wx :: WindowAttributes -> Int
wx = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_x
wy :: WindowAttributes -> Int
wy = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_y
ww :: WindowAttributes -> Int
ww = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_width
wh :: WindowAttributes -> Int
wh = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_height
getSnap :: Bool -> Maybe Int -> Display -> Window -> X ((Maybe Int,Maybe Int,Bool),(Maybe Int,Maybe Int,Bool))
getSnap :: Bool
-> Maybe Int
-> Display
-> Window
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
getSnap horiz :: Bool
horiz collidedist :: Maybe Int
collidedist d :: Display
d w :: Window
w = do
WindowAttributes
wa <- IO WindowAttributes -> X WindowAttributes
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO WindowAttributes -> X WindowAttributes)
-> IO WindowAttributes -> X WindowAttributes
forall a b. (a -> b) -> a -> b
$ Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d Window
w
Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
screen <- StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X (StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X (Screen
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
-> X (StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet
WorkspaceId (Layout Window) Window ScreenId ScreenDetail
windowset
let sr :: Rectangle
sr = ScreenDetail -> Rectangle
screenRect (ScreenDetail -> Rectangle) -> ScreenDetail -> Rectangle
forall a b. (a -> b) -> a -> b
$ Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> ScreenDetail
forall i l a sid sd. Screen i l a sid sd -> sd
W.screenDetail Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
screen
wl :: [Window]
wl = Maybe (Stack Window) -> [Window]
forall a. Maybe (Stack a) -> [a]
W.integrate' (Maybe (Stack Window) -> [Window])
-> (Workspace WorkspaceId (Layout Window) Window
-> Maybe (Stack Window))
-> Workspace WorkspaceId (Layout Window) Window
-> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace WorkspaceId (Layout Window) Window
-> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack (Workspace WorkspaceId (Layout Window) Window -> [Window])
-> Workspace WorkspaceId (Layout Window) Window -> [Window]
forall a b. (a -> b) -> a -> b
$ Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
-> Workspace WorkspaceId (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
screen
Rectangle
gr <- ((Rectangle -> Rectangle) -> Rectangle)
-> X (Rectangle -> Rectangle) -> X Rectangle
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Rectangle -> Rectangle) -> Rectangle -> Rectangle
forall a b. (a -> b) -> a -> b
$Rectangle
sr) (X (Rectangle -> Rectangle) -> X Rectangle)
-> X (Rectangle -> Rectangle) -> X Rectangle
forall a b. (a -> b) -> a -> b
$ Set Direction2D -> X (Rectangle -> Rectangle)
calcGap (Set Direction2D -> X (Rectangle -> Rectangle))
-> Set Direction2D -> X (Rectangle -> Rectangle)
forall a b. (a -> b) -> a -> b
$ [Direction2D] -> Set Direction2D
forall a. Ord a => [a] -> Set a
S.fromList [Direction2D
forall a. Bounded a => a
minBound .. Direction2D
forall a. Bounded a => a
maxBound]
[WindowAttributes]
wla <- (WindowAttributes -> Bool)
-> [WindowAttributes] -> [WindowAttributes]
forall a. (a -> Bool) -> [a] -> [a]
filter (WindowAttributes -> WindowAttributes -> Bool
collides WindowAttributes
wa) ([WindowAttributes] -> [WindowAttributes])
-> X [WindowAttributes] -> X [WindowAttributes]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
`fmap` (IO [WindowAttributes] -> X [WindowAttributes]
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO [WindowAttributes] -> X [WindowAttributes])
-> IO [WindowAttributes] -> X [WindowAttributes]
forall a b. (a -> b) -> a -> b
$ (Window -> IO WindowAttributes)
-> [Window] -> IO [WindowAttributes]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Display -> Window -> IO WindowAttributes
getWindowAttributes Display
d) ([Window] -> IO [WindowAttributes])
-> [Window] -> IO [WindowAttributes]
forall a b. (a -> b) -> a -> b
$ (Window -> Bool) -> [Window] -> [Window]
forall a. (a -> Bool) -> [a] -> [a]
filter (Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
/=Window
w) [Window]
wl)
((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
-> X ((Maybe Int, Maybe Int, Bool), (Maybe Int, Maybe Int, Bool))
forall (m :: * -> *) a. Monad m => a -> m a
return ( [Int] -> Int -> (Maybe Int, Maybe Int, Bool)
forall a. Ord a => [a] -> a -> (Maybe a, Maybe a, Bool)
neighbours (WindowAttributes
-> Rectangle -> Rectangle -> [WindowAttributes] -> [Int]
forall (t :: * -> *).
Foldable t =>
WindowAttributes
-> Rectangle -> Rectangle -> t WindowAttributes -> [Int]
back WindowAttributes
wa Rectangle
sr Rectangle
gr [WindowAttributes]
wla) (WindowAttributes -> Int
wpos WindowAttributes
wa)
, [Int] -> Int -> (Maybe Int, Maybe Int, Bool)
forall a. Ord a => [a] -> a -> (Maybe a, Maybe a, Bool)
neighbours (WindowAttributes
-> Rectangle -> Rectangle -> [WindowAttributes] -> [Int]
forall (t :: * -> *).
Foldable t =>
WindowAttributes
-> Rectangle -> Rectangle -> t WindowAttributes -> [Int]
front WindowAttributes
wa Rectangle
sr Rectangle
gr [WindowAttributes]
wla) (WindowAttributes -> Int
wpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
wa)
)
where
wborder :: WindowAttributes -> Int
wborder = CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_border_width
(wpos :: WindowAttributes -> Int
wpos, wdim :: WindowAttributes -> Int
wdim, rpos :: Rectangle -> Int
rpos, rdim :: Rectangle -> Int
rdim) = Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
constructors Bool
horiz
(refwpos :: WindowAttributes -> Int
refwpos, refwdim :: WindowAttributes -> Int
refwdim, _, _) = Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
constructors (Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int))
-> Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
forall a b. (a -> b) -> a -> b
$ Bool -> Bool
not Bool
horiz
back :: WindowAttributes
-> Rectangle -> Rectangle -> t WindowAttributes -> [Int]
back wa :: WindowAttributes
wa sr :: Rectangle
sr gr :: Rectangle
gr wla :: t WindowAttributes
wla = (Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Rectangle -> Int
rpos Rectangle
sr) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$
(Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Rectangle -> Int
rpos Rectangle
sr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Rectangle -> Int
rdim Rectangle
sr) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$
[Int] -> [Int]
forall a. Ord a => [a] -> [a]
sort ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Rectangle -> Int
rpos Rectangle
sr)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:(Rectangle -> Int
rpos Rectangle
gr)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:(Rectangle -> Int
rpos Rectangle
gr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Rectangle -> Int
rdim Rectangle
gr)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:
(WindowAttributes -> [Int] -> [Int])
-> [Int] -> t WindowAttributes -> [Int]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a :: WindowAttributes
a as :: [Int]
as -> (WindowAttributes -> Int
wpos WindowAttributes
a)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:(WindowAttributes -> Int
wpos WindowAttributes
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wborder WindowAttributes
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wborder WindowAttributes
wa)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
as) [] t WindowAttributes
wla
front :: WindowAttributes
-> Rectangle -> Rectangle -> t WindowAttributes -> [Int]
front wa :: WindowAttributes
wa sr :: Rectangle
sr gr :: Rectangle
gr wla :: t WindowAttributes
wla = (Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Rectangle -> Int
rpos Rectangle
sr) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$
(Int -> Bool) -> [Int] -> [Int]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Rectangle -> Int
rpos Rectangle
sr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Rectangle -> Int
rdim Rectangle
sr) ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$
[Int] -> [Int]
forall a. Ord a => [a] -> [a]
sort ([Int] -> [Int]) -> [Int] -> [Int]
forall a b. (a -> b) -> a -> b
$ (Rectangle -> Int
rpos Rectangle
gr Int -> Int -> Int
forall a. Num a => a -> a -> a
- 2Int -> Int -> Int
forall a. Num a => a -> a -> a
*WindowAttributes -> Int
wborder WindowAttributes
wa)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:(Rectangle -> Int
rpos Rectangle
gr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Rectangle -> Int
rdim Rectangle
gr Int -> Int -> Int
forall a. Num a => a -> a -> a
- 2Int -> Int -> Int
forall a. Num a => a -> a -> a
*WindowAttributes -> Int
wborder WindowAttributes
wa)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:(Rectangle -> Int
rpos Rectangle
sr Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Rectangle -> Int
rdim Rectangle
sr Int -> Int -> Int
forall a. Num a => a -> a -> a
- 2Int -> Int -> Int
forall a. Num a => a -> a -> a
*WindowAttributes -> Int
wborder WindowAttributes
wa)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:
(WindowAttributes -> [Int] -> [Int])
-> [Int] -> t WindowAttributes -> [Int]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (\a :: WindowAttributes
a as :: [Int]
as -> (WindowAttributes -> Int
wpos WindowAttributes
a Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wborder WindowAttributes
a Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wborder WindowAttributes
wa)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:(WindowAttributes -> Int
wpos WindowAttributes
a Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wdim WindowAttributes
a)Int -> [Int] -> [Int]
forall a. a -> [a] -> [a]
:[Int]
as) [] t WindowAttributes
wla
neighbours :: [a] -> a -> (Maybe a, Maybe a, Bool)
neighbours l :: [a]
l v :: a
v = ( [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe ([a] -> Maybe a) -> [a] -> Maybe a
forall a b. (a -> b) -> a -> b
$ [a] -> [a]
forall a. [a] -> [a]
reverse ([a] -> [a]) -> [a] -> [a]
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
< a
v) [a]
l
, [a] -> Maybe a
forall a. [a] -> Maybe a
listToMaybe ([a] -> Maybe a) -> [a] -> Maybe a
forall a b. (a -> b) -> a -> b
$ (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
dropWhile (a -> a -> Bool
forall a. Ord a => a -> a -> Bool
<= a
v) [a]
l
, a
v a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [a]
l
)
collides :: WindowAttributes -> WindowAttributes -> Bool
collides wa :: WindowAttributes
wa oa :: WindowAttributes
oa = case Maybe Int
collidedist of
Nothing -> Bool
True
Just dist :: Int
dist -> ( WindowAttributes -> Int
refwpos WindowAttributes
oa Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wborder WindowAttributes
oa Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< WindowAttributes -> Int
refwpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
refwdim WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wborder WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
dist
Bool -> Bool -> Bool
&& WindowAttributes -> Int
refwpos WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- WindowAttributes -> Int
wborder WindowAttributes
wa Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
dist Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< WindowAttributes -> Int
refwpos WindowAttributes
oa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
refwdim WindowAttributes
oa Int -> Int -> Int
forall a. Num a => a -> a -> a
+ WindowAttributes -> Int
wborder WindowAttributes
oa )
constructors :: Bool -> (WindowAttributes -> Int, WindowAttributes -> Int, Rectangle -> Int, Rectangle -> Int)
constructors :: Bool
-> (WindowAttributes -> Int, WindowAttributes -> Int,
Rectangle -> Int, Rectangle -> Int)
constructors True = ( CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_x
, CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_width
, Position -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(Position -> Int) -> (Rectangle -> Position) -> Rectangle -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Rectangle -> Position
rect_x
, Dimension -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(Dimension -> Int) -> (Rectangle -> Dimension) -> Rectangle -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Rectangle -> Dimension
rect_width
)
constructors False = ( CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_y
, CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(CInt -> Int)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.WindowAttributes -> CInt
wa_height
, Position -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(Position -> Int) -> (Rectangle -> Position) -> Rectangle -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Rectangle -> Position
rect_y
, Dimension -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral(Dimension -> Int) -> (Rectangle -> Dimension) -> Rectangle -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Rectangle -> Dimension
rect_height
)