{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances #-}
module XMonad.Layout.FocusTracking
(
FocusTracking(..)
, focusTracking
) where
import XMonad.Prelude
import XMonad
import XMonad.Layout.LayoutModifier
import XMonad.Util.Stack (findZ)
import qualified XMonad.StackSet as W
newtype FocusTracking a = FocusTracking (Maybe Window)
deriving (ReadPrec [FocusTracking a]
ReadPrec (FocusTracking a)
ReadS [FocusTracking a]
forall a. ReadPrec [FocusTracking a]
forall a. ReadPrec (FocusTracking a)
forall a. Int -> ReadS (FocusTracking a)
forall a. ReadS [FocusTracking a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [FocusTracking a]
$creadListPrec :: forall a. ReadPrec [FocusTracking a]
readPrec :: ReadPrec (FocusTracking a)
$creadPrec :: forall a. ReadPrec (FocusTracking a)
readList :: ReadS [FocusTracking a]
$creadList :: forall a. ReadS [FocusTracking a]
readsPrec :: Int -> ReadS (FocusTracking a)
$creadsPrec :: forall a. Int -> ReadS (FocusTracking a)
Read, Int -> FocusTracking a -> ShowS
forall a. Int -> FocusTracking a -> ShowS
forall a. [FocusTracking a] -> ShowS
forall a. FocusTracking a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FocusTracking a] -> ShowS
$cshowList :: forall a. [FocusTracking a] -> ShowS
show :: FocusTracking a -> String
$cshow :: forall a. FocusTracking a -> String
showsPrec :: Int -> FocusTracking a -> ShowS
$cshowsPrec :: forall a. Int -> FocusTracking a -> ShowS
Show)
instance LayoutModifier FocusTracking Window where
modifyLayoutWithUpdate :: forall (l :: * -> *).
LayoutClass l Window =>
FocusTracking Window
-> Workspace String (l Window) Window
-> Rectangle
-> X (([(Window, Rectangle)], Maybe (l Window)),
Maybe (FocusTracking Window))
modifyLayoutWithUpdate (FocusTracking Maybe Window
mw) ws :: Workspace String (l Window) Window
ws@W.Workspace{ stack :: forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack = Maybe (Stack Window)
ms } Rectangle
r
= do
Maybe Window
xCur <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 (forall i l a. Workspace i l a -> i
W.tag Workspace String (l Window) Window
ws) forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState
-> StackSet String (Layout Window) Window ScreenId ScreenDetail
windowset)
let isF :: Bool
isF = Maybe Window
xCur forall a. Eq a => a -> a -> Bool
/= (forall a. Stack a -> a
W.focus forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (Stack Window)
ms)
newStack :: Maybe (Stack Window)
newStack | Bool
isF = (Maybe Window
mw forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> forall a. (a -> Bool) -> Zipper a -> Zipper a
findZ (Window
wforall a. Eq a => a -> a -> Bool
==) Maybe (Stack Window)
ms) forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Maybe (Stack Window)
ms
| Bool
otherwise = Maybe (Stack Window)
ms
newState :: Maybe Window
newState | Bool
isF = Maybe Window
mw
| Bool
otherwise = Maybe Window
xCur
([(Window, Rectangle)], Maybe (l Window))
ran <- forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace String (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout Workspace String (l Window) Window
ws{ stack :: Maybe (Stack Window)
W.stack = Maybe (Stack Window)
newStack } Rectangle
r
forall (m :: * -> *) a. Monad m => a -> m a
return (([(Window, Rectangle)], Maybe (l Window))
ran, forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Maybe Window
newState forall a. Eq a => a -> a -> Bool
/= Maybe Window
mw) forall (f :: * -> *) a b. Functor f => f a -> b -> f b
$> forall a. Maybe Window -> FocusTracking a
FocusTracking Maybe Window
newState)
focusTracking :: l a -> ModifiedLayout FocusTracking l a
focusTracking :: forall (l :: * -> *) a. l a -> ModifiedLayout FocusTracking l a
focusTracking = forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout (forall a. Maybe Window -> FocusTracking a
FocusTracking forall a. Maybe a
Nothing)