{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TupleSections #-}
module XMonad.Layout.Square (
Square(..) ) where
import XMonad
import XMonad.StackSet ( integrate )
data Square a = Square deriving ( ReadPrec [Square a]
ReadPrec (Square a)
ReadS [Square a]
forall a. ReadPrec [Square a]
forall a. ReadPrec (Square a)
forall a. Int -> ReadS (Square a)
forall a. ReadS [Square a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Square a]
$creadListPrec :: forall a. ReadPrec [Square a]
readPrec :: ReadPrec (Square a)
$creadPrec :: forall a. ReadPrec (Square a)
readList :: ReadS [Square a]
$creadList :: forall a. ReadS [Square a]
readsPrec :: Int -> ReadS (Square a)
$creadsPrec :: forall a. Int -> ReadS (Square a)
Read, Int -> Square a -> ShowS
forall a. Int -> Square a -> ShowS
forall a. [Square a] -> ShowS
forall a. Square a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Square a] -> ShowS
$cshowList :: forall a. [Square a] -> ShowS
show :: Square a -> String
$cshow :: forall a. Square a -> String
showsPrec :: Int -> Square a -> ShowS
$cshowsPrec :: forall a. Int -> Square a -> ShowS
Show )
instance LayoutClass Square a where
pureLayout :: Square a -> Rectangle -> Stack a -> [(a, Rectangle)]
pureLayout Square a
Square Rectangle
r Stack a
s = forall {a}. [a] -> [(a, Rectangle)]
arrange (forall a. Stack a -> [a]
integrate Stack a
s)
where arrange :: [a] -> [(a, Rectangle)]
arrange ws :: [a]
ws@(a
_:[a]
_) = forall a b. (a -> b) -> [a] -> [b]
map (, Rectangle
rest) (forall a. [a] -> [a]
init [a]
ws) forall a. [a] -> [a] -> [a]
++ [(forall a. [a] -> a
last [a]
ws,Rectangle
sq)]
arrange [] = []
(Rectangle
rest, Rectangle
sq) = Rectangle -> (Rectangle, Rectangle)
splitSquare Rectangle
r
splitSquare :: Rectangle -> (Rectangle, Rectangle)
splitSquare :: Rectangle -> (Rectangle, Rectangle)
splitSquare (Rectangle Position
x Position
y Dimension
w Dimension
h)
| Dimension
w forall a. Ord a => a -> a -> Bool
> Dimension
h = (Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x Position
y (Dimension
w forall a. Num a => a -> a -> a
- Dimension
h) Dimension
h, Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle (Position
xforall a. Num a => a -> a -> a
+forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
wforall a. Num a => a -> a -> a
-Dimension
h)) Position
y Dimension
h Dimension
h)
| Bool
otherwise = (Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x Position
y Dimension
w (Dimension
hforall a. Num a => a -> a -> a
-Dimension
w), Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x (Position
yforall a. Num a => a -> a -> a
+forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
hforall a. Num a => a -> a -> a
-Dimension
w)) Dimension
w Dimension
w)