From 616afa9460c7f93c45e354e7013d92963d11e5f2 Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sun, 19 Mar 2023 13:14:18 +0100 Subject: [PATCH] Made setting/getting window mode easier --- wmgr.gd | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/wmgr.gd b/wmgr.gd index 522c3e5..bd62c53 100644 --- a/wmgr.gd +++ b/wmgr.gd @@ -31,25 +31,18 @@ func set_title(title:String) -> void: DisplayServer.window_set_title(title) window_title = title -func set_windowed() -> void: - Logger.info("wmgr","Applying new window mode (windowed)") - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) - -func set_minimized() -> void: - Logger.info("wmgr","Applying new window mode (minimized)") - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED) - -func set_maximized() -> void: - Logger.info("wmgr","Applying new window mode (maximized)") - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MAXIMIZED) - -func set_fullscreen() -> void: - Logger.info("wmgr","Applying new window mode (fullscreen)") - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) - -func set_fullsceen_exclusive() -> void: - Logger.info("wmgr","Applying new window mode (exclusive fullscreen)") - DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN) +func set_mode(mode:String) -> bool: + Logger.info("wmgr","Applying new window mode (" + mode + ")") + match(mode): + "WINDOWED": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) + "MINIMIZED": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MINIMIZED) + "MAXIMIZED": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_MAXIMIZED) + "FULLSCREEN": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) + "EXCLUSIVE_FULLSCREEN": DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_EXCLUSIVE_FULLSCREEN) + _: + Logger.error("wmgr","Invalid window mode \"" + mode + "\".") + return false + return true func get_size() -> Vector2i: return DisplayServer.window_get_size() @@ -60,8 +53,16 @@ func get_position() -> Vector2i: func get_title() -> String: return window_title -func get_mode() -> int: - return DisplayServer.window_get_mode() +func get_mode() -> String: + match(DisplayServer.window_get_mode()): + 0: return "WINDOWED" + 1: return "MINIMIZED" + 2: return "MAXIMIZED" + 3: return "FULLSCREEN" + 4: return "EXCLUSIVE_FULLSCREEN" + _: + Logger.error("wmgr","Failed to get window mode: The window mode id \"" + str(DisplayServer.window_get_mode()) + "\" is not known to CORE.") + return "INVALID_MODE" func _ready() -> void: Logger.info("wmgr","Configuring window")