From 77fbe236449437a590e4267f97bdd985246ff1b9 Mon Sep 17 00:00:00 2001 From: seanmce33 Date: Fri, 12 Sep 2008 20:48:30 +0200 Subject: raiseMaster darcs-hash:20080912184830-d2fc6-8dbaa909dd005ac7da2e7477d6dcc1b25c371047.gz --- XMonad/Actions/WindowGo.hs | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'XMonad/Actions/WindowGo.hs') diff --git a/XMonad/Actions/WindowGo.hs b/XMonad/Actions/WindowGo.hs index e5e70e0..deb67ae 100644 --- a/XMonad/Actions/WindowGo.hs +++ b/XMonad/Actions/WindowGo.hs @@ -24,6 +24,10 @@ module XMonad.Actions.WindowGo ( raiseBrowser, raiseEditor, + runOrRaiseAndDo, + runOrRaiseMaster, + raiseAndDo, + raiseMaster, module XMonad.ManageHook ) where @@ -33,8 +37,9 @@ 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, peek) - +import qualified XMonad.StackSet as W (allWindows, peek, swapMaster) +import XMonad.Operations (windows) +import Graphics.X11 (Window) {- $usage Import the module into your @~\/.xmonad\/xmonad.hs@: @@ -134,3 +139,38 @@ raiseVar getvar = liftIO getvar >>= \var -> runOrRaise var (fmap (map toLower) c raiseBrowser, raiseEditor :: X () raiseBrowser = raiseVar getBrowser raiseEditor = raiseVar getEditor + +{- | if the window is found the window is focused and the third argument is called + otherwise, the first argument is called + See 'raiseMaster' for an example -} +raiseAndDo :: X () -> Query Bool -> (Window -> X ())-> X () +raiseAndDo raisef thatUserQuery afterRaise = withWindowSet $ \s -> do + maybeResult <- filterM (runQuery thatUserQuery) (W.allWindows s) + case maybeResult of + [] -> raisef + (x:_) -> do + XMonad.focus x + afterRaise x + +{- | if the window is found the window is focused and the third argument is called + otherwise, raisef is called -} +runOrRaiseAndDo :: String -> Query Bool -> (Window -> X ()) -> X () +runOrRaiseAndDo run query afterRaise = raiseAndDo (spawn run) query afterRaise + + +{- | if the window is found the window is focused and set to master + otherwise, the first argument is called + + raiseMaster (runInTerm \"-title ghci\" \"zsh -c \'ghci\'\") (title =? \"ghci\") -} +raiseMaster :: X () -> Query Bool -> X () +raiseMaster raisef thatUserQuery = raiseAndDo raisef thatUserQuery (\_ -> windows W.swapMaster) + +{- | if the window is found the window is focused and set to master + otherwise, action is run + + runOrRaiseMaster \"firefox\" (className =? \"Firefox\")) + -} +runOrRaiseMaster :: String -> Query Bool -> X () +runOrRaiseMaster run query = runOrRaiseAndDo run query (\_ -> windows W.swapMaster) + + -- cgit v1.2.3