{-# LANGUAGE MultiParamTypeClasses, PatternGuards, RankNTypes, TypeSynonymInstances #-}
module XMonad.Actions.Navigation2D (
navigation2D
, navigation2DP
, additionalNav2DKeys
, additionalNav2DKeysP
, withNavigation2DConfig
, Navigation2DConfig(..)
, def
, Navigation2D
, lineNavigation
, centerNavigation
, sideNavigation
, sideNavigationWithBias
, hybridOf
, hybridNavigation
, fullScreenRect
, singleWindowRect
, switchLayer
, windowGo
, windowSwap
, windowToScreen
, screenGo
, screenSwap
, Direction2D(..)
) where
import qualified Data.List as L
import qualified Data.Map as M
import Control.Arrow (second)
import XMonad.Prelude
import XMonad hiding (Screen)
import qualified XMonad.StackSet as W
import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Util.EZConfig (additionalKeys, additionalKeysP)
import XMonad.Util.Types
type Rect a = (a, Rectangle)
type WinRect = Rect Window
type WSRect = Rect WorkspaceId
data Navigation2D = N Generality (forall a . Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
runNav :: forall a . Eq a => Navigation2D -> (Direction2D -> Rect a -> [Rect a] -> Maybe a)
runNav :: Navigation2D -> Direction2D -> Rect a -> [Rect a] -> Maybe a
runNav (N Generality
_ forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
nav) = Direction2D -> Rect a -> [Rect a] -> Maybe a
forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
nav
type Generality = Int
instance Eq Navigation2D where
(N Generality
x forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
_) == :: Navigation2D -> Navigation2D -> Bool
== (N Generality
y forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
_) = Generality
x Generality -> Generality -> Bool
forall a. Eq a => a -> a -> Bool
== Generality
y
instance Ord Navigation2D where
(N Generality
x forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
_) <= :: Navigation2D -> Navigation2D -> Bool
<= (N Generality
y forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
_) = Generality
x Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
<= Generality
y
lineNavigation :: Navigation2D
lineNavigation :: Navigation2D
lineNavigation = Generality
-> (forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D
N Generality
1 forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
doLineNavigation
centerNavigation :: Navigation2D
centerNavigation :: Navigation2D
centerNavigation = Generality
-> (forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D
N Generality
2 forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
doCenterNavigation
sideNavigation :: Navigation2D
sideNavigation :: Navigation2D
sideNavigation = Generality
-> (forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D
N Generality
1 (Generality -> Direction2D -> Rect a -> [Rect a] -> Maybe a
forall a.
Eq a =>
Generality -> Direction2D -> Rect a -> [Rect a] -> Maybe a
doSideNavigationWithBias Generality
1)
sideNavigationWithBias :: Int -> Navigation2D
sideNavigationWithBias :: Generality -> Navigation2D
sideNavigationWithBias Generality
b = Generality
-> (forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D
N Generality
1 (Generality -> Direction2D -> Rect a -> [Rect a] -> Maybe a
forall a.
Eq a =>
Generality -> Direction2D -> Rect a -> [Rect a] -> Maybe a
doSideNavigationWithBias Generality
b)
hybridOf :: Navigation2D -> Navigation2D -> Navigation2D
hybridOf :: Navigation2D -> Navigation2D -> Navigation2D
hybridOf (N Generality
g1 forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
s1) (N Generality
g2 forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
s2) = Generality
-> (forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D
N (Generality -> Generality -> Generality
forall a. Ord a => a -> a -> a
max Generality
g1 Generality
g2) ((forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D)
-> (forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Navigation2D
forall a b. (a -> b) -> a -> b
$ (Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> (Direction2D -> Rect a -> [Rect a] -> Maybe a)
-> Direction2D
-> Rect a
-> [Rect a]
-> Maybe a
forall (f :: * -> *) t t t a.
Alternative f =>
(t -> t -> t -> f a) -> (t -> t -> t -> f a) -> t -> t -> t -> f a
applyToBoth Direction2D -> Rect a -> [Rect a] -> Maybe a
forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
s1 Direction2D -> Rect a -> [Rect a] -> Maybe a
forall a. Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
s2
where
applyToBoth :: (t -> t -> t -> f a) -> (t -> t -> t -> f a) -> t -> t -> t -> f a
applyToBoth t -> t -> t -> f a
f t -> t -> t -> f a
g t
a t
b t
c = t -> t -> t -> f a
f t
a t
b t
c f a -> f a -> f a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> t -> t -> t -> f a
g t
a t
b t
c
{-# DEPRECATED hybridNavigation "Use hybridOf with lineNavigation and centerNavigation as arguments." #-}
hybridNavigation :: Navigation2D
hybridNavigation :: Navigation2D
hybridNavigation = Navigation2D -> Navigation2D -> Navigation2D
hybridOf Navigation2D
lineNavigation Navigation2D
centerNavigation
data Navigation2DConfig = Navigation2DConfig
{ Navigation2DConfig -> Navigation2D
defaultTiledNavigation :: Navigation2D
, Navigation2DConfig -> Navigation2D
floatNavigation :: Navigation2D
, Navigation2DConfig -> Navigation2D
screenNavigation :: Navigation2D
, Navigation2DConfig -> [(String, Navigation2D)]
layoutNavigation :: [(String, Navigation2D)]
, Navigation2DConfig
-> [(String, Screen -> Window -> X (Maybe Rectangle))]
unmappedWindowRect :: [(String, Screen -> Window -> X (Maybe Rectangle))]
}
type Screen = W.Screen WorkspaceId (Layout Window) Window ScreenId ScreenDetail
navigation2D :: Navigation2DConfig -> (KeySym, KeySym, KeySym, KeySym) -> [(ButtonMask, Direction2D -> Bool -> X ())] ->
Bool -> XConfig l -> XConfig l
navigation2D :: Navigation2DConfig
-> (Window, Window, Window, Window)
-> [(ButtonMask, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
navigation2D Navigation2DConfig
navConfig (Window
u, Window
l, Window
d, Window
r) [(ButtonMask, Direction2D -> Bool -> X ())]
modifiers Bool
wrap XConfig l
xconfig =
(Window, Window, Window, Window)
-> [(ButtonMask, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
forall (l :: * -> *).
(Window, Window, Window, Window)
-> [(ButtonMask, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
additionalNav2DKeys (Window
u, Window
l, Window
d, Window
r) [(ButtonMask, Direction2D -> Bool -> X ())]
modifiers Bool
wrap (XConfig l -> XConfig l) -> XConfig l -> XConfig l
forall a b. (a -> b) -> a -> b
$
Navigation2DConfig -> XConfig l -> XConfig l
forall (a :: * -> *). Navigation2DConfig -> XConfig a -> XConfig a
withNavigation2DConfig Navigation2DConfig
navConfig XConfig l
xconfig
navigation2DP :: Navigation2DConfig -> (String, String, String, String) -> [(String, Direction2D -> Bool -> X ())] ->
Bool -> XConfig l -> XConfig l
navigation2DP :: Navigation2DConfig
-> (String, String, String, String)
-> [(String, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
navigation2DP Navigation2DConfig
navConfig (String
u, String
l, String
d, String
r) [(String, Direction2D -> Bool -> X ())]
modifiers Bool
wrap XConfig l
xconfig =
(String, String, String, String)
-> [(String, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
forall (l :: * -> *).
(String, String, String, String)
-> [(String, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
additionalNav2DKeysP (String
u, String
l, String
d, String
r) [(String, Direction2D -> Bool -> X ())]
modifiers Bool
wrap (XConfig l -> XConfig l) -> XConfig l -> XConfig l
forall a b. (a -> b) -> a -> b
$
Navigation2DConfig -> XConfig l -> XConfig l
forall (a :: * -> *). Navigation2DConfig -> XConfig a -> XConfig a
withNavigation2DConfig Navigation2DConfig
navConfig XConfig l
xconfig
additionalNav2DKeys :: (KeySym, KeySym, KeySym, KeySym) -> [(ButtonMask, Direction2D -> Bool -> X ())] ->
Bool -> XConfig l -> XConfig l
additionalNav2DKeys :: (Window, Window, Window, Window)
-> [(ButtonMask, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
additionalNav2DKeys (Window
u, Window
l, Window
d, Window
r) [(ButtonMask, Direction2D -> Bool -> X ())]
modifiers Bool
wrap =
(XConfig l -> [((ButtonMask, Window), X ())] -> XConfig l)
-> [((ButtonMask, Window), X ())] -> XConfig l -> XConfig l
forall a b c. (a -> b -> c) -> b -> a -> c
flip XConfig l -> [((ButtonMask, Window), X ())] -> XConfig l
forall (a :: * -> *).
XConfig a -> [((ButtonMask, Window), X ())] -> XConfig a
additionalKeys [((ButtonMask
modif, Window
k), Direction2D -> Bool -> X ()
func Direction2D
dir Bool
wrap) | (ButtonMask
modif, Direction2D -> Bool -> X ()
func) <- [(ButtonMask, Direction2D -> Bool -> X ())]
modifiers, (Window
k, Direction2D
dir) <- [(Window, Direction2D)]
dirKeys]
where dirKeys :: [(Window, Direction2D)]
dirKeys = [(Window
u, Direction2D
U), (Window
l, Direction2D
L), (Window
d, Direction2D
D), (Window
r, Direction2D
R)]
additionalNav2DKeysP :: (String, String, String, String) -> [(String, Direction2D -> Bool -> X ())] ->
Bool -> XConfig l -> XConfig l
additionalNav2DKeysP :: (String, String, String, String)
-> [(String, Direction2D -> Bool -> X ())]
-> Bool
-> XConfig l
-> XConfig l
additionalNav2DKeysP (String
u, String
l, String
d, String
r) [(String, Direction2D -> Bool -> X ())]
modifiers Bool
wrap =
(XConfig l -> [(String, X ())] -> XConfig l)
-> [(String, X ())] -> XConfig l -> XConfig l
forall a b c. (a -> b -> c) -> b -> a -> c
flip XConfig l -> [(String, X ())] -> XConfig l
forall (l :: * -> *). XConfig l -> [(String, X ())] -> XConfig l
additionalKeysP [(String
modif String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
k, Direction2D -> Bool -> X ()
func Direction2D
dir Bool
wrap) | (String
modif, Direction2D -> Bool -> X ()
func) <- [(String, Direction2D -> Bool -> X ())]
modifiers, (String
k, Direction2D
dir) <- [(String, Direction2D)]
dirKeys]
where dirKeys :: [(String, Direction2D)]
dirKeys = [(String
u, Direction2D
U), (String
l, Direction2D
L), (String
d, Direction2D
D), (String
r, Direction2D
R)]
instance ExtensionClass Navigation2DConfig where
initialValue :: Navigation2DConfig
initialValue = Navigation2DConfig
forall a. Default a => a
def
withNavigation2DConfig :: Navigation2DConfig -> XConfig a -> XConfig a
withNavigation2DConfig :: Navigation2DConfig -> XConfig a -> XConfig a
withNavigation2DConfig Navigation2DConfig
conf2d XConfig a
xconf = XConfig a
xconf { startupHook :: X ()
startupHook = XConfig a -> X ()
forall (l :: * -> *). XConfig l -> X ()
startupHook XConfig a
xconf
X () -> X () -> X ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Navigation2DConfig -> X ()
forall a (m :: * -> *). (ExtensionClass a, XLike m) => a -> m ()
XS.put Navigation2DConfig
conf2d
}
instance Default Navigation2DConfig where
def :: Navigation2DConfig
def = Navigation2DConfig :: Navigation2D
-> Navigation2D
-> Navigation2D
-> [(String, Navigation2D)]
-> [(String, Screen -> Window -> X (Maybe Rectangle))]
-> Navigation2DConfig
Navigation2DConfig { defaultTiledNavigation :: Navigation2D
defaultTiledNavigation = Navigation2D
lineNavigation
, floatNavigation :: Navigation2D
floatNavigation = Navigation2D
centerNavigation
, screenNavigation :: Navigation2D
screenNavigation = Navigation2D
lineNavigation
, layoutNavigation :: [(String, Navigation2D)]
layoutNavigation = []
, unmappedWindowRect :: [(String, Screen -> Window -> X (Maybe Rectangle))]
unmappedWindowRect = []
}
switchLayer :: X ()
switchLayer :: X ()
switchLayer = ([WinRect] -> [WinRect] -> [WinRect])
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WSRect -> [WSRect] -> X ())
-> Bool
-> X ()
actOnLayer [WinRect] -> [WinRect] -> [WinRect]
forall a. a -> a -> a
otherLayer
( \ Navigation2DConfig
_ WinRect
cur [WinRect]
wins -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ WinRect -> [WinRect] -> WindowSet -> WindowSet
doFocusClosestWindow WinRect
cur [WinRect]
wins
)
( \ Navigation2DConfig
_ WinRect
cur [WinRect]
wins -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ WinRect -> [WinRect] -> WindowSet -> WindowSet
doFocusClosestWindow WinRect
cur [WinRect]
wins
)
( \ Navigation2DConfig
_ WSRect
_ [WSRect]
_ -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return () )
Bool
False
windowGo :: Direction2D -> Bool -> X ()
windowGo :: Direction2D -> Bool -> X ()
windowGo Direction2D
dir = ([WinRect] -> [WinRect] -> [WinRect])
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WSRect -> [WSRect] -> X ())
-> Bool
-> X ()
actOnLayer [WinRect] -> [WinRect] -> [WinRect]
forall a. a -> a -> a
thisLayer
( \ Navigation2DConfig
conf WinRect
cur [WinRect]
wins -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> WindowSet
-> WindowSet
doTiledNavigation Navigation2DConfig
conf Direction2D
dir 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 WinRect
cur [WinRect]
wins
)
( \ Navigation2DConfig
conf WinRect
cur [WinRect]
wins -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> WindowSet
-> WindowSet
doFloatNavigation Navigation2DConfig
conf Direction2D
dir 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 WinRect
cur [WinRect]
wins
)
( \ Navigation2DConfig
conf WSRect
cur [WSRect]
wspcs -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (String -> WindowSet -> WindowSet)
-> WSRect
-> [WSRect]
-> WindowSet
-> WindowSet
doScreenNavigation Navigation2DConfig
conf Direction2D
dir String -> WindowSet -> WindowSet
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view WSRect
cur [WSRect]
wspcs
)
windowSwap :: Direction2D -> Bool -> X ()
windowSwap :: Direction2D -> Bool -> X ()
windowSwap Direction2D
dir = ([WinRect] -> [WinRect] -> [WinRect])
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WSRect -> [WSRect] -> X ())
-> Bool
-> X ()
actOnLayer [WinRect] -> [WinRect] -> [WinRect]
forall a. a -> a -> a
thisLayer
( \ Navigation2DConfig
conf WinRect
cur [WinRect]
wins -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> WindowSet
-> WindowSet
doTiledNavigation Navigation2DConfig
conf Direction2D
dir Window -> WindowSet -> WindowSet
swap WinRect
cur [WinRect]
wins
)
( \ Navigation2DConfig
conf WinRect
cur [WinRect]
wins -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> WindowSet
-> WindowSet
doFloatNavigation Navigation2DConfig
conf Direction2D
dir Window -> WindowSet -> WindowSet
swap WinRect
cur [WinRect]
wins
)
( \ Navigation2DConfig
_ WSRect
_ [WSRect]
_ -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return () )
windowToScreen :: Direction2D -> Bool -> X ()
windowToScreen :: Direction2D -> Bool -> X ()
windowToScreen Direction2D
dir = (Navigation2DConfig -> WSRect -> [WSRect] -> X ()) -> Bool -> X ()
actOnScreens ( \ Navigation2DConfig
conf WSRect
cur [WSRect]
wspcs -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (String -> WindowSet -> WindowSet)
-> WSRect
-> [WSRect]
-> WindowSet
-> WindowSet
doScreenNavigation Navigation2DConfig
conf Direction2D
dir String -> WindowSet -> WindowSet
forall a s i l sd.
(Ord a, Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.shift WSRect
cur [WSRect]
wspcs
)
screenGo :: Direction2D -> Bool -> X ()
screenGo :: Direction2D -> Bool -> X ()
screenGo Direction2D
dir = (Navigation2DConfig -> WSRect -> [WSRect] -> X ()) -> Bool -> X ()
actOnScreens ( \ Navigation2DConfig
conf WSRect
cur [WSRect]
wspcs -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (String -> WindowSet -> WindowSet)
-> WSRect
-> [WSRect]
-> WindowSet
-> WindowSet
doScreenNavigation Navigation2DConfig
conf Direction2D
dir String -> WindowSet -> WindowSet
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.view WSRect
cur [WSRect]
wspcs
)
screenSwap :: Direction2D -> Bool -> X ()
screenSwap :: Direction2D -> Bool -> X ()
screenSwap Direction2D
dir = (Navigation2DConfig -> WSRect -> [WSRect] -> X ()) -> Bool -> X ()
actOnScreens ( \ Navigation2DConfig
conf WSRect
cur [WSRect]
wspcs -> (WindowSet -> WindowSet) -> X ()
windows
((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ Navigation2DConfig
-> Direction2D
-> (String -> WindowSet -> WindowSet)
-> WSRect
-> [WSRect]
-> WindowSet
-> WindowSet
doScreenNavigation Navigation2DConfig
conf Direction2D
dir String -> WindowSet -> WindowSet
forall s i l a sd.
(Eq s, Eq i) =>
i -> StackSet i l a s sd -> StackSet i l a s sd
W.greedyView WSRect
cur [WSRect]
wspcs
)
fullScreenRect :: Screen -> Window -> X (Maybe Rectangle)
fullScreenRect :: Screen -> Window -> X (Maybe Rectangle)
fullScreenRect Screen
scr Window
_ = Maybe Rectangle -> X (Maybe Rectangle)
forall (m :: * -> *) a. Monad m => a -> m a
return (Rectangle -> Maybe Rectangle
forall a. a -> Maybe a
Just (Rectangle -> Maybe Rectangle)
-> (Screen -> Rectangle) -> Screen -> Maybe Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ScreenDetail -> Rectangle
screenRect (ScreenDetail -> Rectangle)
-> (Screen -> ScreenDetail) -> Screen -> Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> ScreenDetail
forall i l a sid sd. Screen i l a sid sd -> sd
W.screenDetail (Screen -> Maybe Rectangle) -> Screen -> Maybe Rectangle
forall a b. (a -> b) -> a -> b
$ Screen
scr)
singleWindowRect :: Screen -> Window -> X (Maybe Rectangle)
singleWindowRect :: Screen -> Window -> X (Maybe Rectangle)
singleWindowRect Screen
scr Window
win = [Rectangle] -> Maybe Rectangle
forall a. [a] -> Maybe a
listToMaybe
([Rectangle] -> Maybe Rectangle)
-> (([WinRect], Maybe (Layout Window)) -> [Rectangle])
-> ([WinRect], Maybe (Layout Window))
-> Maybe Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WinRect -> Rectangle) -> [WinRect] -> [Rectangle]
forall a b. (a -> b) -> [a] -> [b]
map WinRect -> Rectangle
forall a b. (a, b) -> b
snd
([WinRect] -> [Rectangle])
-> (([WinRect], Maybe (Layout Window)) -> [WinRect])
-> ([WinRect], Maybe (Layout Window))
-> [Rectangle]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([WinRect], Maybe (Layout Window)) -> [WinRect]
forall a b. (a, b) -> a
fst
(([WinRect], Maybe (Layout Window)) -> Maybe Rectangle)
-> X ([WinRect], Maybe (Layout Window)) -> X (Maybe Rectangle)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Workspace String (Layout Window) Window
-> Rectangle -> X ([WinRect], Maybe (Layout Window))
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace String (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout ((Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace Screen
scr) { stack :: Maybe (Stack Window)
W.stack = [Window] -> Maybe (Stack Window)
forall a. [a] -> Maybe (Stack a)
W.differentiate [Window
win] })
(ScreenDetail -> Rectangle
screenRect (ScreenDetail -> Rectangle)
-> (Screen -> ScreenDetail) -> Screen -> Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> ScreenDetail
forall i l a sid sd. Screen i l a sid sd -> sd
W.screenDetail (Screen -> Rectangle) -> Screen -> Rectangle
forall a b. (a -> b) -> a -> b
$ Screen
scr)
actOnLayer :: ([WinRect] -> [WinRect] -> [WinRect])
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WSRect -> [WSRect] -> X ())
-> Bool
-> X ()
actOnLayer :: ([WinRect] -> [WinRect] -> [WinRect])
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WinRect -> [WinRect] -> X ())
-> (Navigation2DConfig -> WSRect -> [WSRect] -> X ())
-> Bool
-> X ()
actOnLayer [WinRect] -> [WinRect] -> [WinRect]
choice Navigation2DConfig -> WinRect -> [WinRect] -> X ()
tiledact Navigation2DConfig -> WinRect -> [WinRect] -> X ()
floatact Navigation2DConfig -> WSRect -> [WSRect] -> X ()
wsact Bool
wrap = (WindowSet -> X ()) -> X ()
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X ()) -> X ()) -> (WindowSet -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \WindowSet
winset -> do
Navigation2DConfig
conf <- X Navigation2DConfig
forall a (m :: * -> *). (ExtensionClass a, XLike m) => m a
XS.get
([WinRect]
floating, [WinRect]
tiled) <- Navigation2DConfig -> Bool -> WindowSet -> X ([WinRect], [WinRect])
navigableWindows Navigation2DConfig
conf Bool
wrap WindowSet
winset
let cur :: Maybe Window
cur = WindowSet -> Maybe Window
forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek WindowSet
winset
case Maybe Window
cur of
Maybe Window
Nothing -> (Navigation2DConfig -> WSRect -> [WSRect] -> X ()) -> Bool -> X ()
actOnScreens Navigation2DConfig -> WSRect -> [WSRect] -> X ()
wsact Bool
wrap
Just Window
w | Just Rectangle
rect <- Window -> [WinRect] -> Maybe Rectangle
forall a b. Eq a => a -> [(a, b)] -> Maybe b
L.lookup Window
w [WinRect]
tiled -> Navigation2DConfig -> WinRect -> [WinRect] -> X ()
tiledact Navigation2DConfig
conf (Window
w, Rectangle
rect) ([WinRect] -> [WinRect] -> [WinRect]
choice [WinRect]
tiled [WinRect]
floating)
| Just Rectangle
rect <- Window -> [WinRect] -> Maybe Rectangle
forall a b. Eq a => a -> [(a, b)] -> Maybe b
L.lookup Window
w [WinRect]
floating -> Navigation2DConfig -> WinRect -> [WinRect] -> X ()
floatact Navigation2DConfig
conf (Window
w, Rectangle
rect) ([WinRect] -> [WinRect] -> [WinRect]
choice [WinRect]
floating [WinRect]
tiled)
| Bool
otherwise -> () -> X ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
navigableWindows :: Navigation2DConfig -> Bool -> WindowSet -> X ([WinRect], [WinRect])
navigableWindows :: Navigation2DConfig -> Bool -> WindowSet -> X ([WinRect], [WinRect])
navigableWindows Navigation2DConfig
conf Bool
wrap WindowSet
winset = (WinRect -> Bool) -> [WinRect] -> ([WinRect], [WinRect])
forall a. (a -> Bool) -> [a] -> ([a], [a])
L.partition (\(Window
win, Rectangle
_) -> Window -> Map Window RationalRect -> Bool
forall k a. Ord k => k -> Map k a -> Bool
M.member Window
win (WindowSet -> Map Window RationalRect
forall i l a sid sd. StackSet i l a sid sd -> Map a RationalRect
W.floating WindowSet
winset))
([WinRect] -> ([WinRect], [WinRect]))
-> ([[Maybe WinRect]] -> [WinRect])
-> [[Maybe WinRect]]
-> ([WinRect], [WinRect])
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> Bool -> [WinRect] -> [WinRect]
forall a. WindowSet -> Bool -> [Rect a] -> [Rect a]
addWrapping WindowSet
winset Bool
wrap
([WinRect] -> [WinRect])
-> ([[Maybe WinRect]] -> [WinRect])
-> [[Maybe WinRect]]
-> [WinRect]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Maybe WinRect] -> [WinRect]
forall a. [Maybe a] -> [a]
catMaybes
([Maybe WinRect] -> [WinRect])
-> ([[Maybe WinRect]] -> [Maybe WinRect])
-> [[Maybe WinRect]]
-> [WinRect]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [[Maybe WinRect]] -> [Maybe WinRect]
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat
([[Maybe WinRect]] -> ([WinRect], [WinRect]))
-> X [[Maybe WinRect]] -> X ([WinRect], [WinRect])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
( (Screen -> X [Maybe WinRect]) -> [Screen] -> X [[Maybe WinRect]]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM ( \Screen
scr -> (Window -> X (Maybe WinRect)) -> [Window] -> X [Maybe WinRect]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM (Screen -> Window -> X (Maybe WinRect)
maybeWinRect Screen
scr)
([Window] -> X [Maybe WinRect]) -> [Window] -> X [Maybe WinRect]
forall a b. (a -> b) -> a -> b
$ Maybe (Stack Window) -> [Window]
forall a. Maybe (Stack a) -> [a]
W.integrate'
(Maybe (Stack Window) -> [Window])
-> Maybe (Stack Window) -> [Window]
forall a b. (a -> b) -> a -> b
$ Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack
(Workspace String (Layout Window) Window -> Maybe (Stack Window))
-> Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall a b. (a -> b) -> a -> b
$ Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace Screen
scr
)
([Screen] -> X [[Maybe WinRect]])
-> (WindowSet -> [Screen]) -> WindowSet -> X [[Maybe WinRect]]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> [Screen]
sortedScreens
) WindowSet
winset
where
maybeWinRect :: Screen -> Window -> X (Maybe WinRect)
maybeWinRect Screen
scr Window
win = do
Maybe Rectangle
winrect <- Window -> X (Maybe Rectangle)
windowRect Window
win
Maybe Rectangle
rect <- case Maybe Rectangle
winrect of
Just Rectangle
_ -> Maybe Rectangle -> X (Maybe Rectangle)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Rectangle
winrect
Maybe Rectangle
Nothing -> X (Maybe Rectangle)
-> ((Screen -> Window -> X (Maybe Rectangle))
-> X (Maybe Rectangle))
-> Maybe (Screen -> Window -> X (Maybe Rectangle))
-> X (Maybe Rectangle)
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe Rectangle -> X (Maybe Rectangle)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Rectangle
forall a. Maybe a
Nothing)
(\Screen -> Window -> X (Maybe Rectangle)
f -> Screen -> Window -> X (Maybe Rectangle)
f Screen
scr Window
win)
(String
-> [(String, Screen -> Window -> X (Maybe Rectangle))]
-> Maybe (Screen -> Window -> X (Maybe Rectangle))
forall a b. Eq a => a -> [(a, b)] -> Maybe b
L.lookup (Layout Window -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description (Layout Window -> String)
-> (Screen -> Layout Window) -> Screen -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Layout Window
forall i l a. Workspace i l a -> l
W.layout (Workspace String (Layout Window) Window -> Layout Window)
-> (Screen -> Workspace String (Layout Window) Window)
-> Screen
-> Layout Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen -> String) -> Screen -> String
forall a b. (a -> b) -> a -> b
$ Screen
scr) (Navigation2DConfig
-> [(String, Screen -> Window -> X (Maybe Rectangle))]
unmappedWindowRect Navigation2DConfig
conf))
Maybe WinRect -> X (Maybe WinRect)
forall (m :: * -> *) a. Monad m => a -> m a
return ((,) Window
win (Rectangle -> WinRect) -> Maybe Rectangle -> Maybe WinRect
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe Rectangle
rect)
windowRect :: Window -> X (Maybe Rectangle)
windowRect :: Window -> X (Maybe Rectangle)
windowRect Window
win = (Display -> X (Maybe Rectangle)) -> X (Maybe Rectangle)
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X (Maybe Rectangle)) -> X (Maybe Rectangle))
-> (Display -> X (Maybe Rectangle)) -> X (Maybe Rectangle)
forall a b. (a -> b) -> a -> b
$ \Display
dpy -> do
Bool
mp <- Window -> X Bool
isMapped Window
win
if Bool
mp then do (Window
_, Position
x, Position
y, Dimension
w, Dimension
h, Dimension
bw, CInt
_) <- IO
(Window, Position, Position, Dimension, Dimension, Dimension, CInt)
-> X (Window, Position, Position, Dimension, Dimension, Dimension,
CInt)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO
(Window, Position, Position, Dimension, Dimension, Dimension, CInt)
-> X (Window, Position, Position, Dimension, Dimension, Dimension,
CInt))
-> IO
(Window, Position, Position, Dimension, Dimension, Dimension, CInt)
-> X (Window, Position, Position, Dimension, Dimension, Dimension,
CInt)
forall a b. (a -> b) -> a -> b
$ Display
-> Window
-> IO
(Window, Position, Position, Dimension, Dimension, Dimension, CInt)
getGeometry Display
dpy Window
win
Maybe Rectangle -> X (Maybe Rectangle)
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Rectangle -> X (Maybe Rectangle))
-> Maybe Rectangle -> X (Maybe Rectangle)
forall a b. (a -> b) -> a -> b
$ Rectangle -> Maybe Rectangle
forall a. a -> Maybe a
Just (Rectangle -> Maybe Rectangle) -> Rectangle -> Maybe Rectangle
forall a b. (a -> b) -> a -> b
$ Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x Position
y (Dimension
w Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
+ Dimension
2 Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
* Dimension
bw) (Dimension
h Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
+ Dimension
2 Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
* Dimension
bw)
X (Maybe Rectangle) -> X (Maybe Rectangle) -> X (Maybe Rectangle)
forall a. X a -> X a -> X a
`catchX` Maybe Rectangle -> X (Maybe Rectangle)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Rectangle
forall a. Maybe a
Nothing
else Maybe Rectangle -> X (Maybe Rectangle)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe Rectangle
forall a. Maybe a
Nothing
actOnScreens :: (Navigation2DConfig -> WSRect -> [WSRect] -> X ())
-> Bool
-> X ()
actOnScreens :: (Navigation2DConfig -> WSRect -> [WSRect] -> X ()) -> Bool -> X ()
actOnScreens Navigation2DConfig -> WSRect -> [WSRect] -> X ()
act Bool
wrap = (WindowSet -> X ()) -> X ()
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X ()) -> X ()) -> (WindowSet -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \WindowSet
winset -> do
Navigation2DConfig
conf <- X Navigation2DConfig
forall a (m :: * -> *). (ExtensionClass a, XLike m) => m a
XS.get
let wsrects :: [WSRect]
wsrects = WindowSet -> Bool -> [WSRect]
visibleWorkspaces WindowSet
winset Bool
wrap
cur :: String
cur = Workspace String (Layout Window) Window -> String
forall i l a. Workspace i l a -> i
W.tag (Workspace String (Layout Window) Window -> String)
-> (WindowSet -> Workspace String (Layout Window) Window)
-> WindowSet
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen -> Workspace String (Layout Window) Window)
-> (WindowSet -> Screen)
-> WindowSet
-> Workspace String (Layout Window) Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> Screen
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (WindowSet -> String) -> WindowSet -> String
forall a b. (a -> b) -> a -> b
$ WindowSet
winset
rect :: Rectangle
rect = Maybe Rectangle -> Rectangle
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Rectangle -> Rectangle) -> Maybe Rectangle -> Rectangle
forall a b. (a -> b) -> a -> b
$ String -> [WSRect] -> Maybe Rectangle
forall a b. Eq a => a -> [(a, b)] -> Maybe b
L.lookup String
cur [WSRect]
wsrects
Navigation2DConfig -> WSRect -> [WSRect] -> X ()
act Navigation2DConfig
conf (String
cur, Rectangle
rect) [WSRect]
wsrects
isMapped :: Window -> X Bool
isMapped :: Window -> X Bool
isMapped Window
win = (Display -> X Bool) -> X Bool
forall a. (Display -> X a) -> X a
withDisplay
((Display -> X Bool) -> X Bool) -> (Display -> X Bool) -> X Bool
forall a b. (a -> b) -> a -> b
$ \Display
dpy -> IO Bool -> X Bool
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io
(IO Bool -> X Bool) -> IO Bool -> X Bool
forall a b. (a -> b) -> a -> b
$ (CInt
waIsUnmapped CInt -> CInt -> Bool
forall a. Eq a => a -> a -> Bool
/=)
(CInt -> Bool)
-> (WindowAttributes -> CInt) -> WindowAttributes -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowAttributes -> CInt
wa_map_state
(WindowAttributes -> Bool) -> IO WindowAttributes -> IO Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Display -> Window -> IO WindowAttributes
getWindowAttributes Display
dpy Window
win
doFocusClosestWindow :: WinRect
-> [WinRect]
-> (WindowSet -> WindowSet)
doFocusClosestWindow :: WinRect -> [WinRect] -> WindowSet -> WindowSet
doFocusClosestWindow (Window
cur, Rectangle
rect) [WinRect]
winrects
| [(Window, (Position, Position))] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Window, (Position, Position))]
winctrs = WindowSet -> WindowSet
forall a. a -> a
id
| Bool
otherwise = 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 -> WindowSet -> WindowSet)
-> ((Window, (Position, Position)) -> Window)
-> (Window, (Position, Position))
-> WindowSet
-> WindowSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Window, (Position, Position)) -> Window
forall a b. (a, b) -> a
fst ((Window, (Position, Position)) -> WindowSet -> WindowSet)
-> (Window, (Position, Position)) -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ ((Window, (Position, Position))
-> (Window, (Position, Position))
-> (Window, (Position, Position)))
-> [(Window, (Position, Position))]
-> (Window, (Position, Position))
forall a. (a -> a -> a) -> [a] -> a
L.foldl1' (Window, (Position, Position))
-> (Window, (Position, Position)) -> (Window, (Position, Position))
forall a.
(a, (Position, Position))
-> (a, (Position, Position)) -> (a, (Position, Position))
closer [(Window, (Position, Position))]
winctrs
where
ctr :: (Position, Position)
ctr = Rectangle -> (Position, Position)
centerOf Rectangle
rect
winctrs :: [(Window, (Position, Position))]
winctrs = ((Window, (Position, Position)) -> Bool)
-> [(Window, (Position, Position))]
-> [(Window, (Position, Position))]
forall a. (a -> Bool) -> [a] -> [a]
filter ((Window
cur Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
/=) (Window -> Bool)
-> ((Window, (Position, Position)) -> Window)
-> (Window, (Position, Position))
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Window, (Position, Position)) -> Window
forall a b. (a, b) -> a
fst)
([(Window, (Position, Position))]
-> [(Window, (Position, Position))])
-> [(Window, (Position, Position))]
-> [(Window, (Position, Position))]
forall a b. (a -> b) -> a -> b
$ (WinRect -> (Window, (Position, Position)))
-> [WinRect] -> [(Window, (Position, Position))]
forall a b. (a -> b) -> [a] -> [b]
map ((Rectangle -> (Position, Position))
-> WinRect -> (Window, (Position, Position))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second Rectangle -> (Position, Position)
centerOf) [WinRect]
winrects
closer :: (a, (Position, Position))
-> (a, (Position, Position)) -> (a, (Position, Position))
closer wc1 :: (a, (Position, Position))
wc1@(a
_, (Position, Position)
c1) wc2 :: (a, (Position, Position))
wc2@(a
_, (Position, Position)
c2) | (Position, Position) -> (Position, Position) -> Generality
lDist (Position, Position)
ctr (Position, Position)
c1 Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
> (Position, Position) -> (Position, Position) -> Generality
lDist (Position, Position)
ctr (Position, Position)
c2 = (a, (Position, Position))
wc2
| Bool
otherwise = (a, (Position, Position))
wc1
doTiledNavigation :: Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> (WindowSet -> WindowSet)
doTiledNavigation :: Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> WindowSet
-> WindowSet
doTiledNavigation Navigation2DConfig
conf Direction2D
dir Window -> WindowSet -> WindowSet
act WinRect
cur [WinRect]
winrects WindowSet
winset
| Just Window
win <- Navigation2D -> Direction2D -> WinRect -> [WinRect] -> Maybe Window
forall a.
Eq a =>
Navigation2D -> Direction2D -> Rect a -> [Rect a] -> Maybe a
runNav Navigation2D
nav Direction2D
dir WinRect
cur [WinRect]
winrects = Window -> WindowSet -> WindowSet
act Window
win WindowSet
winset
| Bool
otherwise = WindowSet
winset
where
layouts :: [String]
layouts = (Screen -> String) -> [Screen] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (Layout Window -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description (Layout Window -> String)
-> (Screen -> Layout Window) -> Screen -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Layout Window
forall i l a. Workspace i l a -> l
W.layout (Workspace String (Layout Window) Window -> Layout Window)
-> (Screen -> Workspace String (Layout Window) Window)
-> Screen
-> Layout Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace)
([Screen] -> [String]) -> [Screen] -> [String]
forall a b. (a -> b) -> a -> b
$ WindowSet -> [Screen]
forall i l a s sd. StackSet i l a s sd -> [Screen i l a s sd]
W.screens WindowSet
winset
nav :: Navigation2D
nav = [Navigation2D] -> Navigation2D
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum
([Navigation2D] -> Navigation2D) -> [Navigation2D] -> Navigation2D
forall a b. (a -> b) -> a -> b
$ (String -> Navigation2D) -> [String] -> [Navigation2D]
forall a b. (a -> b) -> [a] -> [b]
map ( Navigation2D -> Maybe Navigation2D -> Navigation2D
forall a. a -> Maybe a -> a
fromMaybe (Navigation2DConfig -> Navigation2D
defaultTiledNavigation Navigation2DConfig
conf)
(Maybe Navigation2D -> Navigation2D)
-> (String -> Maybe Navigation2D) -> String -> Navigation2D
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> [(String, Navigation2D)] -> Maybe Navigation2D)
-> [(String, Navigation2D)] -> String -> Maybe Navigation2D
forall a b c. (a -> b -> c) -> b -> a -> c
flip String -> [(String, Navigation2D)] -> Maybe Navigation2D
forall a b. Eq a => a -> [(a, b)] -> Maybe b
L.lookup (Navigation2DConfig -> [(String, Navigation2D)]
layoutNavigation Navigation2DConfig
conf)
) [String]
layouts
doFloatNavigation :: Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> (WindowSet -> WindowSet)
doFloatNavigation :: Navigation2DConfig
-> Direction2D
-> (Window -> WindowSet -> WindowSet)
-> WinRect
-> [WinRect]
-> WindowSet
-> WindowSet
doFloatNavigation Navigation2DConfig
conf Direction2D
dir Window -> WindowSet -> WindowSet
act WinRect
cur [WinRect]
winrects
| Just Window
win <- Navigation2D -> Direction2D -> WinRect -> [WinRect] -> Maybe Window
forall a.
Eq a =>
Navigation2D -> Direction2D -> Rect a -> [Rect a] -> Maybe a
runNav Navigation2D
nav Direction2D
dir WinRect
cur [WinRect]
winrects = Window -> WindowSet -> WindowSet
act Window
win
| Bool
otherwise = WindowSet -> WindowSet
forall a. a -> a
id
where
nav :: Navigation2D
nav = Navigation2DConfig -> Navigation2D
floatNavigation Navigation2DConfig
conf
doScreenNavigation :: Navigation2DConfig
-> Direction2D
-> (WorkspaceId -> WindowSet -> WindowSet)
-> WSRect
-> [WSRect]
-> (WindowSet -> WindowSet)
doScreenNavigation :: Navigation2DConfig
-> Direction2D
-> (String -> WindowSet -> WindowSet)
-> WSRect
-> [WSRect]
-> WindowSet
-> WindowSet
doScreenNavigation Navigation2DConfig
conf Direction2D
dir String -> WindowSet -> WindowSet
act WSRect
cur [WSRect]
wsrects
| Just String
ws <- Navigation2D -> Direction2D -> WSRect -> [WSRect] -> Maybe String
forall a.
Eq a =>
Navigation2D -> Direction2D -> Rect a -> [Rect a] -> Maybe a
runNav Navigation2D
nav Direction2D
dir WSRect
cur [WSRect]
wsrects = String -> WindowSet -> WindowSet
act String
ws
| Bool
otherwise = WindowSet -> WindowSet
forall a. a -> a
id
where
nav :: Navigation2D
nav = Navigation2DConfig -> Navigation2D
screenNavigation Navigation2DConfig
conf
doLineNavigation :: Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
doLineNavigation :: Direction2D -> Rect a -> [Rect a] -> Maybe a
doLineNavigation Direction2D
dir (a
cur, Rectangle
rect) [Rect a]
winrects
| [Rect a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Rect a]
winrects' = Maybe a
forall a. Maybe a
Nothing
| Bool
otherwise = a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> (Rect a -> a) -> Rect a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rect a -> a
forall a b. (a, b) -> a
fst (Rect a -> Maybe a) -> Rect a -> Maybe a
forall a b. (a -> b) -> a -> b
$ (Rect a -> Rect a -> Rect a) -> [Rect a] -> Rect a
forall a. (a -> a -> a) -> [a] -> a
L.foldl1' Rect a -> Rect a -> Rect a
forall a. (a, Rectangle) -> (a, Rectangle) -> (a, Rectangle)
closer [Rect a]
winrects'
where
ctr :: (Position, Position)
ctr@(Position
xc, Position
yc) = Rectangle -> (Position, Position)
centerOf Rectangle
rect
winrects' :: [Rect a]
winrects' = (Rect a -> Bool) -> [Rect a] -> [Rect a]
forall a. (a -> Bool) -> [a] -> [a]
filter Rect a -> Bool
forall a. (a, Rectangle) -> Bool
dirFilter
([Rect a] -> [Rect a])
-> ([Rect a] -> [Rect a]) -> [Rect a] -> [Rect a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect a -> Bool) -> [Rect a] -> [Rect a]
forall a. (a -> Bool) -> [a] -> [a]
filter ((a
cur a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/=) (a -> Bool) -> (Rect a -> a) -> Rect a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rect a -> a
forall a b. (a, b) -> a
fst)
([Rect a] -> [Rect a]) -> [Rect a] -> [Rect a]
forall a b. (a -> b) -> a -> b
$ [Rect a]
winrects
dirFilter :: (a, Rectangle) -> Bool
dirFilter (a
_, Rectangle
r) = (Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
L Bool -> Bool -> Bool
&& Rectangle -> Rectangle -> Bool
leftOf Rectangle
r Rectangle
rect Bool -> Bool -> Bool
&& Position -> Rectangle -> Bool
intersectsY Position
yc Rectangle
r)
Bool -> Bool -> Bool
|| (Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
R Bool -> Bool -> Bool
&& Rectangle -> Rectangle -> Bool
leftOf Rectangle
rect Rectangle
r Bool -> Bool -> Bool
&& Position -> Rectangle -> Bool
intersectsY Position
yc Rectangle
r)
Bool -> Bool -> Bool
|| (Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
U Bool -> Bool -> Bool
&& Rectangle -> Rectangle -> Bool
above Rectangle
r Rectangle
rect Bool -> Bool -> Bool
&& Position -> Rectangle -> Bool
intersectsX Position
xc Rectangle
r)
Bool -> Bool -> Bool
|| (Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
D Bool -> Bool -> Bool
&& Rectangle -> Rectangle -> Bool
above Rectangle
rect Rectangle
r Bool -> Bool -> Bool
&& Position -> Rectangle -> Bool
intersectsX Position
xc Rectangle
r)
leftOf :: Rectangle -> Rectangle -> Bool
leftOf Rectangle
r1 Rectangle
r2 = Rectangle -> Position
rect_x Rectangle
r1 Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_width Rectangle
r1) Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
<= Rectangle -> Position
rect_x Rectangle
r2
above :: Rectangle -> Rectangle -> Bool
above Rectangle
r1 Rectangle
r2 = Rectangle -> Position
rect_y Rectangle
r1 Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_height Rectangle
r1) Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
<= Rectangle -> Position
rect_y Rectangle
r2
intersectsX :: Position -> Rectangle -> Bool
intersectsX Position
x Rectangle
r = Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
<= Position
x Bool -> Bool -> Bool
&& Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_width Rectangle
r) Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
>= Position
x
intersectsY :: Position -> Rectangle -> Bool
intersectsY Position
y Rectangle
r = Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
<= Position
y Bool -> Bool -> Bool
&& Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_height Rectangle
r) Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
>= Position
y
closer :: (a, Rectangle) -> (a, Rectangle) -> (a, Rectangle)
closer wr1 :: (a, Rectangle)
wr1@(a
_, Rectangle
r1) wr2 :: (a, Rectangle)
wr2@(a
_, Rectangle
r2) | (Position, Position) -> Rectangle -> Position
dist (Position, Position)
ctr Rectangle
r1 Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
> (Position, Position) -> Rectangle -> Position
dist (Position, Position)
ctr Rectangle
r2 = (a, Rectangle)
wr2
| Bool
otherwise = (a, Rectangle)
wr1
dist :: (Position, Position) -> Rectangle -> Position
dist (Position
x, Position
y) Rectangle
r | Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
L = Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
- Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_width Rectangle
r)
| Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
R = Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
x
| Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
U = Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
- Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_height Rectangle
r)
| Bool
otherwise = Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
y
doCenterNavigation :: Eq a => Direction2D -> Rect a -> [Rect a] -> Maybe a
doCenterNavigation :: Direction2D -> Rect a -> [Rect a] -> Maybe a
doCenterNavigation Direction2D
dir (a
cur, Rectangle
rect) [Rect a]
winrects
| ((a
w, (Position, Position)
_):[(a, (Position, Position))]
_) <- [(a, (Position, Position))]
onCtr' = a -> Maybe a
forall a. a -> Maybe a
Just a
w
| Bool
otherwise = Maybe a
closestOffCtr
where
(Position
xc, Position
yc) = Rectangle -> (Position, Position)
centerOf Rectangle
rect
winctrs :: [(a, (Position, Position))]
winctrs = (Rect a -> (a, (Position, Position)))
-> [Rect a] -> [(a, (Position, Position))]
forall a b. (a -> b) -> [a] -> [b]
map ((Rectangle -> (Position, Position))
-> Rect a -> (a, (Position, Position))
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Position, Position) -> (Position, Position)
dirTransform ((Position, Position) -> (Position, Position))
-> (Rectangle -> (Position, Position))
-> Rectangle
-> (Position, Position)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rectangle -> (Position, Position)
centerOf))
([Rect a] -> [(a, (Position, Position))])
-> [Rect a] -> [(a, (Position, Position))]
forall a b. (a -> b) -> a -> b
$ [Rect a] -> [Rect a]
forall a. [a] -> [a]
stackTransform [Rect a]
winrects
stackTransform :: [a] -> [a]
stackTransform | Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
L Bool -> Bool -> Bool
|| Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
U = [a] -> [a]
forall a. [a] -> [a]
reverse
| Bool
otherwise = [a] -> [a]
forall a. a -> a
id
dirTransform :: (Position, Position) -> (Position, Position)
dirTransform (Position
x, Position
y) | Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
R = ( Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
xc , Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
yc )
| Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
L = (-(Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
xc), -(Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
yc))
| Direction2D
dir Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
== Direction2D
D = ( Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
yc , Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
xc )
| Bool
otherwise = (-(Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
yc), -(Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
xc))
([(a, (Position, Position))]
onCtr, [(a, (Position, Position))]
offCtr) = ((a, (Position, Position)) -> Bool)
-> [(a, (Position, Position))]
-> ([(a, (Position, Position))], [(a, (Position, Position))])
forall a. (a -> Bool) -> [a] -> ([a], [a])
L.partition (\(a
_, (Position
x, Position
y)) -> Position
x Position -> Position -> Bool
forall a. Eq a => a -> a -> Bool
== Position
0 Bool -> Bool -> Bool
&& Position
y Position -> Position -> Bool
forall a. Eq a => a -> a -> Bool
== Position
0) [(a, (Position, Position))]
winctrs
onCtr' :: [(a, (Position, Position))]
onCtr' = [(a, (Position, Position))] -> [(a, (Position, Position))]
forall a. [a] -> [a]
L.tail ([(a, (Position, Position))] -> [(a, (Position, Position))])
-> [(a, (Position, Position))] -> [(a, (Position, Position))]
forall a b. (a -> b) -> a -> b
$ ((a, (Position, Position)) -> Bool)
-> [(a, (Position, Position))] -> [(a, (Position, Position))]
forall a. (a -> Bool) -> [a] -> [a]
L.dropWhile ((a
cur a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/=) (a -> Bool)
-> ((a, (Position, Position)) -> a)
-> (a, (Position, Position))
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, (Position, Position)) -> a
forall a b. (a, b) -> a
fst) [(a, (Position, Position))]
onCtr
offCtr' :: [(a, (Position, Position))]
offCtr' = ((a, (Position, Position)) -> Bool)
-> [(a, (Position, Position))] -> [(a, (Position, Position))]
forall a. (a -> Bool) -> [a] -> [a]
L.filter (\(a
_, (Position
x, Position
y)) -> Position
x Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
> Position
0 Bool -> Bool -> Bool
&& Position
y Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
< Position
x Bool -> Bool -> Bool
&& Position
y Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
>= -Position
x) [(a, (Position, Position))]
offCtr
closestOffCtr :: Maybe a
closestOffCtr = if [(a, (Position, Position))] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(a, (Position, Position))]
offCtr' then Maybe a
forall a. Maybe a
Nothing
else a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ (a, (Position, Position)) -> a
forall a b. (a, b) -> a
fst ((a, (Position, Position)) -> a) -> (a, (Position, Position)) -> a
forall a b. (a -> b) -> a -> b
$ ((a, (Position, Position))
-> (a, (Position, Position)) -> (a, (Position, Position)))
-> [(a, (Position, Position))] -> (a, (Position, Position))
forall a. (a -> a -> a) -> [a] -> a
L.foldl1' (a, (Position, Position))
-> (a, (Position, Position)) -> (a, (Position, Position))
forall a.
(a, (Position, Position))
-> (a, (Position, Position)) -> (a, (Position, Position))
closest [(a, (Position, Position))]
offCtr'
closest :: (a, (Position, Position))
-> (a, (Position, Position)) -> (a, (Position, Position))
closest wp :: (a, (Position, Position))
wp@(a
_, p :: (Position, Position)
p@(Position
_, Position
yp)) wq :: (a, (Position, Position))
wq@(a
_, q :: (Position, Position)
q@(Position
_, Position
yq))
| (Position, Position) -> (Position, Position) -> Generality
lDist (Position
0, Position
0) (Position, Position)
q Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
< (Position, Position) -> (Position, Position) -> Generality
lDist (Position
0, Position
0) (Position, Position)
p = (a, (Position, Position))
wq
| (Position, Position) -> (Position, Position) -> Generality
lDist (Position
0, Position
0) (Position, Position)
p Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
< (Position, Position) -> (Position, Position) -> Generality
lDist (Position
0, Position
0) (Position, Position)
q = (a, (Position, Position))
wp
| Position
yq Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
< Position
yp = (a, (Position, Position))
wq
| Bool
otherwise = (a, (Position, Position))
wp
data SideRect = SideRect { SideRect -> Generality
x1 :: Int, SideRect -> Generality
x2 :: Int, SideRect -> Generality
y1 :: Int, SideRect -> Generality
y2 :: Int }
deriving Generality -> SideRect -> String -> String
[SideRect] -> String -> String
SideRect -> String
(Generality -> SideRect -> String -> String)
-> (SideRect -> String)
-> ([SideRect] -> String -> String)
-> Show SideRect
forall a.
(Generality -> a -> String -> String)
-> (a -> String) -> ([a] -> String -> String) -> Show a
showList :: [SideRect] -> String -> String
$cshowList :: [SideRect] -> String -> String
show :: SideRect -> String
$cshow :: SideRect -> String
showsPrec :: Generality -> SideRect -> String -> String
$cshowsPrec :: Generality -> SideRect -> String -> String
Show
toSR :: Rectangle -> SideRect
toSR :: Rectangle -> SideRect
toSR (Rectangle Position
x Position
y Dimension
w Dimension
h) = Generality -> Generality -> Generality -> Generality -> SideRect
SideRect (Position -> Generality
forall a b. (Integral a, Num b) => a -> b
fi Position
x) (Position -> Generality
forall a b. (Integral a, Num b) => a -> b
fi Position
x Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
+ Dimension -> Generality
forall a b. (Integral a, Num b) => a -> b
fi Dimension
w) (-Position -> Generality
forall a b. (Integral a, Num b) => a -> b
fi Position
y Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Dimension -> Generality
forall a b. (Integral a, Num b) => a -> b
fi Dimension
h) (-Position -> Generality
forall a b. (Integral a, Num b) => a -> b
fi Position
y)
doSideNavigationWithBias ::
Eq a => Int -> Direction2D -> Rect a -> [Rect a] -> Maybe a
doSideNavigationWithBias :: Generality -> Direction2D -> Rect a -> [Rect a] -> Maybe a
doSideNavigationWithBias Generality
bias Direction2D
dir (a
cur, Rectangle
rect)
= ((a, SideRect) -> a) -> Maybe (a, SideRect) -> Maybe a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (a, SideRect) -> a
forall a b. (a, b) -> a
fst (Maybe (a, SideRect) -> Maybe a)
-> ([Rect a] -> Maybe (a, SideRect)) -> [Rect a] -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(a, SideRect)] -> Maybe (a, SideRect)
forall a. [a] -> Maybe a
listToMaybe
([(a, SideRect)] -> Maybe (a, SideRect))
-> ([Rect a] -> [(a, SideRect)]) -> [Rect a] -> Maybe (a, SideRect)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, SideRect) -> Generality) -> [(a, SideRect)] -> [(a, SideRect)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
L.sortOn (a, SideRect) -> Generality
forall a. (a, SideRect) -> Generality
dist ([(a, SideRect)] -> [(a, SideRect)])
-> ([Rect a] -> [(a, SideRect)]) -> [Rect a] -> [(a, SideRect)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, SideRect) -> [(a, SideRect)] -> [(a, SideRect)])
-> [(a, SideRect)] -> [(a, SideRect)] -> [(a, SideRect)]
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (a, SideRect) -> [(a, SideRect)] -> [(a, SideRect)]
forall a. (a, SideRect) -> [(a, SideRect)] -> [(a, SideRect)]
acClosest []
([(a, SideRect)] -> [(a, SideRect)])
-> ([Rect a] -> [(a, SideRect)]) -> [Rect a] -> [(a, SideRect)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, SideRect) -> Bool) -> [(a, SideRect)] -> [(a, SideRect)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((a, SideRect) -> (a, SideRect) -> Bool
forall a a. (a, SideRect) -> (a, SideRect) -> Bool
`toRightOf` (a
cur, Rectangle -> SideRect
transform Rectangle
rect))
([(a, SideRect)] -> [(a, SideRect)])
-> ([Rect a] -> [(a, SideRect)]) -> [Rect a] -> [(a, SideRect)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rect a -> (a, SideRect)) -> [Rect a] -> [(a, SideRect)]
forall a b. (a -> b) -> [a] -> [b]
map ((Rectangle -> SideRect) -> Rect a -> (a, SideRect)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Rectangle -> SideRect
transform)
where
cOf :: SideRect -> (Generality, Generality)
cOf SideRect
r = ((SideRect -> Generality
x1 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
+ SideRect -> Generality
x2 SideRect
r) Generality -> Generality -> Generality
forall a. Integral a => a -> a -> a
`div` Generality
2, (SideRect -> Generality
y1 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
+ SideRect -> Generality
y2 SideRect
r) Generality -> Generality -> Generality
forall a. Integral a => a -> a -> a
`div` Generality
2)
(Generality
x0, Generality
y0) = SideRect -> (Generality, Generality)
cOf (SideRect -> (Generality, Generality))
-> (Rectangle -> SideRect) -> Rectangle -> (Generality, Generality)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rectangle -> SideRect
toSR (Rectangle -> (Generality, Generality))
-> Rectangle -> (Generality, Generality)
forall a b. (a -> b) -> a -> b
$ Rectangle
rect
translate :: SideRect -> SideRect
translate SideRect
r = Generality -> Generality -> Generality -> Generality -> SideRect
SideRect (SideRect -> Generality
x1 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Generality
x0) (SideRect -> Generality
x2 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Generality
x0) (SideRect -> Generality
y1 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Generality
y0) (SideRect -> Generality
y2 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Generality
y0)
rHalfPiCC :: SideRect -> SideRect
rHalfPiCC SideRect
r = Generality -> Generality -> Generality -> Generality -> SideRect
SideRect (-SideRect -> Generality
y2 SideRect
r) (-SideRect -> Generality
y1 SideRect
r) (SideRect -> Generality
x1 SideRect
r) (SideRect -> Generality
x2 SideRect
r)
rotateToR :: Direction2D -> SideRect -> SideRect
rotateToR Direction2D
d = let ([Direction2D]
_, Direction2D
_:[Direction2D]
l) = (Direction2D -> Bool)
-> [Direction2D] -> ([Direction2D], [Direction2D])
forall a. (a -> Bool) -> [a] -> ([a], [a])
break (Direction2D
d Direction2D -> Direction2D -> Bool
forall a. Eq a => a -> a -> Bool
==) [Direction2D
U, Direction2D
L, Direction2D
D, Direction2D
R]
in (Direction2D -> (SideRect -> SideRect) -> SideRect -> SideRect)
-> (SideRect -> SideRect) -> [Direction2D] -> SideRect -> SideRect
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (((SideRect -> SideRect) -> SideRect -> SideRect)
-> Direction2D -> (SideRect -> SideRect) -> SideRect -> SideRect
forall a b. a -> b -> a
const (((SideRect -> SideRect) -> SideRect -> SideRect)
-> Direction2D -> (SideRect -> SideRect) -> SideRect -> SideRect)
-> ((SideRect -> SideRect) -> SideRect -> SideRect)
-> Direction2D
-> (SideRect -> SideRect)
-> SideRect
-> SideRect
forall a b. (a -> b) -> a -> b
$ (SideRect -> SideRect)
-> (SideRect -> SideRect) -> SideRect -> SideRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
(.) SideRect -> SideRect
rHalfPiCC) SideRect -> SideRect
forall a. a -> a
id [Direction2D]
l
transform :: Rectangle -> SideRect
transform = Direction2D -> SideRect -> SideRect
rotateToR Direction2D
dir (SideRect -> SideRect)
-> (Rectangle -> SideRect) -> Rectangle -> SideRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SideRect -> SideRect
translate (SideRect -> SideRect)
-> (Rectangle -> SideRect) -> Rectangle -> SideRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rectangle -> SideRect
toSR
toRightOf :: (a, SideRect) -> (a, SideRect) -> Bool
toRightOf (a
_, SideRect
r) (a
_, SideRect
c) = (SideRect -> Generality
x2 SideRect
r Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
> SideRect -> Generality
x2 SideRect
c) Bool -> Bool -> Bool
&& (SideRect -> Generality
y2 SideRect
r Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
> SideRect -> Generality
y1 SideRect
c) Bool -> Bool -> Bool
&& (SideRect -> Generality
y1 SideRect
r Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
< SideRect -> Generality
y2 SideRect
c)
acClosest :: (a, SideRect) -> [(a, SideRect)] -> [(a, SideRect)]
acClosest (a
w, SideRect
r) l :: [(a, SideRect)]
l@((a
_, SideRect
r'):[(a, SideRect)]
_) | SideRect -> Generality
x1 SideRect
r Generality -> Generality -> Bool
forall a. Eq a => a -> a -> Bool
== SideRect -> Generality
x1 SideRect
r' = (a
w, SideRect
r) (a, SideRect) -> [(a, SideRect)] -> [(a, SideRect)]
forall a. a -> [a] -> [a]
: [(a, SideRect)]
l
| SideRect -> Generality
x1 SideRect
r Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
> SideRect -> Generality
x1 SideRect
r' = [(a, SideRect)]
l
acClosest (a
w, SideRect
r) [(a, SideRect)]
_ = [(a
w, SideRect
r)]
dist :: (a, SideRect) -> Generality
dist (a
_, SideRect
r) | (SideRect -> Generality
y1 SideRect
r Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
<= Generality
bias) Bool -> Bool -> Bool
&& (Generality
bias Generality -> Generality -> Bool
forall a. Ord a => a -> a -> Bool
<= SideRect -> Generality
y2 SideRect
r) = Generality
0
| Bool
otherwise = Generality -> Generality -> Generality
forall a. Ord a => a -> a -> a
min (Generality -> Generality
forall a. Num a => a -> a
abs (Generality -> Generality) -> Generality -> Generality
forall a b. (a -> b) -> a -> b
$ SideRect -> Generality
y1 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Generality
bias) (Generality -> Generality
forall a. Num a => a -> a
abs (Generality -> Generality) -> Generality -> Generality
forall a b. (a -> b) -> a -> b
$ SideRect -> Generality
y2 SideRect
r Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
- Generality
bias)
swap :: Window -> WindowSet -> WindowSet
swap :: Window -> WindowSet -> WindowSet
swap Window
win WindowSet
winset = 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
cur
(WindowSet -> WindowSet) -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ (WindowSet -> Window -> WindowSet)
-> WindowSet -> [Window] -> WindowSet
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
L.foldl' ((Window -> WindowSet -> WindowSet)
-> WindowSet -> Window -> WindowSet
forall a b c. (a -> b -> c) -> b -> a -> c
flip 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) WindowSet
newwinset [Window]
newfocused
where
cur :: Window
cur = Maybe Window -> Window
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe Window -> Window) -> Maybe Window -> Window
forall a b. (a -> b) -> a -> b
$ WindowSet -> Maybe Window
forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek WindowSet
winset
scrs :: [Screen]
scrs = WindowSet -> [Screen]
forall i l a s sd. StackSet i l a s sd -> [Screen i l a s sd]
W.screens WindowSet
winset
visws :: [Workspace String (Layout Window) Window]
visws = (Screen -> Workspace String (Layout Window) Window)
-> [Screen] -> [Workspace String (Layout Window) Window]
forall a b. (a -> b) -> [a] -> [b]
map Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace [Screen]
scrs
focused :: [Window]
focused = (Workspace String (Layout Window) Window -> Maybe Window)
-> [Workspace String (Layout Window) Window] -> [Window]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe ((Stack Window -> Window) -> Maybe (Stack Window) -> Maybe Window
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Stack Window -> Window
forall a. Stack a -> a
W.focus (Maybe (Stack Window) -> Maybe Window)
-> (Workspace String (Layout Window) Window
-> Maybe (Stack Window))
-> Workspace String (Layout Window) Window
-> Maybe Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack) [Workspace String (Layout Window) Window]
visws
wins :: [[Window]]
wins = (Workspace String (Layout Window) Window -> [Window])
-> [Workspace String (Layout Window) Window] -> [[Window]]
forall a b. (a -> b) -> [a] -> [b]
map (Maybe (Stack Window) -> [Window]
forall a. Maybe (Stack a) -> [a]
W.integrate' (Maybe (Stack Window) -> [Window])
-> (Workspace String (Layout Window) Window
-> Maybe (Stack Window))
-> Workspace String (Layout Window) Window
-> [Window]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace String (Layout Window) Window -> Maybe (Stack Window)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack) [Workspace String (Layout Window) Window]
visws
newfocused :: [Window]
newfocused = (Window -> Window) -> [Window] -> [Window]
forall a b. (a -> b) -> [a] -> [b]
map Window -> Window
swapWins [Window]
focused
newwins :: [[Window]]
newwins = ([Window] -> [Window]) -> [[Window]] -> [[Window]]
forall a b. (a -> b) -> [a] -> [b]
map ((Window -> Window) -> [Window] -> [Window]
forall a b. (a -> b) -> [a] -> [b]
map Window -> Window
swapWins) [[Window]]
wins
swapWins :: Window -> Window
swapWins Window
x | Window
x Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
== Window
cur = Window
win
| Window
x Window -> Window -> Bool
forall a. Eq a => a -> a -> Bool
== Window
win = Window
cur
| Bool
otherwise = Window
x
newvisws :: [Workspace String (Layout Window) Window]
newvisws = (Workspace String (Layout Window) Window
-> [Window] -> Workspace String (Layout Window) Window)
-> [Workspace String (Layout Window) Window]
-> [[Window]]
-> [Workspace String (Layout Window) Window]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Workspace String (Layout Window) Window
ws [Window]
wns -> Workspace String (Layout Window) Window
ws { stack :: Maybe (Stack Window)
W.stack = [Window] -> Maybe (Stack Window)
forall a. [a] -> Maybe (Stack a)
W.differentiate [Window]
wns }) [Workspace String (Layout Window) Window]
visws [[Window]]
newwins
newscrs :: [Screen]
newscrs = (Screen -> Workspace String (Layout Window) Window -> Screen)
-> [Screen]
-> [Workspace String (Layout Window) Window]
-> [Screen]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith (\Screen
scr Workspace String (Layout Window) Window
ws -> Screen
scr { workspace :: Workspace String (Layout Window) Window
W.workspace = Workspace String (Layout Window) Window
ws }) [Screen]
scrs [Workspace String (Layout Window) Window]
newvisws
newwinset :: WindowSet
newwinset = WindowSet
winset { current :: Screen
W.current = [Screen] -> Screen
forall a. [a] -> a
head [Screen]
newscrs
, visible :: [Screen]
W.visible = [Screen] -> [Screen]
forall a. [a] -> [a]
tail [Screen]
newscrs
}
centerOf :: Rectangle -> (Position, Position)
centerOf :: Rectangle -> (Position, Position)
centerOf Rectangle
r = (Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_width Rectangle
r) Position -> Position -> Position
forall a. Integral a => a -> a -> a
`div` Position
2, Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_height Rectangle
r) Position -> Position -> Position
forall a. Integral a => a -> a -> a
`div` Position
2)
thisLayer, otherLayer :: a -> a -> a
thisLayer :: a -> a -> a
thisLayer = a -> a -> a
forall a b. a -> b -> a
const
otherLayer :: a -> a -> a
otherLayer a
_ a
x = a
x
visibleWorkspaces :: WindowSet -> Bool -> [WSRect]
visibleWorkspaces :: WindowSet -> Bool -> [WSRect]
visibleWorkspaces WindowSet
winset Bool
wrap = WindowSet -> Bool -> [WSRect] -> [WSRect]
forall a. WindowSet -> Bool -> [Rect a] -> [Rect a]
addWrapping WindowSet
winset Bool
wrap
([WSRect] -> [WSRect]) -> [WSRect] -> [WSRect]
forall a b. (a -> b) -> a -> b
$ (Screen -> WSRect) -> [Screen] -> [WSRect]
forall a b. (a -> b) -> [a] -> [b]
map ( \Screen
scr -> ( Workspace String (Layout Window) Window -> String
forall i l a. Workspace i l a -> i
W.tag (Workspace String (Layout Window) Window -> String)
-> (Screen -> Workspace String (Layout Window) Window)
-> Screen
-> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> Workspace String (Layout Window) Window
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen -> String) -> Screen -> String
forall a b. (a -> b) -> a -> b
$ Screen
scr
, ScreenDetail -> Rectangle
screenRect (ScreenDetail -> Rectangle)
-> (Screen -> ScreenDetail) -> Screen -> Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen -> ScreenDetail
forall i l a sid sd. Screen i l a sid sd -> sd
W.screenDetail (Screen -> Rectangle) -> Screen -> Rectangle
forall a b. (a -> b) -> a -> b
$ Screen
scr
)
)
([Screen] -> [WSRect]) -> [Screen] -> [WSRect]
forall a b. (a -> b) -> a -> b
$ WindowSet -> [Screen]
sortedScreens WindowSet
winset
addWrapping :: WindowSet
-> Bool
-> [Rect a]
-> [Rect a]
addWrapping :: WindowSet -> Bool -> [Rect a] -> [Rect a]
addWrapping WindowSet
_ Bool
False [Rect a]
wrects = [Rect a]
wrects
addWrapping WindowSet
winset Bool
True [Rect a]
wrects = [ (a
w, Rectangle
r { rect_x :: Position
rect_x = Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Integer -> Position
forall a b. (Integral a, Num b) => a -> b
fi Integer
x
, rect_y :: Position
rect_y = Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Integer -> Position
forall a b. (Integral a, Num b) => a -> b
fi Integer
y
}
)
| (a
w, Rectangle
r) <- [Rect a]
wrects
, (Integer
x, Integer
y) <- [(Integer
0, Integer
0), (-Integer
xoff, Integer
0), (Integer
xoff, Integer
0), (Integer
0, -Integer
yoff), (Integer
0, Integer
yoff)]
]
where
(Integer
xoff, Integer
yoff) = WindowSet -> (Integer, Integer)
wrapOffsets WindowSet
winset
wrapOffsets :: WindowSet -> (Integer, Integer)
wrapOffsets :: WindowSet -> (Integer, Integer)
wrapOffsets WindowSet
winset = (Integer
max_x Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
min_x, Integer
max_y Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
- Integer
min_y)
where
min_x :: Integer
min_x = Position -> Integer
forall a b. (Integral a, Num b) => a -> b
fi (Position -> Integer) -> Position -> Integer
forall a b. (a -> b) -> a -> b
$ [Position] -> Position
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum ([Position] -> Position) -> [Position] -> Position
forall a b. (a -> b) -> a -> b
$ (Rectangle -> Position) -> [Rectangle] -> [Position]
forall a b. (a -> b) -> [a] -> [b]
map Rectangle -> Position
rect_x [Rectangle]
rects
min_y :: Integer
min_y = Position -> Integer
forall a b. (Integral a, Num b) => a -> b
fi (Position -> Integer) -> Position -> Integer
forall a b. (a -> b) -> a -> b
$ [Position] -> Position
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
minimum ([Position] -> Position) -> [Position] -> Position
forall a b. (a -> b) -> a -> b
$ (Rectangle -> Position) -> [Rectangle] -> [Position]
forall a b. (a -> b) -> [a] -> [b]
map Rectangle -> Position
rect_y [Rectangle]
rects
max_x :: Integer
max_x = Position -> Integer
forall a b. (Integral a, Num b) => a -> b
fi (Position -> Integer) -> Position -> Integer
forall a b. (a -> b) -> a -> b
$ [Position] -> Position
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Position] -> Position) -> [Position] -> Position
forall a b. (a -> b) -> a -> b
$ (Rectangle -> Position) -> [Rectangle] -> [Position]
forall a b. (a -> b) -> [a] -> [b]
map (\Rectangle
r -> Rectangle -> Position
rect_x Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_width Rectangle
r)) [Rectangle]
rects
max_y :: Integer
max_y = Position -> Integer
forall a b. (Integral a, Num b) => a -> b
fi (Position -> Integer) -> Position -> Integer
forall a b. (a -> b) -> a -> b
$ [Position] -> Position
forall (t :: * -> *) a. (Foldable t, Ord a) => t a -> a
maximum ([Position] -> Position) -> [Position] -> Position
forall a b. (a -> b) -> a -> b
$ (Rectangle -> Position) -> [Rectangle] -> [Position]
forall a b. (a -> b) -> [a] -> [b]
map (\Rectangle
r -> Rectangle -> Position
rect_y Rectangle
r Position -> Position -> Position
forall a. Num a => a -> a -> a
+ Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fi (Rectangle -> Dimension
rect_height Rectangle
r)) [Rectangle]
rects
rects :: [Rectangle]
rects = (WSRect -> Rectangle) -> [WSRect] -> [Rectangle]
forall a b. (a -> b) -> [a] -> [b]
map WSRect -> Rectangle
forall a b. (a, b) -> b
snd ([WSRect] -> [Rectangle]) -> [WSRect] -> [Rectangle]
forall a b. (a -> b) -> a -> b
$ WindowSet -> Bool -> [WSRect]
visibleWorkspaces WindowSet
winset Bool
False
sortedScreens :: WindowSet -> [Screen]
sortedScreens :: WindowSet -> [Screen]
sortedScreens WindowSet
winset = (Screen -> Screen -> Ordering) -> [Screen] -> [Screen]
forall a. (a -> a -> Ordering) -> [a] -> [a]
L.sortBy Screen -> Screen -> Ordering
forall i l a sid i l a sid.
Screen i l a sid ScreenDetail
-> Screen i l a sid ScreenDetail -> Ordering
cmp
([Screen] -> [Screen]) -> [Screen] -> [Screen]
forall a b. (a -> b) -> a -> b
$ WindowSet -> [Screen]
forall i l a s sd. StackSet i l a s sd -> [Screen i l a s sd]
W.screens WindowSet
winset
where
cmp :: Screen i l a sid ScreenDetail
-> Screen i l a sid ScreenDetail -> Ordering
cmp Screen i l a sid ScreenDetail
s1 Screen i l a sid ScreenDetail
s2 | Position
x Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
< Position
x' = Ordering
LT
| Position
x Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
> Position
x' = Ordering
GT
| Position
y Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
< Position
x' = Ordering
LT
| Position
y Position -> Position -> Bool
forall a. Ord a => a -> a -> Bool
> Position
y' = Ordering
GT
| Bool
otherwise = Ordering
EQ
where
(Position
x , Position
y ) = Rectangle -> (Position, Position)
centerOf (ScreenDetail -> Rectangle
screenRect (ScreenDetail -> Rectangle)
-> (Screen i l a sid ScreenDetail -> ScreenDetail)
-> Screen i l a sid ScreenDetail
-> Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen i l a sid ScreenDetail -> ScreenDetail
forall i l a sid sd. Screen i l a sid sd -> sd
W.screenDetail (Screen i l a sid ScreenDetail -> Rectangle)
-> Screen i l a sid ScreenDetail -> Rectangle
forall a b. (a -> b) -> a -> b
$ Screen i l a sid ScreenDetail
s1)
(Position
x', Position
y') = Rectangle -> (Position, Position)
centerOf (ScreenDetail -> Rectangle
screenRect (ScreenDetail -> Rectangle)
-> (Screen i l a sid ScreenDetail -> ScreenDetail)
-> Screen i l a sid ScreenDetail
-> Rectangle
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Screen i l a sid ScreenDetail -> ScreenDetail
forall i l a sid sd. Screen i l a sid sd -> sd
W.screenDetail (Screen i l a sid ScreenDetail -> Rectangle)
-> Screen i l a sid ScreenDetail -> Rectangle
forall a b. (a -> b) -> a -> b
$ Screen i l a sid ScreenDetail
s2)
lDist :: (Position, Position) -> (Position, Position) -> Int
lDist :: (Position, Position) -> (Position, Position) -> Generality
lDist (Position
x, Position
y) (Position
x', Position
y') = Generality -> Generality
forall a. Num a => a -> a
abs (Position -> Generality
forall a b. (Integral a, Num b) => a -> b
fi (Position -> Generality) -> Position -> Generality
forall a b. (a -> b) -> a -> b
$ Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
x') Generality -> Generality -> Generality
forall a. Num a => a -> a -> a
+ Generality -> Generality
forall a. Num a => a -> a
abs (Position -> Generality
forall a b. (Integral a, Num b) => a -> b
fi (Position -> Generality) -> Position -> Generality
forall a b. (a -> b) -> a -> b
$ Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- Position
y')