From 8ae290915a5af214b0151ab1c5219d9f9d465031 Mon Sep 17 00:00:00 2001 From: gwern0 Date: Tue, 1 Apr 2008 04:17:40 +0200 Subject: WindowGo.hs: +raiseBrowser, raiseEditor Specialize runOrRaise in the same way as with Actions.Search, for one's browser and one's editors. darcs-hash:20080401021740-f7719-010716f904682bee3d7f96862dd5bcef73f7907f.gz --- XMonad/Actions/WindowGo.hs | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'XMonad/Actions/WindowGo.hs') diff --git a/XMonad/Actions/WindowGo.hs b/XMonad/Actions/WindowGo.hs index 57878b9..1bf1c26 100644 --- a/XMonad/Actions/WindowGo.hs +++ b/XMonad/Actions/WindowGo.hs @@ -10,8 +10,7 @@ Defines a few convenient operations for raising (traveling to) windows based on monad, such as 'runOrRaise'. runOrRaise will run a shell command unless it can find a specified window; you would use this to automatically travel to your Firefox or Emacs session, or start a new one (for example), instead of trying to -remember where you left it or whether you still have one running. --} +remember where you left it or whether you still have one running. -} module XMonad.Actions.WindowGo ( -- * Usage @@ -19,13 +18,19 @@ module XMonad.Actions.WindowGo ( raise, runOrRaise, raiseMaybe, + + raiseBrowser, + raiseEditor, module XMonad.ManageHook ) where -import XMonad (Query(), X(), withWindowSet, spawn, runQuery, focus) import Control.Monad (filterM) -import qualified XMonad.StackSet as W (allWindows) +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) {- $usage @@ -39,7 +44,10 @@ and define appropriate key bindings: > , ((modMask x .|. shiftMask, xK_b), runOrRaise "firefox" (className =? "Firefox")) (Note that Firefox v3 and up have a class-name of "Firefox" and "Navigator"; -lower versions use other classnames such as "Firefox-bin" +lower versions use other classnames such as "Firefox-bin". Either choose the +appropriate one, or cover your bases by using instead something like + @(className =? "Firefox" <||> className =? "Firefox-bin")@.) + For detailed instructions on editing your key bindings, see "XMonad.Doc.Extending#Editing_key_bindings". -} @@ -84,3 +92,15 @@ raiseMaybe f thatUserQuery = withWindowSet $ \s -> do case maybeResult of [] -> f (x:_) -> focus x + +-- | 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 () +raiseVar getvar = liftIO getvar >>= \var -> runOrRaise var (fmap (map toLower) className =? var) + +-- | 'raiseBrowser' and 'raiseEditor' grab $BROWSER and $EDITOR respectively and they either +-- take you to the specified, or they try to run it. This is most useful if your variables are simple +-- and look like 'firefox' or 'emacs'. +raiseBrowser, raiseEditor :: X () +raiseBrowser = raiseVar getBrowser +raiseEditor = raiseVar getEditor -- cgit v1.2.3