gnome-power-manager r3190 - in trunk: . src



Author: rhughes
Date: Tue Jan 27 17:24:37 2009
New Revision: 3190
URL: http://svn.gnome.org/viewvc/gnome-power-manager?rev=3190&view=rev

Log:
2009-01-27  Richard Hughes  <richard hughsie com>

* configure.ac:
* src/gpm-backlight.c: (gpm_backlight_error_quark),
(gpm_backlight_sync_policy), (gpm_backlight_set_mode),
(gpm_backlight_get_mode),
(gpm_backlight_brightness_evaluate_and_set),
(gpm_conf_gconf_key_changed_cb), (ac_adapter_changed_cb),
(gpm_backlight_notify_system_idle_changed), (idle_changed_cb),
(mode_changed_cb), (sensor_changed_cb), (control_resume_cb),
(gpm_backlight_finalize), (gpm_backlight_init):
* src/gpm-common.h:
* src/gpm-idle.c: (gpm_idle_evaluate), (gpm_idle_set_timeout_dim),
(gpm_idle_set_timeout_blank), (gpm_idle_set_timeout_sleep),
(gpm_idle_idletime_alarm_expired_cb), (gpm_idle_idletime_reset_cb),
(gpm_idle_finalize), (gpm_idle_init):
* src/gpm-manager.c: (gpm_manager_sync_policy_sleep):
* src/gpm-phone.c: (gpm_phone_test):
Use EggIdletime code to control the X idle time, and use gnome-session
to control the session idle time.
We still need to proxy requests from the legacy interface.
Fixes #567918


Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/gpm-backlight.c
   trunk/src/gpm-common.h
   trunk/src/gpm-idle.c
   trunk/src/gpm-manager.c
   trunk/src/gpm-phone.c

Modified: trunk/configure.ac
==============================================================================
--- trunk/configure.ac	(original)
+++ trunk/configure.ac	Tue Jan 27 17:24:37 2009
@@ -31,7 +31,7 @@
 	WARNINGFLAGS="$WARNINGFLAGS -Wcast-align -Wno-uninitialized"
 	WARNINGFLAGS="$WARNINGFLAGS -Wmissing-declarations"
 	WARNINGFLAGS="$WARNINGFLAGS -Wredundant-decls"
-	WARNINGFLAGS="$WARNINGFLAGS -Wmissing-noreturn"
+#	WARNINGFLAGS="$WARNINGFLAGS -Wmissing-noreturn"
 	WARNINGFLAGS="$WARNINGFLAGS -Wpointer-arith"
 	WARNINGFLAGS="$WARNINGFLAGS -Wcast-align"
 	WARNINGFLAGS="$WARNINGFLAGS -Wwrite-strings"

Modified: trunk/src/gpm-backlight.c
==============================================================================
--- trunk/src/gpm-backlight.c	(original)
+++ trunk/src/gpm-backlight.c	Tue Jan 27 17:24:37 2009
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2005-2007 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2005-2009 Richard Hughes <richard hughsie com>
  * Copyright (C) 2005 William Jon McCann <mccann jhu edu>
  *
  * Licensed under the GNU General Public License Version 2
@@ -58,8 +58,6 @@
 #include "gpm-stock-icons.h"
 #include "gpm-prefs-server.h"
 
-#define DIM_INTERVAL		10 /* ms */
-
 #define GPM_BACKLIGHT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_BACKLIGHT, GpmBacklightPrivate))
 
 struct GpmBacklightPrivate
@@ -90,7 +88,7 @@
 	LAST_SIGNAL
 };
 
-static guint	     signals [LAST_SIGNAL] = { 0 };
+static guint signals [LAST_SIGNAL] = { 0 };
 
 G_DEFINE_TYPE (GpmBacklight, gpm_backlight, G_TYPE_OBJECT)
 
@@ -102,9 +100,8 @@
 gpm_backlight_error_quark (void)
 {
 	static GQuark quark = 0;
-	if (!quark) {
+	if (!quark)
 		quark = g_quark_from_static_string ("gpm_backlight_error");
-	}
 	return quark;
 }
 
