Here's what I use, inspired by XMonad.Util.WindowBringer. You'll need to install the Text.PCRE package. Apologies if I forgot any import statements.
import XMonad
import qualified XMonad.StackSet as W
import XMonad.Util.NamedWindows (getName)
import Control.Applicative ((<$>))
import Data.List (find)
import Text.Regex.PCRE ((=~))
findWindow :: String -> X (Maybe Window)
findWindow regex = do
wmap <- concat <$> (mapM mappings =<< (W.workspaces <$> gets windowset))
:: X [(String, Window)]
return (snd <$> find ((=~ regex) . fst) wmap)
where mappings :: WindowSpace -> X [(String, Window)]
mappings ws = mapM mapping $ W.integrate' (W.stack ws)
mapping w = flip (,) w <$> show <$> getName w
warpTo :: String -> X ()
warpTo regex =
findWindow regex >>= (flip whenJust $ windows . W.focusWindow)
In principle you should then be able to bind a key to warpTo "Chromium" >> spawn "xdotool key --clearmodifiers ctrl+r"
. However, this doesn't work for me, apparently due to some race condition I don't understand. Luckily, I find that the following works:
warpTo "Chromium" >> spawn "sleep 0.2; xdotool key --clearmodifiers ctrl+r"
You might be able to get away with a shorter delay.