[xmonad] darcs patch: Column layout
Adam Vogt
vogt.adam at gmail.com
Wed Jun 17 01:38:54 EDT 2009
Hello Ilya,
I have a couple small suggestions inline below, send another patch fixing
these things, and I'll apply it:
* On Saturday, June 06 2009, portnov wrote:
[..]
>+-- $usage
>+-- This module defines layot named Column. It places all windows in one
s/layot/layout/
>+-- column. Windows heights are calculated from equation: H1/H2 = H2/H3 = ... =
>+-- q, where `q' is given (thus, windows heights are members of geometric
>+-- progression). With Shrink/Expand messages one can change the `q' value.
[..]
>+columnMessage :: Column a -> SomeMessage -> Maybe (Column a)
>+columnMessage (Column q) m = fmap resize (fromMessage m)
>+ where resize Shrink = Column (q-0.1)
>+ resize Expand = Column (q+0.1)
Perhaps the 0.1 should be an additional parameter to Column? In many cases
I noticed that the step between Expand messages was too small.
>+columnLayout :: Column a -> Rectangle -> W.Stack a -> [(a,Rectangle)]
>+columnLayout (Column q) rect stack = zip ws rects
>+ where ws = W.integrate stack
>+ n = length ws
>+ heights = map (xn n rect q) [1..n]
>+ ys = [fromIntegral $ sum $ take k heights | k <- [0..n-1]]
>+ rects = map (mkRect rect) $ zip heights ys
>+
>+mkRect :: Rectangle -> (Dimension,Position) -> Rectangle
>+mkRect (Rectangle xs ys ws _) (h,y) = Rectangle xs (ys+fromIntegral y) ws h
>+
>+xn :: Int -> Rectangle -> Float -> Int -> Dimension
>+xn n (Rectangle _ _ _ h) q k = if q==1 then
>+ h `div` (fromIntegral n)
>+ else
>+ round ((fromIntegral h)*q^(n-k)*(1-q)/(1-q^n))
I got some strange behavior (windows given rectangles larger than my
screen) when q <= 0, I'm not sure whether it is reasonable to clamp the q
value at 0.05 or something.
I think the algorithm for the list of heights might be clearer as follows
(untested):
> heights h n q = correct $ map (round . (*fromIntegral h)) $ normalize
> $ take n $ iterate (/q) 1
> where normalize x = let s = sum x in map (/ s) x
> correct (x:xs) = (h - sum xs) : xs
> correct _ = []
Thanks,
Adam
More information about the xmonad
mailing list