Fullscreen and windowed with f11 madness

Godot Version

Godot 4.3 C# stable

Question

HELP!! I need help figuring out how to make a toggle for fullscreen and windowed.
I have tried YouTube, Google, and chat-GPT. (The project defaults to fullscreen) Here’s the code
“”

extends Node

var screen = true

func _process(_delta):
	if screen == true:
		DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_FULLSCREEN, 0)
		if Input.is_action_just_pressed("fullscreen"):
			screen = false
	else:
		DisplayServer.window_set_mode(DisplayServer.WindowMode.WINDOW_MODE_WINDOWED, 0)
		if Input.is_action_just_pressed("fullscreen"):
			screen = true

“”
(and yes I have gone to settings and turned on globals for the script)

Hi,

I use the following code, when starting my App. It looks at a value saved in my app config file to determine what mode to set.

match get_xml_key_data("win",file_data):
		"0","1","2":
	        DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)
						
		"3":
			DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)

When exiting the program I get the window mode and save it to my config file.

Ryn

Make sure to format your scripts when pasting.

No need for your script to be in _process, it does not need to run every frame. Use _input and check event.is_action_pressed("fullscreen")

Here’s a slim script that can be placed as a Global as you’ve mentioned

extends Node

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("fullscreen"):
		var mode := DisplayServer.window_get_mode()
		var window: bool = mode != DisplayServer.WINDOW_MODE_FULLSCREEN
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN if window else DisplayServer.WINDOW_MODE_WINDOWED)
2 Likes

Hello @gertkeno, I saw your response and tried the code you placed. It worked, but the code does not work with fullscreen as the default. (Which is the problem.) Here’s the error that Godot says.

‘’’
E 0:00:03:0624 affine_invert: Condition “det == 0” is true.
<C++ Source> core/math/transform_2d.cpp:51 @ affine_invert()
‘’’

Works for me, are you sure it’s the same script? my example should not produce an affine_invert call.

I am using the Godot version 4.3 mono (stable)


When the game starts in fullscreen the first time pressing f11 it does nothing the second time it crashes the window(but not the game). And gives the same error.

crashes the window? Are you sure it’s not still open in the background? Looks like it’s still in the task bar. I am also on 4.3

that’s what I meant. But it won’t open when I place my mouse on top of the icon and when I click, well. See for yourself.

Side Note: Sorry that I took so long, I was at the cinema. And making the video shorter so that the Godot Forum accepts it.

Sorry to say I just can’t reproduce this behaviour, maybe it doesn’t like borderless on your system? You could add that to the script if it helps?

extends Node

func _input(event: InputEvent) -> void:
	if event.is_action_pressed("fullscreen"):
		var window: bool = DisplayServer.window_get_mode() != DisplayServer.WINDOW_MODE_FULLSCREEN
		DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN if window else DisplayServer.WINDOW_MODE_WINDOWED)

		var borderless: bool = DisplayServer.window_get_flag(DisplayServer.WINDOW_FLAG_BORDERLESS)
		DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, not borderless)
2 Likes

THANK YOU!!! You are the type of person who helps others make games and inspires others to help others.