[gnome-settings-daemon/benzea/fix-lid-screen-locking] power: Lock screen when the lid is closed without external monitors



commit 9b2bb743d85940d773f82b7497993d7e7d2e996c
Author: Benjamin Berg <bberg redhat com>
Date:   Wed Feb 20 12:21:26 2019 +0100

    power: Lock screen when the lid is closed without external monitors
    
    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

 plugins/power/gsd-power-manager.c | 24 ++++++++++--------------
 1 file 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);
         }
 }
 


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