XMonad, `spawnOn` order

Viewed 74

I have the following in my xmonad.hs:

spawnOnOnce "0" "kitty -e vim ~/configuration.org; kitty"
spawnOnOnce "0" "kitty"

And it works, but the thing is, the order of the execution is always different: sometimes the first "spawn" is executed and sometime the second. I need the order of execution to be always the same, e.g., in the order they are written.

Please help :-)

EDIT 1:

As per @JosephSible-ReinstateMonica request in the comments below:

Why does it matter the exact order in which the processes are spawned?

I use the "Master/Stack" layout (with manageHook = insertPosition End Newer ...), and if the second "spawnOn" is the first to be executed, then it would be on the left side of the screen, I want it to be always on the right side of the screen.

1 Answers

It's likely that spawnOnOnce does not make guarantees about execution order.

You could probably get around this by having the first command upon completion send a SIGUSR2 signal to the xmonad process, and having the second command wait for that SIGUSR2 signal.

Proof of concept (untested):

spawnOnOnce "0" "kitty -e vim ~/configuration.org; kitty; pkill --SIGUSR2 xmonad"
void $ installHandler sigUSR2 (CatchOnce $ spawnOnOnce "0" "kitty") Nothing

Where installHandler, sigUSR2, and CatchOnce come from System.Posix.Signals.

Since kitty is a terminal, this may not work, since the pkill --SIGUSR2 may not be executed until kitty is closed. So, you may have to play around with that: pkill --SIGUSR2 xmonad & kitty might work, or kitty & pkill --SIGUSR2 xmonad; wait.

Related