Merge lp:~donadigo/audience/gtk-application-inhibit into lp:~audience-members/audience/trunk

Proposed by Adam Bieńkowski
Status: Rejected
Rejected by: Felipe Escoto
Proposed branch: lp:~donadigo/audience/gtk-application-inhibit
Merge into: lp:~audience-members/audience/trunk
Diff against target: 186 lines (+25/-107)
3 files modified
src/CMakeLists.txt (+0/-1)
src/Services/Inhibitor.vala (+0/-102)
src/Widgets/Player/PlayerPage.vala (+25/-4)
To merge this branch: bzr merge lp:~donadigo/audience/gtk-application-inhibit
Reviewer Review Type Date Requested Status
Felipe Escoto (community) Disapprove
Review via email: mp+314769@code.launchpad.net

Commit message

* Use Gtk.Application.inhibit API instead of a custom one

Description of the change

This branch fixes bug #1656441: "Use Gtk.Application.inhibit".

Instead of creating an entire new class for managing inhibition, we just call Gtk.Application.inhibit, which supports different types of inhibiting and also ensures that in the future we can e.g: implement org.freedesktop.portal.Desktop interface for a custom inhibit behaviour.

To post a comment you must log in.
718. By Adam Bieńkowski

Make reason translatable

Revision history for this message
Felipe Escoto (philip.scott) wrote :

Gtk.Inhibit doesn't seem to work under either pantheon or gnome shell. On both desktop environments the display still turns off :/

At least for now, the current method will have to stay

review: Disapprove

Unmerged revisions

718. By Adam Bieńkowski

Make reason translatable

717. By Adam Bieńkowski

Remove debug line change

716. By Adam Bieńkowski

Use mainwindow from app instance

715. By Adam Bieńkowski

