Window focus after Restart

There is a RestartFunction. Can this be used to focus current window after restart? I searched, not sure if possible.

DestroyFunc RestartFunction
AddToFunc RestartFunction
+ I Current Focus

What do you mean by current windows? Current already implies the window that has focus, so trying to focus the window that has focus won’t do much.

Window which is focused, is unfocused after restart. How to get it focused without a mouse click?

I found something similar in one of my old topics. It may work if top window $[w.id] is stored.

DestroyFunc RestartFunction
AddToFunc RestartFunction
+ I Current InfoStoreAdd WinID $[w.id]
+ I WindowId $[infostore.WinID] Focus

Ahh okay, now I understand what you are trying to do. I use SloppyFocus so the focused window is often the same because it is based off mouse location.

Your second approach is more on track, you need to save the current focused window, then restore it. But I still don’t think your approach is fully correct. First you no longer need to use RestartFunction, instead just use StartFunction with the Test (Restart) conditional.

Also the RestartFunction is only run on the initialization phase, you need to also run a function before the restart, which is what the ExitFunction is for. In testing this I found a few issues due to how fvwm saves and restores a session during restart. The best solution I found is as follows.

# Save focus window ID on restart
AddToFunc ExitFunction
+ I Test (ToRestart) Current InfoStoreAdd FocusId $[w.id]

# Focus previously focused window on restart
AddToFunc StartFunction
+ Test (Restart) Schedule 500 WindowId $[infostore.FocusId] Focus
+ Test (Restart) InfoStoreRemove FocusId

Note the Schedule is a work around, you need to change focus after the initialization is complete which is after StartFunction is run, so this just delays things. Adjust the number to how long you need/want to wait for the window to gain focus.

1 Like

Good to know, ExitFunction executes what-ever-is-there before Restart. In this case stores $[w.id].

Needs higher Schedule when desk has Firefox and other heavy apps.
+ I Test (Restart) Schedule 1500 WindowId $[infostore.FocusId] Focus

I am using ClickToFocus, this function does the job, thanks.

My guess is computer speed is more at play there, I too was restarting with firefox, and between StartFunction running and the restart finishing, 500 was more than enough time for me. But that is the problem with timers like that, depends a lot on so many factors. Glad it worked.