run a program when switching to a workspace

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.). Thanks! Sergey

On Monday 25 of May 2009 18:47:42 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.).
Why not. Use something like this. I used key bindings description from EZConfig.
(("M-w") , spawn "some-program" >> windows $ W.greedyView "Some workspace")

On Mon, 25 May 2009 19:03:28 +0400
Khudyakov Alexey
On Monday 25 of May 2009 18:47:42 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.).
Why not.
Use something like this. I used key bindings description from EZConfig.
(("M-w") , spawn "some-program" >> windows $ W.greedyView "Some workspace")
Thanks for the reply, Alexey. Wouldn't it just add another key binding? What I meant is e.g. if I switch to the workspace "1" (no matter how) the keyboard layout falls to default one ("us") by running a script. In that case a key binding will not help... Cheers, Sergey

* Sergey Manucharian
On Mon, 25 May 2009 19:03:28 +0400 Khudyakov Alexey
wrote: On Monday 25 of May 2009 18:47:42 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.).
Why not.
Use something like this. I used key bindings description from EZConfig.
(("M-w") , spawn "some-program" >> windows $ W.greedyView "Some workspace")
Thanks for the reply, Alexey.
Wouldn't it just add another key binding? What I meant is e.g. if I switch to the workspace "1" (no matter how) the keyboard layout falls to default one ("us") by running a script. In that case a key binding will not help...
Try TopicSpace module: http://code.haskell.org/XMonadContrib/XMonad/Actions/TopicSpace.hs -- Roman I. Cheplyaka (aka Feuerbach @ IRC) http://ro-che.info/docs/xmonad.hs

Excerpts from Roman Cheplyaka's message of Tue May 26 20:29:28 +0200 2009:
* Sergey Manucharian
[2009-05-26 09:58:57-0600] On Mon, 25 May 2009 19:03:28 +0400 Khudyakov Alexey
wrote: On Monday 25 of May 2009 18:47:42 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.).
Why not.
Use something like this. I used key bindings description from EZConfig.
(("M-w") , spawn "some-program" >> windows $ W.greedyView "Some workspace")
Thanks for the reply, Alexey.
Wouldn't it just add another key binding? What I meant is e.g. if I switch to the workspace "1" (no matter how) the keyboard layout falls to default one ("us") by running a script. In that case a key binding will not help...
Try TopicSpace module: http://code.haskell.org/XMonadContrib/XMonad/Actions/TopicSpace.hs
Currently TopicSpace have support for spawning a command when you enter an empty workspace, not each time you enter it. However it could be a nice addition. However I'm wondering if a hook would not be more appropriated. Best regards, -- Nicolas Pouillard

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. -Brent

* Brent Yorgey
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

