Added next-window versions of the raise* functions.

This commit is contained in:
Ian Zerny 2008-04-05 18:29:00 +00:00
parent b495c7f725
commit ef25a538bf

View File

@ -16,8 +16,11 @@ module XMonad.Actions.WindowGo (
-- * Usage -- * Usage
-- $usage -- $usage
raise, raise,
raiseNext,
runOrRaise, runOrRaise,
runOrRaiseNext,
raiseMaybe, raiseMaybe,
raiseNextMaybe,
raiseBrowser, raiseBrowser,
raiseEditor, raiseEditor,
@ -30,7 +33,7 @@ import Data.Char (toLower)
import XMonad (Query(), X(), withWindowSet, spawn, runQuery, liftIO, focus) import XMonad (Query(), X(), withWindowSet, spawn, runQuery, liftIO, focus)
import XMonad.ManageHook import XMonad.ManageHook
import XMonad.Prompt.Shell (getBrowser, getEditor) import XMonad.Prompt.Shell (getBrowser, getEditor)
import qualified XMonad.StackSet as W (allWindows) import qualified XMonad.StackSet as W (allWindows, peek)
{- $usage {- $usage
@ -93,6 +96,33 @@ raiseMaybe f thatUserQuery = withWindowSet $ \s -> do
[] -> f [] -> f
(x:_) -> focus x (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, -- | 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. -- or we then interpret that String as a executable name.
raiseVar :: IO String -> X () raiseVar :: IO String -> X ()