[gnome-sudoku/arnaudb/wip/gtk4: 9/33] Make on_window_state_event work.



commit b5ab389d2088205f2e56aad7dab5a40a3c5ac30d
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun Apr 12 13:10:40 2020 +0200

    Make on_window_state_event work.

 src/gnome-sudoku.vala | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
---
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 0c13ecd..896a6a4 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -153,7 +153,7 @@ public class Sudoku : Gtk.Application
 
         window = (ApplicationWindow) builder.get_object ("sudoku_app");
         window.size_allocate.connect (size_allocate_cb);
-        window.window_state_event.connect (window_state_event_cb);
+        window.map.connect (init_state_watcher);
         window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
         if (settings.get_boolean ("window-is-maximized"))
             window.maximize ();
@@ -238,25 +238,30 @@ public class Sudoku : Gtk.Application
         window.get_size (out window_width, out window_height);
     }
 
-    private const Gdk.WindowState tiled_state = Gdk.WindowState.TILED
-                                              | Gdk.WindowState.TOP_TILED
-                                              | Gdk.WindowState.BOTTOM_TILED
-                                              | Gdk.WindowState.LEFT_TILED
-                                              | Gdk.WindowState.RIGHT_TILED;
-    private bool window_state_event_cb (Gdk.EventWindowState event)
+    private inline 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 = window.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);
+    }
 
-        /* fullscreen: saved as maximized */
-        if ((event.changed_mask & Gdk.WindowState.FULLSCREEN) != 0)
-            window_is_fullscreen = (event.new_window_state & Gdk.WindowState.FULLSCREEN) != 0;
+    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 inline void on_window_state_event ()
+    {
+        Gdk.SurfaceState state = surface.get_state ();
 
+        window_is_maximized =   (state & Gdk.SurfaceState.MAXIMIZED)  != 0;
+        /* fullscreen: saved as maximized */
+        window_is_fullscreen =  (state & Gdk.SurfaceState.FULLSCREEN) != 0;
         /* We don’t save this state, but track it for saving size allocation */
-        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;
     }
 
     private void paused_changed_cb ()


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