[gnome-taquin/arnaudb/wip/gtk4: 6/56] Adapt AdaptativeWindow.




commit 5df551067040d5b070cd801cb19b77468499567b
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Feb 19 20:53:45 2020 +0100

    Adapt AdaptativeWindow.

 data/ui/adaptative-window.ui |  4 ++--
 src/adaptative-window.vala   | 42 ++++++++++++++++++++++++------------------
 2 files changed, 26 insertions(+), 20 deletions(-)
---
diff --git a/data/ui/adaptative-window.ui b/data/ui/adaptative-window.ui
index 2bf1552..298609b 100644
--- a/data/ui/adaptative-window.ui
+++ b/data/ui/adaptative-window.ui
@@ -16,11 +16,11 @@
   along with GNOME Taquin.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
-  <requires lib="gtk+" version="3.12"/>
+  <requires lib="gtk+" version="3.96"/>
   <template class="AdaptativeWindow" parent="GtkApplicationWindow">
     <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="window-state-event"   handler="on_window_state_event"/>
+    <signal name="map"                  handler="init_state_watcher"/>
     <signal name="size-allocate"        handler="on_size_allocate"/>
     <signal name="destroy"              handler="on_destroy"/>
   </template>
diff --git a/src/adaptative-window.vala b/src/adaptative-window.vala
index 4548f1a..d99cd98 100644
--- a/src/adaptative-window.vala
+++ b/src/adaptative-window.vala
@@ -223,40 +223,46 @@ private abstract class AdaptativeWindow : ApplicationWindow
     \*/
 
     [GtkCallback]
-    private bool on_window_state_event (Widget widget, Gdk.EventWindowState event)
+    private void init_state_watcher ()
     {
-        if ((event.changed_mask & Gdk.WindowState.MAXIMIZED) != 0)
-            window_is_maximized = (event.new_window_state & Gdk.WindowState.MAXIMIZED) != 0;
+        Gdk.Surface? nullable_surface = get_surface ();     // TODO report bug, get_surface() returns a 
nullable Surface
+        if (nullable_surface == null || !((!) nullable_surface is Gdk.Toplevel))
+            assert_not_reached ();
+        surface = (Gdk.Toplevel) (!) nullable_surface;
+        surface.notify ["state"].connect (on_window_state_event);
+    }
+
+    private Gdk.Toplevel surface;
+    private const Gdk.ToplevelState tiled_state = Gdk.ToplevelState.TILED
+                                                | Gdk.ToplevelState.TOP_TILED
+                                                | Gdk.ToplevelState.BOTTOM_TILED
+                                                | Gdk.ToplevelState.LEFT_TILED
+                                                | Gdk.ToplevelState.RIGHT_TILED;
+    private void on_window_state_event ()
+    {
+        Gdk.ToplevelState state = surface.get_state ();
+
+        window_is_maximized = (state & Gdk.ToplevelState.MAXIMIZED) != 0;
 
         /* fullscreen: saved as maximized */
         bool window_was_fullscreen = window_is_fullscreen;
-        if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
-            window_is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
+
+        window_is_fullscreen = (state & Gdk.ToplevelState.FULLSCREEN) != 0;
+
         if (window_was_fullscreen && !window_is_fullscreen)
             on_unfullscreen ();
         else if (!window_was_fullscreen && window_is_fullscreen)
             on_fullscreen ();
 
         /* tiled: not saved, but should not change saved window size */
-        Gdk.WindowState tiled_state = Gdk.WindowState.TILED
-                                    | Gdk.WindowState.TOP_TILED
-                                    | Gdk.WindowState.BOTTOM_TILED
-                                    | Gdk.WindowState.LEFT_TILED
-                                    | Gdk.WindowState.RIGHT_TILED;
-        if ((event.changed_mask & tiled_state) != 0)
-            window_is_tiled = (event.new_window_state & tiled_state) != 0;
-
-        return false;
+        window_is_tiled = (state & tiled_state) != 0;
     }
     protected abstract void on_fullscreen ();
     protected abstract void on_unfullscreen ();
 
     [GtkCallback]
-    private void on_size_allocate (Allocation allocation)
+    private void on_size_allocate (int width, int height)
     {
-        int height = allocation.height;
-        int width = allocation.width;
-
         update_adaptative_children (ref width, ref height);
         update_window_state ();
     }


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