More predictable aspect ratio in GridVariants.Grid

The old version fairly arbitrarily decided to prefer windows that are too
high over those that are too wide.  The new version chooses the number of
columns so that all windows on the screen are as close as possible to the
desired aspect ratio.  As a side effect, the layout changes much more
predictably under addition and removal of clients.
This commit is contained in:
Norbert Zeh
2009-03-11 01:36:17 +00:00
parent e8d80d552c
commit ac8c6ab633

View File

@@ -135,8 +135,18 @@ arrangeAspectGrid :: Rectangle -> Int -> Rational -> [Rectangle]
arrangeAspectGrid rect@(Rectangle _ _ rw rh) nwins aspect =
arrangeGrid rect nwins (min nwins ncols)
where
ncols = ceiling $ sqrt $ ( fromRational
( (fromIntegral rw * fromIntegral nwins) / (fromIntegral rh * aspect) ) :: Double)
scr_a = fromIntegral rw / fromIntegral rh
fcols = sqrt ( fromRational $ scr_a * fromIntegral nwins / aspect ) :: Double
cols1 = floor fcols :: Int
cols2 = ceiling fcols :: Int
rows1 = ceiling ( fromIntegral nwins / fromIntegral cols1 :: Rational ) :: Int
rows2 = floor ( fromIntegral nwins / fromIntegral cols2 :: Rational ) :: Int
a1 = scr_a * fromIntegral rows1 / fromIntegral cols1
a2 = scr_a * fromIntegral rows2 / fromIntegral cols2
ncols | cols1 == 0 = cols2
| rows2 == 0 = cols1
| a1 / aspect < aspect / a2 = cols1
| otherwise = cols2
arrangeGrid :: Rectangle -> Int -> Int -> [Rectangle]
arrangeGrid (Rectangle rx ry rw rh) nwins ncols =