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
This commit is contained in:
parent
8747c0c58d
commit
6bcad45392
@ -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');
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user