{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Actions.WorkspaceCursors
(
focusDepth
,makeCursors
,toList
,workspaceCursors
,WorkspaceCursors
,getFocus
,modifyLayer
,modifyLayer'
,shiftModifyLayer,shiftLayer
,focusNth'
,noWrapUp,noWrapDown,
Cursors,
) where
import qualified XMonad.StackSet as W
import XMonad.Actions.FocusNth(focusNth')
import XMonad.Layout.LayoutModifier(ModifiedLayout(..),
LayoutModifier(handleMess, redoLayout))
import XMonad(Message, WorkspaceId, X, XState(windowset),
fromMessage, sendMessage, windows, gets)
import XMonad.Util.Stack (reverseS)
import XMonad.Prelude
makeCursors :: [[String]] -> Cursors String
makeCursors :: [[WorkspaceId]] -> Cursors WorkspaceId
makeCursors [] = WorkspaceId -> Cursors WorkspaceId
forall a. HasCallStack => WorkspaceId -> a
error WorkspaceId
"Workspace Cursors cannot be empty"
makeCursors ([WorkspaceId]
a : [[WorkspaceId]]
as) = [WorkspaceId] -> WorkspaceId
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat ([WorkspaceId] -> WorkspaceId)
-> ([WorkspaceId] -> [WorkspaceId]) -> [WorkspaceId] -> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [WorkspaceId] -> [WorkspaceId]
forall a. [a] -> [a]
reverse ([WorkspaceId] -> WorkspaceId)
-> Cursors [WorkspaceId] -> Cursors WorkspaceId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Cursors [WorkspaceId] -> [[WorkspaceId]] -> Cursors [WorkspaceId])
-> Cursors [WorkspaceId]
-> [[[WorkspaceId]]]
-> Cursors [WorkspaceId]
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl Cursors [WorkspaceId] -> [[WorkspaceId]] -> Cursors [WorkspaceId]
forall a. Monoid a => Cursors a -> [a] -> Cursors a
addDim Cursors [WorkspaceId]
x [[[WorkspaceId]]]
xs
where x :: Cursors [WorkspaceId]
x = [[WorkspaceId]] -> Cursors [WorkspaceId]
forall a. [a] -> Cursors a
end ([[WorkspaceId]] -> Cursors [WorkspaceId])
-> [[WorkspaceId]] -> Cursors [WorkspaceId]
forall a b. (a -> b) -> a -> b
$ (WorkspaceId -> [WorkspaceId]) -> [WorkspaceId] -> [[WorkspaceId]]
forall a b. (a -> b) -> [a] -> [b]
map WorkspaceId -> [WorkspaceId]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return [WorkspaceId]
a
xs :: [[[WorkspaceId]]]
xs = ([WorkspaceId] -> [[WorkspaceId]])
-> [[WorkspaceId]] -> [[[WorkspaceId]]]
forall a b. (a -> b) -> [a] -> [b]
map ((WorkspaceId -> [WorkspaceId]) -> [WorkspaceId] -> [[WorkspaceId]]
forall a b. (a -> b) -> [a] -> [b]
map WorkspaceId -> [WorkspaceId]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return) [[WorkspaceId]]
as
addDim :: (Monoid a) => Cursors a -> [a] -> Cursors a
addDim :: forall a. Monoid a => Cursors a -> [a] -> Cursors a
addDim Cursors a
prev [a]
prefixes = Stack (Cursors a) -> Cursors a
forall a. Stack (Cursors a) -> Cursors a
Cons (Stack (Cursors a) -> Cursors a)
-> ([Cursors a] -> Stack (Cursors a)) -> [Cursors a] -> Cursors a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Stack (Cursors a)) -> Stack (Cursors a)
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (Stack (Cursors a)) -> Stack (Cursors a))
-> ([Cursors a] -> Maybe (Stack (Cursors a)))
-> [Cursors a]
-> Stack (Cursors a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Cursors a] -> Maybe (Stack (Cursors a))
forall a. [a] -> Maybe (Stack a)
W.differentiate
([Cursors a] -> Cursors a) -> [Cursors a] -> Cursors a
forall a b. (a -> b) -> a -> b
$ (a -> Cursors a) -> [a] -> [Cursors a]
forall a b. (a -> b) -> [a] -> [b]
map (((a -> a) -> Cursors a -> Cursors a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Cursors a
prev) ((a -> a) -> Cursors a) -> (a -> a -> a) -> a -> Cursors a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> a -> a
forall a. Monoid a => a -> a -> a
mappend) [a]
prefixes
end :: [a] -> Cursors a
end :: forall a. [a] -> Cursors a
end = Stack (Cursors a) -> Cursors a
forall a. Stack (Cursors a) -> Cursors a
Cons (Stack (Cursors a) -> Cursors a)
-> ([a] -> Stack (Cursors a)) -> [a] -> Cursors a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe (Stack (Cursors a)) -> Stack (Cursors a)
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (Stack (Cursors a)) -> Stack (Cursors a))
-> ([a] -> Maybe (Stack (Cursors a))) -> [a] -> Stack (Cursors a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Cursors a] -> Maybe (Stack (Cursors a))
forall a. [a] -> Maybe (Stack a)
W.differentiate ([Cursors a] -> Maybe (Stack (Cursors a)))
-> ([a] -> [Cursors a]) -> [a] -> Maybe (Stack (Cursors a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Cursors a) -> [a] -> [Cursors a]
forall a b. (a -> b) -> [a] -> [b]
map a -> Cursors a
forall a. a -> Cursors a
End
data Cursors a
= Cons (W.Stack (Cursors a))
| End a deriving (Cursors a -> Cursors a -> Bool
(Cursors a -> Cursors a -> Bool)
-> (Cursors a -> Cursors a -> Bool) -> Eq (Cursors a)
forall a. Eq a => Cursors a -> Cursors a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall a. Eq a => Cursors a -> Cursors a -> Bool
== :: Cursors a -> Cursors a -> Bool
$c/= :: forall a. Eq a => Cursors a -> Cursors a -> Bool
/= :: Cursors a -> Cursors a -> Bool
Eq,Int -> Cursors a -> ShowS
[Cursors a] -> ShowS
Cursors a -> WorkspaceId
(Int -> Cursors a -> ShowS)
-> (Cursors a -> WorkspaceId)
-> ([Cursors a] -> ShowS)
-> Show (Cursors a)
forall a. Show a => Int -> Cursors a -> ShowS
forall a. Show a => [Cursors a] -> ShowS
forall a. Show a => Cursors a -> WorkspaceId
forall a.
(Int -> a -> ShowS)
-> (a -> WorkspaceId) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> Cursors a -> ShowS
showsPrec :: Int -> Cursors a -> ShowS
$cshow :: forall a. Show a => Cursors a -> WorkspaceId
show :: Cursors a -> WorkspaceId
$cshowList :: forall a. Show a => [Cursors a] -> ShowS
showList :: [Cursors a] -> ShowS
Show,ReadPrec [Cursors a]
ReadPrec (Cursors a)
Int -> ReadS (Cursors a)
ReadS [Cursors a]
(Int -> ReadS (Cursors a))
-> ReadS [Cursors a]
-> ReadPrec (Cursors a)
-> ReadPrec [Cursors a]
-> Read (Cursors a)
forall a. Read a => ReadPrec [Cursors a]
forall a. Read a => ReadPrec (Cursors a)
forall a. Read a => Int -> ReadS (Cursors a)
forall a. Read a => ReadS [Cursors a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (Cursors a)
readsPrec :: Int -> ReadS (Cursors a)
$creadList :: forall a. Read a => ReadS [Cursors a]
readList :: ReadS [Cursors a]
$creadPrec :: forall a. Read a => ReadPrec (Cursors a)
readPrec :: ReadPrec (Cursors a)
$creadListPrec :: forall a. Read a => ReadPrec [Cursors a]
readListPrec :: ReadPrec [Cursors a]
Read)
instance Foldable Cursors where
foldMap :: forall m a. Monoid m => (a -> m) -> Cursors a -> m
foldMap a -> m
f (End a
x) = a -> m
f a
x
foldMap a -> m
f (Cons (W.Stack Cursors a
x [Cursors a]
y [Cursors a]
z)) = (a -> m) -> Cursors a -> m
forall m a. Monoid m => (a -> m) -> Cursors a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f Cursors a
x m -> m -> m
forall a. Monoid a => a -> a -> a
`mappend` [m] -> m
forall a. Monoid a => [a] -> a
mconcat ((Cursors a -> m) -> [Cursors a] -> [m]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> m) -> Cursors a -> m
forall m a. Monoid m => (a -> m) -> Cursors a -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap a -> m
f) ([Cursors a] -> [m]) -> [Cursors a] -> [m]
forall a b. (a -> b) -> a -> b
$ [Cursors a] -> [Cursors a]
forall a. [a] -> [a]
reverse [Cursors a]
y [Cursors a] -> [Cursors a] -> [Cursors a]
forall a. [a] -> [a] -> [a]
++ [Cursors a]
z)
instance Functor Cursors where
fmap :: forall a b. (a -> b) -> Cursors a -> Cursors b
fmap a -> b
f (End a
a) = b -> Cursors b
forall a. a -> Cursors a
End (b -> Cursors b) -> b -> Cursors b
forall a b. (a -> b) -> a -> b
$ a -> b
f a
a
fmap a -> b
f (Cons (W.Stack Cursors a
x [Cursors a]
y [Cursors a]
z)) = Stack (Cursors b) -> Cursors b
forall a. Stack (Cursors a) -> Cursors a
Cons (Stack (Cursors b) -> Cursors b) -> Stack (Cursors b) -> Cursors b
forall a b. (a -> b) -> a -> b
$ Cursors b -> [Cursors b] -> [Cursors b] -> Stack (Cursors b)
forall a. a -> [a] -> [a] -> Stack a
W.Stack ((a -> b) -> Cursors a -> Cursors b
forall a b. (a -> b) -> Cursors a -> Cursors b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f Cursors a
x) ((Cursors a -> Cursors b) -> [Cursors a] -> [Cursors b]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> Cursors a -> Cursors b
forall a b. (a -> b) -> Cursors a -> Cursors b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) [Cursors a]
y) ((Cursors a -> Cursors b) -> [Cursors a] -> [Cursors b]
forall a b. (a -> b) -> [a] -> [b]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((a -> b) -> Cursors a -> Cursors b
forall a b. (a -> b) -> Cursors a -> Cursors b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap a -> b
f) [Cursors a]
z)
changeFocus :: (Cursors t -> Bool) -> Cursors t -> [Cursors t]
changeFocus :: forall t. (Cursors t -> Bool) -> Cursors t -> [Cursors t]
changeFocus Cursors t -> Bool
p (Cons Stack (Cursors t)
x) = do
Stack (Cursors t)
choose <- (Cursors t -> Bool) -> Stack (Cursors t) -> [Stack (Cursors t)]
forall a. (a -> Bool) -> Stack a -> [Stack a]
chFocus Cursors t -> Bool
p Stack (Cursors t)
x
Cursors t
foc <- (Cursors t -> Bool) -> Cursors t -> [Cursors t]
forall t. (Cursors t -> Bool) -> Cursors t -> [Cursors t]
changeFocus Cursors t -> Bool
p (Cursors t -> [Cursors t]) -> Cursors t -> [Cursors t]
forall a b. (a -> b) -> a -> b
$ Stack (Cursors t) -> Cursors t
forall a. Stack a -> a
W.focus Stack (Cursors t)
choose
Cursors t -> [Cursors t]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return (Cursors t -> [Cursors t])
-> (Stack (Cursors t) -> Cursors t)
-> Stack (Cursors t)
-> [Cursors t]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack (Cursors t) -> Cursors t
forall a. Stack (Cursors a) -> Cursors a
Cons (Stack (Cursors t) -> [Cursors t])
-> Stack (Cursors t) -> [Cursors t]
forall a b. (a -> b) -> a -> b
$ Stack (Cursors t)
choose { W.focus = foc }
changeFocus Cursors t -> Bool
p Cursors t
x = Bool -> [()]
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Cursors t -> Bool
p Cursors t
x) [()] -> [Cursors t] -> [Cursors t]
forall a b. [a] -> [b] -> [b]
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Cursors t -> [Cursors t]
forall a. a -> [a]
forall (m :: * -> *) a. Monad m => a -> m a
return Cursors t
x
chFocus :: (a -> Bool) -> W.Stack a -> [W.Stack a]
chFocus :: forall a. (a -> Bool) -> Stack a -> [Stack a]
chFocus a -> Bool
p Stack a
st = (Stack a -> Bool) -> [Stack a] -> [Stack a]
forall a. (a -> Bool) -> [a] -> [a]
filter (a -> Bool
p (a -> Bool) -> (Stack a -> a) -> Stack a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> a
forall a. Stack a -> a
W.focus) ([Stack a] -> [Stack a]) -> [Stack a] -> [Stack a]
forall a b. (a -> b) -> a -> b
$ (Stack a -> a -> Stack a) -> [Stack a] -> [a] -> [Stack a]
forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith Stack a -> a -> Stack a
forall a b. a -> b -> a
const ((Stack a -> Stack a) -> Stack a -> [Stack a]
forall a. (a -> a) -> a -> [a]
iterate Stack a -> Stack a
forall a. Stack a -> Stack a
W.focusDown' Stack a
st) (Stack a -> [a]
forall a. Stack a -> [a]
W.integrate Stack a
st)
getFocus :: Cursors b -> b
getFocus :: forall b. Cursors b -> b
getFocus (Cons Stack (Cursors b)
x) = Cursors b -> b
forall b. Cursors b -> b
getFocus (Cursors b -> b) -> Cursors b -> b
forall a b. (a -> b) -> a -> b
$ Stack (Cursors b) -> Cursors b
forall a. Stack a -> a
W.focus Stack (Cursors b)
x
getFocus (End b
x) = b
x
focusTo :: (Eq t) => t -> Cursors t -> Maybe (Cursors t)
focusTo :: forall t. Eq t => t -> Cursors t -> Maybe (Cursors t)
focusTo t
x = (Cursors t -> Bool) -> [Cursors t] -> Maybe (Cursors t)
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
find ((t
xt -> t -> Bool
forall a. Eq a => a -> a -> Bool
==) (t -> Bool) -> (Cursors t -> t) -> Cursors t -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cursors t -> t
forall b. Cursors b -> b
getFocus) ([Cursors t] -> Maybe (Cursors t))
-> (Cursors t -> [Cursors t]) -> Cursors t -> Maybe (Cursors t)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cursors t -> Bool) -> Cursors t -> [Cursors t]
forall t. (Cursors t -> Bool) -> Cursors t -> [Cursors t]
changeFocus (Bool -> Cursors t -> Bool
forall a b. a -> b -> a
const Bool
True)
noWrapUp :: W.Stack t -> W.Stack t
noWrapUp :: forall a. Stack a -> Stack a
noWrapUp (W.Stack t
t (t
l:[t]
ls) [t]
rs) = t -> [t] -> [t] -> Stack t
forall a. a -> [a] -> [a] -> Stack a
W.Stack t
l [t]
ls (t
tt -> [t] -> [t]
forall a. a -> [a] -> [a]
:[t]
rs)
noWrapUp x :: Stack t
x@(W.Stack t
_ [] [t]
_ ) = Stack t
x
noWrapDown :: W.Stack t -> W.Stack t
noWrapDown :: forall a. Stack a -> Stack a
noWrapDown = Stack t -> Stack t
forall a. Stack a -> Stack a
reverseS (Stack t -> Stack t) -> (Stack t -> Stack t) -> Stack t -> Stack t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack t -> Stack t
forall a. Stack a -> Stack a
noWrapUp (Stack t -> Stack t) -> (Stack t -> Stack t) -> Stack t -> Stack t
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack t -> Stack t
forall a. Stack a -> Stack a
reverseS
focusDepth :: Cursors t -> Int
focusDepth :: forall a. Cursors a -> Int
focusDepth (Cons Stack (Cursors t)
x) = Int
1 Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Cursors t -> Int
forall a. Cursors a -> Int
focusDepth (Stack (Cursors t) -> Cursors t
forall a. Stack a -> a
W.focus Stack (Cursors t)
x)
focusDepth (End t
_) = Int
0
descend :: Monad m =>(W.Stack (Cursors a) -> m (W.Stack (Cursors a)))-> Int-> Cursors a-> m (Cursors a)
descend :: forall (m :: * -> *) a.
Monad m =>
(Stack (Cursors a) -> m (Stack (Cursors a)))
-> Int -> Cursors a -> m (Cursors a)
descend Stack (Cursors a) -> m (Stack (Cursors a))
f Int
1 (Cons Stack (Cursors a)
x) = Stack (Cursors a) -> Cursors a
forall a. Stack (Cursors a) -> Cursors a
Cons (Stack (Cursors a) -> Cursors a)
-> m (Stack (Cursors a)) -> m (Cursors a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Stack (Cursors a) -> m (Stack (Cursors a))
f Stack (Cursors a)
x
descend Stack (Cursors a) -> m (Stack (Cursors a))
f Int
n (Cons Stack (Cursors a)
x) | Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1 = (Stack (Cursors a) -> Cursors a)
-> m (Stack (Cursors a)) -> m (Cursors a)
forall a b. (a -> b) -> m a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Stack (Cursors a) -> Cursors a
forall a. Stack (Cursors a) -> Cursors a
Cons (m (Stack (Cursors a)) -> m (Cursors a))
-> m (Stack (Cursors a)) -> m (Cursors a)
forall a b. (a -> b) -> a -> b
$ (Stack (Cursors a) -> m (Stack (Cursors a)))
-> Int -> Cursors a -> m (Cursors a)
forall (m :: * -> *) a.
Monad m =>
(Stack (Cursors a) -> m (Stack (Cursors a)))
-> Int -> Cursors a -> m (Cursors a)
descend Stack (Cursors a) -> m (Stack (Cursors a))
f (Int -> Int
forall a. Enum a => a -> a
pred Int
n) (Cursors a -> m (Cursors a))
-> Stack (Cursors a) -> m (Stack (Cursors a))
forall (m :: * -> *) a1.
Monad m =>
(a1 -> m a1) -> Stack a1 -> m (Stack a1)
`onFocus` Stack (Cursors a)
x
descend Stack (Cursors a) -> m (Stack (Cursors a))
_ Int
_ Cursors a
x = Cursors a -> m (Cursors a)
forall a. a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return Cursors a
x
onFocus :: (Monad m) => (a1 -> m a1) -> W.Stack a1 -> m (W.Stack a1)
onFocus :: forall (m :: * -> *) a1.
Monad m =>
(a1 -> m a1) -> Stack a1 -> m (Stack a1)
onFocus a1 -> m a1
f Stack a1
st = (\a1
x -> Stack a1
st { W.focus = x}) (a1 -> Stack a1) -> m a1 -> m (Stack a1)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a1 -> m a1
f (Stack a1 -> a1
forall a. Stack a -> a
W.focus Stack a1
st)
modifyLayer :: (W.Stack (Cursors String) -> W.Stack (Cursors String)) -> Int -> X ()
modifyLayer :: (Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId))
-> Int -> X ()
modifyLayer Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId)
f Int
depth = (Cursors WorkspaceId -> X (Cursors WorkspaceId)) -> X ()
modifyCursors ((Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> Cursors WorkspaceId -> X (Cursors WorkspaceId)
forall (m :: * -> *) a.
Monad m =>
(Stack (Cursors a) -> m (Stack (Cursors a)))
-> Int -> Cursors a -> m (Cursors a)
descend (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> (Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId))
-> Stack (Cursors WorkspaceId)
-> X (Stack (Cursors WorkspaceId))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId)
f) Int
depth)
shiftModifyLayer :: (W.Stack (Cursors String) -> W.Stack (Cursors WorkspaceId))-> Int-> X ()
shiftModifyLayer :: (Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId))
-> Int -> X ()
shiftModifyLayer Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId)
f = (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> X ()
modifyLayer' ((Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> X ())
-> (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int
-> X ()
forall a b. (a -> b) -> a -> b
$ \Stack (Cursors WorkspaceId)
st -> do
let st' :: Stack (Cursors WorkspaceId)
st' = Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId)
f Stack (Cursors WorkspaceId)
st
(WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ WorkspaceId -> 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 (WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ Cursors WorkspaceId -> WorkspaceId
forall b. Cursors b -> b
getFocus (Stack (Cursors WorkspaceId) -> Cursors WorkspaceId
forall a. Stack (Cursors a) -> Cursors a
Cons Stack (Cursors WorkspaceId)
st')
Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Stack (Cursors WorkspaceId)
st'
shiftLayer :: (W.Stack (Cursors String) -> W.Stack (Cursors WorkspaceId))-> Int-> X ()
shiftLayer :: (Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId))
-> Int -> X ()
shiftLayer Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId)
f = (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> X ()
modifyLayer' ((Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> X ())
-> (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int
-> X ()
forall a b. (a -> b) -> a -> b
$ \Stack (Cursors WorkspaceId)
st -> do
(WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ WorkspaceId -> 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 (WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ Cursors WorkspaceId -> WorkspaceId
forall b. Cursors b -> b
getFocus (Cursors WorkspaceId -> WorkspaceId)
-> Cursors WorkspaceId -> WorkspaceId
forall a b. (a -> b) -> a -> b
$ Stack (Cursors WorkspaceId) -> Cursors WorkspaceId
forall a. Stack (Cursors a) -> Cursors a
Cons (Stack (Cursors WorkspaceId) -> Cursors WorkspaceId)
-> Stack (Cursors WorkspaceId) -> Cursors WorkspaceId
forall a b. (a -> b) -> a -> b
$ Stack (Cursors WorkspaceId) -> Stack (Cursors WorkspaceId)
f Stack (Cursors WorkspaceId)
st
Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Stack (Cursors WorkspaceId)
st
modifyLayer' :: (W.Stack (Cursors String) -> X (W.Stack (Cursors String))) -> Int -> X ()
modifyLayer' :: (Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> X ()
modifyLayer' Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId))
f Int
depth = (Cursors WorkspaceId -> X (Cursors WorkspaceId)) -> X ()
modifyCursors ((Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId)))
-> Int -> Cursors WorkspaceId -> X (Cursors WorkspaceId)
forall (m :: * -> *) a.
Monad m =>
(Stack (Cursors a) -> m (Stack (Cursors a)))
-> Int -> Cursors a -> m (Cursors a)
descend Stack (Cursors WorkspaceId) -> X (Stack (Cursors WorkspaceId))
f Int
depth)
modifyCursors :: (Cursors String -> X (Cursors String)) -> X ()
modifyCursors :: (Cursors WorkspaceId -> X (Cursors WorkspaceId)) -> X ()
modifyCursors = ChangeCursors -> X ()
forall a. Message a => a -> X ()
sendMessage (ChangeCursors -> X ())
-> ((Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> ChangeCursors)
-> (Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Cursors WorkspaceId -> X (Cursors WorkspaceId)) -> ChangeCursors
ChangeCursors ((Cursors WorkspaceId -> X (Cursors WorkspaceId)) -> ChangeCursors)
-> ((Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> (Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> ChangeCursors
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((X () -> X (Cursors WorkspaceId) -> X (Cursors WorkspaceId))
-> (Cursors WorkspaceId -> X ())
-> (Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> Cursors WorkspaceId
-> X (Cursors WorkspaceId)
forall a b c.
(a -> b -> c)
-> (Cursors WorkspaceId -> a)
-> (Cursors WorkspaceId -> b)
-> Cursors WorkspaceId
-> c
forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 X () -> X (Cursors WorkspaceId) -> X (Cursors WorkspaceId)
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
(>>) Cursors WorkspaceId -> X ()
updateXMD Cursors WorkspaceId -> X (Cursors WorkspaceId)
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> (Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> Cursors WorkspaceId
-> X (Cursors WorkspaceId)
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=<)
newtype WorkspaceCursors a = WorkspaceCursors (Cursors String)
deriving (ReadPrec [WorkspaceCursors a]
ReadPrec (WorkspaceCursors a)
Int -> ReadS (WorkspaceCursors a)
ReadS [WorkspaceCursors a]
(Int -> ReadS (WorkspaceCursors a))
-> ReadS [WorkspaceCursors a]
-> ReadPrec (WorkspaceCursors a)
-> ReadPrec [WorkspaceCursors a]
-> Read (WorkspaceCursors a)
forall a. ReadPrec [WorkspaceCursors a]
forall a. ReadPrec (WorkspaceCursors a)
forall a. Int -> ReadS (WorkspaceCursors a)
forall a. ReadS [WorkspaceCursors a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (WorkspaceCursors a)
readsPrec :: Int -> ReadS (WorkspaceCursors a)
$creadList :: forall a. ReadS [WorkspaceCursors a]
readList :: ReadS [WorkspaceCursors a]
$creadPrec :: forall a. ReadPrec (WorkspaceCursors a)
readPrec :: ReadPrec (WorkspaceCursors a)
$creadListPrec :: forall a. ReadPrec [WorkspaceCursors a]
readListPrec :: ReadPrec [WorkspaceCursors a]
Read,Int -> WorkspaceCursors a -> ShowS
[WorkspaceCursors a] -> ShowS
WorkspaceCursors a -> WorkspaceId
(Int -> WorkspaceCursors a -> ShowS)
-> (WorkspaceCursors a -> WorkspaceId)
-> ([WorkspaceCursors a] -> ShowS)
-> Show (WorkspaceCursors a)
forall a. Int -> WorkspaceCursors a -> ShowS
forall a. [WorkspaceCursors a] -> ShowS
forall a. WorkspaceCursors a -> WorkspaceId
forall a.
(Int -> a -> ShowS)
-> (a -> WorkspaceId) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> WorkspaceCursors a -> ShowS
showsPrec :: Int -> WorkspaceCursors a -> ShowS
$cshow :: forall a. WorkspaceCursors a -> WorkspaceId
show :: WorkspaceCursors a -> WorkspaceId
$cshowList :: forall a. [WorkspaceCursors a] -> ShowS
showList :: [WorkspaceCursors a] -> ShowS
Show)
workspaceCursors :: Cursors String -> l a -> ModifiedLayout WorkspaceCursors l a
workspaceCursors :: forall (l :: * -> *) a.
Cursors WorkspaceId -> l a -> ModifiedLayout WorkspaceCursors l a
workspaceCursors = WorkspaceCursors a -> l a -> ModifiedLayout WorkspaceCursors l a
forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout (WorkspaceCursors a -> l a -> ModifiedLayout WorkspaceCursors l a)
-> (Cursors WorkspaceId -> WorkspaceCursors a)
-> Cursors WorkspaceId
-> l a
-> ModifiedLayout WorkspaceCursors l a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Cursors WorkspaceId -> WorkspaceCursors a
forall a. Cursors WorkspaceId -> WorkspaceCursors a
WorkspaceCursors
newtype ChangeCursors = ChangeCursors { ChangeCursors -> Cursors WorkspaceId -> X (Cursors WorkspaceId)
unWrap :: Cursors String -> X (Cursors String) }
instance Message ChangeCursors
updateXMD :: Cursors WorkspaceId -> X ()
updateXMD :: Cursors WorkspaceId -> X ()
updateXMD Cursors WorkspaceId
cs = do
Bool
changed <- (XState -> Bool) -> X Bool
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> Bool) -> X Bool) -> (XState -> Bool) -> X Bool
forall a b. (a -> b) -> a -> b
$ (Cursors WorkspaceId -> WorkspaceId
forall b. Cursors b -> b
getFocus Cursors WorkspaceId
cs WorkspaceId -> WorkspaceId -> Bool
forall a. Eq a => a -> a -> Bool
/=) (WorkspaceId -> Bool) -> (XState -> WorkspaceId) -> XState -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> WorkspaceId
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag (WindowSet -> WorkspaceId)
-> (XState -> WindowSet) -> XState -> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset
Bool -> X () -> X ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
changed (X () -> X ()) -> X () -> X ()
forall a b. (a -> b) -> a -> b
$ (WindowSet -> WindowSet) -> X ()
windows ((WindowSet -> WindowSet) -> X ())
-> (WindowSet -> WindowSet) -> X ()
forall a b. (a -> b) -> a -> b
$ WorkspaceId -> 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 (WorkspaceId -> WindowSet -> WindowSet)
-> WorkspaceId -> WindowSet -> WindowSet
forall a b. (a -> b) -> a -> b
$ Cursors WorkspaceId -> WorkspaceId
forall b. Cursors b -> b
getFocus Cursors WorkspaceId
cs
instance LayoutModifier WorkspaceCursors a where
redoLayout :: WorkspaceCursors a
-> Rectangle
-> Maybe (Stack a)
-> [(a, Rectangle)]
-> X ([(a, Rectangle)], Maybe (WorkspaceCursors a))
redoLayout (WorkspaceCursors Cursors WorkspaceId
cs) Rectangle
_ Maybe (Stack a)
_ [(a, Rectangle)]
arrs = do
WorkspaceId
cws <- (XState -> WorkspaceId) -> X WorkspaceId
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets ((XState -> WorkspaceId) -> X WorkspaceId)
-> (XState -> WorkspaceId) -> X WorkspaceId
forall a b. (a -> b) -> a -> b
$ WindowSet -> WorkspaceId
forall i l a s sd. StackSet i l a s sd -> i
W.currentTag (WindowSet -> WorkspaceId)
-> (XState -> WindowSet) -> XState -> WorkspaceId
forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset
([(a, Rectangle)], Maybe (WorkspaceCursors a))
-> X ([(a, Rectangle)], Maybe (WorkspaceCursors a))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ([(a, Rectangle)]
arrs,Cursors WorkspaceId -> WorkspaceCursors a
forall a. Cursors WorkspaceId -> WorkspaceCursors a
WorkspaceCursors (Cursors WorkspaceId -> WorkspaceCursors a)
-> Maybe (Cursors WorkspaceId) -> Maybe (WorkspaceCursors a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> WorkspaceId -> Cursors WorkspaceId -> Maybe (Cursors WorkspaceId)
forall t. Eq t => t -> Cursors t -> Maybe (Cursors t)
focusTo WorkspaceId
cws Cursors WorkspaceId
cs)
handleMess :: WorkspaceCursors a -> SomeMessage -> X (Maybe (WorkspaceCursors a))
handleMess (WorkspaceCursors Cursors WorkspaceId
cs) SomeMessage
m =
(ChangeCursors -> X (WorkspaceCursors a))
-> Maybe ChangeCursors -> X (Maybe (WorkspaceCursors a))
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse ((Cursors WorkspaceId -> WorkspaceCursors a)
-> X (Cursors WorkspaceId) -> X (WorkspaceCursors a)
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Cursors WorkspaceId -> WorkspaceCursors a
forall a. Cursors WorkspaceId -> WorkspaceCursors a
WorkspaceCursors (X (Cursors WorkspaceId) -> X (WorkspaceCursors a))
-> (ChangeCursors -> X (Cursors WorkspaceId))
-> ChangeCursors
-> X (WorkspaceCursors a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> Cursors WorkspaceId -> X (Cursors WorkspaceId)
forall a b. (a -> b) -> a -> b
$ Cursors WorkspaceId
cs) ((Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> X (Cursors WorkspaceId))
-> (ChangeCursors
-> Cursors WorkspaceId -> X (Cursors WorkspaceId))
-> ChangeCursors
-> X (Cursors WorkspaceId)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ChangeCursors -> Cursors WorkspaceId -> X (Cursors WorkspaceId)
unWrap) (SomeMessage -> Maybe ChangeCursors
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m)