Application that "remembers desk + page"

I would be interested to add something in my .fvwm2rc like remembering the desk + page when I close the window. Then when launching again the application, the window would be at same page and desktop, like where I left it when closing. I read that I could do that with the event with add_window, but no idea how. Is there some code for that ?

You want to modify the very functions I wrote here: … 7621163157

Except that where you’re writing out the window class, you would write out in addition:

Style $[w.class] StartsOnPage $[desk.n] $[page.nx] $[page.ny]

– Thomas Adam

Whao, that was a very fast reply, but actually you did not reply the question. In the provided link, there is only “Remembering the state of maximised windows.”. In my case, it is rather general, just remembering desk + page, what they were. (no maximized windows) :confused: :frowning:

I thought maybe you might have been able to adapt them. Sigh.

Here’s what you want:

Set-up FvwEvent:

DestroyModuleConfig FE-DP: *
*FE-DP: Cmd Function
*FE-DP: destroy_window FuncCheckWindowDW

Module FvwmEvent FE-DP

The pre-condition here is that when all of this runs first, you’re going to have to set the style for the window yourself, and let the file controlled by FvwmEvent override it.

DestroyFunc FuncCheckWindowDW
AddToFunc   FuncCheckWindowDW
+ I Test (!F $[FVWM_USERDIR]/stylestates) Exec exec touch $[FVWM_USERDIR]/stylestates
+ I PipeRead 'if grep -q \"$[]\" \
      $[FVWM_USERDIR]/stylestates; then \
      sed -ie "/\"$[]\"/d;" $[FVWM_USERDIR]/stylestates; fi'
+ I PipeRead 'if ! grep -q \"$[]\" \
      $[FVWM_USERDIR]/stylestates; then \
      echo "Style \"$[]\" StartsOnPage $[w.desk] $[page.nx] $[page.ny], SkipMapping" >> $[FVWM_USERDIR]/stylestates; fi'
+ I Read $./stylestates

So what the above does is everything on when a window closes. You don’t need to check what happens when a window is mapped because it’s already been taken care of. When you close a window, what happens is that the entry for it (based on the window’s name) is deleted and then re-entered into the ‘stylestates’ file.

Once that has happened, the file is then read by FVWM. So to explain this. Assume you closed a window called “buttons”. Here’s what you’d see in this stylestates:

Style "buttons" StartsOnPage 0 1 2

Where the numbers “0 1 2” are for wherever the window is at the time it’s closed. Then the entire file is re-read by FVWM. Such that when a window is next launched matching those lines, FVWM should be moving said window to wherever it was.

Oh, one more thing. This file will need to be read at Init:

AddToFunc StartFunction I Test (Init) Read $./stylestates

Not tested. Change at your leisure. Note that using $[] here is potentially disasterous, and if you can use $[w.class] try to do so – but at some point you’re going to run into problems due to the way FVWM interprets its style lines. In the case we’re using, the function just appends its information. Hence for each style read the last match is always going to win. In the cases of specific matching this might not be what you want at all.

– Thomas Adam

thanks, I just to note, that I understood anything.
I added the code in green to the config and nothing happened like requested above.

Hmm? Then you can’t have added it right. It’s working fine here. Can you be more specific?

– Thomas Adam

The only thing which might make it not work, is the use of:

sed -i

That’s not portable at all, and is in fact doing under the hood this:

sed -e '...' < ./file > ./output.file && mv ./output.file ./file

You should check that and change it as apropos.

– Thomas Adam