diff options
author | Bastien Nocera <hadess@hadess.net> | 2013-04-17 16:27:11 +0200 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2013-04-17 16:27:11 +0200 |
commit | 1e14c67c105a8564d742515778157e0d1bce319c (patch) | |
tree | f177a9c51a50d708a2e99b24848cb821810ea648 | |
parent | e477570e2130e022d25b97fc48df912e6a92b69b (diff) | |
download | gnome-settings-daemon-1e14c67c105a8564d742515778157e0d1bce319c.tar.gz |
power: Don't poll for external monitors
Instead of checking every 30 seconds whether we should suspend,
only start the timeout if we should suspend but don't because
the external monitor is gone.
We currently ignore changes to "default-monitors-setup" because it's
unlikely that they will happen between external monitor changes.
This fix also ensures that there are really 30 seconds of safety timer
instead of somewhere between 0 and 30 seconds.
https://bugzilla.gnome.org/show_bug.cgi?id=698132
-rw-r--r-- | plugins/power/gsd-power-manager.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c index 4242bcea..9794e617 100644 --- a/plugins/power/gsd-power-manager.c +++ b/plugins/power/gsd-power-manager.c @@ -2169,6 +2169,7 @@ suspend_on_lid_close (GsdPowerManager *manager) static gboolean inhibit_lid_switch_timer_cb (GsdPowerManager *manager) { + /* Just to make sure */ if (suspend_on_lid_close (manager)) { g_debug ("no external monitors for a while; uninhibiting lid close"); uninhibit_lid_switch (manager); @@ -2177,7 +2178,7 @@ inhibit_lid_switch_timer_cb (GsdPowerManager *manager) } g_debug ("external monitor still there; trying again later"); - return G_SOURCE_CONTINUE; + return G_SOURCE_REMOVE; } /* Sets up a timer to be triggered some seconds after closing the laptop lid @@ -2201,12 +2202,20 @@ setup_inhibit_lid_switch_timer (GsdPowerManager *manager) } static void +stop_inhibit_lid_switch_timer (GsdPowerManager *manager) { + if (manager->priv->inhibit_lid_switch_timer_id != 0) { + g_debug ("stopping lid close safety timer"); + g_source_remove (manager->priv->inhibit_lid_switch_timer_id); + manager->priv->inhibit_lid_switch_timer_id = 0; + } +} + +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"); - g_source_remove (manager->priv->inhibit_lid_switch_timer_id); - manager->priv->inhibit_lid_switch_timer_id = 0; setup_inhibit_lid_switch_timer (manager); } } @@ -2262,8 +2271,6 @@ 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 */ - restart_inhibit_lid_switch_timer (manager); - if (suspend_on_lid_close (manager)) { gboolean is_inhibited; @@ -2276,6 +2283,11 @@ 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); + uninhibit_lid_switch (manager); } } |