2

E.g. I want to bind Mod+Shift+m to bring me to the window whose className is "Emacs", so I can instantly switch to that application regardless which workspace I'm in and which window I'm focusing.

Chris Stryczynski
  • 5,178
  • 5
  • 40
  • 80

1 Answers1

0

https://stackoverflow.com/a/50427647/1663462

module WindowFinder where

import XMonad
import qualified XMonad.StackSet as W
import Control.Monad
import Data.Bool  (bool)

findWindows :: String -> X [Window]
findWindows name = do
  withWindowSet $ (\ws -> do
    forM (W.allWindows ws)
      (\w -> do
            s <- withDisplay $ \d -> fmap resClass . liftIO $ getClassHint d w
            return $ bool [] [w] (s == name) :: X [Window]
      ) >>= return . join
    )

With the above module imported you can set the following key binding:

          , ((modm, xK_c), do
            win' <- findWindows "Chromium"
            when (length win' > 0)
              (windows $ W.focusWindow $ head win')
          )
Chris Stryczynski
  • 5,178
  • 5
  • 40
  • 80