Godot Version
4.6.3 stable
Question
OK so my game had a simple fullscreen toggle function.
The project is set Window / Mode = Windowed in editor settings.
There’s a fullscreen bool, that starts out false, and whenever you pressed F11, it calls a simple flipper:
if fullscreen:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
print(fullscreen, " so set to windowed")
fullscreen = false
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
print(fullscreen, " so set to full")
fullscreen = true
It worked fine.
However, I have started working on a config system, and the first thing I’ve implemented is remembering the value of fullscreen and restoring it correctly. Here I hit a strange snag.
The process is thus:
- called off the _ready() function of the main scene, the value of
fullscreenis read from file (if no file, it is initialized tofalse) - a function is called with said value:
func set_fullscreen(val : bool):
fullscreen = val
if val == true:
print ("setup said ", val, " so full")
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
print ("setup said ", val, " so window")
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
- when the game is closed, the script checks the current value of
fullscreenand writes it to config file
Here’s the snag:
The system works fine if the loaded setting is false. The game starts windowed, F11 flips to fullscreen, F11 again flips to windowed, etc.
BUT
If the loaded setting is true, the game starts fullscreen… but the first F11 sets the game fullscreen again, and only the second F11 flips to window. This is NOT an issue with bools. Based on the print() logging above, in this situation, upon the first F11 the game logs correctly true so set to windowed, but remains fullscreen; the second F11 logs false so set to full, and the game becomes windowed. In other words, DisplayServer.window_set_mode behaves incorrectly.
How to remedy this?