Skip to content

Commit cbabf1f

Browse files
committed
Save and restore window size
1 parent 5ee9865 commit cbabf1f

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

data/com.ranfdev.DistroShelf.gschema.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,15 @@
66
<summary>Selected terminal emulator</summary>
77
<description>The terminal emulator selected by the user.</description>
88
</key>
9+
<key name="window-width" type="i">
10+
<default>900</default>
11+
<summary>Window width</summary>
12+
<description>The width of the main window when last closed.</description>
13+
</key>
14+
<key name="window-height" type="i">
15+
<default>700</default>
16+
<summary>Window height</summary>
17+
<description>The height of the main window when last closed.</description>
18+
</key>
919
</schema>
1020
</schemalist>

src/window.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ impl DistroShelfWindow {
116116
.property("root-store", root_store)
117117
.build();
118118

119+
// Restore window size from settings
120+
let settings = gio::Settings::new("com.ranfdev.DistroShelf");
121+
let width = settings.int("window-width");
122+
let height = settings.int("window-height");
123+
this.set_default_size(width, height);
124+
119125
this.setup_gactions();
120126
let this_clone = this.clone();
121127
this.root_store()
@@ -162,6 +168,16 @@ impl DistroShelfWindow {
162168
this.build_sidebar();
163169
this.root_store().load_containers();
164170

171+
// Save window size when closing
172+
let this_clone = this.clone();
173+
this.connect_close_request(move |_| {
174+
let (width, height) = this_clone.default_size();
175+
let settings = gio::Settings::new("com.ranfdev.DistroShelf");
176+
let _ = settings.set_int("window-width", width);
177+
let _ = settings.set_int("window-height", height);
178+
glib::Propagation::Proceed
179+
});
180+
165181
this
166182
}
167183

0 commit comments

Comments
 (0)