mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-08-06 23:11:54 -07:00
Grid/HintedGrid: use an ncolumns formula inspired by dwm's "optimal" mode
This commit is contained in:
@@ -46,7 +46,7 @@ arrange :: Rectangle -> [a] -> [(a, Rectangle)]
|
|||||||
arrange (Rectangle rx ry rw rh) st = zip st rectangles
|
arrange (Rectangle rx ry rw rh) st = zip st rectangles
|
||||||
where
|
where
|
||||||
nwins = length st
|
nwins = length st
|
||||||
ncols = ceiling . (sqrt :: Double -> Double) . fromIntegral $ nwins
|
ncols = max 1 . round . sqrt $ fromIntegral nwins * fromIntegral rw / (fromIntegral rh :: Double)
|
||||||
mincs = nwins `div` ncols
|
mincs = nwins `div` ncols
|
||||||
extrs = nwins - ncols * mincs
|
extrs = nwins - ncols * mincs
|
||||||
chop :: Int -> Dimension -> [(Position, Dimension)]
|
chop :: Int -> Dimension -> [(Position, Dimension)]
|
||||||
|
@@ -56,9 +56,6 @@ instance LayoutClass Grid Window where
|
|||||||
adjBorders :: Dimension -> D -> D
|
adjBorders :: Dimension -> D -> D
|
||||||
adjBorders b (w, h) = (w + 2 * b, h + 2 * b)
|
adjBorders b (w, h) = (w + 2 * b, h + 2 * b)
|
||||||
|
|
||||||
isqrt :: (Integral a) => a -> a
|
|
||||||
isqrt = ceiling . (sqrt :: Double -> Double) . fromIntegral
|
|
||||||
|
|
||||||
replicateS :: Int -> (a -> (b, a)) -> a -> ([b], a)
|
replicateS :: Int -> (a -> (b, a)) -> a -> ([b], a)
|
||||||
replicateS n = runState . replicateM n . State
|
replicateS n = runState . replicateM n . State
|
||||||
|
|
||||||
@@ -110,7 +107,7 @@ arrange' :: D -> [D -> D] -> [Rectangle]
|
|||||||
arrange' (rw, rh) adjs = reverse $ doRect rh rw (fromIntegral ncolumns) (ecols ++ cols)
|
arrange' (rw, rh) adjs = reverse $ doRect rh rw (fromIntegral ncolumns) (ecols ++ cols)
|
||||||
where
|
where
|
||||||
nwindows = length adjs
|
nwindows = length adjs
|
||||||
ncolumns = isqrt nwindows
|
ncolumns = max 1 . round . sqrt $ fromIntegral nwindows * fromIntegral rw / (fromIntegral rh :: Double)
|
||||||
nrows = nwindows `div` ncolumns
|
nrows = nwindows `div` ncolumns
|
||||||
nextras = nwindows - ncolumns * nrows
|
nextras = nwindows - ncolumns * nrows
|
||||||
(ecols, adjs') = replicateS nextras (splitAt (nrows + 1)) $ reverse adjs
|
(ecols, adjs') = replicateS nextras (splitAt (nrows + 1)) $ reverse adjs
|
||||||
|
Reference in New Issue
Block a user