4

I'm trying to write an xmonad.hs which, at startup, launches some apps on some workspaces. Several of these apps (e.g., atop) will run within a terminal (urxvt being my preference).

This has been asked a few times before, e.g, here, here, and is obliquely touched on on the XMonad FAQ.

However, these rely on:

  1. using spawnOn from XMonad.Actions.SpawnOn, which flat doesn't work (testing with urxvt, and also xclock as a simple example); it gets sent to the current workspace.

  2. using spawn prog >> windows $ greedyView <workspace>, which kinda works, but has major timing issues - e.g., if you run two in succession, with different workspaces, both progs end up on the latter workspace. FWIW, I experimented with using threaddelay to assist; it didn't make any discernable difference, even with a 10s delay between spawns (I remembered that threadDelay is in microseconds, and so used 10000000).

  3. rely on using general hooks for programs - meaning that whenever I start them up, they'll get sent to the given workspace. That's not what I want; I just want them placed there at startup.

Relatedly, it surprises me that the API doesn't let me start up an app and then give me a reference to that app/window (potentially with a timeout); so that I can confidently send that app/window to a workspace.

Any help would be greatly appreciated.

melpomene
  • 84,125
  • 8
  • 85
  • 148
user3416536
  • 1,429
  • 9
  • 20

2 Answers2

2

Install wmctrl

sudo apt install wmctrl

And create a script (in this example thunderbird on the second workspace (-t 1)):

#!/bin/sh

 (thunderbird &)  & sleep 5 && 
sh -c "wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"

To know your application name on wmctrl you can view it by taping on your terminal :

wmctrl -l

And replace it with the correct name in the script.

Be carrefull with the capital letter ("Thunderbird" not "thunderbird") !!

Other example with firefox on the 3d workspace (-t 2):

#!/bin/sh
(firefox &)  & sleep 5 && 
sh -c "wmctrl -i -r `wmctrl -l | grep Firefox` -t 2"

Bonus :

Here is the command to execute at start-up :

sh -c "thunderbird  & sleep 5 && wmctrl -i -r `wmctrl -l | grep Thunderbird` -t 1"

Work on Debain 10 with Cinnamon. But should work for all

Pierre
  • 21
  • 3
1

You can spawn the app via startupHook and then use a manageHook to handle window placement.

manageHook such as:

, className =? "deluge" --> doShift ( myWorkspaces !! 3 )

The above will actually spawn deluge on Workspace 4. In my startupHook I have

spawnOnce "deluge-gtk" to launch the app on start-up.

You would want to import XMonad.Util.SpawnOnce. doShift comes from the default XMonad.ManageHooks You could also take a look at XMonad.Actions.SpawnOn but I only use manageSpawn from that module.

Dharman
  • 30,962
  • 25
  • 85
  • 135