[four-in-a-row/arnaudb/wip/gtk4] The size-allocate signal is gone.



commit 43ab3e530758b0c2564b3b57ae6cb789e0f5e490
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat Sep 26 17:46:44 2020 +0200

    The size-allocate signal is gone.

 data/ui/adaptative-window.ui |  1 -
 src/adaptative-window.vala   |  4 ++--
 src/game-actionbar.vala      | 16 +++++++++++++---
 src/game-board-view.vala     | 22 +++++++++++++++-------
 src/history-button.vala      | 16 ++++++++++++----
 5 files changed, 42 insertions(+), 17 deletions(-)
---
diff --git a/data/ui/adaptative-window.ui b/data/ui/adaptative-window.ui
index 91a2f3c..24108d0 100644
--- a/data/ui/adaptative-window.ui
+++ b/data/ui/adaptative-window.ui
@@ -23,7 +23,6 @@
     <property name="height-request">284</property>  <!-- 288px max for Purism Librem 5 landscape, for 720px 
width; update gschema also -->
     <property name="width-request">350</property>   <!-- 360px max for Purism Librem 5 portrait, for 648px 
height; update gschema also -->
     <signal name="map"                  handler="init_state_watcher"/>
-    <signal name="size-allocate"        handler="on_size_allocate"/>
     <signal name="destroy"              handler="on_destroy"/>
   </template>
 </interface>
diff --git a/src/adaptative-window.vala b/src/adaptative-window.vala
index fd54754..e5b097c 100644
--- a/src/adaptative-window.vala
+++ b/src/adaptative-window.vala
@@ -127,6 +127,7 @@ private abstract class AdaptativeWindow : ApplicationWindow
             assert_not_reached ();
         surface = (Gdk.Toplevel) (!) nullable_surface;
         surface.notify ["state"].connect (on_window_state_event);
+        surface.size_changed.connect (on_size_changed);
     }
 
     private Gdk.Toplevel surface;
@@ -157,8 +158,7 @@ private abstract class AdaptativeWindow : ApplicationWindow
     protected abstract void on_fullscreen ();
     protected abstract void on_unfullscreen ();
 
-    [GtkCallback]
-    private void on_size_allocate (int width, int height)
+    private inline void on_size_changed (Gdk.Surface _surface, int width, int height)
     {
         update_adaptative_children (ref width, ref height);
         update_window_state ();
diff --git a/src/game-actionbar.vala b/src/game-actionbar.vala
index 3f15e4b..3b7bf34 100644
--- a/src/game-actionbar.vala
+++ b/src/game-actionbar.vala
@@ -110,12 +110,22 @@ private class GameActionBarPlaceHolder : Widget, AdaptativeWidget
     internal GameActionBarPlaceHolder (GameActionBar _actionbar)
     {
         actionbar = _actionbar;
-        actionbar.size_allocate.connect (set_height);
-        set_height ();
+        actionbar.map.connect (init_state_watcher);
+     // set_height ();
         revealer.set_reveal_child (true);    // seems like setting it in the UI file does not work, while it 
is OK for GameActionBar...
     }
 
-    private void set_height ()
+    private Gdk.Toplevel surface;
+    private inline void init_state_watcher ()
+    {
+        Gdk.Surface? nullable_surface = ((Gtk.Native) actionbar).get_surface ();
+        if (nullable_surface == null || !((!) nullable_surface is Gdk.Toplevel))
+            assert_not_reached ();
+        surface = (Gdk.Toplevel) (!) nullable_surface;
+        surface.size_changed.connect (on_size_changed);
+    }
+
+    private inline void on_size_changed (Gdk.Surface _surface, int width, int height)
     {
         Requisition natural_size;
         Widget? widget = actionbar.get_first_child ();
diff --git a/src/game-board-view.vala b/src/game-board-view.vala
index 1a38e05..809abda 100644
--- a/src/game-board-view.vala
+++ b/src/game-board-view.vala
@@ -43,7 +43,7 @@ private class GameBoardView : Gtk.DrawingArea
 
         init_mouse ();
         set_draw_func (draw);
-        size_allocate.connect (on_size_allocate);
+        map.connect (init_state_watcher);
     }
 
     protected override bool focus (Gtk.DirectionType direction)
@@ -84,15 +84,23 @@ private class GameBoardView : Gtk.DrawingArea
 //                                     tile_size);
     }
 
-    private inline void on_size_allocate ()
+    private Gdk.Toplevel surface;
+    private inline void init_state_watcher ()
     {
-        int allocated_width  = get_allocated_width ();
-        int allocated_height = get_allocated_height ();
-        int size = int.min (allocated_width, allocated_height);
+        Gdk.Surface? nullable_surface = ((Gtk.Native) this).get_surface ();
+        if (nullable_surface == null || !((!) nullable_surface is Gdk.Toplevel))
+            assert_not_reached ();
+        surface = (Gdk.Toplevel) (!) nullable_surface;
+        surface.size_changed.connect (on_size_changed);
+    }
+
+    private inline void on_size_changed (Gdk.Surface _surface, int width, int height)
+    {
+        int size = int.min (width, height);
         tile_size = size / game_board.size;
         board_size = tile_size * game_board.size;
-        board_x = (allocated_width  - board_size) / 2;
-        board_y = (allocated_height - board_size) / 2;
+        board_x = (width  - board_size) / 2;
+        board_y = (height - board_size) / 2;
 
         offset [Tile.PLAYER1]        = 0;
         offset [Tile.PLAYER2]        = tile_size;
diff --git a/src/history-button.vala b/src/history-button.vala
index 309dfbc..6efc1ee 100644
--- a/src/history-button.vala
+++ b/src/history-button.vala
@@ -47,7 +47,7 @@ private class HistoryButton : ToggleButton, AdaptativeWidget
         BinLayout layout = new BinLayout ();
         set_layout_manager (layout);
 
-        drawing.size_allocate.connect (configure_drawing);
+        drawing.map.connect (init_state_watcher);
         drawing.set_draw_func (update_drawing);
         theme_manager.theme_changed.connect (() => {
                 if (!drawing_configured)
@@ -89,10 +89,18 @@ private class HistoryButton : ToggleButton, AdaptativeWidget
 
     private Gdk.Pixbuf tileset_pixbuf;
 
-    private inline void configure_drawing ()
+    private Gdk.Toplevel surface;
+    private inline void init_state_watcher ()
+    {
+        Gdk.Surface? nullable_surface = ((Gtk.Native) drawing).get_surface ();
+        if (nullable_surface == null || !((!) nullable_surface is Gdk.Toplevel))
+            assert_not_reached ();
+        surface = (Gdk.Toplevel) (!) nullable_surface;
+        surface.size_changed.connect (on_size_changed);
+    }
+
+    private inline void on_size_changed (Gdk.Surface _surface, int width, int height)
     {
-        int height          = drawing.get_allocated_height ();
-        int width           = drawing.get_allocated_width ();
         int new_height      = (int) double.min (height, width / 2.0);
 
         bool refresh_pixbuf = drawing_height != new_height;


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