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



commit 9119357bbab81db4c99e98395a4c8b3ca526214e
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 d870f11e..c2674c59 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -7,7 +7,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 d63b5c43..6fbde7c9 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;
@@ -113,6 +114,10 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        get_style_context ().add_class ("devel");
 
                set_help_overlay (new ShortcutsWindow ());
+
+               var surface = get_surface ();
+               state = surface.state;
+               surface.notify["state"].connect(on_surface_state_changed);
        }
 
        public void show_error (string error_message) {
@@ -170,19 +175,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)
@@ -190,8 +198,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]