[gnome-clocks] Improve saving/loading of window size
- From: Bilal Elmoussaoui <bilelmoussaoui src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Improve saving/loading of window size
- Date: Fri, 7 Jan 2022 17:23:45 +0000 (UTC)
commit 316537107ccb7018f38bf7807e2c700996e6b27a
Author: Maximiliano Sandoval R <msandova gnome org>
Date: Tue Dec 14 01:00:58 2021 +0100
Improve saving/loading of window size
build-aux/flatpak/org.gnome.clocks.json | 3 ++-
src/window.vala | 46 +++++++++++++++++++++++----------
2 files changed, 35 insertions(+), 14 deletions(-)
---
diff --git a/build-aux/flatpak/org.gnome.clocks.json b/build-aux/flatpak/org.gnome.clocks.json
index d16a75f8..8e5d221c 100644
--- a/build-aux/flatpak/org.gnome.clocks.json
+++ b/build-aux/flatpak/org.gnome.clocks.json
@@ -16,7 +16,8 @@
"--filesystem=xdg-run/dconf",
"--filesystem=~/.config/dconf:ro",
"--talk-name=ca.desrt.dconf",
- "--env=DCONF_USER_CONFIG_DIR=.config/dconf"
+ "--env=DCONF_USER_CONFIG_DIR=.config/dconf",
+ "--env=G_MESSAGES_DEBUG=org.gnome.ClocksDevel"
],
"cleanup": ["/include", "/lib/pkgconfig",
"/share/pkgconfig", "/share/aclocal",
diff --git a/src/window.vala b/src/window.vala
index acbf42fc..6ee3afe2 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -99,19 +99,7 @@ public class Window : Adw.ApplicationWindow {
pane_changed ();
- // Setup window geometry saving
- var window_maximized = settings.get_boolean ("maximized");
- if (window_maximized) {
- maximize ();
- } else {
- int width, height;
- width = settings.get_int ("width");
- height = settings.get_int ("height");
- set_default_size (width, height);
- }
- settings.bind ("maximized", this, "maximized", SettingsBindFlags.SET);
- settings.bind ("width", this, "default-width", SettingsBindFlags.SET);
- settings.bind ("height", this, "default-height", SettingsBindFlags.SET);
+ load_window_state ();
world.show_standalone.connect ((w, l) => {
stack.visible_child = w;
@@ -223,6 +211,38 @@ public class Window : Adw.ApplicationWindow {
world.add_location (location);
}
+ public override bool close_request () {
+ save_window_state ();
+ return base.close_request ();
+ }
+
+ private void load_window_state () {
+ var window_maximized = settings.get_boolean ("maximized");
+ if (window_maximized) {
+ maximize ();
+ } else {
+ int width, height;
+ width = settings.get_int ("width");
+ height = settings.get_int ("height");
+ set_default_size (width, height);
+ }
+ }
+
+ private void save_window_state () {
+ var width = 0;
+ var height = 0;
+
+ get_default_size (out width, out height);
+
+ debug ("Saving window geometry: %i × %i", width, height);
+
+ settings.set_int ("width", width);
+ settings.set_int ("height", height);
+
+ settings.set_boolean ("maximized", is_maximized ());
+ settings.apply ();
+ }
+
[GtkCallback]
private void enter_cb (Gtk.EventControllerFocus controller) {
((Application) application).withdraw_notifications ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]