9

I find it a bit awkward in xmonad to switch back and forth between two windows. Is there an extension (or a part of core xmonad) which allows this?

For example, I want to switch between firefox and emacs often, and they might not be in the same workspace. I currently do this using gotoMenu by typing M-g firefox<cr> and M-g emacs<cr> but this is awkward, especially if there's more than one instance of either app. Ideally I'd like a single shortcut to perform an action like give-focus-to-most-recently-used-unfocussed-window, which I could just press over and over to switch back and forth.

Garrett
  • 47,045
  • 6
  • 61
  • 50
Matthew Gilliard
  • 9,298
  • 3
  • 33
  • 48

1 Answers1

12

XMonad.Actions.GroupNavigation seems to be a perfect fit. To let the module track your window history, make sure that logHook invokes historyHook. For example:

import XMonad.Actions.GroupNavigation
...
main = xmonad $ defaultConfig {
   ...
   , logHook = myLogHook xmobars >> historyHook
}

Then create a key binding for the following expression, which will toggle between the current and most recent window.

("M-x", nextMatch History (return True))
Garrett
  • 47,045
  • 6
  • 61
  • 50
  • This works perfectly - although my key binding looks like `((modm, xK_x), nextMatch History (return True))` – Matthew Gilliard Jan 07 '14 at 08:45
  • 2
    @Matthew If you're using `XMonad.Util.EZConfig.additionalKeysP` to add extra key bindings, you can specify them in this stringy format instead. Or (import from the same place), you can use `additionalKeys` to add them as you are doing (with (modm, xK_x)). – Squidly Jan 07 '14 at 11:00
  • i had to delete `xmobars` – Toothrot Jan 11 '20 at 18:28
  • I don't get it. This is like Alt-Tab behavior, but severely limited, because it can't cycle most recently used applications, only application in singular – Jason Hunter Oct 20 '22 at 07:25