Inconsistent behavior switching between Fullscreen and Windowed Mode

Godot Version

4.5

Question

I’m trying to set up basic window options for Fullscreen, and Windowed.

The game starts in fullscreen, but when I hit the windowed button I get inconsistent behavior. The first time I hit it, the screen flickers like it’s doing something, but it seems to still be in fullscreen mode (no header bar).

However, if I press the fullscreen button and then press the windowed button again, now it is in windowed mode, filling the whole screen aside from the OS header, with the window header present.

If I repeat this one more time, pressing the fullscreen button and then the windowed button once more, it does go to windowed mode, but now the window is smaller and sized to about a quarter of the screen size.

Any idea what could be causing this? I’m using fairly basic code here:

For Fullscreen:

DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)

For Windowed:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)

Added note:
This occurs whether I use Fullscreen or Exclusive Fullscreen. I also saw that fullscreen forces the borderless flag to true, so I accounted for that when switching to windowed mode.

Second note:
I switched from a button based approach to a OptionButton based one and it works as expected. So weird. I’d still like to try to figure out why the buttons don’t work properly, but at least I have something working.

1 Like

If you put a print statement in your button-based approach, I wonder if you’d find that it was being invoked twice or something.

I found I had to keep my own boolean to track the state and only fire the window_set_mode() call if the desired state was not the current state.

That’s strange that it would work for OptionButton but not Button. I also use the option dropdown and it has worked for me.

The first thing I think of would be embedding your window in the editor. I know that doesn’t play nice with switching the video settings around, though I’m not too familiar as I no longer have my project embed the game.

There’s the obvious possibility that there was a slip-up with an extra connection or a typo or something and redoing it fixed the issue.

Maaybe the signal you were using for button was wrong and picking up multiple inputs? Doesn’t seem like that would be the case though.

Seems like you figured it out, but in-case someone else needs it as reference you set the borderless window flag to false with this:

DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, false)

I remember running into issues with where the window was centered as well, so here’s how I solved that in-case it helps.

var center_screen = DisplayServer.screen_get_position() + DisplayServer.screen_get_size() / 2
var window_size = get_window().get_size_with_decorations()
var new_window_position = center_screen - window_size / 2
get_window().set_position(new_window_position)