Use Gtk.Application.inhibit API

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2016-11-02 23:59:41 +0000
+++ src/CMakeLists.txt 2017-01-14 18:26:31 +0000
@@ -66,7 +66,6 @@
66 Widgets/Library/LibraryItem.vala66 Widgets/Library/LibraryItem.vala
67 Widgets/Library/EpisodesPage.vala67 Widgets/Library/EpisodesPage.vala
6868
69 Services/Inhibitor.vala
70 Services/DirictoryMonitoring.vala69 Services/DirictoryMonitoring.vala
71 Services/LibraryManager.vala70 Services/LibraryManager.vala
72 Services/Thubnailer.vala71 Services/Thubnailer.vala
7372
=== removed file 'src/Services/Inhibitor.vala'
--- src/Services/Inhibitor.vala 2016-07-19 11:56:12 +0000
+++ src/Services/Inhibitor.vala 1970-01-01 00:00:00 +0000
@@ -1,102 +0,0 @@
1/*-
2 * Copyright (c) 2016 elementary LLC. (https://elementary.io)
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18[DBus (name = "org.freedesktop.ScreenSaver")]
19public interface ScreenSaverIface : Object {
20 public abstract uint32 Inhibit (string app_name, string reason) throws Error;
21 public abstract void UnInhibit (uint32 cookie) throws Error;
22 public abstract void SimulateUserActivity () throws Error;
23}
24
25public class Audience.Services.Inhibitor : Object {
26 private const string IFACE = "org.freedesktop.ScreenSaver";
27 private const string IFACE_PATH = "/ScreenSaver";
28
29 private static Inhibitor? instance = null;
30
31 private uint32? inhibit_cookie = null;
32
33 private ScreenSaverIface? screensaver_iface = null;
34
35 private bool inhibited = false;
36 private bool simulator_started = false;
37
38 private Inhibitor () {
39 try {
40 screensaver_iface = Bus.get_proxy_sync (BusType.SESSION, IFACE, IFACE_PATH, DBusProxyFlags.NONE);
41 } catch (Error e) {
42 error ("Could not start screensaver interface: %s", e.message);
43 }
44 }
45
46 public static Inhibitor get_instance () {
47 if (instance == null) {
48 instance = new Audience.Services.Inhibitor ();
49 }
50
51 return instance;
52 }
53
54 public void inhibit () {
55 if (screensaver_iface != null && !inhibited) {
56 try {
57 inhibited = true;
58 inhibit_cookie = screensaver_iface.Inhibit ("Audience", "Playing movie");
59 simulate_activity ();
60 debug ("Inhibiting screen");
61 } catch (Error e) {
62 error ("Could not inhibit screen: %s", e.message);
63 }
64 }
65 }
66
67 public void uninhibit () {
68 if (screensaver_iface != null && inhibited) {//&& inhibit_cookie != null) {
69 try {
70 inhibited = false;
71 screensaver_iface.UnInhibit (inhibit_cookie);
72 debug ("Uninhibiting screen");
73 } catch (Error e) {
74 error ("Could not uninhibit screen: %s", e.message);
75 }
76 }
77 }
78
79 /*
80 * Inhibit currently does not block a suspend from ocurring,
81 * so we simulate user activity every 2 mins to prevent it
82 */
83 private void simulate_activity () {
84 if (simulator_started) return;
85
86 simulator_started = true;
87 Timeout.add_full (Priority.DEFAULT, 120000, ()=> {
88 if (inhibited) {
89 try {
90 debug ("Simulating activity");
91 screensaver_iface.SimulateUserActivity ();
92 } catch (Error e) {
93 error ("Could not simulate user activity: %s", e.message);
94 }
95 } else {
96 simulator_started = false;
97 }
98
99 return inhibited;
100 });
101 }
102}
1030
=== modified file 'src/Widgets/Player/PlayerPage.vala'
--- src/Widgets/Player/PlayerPage.vala 2016-11-02 23:59:41 +0000
+++ src/Widgets/Player/PlayerPage.vala 2017-01-14 18:26:31 +0000
@@ -22,6 +22,8 @@
22 private GnomeMediaKeys mediakeys;22 private GnomeMediaKeys mediakeys;
23 private ClutterGst.Playback playback;23 private ClutterGst.Playback playback;
2424
25 private static uint inhibit_cookie = 0;
26
25 private bool mouse_primary_down = false;27 private bool mouse_primary_down = false;
2628
27 public bool repeat {29 public bool repeat {
@@ -192,7 +194,6 @@
192 settings.last_stopped = playback.progress;194 settings.last_stopped = playback.progress;
193195
194 get_playlist_widget ().save_playlist ();196 get_playlist_widget ().save_playlist ();
195 Audience.Services.Inhibitor.get_instance ().uninhibit ();
196 });197 });
197198
198 //end199 //end
@@ -231,9 +232,9 @@
231232
232 notify["playing"].connect (() => {233 notify["playing"].connect (() => {
233 if (playing) {234 if (playing) {
234 Audience.Services.Inhibitor.get_instance ().inhibit ();235 inhibit ();
235 } else {236 } else {
236 Audience.Services.Inhibitor.get_instance ().uninhibit ();237 uninhibit ();
237 }238 }
238 });239 });
239240
@@ -264,7 +265,7 @@
264265
265 bottom_bar.preferences_popover.is_setup = false;266 bottom_bar.preferences_popover.is_setup = false;
266267
267 Audience.Services.Inhibitor.get_instance ().inhibit ();268 inhibit ();
268 settings.current_video = uri;269 settings.current_video = uri;
269 }270 }
270271
@@ -366,6 +367,26 @@
366 return false;367 return false;
367 }368 }
368369
370 private void inhibit () {
371 if (inhibit_cookie != 0) {
372 return;
373 }
374
375 var app = App.get_instance ();
376 inhibit_cookie = app.inhibit (app.mainwindow,
377 Gtk.ApplicationInhibitFlags.SUSPEND | Gtk.ApplicationInhibitFlags.IDLE,
378 _("Playing movie"));
379 }
380
381 private void uninhibit () {
382 if (inhibit_cookie == 0) {
383 return;
384 }
385
386 App.get_instance ().uninhibit (inhibit_cookie);
387 inhibit_cookie = 0;
388 }
389
369 public bool update_pointer_position (double y, int window_height) {390 public bool update_pointer_position (double y, int window_height) {
370 App.get_instance ().mainwindow.get_window ().set_cursor (null);391 App.get_instance ().mainwindow.get_window ().set_cursor (null);
371392

Subscribers

People subscribed via source and target branches