[xmonad] run a program when switching to a workspace

Sergey Manucharian sergey at ingeniware.com
Fri May 29 01:01:16 EDT 2009


On Thu, 28 May 2009 09:33:24 -0400
Brent Yorgey <byorgey at seas.upenn.edu> wrote:

> On Thu, May 28, 2009 at 10:50:34AM +0300, Roman Cheplyaka wrote:
> > * 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?
> 
> That's a nice idea!  I've always thought that the logHook could be
> generalized in a number of interesting ways.  There are lots of things
> that might want to be notified of status changes which have nothing to
> do with logging.
> 
> -Brent

Thanks for ideas, guys!

By the way, another solution with EventHook is posted here:

http://bbs.archlinux.org/viewtopic.php?pid=560598#p559566

Cheers,
Sergey


More information about the xmonad mailing list