@@ -117,20 +114,19 @@
 static void
 gpm_backlight_sync_policy (GpmBacklight *backlight)
 {
-	GError  *error;
+	GError *error;
 	gboolean res;
-	guint    timeout = 0;
-	guint    standby = 0;
-	guint    suspend = 0;
-	guint    off = 0;
-	gchar   *dpms_method;
+	guint timeout = 0;
+	guint standby = 0;
+	guint suspend = 0;
+	guint off = 0;
+	gchar *dpms_method;
 	GpmDpmsMethod method;
 	gboolean on_ac;
 
 	/* no point processing if we can't do the dpms action */
-	if (backlight->priv->can_dpms == FALSE) {
+	if (!backlight->priv->can_dpms)
 		return;
-	}
 
 	/* get the ac state */
 	on_ac = gpm_ac_adapter_is_present (backlight->priv->ac_adapter);
@@ -173,19 +169,19 @@
 		/* suspend after one timeout, turn off after another */
 		standby = timeout;
 		suspend = timeout;
-		off     = timeout * 2;
+		off = timeout * 2;
 	} else if (method == GPM_DPMS_METHOD_STANDBY) {
 		standby = timeout;
 		suspend = 0;
-		off     = 0;
+		off = 0;
 	} else if (method == GPM_DPMS_METHOD_SUSPEND) {
 		standby = 0;
 		suspend = timeout;
-		off     = 0;
+		off = 0;
 	} else if (method == GPM_DPMS_METHOD_OFF) {
 		standby = 0;
 		suspend = 0;
-		off     = timeout;
+		off = timeout;
 	} else {
 		/* wtf? */
 		egg_warning ("unknown backlight mode!");
@@ -212,9 +208,7 @@
 
 /* dbus methods shouldn't use enumerated types, but should use textual descriptors */
 gboolean
-gpm_backlight_set_mode (GpmBacklight *backlight,
-			const gchar  *mode_str,
-			GError      **error)
+gpm_backlight_set_mode (GpmBacklight *backlight, const gchar *mode_str, GError **error)
 {
 	gboolean ret;
 	GpmDpmsMode mode;
@@ -257,9 +251,8 @@
 	}
 
 	ret = gpm_dpms_get_mode_enum (backlight->priv->dpms, &mode, error);
-	if (ret) {
+	if (ret)
 		*mode_str = g_strdup (gpm_dpms_mode_to_string (mode));
-	}
 	return ret;
 }
 
@@ -397,11 +390,10 @@
 	egg_debug ("2. battery scale %f, brightness %f", scale, brightness);
 
 	/* reduce if system is momentarily idle */
-	if (on_ac) {
+	if (on_ac)
 		enable_action = gconf_client_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_AC, NULL);
-	} else {
+	else
 		enable_action = gconf_client_get_bool (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_BATT, NULL);
-	}
 	if (enable_action && backlight->priv->system_is_idle) {
 		value = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_BRIGHTNESS, NULL);
 		if (value > 100) {
@@ -446,9 +438,8 @@
 	}
 
 	/* only show dialog if interactive */
-	if (interactive) {
+	if (interactive)
 		gpm_feedback_display_value (backlight->priv->feedback, (float) brightness);
-	}
 
 	ret = gpm_brightness_set (backlight->priv->brightness, value, &hw_changed);
 	/* we emit a signal for the brightness applet */
@@ -500,6 +491,7 @@
 		gpm_backlight_sync_policy (backlight);
 	} else if (strcmp (entry->key, GPM_CONF_BACKLIGHT_IDLE_DIM_TIME) == 0) {
 		backlight->priv->idle_dim_timeout = gconf_value_get_int (value);
+		gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
 	} else {
 		egg_debug ("unknown key %s", entry->key);
 	}
@@ -514,9 +506,7 @@
  * Does the actions when the ac power source is inserted/removed.
  **/
 static void
-ac_adapter_changed_cb (GpmAcAdapter     *ac_adapter,
-		       gboolean		 on_ac,
-		       GpmBacklight     *backlight)
+ac_adapter_changed_cb (GpmAcAdapter *ac_adapter, gboolean on_ac, GpmBacklight *backlight)
 {
 	gpm_backlight_brightness_evaluate_and_set (backlight, TRUE);
 }
