From bd4f72d6e453aa7dee2f8f9470f2f71af1667a92 Mon Sep 17 00:00:00 2001 From: Ian Zerny Date: Sat, 5 Apr 2008 20:29:00 +0200 Subject: Added next-window versions of the raise* functions. darcs-hash:20080405182900-ba7e7-6871a7f6ac9155c062c152c3c902c895ab9aa94b.gz --- XMonad/Actions/WindowGo.hs | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'XMonad/Actions/WindowGo.hs') diff --git a/XMonad/Actions/WindowGo.hs b/XMonad/Actions/WindowGo.hs index 8bcedb4..e5e70e0 100644 --- a/XMonad/Actions/WindowGo.hs +++ b/XMonad/Actions/WindowGo.hs @@ -16,8 +16,11 @@ module XMonad.Actions.WindowGo ( -- * Usage -- $usage raise, + raiseNext, runOrRaise, + runOrRaiseNext, raiseMaybe, + raiseNextMaybe, raiseBrowser, raiseEditor, @@ -30,7 +33,7 @@ import Data.Char (toLower) import XMonad (Query(), X(), withWindowSet, spawn, runQuery, liftIO, focus) import XMonad.ManageHook import XMonad.Prompt.Shell (getBrowser, getEditor) -import qualified XMonad.StackSet as W (allWindows) +import qualified XMonad.StackSet as W (allWindows, peek) {- $usage @@ -93,6 +96,33 @@ raiseMaybe f thatUserQuery = withWindowSet $ \s -> do [] -> f (x:_) -> focus x +-- | See 'runOrRaise' and 'raiseNextMaybe'. Version that allows cycling through matches. +runOrRaiseNext :: String -> Query Bool -> X () +runOrRaiseNext action = raiseNextMaybe $ spawn action + +-- | See 'raise' and 'raiseNextMaybe'. Version that allows cycling through matches. +raiseNext :: Query Bool -> X () +raiseNext = raiseNextMaybe $ return () + +{- | See 'raiseMaybe'. + 'raiseNextMaybe' is an alternative version that allows cycling + through the matching windows. If the focused window matches the + query the next matching window is raised. If no matches are found + the function f is executed. +-} +raiseNextMaybe :: X () -> Query Bool -> X () +raiseNextMaybe f thatUserQuery = withWindowSet $ \s -> do + ws <- filterM (runQuery thatUserQuery) (W.allWindows s) + case ws of + [] -> f + (x:_) -> let go (Just w) | (w `elem` ws) = next w $ cycle ws + go _ = focus x + in go $ W.peek s + where + next w (x:y:_) | x==w = focus y + next w (_:xs) = next w xs + next _ _ = error "raiseNextMaybe: empty list" + -- | Given a function which gets us a String, we try to raise a window with that classname, -- or we then interpret that String as a executable name. raiseVar :: IO String -> X () -- cgit v1.2.3