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
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-11-02 23:59:41 +0000
3+++ src/CMakeLists.txt 2017-01-14 18:26:31 +0000
4@@ -66,7 +66,6 @@
5 Widgets/Library/LibraryItem.vala
6 Widgets/Library/EpisodesPage.vala
7
8- Services/Inhibitor.vala
9 Services/DirictoryMonitoring.vala
10 Services/LibraryManager.vala
11 Services/Thubnailer.vala
12
13=== removed file 'src/Services/Inhibitor.vala'
14--- src/Services/Inhibitor.vala 2016-07-19 11:56:12 +0000
15+++ src/Services/Inhibitor.vala 1970-01-01 00:00:00 +0000
16@@ -1,102 +0,0 @@
17-/*-
18- * Copyright (c) 2016 elementary LLC. (https://elementary.io)
19- *
20- * This program is free software: you can redistribute it and/or modify
21- * it under the terms of the GNU Library General Public License as published by
22- * the Free Software Foundation, either version 2.1 of the License, or
23- * (at your option) any later version.
24- *
25- * This program is distributed in the hope that it will be useful,
26- * but WITHOUT ANY WARRANTY; without even the implied warranty of
27- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28- * GNU Library General Public License for more details.
29- *
30- * You should have received a copy of the GNU Library General Public License
31- * along with this program. If not, see <http://www.gnu.org/licenses/>.
32- */
33-
34-[DBus (name = "org.freedesktop.ScreenSaver")]
35-public interface ScreenSaverIface : Object {
36- public abstract uint32 Inhibit (string app_name, string reason) throws Error;
37- public abstract void UnInhibit (uint32 cookie) throws Error;
38- public abstract void SimulateUserActivity () throws Error;
39-}
40-
41-public class Audience.Services.Inhibitor : Object {
42- private const string IFACE = "org.freedesktop.ScreenSaver";
43- private const string IFACE_PATH = "/ScreenSaver";
44-
45- private static Inhibitor? instance = null;
46-
47- private uint32? inhibit_cookie = null;
48-
49- private ScreenSaverIface? screensaver_iface = null;
50-
51- private bool inhibited = false;
52- private bool simulator_started = false;
53-
54- private Inhibitor () {
55- try {
56- screensaver_iface = Bus.get_proxy_sync (BusType.SESSION, IFACE, IFACE_PATH, DBusProxyFlags.NONE);
57- } catch (Error e) {
58- error ("Could not start screensaver interface: %s", e.message);
59- }
60- }
61-
62- public static Inhibitor get_instance () {
63- if (instance == null) {
64- instance = new Audience.Services.Inhibitor ();
65- }
66-
67- return instance;
68- }
69-
70- public void inhibit () {
71- if (screensaver_iface != null && !inhibited) {
72- try {
73- inhibited = true;
74- inhibit_cookie = screensaver_iface.Inhibit ("Audience", "Playing movie");
75- simulate_activity ();
76- debug ("Inhibiting screen");
77- } catch (Error e) {
78- error ("Could not inhibit screen: %s", e.message);
79- }
80- }
81- }
82-
83- public void uninhibit () {
84- if (screensaver_iface != null && inhibited) {//&& inhibit_cookie != null) {
85- try {
86- inhibited = false;
87- screensaver_iface.UnInhibit (inhibit_cookie);
88- debug ("Uninhibiting screen");
89- } catch (Error e) {
90- error ("Could not uninhibit screen: %s", e.message);
91- }
92- }
93- }
94-
95- /*
96- * Inhibit currently does not block a suspend from ocurring,
97- * so we simulate user activity every 2 mins to prevent it
98- */
99- private void simulate_activity () {
100- if (simulator_started) return;
101-
102- simulator_started = true;
103- Timeout.add_full (Priority.DEFAULT, 120000, ()=> {
104- if (inhibited) {
105- try {
106- debug ("Simulating activity");
107- screensaver_iface.SimulateUserActivity ();
108- } catch (Error e) {
109- error ("Could not simulate user activity: %s", e.message);
110- }
111- } else {
112- simulator_started = false;
113- }
114-
115- return inhibited;
116- });
117- }
118-}
119
120=== modified file 'src/Widgets/Player/PlayerPage.vala'
121--- src/Widgets/Player/PlayerPage.vala 2016-11-02 23:59:41 +0000
122+++ src/Widgets/Player/PlayerPage.vala 2017-01-14 18:26:31 +0000
123@@ -22,6 +22,8 @@
124 private GnomeMediaKeys mediakeys;
125 private ClutterGst.Playback playback;
126
127+ private static uint inhibit_cookie = 0;
128+
129 private bool mouse_primary_down = false;
130
131 public bool repeat {
132@@ -192,7 +194,6 @@
133 settings.last_stopped = playback.progress;
134
135 get_playlist_widget ().save_playlist ();
136- Audience.Services.Inhibitor.get_instance ().uninhibit ();
137 });
138
139 //end
140@@ -231,9 +232,9 @@
141
142 notify["playing"].connect (() => {
143 if (playing) {
144- Audience.Services.Inhibitor.get_instance ().inhibit ();
145+ inhibit ();
146 } else {
147- Audience.Services.Inhibitor.get_instance ().uninhibit ();
148+ uninhibit ();
149 }
150 });
151
152@@ -264,7 +265,7 @@
153
154 bottom_bar.preferences_popover.is_setup = false;
155
156- Audience.Services.Inhibitor.get_instance ().inhibit ();
157+ inhibit ();
158 settings.current_video = uri;
159 }
160
161@@ -366,6 +367,26 @@
162 return false;
163 }
164
165+ private void inhibit () {
166+ if (inhibit_cookie != 0) {
167+ return;
168+ }
169+
170+ var app = App.get_instance ();
171+ inhibit_cookie = app.inhibit (app.mainwindow,
172+ Gtk.ApplicationInhibitFlags.SUSPEND | Gtk.ApplicationInhibitFlags.IDLE,
173+ _("Playing movie"));
174+ }
175+
176+ private void uninhibit () {
177+ if (inhibit_cookie == 0) {
178+ return;
179+ }
180+
181+ App.get_instance ().uninhibit (inhibit_cookie);
182+ inhibit_cookie = 0;
183+ }
184+
185 public bool update_pointer_position (double y, int window_height) {
186 App.get_instance ().mainwindow.get_window ().set_cursor (null);
187

Subscribers

People subscribed via source and target branches