[gnome-settings-daemon] power: Fix restarting of the lid inhibitor check timer
- From: Rui Matos <rtcm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Fix restarting of the lid inhibitor check timer
- Date: Mon, 5 May 2014 14:31:05 +0000 (UTC)
commit bb47f3ddaeca988d442201937e6993ad8b5de30b
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 4917d01..309cc1d 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -189,6 +189,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);
@@ -1091,16 +1092,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
@@ -1135,11 +1135,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
@@ -1205,10 +1203,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);
}
}
@@ -2190,21 +2184,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]