Not running my startupHook on restart

I have a startupHook that spawns a number of windows on various workspaces. When I restart XMonad, I don't want those windows opened again. Is there an easy way to have startupHook only run when logging in, and not when restarting XMonad? The way I have tried to solve this, unsuccessfully, is to make my startupHook look like this: myStartup = when (noRun /= "1") $ do spawnOn "1" "emacs" spawnOn "6" "x-terminal-emulator" -- and so on... where noRun = unsafePerformIO $ env "NO_STARTUP_HOOK" "0" env :: String -> String -> IO String env variable fallthrough = getEnv variable `Control.Exception.catch` econst fallthrough (where getEnv is imported from System.Environment). And then I have changed the restart keybinding like this: , ("M-S-r", spawn "xmonad --recompile; export NO_STARTUP_HOOK=1; xmonad --restart") Unfortunately it doesn't work - I guess something "more" is going on when "xmonad --restart" runs, because if I add a key: , ("M-S-y", spawn "export HEP=yay; notify-send --expire-time 2000 'Testing' \"ENV: [$HEP]\"") then pressing M-S-y gives me an alert with the text "ENV: [yay]" in it. But if I do: , ("M-S-y", spawn "notify-send --expire-time 2000 'Testing' \"ENV: [$NO_STARTUP_HOOK]\"") the notification says "ENV: []" regardless of whether I have restarted XMonad or not. I have a feeling that I am taking the long walk to solve this - any ideas of the easy way to the goal here? Thanks! Adam -- "Här kommer rädslan, nu igen Adam Sjøgren När alla fjärilar i magen nålas upp asjo@koldfront.dk till ett mönster på min säng"

On Thu, Dec 31, 2015 at 11:35 AM, Adam Sjøgren
I have a startupHook that spawns a number of windows on various workspaces.
When I restart XMonad, I don't want those windows opened again.
Use XMonad.Util.SpawnOnce.spawnOnce. If you want to use SpawnOn as well then you'd need to write your own spawner combining the two. The more general way to do it is: as <- io getArgs when (null as) $ do {- your startup code here -} which takes advantage of the fact that restarts pass --resume as a parameter, followed by the serialized xmonad state. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

Brandon writes:
The more general way to do it is:
as <- io getArgs when (null as) $ do {- your startup code here -}
which takes advantage of the fact that restarts pass --resume as a parameter, followed by the serialized xmonad state.
That worked great - thanks! Best regards, Adam -- "On the quiet side. Somewhat peculiar. A good Adam Sjøgren companion, in a weird sort of way." asjo@koldfront.dk

On 31.12.2015 09:06, Adam Sjøgren wrote:
Brandon writes:
as <- io getArgs when (null as) $ do {- your startup code here -}
That worked great - thanks! For me it does not work, I don't know why.
myStartupHook = do args <- io getArgs spawn $ "xmessage " ++ show (length args) ... When I restart xmonad, xmessage pops up and shows "0". But `ps aux | grep xmonad` shows me the --resume option and the serialized state in the command line. Any ideas?

On Thu, Jan 7, 2016 at 3:30 PM, Jakob Schöttl
For me it does not work, I don't know why.
myStartupHook = do args <- io getArgs spawn $ "xmessage " ++ show (length args) ...
Actually... I updated to 0.12 and at the same time switched from ghc 7.6.3 to 7.10.3, and found the same thing. I had to move the "args <- io getArgs" directly into "main" before invocation of the "xmonad" function. I haven't yet looked at the code but this seems surprising. I also suspect it's not related to a change in xmonad, since the only core changes (and only a core change could have any effect here) were documentation. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

On 07.01.2016 12:44, Brandon Allbery wrote:
On Thu, Jan 7, 2016 at 3:30 PM, Jakob Schöttl
mailto:jschoett@gmail.com> wrote: For me it does not work, I don't know why.
myStartupHook = do args <- io getArgs spawn $ "xmessage " ++ show (length args) ...
Actually... I updated to 0.12 and at the same time switched from ghc 7.6.3 to 7.10.3, and found the same thing. I had to move the "args <- io getArgs" directly into "main" before invocation of the "xmonad" function.
I haven't yet looked at the code but this seems surprising. I also suspect it's not related to a change in xmonad, since the only core changes (and only a core change could have any effect here) were documentation.
That works! Thank you. Yeah it sounds like a GHC bug for me. I also have xmonad 0.12 and GHC 7.10.3.

