[gnome-games/wip/exalm/gtk4: 212/238] application-window: Stop using 'window-state-event' signal



commit b0d8bdc9a9678752a73ff087aa8c21487cc270e5
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Jul 29 10:41:05 2018 +0500

    application-window: Stop using 'window-state-event' signal
    
    Use 'notify::state' of GdkSurface instead.

 data/ui/application-window.ui  |  1 -
 src/ui/application-window.vala | 24 +++++++++++++++---------
 2 files changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/data/ui/application-window.ui b/data/ui/application-window.ui
index 07bea976..f1b9e240 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -6,7 +6,6 @@
     <property name="default-height">600</property>
     <property name="show-menubar">False</property>
     <signal name="close-request" after="yes" handler="on_close_request"/>
-    <signal name="window-state-event" after="yes" handler="on_window_state_event"/>
     <signal name="notify::is-active" after="yes" handler="on_active_changed"/>
     <child>
       <object class="GtkEventControllerKey">
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index f653258b..9d7ba858 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -55,6 +55,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private Binding fullscreen_binding;
        private Binding loading_notification_binding;
 
+       private Gdk.SurfaceState state;
        private long window_size_update_timeout;
 
        private uint inhibit_cookie;
@@ -111,6 +112,10 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        get_style_context ().add_class ("devel");
 
                init_help_overlay ();
+
+               var surface = get_surface ();
+               state = surface.state;
+               surface.notify["state"].connect(on_surface_state_changed);
        }
 
        private void init_help_overlay () {
@@ -185,19 +190,22 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        display_view.back ();
        }
 
-       [GtkCallback]
-       public bool on_window_state_event (Gdk.EventWindowState event) {
-               var is_maximized = (bool) (event.new_window_state & Gdk.WindowState.MAXIMIZED);
+       public void on_surface_state_changed () {
+               var surface = get_surface ();
+               var changed_mask = state ^ surface.state;
+               state = surface.state;
+
+               var is_maximized = (state & Gdk.SurfaceState.MAXIMIZED) != 0;
                settings.set_boolean ("window-maximized", is_maximized);
 
-               is_fullscreen = (bool) (event.new_window_state & Gdk.WindowState.FULLSCREEN);
+               is_fullscreen = (bool) (state & Gdk.SurfaceState.FULLSCREEN);
                if (current_view == display_view)
                        display_view.update_pause (false);
 
-               if (!(bool) (event.changed_mask & Gdk.WindowState.FOCUSED))
-                       return false;
+               if ((changed_mask & Gdk.SurfaceState.FOCUSED) == 0)
+                       return;
 
-               var focused = (bool) (event.new_window_state & Gdk.WindowState.FOCUSED);
+               var focused = (bool) (state & Gdk.SurfaceState.FOCUSED);
                var playing = (current_view == display_view);
 
                if (focused && playing)
@@ -205,8 +213,6 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                if (!focused)
                        uninhibit (Gtk.ApplicationInhibitFlags.IDLE);
-
-               return false;
        }
 
        public bool gamepad_button_press_event (Manette.Event event) {


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