{-# OPTIONS_GHC -fno-warn-name-shadowing -fno-warn-unused-binds #-}
{-# LANGUAGE StandaloneDeriving, FlexibleContexts, UndecidableInstances, FlexibleInstances, MultiParamTypeClasses, PatternGuards, Rank2Types #-}
module XMonad.Layout.Groups (
group
, GroupsMessage(..)
, ModifySpec
, ModifySpecX
, swapUp
, swapDown
, swapMaster
, focusUp
, focusDown
, focusMaster
, swapGroupUp
, swapGroupDown
, swapGroupMaster
, focusGroupUp
, focusGroupDown
, focusGroupMaster
, moveToGroupUp
, moveToGroupDown
, moveToNewGroupUp
, moveToNewGroupDown
, splitGroup
, Groups
, Group(..)
, onZipper
, onLayout
, WithID
, sameID
) where
import XMonad
import XMonad.Prelude hiding (group)
import qualified XMonad.StackSet as W
import XMonad.Util.Stack
import Control.Arrow ((>>>))
group :: l Window -> l2 (Group l Window) -> Groups l l2 Window
group :: forall (l :: * -> *) (l2 :: * -> *).
l Window -> l2 (Group l Window) -> Groups l l2 Window
group l Window
l l2 (Group l Window)
l2 = l Window
-> l2 (Group l Window)
-> Stack (Group l Window)
-> Uniq
-> Groups l l2 Window
forall (l :: * -> *) (l2 :: * -> *) a.
l a -> l2 (Group l a) -> Stack (Group l a) -> Uniq -> Groups l l2 a
Groups l Window
l l2 (Group l Window)
l2 Stack (Group l Window)
startingGroups (Integer -> Integer -> Uniq
U Integer
1 Integer
0)
where startingGroups :: Stack (Group l Window)
startingGroups = Maybe (Stack (Group l Window)) -> Stack (Group l Window)
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (Stack (Group l Window)) -> Stack (Group l Window))
-> Maybe (Stack (Group l Window)) -> Stack (Group l Window)
forall a b. (a -> b) -> a -> b
$ Group l Window -> Maybe (Stack (Group l Window))
forall a. a -> Zipper a
singletonZ (Group l Window -> Maybe (Stack (Group l Window)))
-> Group l Window -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G (Uniq -> l Window -> WithID l Window
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID (Integer -> Integer -> Uniq
U Integer
0 Integer
0) l Window
l) Zipper Window
forall a. Zipper a
emptyZ
data Uniq = U Integer Integer
deriving (Uniq -> Uniq -> Bool
(Uniq -> Uniq -> Bool) -> (Uniq -> Uniq -> Bool) -> Eq Uniq
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Uniq -> Uniq -> Bool
== :: Uniq -> Uniq -> Bool
$c/= :: Uniq -> Uniq -> Bool
/= :: Uniq -> Uniq -> Bool
Eq, Int -> Uniq -> ShowS
[Uniq] -> ShowS
Uniq -> String
(Int -> Uniq -> ShowS)
-> (Uniq -> String) -> ([Uniq] -> ShowS) -> Show Uniq
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Uniq -> ShowS
showsPrec :: Int -> Uniq -> ShowS
$cshow :: Uniq -> String
show :: Uniq -> String
$cshowList :: [Uniq] -> ShowS
showList :: [Uniq] -> ShowS
Show, ReadPrec [Uniq]
ReadPrec Uniq
Int -> ReadS Uniq
ReadS [Uniq]
(Int -> ReadS Uniq)
-> ReadS [Uniq] -> ReadPrec Uniq -> ReadPrec [Uniq] -> Read Uniq
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Uniq
readsPrec :: Int -> ReadS Uniq
$creadList :: ReadS [Uniq]
readList :: ReadS [Uniq]
$creadPrec :: ReadPrec Uniq
readPrec :: ReadPrec Uniq
$creadListPrec :: ReadPrec [Uniq]
readListPrec :: ReadPrec [Uniq]
Read)
gen :: Uniq -> (Uniq, Stream Uniq)
gen :: Uniq -> (Uniq, Stream Uniq)
gen (U Integer
i1 Integer
i2) = (Integer -> Integer -> Uniq
U (Integer
i1Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+Integer
1) Integer
i2, (Integer -> Uniq) -> Stream Integer -> Stream Uniq
forall a b. (a -> b) -> Stream a -> Stream b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Integer -> Integer -> Uniq
U Integer
i1) ([Item (Stream Integer)] -> Stream Integer
forall l. IsList l => [Item l] -> l
fromList [Integer
Item (Stream Integer)
i2..]))
data WithID l a = ID { forall (l :: * -> *) a. WithID l a -> Uniq
getID :: Uniq
, forall (l :: * -> *) a. WithID l a -> l a
unID :: l a}
deriving (Int -> WithID l a -> ShowS
[WithID l a] -> ShowS
WithID l a -> String
(Int -> WithID l a -> ShowS)
-> (WithID l a -> String)
-> ([WithID l a] -> ShowS)
-> Show (WithID l a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (l :: * -> *) a. Show (l a) => Int -> WithID l a -> ShowS
forall (l :: * -> *) a. Show (l a) => [WithID l a] -> ShowS
forall (l :: * -> *) a. Show (l a) => WithID l a -> String
$cshowsPrec :: forall (l :: * -> *) a. Show (l a) => Int -> WithID l a -> ShowS
showsPrec :: Int -> WithID l a -> ShowS
$cshow :: forall (l :: * -> *) a. Show (l a) => WithID l a -> String
show :: WithID l a -> String
$cshowList :: forall (l :: * -> *) a. Show (l a) => [WithID l a] -> ShowS
showList :: [WithID l a] -> ShowS
Show, ReadPrec [WithID l a]
ReadPrec (WithID l a)
Int -> ReadS (WithID l a)
ReadS [WithID l a]
(Int -> ReadS (WithID l a))
-> ReadS [WithID l a]
-> ReadPrec (WithID l a)
-> ReadPrec [WithID l a]
-> Read (WithID l a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (l :: * -> *) a. Read (l a) => ReadPrec [WithID l a]
forall (l :: * -> *) a. Read (l a) => ReadPrec (WithID l a)
forall (l :: * -> *) a. Read (l a) => Int -> ReadS (WithID l a)
forall (l :: * -> *) a. Read (l a) => ReadS [WithID l a]
$creadsPrec :: forall (l :: * -> *) a. Read (l a) => Int -> ReadS (WithID l a)
readsPrec :: Int -> ReadS (WithID l a)
$creadList :: forall (l :: * -> *) a. Read (l a) => ReadS [WithID l a]
readList :: ReadS [WithID l a]
$creadPrec :: forall (l :: * -> *) a. Read (l a) => ReadPrec (WithID l a)
readPrec :: ReadPrec (WithID l a)
$creadListPrec :: forall (l :: * -> *) a. Read (l a) => ReadPrec [WithID l a]
readListPrec :: ReadPrec [WithID l a]
Read)
sameID :: WithID l a -> WithID l a -> Bool
sameID :: forall (l :: * -> *) a. WithID l a -> WithID l a -> Bool
sameID (ID Uniq
id1 l a
_) (ID Uniq
id2 l a
_) = Uniq
id1 Uniq -> Uniq -> Bool
forall a. Eq a => a -> a -> Bool
== Uniq
id2
instance Eq (WithID l a) where
ID Uniq
id1 l a
_ == :: WithID l a -> WithID l a -> Bool
== ID Uniq
id2 l a
_ = Uniq
id1 Uniq -> Uniq -> Bool
forall a. Eq a => a -> a -> Bool
== Uniq
id2
instance LayoutClass l a => LayoutClass (WithID l) a where
runLayout :: Workspace String (WithID l a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (WithID l a))
runLayout ws :: Workspace String (WithID l a) a
ws@W.Workspace { layout :: forall i l a. Workspace i l a -> l
W.layout = ID Uniq
id l a
l } Rectangle
r
= do ([(a, Rectangle)]
placements, Maybe (l a)
ml') <- Workspace String (l a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (l a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace String (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout Workspace String (WithID l a) a
ws{ W.layout = l} Rectangle
r
([(a, Rectangle)], Maybe (WithID l a))
-> X ([(a, Rectangle)], Maybe (WithID l a))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ([(a, Rectangle)]
placements, Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
id (l a -> WithID l a) -> Maybe (l a) -> Maybe (WithID l a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (l a)
ml')
handleMessage :: WithID l a -> SomeMessage -> X (Maybe (WithID l a))
handleMessage (ID Uniq
id l a
l) SomeMessage
sm = do Maybe (l a)
ml' <- l a -> SomeMessage -> X (Maybe (l a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l a
l SomeMessage
sm
Maybe (WithID l a) -> X (Maybe (WithID l a))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (WithID l a) -> X (Maybe (WithID l a)))
-> Maybe (WithID l a) -> X (Maybe (WithID l a))
forall a b. (a -> b) -> a -> b
$ Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
id (l a -> WithID l a) -> Maybe (l a) -> Maybe (WithID l a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe (l a)
ml'
description :: WithID l a -> String
description (ID Uniq
_ l a
l) = l a -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description l a
l
data Group l a = G { forall (l :: * -> *) a. Group l a -> WithID l a
gLayout :: WithID l a
, forall (l :: * -> *) a. Group l a -> Zipper a
gZipper :: Zipper a }
deriving (Int -> Group l a -> ShowS
[Group l a] -> ShowS
Group l a -> String
(Int -> Group l a -> ShowS)
-> (Group l a -> String)
-> ([Group l a] -> ShowS)
-> Show (Group l a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (l :: * -> *) a.
(Show a, Show (l a)) =>
Int -> Group l a -> ShowS
forall (l :: * -> *) a.
(Show a, Show (l a)) =>
[Group l a] -> ShowS
forall (l :: * -> *) a. (Show a, Show (l a)) => Group l a -> String
$cshowsPrec :: forall (l :: * -> *) a.
(Show a, Show (l a)) =>
Int -> Group l a -> ShowS
showsPrec :: Int -> Group l a -> ShowS
$cshow :: forall (l :: * -> *) a. (Show a, Show (l a)) => Group l a -> String
show :: Group l a -> String
$cshowList :: forall (l :: * -> *) a.
(Show a, Show (l a)) =>
[Group l a] -> ShowS
showList :: [Group l a] -> ShowS
Show, ReadPrec [Group l a]
ReadPrec (Group l a)
Int -> ReadS (Group l a)
ReadS [Group l a]
(Int -> ReadS (Group l a))
-> ReadS [Group l a]
-> ReadPrec (Group l a)
-> ReadPrec [Group l a]
-> Read (Group l a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (l :: * -> *) a.
(Read a, Read (l a)) =>
ReadPrec [Group l a]
forall (l :: * -> *) a.
(Read a, Read (l a)) =>
ReadPrec (Group l a)
forall (l :: * -> *) a.
(Read a, Read (l a)) =>
Int -> ReadS (Group l a)
forall (l :: * -> *) a. (Read a, Read (l a)) => ReadS [Group l a]
$creadsPrec :: forall (l :: * -> *) a.
(Read a, Read (l a)) =>
Int -> ReadS (Group l a)
readsPrec :: Int -> ReadS (Group l a)
$creadList :: forall (l :: * -> *) a. (Read a, Read (l a)) => ReadS [Group l a]
readList :: ReadS [Group l a]
$creadPrec :: forall (l :: * -> *) a.
(Read a, Read (l a)) =>
ReadPrec (Group l a)
readPrec :: ReadPrec (Group l a)
$creadListPrec :: forall (l :: * -> *) a.
(Read a, Read (l a)) =>
ReadPrec [Group l a]
readListPrec :: ReadPrec [Group l a]
Read, Group l a -> Group l a -> Bool
(Group l a -> Group l a -> Bool)
-> (Group l a -> Group l a -> Bool) -> Eq (Group l a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (l :: * -> *) a. Eq a => Group l a -> Group l a -> Bool
$c== :: forall (l :: * -> *) a. Eq a => Group l a -> Group l a -> Bool
== :: Group l a -> Group l a -> Bool
$c/= :: forall (l :: * -> *) a. Eq a => Group l a -> Group l a -> Bool
/= :: Group l a -> Group l a -> Bool
Eq)
onLayout :: (WithID l a -> WithID l a) -> Group l a -> Group l a
onLayout :: forall (l :: * -> *) a.
(WithID l a -> WithID l a) -> Group l a -> Group l a
onLayout WithID l a -> WithID l a
f Group l a
g = Group l a
g { gLayout = f $ gLayout g }
onZipper :: (Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper :: forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper Zipper a -> Zipper a
f Group l a
g = Group l a
g { gZipper = f $ gZipper g }
data Groups l l2 a = Groups {
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout :: l a
, forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> l2 (Group l a)
partitioner :: l2 (Group l a)
, forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups :: W.Stack (Group l a)
, forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> Uniq
seed :: Uniq
}
deriving instance (Show a, Show (l a), Show (l2 (Group l a))) => Show (Groups l l2 a)
deriving instance (Read a, Read (l a), Read (l2 (Group l a))) => Read (Groups l l2 a)
data GroupsMessage = ToEnclosing SomeMessage
| ToGroup Int SomeMessage
| ToFocused SomeMessage
| ToAll SomeMessage
| Refocus
| Modify ModifySpec
| ModifyX ModifySpecX
instance Show GroupsMessage where
show :: GroupsMessage -> String
show (ToEnclosing SomeMessage
_) = String
"ToEnclosing {...}"
show (ToGroup Int
i SomeMessage
_) = String
"ToGroup "String -> ShowS
forall a. [a] -> [a] -> [a]
++Int -> String
forall a. Show a => a -> String
show Int
iString -> ShowS
forall a. [a] -> [a] -> [a]
++String
" {...}"
show (ToFocused SomeMessage
_) = String
"ToFocused {...}"
show (ToAll SomeMessage
_) = String
"ToAll {...}"
show GroupsMessage
Refocus = String
"Refocus"
show (Modify ModifySpec
_) = String
"Modify {...}"
show (ModifyX ModifySpecX
_) = String
"ModifyX {...}"
instance Message GroupsMessage
modifyGroups :: (Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a -> Groups l l2 a
modifyGroups :: forall (l :: * -> *) a (l2 :: * -> *).
(Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a -> Groups l l2 a
modifyGroups Zipper (Group l a) -> Zipper (Group l a)
f Groups l l2 a
g = let (Uniq
seed', Uniq
ident :~ Stream Uniq
_) = Uniq -> (Uniq, Stream Uniq)
gen (Groups l l2 a -> Uniq
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> Uniq
seed Groups l l2 a
g)
defaultGroups :: Stack (Group l a)
defaultGroups = Zipper (Group l a) -> Stack (Group l a)
forall a. HasCallStack => Maybe a -> a
fromJust (Zipper (Group l a) -> Stack (Group l a))
-> Zipper (Group l a) -> Stack (Group l a)
forall a b. (a -> b) -> a -> b
$ Group l a -> Zipper (Group l a)
forall a. a -> Zipper a
singletonZ (Group l a -> Zipper (Group l a))
-> Group l a -> Zipper (Group l a)
forall a b. (a -> b) -> a -> b
$ WithID l a -> Zipper a -> Group l a
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G (Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
ident (l a -> WithID l a) -> l a -> WithID l a
forall a b. (a -> b) -> a -> b
$ Groups l l2 a -> l a
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout Groups l l2 a
g) Zipper a
forall a. Zipper a
emptyZ
in Groups l l2 a
g { groups = fromMaybe defaultGroups . f . Just $ groups g
, seed = seed' }
modifyGroupsX :: (Zipper (Group l a) -> X (Zipper (Group l a)))
-> Groups l l2 a -> X (Groups l l2 a)
modifyGroupsX :: forall (l :: * -> *) a (l2 :: * -> *).
(Zipper (Group l a) -> X (Zipper (Group l a)))
-> Groups l l2 a -> X (Groups l l2 a)
modifyGroupsX Zipper (Group l a) -> X (Zipper (Group l a))
f Groups l l2 a
g = do
let (Uniq
seed', Uniq
ident :~ Stream Uniq
_) = Uniq -> (Uniq, Stream Uniq)
gen (Groups l l2 a -> Uniq
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> Uniq
seed Groups l l2 a
g)
defaultGroups :: Stack (Group l a)
defaultGroups = Zipper (Group l a) -> Stack (Group l a)
forall a. HasCallStack => Maybe a -> a
fromJust (Zipper (Group l a) -> Stack (Group l a))
-> Zipper (Group l a) -> Stack (Group l a)
forall a b. (a -> b) -> a -> b
$ Group l a -> Zipper (Group l a)
forall a. a -> Zipper a
singletonZ (Group l a -> Zipper (Group l a))
-> Group l a -> Zipper (Group l a)
forall a b. (a -> b) -> a -> b
$ WithID l a -> Zipper a -> Group l a
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G (Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
ident (l a -> WithID l a) -> l a -> WithID l a
forall a b. (a -> b) -> a -> b
$ Groups l l2 a -> l a
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout Groups l l2 a
g) Zipper a
forall a. Zipper a
emptyZ
Zipper (Group l a)
g' <- Zipper (Group l a) -> X (Zipper (Group l a))
f (Zipper (Group l a) -> X (Zipper (Group l a)))
-> (Stack (Group l a) -> Zipper (Group l a))
-> Stack (Group l a)
-> X (Zipper (Group l a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack (Group l a) -> Zipper (Group l a)
forall a. a -> Maybe a
Just (Stack (Group l a) -> X (Zipper (Group l a)))
-> Stack (Group l a) -> X (Zipper (Group l a))
forall a b. (a -> b) -> a -> b
$ Groups l l2 a -> Stack (Group l a)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups Groups l l2 a
g
Groups l l2 a -> X (Groups l l2 a)
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Groups l l2 a
g { groups = fromMaybe defaultGroups g', seed = seed' }
readapt :: Eq a => Zipper a -> Groups l l2 a -> Groups l l2 a
readapt :: forall a (l :: * -> *) (l2 :: * -> *).
Eq a =>
Zipper a -> Groups l l2 a -> Groups l l2 a
readapt Zipper a
z Groups l l2 a
g = let mf :: Maybe a
mf = Zipper a -> Maybe a
forall a. Zipper a -> Maybe a
getFocusZ Zipper a
z
(Uniq
seed', Uniq
ident :~ Stream Uniq
_) = Uniq -> (Uniq, Stream Uniq)
gen (Uniq -> (Uniq, Stream Uniq)) -> Uniq -> (Uniq, Stream Uniq)
forall a b. (a -> b) -> a -> b
$ Groups l l2 a -> Uniq
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> Uniq
seed Groups l l2 a
g
g' :: Groups l l2 a
g' = Groups l l2 a
g { seed = seed' }
in ((Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a -> Groups l l2 a)
-> Groups l l2 a
-> (Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a -> Groups l l2 a
forall (l :: * -> *) a (l2 :: * -> *).
(Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a -> Groups l l2 a
modifyGroups Groups l l2 a
g' ((Zipper (Group l a) -> Zipper (Group l a)) -> Groups l l2 a)
-> (Zipper (Group l a) -> Zipper (Group l a)) -> Groups l l2 a
forall a b. (a -> b) -> a -> b
$ (Group l a -> Group l a)
-> Zipper (Group l a) -> Zipper (Group l a)
forall a b. (a -> b) -> Zipper a -> Zipper b
mapZ_ ((Zipper a -> Zipper a) -> Group l a -> Group l a
forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper ((Zipper a -> Zipper a) -> Group l a -> Group l a)
-> (Zipper a -> Zipper a) -> Group l a -> Group l a
forall a b. (a -> b) -> a -> b
$ Zipper a -> Zipper a -> Zipper a
forall a. Eq a => Zipper a -> Zipper a -> Zipper a
removeDeleted Zipper a
z)
(Zipper (Group l a) -> Zipper (Group l a))
-> (Zipper (Group l a) -> Zipper (Group l a))
-> Zipper (Group l a)
-> Zipper (Group l a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Group l a -> Bool) -> Zipper (Group l a) -> Zipper (Group l a)
forall {a}. (a -> Bool) -> Maybe (Stack a) -> Maybe (Stack a)
filterKeepLast (Zipper a -> Bool
forall a. Maybe a -> Bool
isJust (Zipper a -> Bool) -> (Group l a -> Zipper a) -> Group l a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Group l a -> Zipper a
forall (l :: * -> *) a. Group l a -> Zipper a
gZipper)
(Zipper (Group l a) -> Zipper (Group l a))
-> (Zipper (Group l a) -> Zipper (Group l a))
-> Zipper (Group l a)
-> Zipper (Group l a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> [a] -> Zipper (Group l a) -> (Zipper (Group l a), [a])
forall a (l :: * -> *).
Eq a =>
[a] -> Zipper (Group l a) -> (Zipper (Group l a), [a])
findNewWindows (Zipper a -> [a]
forall a. Maybe (Stack a) -> [a]
W.integrate' Zipper a
z)
(Zipper (Group l a) -> (Zipper (Group l a), [a]))
-> ((Zipper (Group l a), [a]) -> Zipper (Group l a))
-> Zipper (Group l a)
-> Zipper (Group l a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> WithID l a -> (Zipper (Group l a), [a]) -> Zipper (Group l a)
forall (l :: * -> *) a.
WithID l a -> (Zipper (Group l a), [a]) -> Zipper (Group l a)
addWindows (Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
ident (l a -> WithID l a) -> l a -> WithID l a
forall a b. (a -> b) -> a -> b
$ Groups l l2 a -> l a
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout Groups l l2 a
g)
((Zipper (Group l a), [a]) -> Zipper (Group l a))
-> (Zipper (Group l a) -> Zipper (Group l a))
-> (Zipper (Group l a), [a])
-> Zipper (Group l a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Maybe a -> Zipper (Group l a) -> Zipper (Group l a)
forall a (l :: * -> *).
Eq a =>
Maybe a -> Zipper (Group l a) -> Zipper (Group l a)
focusGroup Maybe a
mf
(Zipper (Group l a) -> Zipper (Group l a))
-> (Zipper (Group l a) -> Zipper (Group l a))
-> Zipper (Group l a)
-> Zipper (Group l a)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Group l a -> Group l a)
-> Zipper (Group l a) -> Zipper (Group l a)
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ ((Zipper a -> Zipper a) -> Group l a -> Group l a
forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper ((Zipper a -> Zipper a) -> Group l a -> Group l a)
-> (Zipper a -> Zipper a) -> Group l a -> Group l a
forall a b. (a -> b) -> a -> b
$ Maybe a -> Zipper a -> Zipper a
forall a. Eq a => Maybe a -> Zipper a -> Zipper a
focusWindow Maybe a
mf)
where filterKeepLast :: (a -> Bool) -> Maybe (Stack a) -> Maybe (Stack a)
filterKeepLast a -> Bool
_ Maybe (Stack a)
Nothing = Maybe (Stack a)
forall a. Maybe a
Nothing
filterKeepLast a -> Bool
f z :: Maybe (Stack a)
z@(Just Stack a
s) = (a -> Bool) -> Maybe (Stack a) -> Maybe (Stack a)
forall {a}. (a -> Bool) -> Maybe (Stack a) -> Maybe (Stack a)
filterZ_ a -> Bool
f Maybe (Stack a)
z
Maybe (Stack a) -> Maybe (Stack a) -> Maybe (Stack a)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> a -> Maybe (Stack a)
forall a. a -> Zipper a
singletonZ (Stack a -> a
forall a. Stack a -> a
W.focus Stack a
s)
removeDeleted :: Eq a => Zipper a -> Zipper a -> Zipper a
removeDeleted :: forall a. Eq a => Zipper a -> Zipper a -> Zipper a
removeDeleted Zipper a
z = (a -> Bool) -> Zipper a -> Zipper a
forall {a}. (a -> Bool) -> Maybe (Stack a) -> Maybe (Stack a)
filterZ_ (a -> Zipper a -> Bool
forall a. Eq a => a -> Zipper a -> Bool
`elemZ` Zipper a
z)
findNewWindows :: Eq a => [a] -> Zipper (Group l a)
-> (Zipper (Group l a), [a])
findNewWindows :: forall a (l :: * -> *).
Eq a =>
[a] -> Zipper (Group l a) -> (Zipper (Group l a), [a])
findNewWindows [a]
as Zipper (Group l a)
gs = (Zipper (Group l a)
gs, (Group l a -> [a] -> [a]) -> [a] -> Zipper (Group l a) -> [a]
forall a b. (a -> b -> b) -> b -> Zipper a -> b
foldrZ_ Group l a -> [a] -> [a]
forall {a} {l :: * -> *}. Eq a => Group l a -> [a] -> [a]
removePresent [a]
as Zipper (Group l a)
gs)
where removePresent :: Group l a -> [a] -> [a]
removePresent Group l a
g = (a -> Bool) -> [a] -> [a]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool) -> (a -> Bool) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Zipper a -> Bool) -> Zipper a -> a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> Zipper a -> Bool
forall a. Eq a => a -> Zipper a -> Bool
elemZ (Group l a -> Zipper a
forall (l :: * -> *) a. Group l a -> Zipper a
gZipper Group l a
g))
addWindows :: WithID l a -> (Zipper (Group l a), [a]) -> Zipper (Group l a)
addWindows :: forall (l :: * -> *) a.
WithID l a -> (Zipper (Group l a), [a]) -> Zipper (Group l a)
addWindows WithID l a
l (Zipper (Group l a)
Nothing, [a]
as) = Group l a -> Zipper (Group l a)
forall a. a -> Zipper a
singletonZ (Group l a -> Zipper (Group l a))
-> Group l a -> Zipper (Group l a)
forall a b. (a -> b) -> a -> b
$ WithID l a -> Zipper a -> Group l a
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G WithID l a
l ([a] -> Zipper a
forall a. [a] -> Maybe (Stack a)
W.differentiate [a]
as)
addWindows WithID l a
_ (Zipper (Group l a)
z, [a]
as) = (Group l a -> Group l a)
-> Zipper (Group l a) -> Zipper (Group l a)
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ ((Zipper a -> Zipper a) -> Group l a -> Group l a
forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper Zipper a -> Zipper a
add) Zipper (Group l a)
z
where add :: Zipper a -> Zipper a
add Zipper a
z = (Zipper a -> a -> Zipper a) -> Zipper a -> [a] -> Zipper a
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl ((a -> Zipper a -> Zipper a) -> Zipper a -> a -> Zipper a
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> Zipper a -> Zipper a
forall a. a -> Zipper a -> Zipper a
insertUpZ) Zipper a
z [a]
as
focusGroup :: Eq a => Maybe a -> Zipper (Group l a) -> Zipper (Group l a)
focusGroup :: forall a (l :: * -> *).
Eq a =>
Maybe a -> Zipper (Group l a) -> Zipper (Group l a)
focusGroup Maybe a
Nothing = Zipper (Group l a) -> Zipper (Group l a)
forall a. a -> a
id
focusGroup (Just a
a) = [Either (Group l a) (Group l a)] -> Zipper (Group l a)
forall a. [Either a a] -> Zipper a
fromTags ([Either (Group l a) (Group l a)] -> Zipper (Group l a))
-> (Zipper (Group l a) -> [Either (Group l a) (Group l a)])
-> Zipper (Group l a)
-> Zipper (Group l a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Group l a -> Either (Group l a) (Group l a))
-> [Group l a] -> [Either (Group l a) (Group l a)]
forall a b. (a -> b) -> [a] -> [b]
map ((Group l a -> Bool) -> Group l a -> Either (Group l a) (Group l a)
forall a. (a -> Bool) -> a -> Either a a
tagBy ((Group l a -> Bool)
-> Group l a -> Either (Group l a) (Group l a))
-> (Group l a -> Bool)
-> Group l a
-> Either (Group l a) (Group l a)
forall a b. (a -> b) -> a -> b
$ a -> Zipper a -> Bool
forall a. Eq a => a -> Zipper a -> Bool
elemZ a
a (Zipper a -> Bool) -> (Group l a -> Zipper a) -> Group l a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Group l a -> Zipper a
forall (l :: * -> *) a. Group l a -> Zipper a
gZipper) ([Group l a] -> [Either (Group l a) (Group l a)])
-> (Zipper (Group l a) -> [Group l a])
-> Zipper (Group l a)
-> [Either (Group l a) (Group l a)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper (Group l a) -> [Group l a]
forall a. Maybe (Stack a) -> [a]
W.integrate'
focusWindow :: Eq a => Maybe a -> Zipper a -> Zipper a
focusWindow :: forall a. Eq a => Maybe a -> Zipper a -> Zipper a
focusWindow Maybe a
Nothing = Zipper a -> Zipper a
forall a. a -> a
id
focusWindow (Just a
a) = [Either a a] -> Zipper a
forall a. [Either a a] -> Zipper a
fromTags ([Either a a] -> Zipper a)
-> (Zipper a -> [Either a a]) -> Zipper a -> Zipper a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Either a a) -> [a] -> [Either a a]
forall a b. (a -> b) -> [a] -> [b]
map ((a -> Bool) -> a -> Either a a
forall a. (a -> Bool) -> a -> Either a a
tagBy (a -> a -> Bool
forall a. Eq a => a -> a -> Bool
==a
a)) ([a] -> [Either a a])
-> (Zipper a -> [a]) -> Zipper a -> [Either a a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Zipper a -> [a]
forall a. Maybe (Stack a) -> [a]
W.integrate'
instance (LayoutClass l Window, LayoutClass l2 (Group l Window))
=> LayoutClass (Groups l l2) Window where
description :: Groups l l2 Window -> String
description (Groups l Window
_ l2 (Group l Window)
p Stack (Group l Window)
gs Uniq
_) = String
s1String -> ShowS
forall a. [a] -> [a] -> [a]
++String
" by "String -> ShowS
forall a. [a] -> [a] -> [a]
++String
s2
where s1 :: String
s1 = WithID l Window -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description (WithID l Window -> String) -> WithID l Window -> String
forall a b. (a -> b) -> a -> b
$ Group l Window -> WithID l Window
forall (l :: * -> *) a. Group l a -> WithID l a
gLayout (Group l Window -> WithID l Window)
-> Group l Window -> WithID l Window
forall a b. (a -> b) -> a -> b
$ Stack (Group l Window) -> Group l Window
forall a. Stack a -> a
W.focus Stack (Group l Window)
gs
s2 :: String
s2 = l2 (Group l Window) -> String
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> String
description l2 (Group l Window)
p
runLayout :: Workspace String (Groups l l2 Window) Window
-> Rectangle
-> X ([(Window, Rectangle)], Maybe (Groups l l2 Window))
runLayout ws :: Workspace String (Groups l l2 Window) Window
ws@(W.Workspace String
_ Groups l l2 Window
_l Zipper Window
z) Rectangle
r = let l :: Groups l l2 Window
l = Zipper Window -> Groups l l2 Window -> Groups l l2 Window
forall a (l :: * -> *) (l2 :: * -> *).
Eq a =>
Zipper a -> Groups l l2 a -> Groups l l2 a
readapt Zipper Window
z Groups l l2 Window
_l in
do ([(Group l Window, Rectangle)]
areas, Maybe (l2 (Group l Window))
mpart') <- Workspace String (l2 (Group l Window)) (Group l Window)
-> Rectangle
-> X ([(Group l Window, Rectangle)], Maybe (l2 (Group l Window)))
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace String (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout Workspace String (Groups l l2 Window) Window
ws { W.layout = partitioner l
, W.stack = Just $ groups l } Rectangle
r
[([(Window, Rectangle)], Maybe (WithID l Window))]
results <- [(Group l Window, Rectangle)]
-> ((Group l Window, Rectangle)
-> X ([(Window, Rectangle)], Maybe (WithID l Window)))
-> X [([(Window, Rectangle)], Maybe (WithID l Window))]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
t a -> (a -> m b) -> m (t b)
forM [(Group l Window, Rectangle)]
areas (((Group l Window, Rectangle)
-> X ([(Window, Rectangle)], Maybe (WithID l Window)))
-> X [([(Window, Rectangle)], Maybe (WithID l Window))])
-> ((Group l Window, Rectangle)
-> X ([(Window, Rectangle)], Maybe (WithID l Window)))
-> X [([(Window, Rectangle)], Maybe (WithID l Window))]
forall a b. (a -> b) -> a -> b
$ \(Group l Window
g, Rectangle
r') -> Workspace String (WithID l Window) Window
-> Rectangle -> X ([(Window, Rectangle)], Maybe (WithID l Window))
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace String (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout Workspace String (Groups l l2 Window) Window
ws { W.layout = gLayout g
, W.stack = gZipper g } Rectangle
r'
let hidden :: [WithID l Window]
hidden = (Group l Window -> WithID l Window)
-> [Group l Window] -> [WithID l Window]
forall a b. (a -> b) -> [a] -> [b]
map Group l Window -> WithID l Window
forall (l :: * -> *) a. Group l a -> WithID l a
gLayout (Stack (Group l Window) -> [Group l Window]
forall a. Stack a -> [a]
W.integrate (Stack (Group l Window) -> [Group l Window])
-> Stack (Group l Window) -> [Group l Window]
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window -> Stack (Group l Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups Groups l l2 Window
_l) [WithID l Window] -> [WithID l Window] -> [WithID l Window]
forall a. Eq a => [a] -> [a] -> [a]
\\ ((Group l Window, Rectangle) -> WithID l Window)
-> [(Group l Window, Rectangle)] -> [WithID l Window]
forall a b. (a -> b) -> [a] -> [b]
map (Group l Window -> WithID l Window
forall (l :: * -> *) a. Group l a -> WithID l a
gLayout (Group l Window -> WithID l Window)
-> ((Group l Window, Rectangle) -> Group l Window)
-> (Group l Window, Rectangle)
-> WithID l Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Group l Window, Rectangle) -> Group l Window
forall a b. (a, b) -> a
fst) [(Group l Window, Rectangle)]
areas
[Maybe (WithID l Window)]
hidden' <- (WithID l Window -> X (Maybe (WithID l Window)))
-> [WithID l Window] -> X [Maybe (WithID l Window)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM ((WithID l Window -> SomeMessage -> X (Maybe (WithID l Window)))
-> SomeMessage -> WithID l Window -> X (Maybe (WithID l Window))
forall a b c. (a -> b -> c) -> b -> a -> c
flip WithID l Window -> SomeMessage -> X (Maybe (WithID l Window))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage (SomeMessage -> WithID l Window -> X (Maybe (WithID l Window)))
-> SomeMessage -> WithID l Window -> X (Maybe (WithID l Window))
forall a b. (a -> b) -> a -> b
$ LayoutMessages -> SomeMessage
forall a. Message a => a -> SomeMessage
SomeMessage LayoutMessages
Hide) [WithID l Window]
hidden
let placements :: [(Window, Rectangle)]
placements = (([(Window, Rectangle)], Maybe (WithID l Window))
-> [(Window, Rectangle)])
-> [([(Window, Rectangle)], Maybe (WithID l Window))]
-> [(Window, Rectangle)]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap ([(Window, Rectangle)], Maybe (WithID l Window))
-> [(Window, Rectangle)]
forall a b. (a, b) -> a
fst [([(Window, Rectangle)], Maybe (WithID l Window))]
results
newL :: Maybe (Groups l l2 Window)
newL = Groups l l2 Window
-> Maybe (l2 (Group l Window))
-> [Maybe (WithID l Window)]
-> Maybe (Groups l l2 Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
justMakeNew Groups l l2 Window
l Maybe (l2 (Group l Window))
mpart' ((([(Window, Rectangle)], Maybe (WithID l Window))
-> Maybe (WithID l Window))
-> [([(Window, Rectangle)], Maybe (WithID l Window))]
-> [Maybe (WithID l Window)]
forall a b. (a -> b) -> [a] -> [b]
map ([(Window, Rectangle)], Maybe (WithID l Window))
-> Maybe (WithID l Window)
forall a b. (a, b) -> b
snd [([(Window, Rectangle)], Maybe (WithID l Window))]
results [Maybe (WithID l Window)]
-> [Maybe (WithID l Window)] -> [Maybe (WithID l Window)]
forall a. [a] -> [a] -> [a]
++ [Maybe (WithID l Window)]
hidden')
([(Window, Rectangle)], Maybe (Groups l l2 Window))
-> X ([(Window, Rectangle)], Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ([(Window, Rectangle)]
placements, Maybe (Groups l l2 Window)
newL)
handleMessage :: Groups l l2 Window -> SomeMessage -> X (Maybe (Groups l l2 Window))
handleMessage l :: Groups l l2 Window
l@(Groups l Window
_ l2 (Group l Window)
p Stack (Group l Window)
_ Uniq
_) SomeMessage
sm | Just (ToEnclosing SomeMessage
sm') <- SomeMessage -> Maybe GroupsMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
sm
= do Maybe (l2 (Group l Window))
mp' <- l2 (Group l Window)
-> SomeMessage -> X (Maybe (l2 (Group l Window)))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l2 (Group l Window)
p SomeMessage
sm'
Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window)))
-> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window
-> Maybe (l2 (Group l Window))
-> [Maybe (WithID l Window)]
-> Maybe (Groups l l2 Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
maybeMakeNew Groups l l2 Window
l Maybe (l2 (Group l Window))
mp' []
handleMessage l :: Groups l l2 Window
l@(Groups l Window
_ l2 (Group l Window)
p Stack (Group l Window)
gs Uniq
_) SomeMessage
sm | Just (ToAll SomeMessage
sm') <- SomeMessage -> Maybe GroupsMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
sm
= do Maybe (l2 (Group l Window))
mp' <- l2 (Group l Window)
-> SomeMessage -> X (Maybe (l2 (Group l Window)))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l2 (Group l Window)
p SomeMessage
sm'
Zipper (Maybe (WithID l Window))
mg's <- (Group l Window -> X (Maybe (WithID l Window)))
-> Maybe (Stack (Group l Window))
-> X (Zipper (Maybe (WithID l Window)))
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Zipper a -> m (Zipper b)
mapZM_ (SomeMessage -> Group l Window -> X (Maybe (WithID l Window))
forall {l :: * -> *} {a}.
LayoutClass l a =>
SomeMessage -> Group l a -> X (Maybe (WithID l a))
handle SomeMessage
sm') (Maybe (Stack (Group l Window))
-> X (Zipper (Maybe (WithID l Window))))
-> Maybe (Stack (Group l Window))
-> X (Zipper (Maybe (WithID l Window)))
forall a b. (a -> b) -> a -> b
$ Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
gs
Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window)))
-> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window
-> Maybe (l2 (Group l Window))
-> [Maybe (WithID l Window)]
-> Maybe (Groups l l2 Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
maybeMakeNew Groups l l2 Window
l Maybe (l2 (Group l Window))
mp' ([Maybe (WithID l Window)] -> Maybe (Groups l l2 Window))
-> [Maybe (WithID l Window)] -> Maybe (Groups l l2 Window)
forall a b. (a -> b) -> a -> b
$ Zipper (Maybe (WithID l Window)) -> [Maybe (WithID l Window)]
forall a. Maybe (Stack a) -> [a]
W.integrate' Zipper (Maybe (WithID l Window))
mg's
where handle :: SomeMessage -> Group l a -> X (Maybe (WithID l a))
handle SomeMessage
sm (G WithID l a
l Zipper a
_) = WithID l a -> SomeMessage -> X (Maybe (WithID l a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage WithID l a
l SomeMessage
sm
handleMessage Groups l l2 Window
l SomeMessage
sm | Just LayoutMessages
a <- SomeMessage -> Maybe LayoutMessages
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
sm
= let _rightType :: Bool
_rightType = LayoutMessages
a LayoutMessages -> LayoutMessages -> Bool
forall a. Eq a => a -> a -> Bool
== LayoutMessages
Hide
in Groups l l2 Window -> SomeMessage -> X (Maybe (Groups l l2 Window))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage Groups l l2 Window
l (SomeMessage -> X (Maybe (Groups l l2 Window)))
-> SomeMessage -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ GroupsMessage -> SomeMessage
forall a. Message a => a -> SomeMessage
SomeMessage (GroupsMessage -> SomeMessage) -> GroupsMessage -> SomeMessage
forall a b. (a -> b) -> a -> b
$ SomeMessage -> GroupsMessage
ToAll SomeMessage
sm
handleMessage l :: Groups l l2 Window
l@(Groups l Window
_ l2 (Group l Window)
_ Stack (Group l Window)
z Uniq
_) SomeMessage
sm = case SomeMessage -> Maybe GroupsMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
sm of
Just (ToFocused SomeMessage
sm') -> do [Maybe (WithID l Window)]
mg's <- Zipper (Maybe (WithID l Window)) -> [Maybe (WithID l Window)]
forall a. Maybe (Stack a) -> [a]
W.integrate' (Zipper (Maybe (WithID l Window)) -> [Maybe (WithID l Window)])
-> X (Zipper (Maybe (WithID l Window)))
-> X [Maybe (WithID l Window)]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> SomeMessage
-> Stack (Group l Window) -> X (Zipper (Maybe (WithID l Window)))
forall {l :: * -> *} {a}.
LayoutClass l a =>
SomeMessage -> Stack (Group l a) -> X (Zipper (Maybe (WithID l a)))
handleOnFocused SomeMessage
sm' Stack (Group l Window)
z
Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window)))
-> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window
-> Maybe (l2 (Group l Window))
-> [Maybe (WithID l Window)]
-> Maybe (Groups l l2 Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
maybeMakeNew Groups l l2 Window
l Maybe (l2 (Group l Window))
forall a. Maybe a
Nothing [Maybe (WithID l Window)]
mg's
Just (ToGroup Int
i SomeMessage
sm') -> do [Maybe (WithID l Window)]
mg's <- Int
-> SomeMessage
-> Stack (Group l Window)
-> X [Maybe (WithID l Window)]
forall {l :: * -> *} {a} {p}.
(LayoutClass l a, Num p, Enum p, Eq p) =>
p -> SomeMessage -> Stack (Group l a) -> X [Maybe (WithID l a)]
handleOnIndex Int
i SomeMessage
sm' Stack (Group l Window)
z
Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window)))
-> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window
-> Maybe (l2 (Group l Window))
-> [Maybe (WithID l Window)]
-> Maybe (Groups l l2 Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
maybeMakeNew Groups l l2 Window
l Maybe (l2 (Group l Window))
forall a. Maybe a
Nothing [Maybe (WithID l Window)]
mg's
Just (Modify ModifySpec
spec) -> case ModifySpec -> Groups l l2 Window -> Maybe (Groups l l2 Window)
forall (l :: * -> *) (l2 :: * -> *).
ModifySpec -> Groups l l2 Window -> Maybe (Groups l l2 Window)
applySpec WithID l Window
-> Zipper (Group l Window) -> Zipper (Group l Window)
ModifySpec
spec Groups l l2 Window
l of
Just Groups l l2 Window
l' -> Groups l l2 Window -> X (Maybe (Groups l l2 Window))
forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window -> X (Maybe (Groups l l2 Window))
refocus Groups l l2 Window
l'
Maybe (Groups l l2 Window)
Nothing -> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Groups l l2 Window)
forall a. Maybe a
Nothing
Just (ModifyX ModifySpecX
spec) -> do Maybe (Groups l l2 Window)
ml' <- ModifySpecX -> Groups l l2 Window -> X (Maybe (Groups l l2 Window))
forall (l :: * -> *) (l2 :: * -> *).
ModifySpecX -> Groups l l2 Window -> X (Maybe (Groups l l2 Window))
applySpecX WithID l Window
-> Zipper (Group l Window) -> X (Zipper (Group l Window))
ModifySpecX
spec Groups l l2 Window
l
Maybe (Groups l l2 Window) -> (Groups l l2 Window -> X ()) -> X ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe (Groups l l2 Window)
ml' (X (Maybe (Groups l l2 Window)) -> X ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (X (Maybe (Groups l l2 Window)) -> X ())
-> (Groups l l2 Window -> X (Maybe (Groups l l2 Window)))
-> Groups l l2 Window
-> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Groups l l2 Window -> X (Maybe (Groups l l2 Window))
forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window -> X (Maybe (Groups l l2 Window))
refocus)
Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Groups l l2 Window)
ml' Maybe (Groups l l2 Window)
-> Maybe (Groups l l2 Window) -> Maybe (Groups l l2 Window)
forall a. Maybe a -> Maybe a -> Maybe a
forall (f :: * -> *) a. Alternative f => f a -> f a -> f a
<|> Groups l l2 Window -> Maybe (Groups l l2 Window)
forall a. a -> Maybe a
Just Groups l l2 Window
l)
Just GroupsMessage
Refocus -> Groups l l2 Window -> X (Maybe (Groups l l2 Window))
forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window -> X (Maybe (Groups l l2 Window))
refocus Groups l l2 Window
l
Just GroupsMessage
_ -> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Groups l l2 Window)
forall a. Maybe a
Nothing
Maybe GroupsMessage
Nothing -> Groups l l2 Window -> SomeMessage -> X (Maybe (Groups l l2 Window))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage Groups l l2 Window
l (SomeMessage -> X (Maybe (Groups l l2 Window)))
-> SomeMessage -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ GroupsMessage -> SomeMessage
forall a. Message a => a -> SomeMessage
SomeMessage (SomeMessage -> GroupsMessage
ToFocused SomeMessage
sm)
where handleOnFocused :: SomeMessage -> Stack (Group l a) -> X (Zipper (Maybe (WithID l a)))
handleOnFocused SomeMessage
sm Stack (Group l a)
z = (Bool -> Group l a -> X (Maybe (WithID l a)))
-> Zipper (Group l a) -> X (Zipper (Maybe (WithID l a)))
forall (m :: * -> *) a b.
Monad m =>
(Bool -> a -> m b) -> Zipper a -> m (Zipper b)
mapZM Bool -> Group l a -> X (Maybe (WithID l a))
forall {l :: * -> *} {a}.
LayoutClass l a =>
Bool -> Group l a -> X (Maybe (WithID l a))
step (Zipper (Group l a) -> X (Zipper (Maybe (WithID l a))))
-> Zipper (Group l a) -> X (Zipper (Maybe (WithID l a)))
forall a b. (a -> b) -> a -> b
$ Stack (Group l a) -> Zipper (Group l a)
forall a. a -> Maybe a
Just Stack (Group l a)
z
where step :: Bool -> Group l a -> X (Maybe (WithID l a))
step Bool
True (G WithID l a
l Zipper a
_) = WithID l a -> SomeMessage -> X (Maybe (WithID l a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage WithID l a
l SomeMessage
sm
step Bool
False Group l a
_ = Maybe (WithID l a) -> X (Maybe (WithID l a))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (WithID l a)
forall a. Maybe a
Nothing
handleOnIndex :: p -> SomeMessage -> Stack (Group l a) -> X [Maybe (WithID l a)]
handleOnIndex p
i SomeMessage
sm Stack (Group l a)
z = ((p, Group l a) -> X (Maybe (WithID l a)))
-> [(p, Group l a)] -> X [Maybe (WithID l a)]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM (p, Group l a) -> X (Maybe (WithID l a))
forall {l :: * -> *} {a}.
LayoutClass l a =>
(p, Group l a) -> X (Maybe (WithID l a))
step ([(p, Group l a)] -> X [Maybe (WithID l a)])
-> [(p, Group l a)] -> X [Maybe (WithID l a)]
forall a b. (a -> b) -> a -> b
$ [p] -> [Group l a] -> [(p, Group l a)]
forall a b. [a] -> [b] -> [(a, b)]
zip [p
0..] ([Group l a] -> [(p, Group l a)])
-> [Group l a] -> [(p, Group l a)]
forall a b. (a -> b) -> a -> b
$ Stack (Group l a) -> [Group l a]
forall a. Stack a -> [a]
W.integrate Stack (Group l a)
z
where step :: (p, Group l a) -> X (Maybe (WithID l a))
step (p
j, G WithID l a
l Zipper a
_) | p
i p -> p -> Bool
forall a. Eq a => a -> a -> Bool
== p
j = WithID l a -> SomeMessage -> X (Maybe (WithID l a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage WithID l a
l SomeMessage
sm
step (p, Group l a)
_ = Maybe (WithID l a) -> X (Maybe (WithID l a))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (WithID l a)
forall a. Maybe a
Nothing
justMakeNew :: Groups l l2 a -> Maybe (l2 (Group l a)) -> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
justMakeNew :: forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
justMakeNew Groups l l2 a
g Maybe (l2 (Group l a))
mpart' [Maybe (WithID l a)]
ml's = Groups l l2 a -> Maybe (Groups l l2 a)
forall a. a -> Maybe a
Just Groups l l2 a
g { partitioner = fromMaybe (partitioner g) mpart'
, groups = combine (groups g) ml's }
where combine :: Stack (Group l a) -> [Maybe (WithID l a)] -> Stack (Group l a)
combine Stack (Group l a)
z [Maybe (WithID l a)]
ml's = let table :: [(Uniq, l a)]
table = (WithID l a -> (Uniq, l a)) -> [WithID l a] -> [(Uniq, l a)]
forall a b. (a -> b) -> [a] -> [b]
map (\(ID Uniq
id l a
a) -> (Uniq
id, l a
a)) ([WithID l a] -> [(Uniq, l a)]) -> [WithID l a] -> [(Uniq, l a)]
forall a b. (a -> b) -> a -> b
$ [Maybe (WithID l a)] -> [WithID l a]
forall a. [Maybe a] -> [a]
catMaybes [Maybe (WithID l a)]
ml's
in ((Group l a -> Group l a)
-> Stack (Group l a) -> Stack (Group l a))
-> Stack (Group l a)
-> (Group l a -> Group l a)
-> Stack (Group l a)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Group l a -> Group l a) -> Stack (Group l a) -> Stack (Group l a)
forall {a} {b}. (a -> b) -> Stack a -> Stack b
mapS_ Stack (Group l a)
z ((Group l a -> Group l a) -> Stack (Group l a))
-> (Group l a -> Group l a) -> Stack (Group l a)
forall a b. (a -> b) -> a -> b
$ \(G (ID Uniq
id l a
l) Zipper a
ws) -> case Uniq -> [(Uniq, l a)] -> Maybe (l a)
forall a b. Eq a => a -> [(a, b)] -> Maybe b
lookup Uniq
id [(Uniq, l a)]
table of
Maybe (l a)
Nothing -> WithID l a -> Zipper a -> Group l a
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G (Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
id l a
l) Zipper a
ws
Just l a
l' -> WithID l a -> Zipper a -> Group l a
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G (Uniq -> l a -> WithID l a
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
id l a
l') Zipper a
ws
mapS_ :: (a -> b) -> Stack a -> Stack b
mapS_ a -> b
f = Maybe (Stack b) -> Stack b
forall a. HasCallStack => Maybe a -> a
fromJust (Maybe (Stack b) -> Stack b)
-> (Stack a -> Maybe (Stack b)) -> Stack a -> Stack b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> b) -> Zipper a -> Maybe (Stack b)
forall a b. (a -> b) -> Zipper a -> Zipper b
mapZ_ a -> b
f (Zipper a -> Maybe (Stack b))
-> (Stack a -> Zipper a) -> Stack a -> Maybe (Stack b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack a -> Zipper a
forall a. a -> Maybe a
Just
maybeMakeNew :: Groups l l2 a -> Maybe (l2 (Group l a)) -> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
maybeMakeNew :: forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
maybeMakeNew Groups l l2 a
_ Maybe (l2 (Group l a))
Nothing [Maybe (WithID l a)]
ml's | (Maybe (WithID l a) -> Bool) -> [Maybe (WithID l a)] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Maybe (WithID l a) -> Bool
forall a. Maybe a -> Bool
isNothing [Maybe (WithID l a)]
ml's = Maybe (Groups l l2 a)
forall a. Maybe a
Nothing
maybeMakeNew Groups l l2 a
g Maybe (l2 (Group l a))
mpart' [Maybe (WithID l a)]
ml's = Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a
-> Maybe (l2 (Group l a))
-> [Maybe (WithID l a)]
-> Maybe (Groups l l2 a)
justMakeNew Groups l l2 a
g Maybe (l2 (Group l a))
mpart' [Maybe (WithID l a)]
ml's
refocus :: Groups l l2 Window -> X (Maybe (Groups l l2 Window))
refocus :: forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window -> X (Maybe (Groups l l2 Window))
refocus Groups l l2 Window
g =
let mw :: Maybe Window
mw = (Zipper Window -> Maybe Window
forall a. Zipper a -> Maybe a
getFocusZ (Zipper Window -> Maybe Window)
-> (Groups l l2 Window -> Zipper Window)
-> Groups l l2 Window
-> Maybe Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Group l Window -> Zipper Window
forall (l :: * -> *) a. Group l a -> Zipper a
gZipper (Group l Window -> Zipper Window)
-> (Groups l l2 Window -> Group l Window)
-> Groups l l2 Window
-> Zipper Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Stack (Group l Window) -> Group l Window
forall a. Stack a -> a
W.focus (Stack (Group l Window) -> Group l Window)
-> (Groups l l2 Window -> Stack (Group l Window))
-> Groups l l2 Window
-> Group l Window
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Groups l l2 Window -> Stack (Group l Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups) Groups l l2 Window
g
in Groups l l2 Window
g Groups l l2 Window -> Maybe Window -> Maybe (Groups l l2 Window)
forall a b. a -> Maybe b -> Maybe a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Window
mw Maybe (Groups l l2 Window)
-> X () -> X (Maybe (Groups l l2 Window))
forall a b. a -> X b -> X a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Maybe Window -> (Window -> X ()) -> X ()
forall (m :: * -> *) a. Monad m => Maybe a -> (a -> m ()) -> m ()
whenJust Maybe Window
mw ((WindowSet -> WindowSet) -> X ()
modifyWindowSet ((WindowSet -> WindowSet) -> X ())
-> (Window -> WindowSet -> WindowSet) -> Window -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Window -> WindowSet -> WindowSet
forall s a i l sd.
(Eq s, Eq a, Eq i) =>
a -> StackSet i l a s sd -> StackSet i l a s sd
W.focusWindow)
type ModifySpec = forall l. WithID l Window
-> Zipper (Group l Window)
-> Zipper (Group l Window)
type ModifySpecX = forall l. WithID l Window
-> Zipper (Group l Window)
-> X (Zipper (Group l Window))
applySpec :: ModifySpec -> Groups l l2 Window -> Maybe (Groups l l2 Window)
applySpec :: forall (l :: * -> *) (l2 :: * -> *).
ModifySpec -> Groups l l2 Window -> Maybe (Groups l l2 Window)
applySpec ModifySpec
f Groups l l2 Window
g =
let (Uniq
seed', Uniq
ident :~ Stream Uniq
ids) = Uniq -> (Uniq, Stream Uniq)
gen (Uniq -> (Uniq, Stream Uniq)) -> Uniq -> (Uniq, Stream Uniq)
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window -> Uniq
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> Uniq
seed Groups l l2 Window
g
g' :: Groups l l2 Window
g' = ((Zipper (Group l Window) -> Zipper (Group l Window))
-> Groups l l2 Window -> Groups l l2 Window)
-> Groups l l2 Window
-> (Zipper (Group l Window) -> Zipper (Group l Window))
-> Groups l l2 Window
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Zipper (Group l Window) -> Zipper (Group l Window))
-> Groups l l2 Window -> Groups l l2 Window
forall (l :: * -> *) a (l2 :: * -> *).
(Zipper (Group l a) -> Zipper (Group l a))
-> Groups l l2 a -> Groups l l2 a
modifyGroups Groups l l2 Window
g ((Zipper (Group l Window) -> Zipper (Group l Window))
-> Groups l l2 Window)
-> (Zipper (Group l Window) -> Zipper (Group l Window))
-> Groups l l2 Window
forall a b. (a -> b) -> a -> b
$ WithID l Window
-> Zipper (Group l Window) -> Zipper (Group l Window)
ModifySpec
f (Uniq -> l Window -> WithID l Window
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
ident (l Window -> WithID l Window) -> l Window -> WithID l Window
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window -> l Window
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout Groups l l2 Window
g)
(Zipper (Group l Window) -> Zipper (Group l Window))
-> (Zipper (Group l Window) -> Zipper (Group l Window))
-> Zipper (Group l Window)
-> Zipper (Group l Window)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> Zipper (Group l Window)
-> [Either (Group l Window) (Group l Window)]
forall a. Zipper a -> [Either a a]
toTags
(Zipper (Group l Window)
-> [Either (Group l Window) (Group l Window)])
-> ([Either (Group l Window) (Group l Window)]
-> Zipper (Group l Window))
-> Zipper (Group l Window)
-> Zipper (Group l Window)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)]))
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> [Either (Group l Window) (Group l Window)]
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Groups l l2 Window
-> Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window
-> Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
reID Groups l l2 Window
g) ((Stream Uniq
ids, []), [])
([Either (Group l Window) (Group l Window)]
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)]))
-> (((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> Zipper (Group l Window))
-> [Either (Group l Window) (Group l Window)]
-> Zipper (Group l Window)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ((Stream Uniq, [Uniq]), [Either (Group l Window) (Group l Window)])
-> [Either (Group l Window) (Group l Window)]
forall a b. (a, b) -> b
snd
(((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> [Either (Group l Window) (Group l Window)])
-> ([Either (Group l Window) (Group l Window)]
-> Zipper (Group l Window))
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> Zipper (Group l Window)
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> [Either (Group l Window) (Group l Window)]
-> Zipper (Group l Window)
forall a. [Either a a] -> Zipper a
fromTags
in if Groups l l2 Window -> Stack (Group l Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups Groups l l2 Window
g Stack (Group l Window) -> Stack (Group l Window) -> Bool
forall a. Eq a => a -> a -> Bool
== Groups l l2 Window -> Stack (Group l Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups Groups l l2 Window
g'
then Maybe (Groups l l2 Window)
forall a. Maybe a
Nothing
else Groups l l2 Window -> Maybe (Groups l l2 Window)
forall a. a -> Maybe a
Just Groups l l2 Window
g' { seed = seed' }
applySpecX :: ModifySpecX -> Groups l l2 Window -> X (Maybe (Groups l l2 Window))
applySpecX :: forall (l :: * -> *) (l2 :: * -> *).
ModifySpecX -> Groups l l2 Window -> X (Maybe (Groups l l2 Window))
applySpecX ModifySpecX
f Groups l l2 Window
g = do
let (Uniq
seed', Uniq
ident :~ Stream Uniq
ids) = Uniq -> (Uniq, Stream Uniq)
gen (Uniq -> (Uniq, Stream Uniq)) -> Uniq -> (Uniq, Stream Uniq)
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window -> Uniq
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> Uniq
seed Groups l l2 Window
g
Groups l l2 Window
g' <- ((Zipper (Group l Window) -> X (Zipper (Group l Window)))
-> Groups l l2 Window -> X (Groups l l2 Window))
-> Groups l l2 Window
-> (Zipper (Group l Window) -> X (Zipper (Group l Window)))
-> X (Groups l l2 Window)
forall a b c. (a -> b -> c) -> b -> a -> c
flip (Zipper (Group l Window) -> X (Zipper (Group l Window)))
-> Groups l l2 Window -> X (Groups l l2 Window)
forall (l :: * -> *) a (l2 :: * -> *).
(Zipper (Group l a) -> X (Zipper (Group l a)))
-> Groups l l2 a -> X (Groups l l2 a)
modifyGroupsX Groups l l2 Window
g ((Zipper (Group l Window) -> X (Zipper (Group l Window)))
-> X (Groups l l2 Window))
-> (Zipper (Group l Window) -> X (Zipper (Group l Window)))
-> X (Groups l l2 Window)
forall a b. (a -> b) -> a -> b
$ WithID l Window
-> Zipper (Group l Window) -> X (Zipper (Group l Window))
ModifySpecX
f (Uniq -> l Window -> WithID l Window
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
ident (l Window -> WithID l Window) -> l Window -> WithID l Window
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window -> l Window
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout Groups l l2 Window
g)
(Zipper (Group l Window) -> X (Zipper (Group l Window)))
-> (X (Zipper (Group l Window)) -> X (Zipper (Group l Window)))
-> Zipper (Group l Window)
-> X (Zipper (Group l Window))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (Zipper (Group l Window)
-> [Either (Group l Window) (Group l Window)])
-> X (Zipper (Group l Window))
-> X [Either (Group l Window) (Group l Window)]
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Zipper (Group l Window)
-> [Either (Group l Window) (Group l Window)]
forall a. Zipper a -> [Either a a]
toTags
(X (Zipper (Group l Window))
-> X [Either (Group l Window) (Group l Window)])
-> (X [Either (Group l Window) (Group l Window)]
-> X (Zipper (Group l Window)))
-> X (Zipper (Group l Window))
-> X (Zipper (Group l Window))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ([Either (Group l Window) (Group l Window)]
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)]))
-> X [Either (Group l Window) (Group l Window)]
-> X ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)]))
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> [Either (Group l Window) (Group l Window)]
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Groups l l2 Window
-> Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window
-> Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
reID Groups l l2 Window
g) ((Stream Uniq
ids, []), []))
(X [Either (Group l Window) (Group l Window)]
-> X ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)]))
-> (X ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> X (Zipper (Group l Window)))
-> X [Either (Group l Window) (Group l Window)]
-> X (Zipper (Group l Window))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> (((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> [Either (Group l Window) (Group l Window)])
-> X ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> X [Either (Group l Window) (Group l Window)]
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Stream Uniq, [Uniq]), [Either (Group l Window) (Group l Window)])
-> [Either (Group l Window) (Group l Window)]
forall a b. (a, b) -> b
snd
(X ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> X [Either (Group l Window) (Group l Window)])
-> (X [Either (Group l Window) (Group l Window)]
-> X (Zipper (Group l Window)))
-> X ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> X (Zipper (Group l Window))
forall {k} (cat :: k -> k -> *) (a :: k) (b :: k) (c :: k).
Category cat =>
cat a b -> cat b c -> cat a c
>>> ([Either (Group l Window) (Group l Window)]
-> Zipper (Group l Window))
-> X [Either (Group l Window) (Group l Window)]
-> X (Zipper (Group l Window))
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap [Either (Group l Window) (Group l Window)]
-> Zipper (Group l Window)
forall a. [Either a a] -> Zipper a
fromTags
Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window)))
-> Maybe (Groups l l2 Window) -> X (Maybe (Groups l l2 Window))
forall a b. (a -> b) -> a -> b
$ if Groups l l2 Window -> Stack (Group l Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups Groups l l2 Window
g Stack (Group l Window) -> Stack (Group l Window) -> Bool
forall a. Eq a => a -> a -> Bool
== Groups l l2 Window -> Stack (Group l Window)
forall (l :: * -> *) (l2 :: * -> *) a.
Groups l l2 a -> Stack (Group l a)
groups Groups l l2 Window
g'
then Maybe (Groups l l2 Window)
forall a. Maybe a
Nothing
else Groups l l2 Window -> Maybe (Groups l l2 Window)
forall a. a -> Maybe a
Just Groups l l2 Window
g' { seed = seed' }
reID :: Groups l l2 Window
-> Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]), [Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]), [Either (Group l Window) (Group l Window)])
reID :: forall (l :: * -> *) (l2 :: * -> *).
Groups l l2 Window
-> Either (Group l Window) (Group l Window)
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
-> ((Stream Uniq, [Uniq]),
[Either (Group l Window) (Group l Window)])
reID Groups l l2 Window
g Either (Group l Window) (Group l Window)
eg ((Uniq
ident :~ Stream Uniq
ids, [Uniq]
seen), [Either (Group l Window) (Group l Window)]
egs)
| Uniq
myID Uniq -> [Uniq] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Uniq]
seen = ((Stream Uniq
ids, [Uniq]
seen), (Group l Window -> Group l Window)
-> Either (Group l Window) (Group l Window)
-> Either (Group l Window) (Group l Window)
forall a b. (a -> b) -> Either a a -> Either b b
mapE_ (Uniq -> Group l Window -> Group l Window
forall {l :: * -> *}. Uniq -> Group l Window -> Group l Window
setID Uniq
ident) Either (Group l Window) (Group l Window)
egEither (Group l Window) (Group l Window)
-> [Either (Group l Window) (Group l Window)]
-> [Either (Group l Window) (Group l Window)]
forall a. a -> [a] -> [a]
:[Either (Group l Window) (Group l Window)]
egs)
| Bool
otherwise = ((Uniq
ident Uniq -> Stream Uniq -> Stream Uniq
forall a. a -> Stream a -> Stream a
:~ Stream Uniq
ids, Uniq
myIDUniq -> [Uniq] -> [Uniq]
forall a. a -> [a] -> [a]
:[Uniq]
seen), Either (Group l Window) (Group l Window)
egEither (Group l Window) (Group l Window)
-> [Either (Group l Window) (Group l Window)]
-> [Either (Group l Window) (Group l Window)]
forall a. a -> [a] -> [a]
:[Either (Group l Window) (Group l Window)]
egs)
where myID :: Uniq
myID = WithID l Window -> Uniq
forall (l :: * -> *) a. WithID l a -> Uniq
getID (WithID l Window -> Uniq) -> WithID l Window -> Uniq
forall a b. (a -> b) -> a -> b
$ Group l Window -> WithID l Window
forall (l :: * -> *) a. Group l a -> WithID l a
gLayout (Group l Window -> WithID l Window)
-> Group l Window -> WithID l Window
forall a b. (a -> b) -> a -> b
$ Either (Group l Window) (Group l Window) -> Group l Window
forall a. Either a a -> a
fromE Either (Group l Window) (Group l Window)
eg
setID :: Uniq -> Group l Window -> Group l Window
setID Uniq
id (G (ID Uniq
_ l Window
_) Zipper Window
z) = WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G (Uniq -> l Window -> WithID l Window
forall (l :: * -> *) a. Uniq -> l a -> WithID l a
ID Uniq
id (l Window -> WithID l Window) -> l Window -> WithID l Window
forall a b. (a -> b) -> a -> b
$ Groups l l2 Window -> l Window
forall (l :: * -> *) (l2 :: * -> *) a. Groups l l2 a -> l a
baseLayout Groups l l2 Window
g) Zipper Window
z
onFocused :: (Zipper Window -> Zipper Window) -> ModifySpec
onFocused :: (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
f WithID l Window
_ = (Group l Window -> Group l Window)
-> Zipper (Group l Window) -> Zipper (Group l Window)
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ ((Zipper Window -> Zipper Window)
-> Group l Window -> Group l Window
forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper Zipper Window -> Zipper Window
f)
swapUp :: ModifySpec
swapUp :: ModifySpec
swapUp = (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
forall a. Zipper a -> Zipper a
swapUpZ
swapDown :: ModifySpec
swapDown :: ModifySpec
swapDown = (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
forall a. Zipper a -> Zipper a
swapDownZ
swapMaster :: ModifySpec
swapMaster :: ModifySpec
swapMaster = (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
forall a. Zipper a -> Zipper a
swapMasterZ
swapGroupUp :: ModifySpec
swapGroupUp :: ModifySpec
swapGroupUp WithID l Window
_ = Zipper (Group l Window) -> Zipper (Group l Window)
forall a. Zipper a -> Zipper a
swapUpZ
swapGroupDown :: ModifySpec
swapGroupDown :: ModifySpec
swapGroupDown WithID l Window
_ = Zipper (Group l Window) -> Zipper (Group l Window)
forall a. Zipper a -> Zipper a
swapDownZ
swapGroupMaster :: ModifySpec
swapGroupMaster :: ModifySpec
swapGroupMaster WithID l Window
_ = Zipper (Group l Window) -> Zipper (Group l Window)
forall a. Zipper a -> Zipper a
swapMasterZ
focusUp :: ModifySpec
focusUp :: ModifySpec
focusUp = (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
forall a. Zipper a -> Zipper a
focusUpZ
focusDown :: ModifySpec
focusDown :: ModifySpec
focusDown = (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
forall a. Zipper a -> Zipper a
focusDownZ
focusMaster :: ModifySpec
focusMaster :: ModifySpec
focusMaster = (Zipper Window -> Zipper Window) -> ModifySpec
onFocused Zipper Window -> Zipper Window
forall a. Zipper a -> Zipper a
focusMasterZ
focusGroupUp :: ModifySpec
focusGroupUp :: ModifySpec
focusGroupUp WithID l Window
_ = Zipper (Group l Window) -> Zipper (Group l Window)
forall a. Zipper a -> Zipper a
focusUpZ
focusGroupDown :: ModifySpec
focusGroupDown :: ModifySpec
focusGroupDown WithID l Window
_ = Zipper (Group l Window) -> Zipper (Group l Window)
forall a. Zipper a -> Zipper a
focusDownZ
focusGroupMaster :: ModifySpec
focusGroupMaster :: ModifySpec
focusGroupMaster WithID l Window
_ = Zipper (Group l Window) -> Zipper (Group l Window)
forall a. Zipper a -> Zipper a
focusMasterZ
_removeFocused :: W.Stack a -> (a, Zipper a)
_removeFocused :: forall a. Stack a -> (a, Zipper a)
_removeFocused (W.Stack a
f (a
u:[a]
up) [a]
down) = (a
f, Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
u [a]
up [a]
down)
_removeFocused (W.Stack a
f [] (a
d:[a]
down)) = (a
f, Stack a -> Maybe (Stack a)
forall a. a -> Maybe a
Just (Stack a -> Maybe (Stack a)) -> Stack a -> Maybe (Stack a)
forall a b. (a -> b) -> a -> b
$ a -> [a] -> [a] -> Stack a
forall a. a -> [a] -> [a] -> Stack a
W.Stack a
d [] [a]
down)
_removeFocused (W.Stack a
f [] []) = (a
f, Maybe (Stack a)
forall a. Maybe a
Nothing)
_moveToNewGroup :: WithID l Window -> W.Stack (Group l Window)
-> (Group l Window -> Zipper (Group l Window)
-> Zipper (Group l Window))
-> Zipper (Group l Window)
_moveToNewGroup :: forall (l :: * -> *).
WithID l Window
-> Stack (Group l Window)
-> (Group l Window
-> Zipper (Group l Window) -> Zipper (Group l Window))
-> Zipper (Group l Window)
_moveToNewGroup WithID l Window
l0 Stack (Group l Window)
s Group l Window
-> Zipper (Group l Window) -> Zipper (Group l Window)
insertX | G WithID l Window
l (Just Stack Window
f) <- Stack (Group l Window) -> Group l Window
forall a. Stack a -> a
W.focus Stack (Group l Window)
s
= let (Window
w, Zipper Window
f') = Stack Window -> (Window, Zipper Window)
forall a. Stack a -> (a, Zipper a)
_removeFocused Stack Window
f
s' :: Stack (Group l Window)
s' = Stack (Group l Window)
s { W.focus = G l f' }
in Group l Window
-> Zipper (Group l Window) -> Zipper (Group l Window)
insertX (WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G WithID l Window
l0 (Zipper Window -> Group l Window)
-> Zipper Window -> Group l Window
forall a b. (a -> b) -> a -> b
$ Window -> Zipper Window
forall a. a -> Zipper a
singletonZ Window
w) (Zipper (Group l Window) -> Zipper (Group l Window))
-> Zipper (Group l Window) -> Zipper (Group l Window)
forall a b. (a -> b) -> a -> b
$ Stack (Group l Window) -> Zipper (Group l Window)
forall a. a -> Maybe a
Just Stack (Group l Window)
s'
_moveToNewGroup WithID l Window
_ Stack (Group l Window)
s Group l Window
-> Zipper (Group l Window) -> Zipper (Group l Window)
_ = Stack (Group l Window) -> Zipper (Group l Window)
forall a. a -> Maybe a
Just Stack (Group l Window)
s
moveToNewGroupUp :: ModifySpec
moveToNewGroupUp :: ModifySpec
moveToNewGroupUp WithID l Window
_ Maybe (Stack (Group l Window))
Nothing = Maybe (Stack (Group l Window))
forall a. Maybe a
Nothing
moveToNewGroupUp WithID l Window
l0 (Just Stack (Group l Window)
s) = WithID l Window
-> Stack (Group l Window)
-> (Group l Window
-> Maybe (Stack (Group l Window))
-> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window))
forall (l :: * -> *).
WithID l Window
-> Stack (Group l Window)
-> (Group l Window
-> Zipper (Group l Window) -> Zipper (Group l Window))
-> Zipper (Group l Window)
_moveToNewGroup WithID l Window
l0 Stack (Group l Window)
s Group l Window
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. a -> Zipper a -> Zipper a
insertUpZ
moveToNewGroupDown :: ModifySpec
moveToNewGroupDown :: ModifySpec
moveToNewGroupDown WithID l Window
_ Maybe (Stack (Group l Window))
Nothing = Maybe (Stack (Group l Window))
forall a. Maybe a
Nothing
moveToNewGroupDown WithID l Window
l0 (Just Stack (Group l Window)
s) = WithID l Window
-> Stack (Group l Window)
-> (Group l Window
-> Maybe (Stack (Group l Window))
-> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window))
forall (l :: * -> *).
WithID l Window
-> Stack (Group l Window)
-> (Group l Window
-> Zipper (Group l Window) -> Zipper (Group l Window))
-> Zipper (Group l Window)
_moveToNewGroup WithID l Window
l0 Stack (Group l Window)
s Group l Window
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. a -> Zipper a -> Zipper a
insertDownZ
moveToGroupUp :: Bool -> ModifySpec
moveToGroupUp :: Bool -> ModifySpec
moveToGroupUp Bool
_ WithID l Window
_ Maybe (Stack (Group l Window))
Nothing = Maybe (Stack (Group l Window))
forall a. Maybe a
Nothing
moveToGroupUp Bool
False WithID l Window
l0 (Just Stack (Group l Window)
s) = if [Group l Window] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Stack (Group l Window) -> [Group l Window]
forall a. Stack a -> [a]
W.up Stack (Group l Window)
s) then WithID l Window
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
ModifySpec
moveToNewGroupUp WithID l Window
l0 (Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s)
else Bool -> ModifySpec
moveToGroupUp Bool
True WithID l Window
l0 (Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s)
moveToGroupUp Bool
True WithID l Window
_ (Just s :: Stack (Group l Window)
s@(W.Stack Group l Window
_ [] [])) = Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s
moveToGroupUp Bool
True WithID l Window
_ (Just s :: Stack (Group l Window)
s@(W.Stack (G WithID l Window
l (Just Stack Window
f)) [Group l Window]
_ [Group l Window]
_))
= let (Window
w, Zipper Window
f') = Stack Window -> (Window, Zipper Window)
forall a. Stack a -> (a, Zipper a)
_removeFocused Stack Window
f
in (Group l Window -> Group l Window)
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ ((Zipper Window -> Zipper Window)
-> Group l Window -> Group l Window
forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper ((Zipper Window -> Zipper Window)
-> Group l Window -> Group l Window)
-> (Zipper Window -> Zipper Window)
-> Group l Window
-> Group l Window
forall a b. (a -> b) -> a -> b
$ Window -> Zipper Window -> Zipper Window
forall a. a -> Zipper a -> Zipper a
insertUpZ Window
w) (Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. Zipper a -> Zipper a
focusUpZ (Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s { W.focus = G l f' }
moveToGroupUp Bool
True WithID l Window
_ Maybe (Stack (Group l Window))
gs = Maybe (Stack (Group l Window))
gs
moveToGroupDown :: Bool -> ModifySpec
moveToGroupDown :: Bool -> ModifySpec
moveToGroupDown Bool
_ WithID l Window
_ Maybe (Stack (Group l Window))
Nothing = Maybe (Stack (Group l Window))
forall a. Maybe a
Nothing
moveToGroupDown Bool
False WithID l Window
l0 (Just Stack (Group l Window)
s) = if [Group l Window] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Stack (Group l Window) -> [Group l Window]
forall a. Stack a -> [a]
W.down Stack (Group l Window)
s) then WithID l Window
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
ModifySpec
moveToNewGroupDown WithID l Window
l0 (Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s)
else Bool -> ModifySpec
moveToGroupDown Bool
True WithID l Window
l0 (Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s)
moveToGroupDown Bool
True WithID l Window
_ (Just s :: Stack (Group l Window)
s@(W.Stack Group l Window
_ [] [])) = Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s
moveToGroupDown Bool
True WithID l Window
_ (Just s :: Stack (Group l Window)
s@(W.Stack (G WithID l Window
l (Just Stack Window
f)) [Group l Window]
_ [Group l Window]
_))
= let (Window
w, Zipper Window
f') = Stack Window -> (Window, Zipper Window)
forall a. Stack a -> (a, Zipper a)
_removeFocused Stack Window
f
in (Group l Window -> Group l Window)
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ ((Zipper Window -> Zipper Window)
-> Group l Window -> Group l Window
forall a (l :: * -> *).
(Zipper a -> Zipper a) -> Group l a -> Group l a
onZipper ((Zipper Window -> Zipper Window)
-> Group l Window -> Group l Window)
-> (Zipper Window -> Zipper Window)
-> Group l Window
-> Group l Window
forall a b. (a -> b) -> a -> b
$ Window -> Zipper Window -> Zipper Window
forall a. a -> Zipper a -> Zipper a
insertUpZ Window
w) (Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. Zipper a -> Zipper a
focusDownZ (Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ Stack (Group l Window) -> Maybe (Stack (Group l Window))
forall a. a -> Maybe a
Just Stack (Group l Window)
s { W.focus = G l f' }
moveToGroupDown Bool
True WithID l Window
_ Maybe (Stack (Group l Window))
gs = Maybe (Stack (Group l Window))
gs
splitGroup :: ModifySpec
splitGroup :: ModifySpec
splitGroup WithID l Window
_ Maybe (Stack (Group l Window))
Nothing = Maybe (Stack (Group l Window))
forall a. Maybe a
Nothing
splitGroup WithID l Window
l0 z :: Maybe (Stack (Group l Window))
z@(Just Stack (Group l Window)
s) | G WithID l Window
l (Just Stack Window
ws) <- Stack (Group l Window) -> Group l Window
forall a. Stack a -> a
W.focus Stack (Group l Window)
s
= case Stack Window
ws of
W.Stack Window
_ [] [] -> Maybe (Stack (Group l Window))
z
W.Stack Window
f (Window
u:[Window]
up) [] -> let g1 :: Group l Window
g1 = WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G WithID l Window
l (Zipper Window -> Group l Window)
-> Zipper Window -> Group l Window
forall a b. (a -> b) -> a -> b
$ Stack Window -> Zipper Window
forall a. a -> Maybe a
Just (Stack Window -> Zipper Window) -> Stack Window -> Zipper Window
forall a b. (a -> b) -> a -> b
$ Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
f [] []
g2 :: Group l Window
g2 = WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G WithID l Window
l0 (Zipper Window -> Group l Window)
-> Zipper Window -> Group l Window
forall a b. (a -> b) -> a -> b
$ Stack Window -> Zipper Window
forall a. a -> Maybe a
Just (Stack Window -> Zipper Window) -> Stack Window -> Zipper Window
forall a b. (a -> b) -> a -> b
$ Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
u [Window]
up []
in Group l Window
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. a -> Zipper a -> Zipper a
insertDownZ Group l Window
g1 (Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ (Group l Window -> Group l Window)
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ (Group l Window -> Group l Window -> Group l Window
forall a b. a -> b -> a
const Group l Window
g2) Maybe (Stack (Group l Window))
z
W.Stack Window
f [Window]
up (Window
d:[Window]
down) -> let g1 :: Group l Window
g1 = WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G WithID l Window
l (Zipper Window -> Group l Window)
-> Zipper Window -> Group l Window
forall a b. (a -> b) -> a -> b
$ Stack Window -> Zipper Window
forall a. a -> Maybe a
Just (Stack Window -> Zipper Window) -> Stack Window -> Zipper Window
forall a b. (a -> b) -> a -> b
$ Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
f [Window]
up []
g2 :: Group l Window
g2 = WithID l Window -> Zipper Window -> Group l Window
forall (l :: * -> *) a. WithID l a -> Zipper a -> Group l a
G WithID l Window
l0 (Zipper Window -> Group l Window)
-> Zipper Window -> Group l Window
forall a b. (a -> b) -> a -> b
$ Stack Window -> Zipper Window
forall a. a -> Maybe a
Just (Stack Window -> Zipper Window) -> Stack Window -> Zipper Window
forall a b. (a -> b) -> a -> b
$ Window -> [Window] -> [Window] -> Stack Window
forall a. a -> [a] -> [a] -> Stack a
W.Stack Window
d [] [Window]
down
in Group l Window
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. a -> Zipper a -> Zipper a
insertUpZ Group l Window
g1 (Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window)))
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a b. (a -> b) -> a -> b
$ (Group l Window -> Group l Window)
-> Maybe (Stack (Group l Window)) -> Maybe (Stack (Group l Window))
forall a. (a -> a) -> Zipper a -> Zipper a
onFocusedZ (Group l Window -> Group l Window -> Group l Window
forall a b. a -> b -> a
const Group l Window
g2) Maybe (Stack (Group l Window))
z
splitGroup WithID l Window
_ Maybe (Stack (Group l Window))
_ = Maybe (Stack (Group l Window))
forall a. Maybe a
Nothing