From 8747c0c58d415977286ae5d3952068766837757b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BCllner?= Date: Tue, 23 Oct 2012 14:35:49 +0200 Subject: [PATCH] loginManager: Add inhibitor API If screen locking is enabled, the screen shield should drop down on suspend. Currently this is achieved by either explicitly locking the screen (when selecting "Suspend" from the user menu) or by relying on g-s-d delaying the suspension enough time for the shield to get into place (lid close, power button). Systemd inhibitors offer a safer way to ensure that the screen is locked before going to sleep, so add a small abstraction for them in the loginManager - with inhibitors being a systemd-only feature, the ConsoleKit path only has a dummy implementation. https://bugzilla.gnome.org/show_bug.cgi?id=686482 --- js/misc/loginManager.js | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/js/misc/loginManager.js b/js/misc/loginManager.js index fd10c6853..6d9316a24 100644 --- a/js/misc/loginManager.js +++ b/js/misc/loginManager.js @@ -5,6 +5,7 @@ const Gio = imports.gi.Gio; const Lang = imports.lang; const Mainloop = imports.mainloop; const Shell = imports.gi.Shell; +const Signals = imports.signals; const SystemdLoginManagerIface = @@ -25,6 +26,16 @@ const SystemdLoginManagerIface = + + + + + + + + + + ; const SystemdLoginSessionIface = @@ -86,6 +97,8 @@ const LoginManagerSystemd = new Lang.Class({ this._proxy = new SystemdLoginManager(Gio.DBus.system, 'org.freedesktop.login1', '/org/freedesktop/login1'); + this._proxy.connectSignal('PrepareForSleep', + Lang.bind(this, this._prepareForSleep)); }, // Having this function is a bit of a hack since the Systemd and ConsoleKit @@ -139,8 +152,33 @@ const LoginManagerSystemd = new Lang.Class({ suspend: function() { this._proxy.SuspendRemote(true); + }, + + inhibit: function(reason, callback) { + let inVariant = GLib.Variant.new('(ssss)', + ['sleep', + 'GNOME Shell', + reason, + 'delay']); + this._proxy.call_with_unix_fd_list('Inhibit', inVariant, 0, -1, null, null, + Lang.bind(this, function(proxy, result) { + let fd = -1; + try { + let [outVariant, fdList] = proxy.call_with_unix_fd_list_finish(result); + fd = fdList.steal_fds(outVariant.deep_unpack())[0]; + callback(new Gio.UnixInputStream({ fd: fd })); + } catch(e) { + logError(e, "Error getting systemd inhibitor"); + callback(null); + } + })); + }, + + _prepareForSleep: function(proxy, sender, [aboutToSuspend]) { + this.emit('prepare-for-sleep', aboutToSuspend); } }); +Signals.addSignalMethods(LoginManagerSystemd.prototype); const LoginManagerConsoleKit = new Lang.Class({ Name: 'LoginManagerConsoleKit', @@ -196,5 +234,12 @@ const LoginManagerConsoleKit = new Lang.Class({ }, suspend: function() { + this.emit('prepare-for-sleep', true); + this.emit('prepare-for-sleep', false); + }, + + inhibit: function(reason, callback) { + callback(null); } }); +Signals.addSignalMethods(LoginManagerConsoleKit.prototype);