diff --git a/docs/docs/reference/config.md b/docs/docs/reference/config.md
index 0a40c23..561185b 100644
--- a/docs/docs/reference/config.md
+++ b/docs/docs/reference/config.md
@@ -19,6 +19,8 @@ Unlocks experimental features.
Allows or disallows custom modules.
### *bool* automatic_shutdown = *true*
If `quit_safely` (and by extension `Core.cleanup`) should be called when pressing the X.
+### *bool* hide_window_on_shutdown = *true*
+Hides the window during engine shutdown. Useful when your game and the framework will take longer to cleanup.
## Logger
### *CoreTypes.LoggerLevel* logger_level = *CoreTypes.LoggerLevel.INFO*
diff --git a/src/classes/config.gd b/src/classes/config.gd
index 4b4ce2b..a042978 100644
--- a/src/classes/config.gd
+++ b/src/classes/config.gd
@@ -19,6 +19,8 @@ class_name CoreConfiguration
@export var custom_modules: bool
## If [method Core.quit_safely] (and by extension [method Core.cleanup]) should be called when pressing the X.
@export var automatic_shutdown: bool
+## Hides the window during engine shutdown. Useful when your game and the framework will take longer to cleanup.
+@export var hide_window_on_shutdown: bool
@export_category("Logger")
## The minimum log level you want to be displayed.
@@ -67,6 +69,7 @@ func _init() -> void:
development = false
custom_modules = false
automatic_shutdown = true
+ hide_window_on_shutdown = true
# Logger
logger_level = CoreTypes.LoggerLevel.INFO
diff --git a/src/core.gd b/src/core.gd
index 40fa1c1..ea884ed 100644
--- a/src/core.gd
+++ b/src/core.gd
@@ -415,6 +415,21 @@ func check_godot_version() -> bool:
## [b]Note: [i]Using the [code]await[/code] keyword is required for this function.[/i][/b]
func quit_safely(exitcode: int = 0) -> void:
loggeri.info("Shutting down (code " + str(exitcode) + ")")
+ if config.hide_window_on_shutdown:
+ loggeri.verb("Hiding window")
+ Engine.max_fps = -1 # a higher framerate seems to make the shutdown process muuuuch faster
+ DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED) # we don't want to cook the cpu tho
+ DisplayServer.window_set_exclusive(0, false)
+ DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED)
+ DisplayServer.window_set_min_size(Vector2.ZERO)
+ DisplayServer.window_set_size(Vector2i.ZERO)
+ DisplayServer.window_set_max_size(Vector2.ZERO)
+ DisplayServer.window_set_position(Vector2i(9999999, 9999999))
+ DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_BORDERLESS, true)
+ DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_ALWAYS_ON_TOP, false)
+ DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_MOUSE_PASSTHROUGH, false)
+ DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_NO_FOCUS, true)
+ DisplayServer.window_set_flag(DisplayServer.WINDOW_FLAG_RESIZE_DISABLED, true)
await get_tree().create_timer(0.25).timeout
await cleanup()
get_tree().quit(exitcode)