Merge lp:~philip.scott/audience/inhibit-screen into lp:~audience-members/audience/trunk

Proposed by Felipe Escoto
Status: Merged
Approved by: Danielle Foré
Approved revision: 596
Merged at revision: 596
Proposed branch: lp:~philip.scott/audience/inhibit-screen
Merge into: lp:~audience-members/audience/trunk
Diff against target: 213 lines (+114/-38)
3 files modified
src/CMakeLists.txt (+1/-0)
src/Services/Inhibitor.vala (+102/-0)
src/Widgets/PlayerPage.vala (+11/-38)
To merge this branch: bzr merge lp:~philip.scott/audience/inhibit-screen
Reviewer Review Type Date Requested Status
Corentin Noël Needs Fixing
Danielle Foré testing Approve
Review via email: mp+300277@code.launchpad.net

Commit message

Inhibit screen lock during playback

Description of the change

Added a class that takes care of inhibiting the screen.

The same interface could also be used for sending play/pause when the screen locks, buy maybe this should be done elsewhere (Indicator-sound?) and for all players at once

I've found that even if you inhibited the screen, it would only prevent it from locking and not suspending. So now we are simulating user activity every 2 mins

Fixes:
https://bugs.launchpad.net/audience/+bug/1596752
https://bugs.launchpad.net/audience/+bug/1445780

To post a comment you must log in.
Revision history for this message
Corentin Noël (tintou) wrote :

does this code superseed the one in http://bazaar.launchpad.net/~audience-members/audience/trunk/view/head:/src/Widgets/PlayerPage.vala#L404 ? If so it can be removed with this branch

review: Needs Information
Revision history for this message
Danielle Foré (danrabbit) wrote :

afaict, this works as intended

review: Approve (testing)
Revision history for this message
Corentin Noël (tintou) wrote :

There is a small header issue

