Window focus after Restart

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