From 72a985a9e4c939df11ea1bfe3adbf9c712010f5a Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 13 Nov 2024 18:40:43 +0100 Subject: [PATCH] also save window position --- data/eu.callcc.audrey.gschema.xml | 9 +++++++++ src/ui/window.rs | 25 +++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/data/eu.callcc.audrey.gschema.xml b/data/eu.callcc.audrey.gschema.xml index a68f494..e6ca50c 100644 --- a/data/eu.callcc.audrey.gschema.xml +++ b/data/eu.callcc.audrey.gschema.xml @@ -6,6 +6,15 @@ 100 + + + -1 + + + -1 + + + false diff --git a/src/ui/window.rs b/src/ui/window.rs index 03861b4..0793d9b 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -172,7 +172,15 @@ mod imp { let settings = gio::Settings::new(crate::APP_ID); settings.bind("mute", self.obj().as_ref(), "mute").build(); - settings.bind("volume", self.obj().as_ref(), "volume").build(); + settings + .bind("volume", self.obj().as_ref(), "volume") + .build(); + + self.obj() + .set_default_size(settings.int("window-width"), settings.int("window-height")); + if settings.boolean("is-maximized") { + self.obj().maximize(); + } // update time-pos every 100 ms let window = self.obj().downgrade(); @@ -293,7 +301,20 @@ mod imp { } } - impl WindowImpl for Window {} + impl WindowImpl for Window { + fn close_request(&self) -> glib::Propagation { + let size = self.obj().default_size(); + // TODO: don't instantiate this so many times maybe? OnceCell in imp struct? + let settings = gio::Settings::new(crate::APP_ID); + settings.set_int("window-width", size.0).unwrap(); + settings.set_int("window-height", size.1).unwrap(); + settings + .set_boolean("is-maximized", self.obj().is_maximized()) + .unwrap(); + + glib::Propagation::Proceed + } + } impl ApplicationWindowImpl for Window {}