From 199589924b1e260a5a2c456d50f6c0f6a9a2295d Mon Sep 17 00:00:00 2001 From: Hugo Locurcio Date: Tue, 19 Nov 2019 22:36:37 +0100 Subject: [PATCH] Remember the window position and size across restarts This makes it more convenient to use Pixelorama, especially when using multiple monitors. The associated cache configuration file could be reused in the future to store other kinds of "semi-persistent" data. --- Scripts/Main.gd | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Scripts/Main.gd b/Scripts/Main.gd index d56af8d01..d4f0447c6 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -1,5 +1,6 @@ extends Control +var config_cache : ConfigFile = ConfigFile.new() var current_save_path := "" var current_export_path := "" var opensprite_file_selected := false @@ -21,6 +22,20 @@ func _ready() -> void: # This property is only available in 3.2alpha or later, so use `set()` to fail gracefully if it doesn't exist. OS.set("min_window_size", Vector2(1152, 648)) + # Restore the window position/size if values are present in the configuration cache + config_cache.load("user://cache.ini") + + if config_cache.has_section_key("window", "screen"): + OS.current_screen = config_cache.get_value("window", "screen") + if config_cache.has_section_key("window", "maximized"): + OS.window_maximized = config_cache.get_value("window", "maximized") + + if !OS.window_maximized: + if config_cache.has_section_key("window", "position"): + OS.window_position = config_cache.get_value("window", "position") + if config_cache.has_section_key("window", "size"): + OS.window_size = config_cache.get_value("window", "size") + var file_menu_items := { "New..." : KEY_MASK_CTRL + KEY_N, "Open..." : KEY_MASK_CTRL + KEY_O, @@ -818,3 +833,11 @@ func _on_RightHorizontalMirroring_toggled(button_pressed) -> void: Global.right_horizontal_mirror = button_pressed func _on_RightVerticalMirroring_toggled(button_pressed) -> void: Global.right_vertical_mirror = button_pressed + +func _exit_tree() -> void: + # Save the window position and size to remember it when restarting the application + config_cache.set_value("window", "screen", OS.current_screen) + config_cache.set_value("window", "maximized", OS.window_maximized || OS.window_fullscreen) + config_cache.set_value("window", "position", OS.window_position) + config_cache.set_value("window", "size", OS.window_size) + config_cache.save("user://cache.ini")