[iagno/arnaudb/wip/gtk4: 6/54] Make on_window_state_event work.



commit 80dcace12cdb2e0174e9ea7e79cad199b7372665
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Feb 12 16:01:01 2020 +0100

    Make on_window_state_event work.

 data/ui/adaptative-window.ui |  2 +-
 src/adaptative-window.vala   | 37 +++++++++++++++++++++++--------------
 2 files changed, 24 insertions(+), 15 deletions(-)
---
diff --git a/data/ui/adaptative-window.ui b/data/ui/adaptative-window.ui
index 897dad0..d3cd244 100644
--- a/data/ui/adaptative-window.ui
+++ b/data/ui/adaptative-window.ui
@@ -20,7 +20,7 @@
   <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 8526860..fbdbd0d 100644
--- a/src/adaptative-window.vala
+++ b/src/adaptative-window.vala
@@ -223,30 +223,39 @@ 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.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 abstract void on_fullscreen ();
     protected abstract void on_unfullscreen ();


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