[gnome-games] ui: Inhibit the screensaver when playing
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] ui: Inhibit the screensaver when playing
- Date: Thu, 15 Sep 2016 05:27:52 +0000 (UTC)
commit 326b58d9f291a887ce243f87c7a1b3da48ac9e86
Author: Mathieu Bridon <bochecha daitauha fr>
Date: Tue Aug 16 12:15:18 2016 +0200
ui: Inhibit the screensaver when playing
Nobody wants their screen to blank and lock while they are playing.
With this change, we now inhibit the screensaver when the user is
playing a game, and the window is focused.
https://bugzilla.gnome.org/show_bug.cgi?id=769968
src/ui/application-window.vala | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index c9d0ca2..57f0bd0 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -80,6 +80,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
private long focus_out_timeout_id;
+ private uint inhibit_cookie;
+
public ApplicationWindow (ListModel collection) {
collection_box.collection = collection;
}
@@ -96,6 +98,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
BindingFlags.BIDIRECTIONAL);
focus_out_timeout_id = -1;
+ inhibit_cookie = 0;
}
public void run_game (Game game) {
@@ -112,6 +115,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
// Only reset the cancellable if another one didn't replace it.
if (run_game_cancellable == cancellable)
run_game_cancellable = null;
+
+ inhibit ();
}
public bool quit_game () {
@@ -165,6 +170,18 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
is_fullscreen = (bool) (event.new_window_state & Gdk.WindowState.FULLSCREEN);
update_pause (false);
+ if (!(bool) (event.changed_mask & Gdk.WindowState.FOCUSED))
+ return false;
+
+ var focused = (bool) (event.new_window_state & Gdk.WindowState.FOCUSED);
+ var playing = (ui_state == UiState.DISPLAY);
+
+ if (focused && playing)
+ inhibit ();
+
+ if (!focused)
+ uninhibit ();
+
return false;
}
@@ -177,6 +194,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
private void on_display_back () {
if (quit_game ())
ui_state = UiState.COLLECTION;
+
+ uninhibit ();
}
private void run_game_with_cancellable (Game game, Cancellable cancellable) {
@@ -421,4 +440,21 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
return false;
}
+
+ private void inhibit () {
+ Gtk.ApplicationInhibitFlags flag = Gtk.ApplicationInhibitFlags.IDLE;
+
+ if (inhibit_cookie != 0)
+ return;
+
+ inhibit_cookie = application.inhibit (this, flag, _("Playing a game"));
+ }
+
+ private void uninhibit () {
+ if (inhibit_cookie == 0)
+ return;
+
+ application.uninhibit (inhibit_cookie);
+ inhibit_cookie = 0;
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]