@@ -601,11 +591,8 @@
 		if (elapsed < 10) {
 			/* double the event time */
 			backlight->priv->idle_dim_timeout *= 2.0;
-			gconf_client_set_int (backlight->priv->conf,
-					   GPM_CONF_GNOME_SS_PM_DELAY,
-					   backlight->priv->idle_dim_timeout, NULL);
-			egg_debug ("increasing idle dim time to %is",
-				   backlight->priv->idle_dim_timeout);
+			egg_debug ("increasing idle dim time to %is", backlight->priv->idle_dim_timeout);
+			gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
 		}
 
 		/* We reset the dimming after 2 minutes of idle,
@@ -615,11 +602,8 @@
 			backlight->priv->idle_dim_timeout =
 				gconf_client_get_int (backlight->priv->conf,
 					   GPM_CONF_BACKLIGHT_IDLE_DIM_TIME, NULL);
-			gconf_client_set_int (backlight->priv->conf,
-					   GPM_CONF_GNOME_SS_PM_DELAY,
-					   backlight->priv->idle_dim_timeout, NULL);
-			egg_debug ("resetting idle dim time to %is",
-				   backlight->priv->idle_dim_timeout);
+			egg_debug ("resetting idle dim time to %is", backlight->priv->idle_dim_timeout);
+			gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
 		}
 	} else {
 		egg_debug ("we were active for %lfs", elapsed);
@@ -642,16 +626,13 @@
  * session timeout has elapsed for the idle action.
  **/
 static void
