[xmonad] auto start apps on login, but not reloads

Yiannis Tsiouris gtsiour at softlab.ntua.gr
Fri Mar 24 11:39:46 UTC 2017


On 03/24, Brandon Allbery wrote:
> On Fri, Mar 24, 2017 at 6:19 AM, Sam Halliday <sam.halliday at gmail.com>
> wrote:
> 
> > Following http://stackoverflow.com/questions/10976044/ I have added the
> > following to my `startupHook`
> >
> >     startup :: X ()
> >     startup = do
> >               setWMName "LG3D"
> >               spawnOn "workspace1" "urxvt"
> >               spawnOn "workspace2" "emacs"
> >               spawnOn "workspace3" "chromium"
> >
> > but there are three problems:
> >
> > 1. I am duplicating the definition of my terminal. It seems like I
> >    should be using
> >    [`shellPromptOn`](http://xmonad.org/xmonad-docs/xmonad-
> > contrib/XMonad-Actions-SpawnOn.html)
> >    but it takes an extra parameter and I don't know where to get it
> >    from.
> >
> 
> No, that's an interactive prompt at a screen edge that asks for a command,
> with built-in completion, and passes it to a shell. There is no terminal
> involved, unless that is what you tell it to launch. (The `XPConfig` is the
> configuration for an XMonad.Prompt screen edge popup window.)
> 
> 2. this is putting everything on my current workspace. How can I find
> >    out what my workspaces are called? I don't believe I've customised
> >    the names, you can see [my .xmonad/xmonad.hs on github to
> >    confirm](https://github.com/fommil/dotfiles/blob/master/.
> > xmonad/xmonad.hs)
> >
> 
> You indeed haven't, so your workspaces are "1", "2", ... "9".
> 
> You're also missing manageSpawn in the manageHook, so nothing ever gets
> moved anyway.
> 
> 3. This will start the apps again on a `xmonad --restart`. How can we
> >    guard against that? It is very useful to be able to restart xmonad
> >    without quitting and I don't want to lose that ability.
> >
> 
> There isn't anything that combines the functionality of spawnOnce and
> spawnOn currently. I replace the spawnOnce with a bit of a hack that checks
> whether xmonad was launched with parameters (which it normally isn't, but a
> restart passes the old state). Using your config as a template:
> 
>     import Control.Monad
>     import System.Environment
> 
>     main = do
>       args <- getArgs
>       xmonad $ ewmh $ withUrgencyHook dzenUrgencyHook { args = ["-bg",
> "darkgreen", "-xs", "1"] }
>              $ defaultConfig {
>                terminal = "urxvt"
>              , startupHook = startup (null args)
>              *-- and the rest here...*
>         }
> 
>     startup :: Bool -> X ()
>     startup initial = do
>                       setWMName "LG3D"
>                       when initial $ do
>                         spawnOn "1" "urxvt"
>                         spawnOn "2" "emacs"
>                         spawnOn "3" "chromium"
> 
> Note also that chromium can misbehave with spawnOn because we have to rely
> on the window registering the same associated process ID as the one we get
> back from running it, and it often isn't. See
> https://wiki.haskell.org/Xmonad/General_xmonad.hs_config_tips#Terminal_emulator_factories
> for more information. (chromium is a bit worse in that many versions of its
> wrapper script fork, so the pid will *never* match.)

Oh, this is actually very useful! :] Thanks to Brandon for sharing your solution
and to Sam for starting the thread!

Cheers,
Yiannis


More information about the xmonad mailing list