[gnome-settings-daemon] power: Un-idle temporarily when plugging in AC



commit 253001a9a1ac25788a095de4c87676a802a4ad9c
Author: Bastien Nocera <hadess hadess net>
Date:   Thu Jan 17 22:37:18 2013 +0100

    power: Un-idle temporarily when plugging in AC
    
    https://bugzilla.gnome.org/show_bug.cgi?id=662972

 plugins/power/gsd-power-constants.h |    3 ++
 plugins/power/gsd-power-manager.c   |   38 +++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/plugins/power/gsd-power-constants.h b/plugins/power/gsd-power-constants.h
index ef1be10..1117daa 100644
--- a/plugins/power/gsd-power-constants.h
+++ b/plugins/power/gsd-power-constants.h
@@ -30,3 +30,6 @@
 
 /* The dim delay under which we do not bother dimming */
 #define MINIMUM_IDLE_DIM_DELAY                          10 /* seconds */
+
+/* The amount of time we'll undim if the machine is idle when plugged in */
+#define POWER_UP_TIME_ON_AC                             10 /* seconds */
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index a607720..c37452a 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -211,6 +211,9 @@ struct GsdPowerManagerPrivate
         guint                    idle_sleep_id;
         GsdPowerIdleMode         current_idle_mode;
 
+        guint                    temporary_unidle_on_ac_id;
+        GsdPowerIdleMode         previous_idle_mode;
+
         guint                    xscreensaver_watchdog_timer_id;
 };
 
@@ -2750,12 +2753,46 @@ main_battery_or_ups_low_changed (GsdPowerManager *manager,
         idle_configure (manager);
 }
 
+static gboolean
+temporary_unidle_done_cb (GsdPowerManager *manager)
+{
+        idle_set_mode (manager, manager->priv->previous_idle_mode);
+        manager->priv->temporary_unidle_on_ac_id = 0;
+        return FALSE;
+}
+
+static void
+set_temporary_unidle_on_ac (GsdPowerManager *manager,
+                            gboolean         enable)
+{
+        if (!enable) {
+                if (manager->priv->temporary_unidle_on_ac_id != 0) {
+                        g_source_remove (manager->priv->temporary_unidle_on_ac_id);
+                        manager->priv->temporary_unidle_on_ac_id = 0;
+
+                        idle_set_mode (manager, manager->priv->previous_idle_mode);
+                }
+        } else {
+                manager->priv->previous_idle_mode = manager->priv->current_idle_mode;
+                idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL);
+                manager->priv->temporary_unidle_on_ac_id = g_timeout_add_seconds (POWER_UP_TIME_ON_AC,
+                                                                                  (GSourceFunc) temporary_unidle_done_cb,
+                                                                                  manager);
+        }
+}
+
 static void
 up_client_on_battery_cb (UpClient *client,
                          GParamSpec *pspec,
                          GsdPowerManager *manager)
 {
         idle_configure (manager);
+
+        if (!up_client_get_on_battery (manager->priv->up_client)) {
+                if (manager->priv->current_idle_mode == GSD_POWER_IDLE_MODE_BLANK ||
+                    manager->priv->current_idle_mode == GSD_POWER_IDLE_MODE_DIM)
+                        set_temporary_unidle_on_ac (manager, TRUE);
+        }
 }
 
 static void
@@ -3026,6 +3063,7 @@ idle_became_active_cb (GnomeIdleMonitor *monitor,
 {
         g_debug ("idletime reset");
 
+        set_temporary_unidle_on_ac (manager, FALSE);
         idle_set_mode (manager, GSD_POWER_IDLE_MODE_NORMAL);
 }
 



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