[gnome-settings-daemon] power: Adapt to new GnomeIdleMonitor API



commit e8bc8e831d7afac64aa885a702ba32034eb5abff
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Fri Jan 18 00:19:16 2013 -0500

    power: Adapt to new GnomeIdleMonitor API
    
    https://bugzilla.gnome.org/show_bug.cgi?id=688227

 plugins/cursor/gsd-cursor-manager.c |   16 +++++------
 plugins/power/gsd-power-manager.c   |   47 +++++++++++++++++++++-------------
 2 files changed, 36 insertions(+), 27 deletions(-)
---
diff --git a/plugins/cursor/gsd-cursor-manager.c b/plugins/cursor/gsd-cursor-manager.c
index 6b35330..611392b 100644
--- a/plugins/cursor/gsd-cursor-manager.c
+++ b/plugins/cursor/gsd-cursor-manager.c
@@ -47,8 +47,6 @@
 
 #define XFIXES_CURSOR_HIDING_MAJOR 4
 
-#define IDLE_TIME 1
-
 #define GSD_CURSOR_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GSD_TYPE_CURSOR_MANAGER, 
GsdCursorManagerPrivate))
 
 struct GsdCursorManagerPrivate
@@ -129,9 +127,11 @@ set_cursor_visibility (GsdCursorManager *manager,
 
 static void
 monitor_became_active (GnomeIdleMonitor *monitor,
-                       GsdCursorManager *manager)
+                       guint             watch_id,
+                       gpointer          user_data)
 {
         GdkDevice *device;
+        GsdCursorManager *manager = GSD_CURSOR_MANAGER (user_data);
 
         /* Oh, so you're active? */
         g_object_get (G_OBJECT (monitor), "device", &device, NULL);
@@ -170,12 +170,10 @@ device_added_cb (GdkDeviceManager *device_manager,
         g_hash_table_insert (manager->priv->monitors,
                              device,
                              monitor);
-        g_signal_connect (monitor, "became-active",
-                          G_CALLBACK (monitor_became_active), manager);
-        /* We become idle very quickly so that the became-active
-         * kicks in fast */
-        gnome_idle_monitor_add_watch (monitor, IDLE_TIME,
-                                      NULL, NULL, NULL);
+        gnome_idle_monitor_add_user_active_watch (monitor,
+                                                  monitor_became_active,
+                                                  manager,
+                                                  NULL);
 }
 
 static void
diff --git a/plugins/power/gsd-power-manager.c b/plugins/power/gsd-power-manager.c
index 88a0abf..efa8404 100644
--- a/plugins/power/gsd-power-manager.c
+++ b/plugins/power/gsd-power-manager.c
@@ -245,6 +245,8 @@ static void      uninhibit_lid_switch (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_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode);
+static void      idle_triggered_idle_cb (GnomeIdleMonitor *monitor, guint watch_id, gpointer user_data);
+static void      idle_became_active_cb (GnomeIdleMonitor *monitor, guint watch_id, gpointer user_data);
 
 G_DEFINE_TYPE (GsdPowerManager, gsd_power_manager, G_TYPE_OBJECT)
 
@@ -2485,6 +2487,15 @@ idle_set_mode (GsdPowerManager *manager, GsdPowerIdleMode mode)
                 return;
         }
 
