{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.PerWorkspace
(
PerWorkspace,
onWorkspace, onWorkspaces,
modWorkspace, modWorkspaces
) where
import XMonad
import qualified XMonad.StackSet as W
import XMonad.Prelude (fromMaybe)
onWorkspace :: (LayoutClass l1 a, LayoutClass l2 a)
=> WorkspaceId
-> l1 a
-> l2 a
-> PerWorkspace l1 l2 a
onWorkspace :: WorkspaceId -> l1 a -> l2 a -> PerWorkspace l1 l2 a
onWorkspace WorkspaceId
wsId = [WorkspaceId] -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
[WorkspaceId] -> l1 a -> l2 a -> PerWorkspace l1 l2 a
onWorkspaces [WorkspaceId
wsId]
onWorkspaces :: (LayoutClass l1 a, LayoutClass l2 a)
=> [WorkspaceId]
-> l1 a
-> l2 a
-> PerWorkspace l1 l2 a
onWorkspaces :: [WorkspaceId] -> l1 a -> l2 a -> PerWorkspace l1 l2 a
onWorkspaces [WorkspaceId]
wsIds = [WorkspaceId] -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
[WorkspaceId] -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
modWorkspaces [WorkspaceId]
wsIds ((l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a)
-> (l1 a -> l2 a -> l1 a) -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. l1 a -> l2 a -> l1 a
forall a b. a -> b -> a
const
modWorkspace :: (LayoutClass l1 a, LayoutClass l2 a)
=> WorkspaceId
-> (l2 a -> l1 a)
-> l2 a
-> PerWorkspace l1 l2 a
modWorkspace :: WorkspaceId -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
modWorkspace WorkspaceId
wsId = [WorkspaceId] -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
[WorkspaceId] -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
modWorkspaces [WorkspaceId
wsId]
modWorkspaces :: (LayoutClass l1 a, LayoutClass l2 a)
=> [WorkspaceId]
-> (l2 a -> l1 a)
-> l2 a
-> PerWorkspace l1 l2 a
modWorkspaces :: [WorkspaceId] -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
modWorkspaces [WorkspaceId]
wsIds l2 a -> l1 a
f l2 a
l = [WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
PerWorkspace [WorkspaceId]
wsIds Bool
False (l2 a -> l1 a
f l2 a
l) l2 a
l
data PerWorkspace l1 l2 a = PerWorkspace [WorkspaceId]
Bool
(l1 a)
(l2 a)
deriving (ReadPrec [PerWorkspace l1 l2 a]
ReadPrec (PerWorkspace l1 l2 a)
Int -> ReadS (PerWorkspace l1 l2 a)
ReadS [PerWorkspace l1 l2 a]
(Int -> ReadS (PerWorkspace l1 l2 a))
-> ReadS [PerWorkspace l1 l2 a]
-> ReadPrec (PerWorkspace l1 l2 a)
-> ReadPrec [PerWorkspace l1 l2 a]
-> Read (PerWorkspace l1 l2 a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
ReadPrec [PerWorkspace l1 l2 a]
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
ReadPrec (PerWorkspace l1 l2 a)
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
Int -> ReadS (PerWorkspace l1 l2 a)
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
ReadS [PerWorkspace l1 l2 a]
readListPrec :: ReadPrec [PerWorkspace l1 l2 a]
$creadListPrec :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
ReadPrec [PerWorkspace l1 l2 a]
readPrec :: ReadPrec (PerWorkspace l1 l2 a)
$creadPrec :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
ReadPrec (PerWorkspace l1 l2 a)
readList :: ReadS [PerWorkspace l1 l2 a]
$creadList :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
ReadS [PerWorkspace l1 l2 a]
readsPrec :: Int -> ReadS (PerWorkspace l1 l2 a)
$creadsPrec :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Read (l1 a), Read (l2 a)) =>
Int -> ReadS (PerWorkspace l1 l2 a)
Read, Int -> PerWorkspace l1 l2 a -> ShowS
[PerWorkspace l1 l2 a] -> ShowS
PerWorkspace l1 l2 a -> WorkspaceId
(Int -> PerWorkspace l1 l2 a -> ShowS)
-> (PerWorkspace l1 l2 a -> WorkspaceId)
-> ([PerWorkspace l1 l2 a] -> ShowS)
-> Show (PerWorkspace l1 l2 a)
forall a.
(Int -> a -> ShowS)
-> (a -> WorkspaceId) -> ([a] -> ShowS) -> Show a
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Show (l1 a), Show (l2 a)) =>
Int -> PerWorkspace l1 l2 a -> ShowS
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Show (l1 a), Show (l2 a)) =>
[PerWorkspace l1 l2 a] -> ShowS
forall (l1 :: * -> *) (l2 :: * -> *) a.
(Show (l1 a), Show (l2 a)) =>
PerWorkspace l1 l2 a -> WorkspaceId
showList :: [PerWorkspace l1 l2 a] -> ShowS
$cshowList :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Show (l1 a), Show (l2 a)) =>
[PerWorkspace l1 l2 a] -> ShowS
show :: PerWorkspace l1 l2 a -> WorkspaceId
$cshow :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Show (l1 a), Show (l2 a)) =>
PerWorkspace l1 l2 a -> WorkspaceId
showsPrec :: Int -> PerWorkspace l1 l2 a -> ShowS
$cshowsPrec :: forall (l1 :: * -> *) (l2 :: * -> *) a.
(Show (l1 a), Show (l2 a)) =>
Int -> PerWorkspace l1 l2 a -> ShowS
Show)
instance (LayoutClass l1 a, LayoutClass l2 a, Show a) => LayoutClass (PerWorkspace l1 l2) a where
runLayout :: Workspace WorkspaceId (PerWorkspace l1 l2 a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (PerWorkspace l1 l2 a))
runLayout (W.Workspace WorkspaceId
i p :: PerWorkspace l1 l2 a
p@(PerWorkspace [WorkspaceId]
wsIds Bool
_ l1 a
lt l2 a
lf) Maybe (Stack a)
ms) Rectangle
r
| WorkspaceId
i WorkspaceId -> [WorkspaceId] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [WorkspaceId]
wsIds = do ([(a, Rectangle)]
wrs, Maybe (l1 a)
mlt') <- Workspace WorkspaceId (l1 a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (l1 a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace WorkspaceId (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout (WorkspaceId
-> l1 a -> Maybe (Stack a) -> Workspace WorkspaceId (l1 a) a
forall i l a. i -> l -> Maybe (Stack a) -> Workspace i l a
W.Workspace WorkspaceId
i l1 a
lt Maybe (Stack a)
ms) Rectangle
r
([(a, Rectangle)], Maybe (PerWorkspace l1 l2 a))
-> X ([(a, Rectangle)], Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a. Monad m => a -> m a
return ([(a, Rectangle)]
wrs, PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a)
forall a. a -> Maybe a
Just (PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a))
-> PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a)
forall a b. (a -> b) -> a -> b
$ PerWorkspace l1 l2 a -> Maybe (l1 a) -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
PerWorkspace l1 l2 a -> Maybe (l1 a) -> PerWorkspace l1 l2 a
mkNewPerWorkspaceT PerWorkspace l1 l2 a
p Maybe (l1 a)
mlt')
| Bool
otherwise = do ([(a, Rectangle)]
wrs, Maybe (l2 a)
mlt') <- Workspace WorkspaceId (l2 a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (l2 a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace WorkspaceId (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout (WorkspaceId
-> l2 a -> Maybe (Stack a) -> Workspace WorkspaceId (l2 a) a
forall i l a. i -> l -> Maybe (Stack a) -> Workspace i l a
W.Workspace WorkspaceId
i l2 a
lf Maybe (Stack a)
ms) Rectangle
r
([(a, Rectangle)], Maybe (PerWorkspace l1 l2 a))
-> X ([(a, Rectangle)], Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a. Monad m => a -> m a
return ([(a, Rectangle)]
wrs, PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a)
forall a. a -> Maybe a
Just (PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a))
-> PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a)
forall a b. (a -> b) -> a -> b
$ PerWorkspace l1 l2 a -> Maybe (l2 a) -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
PerWorkspace l1 l2 a -> Maybe (l2 a) -> PerWorkspace l1 l2 a
mkNewPerWorkspaceF PerWorkspace l1 l2 a
p Maybe (l2 a)
mlt')
handleMessage :: PerWorkspace l1 l2 a
-> SomeMessage -> X (Maybe (PerWorkspace l1 l2 a))
handleMessage (PerWorkspace [WorkspaceId]
wsIds Bool
bool l1 a
lt l2 a
lf) SomeMessage
m
| Bool
bool = l1 a -> SomeMessage -> X (Maybe (l1 a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l1 a
lt SomeMessage
m X (Maybe (l1 a))
-> (Maybe (l1 a) -> X (Maybe (PerWorkspace l1 l2 a)))
-> X (Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= X (Maybe (PerWorkspace l1 l2 a))
-> (l1 a -> X (Maybe (PerWorkspace l1 l2 a)))
-> Maybe (l1 a)
-> X (Maybe (PerWorkspace l1 l2 a))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (PerWorkspace l1 l2 a) -> X (Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (PerWorkspace l1 l2 a)
forall a. Maybe a
Nothing) (\l1 a
nt -> Maybe (PerWorkspace l1 l2 a) -> X (Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (PerWorkspace l1 l2 a) -> X (Maybe (PerWorkspace l1 l2 a)))
-> (PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a))
-> PerWorkspace l1 l2 a
-> X (Maybe (PerWorkspace l1 l2 a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a)
forall a. a -> Maybe a
Just (PerWorkspace l1 l2 a -> X (Maybe (PerWorkspace l1 l2 a)))
-> PerWorkspace l1 l2 a -> X (Maybe (PerWorkspace l1 l2 a))
forall a b. (a -> b) -> a -> b
$ [WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
PerWorkspace [WorkspaceId]
wsIds Bool
bool l1 a
nt l2 a
lf)
| Bool
otherwise = l2 a -> SomeMessage -> X (Maybe (l2 a))
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l2 a
lf SomeMessage
m X (Maybe (l2 a))
-> (Maybe (l2 a) -> X (Maybe (PerWorkspace l1 l2 a)))
-> X (Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= X (Maybe (PerWorkspace l1 l2 a))
-> (l2 a -> X (Maybe (PerWorkspace l1 l2 a)))
-> Maybe (l2 a)
-> X (Maybe (PerWorkspace l1 l2 a))
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Maybe (PerWorkspace l1 l2 a) -> X (Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (PerWorkspace l1 l2 a)
forall a. Maybe a
Nothing) (Maybe (PerWorkspace l1 l2 a) -> X (Maybe (PerWorkspace l1 l2 a))
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (PerWorkspace l1 l2 a) -> X (Maybe (PerWorkspace l1 l2 a)))
-> (l2 a -> Maybe (PerWorkspace l1 l2 a))
-> l2 a
-> X (Maybe (PerWorkspace l1 l2 a))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a)
forall a. a -> Maybe a
Just (PerWorkspace l1 l2 a -> Maybe (PerWorkspace l1 l2 a))
-> (l2 a -> PerWorkspace l1 l2 a)
-> l2 a
-> Maybe (PerWorkspace l1 l2 a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
PerWorkspace [WorkspaceId]
wsIds Bool
bool l1 a
lt)
description :: PerWorkspace l1 l2 a -> WorkspaceId
description (PerWorkspace [WorkspaceId]
_ Bool
True l1 a
l1 l2 a
_) = l1 a -> WorkspaceId
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> WorkspaceId
description l1 a
l1
description (PerWorkspace [WorkspaceId]
_ Bool
_ l1 a
_ l2 a
l2) = l2 a -> WorkspaceId
forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> WorkspaceId
description l2 a
l2
mkNewPerWorkspaceT :: PerWorkspace l1 l2 a -> Maybe (l1 a) ->
PerWorkspace l1 l2 a
mkNewPerWorkspaceT :: PerWorkspace l1 l2 a -> Maybe (l1 a) -> PerWorkspace l1 l2 a
mkNewPerWorkspaceT (PerWorkspace [WorkspaceId]
wsIds Bool
_ l1 a
lt l2 a
lf) Maybe (l1 a)
mlt' =
(\l1 a
lt' -> [WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
PerWorkspace [WorkspaceId]
wsIds Bool
True l1 a
lt' l2 a
lf) (l1 a -> PerWorkspace l1 l2 a) -> l1 a -> PerWorkspace l1 l2 a
forall a b. (a -> b) -> a -> b
$ l1 a -> Maybe (l1 a) -> l1 a
forall a. a -> Maybe a -> a
fromMaybe l1 a
lt Maybe (l1 a)
mlt'
mkNewPerWorkspaceF :: PerWorkspace l1 l2 a -> Maybe (l2 a) ->
PerWorkspace l1 l2 a
mkNewPerWorkspaceF :: PerWorkspace l1 l2 a -> Maybe (l2 a) -> PerWorkspace l1 l2 a
mkNewPerWorkspaceF (PerWorkspace [WorkspaceId]
wsIds Bool
_ l1 a
lt l2 a
lf) Maybe (l2 a)
mlf' =
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
forall (l1 :: * -> *) (l2 :: * -> *) a.
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
PerWorkspace [WorkspaceId]
wsIds Bool
False l1 a
lt (l2 a -> PerWorkspace l1 l2 a) -> l2 a -> PerWorkspace l1 l2 a
forall a b. (a -> b) -> a -> b
$ l2 a -> Maybe (l2 a) -> l2 a
forall a. a -> Maybe a -> a
fromMaybe l2 a
lf Maybe (l2 a)
mlf'