[xmonad] run a program when switching to a workspace

Roman Cheplyaka roma at ro-che.info
Thu May 28 03:50:34 EDT 2009


* Brent Yorgey <byorgey at seas.upenn.edu> [2009-05-27 22:52:04-0400]
> On Mon, May 25, 2009 at 08:47:42AM -0600, Sergey Manucharian wrote:
> > Hi folks,
> > 
> > How can I configure xmonad to run a program when switching to a
> > particular workspace? Example: I want to run a script changing the
> > keyboard layout to "us" unconditionally when I'm on particular
> > workspaces (with ssh, rdesktop etc.).
> 
> The easiest way to do this is to add an action to your logHook that
> checks the current workspace, and sets the keyboard layout if it is
> the desired workspace:
>  
>   ...
>   logHook = ...other stuff... >> checkKBLayout
> 
>   ...
> 
>   checkKBLayout :: X ()
>   checkKBLayout = do
>     curTag <- gets (W.currentTag . windowset)
>     when (curTag == "foo") $ spawn "set keyboard layout"
> 
> Of course, "foo" should be replaced with whatever workspace you want,
> and "set keyboard layout" should be replaced with a suitable command
> for setting the keyboard layout.

Just to make it clear: the command will be spawned each time when
windowset changes -- e.g. when you change the focus. It's harmless with
setting kb layout, but if you use it for e.g. launching an application
you'll get a new instance each time you change focus.

Another possibility is to create IORef and store previous workspace
there, so you can know whether you really _switched_ to current
workspace.

Maybe create a layer on top of logHook which would provide incremental
information?

-- 
Roman I. Cheplyaka (aka Feuerbach @ IRC)
http://ro-che.info/docs/xmonad.hs


More information about the xmonad mailing list