TilePrime.hs: Correct behavior when number of windows <= nmaster

Additionally this patch does various clean-ups that should not
affect functionality.
This commit is contained in:
Eric Mertens
2007-10-17 20:51:53 +00:00
parent 3b71671751
commit fa81ef9e07

View File

@@ -21,7 +21,7 @@ module XMonadContrib.TilePrime (
) where ) where
import Control.Monad (mplus) import Control.Monad (mplus)
import Data.List (genericLength) import Data.List (mapAccumL)
import Graphics.X11.Xlib import Graphics.X11.Xlib
import Graphics.X11.Xlib.Extras (getWMNormalHints) import Graphics.X11.Xlib.Extras (getWMNormalHints)
import Operations import Operations
@@ -59,30 +59,29 @@ instance LayoutClass TilePrime Window where
resize Expand = c { frac = min 1 $ frac c + delta c } resize Expand = c { frac = min 1 $ frac c + delta c }
incmastern (IncMasterN d) = c { nmaster = max 0 $ nmaster c + d } incmastern (IncMasterN d) = c { nmaster = max 0 $ nmaster c + d }
doLayout c rect s = do doLayout TilePrime { frac = f, nmaster = m, flipped = flp } rect s = do
let flp = flipped c
let xs = W.integrate s let xs = W.integrate s
hints <- withDisplay $ \ disp -> io (mapM (getWMNormalHints disp) xs) hints <- withDisplay $ \ disp -> io (mapM (getWMNormalHints disp) xs)
let xs' = zip xs hints let xs' = zip xs hints
(leftRect, rightRect) (leftRect, rightRect)
| null (drop 1 xs) = (rect, Rectangle 0 0 0 0) | null (drop m xs) = (rect, Rectangle 0 0 0 0)
| flp = splitVerticallyBy (frac c) rect | flp = splitVerticallyBy f rect
| otherwise = splitHorizontallyBy (frac c) rect | otherwise = splitHorizontallyBy f rect
masters = fillWindows flp leftRect (take (nmaster c) xs') (leftXs, rightXs) = splitAt m xs'
slaves = fillWindows flp rightRect (drop (nmaster c) xs') masters = fillWindows leftRect leftXs
slaves = fillWindows rightRect rightXs
return (masters ++ slaves, Nothing) return (masters ++ slaves, Nothing)
where where
fillWindows r xs = snd $ mapAccumL aux (r,n) xs
where n = fromIntegral (length xs) :: Rational
fillWindows _ _ [] = [] aux (r,n) (x,hint) = ((rest,n-1),(x,r'))
fillWindows flp r ((x,hint):xs) = (x,r') : fillWindows flp rest xs
where where
n = 1 + genericLength xs :: Rational (allocated, _) | flp = splitHorizontallyBy (recip n) r
| otherwise = splitVerticallyBy (recip n) r
(alloca, _) | flp = splitHorizontallyBy (recip n) r (w,h) = applySizeHints hint `underBorders` rect_D allocated
| otherwise = splitVerticallyBy (recip n) r
(w,h) = applySizeHints hint `underBorders` (rect_width alloca, rect_height alloca)
r' = r { rect_width = w, rect_height = h } r' = r { rect_width = w, rect_height = h }
@@ -91,6 +90,9 @@ instance LayoutClass TilePrime Window where
| otherwise = r { rect_y = rect_y r + toEnum (fromEnum h) | otherwise = r { rect_y = rect_y r + toEnum (fromEnum h)
, rect_height = rect_height r - h } , rect_height = rect_height r - h }
rect_D :: Rectangle -> D
rect_D Rectangle { rect_width = w, rect_height = h } = (w,h)
-- | Transform a function on dimensions into one without regard for borders -- | Transform a function on dimensions into one without regard for borders
underBorders :: (D -> D) -> D -> D underBorders :: (D -> D) -> D -> D
underBorders f = adjBorders 1 . f . adjBorders (-1) underBorders f = adjBorders 1 . f . adjBorders (-1)