{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TupleSections #-}
module XMonad.Layout.Dishes (
Dishes (..)
) where
import XMonad
import XMonad.StackSet (integrate)
import XMonad.Prelude (ap)
data Dishes a = Dishes Int Rational deriving (Int -> Dishes a -> ShowS
forall a. Int -> Dishes a -> ShowS
forall a. [Dishes a] -> ShowS
forall a. Dishes a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Dishes a] -> ShowS
$cshowList :: forall a. [Dishes a] -> ShowS
show :: Dishes a -> String
$cshow :: forall a. Dishes a -> String
showsPrec :: Int -> Dishes a -> ShowS
$cshowsPrec :: forall a. Int -> Dishes a -> ShowS
Show, ReadPrec [Dishes a]
ReadPrec (Dishes a)
ReadS [Dishes a]
forall a. ReadPrec [Dishes a]
forall a. ReadPrec (Dishes a)
forall a. Int -> ReadS (Dishes a)
forall a. ReadS [Dishes a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Dishes a]
$creadListPrec :: forall a. ReadPrec [Dishes a]
readPrec :: ReadPrec (Dishes a)
$creadPrec :: forall a. ReadPrec (Dishes a)
readList :: ReadS [Dishes a]
$creadList :: forall a. ReadS [Dishes a]
readsPrec :: Int -> ReadS (Dishes a)
$creadsPrec :: forall a. Int -> ReadS (Dishes a)
Read)
instance LayoutClass Dishes a where
doLayout :: Dishes a
-> Rectangle -> Stack a -> X ([(a, Rectangle)], Maybe (Dishes a))
doLayout (Dishes Int
nmaster Rational
h) Rectangle
r =
forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. (, forall a. Maybe a
Nothing) forall b c a. (b -> c) -> (a -> b) -> a -> c
.
forall (m :: * -> *) a b. Monad m => m (a -> b) -> m a -> m b
ap forall a b. [a] -> [b] -> [(a, b)]
zip (Rational -> Rectangle -> Int -> Int -> [Rectangle]
dishes Rational
h Rectangle
r Int
nmaster forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Stack a -> [a]
integrate
pureMessage :: Dishes a -> SomeMessage -> Maybe (Dishes a)
pureMessage (Dishes Int
nmaster Rational
h) SomeMessage
m = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall {a}. IncMasterN -> Dishes a
incmastern (forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m)
where incmastern :: IncMasterN -> Dishes a
incmastern (IncMasterN Int
d) = forall a. Int -> Rational -> Dishes a
Dishes (forall a. Ord a => a -> a -> a
max Int
0 (Int
nmasterforall a. Num a => a -> a -> a
+Int
d)) Rational
h
dishes :: Rational -> Rectangle -> Int -> Int -> [Rectangle]
dishes :: Rational -> Rectangle -> Int -> Int -> [Rectangle]
dishes Rational
h Rectangle
s Int
nmaster Int
n = if Int
n forall a. Ord a => a -> a -> Bool
<= Int
nmaster
then Int -> Rectangle -> [Rectangle]
splitHorizontally Int
n Rectangle
s
else [Rectangle]
ws
where
(Rectangle
m,Rectangle
rest) = forall r. RealFrac r => r -> Rectangle -> (Rectangle, Rectangle)
splitVerticallyBy (Rational
1 forall a. Num a => a -> a -> a
- forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int
n forall a. Num a => a -> a -> a
- Int
nmaster) forall a. Num a => a -> a -> a
* Rational
h) Rectangle
s
ws :: [Rectangle]
ws = Int -> Rectangle -> [Rectangle]
splitHorizontally Int
nmaster Rectangle
m forall a. [a] -> [a] -> [a]
++ Int -> Rectangle -> [Rectangle]
splitVertically (Int
n forall a. Num a => a -> a -> a
- Int
nmaster) Rectangle
rest