X.A.WindowNavigation: add logHook for better state tracking

This commit is contained in:
Devin Mullins 2008-05-25 03:23:25 +00:00
parent f13c352bff
commit 8bec9a32e1

View File

@ -45,9 +45,9 @@ import Graphics.X11.Xlib
-- Don't use it! What, are you crazy? -- Don't use it! What, are you crazy?
-- TODO: -- TODO:
-- - logHook? (2+1, start at master, j,j,a)
-- - cleanup (including inr)
-- - documentation :) -- - documentation :)
-- - monad for WNState?
-- - cleanup (including inr)
-- - tests? (esp. for edge cases in currentPosition) -- - tests? (esp. for edge cases in currentPosition)
-- - solve the 2+3, middle right to bottom left problem -- - solve the 2+3, middle right to bottom left problem
-- - manageHook to draw window decos? -- - manageHook to draw window decos?
@ -68,7 +68,8 @@ withWindowNavigationKeys :: [((KeyMask, KeySym), WNAction)] -> XConfig l -> IO (
withWindowNavigationKeys wnKeys conf = do withWindowNavigationKeys wnKeys conf = do
posRef <- newIORef M.empty posRef <- newIORef M.empty
return conf { keys = \cnf -> M.fromList (map (second (fromWNAction posRef)) wnKeys) return conf { keys = \cnf -> M.fromList (map (second (fromWNAction posRef)) wnKeys)
`M.union` keys conf cnf } `M.union` keys conf cnf,
logHook = logHook conf >> trackMovement posRef }
where fromWNAction posRef (WNGo dir) = go posRef dir where fromWNAction posRef (WNGo dir) = go posRef dir
fromWNAction posRef (WNSwap dir) = swap posRef dir fromWNAction posRef (WNSwap dir) = swap posRef dir
@ -97,13 +98,19 @@ swap = withTargetWindow swapWithFocused
swapWin win1 win2 win = if win == win1 then win2 else if win == win2 then win1 else win swapWin win1 win2 win = if win == win1 then win2 else if win == win2 then win1 else win
withTargetWindow :: (Window -> WindowSet -> WindowSet) -> IORef WNState -> Direction -> X () withTargetWindow :: (Window -> WindowSet -> WindowSet) -> IORef WNState -> Direction -> X ()
withTargetWindow adj posRef dir = fromCurrentPoint $ \win pos -> do withTargetWindow adj posRef dir = fromCurrentPoint posRef $ \win pos -> do
targets <- filter ((/= win) . fst) <$> navigableTargets pos dir targets <- filter ((/= win) . fst) <$> navigableTargets pos dir
whenJust (listToMaybe targets) $ \(targetWin, targetRect) -> do whenJust (listToMaybe targets) $ \(targetWin, targetRect) -> do
windows (adj targetWin) windows (adj targetWin)
setPosition posRef pos targetRect setPosition posRef pos targetRect
where fromCurrentPoint f = withFocused $ \win -> do
currentPosition posRef >>= f win trackMovement :: IORef WNState -> X ()
trackMovement posRef = fromCurrentPoint posRef $ \win pos -> do
windowRect win >>= flip whenJust (setPosition posRef pos . snd)
fromCurrentPoint :: IORef WNState -> (Window -> Point -> X ()) -> X ()
fromCurrentPoint posRef f = withFocused $ \win -> do
currentPosition posRef >>= f win
-- Gets the current position from the IORef passed in, or if nothing (say, from -- Gets the current position from the IORef passed in, or if nothing (say, from
-- a restart), derives the current position from the current window. Also, -- a restart), derives the current position from the current window. Also,