godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.33k stars 21.24k forks source link

Repeated toggle fullscreen increases window size by the window decorations size each time we leave fullscreen #90537

Open hsandt opened 7 months ago

hsandt commented 7 months ago

Tested versions

System information

Godot v4.2.1.stable - Ubuntu 22.04.4 LTS 22.04 - X11 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 860M (nvidia; 535.161.07) - Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz (8 Threads)

Issue description

Repeating toggle fullscreen (DisplayServer.window_set_mode with DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN (or WINDOW_MODE_FULLSCREEN) and DisplayServer.WINDOW_MODE_WINDOWED alternatively) increases the window size each time you leave fullscreen.

This was very visible in my game as I'm using aspect keep, so black edges were immediately visible.

I tried again in a MWE and found out that the exact size delta is equal to the window decorations size (obtained by computing ` DisplayServer.window_get_size_with_decorations() - DisplayServer.window_get_size()).

Test on Linux Ubuntu 22.04 with Unity desktop, where the decorations are just the window titlebar.

2024-04-11 Godot 4.2.1 repeated toggle fullscreen increase window size.webm

Steps to reproduce

  1. Open MRP > demo scene
  2. Run the game
  3. Press F or F11 to toggle fullscreen multiple times
  4. Check Output log each time you leave fullscreen and observe delta in window size, equal to window decorations size
  5. If you do it enough you will see the window get bigger with bare eyes too

Minimal reproduction project (MRP)

v4.2.1 - Toggle full screen repeated causes window height to accumulate extra.zip

hsandt commented 7 months ago

My current workaround is to store the previous window size (before going fullscreen) and restore it manually after leaving fullscreen:

if new_window_mode == DisplayServer.WINDOW_MODE_WINDOWED:
    DisplayServer.window_set_size(previous_window_size)

You still see a short glitch as the window fixes itself, but after that the window size is the expected one.

hsandt commented 7 months ago

I tested the equivalent Window method just to be sure (as it turned out to fix the issue on another Window issue https://github.com/godotengine/godot/issues/89543), but it didn't help.

var window := get_window()
# alternate this via action input
window.mode = Window.MODE_EXCLUSIVE_FULLSCREEN
window.mode = Window.MODE_WINDOWED

The issue still occurs when doing this instead of using DisplayServer.