Jakob writes:
On 07.01.2016 12:44, Brandon Allbery wrote:
Actually... I updated to 0.12 and at the same time switched from ghc 7.6.3 to 7.10.3, and found the same thing. I had to move the "args <- io getArgs" directly into "main" before invocation of the "xmonad" function.
I haven't yet looked at the code but this seems surprising. I also suspect it's not related to a change in xmonad, since the only core changes (and only a core change could have any effect here) were documentation.
That works! Thank you. Yeah it sounds like a GHC bug for me. I also have xmonad 0.12 and GHC 7.10.3.
I run xmonad 0.11.1 and ghc 7.10.3 (both on Debian sid), and it works for me (to have "as <- io getArgs" in my startupHook). Just a data point, Adam -- "Boy, I love summer vacation. Adam Sjøgren I can feel my brain beginning to atrophy already." asjo@koldfront.dk

On Fri, Jan 8, 2016 at 2:26 AM, Adam Sjøgren
Jakob writes:
On 07.01.2016 12:44, Brandon Allbery wrote:
Actually... I updated to 0.12 and at the same time switched from ghc 7.6.3 to 7.10.3, and found the same thing. I had to move the "args <- io getArgs" directly into "main" before invocation of the "xmonad" function.
That works! Thank you. Yeah it sounds like a GHC bug for me. I also have xmonad 0.12 and GHC 7.10.3.
I run xmonad 0.11.1 and ghc 7.10.3 (both on Debian sid), and it works for me (to have "as <- io getArgs" in my startupHook).
Turns out it is a code change. https://github.com/xmonad/xmonad/commit/307b82a53d519f5c86c009eb1a54044a616e... This isn't even mentioned in breaking changes at https://wiki.haskell.org/Xmonad/Notable_changes_since_0.11 There's also documentation in various places that would need to be updated. -- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

asjo@koldfront.dk (Adam Sjøgren) writes:
When I restart XMonad, I don't want those windows opened again.
Also take a look at the new XMonad.Actions.DynamicProjects module: https://hackage.haskell.org/package/xmonad-contrib-0.12/docs/XMonad-Actions-... Or XMonad.Actions.TopicSpace: https://hackage.haskell.org/package/xmonad-contrib-0.12/docs/XMonad-Actions-... Both of which can spawn applications on a specific workspace when it has no windows. -- Peter Jones, Founder, Devalot.com Defending the honor of good code

On Thu, Dec 31, 2015 at 8:35 AM, Adam Sjøgren
And then I have changed the restart keybinding like this:
, ("M-S-r", spawn "xmonad --recompile; export NO_STARTUP_HOOK=1; xmonad --restart")
Unfortunately it doesn't work - I guess something "more" is going on
To explain the "something more", `xmonad --restart` doesn't do what you think it does. Namely: it just sets a property on the root window and dies; the new xmonad process does *not* start managing windows. Instead, the existing xmonad process notices the property change on the root window and restarts *itself*, passing along its current internal state in command-line parameters. This is why the environment change is not absorbed: only the process that sets a root window property and exits sees the new environment; the existing process' environment, which is the one inherited by the new window manager, is unchanged. You should be able to fix this by setting the environment in-process with System.Environment.setEnv and then directly calling XMonad.Operations.restart (why go through a complicated rigamarole to send yourself a message when you can just pretend you already got it? ;-). Something like this: , ("M-S-r", setEnv "NO_STARTUP_HOOK" "1" >> restart "xmonad" True) ~d
participants (5)
-
asjo@koldfront.dk
-
Brandon Allbery
-
Daniel Wagner
-
Jakob Schöttl
-
Peter Jones