-idle_changed_cb (GpmIdle      *idle,
-		 GpmIdleMode   mode,
-		 GpmBacklight *backlight)
+idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight)
 {
 	GError *error;
 
 	/* don't dim or undim the screen when the lid is closed */
-	if (gpm_button_is_lid_closed (backlight->priv->button)) {
+	if (gpm_button_is_lid_closed (backlight->priv->button))
 		return;
-	}
 
 	if (mode == GPM_IDLE_MODE_NORMAL) {
 		/* deactivate display power management */
@@ -705,9 +686,7 @@
  * What happens when the DPMS mode is changed.
  **/
 static void
-mode_changed_cb (GpmDpms      *dpms,
-		 GpmDpmsMode   mode,
-		 GpmBacklight *backlight)
+mode_changed_cb (GpmDpms *dpms, GpmDpmsMode mode, GpmBacklight *backlight)
 {
 	egg_debug ("emitting mode-changed : %s", gpm_dpms_mode_to_string (mode));
 	g_signal_emit (backlight, signals [MODE_CHANGED], 0, gpm_dpms_mode_to_string (mode));
@@ -745,9 +724,7 @@
  * This callback is called when the brightness value changes.
  **/
 static void
-sensor_changed_cb (GpmLightSensor *sensor,
-		   guint           percentage,
-		   GpmBacklight   *backlight)
+sensor_changed_cb (GpmLightSensor *sensor, guint percentage, GpmBacklight *backlight)
 {
 	egg_debug ("sensor changed! %i", percentage);
 	backlight->priv->ambient_sensor_value = percentage / 100.0f;
@@ -762,9 +739,7 @@
  * We have to update the caches on resume
  **/
 static void
-control_resume_cb (GpmControl      *control,
-		   GpmControlAction action,
-		   GpmBacklight    *backlight)
+control_resume_cb (GpmControl *control, GpmControlAction action, GpmBacklight *backlight)
 {
 	gpm_backlight_sync_policy (backlight);
 }
@@ -782,33 +757,17 @@
 
 	g_timer_destroy (backlight->priv->idle_timer);
 
-	if (backlight->priv->light_sensor != NULL) {
-		g_object_unref (backlight->priv->light_sensor);
-	}
-	if (backlight->priv->feedback != NULL) {
-		g_object_unref (backlight->priv->feedback);
-	}
-	if (backlight->priv->dpms != NULL) {
+	if (backlight->priv->dpms != NULL)
 		g_object_unref (backlight->priv->dpms);
-	}
-	if (backlight->priv->control != NULL) {
+	if (backlight->priv->control != NULL)
 		g_object_unref (backlight->priv->control);
-	}
-	if (backlight->priv->conf != NULL) {
-		g_object_unref (backlight->priv->conf);
-	}
-	if (backlight->priv->ac_adapter != NULL) {
-		g_object_unref (backlight->priv->ac_adapter);
-	}
-	if (backlight->priv->button != NULL) {
-		g_object_unref (backlight->priv->button);
-	}
-	if (backlight->priv->idle != NULL) {
-		g_object_unref (backlight->priv->idle);
-	}
-	if (backlight->priv->brightness != NULL) {
-		g_object_unref (backlight->priv->brightness);
-	}
+	g_object_unref (backlight->priv->light_sensor);
+	g_object_unref (backlight->priv->feedback);
+	g_object_unref (backlight->priv->conf);
+	g_object_unref (backlight->priv->ac_adapter);
+	g_object_unref (backlight->priv->button);
+	g_object_unref (backlight->priv->idle)
+	g_object_unref (backlight->priv->brightness);
 
 	g_return_if_fail (backlight->priv != NULL);
 	G_OBJECT_CLASS (gpm_backlight_parent_class)->finalize (object);
@@ -895,17 +854,13 @@
 
 	/* watch for dim value changes */
 	backlight->priv->conf = gconf_client_get_default ();
+
 	/* watch gnome-power-manager keys */
-	gconf_client_add_dir (backlight->priv->conf, GPM_CONF_DIR,
-			      GCONF_CLIENT_PRELOAD_NONE, NULL);
+	gconf_client_add_dir (backlight->priv->conf, GPM_CONF_DIR, GCONF_CLIENT_PRELOAD_NONE, NULL);
 	gconf_client_notify_add (backlight->priv->conf, GPM_CONF_DIR,
 				 (GConfClientNotifyFunc) gpm_conf_gconf_key_changed_cb,
 				 backlight, NULL, NULL);
 
-	/* get and set the default idle dim timeout */
-	backlight->priv->idle_dim_timeout = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_TIME, NULL);
-	gconf_client_set_int (backlight->priv->conf, GPM_CONF_GNOME_SS_PM_DELAY, backlight->priv->idle_dim_timeout, NULL);
-
 	/* set the main brightness, this is designed to be updated if the user changes the
 	 * brightness so we can undim to the 'correct' value */
 	backlight->priv->master_percentage = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_BRIGHTNESS_AC, NULL);
@@ -920,10 +875,15 @@
 	g_signal_connect (backlight->priv->ac_adapter, "ac-adapter-changed",
 			  G_CALLBACK (ac_adapter_changed_cb), backlight);
 
+	/* watch for idle mode changes */
+	backlight->priv->idle = gpm_idle_new ();
+	g_signal_connect (backlight->priv->idle, "idle-changed",
+			  G_CALLBACK (idle_changed_cb), backlight);
+
 	/* assumption */
 	backlight->priv->system_is_idle = FALSE;
 	backlight->priv->idle_dim_timeout = gconf_client_get_int (backlight->priv->conf, GPM_CONF_BACKLIGHT_IDLE_DIM_TIME, NULL);
-	gconf_client_set_int (backlight->priv->conf, GPM_CONF_GNOME_SS_PM_DELAY, backlight->priv->idle_dim_timeout, NULL);
+	gpm_idle_set_timeout_dim (backlight->priv->idle, backlight->priv->idle_dim_timeout);
 
 	/* use a visual widget */
 	backlight->priv->feedback = gpm_feedback_new ();
@@ -942,11 +902,6 @@
 				  G_CALLBACK (control_resume_cb), backlight);
 	}
 
-	/* watch for idle mode changes */
-	backlight->priv->idle = gpm_idle_new ();
-	g_signal_connect (backlight->priv->idle, "idle-changed",
-			  G_CALLBACK (idle_changed_cb), backlight);
-
 	/* sync at startup */
 	gpm_light_sensor_get_absolute (backlight->priv->light_sensor, &value);
 	backlight->priv->ambient_sensor_value = value / 100.0f;

Modified: trunk/src/gpm-common.h
==============================================================================
--- trunk/src/gpm-common.h	(original)
+++ trunk/src/gpm-common.h	Tue Jan 27 17:24:37 2009
@@ -159,9 +159,6 @@
 /* we use the gnome-session key now */
 #define GPM_CONF_SESSION_REQUEST_SAVE		"/apps/gnome-session/options/auto_save_session"
 
