Remember the maximized state

Hello, sometimes i like use Gnome and there is a feature i like a lot : when i close a window maximized, when i run it again, it is maximized !

With Fvwm when you close a window maximized and you run it again later there is only the width and height which are saved. Not the Maximized state. The thing i would like to have : when i close a maximized window and when i run it later, this window must have the previous State (so : Maximized and not just the previous height and width).

How can i do that ? I think use FvwmEvent with “destroy_window” and “add_window” but after, how to test if when the window is closed, it was maximized ?

Thanks for your help and sorry for my English, i hope you undestand well !

This is a more annoying feature, in my opinion. This is because those applications invariable use the PPosition hint that the window sets, rather than allowing the user to specify arbitrary window locations (via --geometry for instance.)

But this is intentional. It is fair to say that if you take firefox for instance (which is a good example of an application that uses PPosition as it’s primary window hint) and maximize it, and then close it again, when you reopen it, it will take up the entire screen as though it were maximized. Of course, the reason why the actual window is not registered as such is because the application doesn’t record that state – and why should it?

The best way around this, is to use FvwmEvent as you say — but does it really matter if the application effectively starts up virutally maximized, anyway?

– Thomas Adam

Yes it does, indeed i use this with my side bar.
Do you know how to remember this state ?

You don’t even need to remember the state. What I would do instead is negate the problem you have, and say that for any programs you know that you’re going to want to maximize, do it when they’re initially opened. So, something like this:

DestroyModuleConfig FE-rw: *
*FE-rw: Cmd Function
*FE-rw: add_window FuncMaximizeFully

This sets up the initial event, to watch for windows that are created, and then run the function ‘FuncMaximizeFully’. Then define the function:

DestroyFunc FuncMaximizeFully
AddToFunc FuncMaximizeFully
+ I ThisWindow ("gFTP|gvim", !Maximized) Maximize

Here, I’ve used “gFTP” and “gvim” as example programs that use PPosition by default. Note the syntax of “program1|program2” which means “OR”. So you can just add the program class names here, as you see fit for those windows you wish to maximize.

Last thing to do is start it:

AddToFunc StartFunction I Module FvwmEvent FE-rw

Of course, there are some other things to consider here, such as the style lines of the programs that you’ll use in this way. I might suggest that you add:

Style foo NoPPosition

Since it doesn’t matter in this case what happens — the window is going to get maximized anyway.

Hope That Helps,

– Thomas Adam

Thanks for your help but it doesn’t do exactly what i want.

Indeed, if i close Firefox while it isn’t maximized, i don’t want get it maximized when i run it later. Do you understand ? That’s why i want to remember the state. If the window wasn’t maximized, it won’t be maximized when i will open it. If it was maximized, when i will open it : i want it maximized.

Ok, it works !

Look at this :

[code]DestroyFunc AddWindowFunc
AddToFunc AddWindowFunc

  • I ThisWindow (irssi) Move 30p 135p
  • I Test (EnvMatch max true) ThisWindow (Firefox-bin) Maximize

DestroyFunc CloseWindowFunc
AddToFunc CloseWindowFunc

  • I ThisWindow (Firefox-bin, Maximized) SetEnv max true
  • I TestRc (NoMatch) SetEnv max false

DestroyModuleConfig FvwmEvent: *
*FvwmEvent: new_desk NewDeskFunc
*FvwmEvent: add_window AddWindowFunc
*FvwmEvent: destroy_window CloseWindowFunc[/code]
It works fine :slight_smile:

But it only works for ONE window, indeed i need to set up several SetEnv for each windows. For instance : if i close firefox while it was maximized and i open Gvim, it will be maximized (if i add it to the AddWindowFunc). I have to find another way to do this task…

I wouldn’t start polluting the environment in this way. What I would do is setup a manual tracker based on a flat-file. This file will store the states of the windows it needs to know about. As before I’ll use an event from last time:

DestroyModuleConfig event: *
*event: Cmd Function
*event: add_window FuncAW
*event: destroy_window FuncDW

Module FvwmEvent event

… which we’re all used to by now. Then the functions:

DestroyFunc FuncFvwmAW
AddToFunc   FuncFvwmAW
+ I ThisWindow PipeRead `\
while read; do \
[[ "$REPLY" == "$[w.class]" ]] && \
echo 'ThisWindow (!Maximized) Maximize' || \
echo Nop; done < $[FVWM_USERDIR]/windowlist`

Quite straight-forward. Since we’re tracking window that need to be maximized if they weren’t before, and appear in our list, we need to check for that. So, the idea is that we read in this file a line at a time, amd match it against the state of the window that has just been mapped. If we find the class of this window matches one in the list o files we’re reading in, the maximize this window, else do nothing.

Then all that needs to happen is the inverse of this for when a window is closed:

DestroyFunc FuncFvwmDW
AddToFunc   FuncFvwmDW
+ I ThisWindow (Maximized) Exec /bin/sh -c 'if ! grep -q $[w.class] $[FVWM_USERDIR]/windowlist; then echo $[w.class] >> $[FVWM_USERDIR]/windowlist; fi'
+ I ThisWindow (!Maximized) Exec /bin/sh -c 'if grep -q $[w.class] $[FVWM_USERDIR]/windowlist; then sed -ie "/$[w.class]/d;" $[FVWM_USERDIR]/windowlist; fi'

What this does, is it checks the state of the window being closed. If it is maximized then the windowlist is checked to see if we’ve seen this window before. If we haven’t we’ll log it as a candidate to be maximized next time around.

If, on the other hand, we have seen this window before, then we simply remove the entry from the file, and that’s it.

There’s a few issues though – and I have cheated somewhat. You’ll note that for the removal of the window class from the windowlist file, I have used sed. This is fine, but the “-i” flag (for in-place editing) is not POSIX. Ideally, I should use:

+ I ThisWindow (!Maximized) Exec /bin/sh -c 'if grep -q $[w.class] $[FVWM_USERDIR]/windowlist; then sed -e "/$[w.class]/d;" < $[FVWM_USERDIR]/windowlist > $[FVWM_USERDIR]/.temp && mv $[FVWM_USERDIR]/.temp $[FVWM_USERDIR]/windowlist; fi'

… which is also the case if you don’t have a fairly recent version of GNU sed.

Other considerations: I’ve used the window’s class as an identifier – because it is unique. In this case though, it might be too specific for your needs (imagine all instances of class ‘Xterm’ maximizing, for instance.) If you find this to be the case, change to using $[] in all instances – especially if you’ve named, say, xterms different things (which aren’t, obviously, depicted in the window’s class.)

– Thomas Adam

Thank you very much ! It works perfectly. I understand what you said and now i will try to use files with bash and/or Sed instead of pollute the environment. It is exactly what i wanted :slight_smile:

Hello, your solution works fine but there is a thing i don’t understand. After a while, there is another file which is created : "windowliste
Do you know where does it come from ?

I assume you mean “windowlist” as the file that’s created? That’s the file that holds the class names of the windows to be maximized next time they appear. Any other files that are created, as not as a result of running those functions.

– Thomas Adam

No you didn’t understand. Indeed i have the file “windowlist”, but after a while, i have another file (with the same contents) called “windowliste”.

ls .fvwm/ files images scripts test_menu theme windowlist windowliste

I don’t know where the “windowliste” file comes from – it’s not from my original functions posted here (I see you have them in your config file on the web, modified slightly). I can only conclude that you must have some other FvwmEvent instance running that outputs something (maybe nothing – you haven’t said) to this windowliste file.

Did you change the output file to windowliste originally, to be more… umm, French?

– Thomas Adam