Skip to content

Commit 5b65946

Browse files
committed
util.js: Lock the screen before switching to the greeter.
Move some relevant code out of the user applet - calling the util.switchToGreeter will lock the screen first.
1 parent 889a2ae commit 5b65946

2 files changed

Lines changed: 17 additions & 19 deletions

File tree

files/usr/share/cinnamon/applets/[email protected]/applet.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,7 @@ class CinnamonUserApplet extends Applet.TextApplet {
8585
if (!Main.lockdownSettings.get_boolean('disable-user-switching')) {
8686
item = new PopupMenu.PopupIconMenuItem(_("Switch User"), "xsi-switch-user", St.IconType.SYMBOLIC);
8787
item.connect('activate', Lang.bind(this, function() {
88-
let lockedId = Main.screensaverController.connect("locked-changed", () => {
89-
Util.switchToGreeter();
90-
Main.screensaverController.disconnect(lockedId);
91-
})
92-
93-
GLib.idle_add(GLib.PRIORITY_DEFAULT, () => {
94-
Main.screensaverController.lockScreen(false);
95-
return GLib.SOURCE_REMOVE;
96-
});
88+
Util.switchToGreeter();
9789
}));
9890
this.menu.addMenuItem(item);
9991
}

js/misc/util.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -817,21 +817,27 @@ function wiggle(actor, params) {
817817
/**
818818
* switchToGreeter:
819819
*
820-
* Switches to the display manager's login greeter, allowing another user
821-
* to log in without logging out the current user. Tries multiple display
822-
* manager methods in order of preference.
820+
* Locks the screen and switches to the greeter, allowing another user
821+
* to log in without logging out the current user. If the screen is
822+
* already locked (e.g. called from the screensaver itself), switches
823+
* immediately.
823824
*/
824825
function switchToGreeter() {
825-
GLib.idle_add(GLib.PRIORITY_DEFAULT, _doSwitchToGreeter);
826-
}
826+
let controller = Main.screensaverController;
827827

828-
function _doSwitchToGreeter() {
829-
// Check if user switching is locked down
830-
if (Main.lockdownSettings.get_boolean('disable-user-switching')) {
831-
global.logWarning("User switching is locked down");
832-
return GLib.SOURCE_REMOVE;
828+
if (controller.locked) {
829+
GLib.idle_add(GLib.PRIORITY_DEFAULT, _doSwitchToGreeter);
830+
return;
833831
}
834832

833+
controller.lockScreen(false, (wasLocked) => {
834+
if (!wasLocked)
835+
return;
836+
GLib.idle_add(GLib.PRIORITY_DEFAULT, _doSwitchToGreeter);
837+
});
838+
}
839+
840+
function _doSwitchToGreeter() {
835841
if (_processIsRunning('gdm')) {
836842
// Old GDM
837843
try {

0 commit comments

Comments
 (0)