[gnome-music/wip/jfelder/gtk4-v3: 8/108] windowplacement: Listen to size changes instead of configure-event




commit 9b99dad92bca69123ab1570a3678883b8bb35670
Author: Jean Felder <jfelder src gnome org>
Date:   Wed Feb 2 23:42:54 2022 +0100

    windowplacement: Listen to size changes instead of configure-event
    
    The "configure-event" signal has been removed in Gtk4.

 gnomemusic/windowplacement.py | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
---
diff --git a/gnomemusic/windowplacement.py b/gnomemusic/windowplacement.py
index c70aaddc4..ee7889c5c 100644
--- a/gnomemusic/windowplacement.py
+++ b/gnomemusic/windowplacement.py
@@ -22,8 +22,14 @@
 # code, but you are not obligated to do so.  If you do not wish to do so,
 # delete this exception statement from your version.
 
+from __future__ import annotations
+import typing
+
 from gi.repository import GLib, GObject
 
+if typing.TYPE_CHECKING:
+    from gnomemusic.window import Window
+
 
 class WindowPlacement(GObject.GObject):
     """Main window placement
@@ -47,9 +53,10 @@ class WindowPlacement(GObject.GObject):
 
         self._restore_window_state()
 
-        self._window_placement_update_timeout = None
+        self._window_placement_update_timeout = 0
         self._window.connect('notify::is-maximized', self._on_maximized)
-        self._window.connect('configure-event', self._on_configure_event)
+        self._window.connect("notify::default-height", self._on_size_change)
+        self._window.connect("notify::default-width", self._on_size_change)
 
     def _restore_window_state(self):
         size_setting = self._settings.get_value('window-size')
@@ -61,18 +68,20 @@ class WindowPlacement(GObject.GObject):
         if self._settings.get_value('window-maximized'):
             self._window.maximize()
 
-    def _on_configure_event(self, widget, event):
-        if self._window_placement_update_timeout is None:
+    def _on_size_change(
+            self, window: Window, size: GObject.ParamSpecInt) -> None:
+        if self._window_placement_update_timeout == 0:
             self._window_placement_update_timeout = GLib.timeout_add(
-                500, self._store_size, widget)
+                500, self._store_size, window)
 
-    def _store_size(self, widget):
-        size = widget.get_size()
+    def _store_size(self, window: Window) -> bool:
+        width = window.get_width()
+        height = window.get_height()
         self._settings.set_value(
-            'window-size', GLib.Variant('ai', [size[0], size[1]]))
+            "window-size", GLib.Variant("ai", [width, height]))
 
         GLib.source_remove(self._window_placement_update_timeout)
-        self._window_placement_update_timeout = None
+        self._window_placement_update_timeout = 0
 
         return False
 


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