I'm trying to do the equivalent of
xdotool search "Chromium" windowactivate --sync key --clearmodifiers ctrl+r
i.e. I would like to switch to Chromium and reload the current page. However, with XMonad I get the following error:
Your windowmanager claims not to support _NET_ACTIVE_WINDOW, so the attempt to activate the window was aborted.
Is there a way in XMonad to programmatically switch to a certain application?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With