    {-# LANGUAGE DeriveDataTypeable, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, TypeSynonymInstances, PatternGuards #-}

    -----------------------------------------------------------------------------
    -- |
    -- Module      :  XMonad.Layout.WindowNavigation
    -- Copyright   :  (c) 2007  David Roundy <droundy@darcs.net>
    -- License     :  BSD3-style (see LICENSE)
    --
    -- Maintainer  :  Devin Mullins <me@twifkak.com>
    -- Stability   :  unstable
    -- Portability :  unportable
    --
    -- WindowNavigation is an extension to allow easy navigation of a workspace.
    --
    -----------------------------------------------------------------------------

    module XMonad.Layout.WindowNavigation (
                                       -- * Usage
                                       -- $usage
                                       windowNavigation, configurableNavigation,
                                       Navigate(..), Direction2D(..),
                                       MoveWindowToWindow(..),
                                       navigateColor, navigateBrightness,
                                       noNavigateBorders, defaultWNConfig, def,
                                       WNConfig, WindowNavigation,
                                      ) where

    import Data.List ( nub, sortBy, (\\) )
    import XMonad hiding (Point)
    import qualified XMonad.StackSet as W
    import XMonad.Layout.LayoutModifier
    import XMonad.Util.Invisible
    import XMonad.Util.Types (Direction2D(..))
    import XMonad.Util.XUtils

    -- $usage
    -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
    --
    -- > import XMonad.Layout.WindowNavigation
    --
    -- Then edit your @layoutHook@ by adding the WindowNavigation layout modifier
    -- to some layout:
    --
    -- > myLayout = windowNavigation (Tall 1 (3/100) (1/2))  ||| Full ||| etc..
    -- > main = xmonad def { layoutHook = myLayout }
    --
    -- For more detailed instructions on editing the layoutHook see:
    --
    -- "XMonad.Doc.Extending#Editing_the_layout_hook"
    --
    -- In keybindings:
    --
    -- >    , ((modm,                 xK_Right), sendMessage $ Go R)
    -- >    , ((modm,                 xK_Left ), sendMessage $ Go L)
    -- >    , ((modm,                 xK_Up   ), sendMessage $ Go U)
    -- >    , ((modm,                 xK_Down ), sendMessage $ Go D)
    -- >    , ((modm .|. controlMask, xK_Right), sendMessage $ Swap R)
    -- >    , ((modm .|. controlMask, xK_Left ), sendMessage $ Swap L)
    -- >    , ((modm .|. controlMask, xK_Up   ), sendMessage $ Swap U)
    -- >    , ((modm .|. controlMask, xK_Down ), sendMessage $ Swap D)
    --
    -- For detailed instruction on editing the key binding see:
    --
    -- "XMonad.Doc.Extending#Editing_key_bindings".

    data MoveWindowToWindow a = MoveWindowToWindow a a deriving ( ReadPrec [MoveWindowToWindow a]
    ReadPrec (MoveWindowToWindow a)
    Int -> ReadS (MoveWindowToWindow a)
    ReadS [MoveWindowToWindow a]
    (Int -> ReadS (MoveWindowToWindow a))
    -> ReadS [MoveWindowToWindow a]
    -> ReadPrec (MoveWindowToWindow a)
    -> ReadPrec [MoveWindowToWindow a]
    -> Read (MoveWindowToWindow a)
    forall a. Read a => ReadPrec [MoveWindowToWindow a]
    forall a. Read a => ReadPrec (MoveWindowToWindow a)
    forall a. Read a => Int -> ReadS (MoveWindowToWindow a)
    forall a. Read a => ReadS [MoveWindowToWindow a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [MoveWindowToWindow a]
    $creadListPrec :: forall a. Read a => ReadPrec [MoveWindowToWindow a]
    readPrec :: ReadPrec (MoveWindowToWindow a)
    $creadPrec :: forall a. Read a => ReadPrec (MoveWindowToWindow a)
    readList :: ReadS [MoveWindowToWindow a]
    $creadList :: forall a. Read a => ReadS [MoveWindowToWindow a]
    readsPrec :: Int -> ReadS (MoveWindowToWindow a)
    $creadsPrec :: forall a. Read a => Int -> ReadS (MoveWindowToWindow a)
    Read, Int -> MoveWindowToWindow a -> ShowS
    [MoveWindowToWindow a] -> ShowS
    MoveWindowToWindow a -> String
    (Int -> MoveWindowToWindow a -> ShowS)
    -> (MoveWindowToWindow a -> String)
    -> ([MoveWindowToWindow a] -> ShowS)
    -> Show (MoveWindowToWindow a)
    forall a. Show a => Int -> MoveWindowToWindow a -> ShowS
    forall a. Show a => [MoveWindowToWindow a] -> ShowS
    forall a. Show a => MoveWindowToWindow a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [MoveWindowToWindow a] -> ShowS
    $cshowList :: forall a. Show a => [MoveWindowToWindow a] -> ShowS
    show :: MoveWindowToWindow a -> String
    $cshow :: forall a. Show a => MoveWindowToWindow a -> String
    showsPrec :: Int -> MoveWindowToWindow a -> ShowS
    $cshowsPrec :: forall a. Show a => Int -> MoveWindowToWindow a -> ShowS
    Show, Typeable )
    instance Typeable a => Message (MoveWindowToWindow a)

    data Navigate = Go Direction2D | Swap Direction2D | Move Direction2D
                  | Apply (Window -> X()) Direction2D -- ^ Apply action with destination window
            deriving ( Typeable )
    instance Message Navigate

    data WNConfig =
        WNC { WNConfig -> Maybe Double
    brightness    :: Maybe Double -- Indicates a fraction of the focus color.
            , WNConfig -> String
    upColor       :: String
            , WNConfig -> String
    downColor     :: String
            , WNConfig -> String
    leftColor     :: String
            , WNConfig -> String
    rightColor    :: String
            } deriving (Int -> WNConfig -> ShowS
    [WNConfig] -> ShowS
    WNConfig -> String
    (Int -> WNConfig -> ShowS)
    -> (WNConfig -> String) -> ([WNConfig] -> ShowS) -> Show WNConfig
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [WNConfig] -> ShowS
    $cshowList :: [WNConfig] -> ShowS
    show :: WNConfig -> String
    $cshow :: WNConfig -> String
    showsPrec :: Int -> WNConfig -> ShowS
    $cshowsPrec :: Int -> WNConfig -> ShowS
    Show, ReadPrec [WNConfig]
    ReadPrec WNConfig
    Int -> ReadS WNConfig
    ReadS [WNConfig]
    (Int -> ReadS WNConfig)
    -> ReadS [WNConfig]
    -> ReadPrec WNConfig
    -> ReadPrec [WNConfig]
    -> Read WNConfig
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [WNConfig]
    $creadListPrec :: ReadPrec [WNConfig]
    readPrec :: ReadPrec WNConfig
    $creadPrec :: ReadPrec WNConfig
    readList :: ReadS [WNConfig]
    $creadList :: ReadS [WNConfig]
    readsPrec :: Int -> ReadS WNConfig
    $creadsPrec :: Int -> ReadS WNConfig
    Read)

    noNavigateBorders :: WNConfig
    noNavigateBorders :: WNConfig
    noNavigateBorders =
        WNConfig
    forall a. Default a => a
    def {brightness :: Maybe Double
    brightness = Double -> Maybe Double
    forall a. a -> Maybe a
    Just 0}

    navigateColor :: String -> WNConfig
    navigateColor :: String -> WNConfig
    navigateColor c :: String
    c =
        Maybe Double -> String -> String -> String -> String -> WNConfig
    WNC Maybe Double
    forall a. Maybe a
    Nothing String
    c String
    c String
    c String
    c

    navigateBrightness :: Double -> WNConfig
    navigateBrightness :: Double -> WNConfig
    navigateBrightness f :: Double
    f = WNConfig
    forall a. Default a => a
    def { brightness :: Maybe Double
    brightness = Double -> Maybe Double
    forall a. a -> Maybe a
    Just (Double -> Maybe Double) -> Double -> Maybe Double
    forall a b. (a -> b) -> a -> b
    $ Double -> Double -> Double
    forall a. Ord a => a -> a -> a
    max 0 (Double -> Double) -> Double -> Double
    forall a b. (a -> b) -> a -> b
    $ Double -> Double -> Double
    forall a. Ord a => a -> a -> a
    min 1 Double
    f }

    instance Default WNConfig where def :: WNConfig
    def = Maybe Double -> String -> String -> String -> String -> WNConfig
    WNC (Double -> Maybe Double
    forall a. a -> Maybe a
    Just 0.4) "#0000FF" "#00FFFF" "#FF0000" "#FF00FF"

    {-# DEPRECATED defaultWNConfig "Use def (from Data.Default, and re-exported by XMonad.Layout.WindowNavigation) instead." #-}
    defaultWNConfig :: WNConfig
    defaultWNConfig :: WNConfig
    defaultWNConfig = WNConfig
    forall a. Default a => a
    def

    data NavigationState a = NS Point [(a,Rectangle)]

    data WindowNavigation a = WindowNavigation WNConfig (Invisible Maybe (NavigationState a)) deriving ( ReadPrec [WindowNavigation a]
    ReadPrec (WindowNavigation a)
    Int -> ReadS (WindowNavigation a)
    ReadS [WindowNavigation a]
    (Int -> ReadS (WindowNavigation a))
    -> ReadS [WindowNavigation a]
    -> ReadPrec (WindowNavigation a)
    -> ReadPrec [WindowNavigation a]
    -> Read (WindowNavigation a)
    forall a. ReadPrec [WindowNavigation a]
    forall a. ReadPrec (WindowNavigation a)
    forall a. Int -> ReadS (WindowNavigation a)
    forall a. ReadS [WindowNavigation a]
    forall a.
    (Int -> ReadS a)
    -> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
    readListPrec :: ReadPrec [WindowNavigation a]
    $creadListPrec :: forall a. ReadPrec [WindowNavigation a]
    readPrec :: ReadPrec (WindowNavigation a)
    $creadPrec :: forall a. ReadPrec (WindowNavigation a)
    readList :: ReadS [WindowNavigation a]
    $creadList :: forall a. ReadS [WindowNavigation a]
    readsPrec :: Int -> ReadS (WindowNavigation a)
    $creadsPrec :: forall a. Int -> ReadS (WindowNavigation a)
    Read, Int -> WindowNavigation a -> ShowS
    [WindowNavigation a] -> ShowS
    WindowNavigation a -> String
    (Int -> WindowNavigation a -> ShowS)
    -> (WindowNavigation a -> String)
    -> ([WindowNavigation a] -> ShowS)
    -> Show (WindowNavigation a)
    forall a. Int -> WindowNavigation a -> ShowS
    forall a. [WindowNavigation a] -> ShowS
    forall a. WindowNavigation a -> String
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    showList :: [WindowNavigation a] -> ShowS
    $cshowList :: forall a. [WindowNavigation a] -> ShowS
    show :: WindowNavigation a -> String
    $cshow :: forall a. WindowNavigation a -> String
    showsPrec :: Int -> WindowNavigation a -> ShowS
    $cshowsPrec :: forall a. Int -> WindowNavigation a -> ShowS
    Show )

    windowNavigation :: LayoutClass l a => l a -> ModifiedLayout WindowNavigation l a
    windowNavigation :: l a -> ModifiedLayout WindowNavigation l a
    windowNavigation = WindowNavigation a -> l a -> ModifiedLayout WindowNavigation l a
    forall (m :: * -> *) (l :: * -> *) a.
    m a -> l a -> ModifiedLayout m l a
    ModifiedLayout (WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    forall a.
    WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    WindowNavigation WNConfig
    forall a. Default a => a
    def (Maybe (NavigationState a) -> Invisible Maybe (NavigationState a)
    forall (m :: * -> *) a. m a -> Invisible m a
    I Maybe (NavigationState a)
    forall a. Maybe a
    Nothing))

    configurableNavigation :: LayoutClass l a => WNConfig -> l a -> ModifiedLayout WindowNavigation l a
    configurableNavigation :: WNConfig -> l a -> ModifiedLayout WindowNavigation l a
    configurableNavigation conf :: WNConfig
    conf = WindowNavigation a -> l a -> ModifiedLayout WindowNavigation l a
    forall (m :: * -> *) (l :: * -> *) a.
    m a -> l a -> ModifiedLayout m l a
    ModifiedLayout (WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    forall a.
    WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    WindowNavigation WNConfig
    conf (Maybe (NavigationState a) -> Invisible Maybe (NavigationState a)
    forall (m :: * -> *) a. m a -> Invisible m a
    I Maybe (NavigationState a)
    forall a. Maybe a
    Nothing))

    instance LayoutModifier WindowNavigation Window where
        redoLayout :: WindowNavigation Window
    -> Rectangle
    -> Maybe (Stack Window)
    -> [(Window, Rectangle)]
    -> X ([(Window, Rectangle)], Maybe (WindowNavigation Window))
    redoLayout (WindowNavigation conf :: WNConfig
    conf (I st :: Maybe (NavigationState Window)
    st)) rscr :: Rectangle
    rscr (Just s :: Stack Window
    s) origwrs :: [(Window, Rectangle)]
    origwrs =
            do XConf { normalBorder :: XConf -> Window
    normalBorder = Window
    nbc, focusedBorder :: XConf -> Window
    focusedBorder = Window
    fbc, display :: XConf -> Display
    display = Display
    dpy } <- X XConf
    forall r (m :: * -> *). MonadReader r m => m r
    ask
               [uc :: Window
    uc,dc :: Window
    dc,lc :: Window
    lc,rc :: Window
    rc] <-
                   case WNConfig -> Maybe Double
    brightness WNConfig
    conf of
                   Just frac :: Double
    frac -> do Window
    myc <- Window -> Window -> Double -> X Window
    averagePixels Window
    fbc Window
    nbc Double
    frac
                                   [Window] -> X [Window]
    forall (m :: * -> *) a. Monad m => a -> m a
    return [Window
    myc,Window
    myc,Window
    myc,Window
    myc]
                   Nothing -> (String -> X Window) -> [String] -> X [Window]
    forall (t :: * -> *) (m :: * -> *) a b.
    (Traversable t, Monad m) =>
    (a -> m b) -> t a -> m (t b)
    mapM (Display -> String -> X Window
    forall (m :: * -> *).
    (Functor m, MonadIO m) =>
    Display -> String -> m Window
    stringToPixel Display
    dpy) [WNConfig -> String
    upColor WNConfig
    conf, WNConfig -> String
    downColor WNConfig
    conf,
                                                        WNConfig -> String
    leftColor WNConfig
    conf, WNConfig -> String
    rightColor WNConfig
    conf]
               let dirc :: Direction2D -> Window
    dirc U = Window
    uc
                   dirc D = Window
    dc
                   dirc L = Window
    lc
                   dirc R = Window
    rc
               let w :: Window
    w    = Stack Window -> Window
    forall a. Stack a -> a
    W.focus Stack Window
    s
                   r :: Rectangle
    r    = case ((Window, Rectangle) -> Bool)
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ((Window -> Window -> Bool
    forall a. Eq a => a -> a -> Bool
    ==Window
    w)(Window -> Bool)
    -> ((Window, Rectangle) -> Window) -> (Window, Rectangle) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    .(Window, Rectangle) -> Window
    forall a b. (a, b) -> a
    fst) [(Window, Rectangle)]
    origwrs of ((_,x :: Rectangle
    x):_) -> Rectangle
    x
                                                             []        -> Rectangle
    rscr
                   pt :: Point
    pt   = case Maybe (NavigationState Window)
    st of Just (NS ptold :: Point
    ptold _) | Point
    ptold Point -> Rectangle -> Bool
    `inrect` Rectangle
    r -> Point
    ptold
                                     _ -> Rectangle -> Point
    center Rectangle
    r
                   existing_wins :: [Window]
    existing_wins = Stack Window -> [Window]
    forall a. Stack a -> [a]
    W.integrate Stack Window
    s
                   wrs :: [(Window, Rectangle)]
    wrs = ((Window, Rectangle) -> Bool)
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ((Window -> [Window] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` [Window]
    existing_wins) (Window -> Bool)
    -> ((Window, Rectangle) -> Window) -> (Window, Rectangle) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Window, Rectangle) -> Window
    forall a b. (a, b) -> a
    fst) ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a b. (a -> b) -> a -> b
    $ ((Window, Rectangle) -> Bool)
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ((Rectangle -> Rectangle -> Bool
    forall a. Eq a => a -> a -> Bool
    /=Rectangle
    r) (Rectangle -> Bool)
    -> ((Window, Rectangle) -> Rectangle)
    -> (Window, Rectangle)
    -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Window, Rectangle) -> Rectangle
    forall a b. (a, b) -> b
    snd) ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a b. (a -> b) -> a -> b
    $
                         ((Window, Rectangle) -> Bool)
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter ((Window -> Window -> Bool
    forall a. Eq a => a -> a -> Bool
    /=Window
    w) (Window -> Bool)
    -> ((Window, Rectangle) -> Window) -> (Window, Rectangle) -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Window, Rectangle) -> Window
    forall a b. (a, b) -> a
    fst) [(Window, Rectangle)]
    origwrs
                   wnavigable :: [(Window, Rectangle)]
    wnavigable = [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. Eq a => [a] -> [a]
    nub ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a b. (a -> b) -> a -> b
    $ (Direction2D -> [(Window, Rectangle)])
    -> [Direction2D] -> [(Window, Rectangle)]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap
                                (\d :: Direction2D
    d -> Int -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. Int -> [a] -> [a]
    take 1 ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a b. (a -> b) -> a -> b
    $ Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable Direction2D
    d Point
    pt [(Window, Rectangle)]
    wrs) [Direction2D
    U,Direction2D
    D,Direction2D
    R,Direction2D
    L]
                   wnavigablec :: [(Window, Window)]
    wnavigablec = [(Window, Window)] -> [(Window, Window)]
    forall a. Eq a => [a] -> [a]
    nub ([(Window, Window)] -> [(Window, Window)])
    -> [(Window, Window)] -> [(Window, Window)]
    forall a b. (a -> b) -> a -> b
    $ (Direction2D -> [(Window, Window)])
    -> [Direction2D] -> [(Window, Window)]
    forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
    concatMap
                                (\d :: Direction2D
    d -> ((Window, Rectangle) -> (Window, Window))
    -> [(Window, Rectangle)] -> [(Window, Window)]
    forall a b. (a -> b) -> [a] -> [b]
    map (\(win :: Window
    win,_) -> (Window
    win,Direction2D -> Window
    dirc Direction2D
    d)) ([(Window, Rectangle)] -> [(Window, Window)])
    -> [(Window, Rectangle)] -> [(Window, Window)]
    forall a b. (a -> b) -> a -> b
    $
                                       Int -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. Int -> [a] -> [a]
    take 1 ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a b. (a -> b) -> a -> b
    $ Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable Direction2D
    d Point
    pt [(Window, Rectangle)]
    wrs) [Direction2D
    U,Direction2D
    D,Direction2D
    R,Direction2D
    L]
                   wothers :: [Window]
    wothers = case Maybe (NavigationState Window)
    st of Just (NS _ wo :: [(Window, Rectangle)]
    wo) -> ((Window, Rectangle) -> Window)
    -> [(Window, Rectangle)] -> [Window]
    forall a b. (a -> b) -> [a] -> [b]
    map (Window, Rectangle) -> Window
    forall a b. (a, b) -> a
    fst [(Window, Rectangle)]
    wo
                                        _              -> []
               (Window -> X ()) -> [Window] -> X ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ (Window -> Window -> X ()
    sc Window
    nbc) ([Window]
    wothers [Window] -> [Window] -> [Window]
    forall a. Eq a => [a] -> [a] -> [a]
    \\ ((Window, Rectangle) -> Window)
    -> [(Window, Rectangle)] -> [Window]
    forall a b. (a -> b) -> [a] -> [b]
    map (Window, Rectangle) -> Window
    forall a b. (a, b) -> a
    fst [(Window, Rectangle)]
    wnavigable)
               ((Window, Window) -> X ()) -> [(Window, Window)] -> X ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ (\(win :: Window
    win,c :: Window
    c) -> Window -> Window -> X ()
    sc Window
    c Window
    win) [(Window, Window)]
    wnavigablec
               ([(Window, Rectangle)], Maybe (WindowNavigation Window))
    -> X ([(Window, Rectangle)], Maybe (WindowNavigation Window))
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([(Window, Rectangle)]
    origwrs, WindowNavigation Window -> Maybe (WindowNavigation Window)
    forall a. a -> Maybe a
    Just (WindowNavigation Window -> Maybe (WindowNavigation Window))
    -> WindowNavigation Window -> Maybe (WindowNavigation Window)
    forall a b. (a -> b) -> a -> b
    $ WNConfig
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a.
    WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    WindowNavigation WNConfig
    conf (Invisible Maybe (NavigationState Window)
     -> WindowNavigation Window)
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a b. (a -> b) -> a -> b
    $ Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall (m :: * -> *) a. m a -> Invisible m a
    I (Maybe (NavigationState Window)
     -> Invisible Maybe (NavigationState Window))
    -> Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $ NavigationState Window -> Maybe (NavigationState Window)
    forall a. a -> Maybe a
    Just (NavigationState Window -> Maybe (NavigationState Window))
    -> NavigationState Window -> Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $ Point -> [(Window, Rectangle)] -> NavigationState Window
    forall a. Point -> [(a, Rectangle)] -> NavigationState a
    NS Point
    pt [(Window, Rectangle)]
    wnavigable)
        redoLayout _ _ _ origwrs :: [(Window, Rectangle)]
    origwrs = ([(Window, Rectangle)], Maybe (WindowNavigation Window))
    -> X ([(Window, Rectangle)], Maybe (WindowNavigation Window))
    forall (m :: * -> *) a. Monad m => a -> m a
    return ([(Window, Rectangle)]
    origwrs, Maybe (WindowNavigation Window)
    forall a. Maybe a
    Nothing)

        handleMessOrMaybeModifyIt :: WindowNavigation Window
    -> SomeMessage
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    handleMessOrMaybeModifyIt (WindowNavigation conf :: WNConfig
    conf (I (Just (NS pt :: Point
    pt wrs :: [(Window, Rectangle)]
    wrs)))) m :: SomeMessage
    m
            | Just (Go d :: Direction2D
    d) <- SomeMessage -> Maybe Navigate
    forall m. Message m => SomeMessage -> Maybe m
    fromMessage SomeMessage
    m =
                             case Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable Direction2D
    d Point
    pt [(Window, Rectangle)]
    wrs of
                             []        -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing
                             ((w :: Window
    w,r :: Rectangle
    r):_) -> do (XState -> XState) -> X ()
    forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
    modify XState -> XState
    focusWindowHere
                                             Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (Either (WindowNavigation Window) SomeMessage)
     -> X (Maybe (Either (WindowNavigation Window) SomeMessage)))
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall a b. (a -> b) -> a -> b
    $ Either (WindowNavigation Window) SomeMessage
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. a -> Maybe a
    Just (Either (WindowNavigation Window) SomeMessage
     -> Maybe (Either (WindowNavigation Window) SomeMessage))
    -> Either (WindowNavigation Window) SomeMessage
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a b. (a -> b) -> a -> b
    $ WindowNavigation Window
    -> Either (WindowNavigation Window) SomeMessage
    forall a b. a -> Either a b
    Left (WindowNavigation Window
     -> Either (WindowNavigation Window) SomeMessage)
    -> WindowNavigation Window
    -> Either (WindowNavigation Window) SomeMessage
    forall a b. (a -> b) -> a -> b
    $ WNConfig
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a.
    WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    WindowNavigation WNConfig
    conf (Invisible Maybe (NavigationState Window)
     -> WindowNavigation Window)
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a b. (a -> b) -> a -> b
    $ Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall (m :: * -> *) a. m a -> Invisible m a
    I (Maybe (NavigationState Window)
     -> Invisible Maybe (NavigationState Window))
    -> Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $ NavigationState Window -> Maybe (NavigationState Window)
    forall a. a -> Maybe a
    Just (NavigationState Window -> Maybe (NavigationState Window))
    -> NavigationState Window -> Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $
                                                    Point -> [(Window, Rectangle)] -> NavigationState Window
    forall a. Point -> [(a, Rectangle)] -> NavigationState a
    NS (Direction2D -> Point -> Rectangle -> Point
    centerd Direction2D
    d Point
    pt Rectangle
    r) [(Window, Rectangle)]
    wrs
                                 where focusWindowHere :: XState -> XState
                                       focusWindowHere :: XState -> XState
    focusWindowHere s :: XState
    s
                                           | Window -> Maybe Window
    forall a. a -> Maybe a
    Just Window
    w Maybe Window -> Maybe Window -> Bool
    forall a. Eq a => a -> a -> Bool
    == StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> Maybe Window
    forall i l a s sd. StackSet i l a s sd -> Maybe a
    W.peek (XState
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    windowset XState
    s) = XState
    s
                                           | Window -> Maybe (Stack Window) -> Bool
    forall a. Eq a => a -> Maybe (Stack a) -> Bool
    has Window
    w (Maybe (Stack Window) -> Bool) -> Maybe (Stack Window) -> Bool
    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 String (Layout Window) Window ScreenId ScreenDetail
    -> 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 (Layout Window) Window ScreenId ScreenDetail
     -> Workspace String (Layout Window) Window)
    -> Screen String (Layout Window) Window ScreenId ScreenDetail
    -> Workspace String (Layout Window) Window
    forall a b. (a -> b) -> a -> b
    $ StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> Screen String (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 String (Layout Window) Window ScreenId ScreenDetail
     -> Screen String (Layout Window) Window ScreenId ScreenDetail)
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> Screen String (Layout Window) Window ScreenId ScreenDetail
    forall a b. (a -> b) -> a -> b
    $ XState
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    windowset XState
    s =
                                               XState
    s { windowset :: StackSet String (Layout Window) Window ScreenId ScreenDetail
    windowset = (StackSet String (Layout Window) Window ScreenId ScreenDetail
     -> Bool)
    -> (StackSet String (Layout Window) Window ScreenId ScreenDetail
        -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    forall a. (a -> Bool) -> (a -> a) -> a -> a
    until ((Window -> Maybe Window
    forall a. a -> Maybe a
    Just Window
    w Maybe Window -> Maybe Window -> Bool
    forall a. Eq a => a -> a -> Bool
    ==) (Maybe Window -> Bool)
    -> (StackSet String (Layout Window) Window ScreenId ScreenDetail
        -> Maybe Window)
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> Maybe Window
    forall i l a s sd. StackSet i l a s sd -> Maybe a
    W.peek)
                                                               StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    forall i l a s sd. StackSet i l a s sd -> StackSet i l a s sd
    W.focusUp (StackSet String (Layout Window) Window ScreenId ScreenDetail
     -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    forall a b. (a -> b) -> a -> b
    $ XState
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    windowset XState
    s }
                                           | Bool
    otherwise = XState
    s
                                       has :: a -> Maybe (Stack a) -> Bool
    has _ Nothing         = Bool
    False
                                       has x :: a
    x (Just (W.Stack t :: a
    t l :: [a]
    l rr :: [a]
    rr)) = a
    x a -> [a] -> Bool
    forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
    `elem` (a
    t a -> [a] -> [a]
    forall a. a -> [a] -> [a]
    : [a]
    l [a] -> [a] -> [a]
    forall a. [a] -> [a] -> [a]
    ++ [a]
    rr)

            | Just (Swap d :: Direction2D
    d) <- SomeMessage -> Maybe Navigate
    forall m. Message m => SomeMessage -> Maybe m
    fromMessage SomeMessage
    m =
                 case Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable Direction2D
    d Point
    pt [(Window, Rectangle)]
    wrs of
                 []        -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing
                 ((w :: Window
    w,_):_) -> do let swap :: Stack Window -> Stack Window
    swap st :: Stack Window
    st = Window -> [Window] -> Stack Window
    forall a. Eq a => a -> [a] -> Stack a
    unint (Stack Window -> Window
    forall a. Stack a -> a
    W.focus Stack Window
    st) ([Window] -> Stack Window) -> [Window] -> Stack Window
    forall a b. (a -> b) -> a -> b
    $ (Window -> Window) -> [Window] -> [Window]
    forall a b. (a -> b) -> [a] -> [b]
    map (Window -> Window -> Window
    swapw (Stack Window -> Window
    forall a. Stack a -> a
    W.focus Stack Window
    st)) ([Window] -> [Window]) -> [Window] -> [Window]
    forall a b. (a -> b) -> a -> b
    $ Stack Window -> [Window]
    forall a. Stack a -> [a]
    W.integrate Stack Window
    st
                                     swapw :: Window -> Window -> Window
    swapw y :: Window
    y x :: Window
    x | Window
    x Window -> Window -> Bool
    forall a. Eq a => a -> a -> Bool
    == Window
    w = Window
    y
                                               | Window
    x Window -> Window -> Bool
    forall a. Eq a => a -> a -> Bool
    == Window
    y = Window
    w
                                               | Bool
    otherwise = Window
    x
                                     unint :: a -> [a] -> Stack a
    unint f :: a
    f xs :: [a]
    xs = case (a -> Bool) -> [a] -> ([a], [a])
    forall a. (a -> Bool) -> [a] -> ([a], [a])
    span (a -> a -> Bool
    forall a. Eq a => a -> a -> Bool
    /= a
    f) [a]
    xs of
                                                  (u :: [a]
    u,_:dn :: [a]
    dn) -> $WStack :: forall a. a -> [a] -> [a] -> Stack a
    W.Stack { focus :: a
    W.focus = a
    f
                                                                      , up :: [a]
    W.up = [a] -> [a]
    forall a. [a] -> [a]
    reverse [a]
    u
                                                                      , down :: [a]
    W.down = [a]
    dn }
                                                  _ -> $WStack :: forall a. a -> [a] -> [a] -> Stack a
    W.Stack { focus :: a
    W.focus = a
    f
                                                               , down :: [a]
    W.down = [a]
    xs
                                                               , up :: [a]
    W.up = [] }
                                 (StackSet String (Layout Window) Window ScreenId ScreenDetail
     -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
    -> X ()
    windows ((StackSet String (Layout Window) Window ScreenId ScreenDetail
      -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
     -> X ())
    -> (StackSet String (Layout Window) Window ScreenId ScreenDetail
        -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
    -> X ()
    forall a b. (a -> b) -> a -> b
    $ (Stack Window -> Stack Window)
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    forall a i l s sd.
    (Stack a -> Stack a) -> StackSet i l a s sd -> StackSet i l a s sd
    W.modify' Stack Window -> Stack Window
    swap
                                 Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing
            | Just (Move d :: Direction2D
    d) <- SomeMessage -> Maybe Navigate
    forall m. Message m => SomeMessage -> Maybe m
    fromMessage SomeMessage
    m =
                 case Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable Direction2D
    d Point
    pt [(Window, Rectangle)]
    wrs of
                 []        -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing
                 ((w :: Window
    w,_):_) -> do Maybe (Stack Window)
    mst <- (XState -> Maybe (Stack Window)) -> X (Maybe (Stack Window))
    forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
    gets (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))
    -> (XState -> Workspace String (Layout Window) Window)
    -> XState
    -> Maybe (Stack Window)
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . Screen String (Layout Window) Window ScreenId ScreenDetail
    -> 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 (Layout Window) Window ScreenId ScreenDetail
     -> Workspace String (Layout Window) Window)
    -> (XState
        -> Screen String (Layout Window) Window ScreenId ScreenDetail)
    -> XState
    -> Workspace String (Layout Window) Window
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . StackSet String (Layout Window) Window ScreenId ScreenDetail
    -> Screen String (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 String (Layout Window) Window ScreenId ScreenDetail
     -> Screen String (Layout Window) Window ScreenId ScreenDetail)
    -> (XState
        -> StackSet String (Layout Window) Window ScreenId ScreenDetail)
    -> XState
    -> Screen String (Layout Window) Window ScreenId ScreenDetail
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . XState
    -> StackSet String (Layout Window) Window ScreenId ScreenDetail
    windowset)
                                 Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (Either (WindowNavigation Window) SomeMessage)
     -> X (Maybe (Either (WindowNavigation Window) SomeMessage)))
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall a b. (a -> b) -> a -> b
    $ do Stack Window
    st <- Maybe (Stack Window)
    mst
                                             Either (WindowNavigation Window) SomeMessage
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. a -> Maybe a
    Just (Either (WindowNavigation Window) SomeMessage
     -> Maybe (Either (WindowNavigation Window) SomeMessage))
    -> Either (WindowNavigation Window) SomeMessage
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a b. (a -> b) -> a -> b
    $ SomeMessage -> Either (WindowNavigation Window) SomeMessage
    forall a b. b -> Either a b
    Right (SomeMessage -> Either (WindowNavigation Window) SomeMessage)
    -> SomeMessage -> Either (WindowNavigation Window) SomeMessage
    forall a b. (a -> b) -> a -> b
    $ MoveWindowToWindow Window -> SomeMessage
    forall a. Message a => a -> SomeMessage
    SomeMessage (MoveWindowToWindow Window -> SomeMessage)
    -> MoveWindowToWindow Window -> SomeMessage
    forall a b. (a -> b) -> a -> b
    $ Window -> Window -> MoveWindowToWindow Window
    forall a. a -> a -> MoveWindowToWindow a
    MoveWindowToWindow (Stack Window -> Window
    forall a. Stack a -> a
    W.focus Stack Window
    st) Window
    w
            | Just (Apply f :: Window -> X ()
    f d :: Direction2D
    d) <- SomeMessage -> Maybe Navigate
    forall m. Message m => SomeMessage -> Maybe m
    fromMessage SomeMessage
    m =
                 case Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable Direction2D
    d Point
    pt [(Window, Rectangle)]
    wrs of
                 []         -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing
                 ((w :: Window
    w,_):_)  -> Window -> X ()
    f Window
    w X ()
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
    >> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing
            | Just Hide <- SomeMessage -> Maybe LayoutMessages
    forall m. Message m => SomeMessage -> Maybe m
    fromMessage SomeMessage
    m =
                           do XConf { normalBorder :: XConf -> Window
    normalBorder = Window
    nbc } <- X XConf
    forall r (m :: * -> *). MonadReader r m => m r
    ask
                              ((Window, Rectangle) -> X ()) -> [(Window, Rectangle)] -> X ()
    forall (t :: * -> *) (m :: * -> *) a b.
    (Foldable t, Monad m) =>
    (a -> m b) -> t a -> m ()
    mapM_ (Window -> Window -> X ()
    sc Window
    nbc (Window -> X ())
    -> ((Window, Rectangle) -> Window) -> (Window, Rectangle) -> X ()
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Window, Rectangle) -> Window
    forall a b. (a, b) -> a
    fst) [(Window, Rectangle)]
    wrs
                              Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return (Maybe (Either (WindowNavigation Window) SomeMessage)
     -> X (Maybe (Either (WindowNavigation Window) SomeMessage)))
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall a b. (a -> b) -> a -> b
    $ Either (WindowNavigation Window) SomeMessage
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. a -> Maybe a
    Just (Either (WindowNavigation Window) SomeMessage
     -> Maybe (Either (WindowNavigation Window) SomeMessage))
    -> Either (WindowNavigation Window) SomeMessage
    -> Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a b. (a -> b) -> a -> b
    $ WindowNavigation Window
    -> Either (WindowNavigation Window) SomeMessage
    forall a b. a -> Either a b
    Left (WindowNavigation Window
     -> Either (WindowNavigation Window) SomeMessage)
    -> WindowNavigation Window
    -> Either (WindowNavigation Window) SomeMessage
    forall a b. (a -> b) -> a -> b
    $ WNConfig
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a.
    WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    WindowNavigation WNConfig
    conf (Invisible Maybe (NavigationState Window)
     -> WindowNavigation Window)
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a b. (a -> b) -> a -> b
    $ Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall (m :: * -> *) a. m a -> Invisible m a
    I (Maybe (NavigationState Window)
     -> Invisible Maybe (NavigationState Window))
    -> Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $ NavigationState Window -> Maybe (NavigationState Window)
    forall a. a -> Maybe a
    Just (NavigationState Window -> Maybe (NavigationState Window))
    -> NavigationState Window -> Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $ Point -> [(Window, Rectangle)] -> NavigationState Window
    forall a. Point -> [(a, Rectangle)] -> NavigationState a
    NS Point
    pt []
            | Just ReleaseResources <- SomeMessage -> Maybe LayoutMessages
    forall m. Message m => SomeMessage -> Maybe m
    fromMessage SomeMessage
    m =
                   WindowNavigation Window
    -> SomeMessage
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a.
    LayoutModifier m a =>
    m a -> SomeMessage -> X (Maybe (Either (m a) SomeMessage))
    handleMessOrMaybeModifyIt (WNConfig
    -> Invisible Maybe (NavigationState Window)
    -> WindowNavigation Window
    forall a.
    WNConfig
    -> Invisible Maybe (NavigationState a) -> WindowNavigation a
    WindowNavigation WNConfig
    conf (Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall (m :: * -> *) a. m a -> Invisible m a
    I (Maybe (NavigationState Window)
     -> Invisible Maybe (NavigationState Window))
    -> Maybe (NavigationState Window)
    -> Invisible Maybe (NavigationState Window)
    forall a b. (a -> b) -> a -> b
    $ NavigationState Window -> Maybe (NavigationState Window)
    forall a. a -> Maybe a
    Just (Point -> [(Window, Rectangle)] -> NavigationState Window
    forall a. Point -> [(a, Rectangle)] -> NavigationState a
    NS Point
    pt [(Window, Rectangle)]
    wrs))) (LayoutMessages -> SomeMessage
    forall a. Message a => a -> SomeMessage
    SomeMessage LayoutMessages
    Hide)
        handleMessOrMaybeModifyIt _ _ = Maybe (Either (WindowNavigation Window) SomeMessage)
    -> X (Maybe (Either (WindowNavigation Window) SomeMessage))
    forall (m :: * -> *) a. Monad m => a -> m a
    return Maybe (Either (WindowNavigation Window) SomeMessage)
    forall a. Maybe a
    Nothing

    navigable :: Direction2D -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable :: Direction2D
    -> Point -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    navigable d :: Direction2D
    d pt :: Point
    pt = Direction2D -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. Direction2D -> [(a, Rectangle)] -> [(a, Rectangle)]
    sortby Direction2D
    d ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> ([(Window, Rectangle)] -> [(Window, Rectangle)])
    -> [(Window, Rectangle)]
    -> [(Window, Rectangle)]
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . ((Window, Rectangle) -> Bool)
    -> [(Window, Rectangle)] -> [(Window, Rectangle)]
    forall a. (a -> Bool) -> [a] -> [a]
    filter (Direction2D -> Point -> Rectangle -> Bool
    inr Direction2D
    d Point
    pt (Rectangle -> Bool)
    -> ((Window, Rectangle) -> Rectangle)
    -> (Window, Rectangle)
    -> Bool
    forall b c a. (b -> c) -> (a -> b) -> a -> c
    . (Window, Rectangle) -> Rectangle
    forall a b. (a, b) -> b
    snd)

    sc :: Pixel -> Window -> X ()
    sc :: Window -> Window -> X ()
    sc c :: Window
    c win :: Window
    win = (Display -> X ()) -> X ()
    forall a. (Display -> X a) -> X a
    withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
    forall a b. (a -> b) -> a -> b
    $ \dpy :: Display
    dpy -> do
        String
    colorName <- IO String -> X String
    forall (m :: * -> *) a. MonadIO m => IO a -> m a
    io (Display -> Window -> IO String
    forall (m :: * -> *). MonadIO m => Display -> Window -> m String
    pixelToString Display
    dpy Window
    c)
        Display -> Window -> String -> Window -> X ()
    setWindowBorderWithFallback Display
    dpy Window
    win String
    colorName Window
    c

    center :: Rectangle -> Point
    center :: Rectangle -> Point
    center (Rectangle x :: Position
    x y :: Position
    y w :: Dimension
    w h :: Dimension
    h) = Double -> Double -> Point
    P (Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    x Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    wDouble -> Double -> Double
    forall a. Fractional a => a -> a -> a
    /2)  (Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    y Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    hDouble -> Double -> Double
    forall a. Fractional a => a -> a -> a
    /2)

    centerd :: Direction2D -> Point -> Rectangle -> Point
    centerd :: Direction2D -> Point -> Rectangle -> Point
    centerd d :: Direction2D
    d (P xx :: Double
    xx yy :: Double
    yy) (Rectangle x :: Position
    x y :: Position
    y w :: Dimension
    w h :: Dimension
    h) | Direction2D
    d Direction2D -> Direction2D -> Bool
    forall a. Eq a => a -> a -> Bool
    == Direction2D
    U Bool -> Bool -> Bool
    || Direction2D
    d Direction2D -> Direction2D -> Bool
    forall a. Eq a => a -> a -> Bool
    == Direction2D
    D = Double -> Double -> Point
    P Double
    xx (Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    y Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    hDouble -> Double -> Double
    forall a. Fractional a => a -> a -> a
    /2)
                                            | Bool
    otherwise = Double -> Double -> Point
    P (Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    x Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    wDouble -> Double -> Double
    forall a. Fractional a => a -> a -> a
    /2) Double
    yy

    inr :: Direction2D -> Point -> Rectangle -> Bool
    inr :: Direction2D -> Point -> Rectangle -> Bool
    inr D (P x :: Double
    x y :: Double
    y) (Rectangle l :: Position
    l yr :: Position
    yr w :: Dimension
    w h :: Dimension
    h) = Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Bool -> Bool -> Bool
    && Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    < Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    w Bool -> Bool -> Bool
    &&
                                         Double
    y Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    <  Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    yr Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    h
    inr U (P x :: Double
    x y :: Double
    y) (Rectangle l :: Position
    l yr :: Position
    yr w :: Dimension
    w _) = Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Bool -> Bool -> Bool
    && Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    < Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    w Bool -> Bool -> Bool
    &&
                                         Double
    y Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >  Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    yr
    inr R (P a :: Double
    a x :: Double
    x) (Rectangle b :: Position
    b l :: Position
    l _ w :: Dimension
    w)  = Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Bool -> Bool -> Bool
    && Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    < Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    w Bool -> Bool -> Bool
    &&
                                         Double
    a Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    <  Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    b
    inr L (P a :: Double
    a x :: Double
    x) (Rectangle b :: Position
    b l :: Position
    l c :: Dimension
    c w :: Dimension
    w)  = Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >= Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Bool -> Bool -> Bool
    && Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    < Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    l Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    w Bool -> Bool -> Bool
    &&
                                         Double
    a Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >  Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    b Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    c

    inrect :: Point -> Rectangle -> Bool
    inrect :: Point -> Rectangle -> Bool
    inrect (P x :: Double
    x y :: Double
    y) (Rectangle a :: Position
    a b :: Position
    b w :: Dimension
    w h :: Dimension
    h) = Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >  Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    a Bool -> Bool -> Bool
    && Double
    x Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    < Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    a Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    w Bool -> Bool -> Bool
    &&
                                         Double
    y Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    >  Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    b Bool -> Bool -> Bool
    && Double
    y Double -> Double -> Bool
    forall a. Ord a => a -> a -> Bool
    < Position -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Position
    b Double -> Double -> Double
    forall a. Num a => a -> a -> a
    + Dimension -> Double
    forall a b. (Integral a, Num b) => a -> b
    fromIntegral Dimension
    h

    sortby :: Direction2D -> [(a,Rectangle)] -> [(a,Rectangle)]
    sortby :: Direction2D -> [(a, Rectangle)] -> [(a, Rectangle)]
    sortby U = ((a, Rectangle) -> (a, Rectangle) -> Ordering)
    -> [(a, Rectangle)] -> [(a, Rectangle)]
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (\(_,Rectangle _ y :: Position
    y _ _) (_,Rectangle _ y' :: Position
    y' _ _) -> Position -> Position -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare Position
    y' Position
    y)
    sortby D = ((a, Rectangle) -> (a, Rectangle) -> Ordering)
    -> [(a, Rectangle)] -> [(a, Rectangle)]
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (\(_,Rectangle _ y :: Position
    y _ _) (_,Rectangle _ y' :: Position
    y' _ _) -> Position -> Position -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare Position
    y Position
    y')
    sortby R = ((a, Rectangle) -> (a, Rectangle) -> Ordering)
    -> [(a, Rectangle)] -> [(a, Rectangle)]
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (\(_,Rectangle x :: Position
    x _ _ _) (_,Rectangle x' :: Position
    x' _ _ _) -> Position -> Position -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare Position
    x Position
    x')
    sortby L = ((a, Rectangle) -> (a, Rectangle) -> Ordering)
    -> [(a, Rectangle)] -> [(a, Rectangle)]
    forall a. (a -> a -> Ordering) -> [a] -> [a]
    sortBy (\(_,Rectangle x :: Position
    x _ _ _) (_,Rectangle x' :: Position
    x' _ _ _) -> Position -> Position -> Ordering
    forall a. Ord a => a -> a -> Ordering
    compare Position
    x' Position
    x)

    data Point = P Double Double