aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Actions
diff options
context:
space:
mode:
authorIan Zerny <ian@zerny.dk>2008-04-05 20:29:00 +0200
committerIan Zerny <ian@zerny.dk>2008-04-05 20:29:00 +0200
commitbd4f72d6e453aa7dee2f8f9470f2f71af1667a92 (patch)
treed4b6eda2772689e36e40faff4c0defa28715de05 /XMonad/Actions
parent6d24c03cfaa94487c8488e0eb9f633e46b91ee8a (diff)
downloadXMonadContrib-bd4f72d6e453aa7dee2f8f9470f2f71af1667a92.tar.gz
XMonadContrib-bd4f72d6e453aa7dee2f8f9470f2f71af1667a92.tar.xz
XMonadContrib-bd4f72d6e453aa7dee2f8f9470f2f71af1667a92.zip
Added next-window versions of the raise* functions.
darcs-hash:20080405182900-ba7e7-6871a7f6ac9155c062c152c3c902c895ab9aa94b.gz
Diffstat (limited to 'XMonad/Actions')
-rw-r--r--XMonad/Actions/WindowGo.hs32
1 files changed, 31 insertions, 1 deletions
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 ()