@lucamar Ah cool, that's good to know, thanks!
I did realize that indeed the window dimensions are correctly preserved if you change the order like User137 suggested. I wasn't sure how to toggle in Pascal, but your method is cleaner than writing isFullscreen in two separate places as well. So this is my current state for the record:
procedure TForm1.ToggleFullscreen;
begin
if isFullscreen then begin
// go to normal -> fullscreen -> normal/restored so it works in GNOME for me
WindowState := wsNormal;
WindowState := wsFullScreen;
WindowState := RestoredWindowState;
BorderStyle := RestoredBorderStyle;
end
else begin
RestoredBorderStyle := BorderStyle;
RestoredWindowState := WindowState;
{$IFDEF WINDOWS}
BorderStyle := bsNone;
{$ENDIF}
WindowState := wsFullScreen;
end;
isFullscreen := not isFullscreen;
end;
Thanks again for your help and suggestions.
P.S.: There is another improvement: When the window is maximized, and you go into fullscreen, it is restored as wsNormal instead of being wsMaximized again. Additionally, probably it's a good idea to store the BorderStyle, too. I edited my code appropriately.
There is also this:
http://wiki.freepascal.org/Application_full_screen_mode. You need 'uses LCLIntf' for ShowWindow function.
P.P.S.: After further testing, I have come to the conclusion that even using RestoredLeft and RestoredTop, the result is for me not satisfactory: If you really want to window to always end up in the position it was before, store your own Left/Top. (For example if you use poDesktopCenter etc. the window won't go back to the side, if you had it all the way on the side)