aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNorbert Zeh <nzeh@cs.dal.ca>2009-03-11 02:36:17 +0100
committerNorbert Zeh <nzeh@cs.dal.ca>2009-03-11 02:36:17 +0100
commit4555e6e2f7f08941270c77b8e37b1af7a083c772 (patch)
tree9e8306ea23362efd3b266720a218689da1518dac
parent19f3604c0b6cf621ce96201a2290d6e5f200f55a (diff)
downloadXMonadContrib-4555e6e2f7f08941270c77b8e37b1af7a083c772.tar.gz
XMonadContrib-4555e6e2f7f08941270c77b8e37b1af7a083c772.tar.xz
XMonadContrib-4555e6e2f7f08941270c77b8e37b1af7a083c772.zip
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
-rw-r--r--XMonad/Layout/GridVariants.hs14
1 files changed, 12 insertions, 2 deletions
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 =