+        /* if we're moving to an idle mode, make sure
+         * we add a watch to take us back to normal */
+        if (mode != GSD_POWER_IDLE_MODE_NORMAL) {
+                gnome_idle_monitor_add_user_active_watch (manager->priv->idle_monitor,
+                                                          idle_became_active_cb,
+                                                          manager,
+                                                          NULL);
+        }
+
         /* save current brightness, and set dim level */
         if (mode == GSD_POWER_IDLE_MODE_DIM) {
                 /* display backlight */
@@ -2670,9 +2681,9 @@ idle_configure (GsdPowerManager *manager)
         if (timeout_blank != 0) {
                 g_debug ("setting up blank callback for %is", timeout_blank);
 
-                manager->priv->idle_blank_id = gnome_idle_monitor_add_watch (manager->priv->idle_monitor,
-                                                                             timeout_blank * 1000,
-                                                                             NULL, NULL, NULL);
+                manager->priv->idle_blank_id = gnome_idle_monitor_add_idle_watch 
(manager->priv->idle_monitor,
+                                                                                  timeout_blank * 1000,
+                                                                                  idle_triggered_idle_cb, 
manager, NULL);
         }
 
         /* only do the sleep timeout when the session is idle
@@ -2693,9 +2704,9 @@ idle_configure (GsdPowerManager *manager)
         if (timeout_sleep != 0) {
                 g_debug ("setting up sleep callback %is", timeout_sleep);
 
-                manager->priv->idle_sleep_id = gnome_idle_monitor_add_watch (manager->priv->idle_monitor,
-                                                                             timeout_sleep * 1000,
-                                                                             NULL, NULL, NULL);
+                manager->priv->idle_sleep_id = gnome_idle_monitor_add_idle_watch 
(manager->priv->idle_monitor,
+                                                                                  timeout_sleep * 1000,
+                                                                                  idle_triggered_idle_cb, 
manager, NULL);
                 if (action_type == GSD_POWER_ACTION_LOGOUT ||
                     action_type == GSD_POWER_ACTION_SUSPEND ||
                     action_type == GSD_POWER_ACTION_HIBERNATE) {
@@ -2708,9 +2719,9 @@ idle_configure (GsdPowerManager *manager)
 
                         g_debug ("setting up sleep warning callback %is", timeout_sleep_warning);
 
-                        manager->priv->idle_sleep_warning_id = gnome_idle_monitor_add_watch 
(manager->priv->idle_monitor,
-                                                                                              
timeout_sleep_warning * 1000,
-                                                                                              NULL, NULL, 
NULL);
+                        manager->priv->idle_sleep_warning_id = gnome_idle_monitor_add_idle_watch 
(manager->priv->idle_monitor,
+                                                                                                  
timeout_sleep_warning * 1000,
+                                                                                                  
idle_triggered_idle_cb, manager, NULL);
                 }
         }
 
@@ -2750,9 +2761,9 @@ idle_configure (GsdPowerManager *manager)
         if (timeout_dim != 0) {
                 g_debug ("setting up dim callback for %is", timeout_dim);
 
-                manager->priv->idle_dim_id = gnome_idle_monitor_add_watch (manager->priv->idle_monitor,
-                                                                           timeout_dim * 1000,
-                                                                           NULL, NULL, NULL);
+                manager->priv->idle_dim_id = gnome_idle_monitor_add_idle_watch (manager->priv->idle_monitor,
+                                                                                timeout_dim * 1000,
+                                                                                idle_triggered_idle_cb, 
manager, NULL);
         }
 }
 
@@ -3081,8 +3092,9 @@ show_sleep_warning (GsdPowerManager *manager)
 static void
 idle_triggered_idle_cb (GnomeIdleMonitor *monitor,
                         guint             watch_id,
-                        GsdPowerManager  *manager)
+                        gpointer          user_data)
 {
+        GsdPowerManager *manager = GSD_POWER_MANAGER (user_data);
         const char *id_name;
 
         id_name = idle_watch_id_to_string (manager, watch_id);
@@ -3104,8 +3116,11 @@ idle_triggered_idle_cb (GnomeIdleMonitor *monitor,
 
 static void
 idle_became_active_cb (GnomeIdleMonitor *monitor,
-                       GsdPowerManager *manager)
+                       guint             watch_id,
+                       gpointer          user_data)
 {
+        GsdPowerManager *manager = GSD_POWER_MANAGER (user_data);
+
         g_debug ("idletime reset");
 
         set_temporary_unidle_on_ac (manager, FALSE);
@@ -3510,10 +3525,6 @@ gsd_power_manager_start (GsdPowerManager *manager,
 
         /* create IDLETIME watcher */
         manager->priv->idle_monitor = gnome_idle_monitor_new ();
-        g_signal_connect (manager->priv->idle_monitor, "became-active",
-                          G_CALLBACK (idle_became_active_cb), manager);
-        g_signal_connect (manager->priv->idle_monitor, "triggered-idle",
-                          G_CALLBACK (idle_triggered_idle_cb), manager);
 
         /* set up the screens */
         g_signal_connect (manager->priv->rr_screen, "changed", G_CALLBACK (on_randr_event), manager);


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