[gnome-clocks] window: Rewrite the code for keeping track of window's state



commit 3f37c00826e3c5714a4f02b4087c7e14bb758f6e
Author: Yetizone <andreii lisita gmail com>
Date:   Thu Jan 14 17:18:30 2021 +0200

    window: Rewrite the code for keeping track of window's state
    
    In GTK3 we use the "window-state-event" and "configure-event" signals
    for keeping track of the window state. These signals are no longer
    available in GTK4.
    
    Instead, the recommended method for keeping track of the window's state
    is to bind the window object's properties to gsettings.
    
    See https://wiki.gnome.org/HowDoI/SaveWindowState

 data/org.gnome.clocks.gschema.xml.in | 23 +++++++++++++++--------
 src/window.vala                      | 27 +++++++--------------------
 2 files changed, 22 insertions(+), 28 deletions(-)
---
diff --git a/data/org.gnome.clocks.gschema.xml.in b/data/org.gnome.clocks.gschema.xml.in
index 6b61579b..9f183f9b 100644
--- a/data/org.gnome.clocks.gschema.xml.in
+++ b/data/org.gnome.clocks.gschema.xml.in
@@ -39,18 +39,25 @@
     <child schema="org.gnome.clocks.state.window" name="window"/>
   </schema>
   <schema id="org.gnome.clocks.state.window" path="/org/gnome/clocks/state/window/">
-    <key type="i" name="state">
-      <default>0</default>
-      <summary>Window state</summary>
+    <key type="b" name="maximized">
+      <default>false</default>
+      <summary>Window maximized</summary>
       <description>
-        State of the window, e.g. maximized.
+        Whether the window is maximized.
       </description>
     </key>
-    <key type="(ii)" name="size">
-      <default>(870, 690)</default>
-      <summary>Window width and height</summary>
+    <key type="i" name="width">
+      <default>870</default>
+      <summary>Window width</summary>
       <description>
-        Width and height of the window.
+        Width of the window.
+      </description>
+    </key>
+    <key type="i" name="height">
+      <default>690</default>
+      <summary>Window height</summary>
+      <description>
+        Height of the window.
       </description>
     </key>
     <key enum="org.gnome.clocks.panelid" name="panel-id">
diff --git a/src/window.vala b/src/window.vala
index fe66e530..5c23f1c2 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -109,14 +109,18 @@ public class Window : Adw.ApplicationWindow {
         pane_changed ();
 
         // Setup window geometry saving
-        var window_state = (Gdk.WindowState) settings.get_int ("state");
-        if (Gdk.WindowState.MAXIMIZED in window_state) {
+        var window_maximized = settings.get_boolean ("maximized");
+        if (window_maximized) {
             maximize ();
         } else {
             int width, height;
-            settings.get ("size", "(ii)", out width, out height);
+            width = settings.get_int ("width");
+            height = settings.get_int ("height");
             resize (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);
 
         world.show_standalone.connect ((w, l) => {
             stack.visible_child = w;
@@ -251,23 +255,6 @@ public class Window : Adw.ApplicationWindow {
         on_back_activate ();
     }
 
-    protected override bool configure_event (Gdk.EventConfigure event) {
-        if (get_realized () && !(Gdk.WindowState.MAXIMIZED in ((Gdk.Window) get_window ()).get_state ())) {
-            int width, height;
-
-            get_size (out width, out height);
-            settings.set ("size", "(ii)", width, height);
-        }
-
-        return base.configure_event (event);
-    }
-
-    protected override bool window_state_event (Gdk.EventWindowState event) {
-        settings.set_int ("state", event.new_window_state);
-
-        return base.window_state_event (event);
-    }
-
     private void on_help_activate () {
         try {
             Gtk.show_uri_on_window (this, "help:gnome-clocks", Gtk.get_current_event_time ());


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]