Add ability to hide the window on shutdown

This commit is contained in:
JeremyStar™ 2024-04-24 01:41:21 +02:00
parent 971b15adfc
commit 5a02c10080
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D
3 changed files with 20 additions and 0 deletions

View file

@ -19,6 +19,8 @@ Unlocks experimental features.
Allows or disallows custom modules.
### *bool* <u>automatic_shutdown</u> = *true*
If `quit_safely` (and by extension `Core.cleanup`) should be called when pressing the X.
### *bool* <u>hide_window_on_shutdown</u> = *true*
Hides the window during engine shutdown. Useful when your game and the framework will take longer to cleanup.
## Logger
### *CoreTypes.LoggerLevel* <u>logger_level</u> = *CoreTypes.LoggerLevel.INFO*

View file

@ -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

View file

@ -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)