aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--XMonad/Actions/WindowGo.hs30
1 files changed, 25 insertions, 5 deletions
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