mirror of
https://github.com/xmonad/xmonad.git
synced 2025-08-17 04:43:47 -07:00
beautify tile
This commit is contained in:
@@ -108,7 +108,7 @@ full = Layout { doLayout = \sc ws -> return [ (w,sc) | w <- ws ]
|
|||||||
tall, wide :: Rational -> Rational -> Layout
|
tall, wide :: Rational -> Rational -> Layout
|
||||||
wide delta frac = mirrorLayout (tall delta frac)
|
wide delta frac = mirrorLayout (tall delta frac)
|
||||||
|
|
||||||
tall delta frac = Layout { doLayout = \a b -> return $ tile frac a b
|
tall delta frac = Layout { doLayout = \r w -> return $ zip w $ tile frac r (length w)
|
||||||
, modifyLayout = fmap handler . fromMessage }
|
, modifyLayout = fmap handler . fromMessage }
|
||||||
|
|
||||||
where handler s = tall delta $ (case s of
|
where handler s = tall delta $ (case s of
|
||||||
@@ -131,16 +131,23 @@ mirrorLayout (Layout { doLayout = dl, modifyLayout = ml }) =
|
|||||||
-- * no windows overlap
|
-- * no windows overlap
|
||||||
-- * no gaps exist between windows.
|
-- * no gaps exist between windows.
|
||||||
--
|
--
|
||||||
tile :: Rational -> Rectangle -> [Window] -> [(Window, Rectangle)]
|
tile :: Rational -> Rectangle -> Int -> [Rectangle]
|
||||||
tile _ _ [] = []
|
tile _ d n | n < 2 = [d]
|
||||||
tile _ d [w] = [(w, d)]
|
tile f r n = r1 : split_vertically (n-1) r2
|
||||||
tile r (Rectangle sx sy sw sh) (w:s) =
|
where (r1,r2) = split_horizontally_by f r
|
||||||
(w, Rectangle sx sy (fromIntegral lw) sh) : zipWith f [sy, sy + rh ..] s
|
|
||||||
where
|
split_vertically, split_horizontally :: Int -> Rectangle -> [Rectangle]
|
||||||
lw = floor $ fromIntegral sw * r
|
split_vertically n r | n < 2 = [r]
|
||||||
rw = sw - fromIntegral lw
|
split_vertically n (Rectangle sx sy sw sh) = Rectangle sx sy sw smallh :
|
||||||
rh = fromIntegral sh `div` fromIntegral (length s)
|
split_vertically (n-1) (Rectangle sx (sy+fromIntegral smallh) sw (sh-smallh))
|
||||||
f i a = (a, Rectangle (sx + lw) i rw (fromIntegral rh))
|
where smallh = sh `div` fromIntegral n
|
||||||
|
split_horizontally n r = map mirrorRect $ split_vertically n $ mirrorRect r
|
||||||
|
|
||||||
|
split_horizontally_by, split_vertically_by :: Rational -> Rectangle -> (Rectangle, Rectangle)
|
||||||
|
split_horizontally_by f (Rectangle sx sy sw sh) =
|
||||||
|
(Rectangle sx sy leftw sh, Rectangle (sx + fromIntegral leftw) sy (sw-fromIntegral leftw) sh)
|
||||||
|
where leftw = floor $ fromIntegral sw * f
|
||||||
|
split_vertically_by f r = (\(a,b)->(mirrorRect a,mirrorRect b)) $ split_horizontally_by f $ mirrorRect r
|
||||||
|
|
||||||
------------------------------------------------------------------------
|
------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@@ -265,7 +265,7 @@ prop_push_local (x :: T) i = not (member i x) ==> hidden x == hidden (push i x)
|
|||||||
-- some properties for layouts:
|
-- some properties for layouts:
|
||||||
|
|
||||||
-- 1 window should always be tiled fullscreen
|
-- 1 window should always be tiled fullscreen
|
||||||
prop_tile_fullscreen rect = tile pct rect [1] == [(1, rect)]
|
prop_tile_fullscreen rect = tile pct rect 1 == [rect]
|
||||||
|
|
||||||
-- multiple windows
|
-- multiple windows
|
||||||
prop_tile_non_overlap rect windows = noOverlaps (tile pct rect windows)
|
prop_tile_non_overlap rect windows = noOverlaps (tile pct rect windows)
|
||||||
@@ -276,8 +276,8 @@ pct = 3 % 100
|
|||||||
noOverlaps [] = True
|
noOverlaps [] = True
|
||||||
noOverlaps [_] = True
|
noOverlaps [_] = True
|
||||||
noOverlaps xs = and [ verts a `notOverlap` verts b
|
noOverlaps xs = and [ verts a `notOverlap` verts b
|
||||||
| (_,a) <- xs
|
| a <- xs
|
||||||
, (_,b) <- filter (\(_,b) -> a /= b) xs
|
, b <- filter (a /=) xs
|
||||||
]
|
]
|
||||||
where
|
where
|
||||||
verts (Rectangle a b w h) = (a,b,a + fromIntegral w - 1, b + fromIntegral h - 1)
|
verts (Rectangle a b w h) = (a,b,a + fromIntegral w - 1, b + fromIntegral h - 1)
|
||||||
|
Reference in New Issue
Block a user