-/* okay to change at runtime */
-#define GPM_CONF_GNOME_SS_PM_DELAY		"/apps/gnome-screensaver/power_management_delay"
-
 /* new info binary */
 #define GPM_CONF_INFO_HISTORY_TIME		"/apps/gnome-power-manager/info/history_time"
 #define GPM_CONF_INFO_HISTORY_TYPE		"/apps/gnome-power-manager/info/history_type"

Modified: trunk/src/gpm-idle.c
==============================================================================
--- trunk/src/gpm-idle.c	(original)
+++ trunk/src/gpm-idle.c	Tue Jan 27 17:24:37 2009
@@ -36,28 +36,33 @@
 
 #include <glib.h>
 
+#include "egg-debug.h"
+#include "egg-idletime.h"
+
 #include "gpm-idle.h"
 #include "gpm-load.h"
-#include "egg-debug.h"
 #include "gpm-session.h"
 
 #define GPM_IDLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_IDLE, GpmIdlePrivate))
 
 /* Sets the idle percent limit, i.e. how hard the computer can work
    while considered "at idle" */
-#define GPM_IDLE_CPU_LIMIT	5
+#define GPM_IDLE_CPU_LIMIT		5
+
+#define GPM_IDLE_IDLETIME_ALARM_ID	1
 
 struct GpmIdlePrivate
 {
+	EggIdletime	*idletime;
 	GpmLoad		*load;
 	GpmSession	*session;
 	GpmIdleMode	 mode;
 	guint		 timeout_dim;		/* in seconds */
 	guint		 timeout_blank;		/* in seconds */
 	guint		 timeout_sleep;		/* in seconds */
-	guint		 timeout_dim_id;
 	guint		 timeout_blank_id;
 	guint		 timeout_sleep_id;
+	gboolean	 x_idle;
 	gboolean	 check_type_cpu;
 };
 
@@ -131,74 +136,6 @@
 }
 
 /**
- * gpm_idle_set_timeout_dim:
- * @idle: This class instance
- * @timeout: The new timeout we want to set, in seconds
- **/
-gboolean
-gpm_idle_set_timeout_dim (GpmIdle *idle, guint timeout)
-{
-	g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
-
-	egg_debug ("Setting dim idle timeout: %ds", timeout);
-	if (idle->priv->timeout_dim != timeout) {
-		idle->priv->timeout_dim = timeout;
-//		gpm_idle_reset (idle);
-	}
-	return TRUE;
-}
-
-/**
- * gpm_idle_set_timeout_blank:
- * @idle: This class instance
- * @timeout: The new timeout we want to set, in seconds
- **/
-gboolean
-gpm_idle_set_timeout_blank (GpmIdle *idle, guint timeout)
-{
-	g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
-
-	egg_debug ("Setting blank idle timeout: %ds", timeout);
-	if (idle->priv->timeout_blank != timeout) {
-		idle->priv->timeout_blank = timeout;
-//		gpm_idle_reset (idle);
-	}
-	return TRUE;
-}
-
-/**
- * gpm_idle_set_timeout_sleep:
- * @idle: This class instance
- * @timeout: The new timeout we want to set, in seconds
- **/
-gboolean
-gpm_idle_set_timeout_sleep (GpmIdle *idle, guint timeout)
-{
-	g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
-
-	egg_debug ("Setting sleep idle timeout: %ds", timeout);
-	if (idle->priv->timeout_sleep != timeout) {
-		idle->priv->timeout_sleep = timeout;
-//		gpm_idle_reset (idle);
-	}
-	return TRUE;
-}
-
-/**
- * gpm_idle_dim_cb:
- **/
-static gboolean
-gpm_idle_dim_cb (GpmIdle *idle)
-{
-	if (idle->priv->mode > GPM_IDLE_MODE_DIM) {
-		egg_debug ("ignoring current mode %s", gpm_idle_mode_to_text (idle->priv->mode));
-		return FALSE;
-	}
-	gpm_idle_set_mode (idle, GPM_IDLE_MODE_DIM);
-	return FALSE;
-}
-
-/**
  * gpm_idle_blank_cb:
  **/
 static gboolean
@@ -250,28 +187,17 @@
 	is_inhibited = gpm_session_get_inhibited (idle->priv->session);
 	egg_debug ("is_idle=%i, is_inhibited=%i", is_idle, is_inhibited);
 
