Merge lp:~psusi/ubuntu/natty/gnome-power-manager/sleep into lp:ubuntu/natty/gnome-power-manager
- Natty (11.04)
- sleep
- Merge into natty
Status: | Rejected |
---|---|
Rejected by: | James Westby |
Proposed branch: | lp:~psusi/ubuntu/natty/gnome-power-manager/sleep |
Merge into: | lp:ubuntu/natty/gnome-power-manager |
Diff against target: |
985 lines (+761/-89) 7 files modified
.pc/applied-patches (+2/-0) .pc/lock-screen-on-signal.patch/src/gpm-control.c (+347/-0) debian/changelog (+9/-0) debian/control (+1/-1) debian/patches/lock-screen-on-signal.patch (+291/-0) debian/patches/series (+1/-0) src/gpm-control.c (+110/-88) |
To merge this branch: | bzr merge lp:~psusi/ubuntu/natty/gnome-power-manager/sleep |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Coulson (community) | Disapprove | ||
Phillip Susi (community) | Needs Resubmitting | ||
Chris Halse Rogers | Needs Fixing | ||
Ubuntu branches | Pending | ||
Review via email: mp+54095@code.launchpad.net |
Commit message
Description of the change
See linked bug report and related branches that all need merged together.
- 188. By Phillip Susi
-
Add lock-screen-
on-signal. patch: refactor gpm suspend and hibernate
methods to lock the screen in response to the signal from upower
indicating that the system is suspending or hibernating, instead of
as part of its decision to suspend or hibernate. (LP: #578542)
Phillip Susi (psusi) wrote : | # |
Oops, good point. I forgot a hunk of code when migrating it from the old suspend control method to the resuming signal handler. I also forgot to remove the duplicate code from the hibernate control method that is now in the signal handlers. Took care of that.
Chris Coulson (chrisccoulson) wrote : | # |
Note that this depends on the upower merge (see my comment there)
Unmerged revisions
- 188. By Phillip Susi
-
Add lock-screen-
on-signal. patch: refactor gpm suspend and hibernate
methods to lock the screen in response to the signal from upower
indicating that the system is suspending or hibernating, instead of
as part of its decision to suspend or hibernate. (LP: #578542)
Preview Diff
1 | === modified file '.pc/applied-patches' |
2 | --- .pc/applied-patches 2011-03-15 01:04:40 +0000 |
3 | +++ .pc/applied-patches 2011-03-29 15:14:57 +0000 |
4 | @@ -1,3 +1,4 @@ |
5 | + |
6 | 00git-devices-changed-signal.patch |
7 | 02-notify-osd-support.patch |
8 | 08-desktop-bugreport-path.patch |
9 | @@ -6,3 +7,4 @@ |
10 | 14_fix_no_xbacklight_crash.patch |
11 | 14-critical-message-timeout.patch |
12 | 15-keyboard-backlight-support.patch |
13 | +lock-screen-on-signal.patch |
14 | |
15 | === added directory '.pc/lock-screen-on-signal.patch' |
16 | === added file '.pc/lock-screen-on-signal.patch/.timestamp' |
17 | === added directory '.pc/lock-screen-on-signal.patch/src' |
18 | === added file '.pc/lock-screen-on-signal.patch/src/gpm-control.c' |
19 | --- .pc/lock-screen-on-signal.patch/src/gpm-control.c 1970-01-01 00:00:00 +0000 |
20 | +++ .pc/lock-screen-on-signal.patch/src/gpm-control.c 2011-03-29 15:14:57 +0000 |
21 | @@ -0,0 +1,347 @@ |
22 | +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- |
23 | + * |
24 | + * Copyright (C) 2006-2007 Richard Hughes <richard@hughsie.com> |
25 | + * |
26 | + * Licensed under the GNU General Public License Version 2 |
27 | + * |
28 | + * This program is free software; you can redistribute it and/or modify |
29 | + * it under the terms of the GNU General Public License as published by |
30 | + * the Free Software Foundation; either version 2 of the License, or |
31 | + * (at your option) any later version. |
32 | + * |
33 | + * This program is distributed in the hope that it will be useful, |
34 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
35 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
36 | + * GNU General Public License for more details. |
37 | + * |
38 | + * You should have received a copy of the GNU General Public License |
39 | + * along with this program; if not, write to the Free Software |
40 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
41 | + */ |
42 | + |
43 | +#ifdef HAVE_CONFIG_H |
44 | +# include <config.h> |
45 | +#endif |
46 | + |
47 | +#include <stdlib.h> |
48 | +#include <stdio.h> |
49 | +#include <time.h> |
50 | +#include <errno.h> |
51 | + |
52 | +#include <string.h> |
53 | +#include <sys/time.h> |
54 | +#include <sys/types.h> |
55 | +#include <sys/wait.h> |
56 | +#ifdef HAVE_UNISTD_H |
57 | +#include <unistd.h> |
58 | +#endif /* HAVE_UNISTD_H */ |
59 | + |
60 | +#include <glib/gi18n.h> |
61 | +#include <dbus/dbus-glib.h> |
62 | +#include <dbus/dbus-glib-lowlevel.h> |
63 | +#include <gnome-keyring.h> |
64 | +#include <gconf/gconf-client.h> |
65 | +#include <libupower-glib/upower.h> |
66 | + |
67 | +#include "egg-debug.h" |
68 | +#include "egg-console-kit.h" |
69 | + |
70 | +#include "gpm-screensaver.h" |
71 | +#include "gpm-common.h" |
72 | +#include "gpm-control.h" |
73 | +#include "gpm-networkmanager.h" |
74 | + |
75 | +#define GPM_CONTROL_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_CONTROL, GpmControlPrivate)) |
76 | + |
77 | +struct GpmControlPrivate |
78 | +{ |
79 | + GConfClient *conf; |
80 | + UpClient *client; |
81 | +}; |
82 | + |
83 | +enum { |
84 | + RESUME, |
85 | + SLEEP, |
86 | + LAST_SIGNAL |
87 | +}; |
88 | + |
89 | +static guint signals [LAST_SIGNAL] = { 0 }; |
90 | +static gpointer gpm_control_object = NULL; |
91 | + |
92 | +G_DEFINE_TYPE (GpmControl, gpm_control, G_TYPE_OBJECT) |
93 | + |
94 | +/** |
95 | + * gpm_control_error_quark: |
96 | + * Return value: Our personal error quark. |
97 | + **/ |
98 | +GQuark |
99 | +gpm_control_error_quark (void) |
100 | +{ |
101 | + static GQuark quark = 0; |
102 | + if (!quark) |
103 | + quark = g_quark_from_static_string ("gpm_control_error"); |
104 | + return quark; |
105 | +} |
106 | + |
107 | +/** |
108 | + * gpm_control_shutdown: |
109 | + * @control: This class instance |
110 | + * |
111 | + * Shuts down the computer |
112 | + **/ |
113 | +gboolean |
114 | +gpm_control_shutdown (GpmControl *control, GError **error) |
115 | +{ |
116 | + gboolean ret; |
117 | + EggConsoleKit *console; |
118 | + console = egg_console_kit_new (); |
119 | + ret = egg_console_kit_stop (console, error); |
120 | + g_object_unref (console); |
121 | + return ret; |
122 | +} |
123 | + |
124 | +/** |
125 | + * gpm_control_get_lock_policy: |
126 | + * @control: This class instance |
127 | + * @policy: The policy gconf string. |
128 | + * |
129 | + * This function finds out if we should lock the screen when we do an |
130 | + * action. It is required as we can either use the gnome-screensaver policy |
131 | + * or the custom policy. See the yelp file for more information. |
132 | + * |
133 | + * Return value: TRUE if we should lock. |
134 | + **/ |
135 | +gboolean |
136 | +gpm_control_get_lock_policy (GpmControl *control, const gchar *policy) |
137 | +{ |
138 | + gboolean do_lock; |
139 | + gboolean use_ss_setting; |
140 | + /* This allows us to over-ride the custom lock settings set in gconf |
141 | + with a system default set in gnome-screensaver. |
142 | + See bug #331164 for all the juicy details. :-) */ |
143 | + use_ss_setting = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_USE_SCREENSAVER, NULL); |
144 | + if (use_ss_setting) { |
145 | + do_lock = gconf_client_get_bool (control->priv->conf, GS_PREF_LOCK_ENABLED, NULL); |
146 | + egg_debug ("Using ScreenSaver settings (%i)", do_lock); |
147 | + } else { |
148 | + do_lock = gconf_client_get_bool (control->priv->conf, policy, NULL); |
149 | + egg_debug ("Using custom locking settings (%i)", do_lock); |
150 | + } |
151 | + return do_lock; |
152 | +} |
153 | + |
154 | +/** |
155 | + * gpm_control_suspend: |
156 | + **/ |
157 | +gboolean |
158 | +gpm_control_suspend (GpmControl *control, GError **error) |
159 | +{ |
160 | + gboolean allowed; |
161 | + gboolean ret = FALSE; |
162 | + gboolean do_lock; |
163 | + gboolean nm_sleep; |
164 | + gboolean lock_gnome_keyring; |
165 | + GnomeKeyringResult keyres; |
166 | + GpmScreensaver *screensaver; |
167 | + guint32 throttle_cookie = 0; |
168 | + |
169 | + screensaver = gpm_screensaver_new (); |
170 | + |
171 | + g_object_get (control->priv->client, |
172 | + "can-suspend", &allowed, |
173 | + NULL); |
174 | + if (!allowed) { |
175 | + egg_debug ("cannot suspend as not allowed from policy"); |
176 | + g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend"); |
177 | + goto out; |
178 | + } |
179 | + |
180 | + /* we should perhaps lock keyrings when sleeping #375681 */ |
181 | + lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_SUSPEND, NULL); |
182 | + if (lock_gnome_keyring) { |
183 | + keyres = gnome_keyring_lock_all_sync (); |
184 | + if (keyres != GNOME_KEYRING_RESULT_OK) |
185 | + egg_warning ("could not lock keyring"); |
186 | + } |
187 | + |
188 | + do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
189 | + if (do_lock) { |
190 | + throttle_cookie = gpm_screensaver_add_throttle (screensaver, "suspend"); |
191 | + gpm_screensaver_lock (screensaver); |
192 | + } |
193 | + |
194 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
195 | + if (nm_sleep) |
196 | + gpm_networkmanager_sleep (); |
197 | + |
198 | + /* Do the suspend */ |
199 | + egg_debug ("emitting sleep"); |
200 | + g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND); |
201 | + |
202 | + ret = up_client_suspend_sync (control->priv->client, NULL, error); |
203 | + |
204 | + egg_debug ("emitting resume"); |
205 | + g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND); |
206 | + |
207 | + if (do_lock) { |
208 | + gpm_screensaver_poke (screensaver); |
209 | + if (throttle_cookie) |
210 | + gpm_screensaver_remove_throttle (screensaver, throttle_cookie); |
211 | + } |
212 | + |
213 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
214 | + if (nm_sleep) |
215 | + gpm_networkmanager_wake (); |
216 | + |
217 | +out: |
218 | + g_object_unref (screensaver); |
219 | + return ret; |
220 | +} |
221 | + |
222 | +/** |
223 | + * gpm_control_hibernate: |
224 | + **/ |
225 | +gboolean |
226 | +gpm_control_hibernate (GpmControl *control, GError **error) |
227 | +{ |
228 | + gboolean allowed; |
229 | + gboolean ret = FALSE; |
230 | + gboolean do_lock; |
231 | + gboolean nm_sleep; |
232 | + gboolean lock_gnome_keyring; |
233 | + GnomeKeyringResult keyres; |
234 | + GpmScreensaver *screensaver; |
235 | + guint32 throttle_cookie = 0; |
236 | + |
237 | + screensaver = gpm_screensaver_new (); |
238 | + |
239 | + g_object_get (control->priv->client, |
240 | + "can-hibernate", &allowed, |
241 | + NULL); |
242 | + if (!allowed) { |
243 | + egg_debug ("cannot hibernate as not allowed from policy"); |
244 | + g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot hibernate"); |
245 | + goto out; |
246 | + } |
247 | + |
248 | + /* we should perhaps lock keyrings when sleeping #375681 */ |
249 | + lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_HIBERNATE, NULL); |
250 | + if (lock_gnome_keyring) { |
251 | + keyres = gnome_keyring_lock_all_sync (); |
252 | + if (keyres != GNOME_KEYRING_RESULT_OK) { |
253 | + egg_warning ("could not lock keyring"); |
254 | + } |
255 | + } |
256 | + |
257 | + do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
258 | + if (do_lock) { |
259 | + throttle_cookie = gpm_screensaver_add_throttle (screensaver, "hibernate"); |
260 | + gpm_screensaver_lock (screensaver); |
261 | + } |
262 | + |
263 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
264 | + if (nm_sleep) |
265 | + gpm_networkmanager_sleep (); |
266 | + |
267 | + egg_debug ("emitting sleep"); |
268 | + g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_HIBERNATE); |
269 | + |
270 | + ret = up_client_hibernate_sync (control->priv->client, NULL, error); |
271 | + |
272 | + egg_debug ("emitting resume"); |
273 | + g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE); |
274 | + |
275 | + if (do_lock) { |
276 | + gpm_screensaver_poke (screensaver); |
277 | + if (throttle_cookie) |
278 | + gpm_screensaver_remove_throttle (screensaver, throttle_cookie); |
279 | + } |
280 | + |
281 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
282 | + if (nm_sleep) |
283 | + gpm_networkmanager_wake (); |
284 | + |
285 | +out: |
286 | + g_object_unref (screensaver); |
287 | + return ret; |
288 | +} |
289 | + |
290 | +/** |
291 | + * gpm_control_finalize: |
292 | + **/ |
293 | +static void |
294 | +gpm_control_finalize (GObject *object) |
295 | +{ |
296 | + GpmControl *control; |
297 | + |
298 | + g_return_if_fail (object != NULL); |
299 | + g_return_if_fail (GPM_IS_CONTROL (object)); |
300 | + control = GPM_CONTROL (object); |
301 | + |
302 | + g_object_unref (control->priv->conf); |
303 | + g_object_unref (control->priv->client); |
304 | + |
305 | + g_return_if_fail (control->priv != NULL); |
306 | + G_OBJECT_CLASS (gpm_control_parent_class)->finalize (object); |
307 | +} |
308 | + |
309 | +/** |
310 | + * gpm_control_class_init: |
311 | + **/ |
312 | +static void |
313 | +gpm_control_class_init (GpmControlClass *klass) |
314 | +{ |
315 | + GObjectClass *object_class = G_OBJECT_CLASS (klass); |
316 | + object_class->finalize = gpm_control_finalize; |
317 | + |
318 | + signals [RESUME] = |
319 | + g_signal_new ("resume", |
320 | + G_TYPE_FROM_CLASS (object_class), |
321 | + G_SIGNAL_RUN_LAST, |
322 | + G_STRUCT_OFFSET (GpmControlClass, resume), |
323 | + NULL, |
324 | + NULL, |
325 | + g_cclosure_marshal_VOID__INT, |
326 | + G_TYPE_NONE, 1, G_TYPE_INT); |
327 | + signals [SLEEP] = |
328 | + g_signal_new ("sleep", |
329 | + G_TYPE_FROM_CLASS (object_class), |
330 | + G_SIGNAL_RUN_LAST, |
331 | + G_STRUCT_OFFSET (GpmControlClass, sleep), |
332 | + NULL, |
333 | + NULL, |
334 | + g_cclosure_marshal_VOID__INT, |
335 | + G_TYPE_NONE, 1, G_TYPE_INT); |
336 | + |
337 | + g_type_class_add_private (klass, sizeof (GpmControlPrivate)); |
338 | +} |
339 | + |
340 | +/** |
341 | + * gpm_control_init: |
342 | + * @control: This control class instance |
343 | + **/ |
344 | +static void |
345 | +gpm_control_init (GpmControl *control) |
346 | +{ |
347 | + control->priv = GPM_CONTROL_GET_PRIVATE (control); |
348 | + |
349 | + control->priv->client = up_client_new (); |
350 | + control->priv->conf = gconf_client_get_default (); |
351 | +} |
352 | + |
353 | +/** |
354 | + * gpm_control_new: |
355 | + * Return value: A new control class instance. |
356 | + **/ |
357 | +GpmControl * |
358 | +gpm_control_new (void) |
359 | +{ |
360 | + if (gpm_control_object != NULL) { |
361 | + g_object_ref (gpm_control_object); |
362 | + } else { |
363 | + gpm_control_object = g_object_new (GPM_TYPE_CONTROL, NULL); |
364 | + g_object_add_weak_pointer (gpm_control_object, &gpm_control_object); |
365 | + } |
366 | + return GPM_CONTROL (gpm_control_object); |
367 | +} |
368 | + |
369 | |
370 | === modified file 'debian/changelog' |
371 | --- debian/changelog 2011-03-15 01:04:40 +0000 |
372 | +++ debian/changelog 2011-03-29 15:14:57 +0000 |
373 | @@ -1,3 +1,12 @@ |
374 | +gnome-power-manager (2.32.0-2ubuntu3) natty; urgency=low |
375 | + |
376 | + * Add lock-screen-on-signal.patch: refactor gpm suspend and hibernate |
377 | + methods to lock the screen in response to the signal from upower |
378 | + indicating that the system is suspending or hibernating, instead of |
379 | + as part of its decision to suspend or hibernate. (LP: #578542) |
380 | + |
381 | + -- Phillip Susi <psusi@cfl.rr.com> Mon, 07 Mar 2011 15:05:01 -0500 |
382 | + |
383 | gnome-power-manager (2.32.0-2ubuntu2) natty; urgency=low |
384 | |
385 | [ Alex Murray <murray.alex@gmail.com> ] |
386 | |
387 | === modified file 'debian/control' |
388 | --- debian/control 2011-01-26 17:20:06 +0000 |
389 | +++ debian/control 2011-03-29 15:14:57 +0000 |
390 | @@ -48,7 +48,7 @@ |
391 | notification-daemon, |
392 | dbus-x11, |
393 | consolekit, |
394 | - upower |
395 | + upower (>= 0.9.8-3ubuntu1) |
396 | Breaks: gnome-session (<< 2.28) |
397 | Recommends: udisks |
398 | Suggests: policykit-1 |
399 | |
400 | === added file 'debian/patches/lock-screen-on-signal.patch' |
401 | --- debian/patches/lock-screen-on-signal.patch 1970-01-01 00:00:00 +0000 |
402 | +++ debian/patches/lock-screen-on-signal.patch 2011-03-29 15:14:57 +0000 |
403 | @@ -0,0 +1,291 @@ |
404 | +From: Phillip Susi <psusi@cfl.rr.com> |
405 | +Last-Update: 2011-03-18 |
406 | +Description: g-p-m used to handle requests to sleep and had config options |
407 | + to lock the screen when suspending and/or hibernating. The functionality |
408 | + of actually performing the suspend or hibernate has since been moved to |
409 | + upower. Because of this, g-p-m no longer had the chance to lock the |
410 | + screen when the system was manually suspended ( as opposed to g-p-m |
411 | + deciding to suspend the system due to idle time or lid switch ). This |
412 | + patch moves this code from the gpm control object suspend and hibernate |
413 | + methods to its SLEEPING and RESUMING signals instead, and ties those |
414 | + signals to upower via dbus. |
415 | +Index: b/src/gpm-control.c |
416 | +=================================================================== |
417 | +--- a/src/gpm-control.c |
418 | ++++ b/src/gpm-control.c |
419 | +@@ -57,6 +57,9 @@ |
420 | + { |
421 | + GConfClient *conf; |
422 | + UpClient *client; |
423 | ++ guint32 throttle_cookie; |
424 | ++ GpmScreensaver *screensaver; |
425 | ++ DBusGProxy *proxy; |
426 | + }; |
427 | + |
428 | + enum { |
429 | +@@ -130,71 +133,90 @@ |
430 | + return do_lock; |
431 | + } |
432 | + |
433 | +-/** |
434 | +- * gpm_control_suspend: |
435 | +- **/ |
436 | +-gboolean |
437 | +-gpm_control_suspend (GpmControl *control, GError **error) |
438 | ++static void gpm_control_sleep(GpmControl *control, |
439 | ++ GpmControlAction action) |
440 | + { |
441 | +- gboolean allowed; |
442 | +- gboolean ret = FALSE; |
443 | ++ gboolean lock_gnome_keyring; |
444 | + gboolean do_lock; |
445 | + gboolean nm_sleep; |
446 | +- gboolean lock_gnome_keyring; |
447 | + GnomeKeyringResult keyres; |
448 | +- GpmScreensaver *screensaver; |
449 | +- guint32 throttle_cookie = 0; |
450 | +- |
451 | +- screensaver = gpm_screensaver_new (); |
452 | + |
453 | +- g_object_get (control->priv->client, |
454 | +- "can-suspend", &allowed, |
455 | +- NULL); |
456 | +- if (!allowed) { |
457 | +- egg_debug ("cannot suspend as not allowed from policy"); |
458 | +- g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend"); |
459 | +- goto out; |
460 | ++ control->priv->screensaver = gpm_screensaver_new (); |
461 | ++ if (action == GPM_CONTROL_ACTION_HIBERNATE) { |
462 | ++ do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
463 | ++ lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_HIBERNATE, NULL); |
464 | ++ } |
465 | ++ else { // GPM_CONTROL_ACTION_SUSPEND |
466 | ++ do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
467 | ++ lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_SUSPEND, NULL); |
468 | + } |
469 | + |
470 | + /* we should perhaps lock keyrings when sleeping #375681 */ |
471 | +- lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_SUSPEND, NULL); |
472 | + if (lock_gnome_keyring) { |
473 | + keyres = gnome_keyring_lock_all_sync (); |
474 | + if (keyres != GNOME_KEYRING_RESULT_OK) |
475 | + egg_warning ("could not lock keyring"); |
476 | + } |
477 | + |
478 | +- do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
479 | + if (do_lock) { |
480 | +- throttle_cookie = gpm_screensaver_add_throttle (screensaver, "suspend"); |
481 | +- gpm_screensaver_lock (screensaver); |
482 | ++ if (action == GPM_CONTROL_ACTION_HIBERNATE) |
483 | ++ control->priv->throttle_cookie = gpm_screensaver_add_throttle (control->priv->screensaver, "hibernate"); |
484 | ++ else control->priv->throttle_cookie = gpm_screensaver_add_throttle (control->priv->screensaver, "suspend"); |
485 | ++ gpm_screensaver_lock (control->priv->screensaver); |
486 | + } |
487 | + |
488 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
489 | + if (nm_sleep) |
490 | + gpm_networkmanager_sleep (); |
491 | ++} |
492 | + |
493 | +- /* Do the suspend */ |
494 | +- egg_debug ("emitting sleep"); |
495 | +- g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND); |
496 | +- |
497 | +- ret = up_client_suspend_sync (control->priv->client, NULL, error); |
498 | +- |
499 | +- egg_debug ("emitting resume"); |
500 | +- g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND); |
501 | ++static void gpm_control_resume(GpmControl *control, |
502 | ++ GpmControlAction action) |
503 | ++{ |
504 | ++ gboolean do_lock; |
505 | ++ gboolean nm_sleep; |
506 | + |
507 | +- if (do_lock) { |
508 | +- gpm_screensaver_poke (screensaver); |
509 | +- if (throttle_cookie) |
510 | +- gpm_screensaver_remove_throttle (screensaver, throttle_cookie); |
511 | ++ if (action == GPM_CONTROL_ACTION_HIBERNATE) { |
512 | ++ do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
513 | ++ } |
514 | ++ else { |
515 | ++ do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
516 | ++ } |
517 | ++ if (control->priv->throttle_cookie) { |
518 | ++ gpm_screensaver_poke (control->priv->screensaver); |
519 | ++ gpm_screensaver_remove_throttle (control->priv->screensaver, control->priv->throttle_cookie); |
520 | + } |
521 | +- |
522 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
523 | + if (nm_sleep) |
524 | + gpm_networkmanager_wake (); |
525 | + |
526 | ++ g_object_unref (control->priv->screensaver); |
527 | ++ control->priv->screensaver = NULL; |
528 | ++ control->priv->throttle_cookie = 0; |
529 | ++} |
530 | ++ |
531 | ++/** |
532 | ++ * gpm_control_suspend: |
533 | ++ **/ |
534 | ++gboolean |
535 | ++gpm_control_suspend (GpmControl *control, GError **error) |
536 | ++{ |
537 | ++ gboolean allowed; |
538 | ++ gboolean ret = FALSE; |
539 | ++ |
540 | ++ g_object_get (control->priv->client, |
541 | ++ "can-suspend", &allowed, |
542 | ++ NULL); |
543 | ++ if (!allowed) { |
544 | ++ egg_debug ("cannot suspend as not allowed from policy"); |
545 | ++ g_set_error_literal (error, GPM_CONTROL_ERROR, GPM_CONTROL_ERROR_GENERAL, "Cannot suspend"); |
546 | ++ goto out; |
547 | ++ } |
548 | ++ |
549 | ++ /* Do the suspend */ |
550 | ++ |
551 | ++ ret = up_client_suspend_sync (control->priv->client, NULL, error); |
552 | + out: |
553 | +- g_object_unref (screensaver); |
554 | + return ret; |
555 | + } |
556 | + |
557 | +@@ -206,14 +228,6 @@ |
558 | + { |
559 | + gboolean allowed; |
560 | + gboolean ret = FALSE; |
561 | +- gboolean do_lock; |
562 | +- gboolean nm_sleep; |
563 | +- gboolean lock_gnome_keyring; |
564 | +- GnomeKeyringResult keyres; |
565 | +- GpmScreensaver *screensaver; |
566 | +- guint32 throttle_cookie = 0; |
567 | +- |
568 | +- screensaver = gpm_screensaver_new (); |
569 | + |
570 | + g_object_get (control->priv->client, |
571 | + "can-hibernate", &allowed, |
572 | +@@ -224,45 +238,8 @@ |
573 | + goto out; |
574 | + } |
575 | + |
576 | +- /* we should perhaps lock keyrings when sleeping #375681 */ |
577 | +- lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_HIBERNATE, NULL); |
578 | +- if (lock_gnome_keyring) { |
579 | +- keyres = gnome_keyring_lock_all_sync (); |
580 | +- if (keyres != GNOME_KEYRING_RESULT_OK) { |
581 | +- egg_warning ("could not lock keyring"); |
582 | +- } |
583 | +- } |
584 | +- |
585 | +- do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
586 | +- if (do_lock) { |
587 | +- throttle_cookie = gpm_screensaver_add_throttle (screensaver, "hibernate"); |
588 | +- gpm_screensaver_lock (screensaver); |
589 | +- } |
590 | +- |
591 | +- nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
592 | +- if (nm_sleep) |
593 | +- gpm_networkmanager_sleep (); |
594 | +- |
595 | +- egg_debug ("emitting sleep"); |
596 | +- g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_HIBERNATE); |
597 | +- |
598 | + ret = up_client_hibernate_sync (control->priv->client, NULL, error); |
599 | +- |
600 | +- egg_debug ("emitting resume"); |
601 | +- g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE); |
602 | +- |
603 | +- if (do_lock) { |
604 | +- gpm_screensaver_poke (screensaver); |
605 | +- if (throttle_cookie) |
606 | +- gpm_screensaver_remove_throttle (screensaver, throttle_cookie); |
607 | +- } |
608 | +- |
609 | +- nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
610 | +- if (nm_sleep) |
611 | +- gpm_networkmanager_wake (); |
612 | +- |
613 | + out: |
614 | +- g_object_unref (screensaver); |
615 | + return ret; |
616 | + } |
617 | + |
618 | +@@ -280,6 +257,7 @@ |
619 | + |
620 | + g_object_unref (control->priv->conf); |
621 | + g_object_unref (control->priv->client); |
622 | ++ g_object_unref (control->priv->proxy); |
623 | + |
624 | + g_return_if_fail (control->priv != NULL); |
625 | + G_OBJECT_CLASS (gpm_control_parent_class)->finalize (object); |
626 | +@@ -293,6 +271,8 @@ |
627 | + { |
628 | + GObjectClass *object_class = G_OBJECT_CLASS (klass); |
629 | + object_class->finalize = gpm_control_finalize; |
630 | ++ klass->sleep = gpm_control_sleep; |
631 | ++ klass->resume = gpm_control_resume; |
632 | + |
633 | + signals [RESUME] = |
634 | + g_signal_new ("resume", |
635 | +@@ -316,6 +296,16 @@ |
636 | + g_type_class_add_private (klass, sizeof (GpmControlPrivate)); |
637 | + } |
638 | + |
639 | ++static void proxy_sleeping_cb (DBusGProxy *proxy, guint type, GpmControl *control) |
640 | ++{ |
641 | ++ g_signal_emit (control, signals [SLEEP], 0, type); |
642 | ++} |
643 | ++ |
644 | ++static void proxy_resuming_cb (DBusGProxy *proxy, guint type, GpmControl *control) |
645 | ++{ |
646 | ++ g_signal_emit (control, signals [RESUME], 0, type); |
647 | ++} |
648 | ++ |
649 | + /** |
650 | + * gpm_control_init: |
651 | + * @control: This control class instance |
652 | +@@ -323,10 +313,42 @@ |
653 | + static void |
654 | + gpm_control_init (GpmControl *control) |
655 | + { |
656 | ++ DBusGConnection *connection; |
657 | ++ GError *error = NULL; |
658 | ++ |
659 | ++ connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); |
660 | ++ g_assert_no_error (error); |
661 | + control->priv = GPM_CONTROL_GET_PRIVATE (control); |
662 | + |
663 | + control->priv->client = up_client_new (); |
664 | + control->priv->conf = gconf_client_get_default (); |
665 | ++ control->priv->proxy = dbus_g_proxy_new_for_name_owner (connection, |
666 | ++ "org.freedesktop.UPower", |
667 | ++ "/org/freedesktop/UPower", |
668 | ++ "org.freedesktop.UPower", |
669 | ++ &error); |
670 | ++ control->priv->throttle_cookie = 0; |
671 | ++ control->priv->screensaver = 0; |
672 | ++ g_assert_no_error (error); |
673 | ++ dbus_g_proxy_add_signal (control->priv->proxy, |
674 | ++ "Sleeping", |
675 | ++ G_TYPE_UINT, |
676 | ++ G_TYPE_INVALID); |
677 | ++ dbus_g_proxy_connect_signal (control->priv->proxy, |
678 | ++ "Sleeping", |
679 | ++ G_CALLBACK (proxy_sleeping_cb), |
680 | ++ control, |
681 | ++ NULL); |
682 | ++ dbus_g_proxy_add_signal (control->priv->proxy, |
683 | ++ "Resuming", |
684 | ++ G_TYPE_UINT, |
685 | ++ G_TYPE_INVALID); |
686 | ++ dbus_g_proxy_connect_signal (control->priv->proxy, |
687 | ++ "Resuming", |
688 | ++ G_CALLBACK (proxy_resuming_cb), |
689 | ++ control, |
690 | ++ NULL); |
691 | ++ g_object_unref (connection); |
692 | + } |
693 | + |
694 | + /** |
695 | |
696 | === modified file 'debian/patches/series' |
697 | --- debian/patches/series 2011-03-15 01:04:40 +0000 |
698 | +++ debian/patches/series 2011-03-29 15:14:57 +0000 |
699 | @@ -6,3 +6,4 @@ |
700 | 14_fix_no_xbacklight_crash.patch |
701 | 14-critical-message-timeout.patch |
702 | 15-keyboard-backlight-support.patch |
703 | +lock-screen-on-signal.patch |
704 | |
705 | === modified file 'src/gpm-control.c' |
706 | --- src/gpm-control.c 2011-01-26 17:20:06 +0000 |
707 | +++ src/gpm-control.c 2011-03-29 15:14:57 +0000 |
708 | @@ -57,6 +57,9 @@ |
709 | { |
710 | GConfClient *conf; |
711 | UpClient *client; |
712 | + guint32 throttle_cookie; |
713 | + GpmScreensaver *screensaver; |
714 | + DBusGProxy *proxy; |
715 | }; |
716 | |
717 | enum { |
718 | @@ -130,6 +133,68 @@ |
719 | return do_lock; |
720 | } |
721 | |
722 | +static void gpm_control_sleep(GpmControl *control, |
723 | + GpmControlAction action) |
724 | +{ |
725 | + gboolean lock_gnome_keyring; |
726 | + gboolean do_lock; |
727 | + gboolean nm_sleep; |
728 | + GnomeKeyringResult keyres; |
729 | + |
730 | + control->priv->screensaver = gpm_screensaver_new (); |
731 | + if (action == GPM_CONTROL_ACTION_HIBERNATE) { |
732 | + do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
733 | + lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_HIBERNATE, NULL); |
734 | + } |
735 | + else { // GPM_CONTROL_ACTION_SUSPEND |
736 | + do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
737 | + lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_SUSPEND, NULL); |
738 | + } |
739 | + |
740 | + /* we should perhaps lock keyrings when sleeping #375681 */ |
741 | + if (lock_gnome_keyring) { |
742 | + keyres = gnome_keyring_lock_all_sync (); |
743 | + if (keyres != GNOME_KEYRING_RESULT_OK) |
744 | + egg_warning ("could not lock keyring"); |
745 | + } |
746 | + |
747 | + if (do_lock) { |
748 | + if (action == GPM_CONTROL_ACTION_HIBERNATE) |
749 | + control->priv->throttle_cookie = gpm_screensaver_add_throttle (control->priv->screensaver, "hibernate"); |
750 | + else control->priv->throttle_cookie = gpm_screensaver_add_throttle (control->priv->screensaver, "suspend"); |
751 | + gpm_screensaver_lock (control->priv->screensaver); |
752 | + } |
753 | + |
754 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
755 | + if (nm_sleep) |
756 | + gpm_networkmanager_sleep (); |
757 | +} |
758 | + |
759 | +static void gpm_control_resume(GpmControl *control, |
760 | + GpmControlAction action) |
761 | +{ |
762 | + gboolean do_lock; |
763 | + gboolean nm_sleep; |
764 | + |
765 | + if (action == GPM_CONTROL_ACTION_HIBERNATE) { |
766 | + do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
767 | + } |
768 | + else { |
769 | + do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
770 | + } |
771 | + if (control->priv->throttle_cookie) { |
772 | + gpm_screensaver_poke (control->priv->screensaver); |
773 | + gpm_screensaver_remove_throttle (control->priv->screensaver, control->priv->throttle_cookie); |
774 | + } |
775 | + nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
776 | + if (nm_sleep) |
777 | + gpm_networkmanager_wake (); |
778 | + |
779 | + g_object_unref (control->priv->screensaver); |
780 | + control->priv->screensaver = NULL; |
781 | + control->priv->throttle_cookie = 0; |
782 | +} |
783 | + |
784 | /** |
785 | * gpm_control_suspend: |
786 | **/ |
787 | @@ -138,14 +203,6 @@ |
788 | { |
789 | gboolean allowed; |
790 | gboolean ret = FALSE; |
791 | - gboolean do_lock; |
792 | - gboolean nm_sleep; |
793 | - gboolean lock_gnome_keyring; |
794 | - GnomeKeyringResult keyres; |
795 | - GpmScreensaver *screensaver; |
796 | - guint32 throttle_cookie = 0; |
797 | - |
798 | - screensaver = gpm_screensaver_new (); |
799 | |
800 | g_object_get (control->priv->client, |
801 | "can-suspend", &allowed, |
802 | @@ -156,45 +213,10 @@ |
803 | goto out; |
804 | } |
805 | |
806 | - /* we should perhaps lock keyrings when sleeping #375681 */ |
807 | - lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_SUSPEND, NULL); |
808 | - if (lock_gnome_keyring) { |
809 | - keyres = gnome_keyring_lock_all_sync (); |
810 | - if (keyres != GNOME_KEYRING_RESULT_OK) |
811 | - egg_warning ("could not lock keyring"); |
812 | - } |
813 | - |
814 | - do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_SUSPEND); |
815 | - if (do_lock) { |
816 | - throttle_cookie = gpm_screensaver_add_throttle (screensaver, "suspend"); |
817 | - gpm_screensaver_lock (screensaver); |
818 | - } |
819 | - |
820 | - nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
821 | - if (nm_sleep) |
822 | - gpm_networkmanager_sleep (); |
823 | - |
824 | /* Do the suspend */ |
825 | - egg_debug ("emitting sleep"); |
826 | - g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_SUSPEND); |
827 | |
828 | ret = up_client_suspend_sync (control->priv->client, NULL, error); |
829 | - |
830 | - egg_debug ("emitting resume"); |
831 | - g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_SUSPEND); |
832 | - |
833 | - if (do_lock) { |
834 | - gpm_screensaver_poke (screensaver); |
835 | - if (throttle_cookie) |
836 | - gpm_screensaver_remove_throttle (screensaver, throttle_cookie); |
837 | - } |
838 | - |
839 | - nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
840 | - if (nm_sleep) |
841 | - gpm_networkmanager_wake (); |
842 | - |
843 | out: |
844 | - g_object_unref (screensaver); |
845 | return ret; |
846 | } |
847 | |
848 | @@ -206,14 +228,6 @@ |
849 | { |
850 | gboolean allowed; |
851 | gboolean ret = FALSE; |
852 | - gboolean do_lock; |
853 | - gboolean nm_sleep; |
854 | - gboolean lock_gnome_keyring; |
855 | - GnomeKeyringResult keyres; |
856 | - GpmScreensaver *screensaver; |
857 | - guint32 throttle_cookie = 0; |
858 | - |
859 | - screensaver = gpm_screensaver_new (); |
860 | |
861 | g_object_get (control->priv->client, |
862 | "can-hibernate", &allowed, |
863 | @@ -224,45 +238,8 @@ |
864 | goto out; |
865 | } |
866 | |
867 | - /* we should perhaps lock keyrings when sleeping #375681 */ |
868 | - lock_gnome_keyring = gconf_client_get_bool (control->priv->conf, GPM_CONF_LOCK_GNOME_KEYRING_HIBERNATE, NULL); |
869 | - if (lock_gnome_keyring) { |
870 | - keyres = gnome_keyring_lock_all_sync (); |
871 | - if (keyres != GNOME_KEYRING_RESULT_OK) { |
872 | - egg_warning ("could not lock keyring"); |
873 | - } |
874 | - } |
875 | - |
876 | - do_lock = gpm_control_get_lock_policy (control, GPM_CONF_LOCK_ON_HIBERNATE); |
877 | - if (do_lock) { |
878 | - throttle_cookie = gpm_screensaver_add_throttle (screensaver, "hibernate"); |
879 | - gpm_screensaver_lock (screensaver); |
880 | - } |
881 | - |
882 | - nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
883 | - if (nm_sleep) |
884 | - gpm_networkmanager_sleep (); |
885 | - |
886 | - egg_debug ("emitting sleep"); |
887 | - g_signal_emit (control, signals [SLEEP], 0, GPM_CONTROL_ACTION_HIBERNATE); |
888 | - |
889 | ret = up_client_hibernate_sync (control->priv->client, NULL, error); |
890 | - |
891 | - egg_debug ("emitting resume"); |
892 | - g_signal_emit (control, signals [RESUME], 0, GPM_CONTROL_ACTION_HIBERNATE); |
893 | - |
894 | - if (do_lock) { |
895 | - gpm_screensaver_poke (screensaver); |
896 | - if (throttle_cookie) |
897 | - gpm_screensaver_remove_throttle (screensaver, throttle_cookie); |
898 | - } |
899 | - |
900 | - nm_sleep = gconf_client_get_bool (control->priv->conf, GPM_CONF_NETWORKMANAGER_SLEEP, NULL); |
901 | - if (nm_sleep) |
902 | - gpm_networkmanager_wake (); |
903 | - |
904 | out: |
905 | - g_object_unref (screensaver); |
906 | return ret; |
907 | } |
908 | |
909 | @@ -280,6 +257,7 @@ |
910 | |
911 | g_object_unref (control->priv->conf); |
912 | g_object_unref (control->priv->client); |
913 | + g_object_unref (control->priv->proxy); |
914 | |
915 | g_return_if_fail (control->priv != NULL); |
916 | G_OBJECT_CLASS (gpm_control_parent_class)->finalize (object); |
917 | @@ -293,6 +271,8 @@ |
918 | { |
919 | GObjectClass *object_class = G_OBJECT_CLASS (klass); |
920 | object_class->finalize = gpm_control_finalize; |
921 | + klass->sleep = gpm_control_sleep; |
922 | + klass->resume = gpm_control_resume; |
923 | |
924 | signals [RESUME] = |
925 | g_signal_new ("resume", |
926 | @@ -316,6 +296,16 @@ |
927 | g_type_class_add_private (klass, sizeof (GpmControlPrivate)); |
928 | } |
929 | |
930 | +static void proxy_sleeping_cb (DBusGProxy *proxy, guint type, GpmControl *control) |
931 | +{ |
932 | + g_signal_emit (control, signals [SLEEP], 0, type); |
933 | +} |
934 | + |
935 | +static void proxy_resuming_cb (DBusGProxy *proxy, guint type, GpmControl *control) |
936 | +{ |
937 | + g_signal_emit (control, signals [RESUME], 0, type); |
938 | +} |
939 | + |
940 | /** |
941 | * gpm_control_init: |
942 | * @control: This control class instance |
943 | @@ -323,10 +313,42 @@ |
944 | static void |
945 | gpm_control_init (GpmControl *control) |
946 | { |
947 | + DBusGConnection *connection; |
948 | + GError *error = NULL; |
949 | + |
950 | + connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); |
951 | + g_assert_no_error (error); |
952 | control->priv = GPM_CONTROL_GET_PRIVATE (control); |
953 | |
954 | control->priv->client = up_client_new (); |
955 | control->priv->conf = gconf_client_get_default (); |
956 | + control->priv->proxy = dbus_g_proxy_new_for_name_owner (connection, |
957 | + "org.freedesktop.UPower", |
958 | + "/org/freedesktop/UPower", |
959 | + "org.freedesktop.UPower", |
960 | + &error); |
961 | + control->priv->throttle_cookie = 0; |
962 | + control->priv->screensaver = 0; |
963 | + g_assert_no_error (error); |
964 | + dbus_g_proxy_add_signal (control->priv->proxy, |
965 | + "Sleeping", |
966 | + G_TYPE_UINT, |
967 | + G_TYPE_INVALID); |
968 | + dbus_g_proxy_connect_signal (control->priv->proxy, |
969 | + "Sleeping", |
970 | + G_CALLBACK (proxy_sleeping_cb), |
971 | + control, |
972 | + NULL); |
973 | + dbus_g_proxy_add_signal (control->priv->proxy, |
974 | + "Resuming", |
975 | + G_TYPE_UINT, |
976 | + G_TYPE_INVALID); |
977 | + dbus_g_proxy_connect_signal (control->priv->proxy, |
978 | + "Resuming", |
979 | + G_CALLBACK (proxy_resuming_cb), |
980 | + control, |
981 | + NULL); |
982 | + g_object_unref (connection); |
983 | } |
984 | |
985 | /** |
gpm_control_resume seems to be almost entirely dead code - you've got a lot of ifs that lead to reading gconf keys, but never actually use them?
Apart from that, looks good to me.