WindowGo.hs: +raiseBrowser, raiseEditor

Specialize runOrRaise in the same way as with Actions.Search, for one's browser and one's editors.
This commit is contained in:
gwern0 2008-04-01 02:17:40 +00:00
parent acd13fd324
commit 64396d85ab

View File

@ -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 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 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 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 ( module XMonad.Actions.WindowGo (
-- * Usage -- * Usage
@ -19,13 +18,19 @@ module XMonad.Actions.WindowGo (
raise, raise,
runOrRaise, runOrRaise,
raiseMaybe, raiseMaybe,
raiseBrowser,
raiseEditor,
module XMonad.ManageHook module XMonad.ManageHook
) where ) where
import XMonad (Query(), X(), withWindowSet, spawn, runQuery, focus)
import Control.Monad (filterM) 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.ManageHook
import XMonad.Prompt.Shell (getBrowser, getEditor)
import qualified XMonad.StackSet as W (allWindows)
{- $usage {- $usage
@ -39,7 +44,10 @@ and define appropriate key bindings:
> , ((modMask x .|. shiftMask, xK_b), runOrRaise "firefox" (className =? "Firefox")) > , ((modMask x .|. shiftMask, xK_b), runOrRaise "firefox" (className =? "Firefox"))
(Note that Firefox v3 and up have a class-name of "Firefox" and "Navigator"; (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 For detailed instructions on editing your key bindings, see
"XMonad.Doc.Extending#Editing_key_bindings". -} "XMonad.Doc.Extending#Editing_key_bindings". -}
@ -84,3 +92,15 @@ raiseMaybe f thatUserQuery = withWindowSet $ \s -> do
case maybeResult of case maybeResult of
[] -> f [] -> f
(x:_) -> focus x (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