{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.TwoPanePersistent
(
TwoPanePersistent(..)
) where
import XMonad.StackSet (focus, up, down, Stack, Stack(..))
import XMonad hiding (focus)
data TwoPanePersistent a = TwoPanePersistent
{ TwoPanePersistent a -> Maybe a
slaveWin :: Maybe a
, TwoPanePersistent a -> Rational
dFrac :: Rational
, TwoPanePersistent a -> Rational
mFrac :: Rational
} deriving (Int -> TwoPanePersistent a -> ShowS
[TwoPanePersistent a] -> ShowS
TwoPanePersistent a -> String
(Int -> TwoPanePersistent a -> ShowS)
-> (TwoPanePersistent a -> String)
-> ([TwoPanePersistent a] -> ShowS)
-> Show (TwoPanePersistent a)
forall a. Show a => Int -> TwoPanePersistent a -> ShowS
forall a. Show a => [TwoPanePersistent a] -> ShowS
forall a. Show a => TwoPanePersistent a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TwoPanePersistent a] -> ShowS
$cshowList :: forall a. Show a => [TwoPanePersistent a] -> ShowS
show :: TwoPanePersistent a -> String
$cshow :: forall a. Show a => TwoPanePersistent a -> String
showsPrec :: Int -> TwoPanePersistent a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> TwoPanePersistent a -> ShowS
Show, ReadPrec [TwoPanePersistent a]
ReadPrec (TwoPanePersistent a)
Int -> ReadS (TwoPanePersistent a)
ReadS [TwoPanePersistent a]
(Int -> ReadS (TwoPanePersistent a))
-> ReadS [TwoPanePersistent a]
-> ReadPrec (TwoPanePersistent a)
-> ReadPrec [TwoPanePersistent a]
-> Read (TwoPanePersistent a)
forall a. Read a => ReadPrec [TwoPanePersistent a]
forall a. Read a => ReadPrec (TwoPanePersistent a)
forall a. Read a => Int -> ReadS (TwoPanePersistent a)
forall a. Read a => ReadS [TwoPanePersistent a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [TwoPanePersistent a]
$creadListPrec :: forall a. Read a => ReadPrec [TwoPanePersistent a]
readPrec :: ReadPrec (TwoPanePersistent a)
$creadPrec :: forall a. Read a => ReadPrec (TwoPanePersistent a)
readList :: ReadS [TwoPanePersistent a]
$creadList :: forall a. Read a => ReadS [TwoPanePersistent a]
readsPrec :: Int -> ReadS (TwoPanePersistent a)
$creadsPrec :: forall a. Read a => Int -> ReadS (TwoPanePersistent a)
Read)
instance (Show a, Eq a) => LayoutClass TwoPanePersistent a where
doLayout :: TwoPanePersistent a
-> Rectangle
-> Stack a
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a))
doLayout TwoPanePersistent a
l Rectangle
r Stack a
s =
case [a] -> [a]
forall a. [a] -> [a]
reverse (Stack a -> [a]
forall a. Stack a -> [a]
up Stack a
s) of
[] -> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a))
forall (m :: * -> *) a. Monad m => a -> m a
return (([(a, Rectangle)], Maybe (TwoPanePersistent a))
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a)))
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a))
forall a b. (a -> b) -> a -> b
$ TwoPanePersistent a
-> Stack a
-> Rectangle
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
forall a.
Eq a =>
TwoPanePersistent a
-> Stack a
-> Rectangle
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
focusedMaster TwoPanePersistent a
l Stack a
s Rectangle
r
(a
master:[a]
_) -> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a))
forall (m :: * -> *) a. Monad m => a -> m a
return (([(a, Rectangle)], Maybe (TwoPanePersistent a))
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a)))
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
-> X ([(a, Rectangle)], Maybe (TwoPanePersistent a))
forall a b. (a -> b) -> a -> b
$ TwoPanePersistent a
-> Stack a
-> Rectangle
-> a
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
forall a.
TwoPanePersistent a
-> Stack a
-> Rectangle
-> a
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
focusedSlave TwoPanePersistent a
l Stack a
s Rectangle
r a
master
pureMessage :: TwoPanePersistent a -> SomeMessage -> Maybe (TwoPanePersistent a)
pureMessage (TwoPanePersistent Maybe a
w Rational
delta Rational
split) SomeMessage
x =
case SomeMessage -> Maybe Resize
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
x of
Just Resize
Shrink -> TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a. a -> Maybe a
Just (Maybe a -> Rational -> Rational -> TwoPanePersistent a
forall a. Maybe a -> Rational -> Rational -> TwoPanePersistent a
TwoPanePersistent Maybe a
w Rational
delta (Rational
split Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
- Rational
delta))
Just Resize
Expand -> TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a. a -> Maybe a
Just (Maybe a -> Rational -> Rational -> TwoPanePersistent a
forall a. Maybe a -> Rational -> Rational -> TwoPanePersistent a
TwoPanePersistent Maybe a
w Rational
delta (Rational
split Rational -> Rational -> Rational
forall a. Num a => a -> a -> a
+ Rational
delta))
Maybe Resize
_ -> Maybe (TwoPanePersistent a)
forall a. Maybe a
Nothing
description :: TwoPanePersistent a -> String
description TwoPanePersistent a
_ = String
"TwoPanePersistent"
focusedMaster :: (Eq a) => TwoPanePersistent a -> Stack a -> Rectangle
-> ( [(a, Rectangle)], Maybe (TwoPanePersistent a) )
focusedMaster :: TwoPanePersistent a
-> Stack a
-> Rectangle
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
focusedMaster (TwoPanePersistent Maybe a
w Rational
delta Rational
split) Stack a
s Rectangle
r =
let (Rectangle
left, Rectangle
right) = Rational -> Rectangle -> (Rectangle, Rectangle)
forall r. RealFrac r => r -> Rectangle -> (Rectangle, Rectangle)
splitHorizontallyBy Rational
split Rectangle
r in
case Stack a -> [a]
forall a. Stack a -> [a]
down Stack a
s of
(a
next:[a]
_) -> let nextSlave :: ([(a, Rectangle)], Maybe (TwoPanePersistent a))
nextSlave = ( [(Stack a -> a
forall a. Stack a -> a
focus Stack a
s, Rectangle
left), (a
next, Rectangle
right)]
, TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a. a -> Maybe a
Just (TwoPanePersistent a -> Maybe (TwoPanePersistent a))
-> TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a b. (a -> b) -> a -> b
$ Maybe a -> Rational -> Rational -> TwoPanePersistent a
forall a. Maybe a -> Rational -> Rational -> TwoPanePersistent a
TwoPanePersistent (a -> Maybe a
forall a. a -> Maybe a
Just a
next) Rational
delta Rational
split )
in case Maybe a
w of
Just a
win -> if a
win a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` Stack a -> [a]
forall a. Stack a -> [a]
down Stack a
s Bool -> Bool -> Bool
&& (Stack a -> a
forall a. Stack a -> a
focus Stack a
s a -> a -> Bool
forall a. Eq a => a -> a -> Bool
/= a
win)
then ( [(Stack a -> a
forall a. Stack a -> a
focus Stack a
s, Rectangle
left), (a
win, Rectangle
right)]
, TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a. a -> Maybe a
Just (TwoPanePersistent a -> Maybe (TwoPanePersistent a))
-> TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a b. (a -> b) -> a -> b
$ Maybe a -> Rational -> Rational -> TwoPanePersistent a
forall a. Maybe a -> Rational -> Rational -> TwoPanePersistent a
TwoPanePersistent Maybe a
w Rational
delta Rational
split )
else ([(a, Rectangle)], Maybe (TwoPanePersistent a))
nextSlave
Maybe a
Nothing -> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
nextSlave
[] -> ( [(Stack a -> a
forall a. Stack a -> a
focus Stack a
s, Rectangle
r)]
, TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a. a -> Maybe a
Just (TwoPanePersistent a -> Maybe (TwoPanePersistent a))
-> TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a b. (a -> b) -> a -> b
$ Maybe a -> Rational -> Rational -> TwoPanePersistent a
forall a. Maybe a -> Rational -> Rational -> TwoPanePersistent a
TwoPanePersistent Maybe a
forall a. Maybe a
Nothing Rational
delta Rational
split )
focusedSlave :: TwoPanePersistent a -> Stack a -> Rectangle -> a
-> ( [(a, Rectangle)], Maybe (TwoPanePersistent a) )
focusedSlave :: TwoPanePersistent a
-> Stack a
-> Rectangle
-> a
-> ([(a, Rectangle)], Maybe (TwoPanePersistent a))
focusedSlave (TwoPanePersistent Maybe a
_ Rational
delta Rational
split) Stack a
s Rectangle
r a
m =
( [(a
m, Rectangle
left), (Stack a -> a
forall a. Stack a -> a
focus Stack a
s, Rectangle
right)]
, TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a. a -> Maybe a
Just (TwoPanePersistent a -> Maybe (TwoPanePersistent a))
-> TwoPanePersistent a -> Maybe (TwoPanePersistent a)
forall a b. (a -> b) -> a -> b
$ Maybe a -> Rational -> Rational -> TwoPanePersistent a
forall a. Maybe a -> Rational -> Rational -> TwoPanePersistent a
TwoPanePersistent (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> a -> Maybe a
forall a b. (a -> b) -> a -> b
$ Stack a -> a
forall a. Stack a -> a
focus Stack a
s) Rational
delta Rational
split )
where (Rectangle
left, Rectangle
right) = Rational -> Rectangle -> (Rectangle, Rectangle)
forall r. RealFrac r => r -> Rectangle -> (Rectangle, Rectangle)
splitHorizontallyBy Rational
split Rectangle
r