-	/* normal */
-	if (!is_idle || is_inhibited) {
-		if (idle->priv->timeout_dim_id != 0) {
-			g_source_remove (idle->priv->timeout_dim_id);
-			idle->priv->timeout_dim_id = 0;
-		}
-		if (idle->priv->timeout_blank_id != 0) {
-			g_source_remove (idle->priv->timeout_blank_id);
-			idle->priv->timeout_blank_id = 0;
-		}
-		if (idle->priv->timeout_sleep_id != 0) {
-			g_source_remove (idle->priv->timeout_sleep_id);
-			idle->priv->timeout_sleep_id = 0;
-		}
+	if (idle->priv->x_idle) {
+		if (is_inhibited)
+			gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
+		else
+			gpm_idle_set_mode (idle, GPM_IDLE_MODE_DIM);
+	} else {
 		gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
-		return;
 	}
 
-	/* setup dim */
-	if (!is_idle && !is_inhibited) {
-		if (idle->priv->timeout_dim_id != 0)
-			idle->priv->timeout_dim_id = g_timeout_add_seconds (idle->priv->timeout_dim, (GSourceFunc) gpm_idle_dim_cb, idle);
+	/* normal */
+	if (!is_idle) {
 		if (idle->priv->timeout_blank_id != 0) {
 			g_source_remove (idle->priv->timeout_blank_id);
 			idle->priv->timeout_blank_id = 0;
@@ -280,7 +206,10 @@
 			g_source_remove (idle->priv->timeout_sleep_id);
 			idle->priv->timeout_sleep_id = 0;
 		}
-		return;
+		/* don't reset DIM state */
+		if (idle->priv->mode == GPM_IDLE_MODE_BLANK ||
+		    idle->priv->mode == GPM_IDLE_MODE_SLEEP)
+			gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
 	}
 
 	/* if there are any inhibits, clear the dim timeout */
@@ -296,6 +225,61 @@
 }
 
 /**
+ * gpm_idle_set_timeout_dim:
+ * @idle: This class instance
+ * @timeout: The new timeout we want to set, in seconds
+ **/
+gboolean
+gpm_idle_set_timeout_dim (GpmIdle *idle, guint timeout)
+{
+	g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
+
+	egg_debug ("Setting dim idle timeout: %ds", timeout);
+	if (idle->priv->timeout_dim != timeout) {
+		idle->priv->timeout_dim = timeout;
+		egg_idletime_alarm_set (idle->priv->idletime, GPM_IDLE_IDLETIME_ALARM_ID, idle->priv->timeout_dim * 1000);
+		gpm_idle_evaluate (idle);
+	}
+	return TRUE;
+}
+
+/**
+ * gpm_idle_set_timeout_blank:
+ * @idle: This class instance
+ * @timeout: The new timeout we want to set, in seconds
+ **/
+gboolean
+gpm_idle_set_timeout_blank (GpmIdle *idle, guint timeout)
+{
+	g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
+
+	egg_debug ("Setting blank idle timeout: %ds", timeout);
+	if (idle->priv->timeout_blank != timeout) {
+		idle->priv->timeout_blank = timeout;
+		gpm_idle_evaluate (idle);
+	}
+	return TRUE;
+}
+
+/**
+ * gpm_idle_set_timeout_sleep:
+ * @idle: This class instance
+ * @timeout: The new timeout we want to set, in seconds
+ **/
+gboolean
+gpm_idle_set_timeout_sleep (GpmIdle *idle, guint timeout)
+{
+	g_return_val_if_fail (GPM_IS_IDLE (idle), FALSE);
+
+	egg_debug ("Setting sleep idle timeout: %ds", timeout);
+	if (idle->priv->timeout_sleep != timeout) {
+		idle->priv->timeout_sleep = timeout;
+		gpm_idle_evaluate (idle);
+	}
+	return TRUE;
+}
+
+/**
  * gpm_idle_session_idle_changed_cb:
  * @is_idle: If the session is idle
  * @idle: This class instance
@@ -311,10 +295,6 @@
 
 /**
  * gpm_idle_session_inhibited_changed_cb:
- * @is_idle: If the session is idle
- * @idle: This class instance
- *
- * The SessionIdleChanged callback from gnome-session.
  **/
 static void
 gpm_idle_session_inhibited_changed_cb (GpmSession *session, gboolean is_inhibited, GpmIdle *idle)
@@ -324,6 +304,29 @@
 }
 
 /**
+ * gpm_idle_idletime_alarm_expired_cb:
+ **/
+static void
+gpm_idle_idletime_alarm_expired_cb (EggIdletime *idletime, guint alarm_id, GpmIdle *idle)
+{
+	/* set again */
+	egg_debug ("idletime alarm");
+	idle->priv->x_idle = TRUE;
+	gpm_idle_evaluate (idle);
+}
+
+/**
+ * gpm_idle_idletime_reset_cb:
+ **/
+static void
+gpm_idle_idletime_reset_cb (EggIdletime *idletime, GpmIdle *idle)
+{
+	egg_debug ("idletime reset");
+	idle->priv->x_idle = FALSE;
+	gpm_idle_evaluate (idle);
+}
+
+/**
  * gpm_idle_finalize:
  * @object: This class instance
  **/
