From 4555e6e2f7f08941270c77b8e37b1af7a083c772 Mon Sep 17 00:00:00 2001 From: Norbert Zeh Date: Wed, 11 Mar 2009 02:36:17 +0100 Subject: 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. darcs-hash:20090311013617-18a2b-487e30d300b83871e572c4a535b4474b120accca.gz --- XMonad/Layout/GridVariants.hs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'XMonad') diff --git a/XMonad/Layout/GridVariants.hs b/XMonad/Layout/GridVariants.hs index 15fed70..2d47a5a 100644 --- a/XMonad/Layout/GridVariants.hs +++ b/XMonad/Layout/GridVariants.hs @@ -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 = -- cgit v1.2.3