[gnome-settings-daemon/gnome-3-12] power: Fix restarting of the lid inhibitor check timer



commit 38e7e34bd096ca008b93166904c1cccccf1bc2b2
Author: Rui Matos <tiagomatos gmail com>
Date:   Wed Apr 30 17:13:50 2014 +0200

    power: Fix restarting of the lid inhibitor check timer
    
    We were trying to restart the timer when randr events tell us that
    there are no longer any external monitors connected. But we were only
    actually restarting if there was a timer scheduled already, i.e. in
    case that there was no previous timer we wouldn't start a new one
    either and thus we'd never clear the inhibitor. This would happen
    when closing the lid, since we'd stop the timer on
    do_lid_closed_action().
    
    This commit simplifies the logic and makes the timer be one shot again
    as was intended in 1e14c67 .
    
    The logic now is:
    
    1. Only take the inhibitor and start the timer on randr events,
       unconditionally. If there was a timer running from a previous randr
       event we stop it and start a new one so that the "grace period" is
       always counted since the last randr event.
    
    2. On the timer callback we check whether we should keep the inhibitor
       and thus we either suspend at that point or don't. In any case, we
       stop checking until we have further randr events.
    
    3. When the lid closes, we only have to check if we should lock the
       session. If the timer has elapsed already and we should suspend,
       then the inhibitor is already gone and logind starts suspending
       right away. Otherwise we suspend when the timer elapses and we
       remove the inhibitor, unless we see an external monitor at that
       point.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=729331

 plugins/power/gsd-power-manager.c |   35 ++++++++++-------------------------
 1 files changed, 10 insertions(+), 25 deletions(-)
---
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 91ecedf..86b8d0d 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -194,6 +194,7 @@ static void     gsd_power_manager_init        (GsdPowerManager      *power_manag
 static void      engine_device_warning_changed_cb (UpDevice *device, GParamSpec *pspec, GsdPowerManager 
*manager);
 static void      do_power_action_type (GsdPowerManager *manager, GsdPowerActionType action_type);
 static void      uninhibit_lid_switch (GsdPowerManager *manager);
+static void      stop_inhibit_lid_switch_timer (GsdPowerManager *manager);
 static void      main_battery_or_ups_low_changed (GsdPowerManager *manager, gboolean is_low);
 static gboolean  idle_is_session_inhibited (GsdPowerManager *manager, guint mask, gboolean *is_inhibited);
 static void      idle_triggered_idle_cb (GnomeIdleMonitor *monitor, guint watch_id, gpointer user_data);
@@ -1094,16 +1095,15 @@ suspend_on_lid_close (GsdPowerManager *manager)
 static gboolean
 inhibit_lid_switch_timer_cb (GsdPowerManager *manager)
 {
-       /* Just to make sure */
+        stop_inhibit_lid_switch_timer (manager);
+
         if (suspend_on_lid_close (manager)) {
                 g_debug ("no external monitors for a while; uninhibiting lid close");
                 uninhibit_lid_switch (manager);
-                manager->priv->inhibit_lid_switch_timer_id = 0;
-                return G_SOURCE_REMOVE;
         }
 
-        g_debug ("external monitor still there; trying again later");
-        return G_SOURCE_CONTINUE;
+        /* This is a one shot timer. */
+        return G_SOURCE_REMOVE;
 }
 
 /* Sets up a timer to be triggered some seconds after closing the laptop lid
@@ -1138,11 +1138,9 @@ stop_inhibit_lid_switch_timer (GsdPowerManager *manager) {
 static void
 restart_inhibit_lid_switch_timer (GsdPowerManager *manager)
 {
-        if (manager->priv->inhibit_lid_switch_timer_id != 0) {
-                stop_inhibit_lid_switch_timer (manager);
-                g_debug ("restarting lid close safety timer");
-                setup_inhibit_lid_switch_timer (manager);
-        }
+        stop_inhibit_lid_switch_timer (manager);
+        g_debug ("restarting lid close safety timer");
+        setup_inhibit_lid_switch_timer (manager);
 }
 
 static void
@@ -1208,10 +1206,6 @@ do_lid_closed_action (GsdPowerManager *manager)
                          * but the lid is closed */
                         lock_screensaver (manager);
                 }
-
-                restart_inhibit_lid_switch_timer (manager);
-        } else {
-                stop_inhibit_lid_switch_timer (manager);
         }
 }
 
@@ -2210,21 +2204,12 @@ on_randr_event (GnomeRRScreen *screen, gpointer user_data)
 
         g_debug ("Screen configuration changed");
 
-        if (suspend_on_lid_close (manager)) {
-                restart_inhibit_lid_switch_timer (manager);
-                return;
-        }
-
-        /* when a second monitor is plugged in, we take the
-         * handle-lid-switch inhibitor lock of logind to prevent
-         * it from suspending.
-         *
-         * Uninhibiting is done in the inhibit_lid_switch_timer,
+        /* Uninhibiting is done in inhibit_lid_switch_timer_cb,
          * since we want to give users a few seconds when unplugging
          * and replugging an external monitor, not suspend right away.
          */
         inhibit_lid_switch (manager);
-        setup_inhibit_lid_switch_timer (manager);
+        restart_inhibit_lid_switch_timer (manager);
 }
 
 static void


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