[gnome-nibbles/arnaudb/wip/gtk4: 143/188] Handle window size change.




commit c494947d7dfba3374b3ea2ee54e94ece4b889361
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Sep 30 16:27:30 2020 +0200

    Handle window size change.

 src/nibbles-window.vala | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
---
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 85d48c8..0acf95d 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -125,7 +125,6 @@ private class NibblesWindow : ApplicationWindow
             worm_settings[i].changed.connect (worm_settings_changed_cb);
         }
 
-        size_allocate.connect (size_allocate_cb);
         map.connect (init_state_watcher);
         set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-maximized"))
@@ -277,9 +276,18 @@ private class NibblesWindow : ApplicationWindow
         if (nullable_surface == null || !((!) nullable_surface is Gdk.Toplevel))
             assert_not_reached ();
         surface = (Gdk.Toplevel) (!) nullable_surface;
+        surface.size_changed.connect (on_size_changed);
         surface.notify ["state"].connect (on_state_changed);
     }
 
+    private inline void on_size_changed (Gdk.Surface _surface, int width, int height)
+    {
+        if (window_is_maximized || window_is_tiled)
+            return;
+        window_width  = width;
+        window_height = height;
+    }
+
     private Gdk.Toplevel surface;
     private const Gdk.ToplevelState tiled_state = Gdk.ToplevelState.TILED
                                                 | Gdk.ToplevelState.TOP_TILED
@@ -315,13 +323,6 @@ private class NibblesWindow : ApplicationWindow
             return game.handle_keypress (keyval);
     }
 
-    private void size_allocate_cb (Allocation allocation)
-    {
-        if (window_is_maximized || window_is_tiled)
-            return;
-        get_size (out window_width, out window_height);
-    }
-
     private void start_game ()
     {
         settings.set_boolean ("first-run", false);


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