[gnome-klotski/arnaudb/wip/gtk4: 5/14] Make on_window_state_event work.



commit 94c0716ac4a29f7abe522933eaf12ba16fdfd876
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Mar 5 18:54:15 2020 +0100

    Make on_window_state_event work.

 data/klotski.ui         |  2 +-
 src/klotski-window.vala | 37 +++++++++++++++++++++++--------------
 2 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/data/klotski.ui b/data/klotski.ui
index 0631d83..4fa2550 100644
--- a/data/klotski.ui
+++ b/data/klotski.ui
@@ -314,7 +314,7 @@
     <property name="width-request">600</property>
     <property name="height-request">400</property>
     <signal name="size_allocate" handler="on_size_allocate"/>
-    <signal name="window_state_event" handler="on_window_state_event"/>
+    <signal name="map" handler="init_state_watcher"/>
     <signal name="destroy" handler="on_destroy"/>
     <child type="titlebar">
       <object class="GtkHeaderBar" id="headerbar">
diff --git a/src/klotski-window.vala b/src/klotski-window.vala
index c66d8c7..96d4a51 100644
--- a/src/klotski-window.vala
+++ b/src/klotski-window.vala
@@ -631,30 +631,39 @@ private class KlotskiWindow : ApplicationWindow
     }
 
     [GtkCallback]
-    private bool on_window_state_event (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.SurfaceState tiled_state = Gdk.SurfaceState.TILED
+                                               | Gdk.SurfaceState.TOP_TILED
+                                               | Gdk.SurfaceState.BOTTOM_TILED
+                                               | Gdk.SurfaceState.LEFT_TILED
+                                               | Gdk.SurfaceState.RIGHT_TILED;
+    private void on_window_state_event ()
+    {
+        Gdk.SurfaceState state = surface.get_state ();
+
+        window_is_maximized = (state & Gdk.SurfaceState.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.SurfaceState.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 void on_fullscreen ()
     {


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