From 5e0331117db3430beafafabe76f7a96f31ef2bf5 Mon Sep 17 00:00:00 2001 From: bobstopper Date: Sat, 21 Jul 2007 02:23:07 +0200 Subject: Made the direction of spiral in Spiral.hs optionally configurable darcs-hash:20070721002307-ee4f8-0d4e5abc504a5933c0840946a78cae1e768c1e23.gz --- Spiral.hs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'Spiral.hs') diff --git a/Spiral.hs b/Spiral.hs index 3d0ea1e..0e88b81 100644 --- a/Spiral.hs +++ b/Spiral.hs @@ -16,6 +16,9 @@ module XMonadContrib.Spiral ( -- * Usage -- $usage spiral + , spiralWithDir + , Rotation (..) + , Direction (..) ) where import Graphics.X11.Xlib @@ -43,7 +46,8 @@ mkRatios :: [Integer] -> [Rational] mkRatios (x1:x2:xs) = (x1 % x2) : mkRatios (x2:xs) mkRatios _ = [] -data Direction = East | South | West | North deriving (Enum) +data Rotation = CW | CCW +data Direction = East | South | West | North deriving (Eq, Enum) blend :: Rational -> [Rational] -> [Rational] blend scale ratios = zipWith (+) ratios scaleFactors @@ -53,13 +57,18 @@ blend scale ratios = zipWith (+) ratios scaleFactors scaleFactors = map (* step) . reverse . take len $ [0..] spiral :: Rational -> Layout a -spiral scale = Layout { doLayout = l2lModDo fibLayout, - modifyLayout = \m -> return $ fmap resize $ fromMessage m } +spiral = spiralWithDir East CW + +spiralWithDir :: Direction -> Rotation -> Rational -> Layout a +spiralWithDir dir rot scale = Layout { doLayout = l2lModDo fibLayout, + modifyLayout = \m -> return $ fmap resize $ fromMessage m } where fibLayout sc ws = zip ws rects where ratios = blend scale . reverse . take (length ws - 1) . mkRatios $ tail fibs - rects = divideRects (zip ratios (cycle [East .. North])) sc - + rects = divideRects (zip ratios dirs) sc + dirs = dropWhile (/= dir) $ case rot of + CW -> cycle [East .. North] + CCW -> cycle [North, West, South, East] resize Expand = spiral $ (21 % 20) * scale resize Shrink = spiral $ (20 % 21) * scale -- cgit v1.2.3