[gnome-games] ui: Pause game when the window is unfocused



commit 75ce64477419ab4f431b384adff98f146d5958ed
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Aug 17 22:33:04 2016 +0200

    ui: Pause game when the window is unfocused
    
    Also resume it when the window gets the focus back.
    
    This avoids the player to loose control over the game.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=770011

 src/ui/application-window.vala |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 68ad9fe..8b4619c 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -155,6 +155,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool on_window_state_event (Gdk.EventWindowState event) {
                is_fullscreen = (bool) (event.new_window_state & Gdk.WindowState.FULLSCREEN);
 
+               update_toplevel_focus ();
+
                return false;
        }
 
@@ -309,4 +311,17 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                return false;
        }
+
+       private void update_toplevel_focus () {
+               if (ui_state != UiState.DISPLAY)
+                       return;
+
+               if (display_box.runner == null)
+                       return;
+
+               if (has_toplevel_focus)
+                       display_box.runner.resume ();
+               else
+                       display_box.runner.pause ();
+       }
 }


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