@@ -339,8 +342,6 @@
 
 	g_return_if_fail (idle->priv != NULL);
 
-	if (idle->priv->timeout_dim_id != 0)
-		g_source_remove (idle->priv->timeout_dim_id);
 	if (idle->priv->timeout_blank_id != 0)
 		g_source_remove (idle->priv->timeout_blank_id);
 	if (idle->priv->timeout_sleep_id != 0)
@@ -348,6 +349,7 @@
 
 	g_object_unref (idle->priv->load);
 	g_object_unref (idle->priv->session);
+	g_object_unref (idle->priv->idletime);
 
 	G_OBJECT_CLASS (gpm_idle_parent_class)->finalize (object);
 }
@@ -390,13 +392,18 @@
 	idle->priv->timeout_dim = G_MAXUINT;
 	idle->priv->timeout_blank = G_MAXUINT;
 	idle->priv->timeout_sleep = G_MAXUINT;
-	idle->priv->timeout_dim_id = 0;
 	idle->priv->timeout_blank_id = 0;
 	idle->priv->timeout_sleep_id = 0;
+	idle->priv->x_idle = FALSE;
 	idle->priv->load = gpm_load_new ();
 	idle->priv->session = gpm_session_new ();
 	g_signal_connect (idle->priv->session, "idle-changed", G_CALLBACK (gpm_idle_session_idle_changed_cb), idle);
 	g_signal_connect (idle->priv->session, "inhibited-changed", G_CALLBACK (gpm_idle_session_inhibited_changed_cb), idle);
+
+	idle->priv->idletime = egg_idletime_new ();
+	g_signal_connect (idle->priv->idletime, "reset", G_CALLBACK (gpm_idle_idletime_reset_cb), idle);
+	g_signal_connect (idle->priv->idletime, "alarm-expired", G_CALLBACK (gpm_idle_idletime_alarm_expired_cb), idle);
+
 	gpm_idle_evaluate (idle);
 }
 

Modified: trunk/src/gpm-manager.c
==============================================================================
--- trunk/src/gpm-manager.c	(original)
+++ trunk/src/gpm-manager.c	Tue Jan 27 17:24:37 2009
@@ -309,7 +309,6 @@
 	}
 
 	/* set the new sleep (inactivity) value */
-	gpm_idle_set_timeout_dim (manager->priv->idle, 5);
 	gpm_idle_set_timeout_blank (manager->priv->idle, sleep_display);
 	gpm_idle_set_timeout_sleep (manager->priv->idle, sleep_computer);
 }

Modified: trunk/src/gpm-phone.c
==============================================================================
--- trunk/src/gpm-phone.c	(original)
+++ trunk/src/gpm-phone.c	Tue Jan 27 17:24:37 2009
@@ -421,9 +421,8 @@
 	gboolean ret;
 	EggTest *test = (EggTest *) data;
 
-	if (egg_test_start (test, "GpmPhone") == FALSE) {
+	if (egg_test_start (test, "GpmPhone") == FALSE)
 		return;
-	}
 
 	/************************************************************/
 	egg_test_title (test, "make sure we get a non null phone");



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