From 577a6c9b6654cf2e3007bce0fa56334e45be06b1 Mon Sep 17 00:00:00 2001 From: daniel Date: Mon, 22 Sep 2008 03:09:50 +0200 Subject: let Grid have a configurable aspect ratio goal darcs-hash:20080922010950-c98ca-2077ed7e1b481c7849d7501ff4435d9a3fabdde9.gz --- XMonad/Layout/Grid.hs | 21 +++++++++++++++------ XMonad/Layout/IM.hs | 4 ++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/XMonad/Layout/Grid.hs b/XMonad/Layout/Grid.hs index 33c4461..09de582 100644 --- a/XMonad/Layout/Grid.hs +++ b/XMonad/Layout/Grid.hs @@ -17,7 +17,7 @@ module XMonad.Layout.Grid ( -- * Usage -- $usage - Grid(..), arrange + Grid(..), arrange, defaultRatio ) where import XMonad @@ -33,20 +33,29 @@ import XMonad.StackSet -- > myLayouts = Grid ||| Full ||| etc.. -- > main = xmonad defaultConfig { layoutHook = myLayouts } -- +-- You can also specify an aspect ratio for Grid to strive for with the +-- GridRatio constructor: +-- +-- > myLayouts = GridRatio (3/4) ||| etc. +-- -- For more detailed instructions on editing the layoutHook see: -- -- "XMonad.Doc.Extending#Editing_the_layout_hook" -data Grid a = Grid deriving (Read, Show) +data Grid a = Grid | GridRatio Double deriving (Read, Show) + +defaultRatio :: Double +defaultRatio = 9/16 instance LayoutClass Grid a where - pureLayout Grid r s = arrange r (integrate s) + pureLayout Grid r = pureLayout (GridRatio defaultRatio) r + pureLayout (GridRatio d) r = arrange d r . integrate -arrange :: Rectangle -> [a] -> [(a, Rectangle)] -arrange (Rectangle rx ry rw rh) st = zip st rectangles +arrange :: Double -> Rectangle -> [a] -> [(a, Rectangle)] +arrange aspectRatio (Rectangle rx ry rw rh) st = zip st rectangles where nwins = length st - ncols = max 1 . round . sqrt $ fromIntegral nwins * 9 * fromIntegral rw / (16 * fromIntegral rh :: Double) + ncols = max 1 . round . sqrt $ aspectRatio * fromIntegral nwins * fromIntegral rw / fromIntegral rh mincs = nwins `div` ncols extrs = nwins - ncols * mincs chop :: Int -> Dimension -> [(Position, Dimension)] diff --git a/XMonad/Layout/IM.hs b/XMonad/Layout/IM.hs index 0f45d35..ba342d3 100644 --- a/XMonad/Layout/IM.hs +++ b/XMonad/Layout/IM.hs @@ -122,6 +122,6 @@ instance LayoutClass IM Window where let (masterRect, slaveRect) = splitHorizontallyBy r rect master <- findM (hasProperty prop) ws let positions = case master of - Just w -> (w, masterRect) : arrange slaveRect (filter (w /=) ws) - Nothing -> arrange rect ws + Just w -> (w, masterRect) : arrange defaultRatio slaveRect (filter (w /=) ws) + Nothing -> arrange defaultRatio rect ws return (positions, Nothing) -- cgit v1.2.3