Skip to content

Commit 72ffa6f

Browse files
committed
Remember window size #51
1 parent 3fd036e commit 72ffa6f

3 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/components/settings/settings_window.gd

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ func _prepare_settings():
2929
Config.USE_SYSTEM_TITLE_BAR,
3030
SettingCheckbox
3131
))), func(): return DisplayServer.has_feature(DisplayServer.FEATURE_EXTEND_TO_TITLE)),
32+
SettingChangeObserved(SettingCfg(
33+
"application/config/remember_window_rect",
34+
Config.REMEMBER_WINDOW_SIZE,
35+
SettingCheckbox,
36+
tr("Restore last window size and position on startup.")
37+
)),
3238

3339
SettingRestartRequired(SettingChangeObserved(SettingCfg(
3440
"application/theme/preset",

src/config.gd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ var USE_SYSTEM_TITLE_BAR = ConfigFileValue.new(
135135
set(_v): _readonly()
136136

137137

138+
var LAST_WINDOW_RECT = ConfigFileValue.new(
139+
_cfg_auto_save,
140+
"app",
141+
"last_window_rect",
142+
Rect2i()
143+
):
144+
set(_v): _readonly()
145+
146+
147+
var REMEMBER_WINDOW_SIZE = ConfigFileValue.new(
148+
_cfg_auto_save,
149+
"app",
150+
"remember_window_size",
151+
false
152+
):
153+
set(_v): _readonly()
154+
155+
138156
var ALLOW_INSTALL_TO_NOT_EMPTY_DIR = ConfigFileValue.new(
139157
_cfg_auto_save,
140158
"app",

src/main/gui/gui_main.gd

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,23 @@ func _enter_tree():
161161
screen_rect.position.y + (screen_rect.size.y - window_size.y) / 2
162162
)
163163
DisplayServer.window_set_position(window_position)
164+
164165
window.min_size = Vector2(700, 350) * Config.EDSCALE
166+
if Config.REMEMBER_WINDOW_SIZE.ret():
167+
var rect = Config.LAST_WINDOW_RECT.ret(Rect2i(
168+
window.position,
169+
window.min_size
170+
)) as Rect2i
171+
if DisplayServer.get_screen_from_rect(rect) != -1:
172+
window.size = rect.size
173+
window.position = rect.position
165174

166175

167176
func _exit_tree():
168177
for callback in _on_exit_tree_callbacks:
169178
callback.call()
179+
var window = get_window()
180+
Config.LAST_WINDOW_RECT.put(Rect2i(window.position, window.size))
170181

171182

172183
func _popup_manage_tags(item_tags, all_tags, on_confirm):

0 commit comments

Comments
 (0)