License | Public domain |
---|---|
Maintainer | <gwern0@gmail.com> |
Stability | unstable |
Portability | unportable |
Safe Haskell | None |
Language | Haskell2010 |
Defines a few convenient operations for raising (traveling to) windows based on XMonad's Query
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.
Synopsis
- raise :: Query Bool -> X ()
- raiseNext :: Query Bool -> X ()
- runOrRaise :: String -> Query Bool -> X ()
- runOrRaiseNext :: String -> Query Bool -> X ()
- raiseMaybe :: X () -> Query Bool -> X ()
- raiseNextMaybe :: X () -> Query Bool -> X ()
- raiseNextMaybeCustomFocus :: (Window -> WindowSet -> WindowSet) -> X () -> Query Bool -> X ()
- raiseBrowser :: X ()
- raiseEditor :: X ()
- runOrRaiseAndDo :: String -> Query Bool -> (Window -> X ()) -> X ()
- runOrRaiseMaster :: String -> Query Bool -> X ()
- raiseAndDo :: X () -> Query Bool -> (Window -> X ()) -> X ()
- raiseMaster :: X () -> Query Bool -> X ()
- ifWindows :: Query Bool -> ([Window] -> X ()) -> X () -> X ()
- ifWindow :: Query Bool -> ManageHook -> X () -> X ()
- raiseHook :: ManageHook
- module XMonad.ManageHook
Usage
Import the module into your xmonad.hs
:
import XMonad.Actions.WindowGo
and define appropriate key bindings:
, ((modm .|. shiftMask, xK_g), raise (className =? "Firefox")) , ((modm .|. 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". 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 the tutorial.
raise :: Query Bool -> X () Source #
See raiseMaybe
. If the Window can't be found, quietly give up and do nothing.
raiseNext :: Query Bool -> X () Source #
See raise
and raiseNextMaybe
. Version that allows cycling through matches.
runOrRaise :: String -> Query Bool -> X () Source #
action
is an executable to be run via safeSpawnProg
(of XMonad.Util.Run) if the Window cannot be found.
Presumably this executable is the same one that you were looking for.
Note that this does not go through the shell. If you wish to run an arbitrary IO action
(such as spawn
, which will run its String argument through the shell), then you will want to use
raiseMaybe
directly.
runOrRaiseNext :: String -> Query Bool -> X () Source #
See runOrRaise
and raiseNextMaybe
. Version that allows cycling through matches.
raiseMaybe :: X () -> Query Bool -> X () Source #
raiseMaybe
queries all Windows based on a boolean provided by the
user. Currently, there are 3 such useful booleans defined in
XMonad.ManageHook: title
, resource
, className
. Each one tests based pretty
much as you would think. ManageHook also defines several operators, the most
useful of which is (=?). So a useful test might be finding a Window
whose
class is Firefox. Firefox 3 declares the class "Firefox", so you'd want to
pass in a boolean like (className =? "Firefox")
.
If the boolean returns True
on one or more windows, then XMonad will quickly
make visible the first result. If no Window
meets the criteria, then the
first argument comes into play.
The first argument is an arbitrary IO function which will be executed if the
tests fail. This is what enables runOrRaise
to use raiseMaybe
: it simply runs
the desired program if it isn't found. But you don't have to do that. Maybe
you want to do nothing if the search fails (the definition of raise
), or
maybe you want to write to a log file, or call some prompt function, or
something crazy like that. This hook gives you that flexibility. You can do
some cute things with this hook. Suppose you want to do the same thing for
Mutt which you just did for Firefox - but Mutt runs inside a terminal window?
No problem: you search for a terminal window calling itself "mutt", and if
there isn't you run a terminal with a command to run Mutt! Here's an example
(borrowing runInTerm
from XMonad.Util.Run):
, ((modm, xK_m), raiseMaybe (runInTerm "-title mutt" "mutt") (title =? "mutt"))
raiseNextMaybe :: X () -> Query Bool -> X () Source #
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.
raiseNextMaybeCustomFocus :: (Window -> WindowSet -> WindowSet) -> X () -> Query Bool -> X () Source #
See raiseMaybe
and raiseNextMaybe
.
In addition to all of the options offered by raiseNextMaybe
raiseNextMaybeCustomFocus
allows the user to supply the function that
should be used to shift the focus to any window that is found.
raiseBrowser :: X () Source #
raiseBrowser
and raiseEditor
grab $BROWSER and $EDITOR respectively and they either
take you to the specified program's window, or they try to run it. This is most useful
if your variables are simple and look like "firefox" or "emacs".
raiseEditor :: X () Source #
raiseBrowser
and raiseEditor
grab $BROWSER and $EDITOR respectively and they either
take you to the specified program's window, or they try to run it. This is most useful
if your variables are simple and look like "firefox" or "emacs".
runOrRaiseAndDo :: String -> Query Bool -> (Window -> X ()) -> X () Source #
If a window matching the second argument is found, the window is focused and the third argument is called; otherwise, the first argument is called.
runOrRaiseMaster :: String -> Query Bool -> X () Source #
If the window is found the window is focused and set to master otherwise, action is run.
runOrRaiseMaster "firefox" (className =? "Firefox"))
raiseAndDo :: X () -> Query Bool -> (Window -> X ()) -> X () Source #
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.
raiseMaster :: X () -> Query Bool -> X () Source #
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")
ifWindows :: Query Bool -> ([Window] -> X ()) -> X () -> X () Source #
If windows that satisfy the query exist, apply the supplied function to them, otherwise run the action given as second parameter.
ifWindow :: Query Bool -> ManageHook -> X () -> X () Source #
The same as ifWindows, but applies a ManageHook to the first match instead and discards the other matches
raiseHook :: ManageHook Source #
A manage hook that raises the window.
module XMonad.ManageHook