From f760f99b123921235507fbdf490f27eee1e1183c Mon Sep 17 00:00:00 2001 From: Clemens Fruhwirth Date: Sat, 16 Oct 2010 20:35:54 +0200 Subject: Refactor for ad-hoc element and position matching turning td_elementmap into a function using the new td_availSlot and td_elements fields Ignore-this: 85e644a27395e97315efd1ed7a926da8 darcs-hash:20101016183554-ed0c4-b06a89b9c704034777dfa622093d64d25ed507ab.gz --- XMonad/Actions/GridSelect.hs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'XMonad/Actions/GridSelect.hs') diff --git a/XMonad/Actions/GridSelect.hs b/XMonad/Actions/GridSelect.hs index ffcc664..f98c226 100644 --- a/XMonad/Actions/GridSelect.hs +++ b/XMonad/Actions/GridSelect.hs @@ -201,7 +201,8 @@ type TwoDPosition = (Integer, Integer) type TwoDElementMap a = [(TwoDPosition,(String,a))] data TwoDState a = TwoDState { td_curpos :: TwoDPosition - , td_elementmap :: TwoDElementMap a + , td_availSlots :: [TwoDPosition] + , td_elements :: [(String,a)] , td_gsconfig :: GSConfig a , td_font :: XMonadFont , td_paneX :: Integer @@ -209,6 +210,12 @@ data TwoDState a = TwoDState { td_curpos :: TwoDPosition , td_drawingWin :: Window } +td_elementmap :: TwoDState a -> [(TwoDPosition,(String,a))] +td_elementmap s = + let positions = td_availSlots s + elements = td_elements s + in zipWith (,) positions elements + newtype TwoD a b = TwoD { unTwoD :: StateT (TwoDState a) X b } deriving (Monad,Functor,MonadState (TwoDState a)) @@ -420,7 +427,7 @@ stringToRatio s = let gen = mkStdGen $ sum $ map fromEnum s -- select an element with cursors keys. The selected element is returned. gridselect :: GSConfig a -> [(String,a)] -> X (Maybe a) gridselect _ [] = return Nothing -gridselect gsconfig elmap = +gridselect gsconfig elements = withDisplay $ \dpy -> do rootw <- asks theRoot s <- gets $ screenRect . W.screenDetail . W.current . windowset @@ -440,10 +447,10 @@ gridselect gsconfig elmap = originPosX = floor $ ((gs_originFractX gsconfig) - (1/2)) * 2 * fromIntegral restrictX originPosY = floor $ ((gs_originFractY gsconfig) - (1/2)) * 2 * fromIntegral restrictY coords = diamondRestrict restrictX restrictY originPosX originPosY - elmap' = zip coords elmap evalTwoD (updateAllElements >> eventLoop) TwoDState { td_curpos = (head coords), - td_elementmap = elmap', + td_availSlots = coords, + td_elements = elements, td_gsconfig = gsconfig, td_font = font, td_paneX = screenWidth, -- cgit v1.2.3