[gnome-shell] screenShield: Use inhibitors to lock screen on suspend



commit 6bcad453928f47b1a805cbe7f88c3d9d6456504a
Author: Florian MÃllner <fmuellner gnome org>
Date:   Tue Oct 23 15:48:49 2012 +0200

    screenShield: Use inhibitors to lock screen on suspend
    
    If the screen lock is enabled, lock the screen before suspension.
    When using systemd, this will cover both explicitly suspending from
    the user menu and suspension initiated by g-s-d (lid close, power
    button).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686482

 js/ui/screenShield.js |   32 ++++++++++++++++++++++++++++++++
 1 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/js/ui/screenShield.js b/js/ui/screenShield.js
index 7c2729e..8dac448 100644
--- a/js/ui/screenShield.js
+++ b/js/ui/screenShield.js
@@ -526,7 +526,12 @@ const ScreenShield = new Lang.Class({
 
         this._screenSaverDBus = new ShellDBus.ScreenSaverDBus(this);
 
+        this._inhibitor = null;
         this._loginManager = LoginManager.getLoginManager();
+        this._loginManager.connect('prepare-for-sleep',
+                                   Lang.bind(this, this._prepareForSleep));
+        this._inhibitSuspend();
+
         this._loginSession = this._loginManager.getCurrentSessionProxy();
         this._loginSession.connectSignal('Lock', Lang.bind(this, function() { this.lock(false); }));
         this._loginSession.connectSignal('Unlock', Lang.bind(this, function() { this.deactivate(false); }));
@@ -606,6 +611,31 @@ const ScreenShield = new Lang.Class({
         return true;
     },
 
+    _inhibitSuspend: function() {
+        this._loginManager.inhibit(_("GNOME needs to lock the screen"),
+                                   Lang.bind(this, function(inhibitor) {
+                                       this._inhibitor = inhibitor;
+                                   }));
+    },
+
+    _uninhibitSuspend: function() {
+        if (this._inhibitor)
+            this._inhibitor.close(null);
+        this._inhibitor = null;
+    },
+
+    _prepareForSleep: function(loginManager, aboutToSuspend) {
+        if (aboutToSuspend) {
+            if (!this._settings.get_boolean(LOCK_ENABLED_KEY)) {
+                this._uninhibitSuspend();
+                return;
+            }
+            this.lock(true);
+        } else {
+            this._inhibitSuspend();
+        }
+    },
+
     _animateArrows: function() {
         let arrows = this._arrowContainer.get_children();
         let unitaryDelay = ARROW_ANIMATION_TIME / (arrows.length + 1);
@@ -960,6 +990,8 @@ const ScreenShield = new Lang.Class({
         if (prevIsActive != this._isActive)
             this.emit('active-changed');
 
+        this._uninhibitSuspend();
+
         this.emit('lock-screen-shown');
     },
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]