summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Berg <bberg@redhat.com>2019-02-20 12:21:26 +0100
committerBenjamin Berg <bberg@redhat.com>2019-02-20 20:52:37 +0100
commit9b2bb743d85940d773f82b7497993d7e7d2e996c (patch)
treebcc0b9ecf04e24b3b7b32b37bcee9fa21d429311
parent7cd7cbd7d97618c0fc0c9ec7cbd83d9e4e01fcb9 (diff)
downloadgnome-settings-daemon-benzea/fix-lid-screen-locking.tar.gz
power: Lock screen when the lid is closed without external monitorsbenzea/fix-lid-screen-locking
We currently only lock the screen when suspend is disabled on the session level. This is somewhat ironic, because in reality suspend happens because of systemd-logind. In the case where we suspend, it does not hurt to also explicitly lock the screen. In the case that suspend is inhibited (through GNOME Tweaks), this fixes issues where the session remains unlocked. See also https://gitlab.gnome.org/GNOME/gnome-settings-daemon/issues/88 and https://gitlab.gnome.org/GNOME/gnome-tweaks/merge_requests/33
-rw-r--r--plugins/power/gsd-power-manager.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index f965f6f3..98519344 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -1194,7 +1194,7 @@ upower_kbd_toggle (GsdPowerManager *manager,
}
static gboolean
-suspend_on_lid_close (GsdPowerManager *manager)
+have_no_external_monitor (GsdPowerManager *manager)
{
return !external_monitor_is_connected (manager->priv->rr_screen);
}
@@ -1204,7 +1204,7 @@ inhibit_lid_switch_timer_cb (GsdPowerManager *manager)
{
stop_inhibit_lid_switch_timer (manager);
- if (suspend_on_lid_close (manager)) {
+ if (have_no_external_monitor (manager)) {
g_debug ("no external monitors for a while; uninhibiting lid close");
uninhibit_lid_switch (manager);
}
@@ -1297,18 +1297,14 @@ do_lid_closed_action (GsdPowerManager *manager)
/* refresh RANDR so we get an accurate view of what monitors are plugged in when the lid is closed */
gnome_rr_screen_refresh (manager->priv->rr_screen, NULL); /* NULL-GError */
- if (suspend_on_lid_close (manager)) {
- gboolean is_inhibited;
-
- idle_is_session_inhibited (manager,
- GSM_INHIBITOR_FLAG_SUSPEND,
- &is_inhibited);
- if (is_inhibited) {
- g_debug ("Suspend is inhibited but lid is closed, locking the screen");
- /* We put the screensaver on * as we're not suspending,
- * but the lid is closed */
- lock_screensaver (manager);
- }
+ /* In this case, systemd-logind will suspend the machine
+ * for us (see also https://gitlab.gnome.org/GNOME/gnome-settings-daemon/issues/88).
+ * However, GNOME Tweaks may inhibit this suspend mechanism, so we
+ * unconditionally lock the screen even though that would happen implicitly on
+ * suspend. */
+ if (have_no_external_monitor (manager)) {
+ g_debug ("Lid was closed without an external monitor, locking screen");
+ lock_screensaver (manager);
}
}