{-# 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 :: forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
WorkspaceId -> l1 a -> l2 a -> PerWorkspace l1 l2 a
onWorkspace WorkspaceId
wsId = 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 :: forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
[WorkspaceId] -> l1 a -> l2 a -> PerWorkspace l1 l2 a
onWorkspaces [WorkspaceId]
wsIds = forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
[WorkspaceId] -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
modWorkspaces [WorkspaceId]
wsIds forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 :: forall (l1 :: * -> *) a (l2 :: * -> *).
(LayoutClass l1 a, LayoutClass l2 a) =>
WorkspaceId -> (l2 a -> l1 a) -> l2 a -> PerWorkspace l1 l2 a
modWorkspace WorkspaceId
wsId = 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 :: 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
f l2 a
l = 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)
ReadS [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
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 forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [WorkspaceId]
wsIds = do ([(a, Rectangle)]
wrs, Maybe (l1 a)
mlt') <- forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace WorkspaceId (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout (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
forall (m :: * -> *) a. Monad m => a -> m a
return ([(a, Rectangle)]
wrs, forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ 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') <- forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace WorkspaceId (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout (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
forall (m :: * -> *) a. Monad m => a -> m a
return ([(a, Rectangle)]
wrs, forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ 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 = forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l1 a
lt SomeMessage
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) (\l1 a
nt -> forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ 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 = forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> SomeMessage -> X (Maybe (layout a))
handleMessage l2 a
lf SomeMessage
m forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing) (forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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
_) = forall (layout :: * -> *) a.
LayoutClass layout a =>
layout a -> WorkspaceId
description l1 a
l1
description (PerWorkspace [WorkspaceId]
_ Bool
_ l1 a
_ l2 a
l2) = 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 :: forall (l1 :: * -> *) (l2 :: * -> *) a.
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' -> 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) forall a b. (a -> b) -> a -> b
$ 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 :: forall (l1 :: * -> *) (l2 :: * -> *) a.
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' =
forall (l1 :: * -> *) (l2 :: * -> *) a.
[WorkspaceId] -> Bool -> l1 a -> l2 a -> PerWorkspace l1 l2 a
PerWorkspace [WorkspaceId]
wsIds Bool
False l1 a
lt forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a -> a
fromMaybe l2 a
lf Maybe (l2 a)
mlf'