{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_HADDOCK show-extensions #-}
module XMonad.Hooks.Focus
(
Focus (..)
, FocusLock (..)
, toggleLock
, focusLockOn
, focusLockOff
, FocusQuery
, runFocusQuery
, FocusHook
, liftQuery
, new
, focused
, focused'
, focusedOn
, focusedOn'
, focusedCur
, focusedCur'
, newOn
, newOnCur
, unlessFocusLock
, keepFocus
, switchFocus
, keepWorkspace
, switchWorkspace
, manageFocus
, activateSwitchWs
, activateOnCurrentWs
, activateOnCurrentKeepFocus
)
where
import Control.Arrow ((&&&))
import Control.Monad.Reader
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
import qualified XMonad.Util.ExtensibleState as XS
import XMonad.Hooks.ManageHelpers (currentWs)
data Focus = Focus
{
Focus -> [Char]
newWorkspace :: WorkspaceId
, Focus -> Maybe Word64
focusedWindow :: Maybe Window
, Focus -> [Char]
currentWorkspace :: WorkspaceId
}
deriving (Int -> Focus -> ShowS
[Focus] -> ShowS
Focus -> [Char]
(Int -> Focus -> ShowS)
-> (Focus -> [Char]) -> ([Focus] -> ShowS) -> Show Focus
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Focus -> ShowS
showsPrec :: Int -> Focus -> ShowS
$cshow :: Focus -> [Char]
show :: Focus -> [Char]
$cshowList :: [Focus] -> ShowS
showList :: [Focus] -> ShowS
Show)
instance Default Focus where
def :: Focus
def = Focus
{ focusedWindow :: Maybe Word64
focusedWindow = Maybe Word64
forall a. Maybe a
Nothing
, newWorkspace :: [Char]
newWorkspace = [Char]
""
, currentWorkspace :: [Char]
currentWorkspace = [Char]
""
}
newtype FocusLock = FocusLock {FocusLock -> Bool
getFocusLock :: Bool}
deriving (Int -> FocusLock -> ShowS
[FocusLock] -> ShowS
FocusLock -> [Char]
(Int -> FocusLock -> ShowS)
-> (FocusLock -> [Char])
-> ([FocusLock] -> ShowS)
-> Show FocusLock
forall a.
(Int -> a -> ShowS) -> (a -> [Char]) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> FocusLock -> ShowS
showsPrec :: Int -> FocusLock -> ShowS
$cshow :: FocusLock -> [Char]
show :: FocusLock -> [Char]
$cshowList :: [FocusLock] -> ShowS
showList :: [FocusLock] -> ShowS
Show)
instance ExtensionClass FocusLock where
initialValue :: FocusLock
initialValue = Bool -> FocusLock
FocusLock Bool
False
toggleLock :: X ()
toggleLock :: X ()
toggleLock = (FocusLock -> FocusLock) -> X ()
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify (\(FocusLock Bool
b) -> Bool -> FocusLock
FocusLock (Bool -> Bool
not Bool
b))
focusLockOn :: X ()
focusLockOn :: X ()
focusLockOn = (FocusLock -> FocusLock) -> X ()
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify (FocusLock -> FocusLock -> FocusLock
forall a b. a -> b -> a
const (Bool -> FocusLock
FocusLock Bool
True))
focusLockOff :: X ()
focusLockOff :: X ()
focusLockOff = (FocusLock -> FocusLock) -> X ()
forall a (m :: * -> *).
(ExtensionClass a, XLike m) =>
(a -> a) -> m ()
XS.modify (FocusLock -> FocusLock -> FocusLock
forall a b. a -> b -> a
const (Bool -> FocusLock
FocusLock Bool
False))
newtype FocusQuery a = FocusQuery (ReaderT Focus Query a)
deriving newtype ((forall a b. (a -> b) -> FocusQuery a -> FocusQuery b)
-> (forall a b. a -> FocusQuery b -> FocusQuery a)
-> Functor FocusQuery
forall a b. a -> FocusQuery b -> FocusQuery a
forall a b. (a -> b) -> FocusQuery a -> FocusQuery b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> FocusQuery a -> FocusQuery b
fmap :: forall a b. (a -> b) -> FocusQuery a -> FocusQuery b
$c<$ :: forall a b. a -> FocusQuery b -> FocusQuery a
<$ :: forall a b. a -> FocusQuery b -> FocusQuery a
Functor, Functor FocusQuery
Functor FocusQuery =>
(forall a. a -> FocusQuery a)
-> (forall a b.
FocusQuery (a -> b) -> FocusQuery a -> FocusQuery b)
-> (forall a b c.
(a -> b -> c) -> FocusQuery a -> FocusQuery b -> FocusQuery c)
-> (forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b)
-> (forall a b. FocusQuery a -> FocusQuery b -> FocusQuery a)
-> Applicative FocusQuery
forall a. a -> FocusQuery a
forall a b. FocusQuery a -> FocusQuery b -> FocusQuery a
forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b
forall a b. FocusQuery (a -> b) -> FocusQuery a -> FocusQuery b
forall a b c.
(a -> b -> c) -> FocusQuery a -> FocusQuery b -> FocusQuery c
forall (f :: * -> *).
Functor f =>
(forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
$cpure :: forall a. a -> FocusQuery a
pure :: forall a. a -> FocusQuery a
$c<*> :: forall a b. FocusQuery (a -> b) -> FocusQuery a -> FocusQuery b
<*> :: forall a b. FocusQuery (a -> b) -> FocusQuery a -> FocusQuery b
$cliftA2 :: forall a b c.
(a -> b -> c) -> FocusQuery a -> FocusQuery b -> FocusQuery c
liftA2 :: forall a b c.
(a -> b -> c) -> FocusQuery a -> FocusQuery b -> FocusQuery c
$c*> :: forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b
*> :: forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b
$c<* :: forall a b. FocusQuery a -> FocusQuery b -> FocusQuery a
<* :: forall a b. FocusQuery a -> FocusQuery b -> FocusQuery a
Applicative, Applicative FocusQuery
Applicative FocusQuery =>
(forall a b. FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b)
-> (forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b)
-> (forall a. a -> FocusQuery a)
-> Monad FocusQuery
forall a. a -> FocusQuery a
forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b
forall a b. FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b
forall (m :: * -> *).
Applicative m =>
(forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
$c>>= :: forall a b. FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b
>>= :: forall a b. FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b
$c>> :: forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b
>> :: forall a b. FocusQuery a -> FocusQuery b -> FocusQuery b
$creturn :: forall a. a -> FocusQuery a
return :: forall a. a -> FocusQuery a
Monad, MonadReader Focus, Monad FocusQuery
Monad FocusQuery =>
(forall a. IO a -> FocusQuery a) -> MonadIO FocusQuery
forall a. IO a -> FocusQuery a
forall (m :: * -> *).
Monad m =>
(forall a. IO a -> m a) -> MonadIO m
$cliftIO :: forall a. IO a -> FocusQuery a
liftIO :: forall a. IO a -> FocusQuery a
MonadIO)
deriving (NonEmpty (FocusQuery a) -> FocusQuery a
FocusQuery a -> FocusQuery a -> FocusQuery a
(FocusQuery a -> FocusQuery a -> FocusQuery a)
-> (NonEmpty (FocusQuery a) -> FocusQuery a)
-> (forall b. Integral b => b -> FocusQuery a -> FocusQuery a)
-> Semigroup (FocusQuery a)
forall b. Integral b => b -> FocusQuery a -> FocusQuery a
forall a. Semigroup a => NonEmpty (FocusQuery a) -> FocusQuery a
forall a.
Semigroup a =>
FocusQuery a -> FocusQuery a -> FocusQuery a
forall a b.
(Semigroup a, Integral b) =>
b -> FocusQuery a -> FocusQuery a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
$c<> :: forall a.
Semigroup a =>
FocusQuery a -> FocusQuery a -> FocusQuery a
<> :: FocusQuery a -> FocusQuery a -> FocusQuery a
$csconcat :: forall a. Semigroup a => NonEmpty (FocusQuery a) -> FocusQuery a
sconcat :: NonEmpty (FocusQuery a) -> FocusQuery a
$cstimes :: forall a b.
(Semigroup a, Integral b) =>
b -> FocusQuery a -> FocusQuery a
stimes :: forall b. Integral b => b -> FocusQuery a -> FocusQuery a
Semigroup, Semigroup (FocusQuery a)
FocusQuery a
Semigroup (FocusQuery a) =>
FocusQuery a
-> (FocusQuery a -> FocusQuery a -> FocusQuery a)
-> ([FocusQuery a] -> FocusQuery a)
-> Monoid (FocusQuery a)
[FocusQuery a] -> FocusQuery a
FocusQuery a -> FocusQuery a -> FocusQuery a
forall a.
Semigroup a =>
a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. Monoid a => Semigroup (FocusQuery a)
forall a. Monoid a => FocusQuery a
forall a. Monoid a => [FocusQuery a] -> FocusQuery a
forall a. Monoid a => FocusQuery a -> FocusQuery a -> FocusQuery a
$cmempty :: forall a. Monoid a => FocusQuery a
mempty :: FocusQuery a
$cmappend :: forall a. Monoid a => FocusQuery a -> FocusQuery a -> FocusQuery a
mappend :: FocusQuery a -> FocusQuery a -> FocusQuery a
$cmconcat :: forall a. Monoid a => [FocusQuery a] -> FocusQuery a
mconcat :: [FocusQuery a] -> FocusQuery a
Monoid) via Ap FocusQuery a
runFocusQuery :: FocusQuery a -> Focus -> Query a
runFocusQuery :: forall a. FocusQuery a -> Focus -> Query a
runFocusQuery (FocusQuery ReaderT Focus Query a
m) = ReaderT Focus Query a -> Focus -> Query a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT ReaderT Focus Query a
m
type FocusHook = FocusQuery (Endo WindowSet)
liftQuery :: Query a -> FocusQuery a
liftQuery :: forall a. Query a -> FocusQuery a
liftQuery = ReaderT Focus Query a -> FocusQuery a
forall a. ReaderT Focus Query a -> FocusQuery a
FocusQuery (ReaderT Focus Query a -> FocusQuery a)
-> (Query a -> ReaderT Focus Query a) -> Query a -> FocusQuery a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query a -> ReaderT Focus Query a
forall (m :: * -> *) a. Monad m => m a -> ReaderT Focus m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift
new :: Query a -> FocusQuery a
new :: forall a. Query a -> FocusQuery a
new = Query a -> FocusQuery a
forall a. Query a -> FocusQuery a
liftQuery
focused :: Query Bool -> FocusQuery Bool
focused :: Query Bool -> FocusQuery Bool
focused Query Bool
m = Any -> Bool
getAny (Any -> Bool) -> FocusQuery Any -> FocusQuery Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query Any -> FocusQuery Any
forall a. Monoid a => Query a -> FocusQuery a
focused' (Bool -> Any
Any (Bool -> Any) -> Query Bool -> Query Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query Bool
m)
focused' :: Monoid a => Query a -> FocusQuery a
focused' :: forall a. Monoid a => Query a -> FocusQuery a
focused' Query a
m = do
mw <- (Focus -> Maybe Word64) -> FocusQuery (Maybe Word64)
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Focus -> Maybe Word64
focusedWindow
liftQuery (maybe mempty (flip local m . const) mw)
focusedOn :: WorkspaceId -> Query Bool -> FocusQuery Bool
focusedOn :: [Char] -> Query Bool -> FocusQuery Bool
focusedOn [Char]
i Query Bool
m = Any -> Bool
getAny (Any -> Bool) -> FocusQuery Any -> FocusQuery Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Char] -> Query Any -> FocusQuery Any
forall a. Monoid a => [Char] -> Query a -> FocusQuery a
focusedOn' [Char]
i (Bool -> Any
Any (Bool -> Any) -> Query Bool -> Query Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query Bool
m)
focusedOn' :: Monoid a => WorkspaceId -> Query a -> FocusQuery a
focusedOn' :: forall a. Monoid a => [Char] -> Query a -> FocusQuery a
focusedOn' [Char]
i Query a
m = Query a -> FocusQuery a
forall a. Query a -> FocusQuery a
liftQuery (Query a -> FocusQuery a) -> Query a -> FocusQuery a
forall a b. (a -> b) -> a -> b
$ do
mw <- X (Maybe Word64) -> Query (Maybe Word64)
forall a. X a -> Query a
liftX (X (Maybe Word64) -> Query (Maybe Word64))
-> X (Maybe Word64) -> Query (Maybe Word64)
forall a b. (a -> b) -> a -> b
$ (WindowSet -> X (Maybe Word64)) -> X (Maybe Word64)
forall a. (WindowSet -> X a) -> X a
withWindowSet (Maybe Word64 -> X (Maybe Word64)
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Word64 -> X (Maybe Word64))
-> (WindowSet -> Maybe Word64) -> WindowSet -> X (Maybe Word64)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> Maybe Word64
forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek (WindowSet -> Maybe Word64)
-> (WindowSet -> WindowSet) -> WindowSet -> Maybe Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> 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 [Char]
i)
maybe mempty (flip local m . const) mw
focusedCur :: Query Bool -> FocusQuery Bool
focusedCur :: Query Bool -> FocusQuery Bool
focusedCur Query Bool
m = Any -> Bool
getAny (Any -> Bool) -> FocusQuery Any -> FocusQuery Bool
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query Any -> FocusQuery Any
forall a. Monoid a => Query a -> FocusQuery a
focusedCur' (Bool -> Any
Any (Bool -> Any) -> Query Bool -> Query Any
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Query Bool
m)
focusedCur' :: Monoid a => Query a -> FocusQuery a
focusedCur' :: forall a. Monoid a => Query a -> FocusQuery a
focusedCur' Query a
m = (Focus -> [Char]) -> FocusQuery [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Focus -> [Char]
currentWorkspace FocusQuery [Char] -> ([Char] -> FocusQuery a) -> FocusQuery a
forall a b. FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \[Char]
i -> [Char] -> Query a -> FocusQuery a
forall a. Monoid a => [Char] -> Query a -> FocusQuery a
focusedOn' [Char]
i Query a
m
newOn :: WorkspaceId -> FocusQuery Bool
newOn :: [Char] -> FocusQuery Bool
newOn [Char]
i = (Focus -> Bool) -> FocusQuery Bool
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks (([Char]
i [Char] -> [Char] -> Bool
forall a. Eq a => a -> a -> Bool
==) ([Char] -> Bool) -> (Focus -> [Char]) -> Focus -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Focus -> [Char]
newWorkspace)
newOnCur :: FocusQuery Bool
newOnCur :: FocusQuery Bool
newOnCur = (Focus -> [Char]) -> FocusQuery [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Focus -> [Char]
currentWorkspace FocusQuery [Char] -> ([Char] -> FocusQuery Bool) -> FocusQuery Bool
forall a b. FocusQuery a -> (a -> FocusQuery b) -> FocusQuery b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [Char] -> FocusQuery Bool
newOn
unlessFocusLock :: Monoid a => Query a -> Query a
unlessFocusLock :: forall a. Monoid a => Query a -> Query a
unlessFocusLock Query a
m = do
FocusLock b <- X FocusLock -> Query FocusLock
forall a. X a -> Query a
liftX X FocusLock
forall a (m :: * -> *). (ExtensionClass a, XLike m) => m a
XS.get
when' (not b) m
keepFocus :: FocusHook
keepFocus :: FocusQuery (Endo WindowSet)
keepFocus = Query (Endo WindowSet) -> FocusQuery (Endo WindowSet)
forall a. Monoid a => Query a -> FocusQuery a
focused' (Query (Endo WindowSet) -> FocusQuery (Endo WindowSet))
-> Query (Endo WindowSet) -> FocusQuery (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ Query Word64
forall r (m :: * -> *). MonadReader r m => m r
ask Query Word64
-> (Word64 -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall a b. Query a -> (a -> Query b) -> Query b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Word64
w -> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF ((WindowSet -> WindowSet) -> Query (Endo WindowSet))
-> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ \WindowSet
ws ->
[Char] -> 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 (WindowSet -> [Char]
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag WindowSet
ws) (WindowSet -> WindowSet)
-> (WindowSet -> WindowSet) -> WindowSet -> WindowSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> 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 Word64
w (WindowSet -> WindowSet) -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ WindowSet
ws
switchFocus :: FocusHook
switchFocus :: FocusQuery (Endo WindowSet)
switchFocus = do
FocusLock b <- Query FocusLock -> FocusQuery FocusLock
forall a. Query a -> FocusQuery a
liftQuery (Query FocusLock -> FocusQuery FocusLock)
-> (X FocusLock -> Query FocusLock)
-> X FocusLock
-> FocusQuery FocusLock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. X FocusLock -> Query FocusLock
forall a. X a -> Query a
liftX (X FocusLock -> FocusQuery FocusLock)
-> X FocusLock -> FocusQuery FocusLock
forall a b. (a -> b) -> a -> b
$ X FocusLock
forall a (m :: * -> *). (ExtensionClass a, XLike m) => m a
XS.get
if b
then keepFocus
else new $ ask >>= \Word64
w -> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall s. (s -> s) -> Query (Endo s)
doF ((WindowSet -> WindowSet) -> Query (Endo WindowSet))
-> (WindowSet -> WindowSet) -> Query (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ \WindowSet
ws ->
[Char] -> 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 (WindowSet -> [Char]
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag WindowSet
ws) (WindowSet -> WindowSet)
-> (WindowSet -> WindowSet) -> WindowSet -> WindowSet
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> 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 Word64
w (WindowSet -> WindowSet) -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ WindowSet
ws
keepWorkspace :: FocusHook
keepWorkspace :: FocusQuery (Endo WindowSet)
keepWorkspace = do
ws <- (Focus -> [Char]) -> FocusQuery [Char]
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks Focus -> [Char]
currentWorkspace
liftQuery . doF $ W.view ws
switchWorkspace :: FocusHook
switchWorkspace :: FocusQuery (Endo WindowSet)
switchWorkspace = do
FocusLock b <- Query FocusLock -> FocusQuery FocusLock
forall a. Query a -> FocusQuery a
liftQuery (Query FocusLock -> FocusQuery FocusLock)
-> (X FocusLock -> Query FocusLock)
-> X FocusLock
-> FocusQuery FocusLock
forall b c a. (b -> c) -> (a -> b) -> a -> c
. X FocusLock -> Query FocusLock
forall a. X a -> Query a
liftX (X FocusLock -> FocusQuery FocusLock)
-> X FocusLock -> FocusQuery FocusLock
forall a b. (a -> b) -> a -> b
$ X FocusLock
forall a (m :: * -> *). (ExtensionClass a, XLike m) => m a
XS.get
if b
then keepWorkspace
else do
ws <- asks newWorkspace
liftQuery . doF $ W.view ws
manageFocus :: FocusHook -> ManageHook
manageFocus :: FocusQuery (Endo WindowSet) -> Query (Endo WindowSet)
manageFocus FocusQuery (Endo WindowSet)
m = do
fws <- X [([Char], Maybe Word64)] -> Query [([Char], Maybe Word64)]
forall a. X a -> Query a
liftX (X [([Char], Maybe Word64)] -> Query [([Char], Maybe Word64)])
-> ((WindowSet -> X [([Char], Maybe Word64)])
-> X [([Char], Maybe Word64)])
-> (WindowSet -> X [([Char], Maybe Word64)])
-> Query [([Char], Maybe Word64)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WindowSet -> X [([Char], Maybe Word64)])
-> X [([Char], Maybe Word64)]
forall a. (WindowSet -> X a) -> X a
withWindowSet ((WindowSet -> X [([Char], Maybe Word64)])
-> Query [([Char], Maybe Word64)])
-> (WindowSet -> X [([Char], Maybe Word64)])
-> Query [([Char], Maybe Word64)]
forall a b. (a -> b) -> a -> b
$ [([Char], Maybe Word64)] -> X [([Char], Maybe Word64)]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return
([([Char], Maybe Word64)] -> X [([Char], Maybe Word64)])
-> (WindowSet -> [([Char], Maybe Word64)])
-> WindowSet
-> X [([Char], Maybe Word64)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Workspace [Char] (Layout Word64) Word64 -> ([Char], Maybe Word64))
-> [Workspace [Char] (Layout Word64) Word64]
-> [([Char], Maybe Word64)]
forall a b. (a -> b) -> [a] -> [b]
map (Workspace [Char] (Layout Word64) Word64 -> [Char]
forall i l a. Workspace i l a -> i
W.tag (Workspace [Char] (Layout Word64) Word64 -> [Char])
-> (Workspace [Char] (Layout Word64) Word64 -> Maybe Word64)
-> Workspace [Char] (Layout Word64) Word64
-> ([Char], Maybe Word64)
forall b c c'. (b -> c) -> (b -> c') -> b -> (c, c')
forall (a :: * -> * -> *) b c c'.
Arrow a =>
a b c -> a b c' -> a b (c, c')
&&& (Stack Word64 -> Word64) -> Maybe (Stack Word64) -> Maybe Word64
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Stack Word64 -> Word64
forall a. Stack a -> a
W.focus (Maybe (Stack Word64) -> Maybe Word64)
-> (Workspace [Char] (Layout Word64) Word64
-> Maybe (Stack Word64))
-> Workspace [Char] (Layout Word64) Word64
-> Maybe Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Workspace [Char] (Layout Word64) Word64 -> Maybe (Stack Word64)
forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack) ([Workspace [Char] (Layout Word64) Word64]
-> [([Char], Maybe Word64)])
-> (WindowSet -> [Workspace [Char] (Layout Word64) Word64])
-> WindowSet
-> [([Char], Maybe Word64)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> [Workspace [Char] (Layout Word64) Word64]
forall i l a s sd. StackSet i l a s sd -> [Workspace i l a]
W.workspaces
ct <- currentWs
let r = Focus
forall a. Default a => a
def {currentWorkspace = ct}
hs <- forM fws $ \([Char]
i, Maybe Word64
mw) -> do
f <- FocusQuery (Endo WindowSet) -> Focus -> Query (Endo WindowSet)
forall a. FocusQuery a -> Focus -> Query a
runFocusQuery FocusQuery (Endo WindowSet)
m (Focus
r {focusedWindow = mw, newWorkspace = i})
return (i, f)
reader (selectHook hs) >>= doF
where
selectHook :: [(WorkspaceId, Endo WindowSet)] -> Window -> WindowSet -> WindowSet
selectHook :: [([Char], Endo WindowSet)] -> Word64 -> WindowSet -> WindowSet
selectHook [([Char], Endo WindowSet)]
cfs Word64
nw WindowSet
ws = WindowSet -> Maybe WindowSet -> WindowSet
forall a. a -> Maybe a -> a
fromMaybe WindowSet
ws (Maybe WindowSet -> WindowSet) -> Maybe WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ do
i <- Word64 -> WindowSet -> Maybe [Char]
forall a i l s sd. Eq a => a -> StackSet i l a s sd -> Maybe i
W.findTag Word64
nw WindowSet
ws
f <- lookup i cfs
return (appEndo f ws)
when' :: (Monad m, Monoid a) => Bool -> m a -> m a
when' :: forall (m :: * -> *) a. (Monad m, Monoid a) => Bool -> m a -> m a
when' Bool
b m a
mx
| Bool
b = m a
mx
| Bool
otherwise = a -> m a
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return a
forall a. Monoid a => a
mempty
activateSwitchWs :: ManageHook
activateSwitchWs :: Query (Endo WindowSet)
activateSwitchWs = FocusQuery (Endo WindowSet) -> Query (Endo WindowSet)
manageFocus (FocusQuery (Endo WindowSet)
switchWorkspace FocusQuery (Endo WindowSet)
-> FocusQuery (Endo WindowSet) -> FocusQuery (Endo WindowSet)
forall a. Semigroup a => a -> a -> a
<> FocusQuery (Endo WindowSet)
switchFocus)
activateOnCurrent' :: ManageHook
activateOnCurrent' :: Query (Endo WindowSet)
activateOnCurrent' = Query [Char]
currentWs Query [Char]
-> ([Char] -> Query (Endo WindowSet)) -> Query (Endo WindowSet)
forall a b. Query a -> (a -> Query b) -> Query b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Query (Endo WindowSet) -> Query (Endo WindowSet)
forall a. Monoid a => Query a -> Query a
unlessFocusLock (Query (Endo WindowSet) -> Query (Endo WindowSet))
-> ([Char] -> Query (Endo WindowSet))
-> [Char]
-> Query (Endo WindowSet)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Char] -> Query (Endo WindowSet)
doShift
activateOnCurrentWs :: ManageHook
activateOnCurrentWs :: Query (Endo WindowSet)
activateOnCurrentWs = FocusQuery (Endo WindowSet) -> Query (Endo WindowSet)
manageFocus (FocusQuery Bool
newOnCur FocusQuery Bool
-> FocusQuery (Endo WindowSet) -> FocusQuery (Endo WindowSet)
forall (m :: * -> *) a. (Monad m, Monoid a) => m Bool -> m a -> m a
--> FocusQuery (Endo WindowSet)
switchFocus) Query (Endo WindowSet)
-> Query (Endo WindowSet) -> Query (Endo WindowSet)
forall a. Semigroup a => a -> a -> a
<> Query (Endo WindowSet)
activateOnCurrent'
activateOnCurrentKeepFocus :: ManageHook
activateOnCurrentKeepFocus :: Query (Endo WindowSet)
activateOnCurrentKeepFocus = FocusQuery (Endo WindowSet) -> Query (Endo WindowSet)
manageFocus (FocusQuery Bool
newOnCur FocusQuery Bool
-> FocusQuery (Endo WindowSet) -> FocusQuery (Endo WindowSet)
forall (m :: * -> *) a. (Monad m, Monoid a) => m Bool -> m a -> m a
--> FocusQuery (Endo WindowSet)
keepFocus) Query (Endo WindowSet)
-> Query (Endo WindowSet) -> Query (Endo WindowSet)
forall a. Semigroup a => a -> a -> a
<> Query (Endo WindowSet)
activateOnCurrent'