review: Needs Fixing
596. By Felipe Escoto

 Inhibit screen during playback

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-04-06 05:40:05 +0000
3+++ src/CMakeLists.txt 2016-07-19 11:59:25 +0000
4@@ -76,6 +76,7 @@
5 Widgets/PlaylistPopover.vala
6 Widgets/WelcomePage.vala
7 Widgets/PlayerPage.vala
8+ Services/Inhibitor.vala
9 PACKAGES
10 ${VALA_DEPS}
11 OPTIONS
12
13=== added directory 'src/Services'
14=== added file 'src/Services/Inhibitor.vala'
15--- src/Services/Inhibitor.vala 1970-01-01 00:00:00 +0000
16+++ src/Services/Inhibitor.vala 2016-07-19 11:59:25 +0000
17@@ -0,0 +1,102 @@
18+/*-
19+ * Copyright (c) 2016 elementary LLC. (https://elementary.io)
20+ *
21+ * This program is free software: you can redistribute it and/or modify
22+ * it under the terms of the GNU Library General Public License as published by
23+ * the Free Software Foundation, either version 2.1 of the License, or
24+ * (at your option) any later version.
25+ *
26+ * This program is distributed in the hope that it will be useful,
27+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
28+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29+ * GNU Library General Public License for more details.
30+ *
31+ * You should have received a copy of the GNU Library General Public License
32+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
33+ */
34+
35+[DBus (name = "org.freedesktop.ScreenSaver")]
36+public interface ScreenSaverIface : Object {
37+ public abstract uint32 Inhibit (string app_name, string reason) throws Error;
38+ public abstract void UnInhibit (uint32 cookie) throws Error;
39+ public abstract void SimulateUserActivity () throws Error;
40+}
41+
42+public class Audience.Services.Inhibitor : Object {
43+ private const string IFACE = "org.freedesktop.ScreenSaver";
44+ private const string IFACE_PATH = "/ScreenSaver";
45+
46+ private static Inhibitor? instance = null;
47+
48+ private uint32? inhibit_cookie = null;
49+
50+ private ScreenSaverIface? screensaver_iface = null;
51+
52+ private bool inhibited = false;
53+ private bool simulator_started = false;
54+
55+ private Inhibitor () {
56+ try {
57+ screensaver_iface = Bus.get_proxy_sync (BusType.SESSION, IFACE, IFACE_PATH, DBusProxyFlags.NONE);
58+ } catch (Error e) {
59+ error ("Could not start screensaver interface: %s", e.message);
60+ }
61+ }
62+
63+ public static Inhibitor get_instance () {
64+ if (instance == null) {
65+ instance = new Audience.Services.Inhibitor ();
66+ }
67+
68+ return instance;
69+ }
70+
71+ public void inhibit () {
72+ if (screensaver_iface != null && !inhibited) {
73+ try {
74+ inhibited = true;
75+ inhibit_cookie = screensaver_iface.Inhibit ("Audience", "Playing movie");
76+ simulate_activity ();
77+ debug ("Inhibiting screen");
78+ } catch (Error e) {
79+ error ("Could not inhibit screen: %s", e.message);
80+ }
81+ }
82+ }
83+
84+ public void uninhibit () {
85+ if (screensaver_iface != null && inhibited) {//&& inhibit_cookie != null) {
86+ try {
87+ inhibited = false;
88+ screensaver_iface.UnInhibit (inhibit_cookie);
89+ debug ("Uninhibiting screen");
90+ } catch (Error e) {
91+ error ("Could not uninhibit screen: %s", e.message);
92+ }
93+ }
94+ }
95+
96+ /*
97+ * Inhibit currently does not block a suspend from ocurring,
98+ * so we simulate user activity every 2 mins to prevent it
99+ */
100+ private void simulate_activity () {
101+ if (simulator_started) return;
102+
103+ simulator_started = true;
104+ Timeout.add_full (Priority.DEFAULT, 120000, ()=> {
105+ if (inhibited) {
106+ try {
107+ debug ("Simulating activity");
108+ screensaver_iface.SimulateUserActivity ();
109+ } catch (Error e) {
110+ error ("Could not simulate user activity: %s", e.message);
111+ }
112+ } else {
113+ simulator_started = false;
114+ }
115+
116+ return inhibited;
117+ });
118+ }
119+}
120
121=== modified file 'src/Widgets/PlayerPage.vala'
122--- src/Widgets/PlayerPage.vala 2016-03-19 19:19:13 +0000
123+++ src/Widgets/PlayerPage.vala 2016-07-19 11:59:25 +0000
124@@ -22,9 +22,6 @@
125 private GnomeMediaKeys mediakeys;
126 private ClutterGst.Playback playback;
127
128- public GnomeSessionManager session_manager;
129- uint32 inhibit_cookie;
130-
131 private bool mouse_primary_down = false;
132
133 public bool repeat {
134@@ -69,9 +66,6 @@
135 events |= Gdk.EventMask.KEY_RELEASE_MASK;
136 playback = new ClutterGst.Playback ();
137 playback.set_seek_flags (ClutterGst.SeekFlags.ACCURATE);
138- playback.notify["playing"].connect (() => {
139- inhibit_session (playback.playing);
140- });
141
142 clutter = new GtkClutter.Embed ();
143 stage = (Clutter.Stage)clutter.get_stage ();
144@@ -194,6 +188,7 @@
145 settings.last_stopped = playback.progress;
146
147 get_playlist_widget ().save_playlist ();
148+ Audience.Services.Inhibitor.get_instance ().uninhibit ();
149 });
150
151 //end
152@@ -228,6 +223,14 @@
153 var cursor = new Gdk.Cursor.for_display (display, Gdk.CursorType.BLANK_CURSOR);
154 window.set_cursor (cursor);
155 }
156+ });
157+
158+ notify["playing"].connect (() => {
159+ if (playing) {
160+ Audience.Services.Inhibitor.get_instance ().inhibit ();
161+ } else {
162+ Audience.Services.Inhibitor.get_instance ().uninhibit ();
163+ }
164 });
165
166 add (clutter);
167@@ -258,6 +261,8 @@
168 /*subtitles/audio tracks*/
169 bottom_bar.preferences_popover.setup_text ();
170 bottom_bar.preferences_popover.setup_audio ();
171+
172+ Audience.Services.Inhibitor.get_instance ().inhibit ();
173 }
174
175 public string get_played_uri () {
176@@ -395,37 +400,5 @@
177
178 return false;
179 }
180-
181- X.Display dpy;
182- int timeout = -1;
183- int interval;
184- int prefer_blanking;
185- int allow_exposures;
186- void inhibit_session (bool inhibit) {
187- debug ("set inhibit to " + (inhibit ? "true" : "false"));
188- //TODO: Remove X Dependency!
189- //store the default values for setting back
190-
191- if (dpy == null)
192- dpy = new X.Display ();
193-
194- if (timeout == -1)
195- dpy.get_screensaver (out timeout, out interval, out prefer_blanking, out allow_exposures);
196-
197- dpy.set_screensaver (inhibit ? 0 : timeout, interval, prefer_blanking, allow_exposures);
198-
199- //prevent screenlocking in Gnome 3 using org.gnome.SessionManager
200- try {
201- session_manager = Bus.get_proxy_sync (BusType.SESSION,
202- "org.gnome.SessionManager", "/org/gnome/SessionManager");
203- if (inhibit) {
204- inhibit_cookie = session_manager.Inhibit ("audience", 0, "Playing Video using Audience", 12);
205- } else {
206- session_manager.Uninhibit (inhibit_cookie);
207- }
208- } catch (Error e) {
209- warning (e.message);
210- }
211- }
212 }
213 }

Subscribers

People subscribed via source and target branches