Remember script window position on quit [Solved]

I need to get the script’s window position on quit. How do I do that?

No you don’t – what are you trying to do which makes you think that? Don’t give me an XY problem, please.

– Thomas Adam

I have a script that can be dragged on desktop. I want to get the position of the script’s window on exit and alter the script with the new values so on restart the script will have the last position on desktop.

This is odd, but assuming your FvwmScript doesn’t have any Widget configuration for width and height, then the following might work:

DestroyModuleConfig FE-SP:*
*FE-SP: destroy_window SavePositionFunc

AddToFunc StartFunction I Module FvwmEvent FE-SP

The above sets up a module alias which is used along with FvwmEvent – asking it to listen on the destroy_window event which happens just before the window is unmapped (which is how we’re able to ascertain its position). When this event occurs, it will try and run the function SavePositionFunc. The module is then asked to load when FVWM starts up.

As to what the SavePositionFunc does, we’ll simply append a tiny FVWM configuration to a known file. Then we must add a static entry to your ~/.fvwm/config file (or similar) to Read this file in. So, here it is:

DestroyFunc SavePositionFunc
AddToFunc    SavePositionFunc
+ I ThisWindow (SomeWindowClassWeWantToSave) \
      PipeRead `echo Style $[w.class] PositionPlacement $[w.x] $[w.y], StartsOnPage $[desk.n] $[page.nx] $[page.ny] > /some/predefined/location`

Which, assuming the window in question matched “SomeWindowClassWeWantToSave”, would have an entry in the file “/some/predefined/location” each time the window was closed.

Hence now, all that’s left to do in your ~/.fvwm/config file is this:

Read /some/predefined/location Quiet


– Thomas Adam


I changed the function a bit. It replaces the “WindowPosition” line on script exit with the new position coordinates.

DestroyFunc SavePositionFunc
AddToFunc   SavePositionFunc
+ I ThisWindow (FvwmScript) PipeRead `sed 's/^.*WindowPosition.*$/WindowPosition $[w.x] $[w.y]/' /home/.fvwm/scripts/$[]/$[] > /home/.fvwm/scripts/$[]/$[]_new && mv /home/.fvwm/scripts/$[]/$[]_new /home/.fvwm/scripts/$[]/$[]`

Thanks again!