On Thu, May 28, 2009 at 10:50:34AM +0300, Roman Cheplyaka wrote:
* Brent Yorgey
[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

On Thu, 28 May 2009 09:33:24 -0400
Brent Yorgey
On Thu, May 28, 2009 at 10:50:34AM +0300, Roman Cheplyaka wrote:
* Brent Yorgey
[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

On Thu, 28 May 2009 10:50:34 +0300
Roman Cheplyaka
* Brent Yorgey
[2009-05-27 22:52:04-0400] ....... ... logHook = ...other stuff... >> checkKBLayout
...
checkKBLayout :: X () checkKBLayout = do curTag <- gets (W.currentTag . windowset) when (curTag == "foo") $ spawn "set 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.
I wonder why it keeps and keeps spawning the program even if I stay on that workspace.... Cheers, Sergey

* Sergey Manucharian
On Thu, 28 May 2009 10:50:34 +0300 Roman Cheplyaka
wrote: * Brent Yorgey
[2009-05-27 22:52:04-0400] ....... ... logHook = ...other stuff... >> checkKBLayout
...
checkKBLayout :: X () checkKBLayout = do curTag <- gets (W.currentTag . windowset) when (curTag == "foo") $ spawn "set 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.
I wonder why it keeps and keeps spawning the program even if I stay on that workspace....
As I said, "the command will be spawned each time when windowset changes -- e.g. when you change the focus." -- Roman I. Cheplyaka (aka Feuerbach @ IRC) http://ro-che.info/docs/xmonad.hs

Just to make sure it makes sense -- the log hook runs on all state changes -- focus, layout change... This might be why first suggestion was to add to keybinding that switches to that workspace. If you use many ways to change to that special workspace, like CycleWS and fancy clickable dzen areas, you could make a top level function 'toSpecialWS' using the '... >> ...' code from earlier, and re-use that function all the places you need it. -- wmw

On Sun, 31 May 2009 09:52:31 -0600
Wirt Wolff
....... If you use many ways to change to that special workspace, like CycleWS and fancy clickable dzen areas .......
Hi Wirt, By the way, how you can pass an event to xmonad from dzen clickable areas (or any other external program)? Cheers, Sergey

Excerpts from Sergey Manucharian's message of Mon Jun 01 09:25:09 -0600 2009:
On Sun, 31 May 2009 09:52:31 -0600 Wirt Wolff
wrote: .......
By the way, how you can pass an event to xmonad from dzen clickable areas (or any other external program)?
Cheers, Sergey
It's not really passing to xmonad, as far as I know people use xdotool or similar program to generate xorg keypresses. Really this is just another case of keybinding. -- wmw

* On Monday, June 01 2009, Wirt Wolff wrote:
Excerpts from Sergey Manucharian's message of Mon Jun 01 09:25:09 -0600 2009:
On Sun, 31 May 2009 09:52:31 -0600 Wirt Wolff
wrote: .......
By the way, how you can pass an event to xmonad from dzen clickable areas (or any other external program)?
Cheers, Sergey
It's not really passing to xmonad, as far as I know people use xdotool or similar program to generate xorg keypresses. Really this is just another case of keybinding.
I suggest using wmctrl in combination with Hooks.EwmhDesktops. XMonad.Hooks.ServerMode might work too.

On Mon, 1 Jun 2009 19:22:56 -0400
Adam Vogt
* On Monday, June 01 2009, Wirt Wolff wrote: ..... I suggest using wmctrl in combination with Hooks.EwmhDesktops.
Strange, I cannot get it working running xmonad from darcs: ..... Not in scope: `ewmhDesktopsLayout' ..... xmonad.hs: ..... import XMonad.Hooks.EwmhDesktops ..... layoutHook = ewmhDesktopsLayout $ avoidStruts $ ..... ..... Cheers, Sergey

On Sun, Jun 07, 2009 at 01:24:52PM -0600, Sergey Manucharian wrote:
On Mon, 1 Jun 2009 19:22:56 -0400 Adam Vogt
wrote: * On Monday, June 01 2009, Wirt Wolff wrote: ..... I suggest using wmctrl in combination with Hooks.EwmhDesktops.
Strange, I cannot get it working running xmonad from darcs:
..... Not in scope: `ewmhDesktopsLayout' .....
xmonad.hs:
..... import XMonad.Hooks.EwmhDesktops ..... layoutHook = ewmhDesktopsLayout $ avoidStruts $ ..... .....
ewmhDesktopsLayout was recently (February 2009) removed from X.H.EwmhDesktops and replaced with ewmhDesktopsEventHook, which should be added to the handleEventHook in your config. -Brent

On Mon, 8 Jun 2009 16:07:33 -0400
Brent Yorgey
ewmhDesktopsLayout was recently (February 2009) removed from X.H.EwmhDesktops and replaced with ewmhDesktopsEventHook, which should be added to the handleEventHook in your config.
Thanks Brent! Works perfectly. Of course, I've added this as well: logHook = ewmhDesktopsLogHook >> myLogHook' h Cheers, Sergey
participants (7)
-
Adam Vogt
-
Brent Yorgey
-
Khudyakov Alexey
-
Nicolas Pouillard
-
Roman Cheplyaka
-
Sergey Manucharian
-
Wirt Wolff