{-# 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)
Int -> ReadS (Square a)
ReadS [Square a]
(Int -> ReadS (Square a))
-> ReadS [Square a]
-> ReadPrec (Square a)
-> ReadPrec [Square a]
-> Read (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
$creadsPrec :: forall a. Int -> ReadS (Square a)
readsPrec :: Int -> ReadS (Square a)
$creadList :: forall a. ReadS [Square a]
readList :: ReadS [Square a]
$creadPrec :: forall a. ReadPrec (Square a)
readPrec :: ReadPrec (Square a)
$creadListPrec :: forall a. ReadPrec [Square a]
readListPrec :: ReadPrec [Square a]
Read, Int -> Square a -> ShowS
[Square a] -> ShowS
Square a -> String
(Int -> Square a -> ShowS)
-> (Square a -> String) -> ([Square a] -> ShowS) -> Show (Square a)
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
$cshowsPrec :: forall a. Int -> Square a -> ShowS
showsPrec :: Int -> Square a -> ShowS
$cshow :: forall a. Square a -> String
show :: Square a -> String
$cshowList :: forall a. [Square a] -> ShowS
showList :: [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 = [a] -> [(a, Rectangle)]
forall {a}. [a] -> [(a, Rectangle)]
arrange (Stack a -> [a]
forall a. Stack a -> [a]
integrate Stack a
s)
where arrange :: [a] -> [(a, Rectangle)]
arrange ws :: [a]
ws@(a
_:[a]
_) = (a -> (a, Rectangle)) -> [a] -> [(a, Rectangle)]
forall a b. (a -> b) -> [a] -> [b]
map (, Rectangle
rest) ([a] -> [a]
forall a. HasCallStack => [a] -> [a]
init [a]
ws) [(a, Rectangle)] -> [(a, Rectangle)] -> [(a, Rectangle)]
forall a. [a] -> [a] -> [a]
++ [([a] -> a
forall a. HasCallStack => [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 Dimension -> Dimension -> Bool
forall a. Ord a => a -> a -> Bool
> Dimension
h = (Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x Position
y (Dimension
w Dimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
- Dimension
h) Dimension
h, Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle (Position
xPosition -> Position -> Position
forall a. Num a => a -> a -> a
+Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
wDimension -> Dimension -> Dimension
forall 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
hDimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
-Dimension
w), Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x (Position
yPosition -> Position -> Position
forall a. Num a => a -> a -> a
+Dimension -> Position
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Dimension
hDimension -> Dimension -> Dimension
forall a. Num a => a -> a -> a
-Dimension
w)) Dimension
w Dimension
w)