[gnome-power-manager] Convert from our homegrown test framework to GTest, removing a boatload of code in the process



commit f6d773332fc13477c4a1b5df8cc9f99ea7f3a072
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jun 28 16:20:15 2010 +0100

    Convert from our homegrown test framework to GTest, removing a boatload of code in the process

 applets/brightness/Makefile.am               |    2 -
 applets/brightness/egg-dbus-monitor.c        |    1 -
 applets/brightness/egg-dbus-monitor.h        |    1 -
 applets/inhibit/Makefile.am                  |    2 -
 applets/inhibit/egg-dbus-monitor.c           |    1 -
 applets/inhibit/egg-dbus-monitor.h           |    1 -
 src/Makefile.am                              |   67 +--
 src/egg-array-float.c                        |  770 -----------------------
 src/egg-color.c                              |  157 -----
 src/egg-color.h                              |   59 --
 src/egg-discrete.c                           |  162 -----
 src/egg-discrete.h                           |   41 --
 src/egg-idletime.c                           |  690 --------------------
 src/egg-idletime.h                           |   68 --
 src/egg-precision.c                          |  193 ------
 src/egg-precision.h                          |   39 --
 src/egg-string.c                             |   84 +--
 src/egg-test.c                               |  343 ----------
 src/egg-test.h                               |   48 --
 src/gpm-array-float.c                        |  374 +++++++++++
 src/{egg-array-float.h => gpm-array-float.h} |   31 +-
 src/gpm-brightness.c                         |    9 +-
 src/gpm-common.c                             |  160 +++++-
 src/gpm-common.h                             |   36 +-
 src/gpm-dpms.c                               |   83 ---
 src/gpm-graph-widget.c                       |   12 +-
 src/gpm-idle.c                               |  253 +--------
 src/gpm-idle.h                               |    2 +-
 src/gpm-idletime.c                           |  472 ++++++++++++++
 src/gpm-idletime.h                           |   65 ++
 src/gpm-phone.c                              |  120 ----
 src/gpm-screensaver.c                        |   55 --
 src/gpm-self-test.c                          |  865 ++++++++++++++++++++++++--
 src/gpm-self-test.h                          |   58 --
 src/gpm-statistics.c                         |   47 +-
 src/gpm-upower.c                             |    5 +-
 36 files changed, 2015 insertions(+), 3361 deletions(-)
---
diff --git a/applets/brightness/Makefile.am b/applets/brightness/Makefile.am
index 3d798ca..060f29c 100644
--- a/applets/brightness/Makefile.am
+++ b/applets/brightness/Makefile.am
@@ -26,8 +26,6 @@ libexec_PROGRAMS=gnome-brightness-applet
 
 gnome_brightness_applet_SOURCES =				\
 	brightness-applet.c					\
-	egg-dbus-monitor.c					\
-	egg-dbus-monitor.h					\
 	egg-debug.c						\
 	egg-debug.h						\
 	gpm-common.c						\
diff --git a/applets/inhibit/Makefile.am b/applets/inhibit/Makefile.am
index 08ffb42..849f1c6 100644
--- a/applets/inhibit/Makefile.am
+++ b/applets/inhibit/Makefile.am
@@ -26,8 +26,6 @@ libexec_PROGRAMS=gnome-inhibit-applet
 
 gnome_inhibit_applet_SOURCES =					\
 	inhibit-applet.c					\
-	egg-dbus-monitor.c					\
-	egg-dbus-monitor.h					\
 	egg-debug.c						\
 	egg-debug.h						\
 	gpm-common.c						\
diff --git a/src/Makefile.am b/src/Makefile.am
index 0ff3a00..7549091 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -55,18 +55,12 @@ check_PROGRAMS =					\
 
 noinst_LIBRARIES = libgpmshared.a
 libgpmshared_a_SOURCES =				\
-	egg-color.c					\
-	egg-color.h					\
 	egg-debug.h					\
 	egg-debug.c					\
-	egg-precision.h					\
-	egg-precision.c					\
-	egg-array-float.c				\
-	egg-array-float.h				\
-	egg-idletime.h					\
-	egg-idletime.c					\
-	egg-discrete.h					\
-	egg-discrete.c					\
+	gpm-array-float.c				\
+	gpm-array-float.h				\
+	gpm-idletime.h					\
+	gpm-idletime.c					\
 	egg-string.h					\
 	egg-string.c					\
 	egg-console-kit.h				\
@@ -195,63 +189,36 @@ gnome_power_manager_CFLAGS =				\
 	$(NULL)
 
 gnome_power_self_test_SOURCES =				\
-	gpm-self-test.c					\
-	egg-color.h					\
-	egg-color.c					\
-	egg-test.h					\
-	egg-test.c					\
-	egg-debug.h					\
-	egg-debug.c					\
-	egg-dbus-monitor.h				\
-	egg-dbus-monitor.c				\
-	egg-dbus-proxy.h				\
-	egg-dbus-proxy.c				\
-	egg-precision.h					\
-	egg-precision.c					\
-	egg-idletime.h					\
-	egg-idletime.c					\
-	egg-discrete.h					\
-	egg-discrete.c					\
-	egg-array-float.h				\
-	egg-array-float.c				\
-	egg-console-kit.h				\
-	egg-console-kit.c				\
-	gpm-control.h					\
-	gpm-control.c					\
-	gpm-networkmanager.h				\
-	gpm-networkmanager.c				\
 	gpm-dpms.h					\
 	gpm-dpms.c					\
-	gpm-button.h					\
-	gpm-button.c					\
-	gpm-screensaver.h				\
-	gpm-screensaver.c				\
-	gpm-engine.h					\
-	gpm-engine.c					\
-	gpm-phone.h					\
-	gpm-phone.c					\
 	gpm-idle.h					\
 	gpm-idle.c					\
 	gpm-session.h					\
 	gpm-session.c					\
-	gpm-load.h					\
-	gpm-load.c					\
-	gpm-marshal.h					\
-	gpm-marshal.c					\
 	gpm-common.h					\
 	gpm-common.c					\
-	gpm-upower.h					\
-	gpm-upower.c					\
+	gpm-load.h					\
+	gpm-load.c					\
+	gpm-phone.h					\
+	gpm-phone.c					\
+	gpm-screensaver.h				\
+	gpm-screensaver.c				\
+	gpm-idletime.h					\
+	gpm-idletime.c					\
+	gpm-array-float.h				\
+	gpm-array-float.c				\
+	gpm-self-test.c					\
 	$(NULL)
 
 gnome_power_self_test_LDADD =				\
+	libgpmshared.a					\
 	$(GLIB_LIBS)					\
 	$(X11_LIBS)					\
 	$(GNOME_LIBS)					\
 	$(GSTREAMER_LIBS)				\
 	$(UPOWER_LIBS)					\
 	$(DBUS_LIBS)					\
-	$(X11_LIBS)						\
+	$(X11_LIBS)					\
 	$(LIBNOTIFY_LIBS)				\
 	$(GPM_EXTRA_LIBS)				\
 	-lm
diff --git a/src/egg-string.c b/src/egg-string.c
index 204e6d9..2c2da0c 100644
--- a/src/egg-string.c
+++ b/src/egg-string.c
@@ -238,7 +238,7 @@ egg_strreplace (const gchar *text, const gchar *find, const gchar *replace)
 #include "egg-test.h"
 
 void
-egg_string_test (EggTest *test)
+egg_string_test (void)
 {
 	gboolean ret;
 	gchar *text_safe;
@@ -249,13 +249,7 @@ egg_string_test (EggTest *test)
 	gchar **id1;
 	gchar **id2;
 
-	if (!egg_test_start (test, "EggString"))
-		return;
-
-	/************************************************************
-	 ****************    String array equal    ******************
-	 ************************************************************/
-	egg_test_title (test, "egg_strvequal same argument");
+	/* egg_strvequal same argument */
 	id1 = g_strsplit ("the quick brown fox", " ", 0);
 	if (egg_strvequal (id1, id1))
 		egg_test_success (test, NULL);
@@ -263,8 +257,7 @@ egg_string_test (EggTest *test)
 		egg_test_failed (test, "incorrect ret when both same");
 	g_strfreev (id1);
 
-	/************************************************************/
-	egg_test_title (test, "egg_strvequal same");
+	/* egg_strvequal same */
 	id1 = g_strsplit ("the quick brown fox", " ", 0);
 	id2 = g_strsplit ("the quick brown fox", " ", 0);
 	if (egg_strvequal (id1, id2))
@@ -274,8 +267,7 @@ egg_string_test (EggTest *test)
 	g_strfreev (id1);
 	g_strfreev (id2);
 
-	/************************************************************/
-	egg_test_title (test, "egg_strvequal different lengths");
+	/* egg_strvequal different lengths */
 	id1 = g_strsplit ("the quick brown", " ", 0);
 	id2 = g_strsplit ("the quick brown fox", " ", 0);
 	if (!egg_strvequal (id1, id2))
@@ -285,8 +277,7 @@ egg_string_test (EggTest *test)
 	g_strfreev (id1);
 	g_strfreev (id2);
 
-	/************************************************************/
-	egg_test_title (test, "egg_strvequal different");
+	/* egg_strvequal different */
 	id1 = g_strsplit ("the quick brown fox", " ", 0);
 	id2 = g_strsplit ("richard hughes maintainer dude", " ", 0);
 	if (!egg_strvequal (id1, id2))
@@ -296,73 +287,59 @@ egg_string_test (EggTest *test)
 	g_strfreev (id1);
 	g_strfreev (id2);
 
-	/************************************************************
-	 ****************          Zero            ******************
-	 ************************************************************/
+	/* Zero */
 	temp = NULL;
-	egg_test_title (test, "test strzero (null)");
+	/* test strzero (null) */
 	ret = egg_strzero (NULL);
 	if (ret)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "failed null");
 
-	/************************************************************/
-	egg_test_title (test, "test strzero (null first char)");
+	/* test strzero (null first char) */
 	ret = egg_strzero ("");
 	if (ret)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "failed null");
 
-	/************************************************************/
-	egg_test_title (test, "test strzero (long string)");
+	/* test strzero (long string) */
 	ret = egg_strzero ("Richard");
 	if (!ret)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "zero length word!");
 
-	/************************************************************/
-	egg_test_title (test, "id strcmp pass");
+	/* id strcmp pass */
 	ret = (g_strcmp0 ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora") == 0);
 	egg_test_assert (test, ret);
 
-	/************************************************************/
-	egg_test_title (test, "id strcmp fail");
+	/* id strcmp fail */
 	ret = (g_strcmp0 ("moo;0.0.1;i386;fedora", "moo;0.0.2;i386;fedora") == 0);
 	egg_test_assert (test, !ret);
 
-	/************************************************************
-	 ****************          strlen          ******************
-	 ************************************************************/
-	egg_test_title (test, "strlen bigger");
+	/* strlen bigger */
 	length = egg_strlen ("123456789", 20);
 	if (length == 9)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "failed the strlen %i", length);
 
-	/************************************************************/
-	egg_test_title (test, "strlen smaller");
+	/* strlen smaller */
 	length = egg_strlen ("123456789", 5);
 	if (length == 5)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "failed the strlen %i", length);
 
-	/************************************************************/
-	egg_test_title (test, "strlen correct");
+	/* strlen correct */
 	length = egg_strlen ("123456789", 9);
 	if (length == 9)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "failed the strlen %i", length);
 
-	/************************************************************
-	 ****************         Replace          ******************
-	 ************************************************************/
-	egg_test_title (test, "replace start");
+	/* replace start */
 	text_safe = egg_strreplace ("richard\nhughes", "r", "e");
 	if (g_strcmp0 (text_safe, "eichaed\nhughes") == 0)
 		egg_test_success (test, NULL);
@@ -370,8 +347,7 @@ egg_string_test (EggTest *test)
 		egg_test_failed (test, "failed the replace '%s'", text_safe);
 	g_free (text_safe);
 
-	/************************************************************/
-	egg_test_title (test, "replace none");
+	/* replace none */
 	text_safe = egg_strreplace ("richard\nhughes", "dave", "e");
 	if (g_strcmp0 (text_safe, "richard\nhughes") == 0)
 		egg_test_success (test, NULL);
@@ -379,8 +355,7 @@ egg_string_test (EggTest *test)
 		egg_test_failed (test, "failed the replace '%s'", text_safe);
 	g_free (text_safe);
 
-	/************************************************************/
-	egg_test_title (test, "replace end");
+	/* replace end */
 	text_safe = egg_strreplace ("richard\nhughes", "s", "e");
 	if (g_strcmp0 (text_safe, "richard\nhughee") == 0)
 		egg_test_success (test, NULL);
@@ -388,8 +363,7 @@ egg_string_test (EggTest *test)
 		egg_test_failed (test, "failed the replace '%s'", text_safe);
 	g_free (text_safe);
 
-	/************************************************************/
-	egg_test_title (test, "replace unicode");
+	/* replace unicode */
 	text_safe = egg_strreplace ("richard\n- hughes", "\n- ", "\nâ?¢ ");
 	if (g_strcmp0 (text_safe, "richard\nâ?¢ hughes") == 0)
 		egg_test_success (test, NULL);
@@ -397,57 +371,47 @@ egg_string_test (EggTest *test)
 		egg_test_failed (test, "failed the replace '%s'", text_safe);
 	g_free (text_safe);
 
-	/************************************************************
-	 **************        Convert numbers       ****************
-	 ************************************************************/
-	egg_test_title (test, "convert valid number");
+	/* convert valid number */
 	ret = egg_strtoint ("234", &value);
 	if (ret && value == 234)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "value is %i", value);
 
-	/************************************************************/
-	egg_test_title (test, "convert negative valid number");
+	/* convert negative valid number */
 	ret = egg_strtoint ("-234", &value);
 	if (ret && value == -234)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "value is %i", value);
 
-	/************************************************************/
-	egg_test_title (test, "don't convert invalid number");
+	/* don't convert invalid number */
 	ret = egg_strtoint ("dave", &value);
 	if (!ret)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "value is %i", value);
 
-	/************************************************************/
-	egg_test_title (test, "convert NULL to a number");
+	/* convert NULL to a number */
 	ret = egg_strtouint (NULL, &uvalue);
 	if (!ret)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "value is %i", uvalue);
 
-	/************************************************************/
-	egg_test_title (test, "convert valid uint number");
+	/* convert valid uint number */
 	ret = egg_strtouint ("234", &uvalue);
 	if (ret && uvalue == 234)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "value is %i", uvalue);
 
-	/************************************************************/
-	egg_test_title (test, "convert invalid uint number");
+	/* convert invalid uint number */
 	ret = egg_strtouint ("-234", &uvalue);
 	if (ret == FALSE)
 		egg_test_success (test, NULL);
 	else
 		egg_test_failed (test, "value is %i", uvalue);
-
-	egg_test_end (test);
 }
 #endif
 
diff --git a/src/gpm-array-float.c b/src/gpm-array-float.c
new file mode 100644
index 0000000..9796008
--- /dev/null
+++ b/src/gpm-array-float.c
@@ -0,0 +1,374 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2010 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <glib.h>
+
+#include "egg-debug.h"
+#include "gpm-array-float.h"
+
+/**
+ * gpm_array_float_guassian_value:
+ *
+ * @x: input value
+ * @sigma: sigma value
+ * Return value: the gaussian, in floating point precision
+ **/
+gfloat
+gpm_array_float_guassian_value (gfloat x, gfloat sigma)
+{
+	return (1.0 / (sqrtf(2.0*3.1415927) * sigma)) * (expf((-(powf(x,2.0)))/(2.0 * powf(sigma, 2.0))));
+}
+
+/**
+ * gpm_array_float_new:
+ *
+ * @length: length of array
+ * Return value: Allocate array
+ *
+ * Creates a new size array which is zeroed. Free with g_array_free();
+ **/
+GpmArrayFloat *
+gpm_array_float_new (guint length)
+{
+	guint i;
+	GpmArrayFloat *array;
+	array = g_array_sized_new (TRUE, FALSE, sizeof(gfloat), length);
+	array->len = length;
+
+	/* clear to 0.0 */
+	for (i=0; i<length; i++)
+		g_array_index (array, gfloat, i) = 0.0;
+	return array;
+}
+
+/**
+ * gpm_array_float_get:
+ *
+ * @array: input array
+ **/
+gfloat
+gpm_array_float_get (GpmArrayFloat *array, guint i)
+{
+	if (i >= array->len)
+		g_error ("above index! (%i)", i);
+	return g_array_index (array, gfloat, i);
+}
+
+/**
+ * gpm_array_float_set:
+ *
+ * @array: input array
+ **/
+void
+gpm_array_float_set (GpmArrayFloat *array, guint i, gfloat value)
+{
+	g_array_index (array, gfloat, i) = value;
+}
+
+/**
+ * gpm_array_float_free:
+ *
+ * @array: input array
+ *
+ * Frees the array, deallocating data
+ **/
+void
+gpm_array_float_free (GpmArrayFloat *array)
+{
+	if (array != NULL)
+		g_array_free (array, TRUE);
+}
+
+/**
+ * gpm_array_float_get_average:
+ * @array: This class instance
+ *
+ * Gets the average value.
+ **/
+gfloat
+gpm_array_float_get_average (GpmArrayFloat *array)
+{
+	guint i;
+	guint length;
+	gfloat average = 0;
+
+	length = array->len;
+	for (i=0; i<length; i++)
+		average += g_array_index (array, gfloat, i);
+	return average / (gfloat) length;
+}
+
+/**
+ * gpm_array_float_compute_gaussian:
+ *
+ * @length: length of output array
+ * @sigma: sigma value
+ * Return value: Gaussian array
+ *
+ * Create a set of Gaussian array of a specified size
+ **/
+GpmArrayFloat *
+gpm_array_float_compute_gaussian (guint length, gfloat sigma)
+{
+	GpmArrayFloat *array;
+	guint half_length;
+	guint i;
+	gfloat division;
+	gfloat value;
+
+	g_return_val_if_fail (length % 2 == 1, NULL);
+
+	array = gpm_array_float_new (length);
+
+	/* array positions 0..length, has to be an odd number */
+	half_length = (length / 2) + 1;
+	for (i=0; i<half_length; i++) {
+		division = half_length - (i + 1);
+		egg_debug ("half_length=%i, div=%f, sigma=%f", half_length, division, sigma);
+		g_array_index (array, gfloat, i) = gpm_array_float_guassian_value (division, sigma);
+	}
+
+	/* no point working these out, we can just reflect the gaussian */
+	for (i=half_length; i<length; i++) {
+		division = g_array_index (array, gfloat, length-(i+1));
+		g_array_index (array, gfloat, i) = division;
+	}
+
+	/* make sure we get an accurate gaussian */
+	value = gpm_array_float_sum (array);
+	if (fabs (value - 1.0f) > 0.01f) {
+		egg_warning ("got wrong sum (%f), perhaps sigma too high for size?", value);
+		gpm_array_float_free (array);
+		array = NULL;
+	}
+
+	return array;
+}
+
+/**
+ * gpm_array_float_sum:
+ *
+ * @array: input array
+ *
+ * Sum the elements of the array
+ **/
+gfloat
+gpm_array_float_sum (GpmArrayFloat *array)
+{
+	guint length;
+	guint i;
+	gfloat total = 0;
+
+	length = array->len;
+	for (i=0; i<length; i++)
+		total += g_array_index (array, gfloat, i);
+	return total;
+}
+
+/**
+ * gpm_array_float_print:
+ *
+ * @array: input array
+ *
+ * Print the array
+ **/
+gboolean
+gpm_array_float_print (GpmArrayFloat *array)
+{
+	guint length;
+	guint i;
+
+	length = array->len;
+	/* debug out */
+	for (i=0; i<length; i++)
+		egg_debug ("[%i]\tval=%f", i, g_array_index (array, gfloat, i));
+	return TRUE;
+}
+
+/**
+ * gpm_array_float_convolve:
+ *
+ * @data: input array
+ * @kernel: kernel array
+ * Return value: Colvolved array, same length as data
+ *
+ * Convolves an array with a kernel, and returns an array the same size.
+ * THIS FUNCTION IS REALLY SLOW...
+ **/
+GpmArrayFloat *
+gpm_array_float_convolve (GpmArrayFloat *data, GpmArrayFloat *kernel)
+{
+	gint length_data;
+	gint length_kernel;
+	GpmArrayFloat *result;
+	gfloat value;
+	gint i;
+	gint j;
+	gint idx;
+
+	length_data = data->len;
+	length_kernel = kernel->len;
+
+	result = gpm_array_float_new (length_data);
+
+	/* convolve */
+	for (i=0;i<length_data;i++) {
+		value = 0;
+		for (j=0;j<length_kernel;j++) {
+			idx = i+j-(length_kernel/2);
+			if (idx < 0)
+				idx = 0;
+			else if (idx >= length_data)
+				idx = length_data - 1;
+			value += g_array_index (data, gfloat, idx) * g_array_index (kernel, gfloat, j);
+		}
+		g_array_index (result, gfloat, i) = value;
+	}
+	return result;
+}
+
+/**
+ * gpm_array_float_compute_integral:
+ * @array: This class instance
+ *
+ * Computes complete discrete integral of dataset.
+ * Will only work with a step size of one.
+ **/
+gfloat
+gpm_array_float_compute_integral (GpmArrayFloat *array, guint x1, guint x2)
+{
+	gfloat value;
+	guint i;
+
+	g_return_val_if_fail (x2 >= x1, 0.0);
+
+	/* if the same point, then we have no area */
+	if (x1 == x2)
+		return 0.0;
+
+	value = 0.0;
+	for (i=x1; i <= x2; i++)
+		value += g_array_index (array, gfloat, i);
+	return value;
+}
+
+/**
+ * powfi:
+ **/
+static gfloat
+powfi (gfloat base, guint n)
+{
+	guint i;
+	gfloat retval = 1;
+	for (i=1; i <= n; i++)
+		retval *= base;
+	return retval;
+}
+
+/**
+ * gpm_array_float_remove_outliers:
+ *
+ * @data: input array
+ * @size: size to analyse
+ * @sigma: sigma for standard deviation
+ * Return value: Data with outliers removed
+ *
+ * Compares local sections of the data, removing outliers if they fall
+ * ouside of sigma, and using the average of the other points in it's place.
+ **/
+GpmArrayFloat *
+gpm_array_float_remove_outliers (GpmArrayFloat *data, guint length, gfloat sigma)
+{
+	guint i;
+	guint j;
+	guint half_length;
+	gfloat value;
+	gfloat average;
+	gfloat average_not_inc;
+	gfloat average_square;
+	gfloat biggest_difference;
+	gfloat outlier_value;
+	GpmArrayFloat *result;
+
+	g_return_val_if_fail (length % 2 == 1, NULL);
+	result = gpm_array_float_new (data->len);
+
+	/* check for no data */
+	if (data->len == 0)
+		goto out;
+
+	half_length = (length - 1) / 2;
+
+	/* copy start and end of array */
+	for (i=0; i < half_length; i++)
+		g_array_index (result, gfloat, i) = g_array_index (data, gfloat, i);
+	for (i=data->len-half_length; i < data->len; i++)
+		g_array_index (result, gfloat, i) = g_array_index (data, gfloat, i);
+
+	/* find the standard deviation of a block off data */
+	for (i=half_length; i < data->len-half_length; i++) {
+		average = 0;
+		average_square = 0;
+
+		/* find the average and the squared average */
+		for (j=i-half_length; j<i+half_length+1; j++) {
+			value = g_array_index (data, gfloat, j);
+			average += value;
+			average_square += powfi (value, 2);
+		}
+
+		/* divide by length to get average */
+		average /= length;
+		average_square /= length;
+
+		/* find the standard deviation */
+		value = sqrtf (average_square - powfi (average, 2));
+
+		/* stddev is okay */
+		if (value < sigma) {
+			g_array_index (result, gfloat, i) = g_array_index (data, gfloat, i);
+		} else {
+			/* ignore the biggest difference from the average */
+			biggest_difference = 0;
+			outlier_value = 0;
+			for (j=i-half_length; j<i+half_length+1; j++) {
+				value = fabs (g_array_index (data, gfloat, j) - average);
+				if (value > biggest_difference) {
+					biggest_difference = value;
+					outlier_value = g_array_index (data, gfloat, j);
+				}
+			}
+			average_not_inc = (average * length) - outlier_value;
+			average_not_inc /= length - 1;
+			g_array_index (result, gfloat, i) = average_not_inc;
+		}
+	}
+out:
+	return result;
+}
diff --git a/src/egg-array-float.h b/src/gpm-array-float.h
similarity index 62%
rename from src/egg-array-float.h
rename to src/gpm-array-float.h
index e37e1d0..fa3dcb0 100644
--- a/src/egg-array-float.h
+++ b/src/gpm-array-float.h
@@ -27,29 +27,28 @@
 G_BEGIN_DECLS
 
 /* at the moment just use a GArray as it's quick */
-typedef GArray EggArrayFloat;
+typedef GArray GpmArrayFloat;
 
-EggArrayFloat	*egg_array_float_new			(guint		 length);
-void		 egg_array_float_free			(EggArrayFloat	*array);
-gfloat		 egg_array_float_sum			(EggArrayFloat	*array);
-EggArrayFloat	*egg_array_float_compute_gaussian	(guint		 length,
+GpmArrayFloat	*gpm_array_float_new			(guint		 length);
+void		 gpm_array_float_free			(GpmArrayFloat	*array);
+gfloat		 gpm_array_float_sum			(GpmArrayFloat	*array);
+GpmArrayFloat	*gpm_array_float_compute_gaussian	(guint		 length,
 							 gfloat		 sigma);
-gfloat		 egg_array_float_compute_integral	(EggArrayFloat	*array,
+gfloat		 gpm_array_float_compute_integral	(GpmArrayFloat	*array,
 							 guint		 x1,
 							 guint		 x2);
-gfloat		 egg_array_float_get_average		(EggArrayFloat	*array);
-gboolean	 egg_array_float_print			(EggArrayFloat	*array);
-EggArrayFloat	*egg_array_float_convolve		(EggArrayFloat	*data,
-							 EggArrayFloat	*kernel);
-gfloat		 egg_array_float_get			(EggArrayFloat	*array,
+gfloat		 gpm_array_float_get_average		(GpmArrayFloat	*array);
+gboolean	 gpm_array_float_print			(GpmArrayFloat	*array);
+GpmArrayFloat	*gpm_array_float_convolve		(GpmArrayFloat	*data,
+							 GpmArrayFloat	*kernel);
+gfloat		 gpm_array_float_get			(GpmArrayFloat	*array,
 							 guint		 i);
-void		 egg_array_float_set			(EggArrayFloat	*array,
+void		 gpm_array_float_set			(GpmArrayFloat	*array,
 							 guint		 i,
 							 gfloat		 value);
-EggArrayFloat	*egg_array_float_remove_outliers	(EggArrayFloat *data, guint length, gfloat sigma);
-#ifdef EGG_TEST
-void		 egg_array_float_test			(gpointer	 data);
-#endif
+GpmArrayFloat	*gpm_array_float_remove_outliers	(GpmArrayFloat *data, guint length, gfloat sigma);
+gfloat		 gpm_array_float_guassian_value		(gfloat		 x,
+							 gfloat		 sigma);
 
 G_END_DECLS
 
diff --git a/src/gpm-brightness.c b/src/gpm-brightness.c
index cc8233f..5453124 100644
--- a/src/gpm-brightness.c
+++ b/src/gpm-brightness.c
@@ -40,7 +40,6 @@
 #include <unistd.h>
 #endif /* HAVE_UNISTD_H */
 
-#include "egg-discrete.h"
 #include "egg-debug.h"
 #include "egg-string.h"
 
@@ -328,7 +327,7 @@ gpm_brightness_output_get_percentage (GpmBrightness *brightness, RROutput output
 	if (!ret || min == max)
 		return FALSE;
 	egg_debug ("hard value=%i, min=%i, max=%i", cur, min, max);
-	percentage = egg_discrete_to_percent (cur, (max-min)+1);
+	percentage = gpm_discrete_to_percent (cur, (max-min)+1);
 	egg_debug ("percentage %i", percentage);
 	brightness->priv->shared_value = percentage;
 	return TRUE;
@@ -423,7 +422,7 @@ gpm_brightness_output_set (GpmBrightness *brightness, RROutput output)
 	if (!ret || min == max)
 		return FALSE;
 
-	shared_value_abs = egg_discrete_from_percent (brightness->priv->shared_value, (max-min)+1);
+	shared_value_abs = gpm_discrete_from_percent (brightness->priv->shared_value, (max-min)+1);
 	egg_debug ("percent=%i, absolute=%i", brightness->priv->shared_value, shared_value_abs);
 
 	egg_debug ("hard value=%i, min=%i, max=%i", cur, min, max);
@@ -590,7 +589,7 @@ gpm_brightness_set (GpmBrightness *brightness, guint percentage, gboolean *hw_ch
 	if (!ret) {
 		if (brightness->priv->extension_levels < 0)
 			brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
-		brightness->priv->extension_current = egg_discrete_from_percent (percentage, brightness->priv->extension_levels+1);
+		brightness->priv->extension_current = gpm_discrete_from_percent (percentage, brightness->priv->extension_levels+1);
 		ret = gpm_brightness_helper_set_value ("set-brightness", brightness->priv->extension_current);
 	}
 
@@ -639,7 +638,7 @@ gpm_brightness_get (GpmBrightness *brightness, guint *percentage)
 		if (brightness->priv->extension_levels < 0)
 			brightness->priv->extension_levels = gpm_brightness_helper_get_value ("get-max-brightness");
 		brightness->priv->extension_current = gpm_brightness_helper_get_value ("get-brightness");
-		percentage_local = egg_discrete_to_percent (brightness->priv->extension_current, brightness->priv->extension_levels+1);
+		percentage_local = gpm_discrete_to_percent (brightness->priv->extension_current, brightness->priv->extension_levels+1);
 		ret = TRUE;
 	}
 
diff --git a/src/gpm-common.c b/src/gpm-common.c
index 038bb5b..26196d3 100644
--- a/src/gpm-common.c
+++ b/src/gpm-common.c
@@ -26,6 +26,9 @@
 #include <glib/gi18n.h>
 #include <gdk/gdk.h>
 #include <gtk/gtk.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
 
 #include "egg-debug.h"
 #include "gpm-common.h"
@@ -106,21 +109,154 @@ gpm_help_display (const gchar *link_id)
 	g_free (uri);
 }
 
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef EGG_TEST
-#include "egg-test.h"
+/**
+ * gpm_precision_round_up:
+ * @value: The input value
+ * @smallest: The smallest increment allowed
+ *
+ * 101, 10	110
+ * 95,  10	100
+ * 0,   10	0
+ * 112, 10	120
+ * 100, 10	100
+ **/
+gint
+gpm_precision_round_up (gfloat value, gint smallest)
+{
+	gfloat division;
+	if (fabs (value) < 0.01)
+		return 0;
+	if (smallest == 0) {
+		egg_warning ("divisor zero");
+		return 0;
+	}
+	division = (gfloat) value / (gfloat) smallest;
+	division = ceilf (division);
+	division *= smallest;
+	return (gint) division;
+}
 
-void
-gpm_common_test (gpointer data)
+/**
+ * gpm_precision_round_down:
+ * @value: The input value
+ * @smallest: The smallest increment allowed
+ *
+ * 101, 10	100
+ * 95,  10	90
+ * 0,   10	0
+ * 112, 10	110
+ * 100, 10	100
+ **/
+gint
+gpm_precision_round_down (gfloat value, gint smallest)
+{
+	gfloat division;
+	if (fabs (value) < 0.01)
+		return 0;
+	if (smallest == 0) {
+		egg_warning ("divisor zero");
+		return 0;
+	}
+	division = (gfloat) value / (gfloat) smallest;
+	division = floorf (division);
+	division *= smallest;
+	return (gint) division;
+}
+
+/**
+ * gpm_discrete_from_percent:
+ * @percentage: The percentage to convert
+ * @levels: The number of discrete levels
+ *
+ * We have to be carefull when converting from %->discrete as precision is very
+ * important if we want the highest value.
+ *
+ * Return value: The discrete value for this percentage.
+ **/
+guint
+gpm_discrete_from_percent (guint percentage, guint levels)
+{
+	/* check we are in range */
+	if (percentage > 100)
+		return levels;
+	if (levels == 0) {
+		egg_warning ("levels is 0!");
+		return 0;
+	}
+	return ((gfloat) percentage * (gfloat) (levels - 1)) / 100.0f;
+}
+
+/**
+ * gpm_discrete_to_percent:
+ * @hw: The discrete level
+ * @levels: The number of discrete levels
+ *
+ * We have to be carefull when converting from discrete->%.
+ *
+ * Return value: The percentage for this discrete value.
+ **/
+guint
+gpm_discrete_to_percent (guint discrete, guint levels)
+{
+	/* check we are in range */
+	if (discrete > levels)
+		return 100;
+	if (levels == 0) {
+		egg_warning ("levels is 0!");
+		return 0;
+	}
+	return (guint) ((gfloat) discrete * (100.0f / (gfloat) (levels - 1)));
+}
+
+/**
+ * gpm_discrete_to_fraction:
+ * @hw: The discrete level
+ * @levels: The number of discrete levels
+ *
+ * We have to be careful when converting from discrete->fractions.
+ *
+ * Return value: The floating point fraction (0..1) for this discrete value.
+ **/
+gfloat
+gpm_discrete_to_fraction (guint discrete, guint levels)
 {
-	EggTest *test = (EggTest *) data;
-	if (egg_test_start (test, "GpmCommon") == FALSE)
-		return;
+	/* check we are in range */
+	if (discrete > levels)
+		return 1.0;
+	if (levels == 0) {
+		egg_warning ("levels is 0!");
+		return 0.0;
+	}
+	return (guint) ((gfloat) discrete / ((gfloat) (levels - 1)));
+}
 
-	egg_test_end (test);
+/**
+ * gpm_color_from_rgb:
+ * @red: The red value
+ * @green: The green value
+ * @blue: The blue value
+ **/
+guint32
+gpm_color_from_rgb (guint8 red, guint8 green, guint8 blue)
+{
+	guint32 color = 0;
+	color += (guint32) red * 0x10000;
+	color += (guint32) green * 0x100;
+	color += (guint32) blue;
+	return color;
 }
 
-#endif
+/**
+ * gpm_color_to_rgb:
+ * @red: The red value
+ * @green: The green value
+ * @blue: The blue value
+ **/
+void
+gpm_color_to_rgb (guint32 color, guint8 *red, guint8 *green, guint8 *blue)
+{
+	*red = (color & 0xff0000) / 0x10000;
+	*green = (color & 0x00ff00) / 0x100;
+	*blue = color & 0x0000ff;
+}
 
diff --git a/src/gpm-common.h b/src/gpm-common.h
index a86e1f4..ebf7150 100644
--- a/src/gpm-common.h
+++ b/src/gpm-common.h
@@ -173,12 +173,42 @@ typedef enum {
 	GPM_ACTION_POLICY_INTERACTIVE,
 	GPM_ACTION_POLICY_NOTHING
 } GpmActionPolicy;
+#define	GPM_COLOR_WHITE			0xffffff
+#define	GPM_COLOR_BLACK			0x000000
+#define	GPM_COLOR_RED			0xff0000
+#define	GPM_COLOR_GREEN			0x00ff00
+#define	GPM_COLOR_BLUE			0x0000ff
+#define	GPM_COLOR_CYAN			0x00ffff
+#define	GPM_COLOR_MAGENTA		0xff00ff
+#define	GPM_COLOR_YELLOW		0xffff00
+#define	GPM_COLOR_GREY			0xcccccc
+#define	GPM_COLOR_DARK_RED		0x600000
+#define	GPM_COLOR_DARK_GREEN		0x006000
+#define	GPM_COLOR_DARK_BLUE		0x000060
+#define	GPM_COLOR_DARK_CYAN		0x006060
+#define	GPM_COLOR_DARK_MAGENTA		0x600060
+#define	GPM_COLOR_DARK_YELLOW		0x606000
+#define	GPM_COLOR_DARK_GREY		0x606060
 
 gchar		*gpm_get_timestring				(guint		 time);
 void 		 gpm_help_display				(const gchar	*link_id);
-#ifdef EGG_TEST
-void		 gpm_common_test				(gpointer	 data);
-#endif
+gint		 gpm_precision_round_up				(gfloat		 value,
+								gint		 smallest);
+gint		 gpm_precision_round_down			(gfloat		 value,
+								gint		 smallest);
+guint		 gpm_discrete_from_percent			(guint		 percentage,
+								guint		 levels);
+guint		 gpm_discrete_to_percent			(guint		 discrete,
+								guint		 levels);
+gfloat		 gpm_discrete_to_fraction			(guint		 discrete,
+								guint		 levels);
+guint32		 gpm_color_from_rgb				(guint8		 red,
+								guint8		 green,
+								guint8		 blue);
+void		 gpm_color_to_rgb				(guint32	 color,
+								guint8		*red,
+								guint8		*green,
+								guint8		*blue);
 
 G_END_DECLS
 
diff --git a/src/gpm-dpms.c b/src/gpm-dpms.c
index 081ffce..77d9d4a 100644
--- a/src/gpm-dpms.c
+++ b/src/gpm-dpms.c
@@ -390,86 +390,3 @@ gpm_dpms_new (void)
 	return GPM_DPMS (gpm_dpms_object);
 }
 
-
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef EGG_TEST
-#include "egg-test.h"
-
-void
-gpm_dpms_test (gpointer data)
-{
-	GpmDpms *dpms;
-	gboolean ret;
-	GError *error = NULL;
-	EggTest *test = (EggTest *) data;
-
-	if (!egg_test_start (test, "GpmDpms"))
-		return;
-
-	/************************************************************/
-	egg_test_title (test, "get object");
-	dpms = gpm_dpms_new ();
-	if (dpms != NULL)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "got no object");
-
-	/************************************************************/
-	egg_test_title (test, "set on");
-	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error);
-	if (ret)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "failed: %s", error->message);
-
-	g_usleep (2*1000*1000);
-
-	/************************************************************/
-	egg_test_title (test, "set STANDBY");
-	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_STANDBY, &error);
-	if (ret)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "failed: %s", error->message);
-
-	g_usleep (2*1000*1000);
-
-	/************************************************************/
-	egg_test_title (test, "set SUSPEND");
-	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_SUSPEND, &error);
-	if (ret)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "failed: %s", error->message);
-
-	g_usleep (2*1000*1000);
-
-	/************************************************************/
-	egg_test_title (test, "set OFF");
-	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, &error);
-	if (ret)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "failed: %s", error->message);
-
-	g_usleep (2*1000*1000);
-
-	/************************************************************/
-	egg_test_title (test, "set on");
-	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error);
-	if (ret)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "failed: %s", error->message);
-
-	g_usleep (2*1000*1000);
-
-	g_object_unref (dpms);
-
-	egg_test_end (test);
-}
-
-#endif
-
diff --git a/src/gpm-graph-widget.c b/src/gpm-graph-widget.c
index a9ba689..c81ac2d 100644
--- a/src/gpm-graph-widget.c
+++ b/src/gpm-graph-widget.c
@@ -30,8 +30,6 @@
 #include "gpm-graph-widget.h"
 
 #include "egg-debug.h"
-#include "egg-color.h"
-#include "egg-precision.h"
 
 G_DEFINE_TYPE (GpmGraphWidget, gpm_graph_widget, GTK_TYPE_DRAWING_AREA);
 #define GPM_GRAPH_WIDGET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_GRAPH_WIDGET, GpmGraphWidgetPrivate))
@@ -691,8 +689,8 @@ gpm_graph_widget_autorange_x (GpmGraphWidget *graph)
 			rounding_x = 10 * 60;
 	}
 
-	graph->priv->start_x = egg_precision_round_down (smallest_x, rounding_x);
-	graph->priv->stop_x = egg_precision_round_up (biggest_x, rounding_x);
+	graph->priv->start_x = gpm_precision_round_down (smallest_x, rounding_x);
+	graph->priv->stop_x = gpm_precision_round_up (biggest_x, rounding_x);
 
 	egg_debug ("Processed(1) range is %i<x<%i",
 		   graph->priv->start_x, graph->priv->stop_x);
@@ -785,8 +783,8 @@ gpm_graph_widget_autorange_y (GpmGraphWidget *graph)
 			rounding_y = 10 * 60;
 	}
 
-	graph->priv->start_y = egg_precision_round_down (smallest_y, rounding_y);
-	graph->priv->stop_y = egg_precision_round_up (biggest_y, rounding_y);
+	graph->priv->start_y = gpm_precision_round_down (smallest_y, rounding_y);
+	graph->priv->stop_y = gpm_precision_round_up (biggest_y, rounding_y);
 
 	/* a factor graph always is centered around zero */
 	if (graph->priv->type_y == GPM_GRAPH_WIDGET_TYPE_FACTOR) {
@@ -822,7 +820,7 @@ static void
 gpm_graph_widget_set_color (cairo_t *cr, guint32 color)
 {
 	guint8 r, g, b;
-	egg_color_to_rgb (color, &r, &g, &b);
+	gpm_color_to_rgb (color, &r, &g, &b);
 	cairo_set_source_rgb (cr, ((gdouble) r)/256.0f, ((gdouble) g)/256.0f, ((gdouble) b)/256.0f);
 }
 
diff --git a/src/gpm-idle.c b/src/gpm-idle.c
index 3775019..ce6f595 100644
--- a/src/gpm-idle.c
+++ b/src/gpm-idle.c
@@ -39,7 +39,7 @@
 #include <gtk/gtk.h>
 
 #include "egg-debug.h"
-#include "egg-idletime.h"
+#include "gpm-idletime.h"
 
 #include "gpm-idle.h"
 #include "gpm-load.h"
@@ -54,7 +54,7 @@
 
 struct GpmIdlePrivate
 {
-	EggIdletime	*idletime;
+	GpmIdletime	*idletime;
 	GpmLoad		*load;
 	GpmSession	*session;
 	GpmIdleMode	 mode;
@@ -80,7 +80,7 @@ G_DEFINE_TYPE (GpmIdle, gpm_idle, G_TYPE_OBJECT)
 /**
  * gpm_idle_mode_to_string:
  **/
-static const gchar *
+const gchar *
 gpm_idle_mode_to_string (GpmIdleMode mode)
 {
 	if (mode == GPM_IDLE_MODE_NORMAL)
@@ -271,9 +271,9 @@ gpm_idle_set_timeout_dim (GpmIdle *idle, guint timeout)
 		idle->priv->timeout_dim = timeout;
 
 		if (timeout > 0)
-			egg_idletime_alarm_set (idle->priv->idletime, GPM_IDLE_IDLETIME_ID, timeout * 1000);
+			gpm_idletime_alarm_set (idle->priv->idletime, GPM_IDLE_IDLETIME_ID, timeout * 1000);
 		else
-			egg_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
+			gpm_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
 	}
 	return TRUE;
 }
@@ -341,7 +341,7 @@ gpm_idle_session_inhibited_changed_cb (GpmSession *session, gboolean is_idle_inh
  * We're idle, something timed out
  **/
 static void
-gpm_idle_idletime_alarm_expired_cb (EggIdletime *idletime, guint alarm_id, GpmIdle *idle)
+gpm_idle_idletime_alarm_expired_cb (GpmIdletime *idletime, guint alarm_id, GpmIdle *idle)
 {
 	egg_debug ("idletime alarm: %i", alarm_id);
 
@@ -356,7 +356,7 @@ gpm_idle_idletime_alarm_expired_cb (EggIdletime *idletime, guint alarm_id, GpmId
  * We're no longer idle, the user moved
  **/
 static void
-gpm_idle_idletime_reset_cb (EggIdletime *idletime, GpmIdle *idle)
+gpm_idle_idletime_reset_cb (GpmIdletime *idletime, GpmIdle *idle)
 {
 	egg_debug ("idletime reset");
 
@@ -388,7 +388,7 @@ gpm_idle_finalize (GObject *object)
 	g_object_unref (idle->priv->load);
 	g_object_unref (idle->priv->session);
 
-	egg_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
+	gpm_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
 	g_object_unref (idle->priv->idletime);
 
 	G_OBJECT_CLASS (gpm_idle_parent_class)->finalize (object);
@@ -439,7 +439,7 @@ gpm_idle_init (GpmIdle *idle)
 	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 ();
+	idle->priv->idletime = gpm_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);
 
@@ -462,238 +462,3 @@ gpm_idle_new (void)
 	return GPM_IDLE (gpm_idle_object);
 }
 
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef EGG_TEST
-#include "egg-test.h"
-#include "gpm-dpms.h"
-
-static GpmIdleMode _mode = 0;
-
-static void
-gpm_idle_test_idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, EggTest *test)
-{
-	_mode = mode;
-	egg_debug ("idle-changed %s", gpm_idle_mode_to_string (mode));
-	egg_test_loop_quit (test);
-}
-
-static gboolean
-gpm_idle_test_delay_cb (EggTest *test)
-{
-	egg_warning ("timing out");
-	egg_test_loop_quit (test);
-	return FALSE;
-}
-
-void
-gpm_idle_test (gpointer data)
-{
-	GpmIdle *idle;
-	gboolean ret;
-	EggTest *test = (EggTest *) data;
-	GpmIdleMode mode;
-	GpmDpms *dpms;
-
-	if (!egg_test_start (test, "GpmIdle"))
-		return;
-
-	/************************************************************/
-	egg_test_title (test, "get object");
-	idle = gpm_idle_new ();
-	if (idle != NULL)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "got no object");
-
-	/* set up defaults */
-	gpm_idle_set_check_cpu (idle, FALSE);
-	gpm_idle_set_timeout_dim (idle, 4);
-	gpm_idle_set_timeout_blank (idle, 5);
-	gpm_idle_set_timeout_sleep (idle, 15);
-	g_signal_connect (idle, "idle-changed",
-			  G_CALLBACK (gpm_idle_test_idle_changed_cb), test);
-
-	/************************************************************/
-	egg_test_title (test, "check cpu type");
-	egg_test_assert (test, (idle->priv->check_type_cpu == FALSE));
-
-	/************************************************************/
-	egg_test_title (test, "check timeout dim");
-	egg_test_assert (test, (idle->priv->timeout_dim == 4));
-
-	/************************************************************/
-	egg_test_title (test, "check timeout blank");
-	egg_test_assert (test, (idle->priv->timeout_blank == 5));
-
-	/************************************************************/
-	egg_test_title (test, "check timeout sleep");
-	egg_test_assert (test, (idle->priv->timeout_sleep == 15));
-
-	/************************************************************/
-	egg_test_title (test, "check x_idle");
-	egg_test_assert (test, (idle->priv->x_idle == FALSE));
-
-	/************************************************************/
-	egg_test_title (test, "check blank id");
-	egg_test_assert (test, (idle->priv->timeout_blank_id == 0));
-
-	/************************************************************/
-	egg_test_title (test, "check sleep id");
-	egg_test_assert (test, (idle->priv->timeout_sleep_id == 0));
-
-	/************************************************************/
-	egg_test_title (test, "check normal at startup");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_NORMAL)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	g_print ("*****************************\n");
-	g_print ("*** DO NOT MOVE THE MOUSE ***\n");
-	g_print ("*****************************\n");
-	egg_test_loop_wait (test, 2000 + 10000);
-	egg_test_loop_check (test);
-
-	/************************************************************/
-	egg_test_title (test, "check callback mode");
-	if (_mode == GPM_IDLE_MODE_DIM)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check current mode");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_DIM)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check x_idle");
-	egg_test_assert (test, (idle->priv->x_idle == TRUE));
-
-	/************************************************************/
-	egg_test_title (test, "check blank id");
-	egg_test_assert (test, (idle->priv->timeout_blank_id != 0));
-
-	/************************************************************/
-	egg_test_title (test, "check sleep id");
-	egg_test_assert (test, (idle->priv->timeout_sleep_id == 0));
-
-	/************************************************************/
-	egg_test_loop_wait (test, 5000 + 1000);
-	egg_test_loop_check (test);
-
-	/************************************************************/
-	egg_test_title (test, "check callback mode");
-	if (_mode == GPM_IDLE_MODE_BLANK)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check current mode");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_BLANK)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	g_print ("**********************\n");
-	g_print ("*** MOVE THE MOUSE ***\n");
-	g_print ("**********************\n");
-	egg_test_loop_wait (test, G_MAXUINT);
-	egg_test_loop_check (test);
-
-	/************************************************************/
-	egg_test_title (test, "check callback mode");
-	if (_mode == GPM_IDLE_MODE_NORMAL)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check current mode");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_NORMAL)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check x_idle");
-	egg_test_assert (test, (idle->priv->x_idle == FALSE));
-
-	/************************************************************/
-	egg_test_title (test, "check blank id");
-	egg_test_assert (test, (idle->priv->timeout_blank_id == 0));
-
-	/************************************************************/
-	g_print ("*****************************\n");
-	g_print ("*** DO NOT MOVE THE MOUSE ***\n");
-	g_print ("*****************************\n");
-	egg_test_loop_wait (test, 4000 + 1500);
-	egg_test_loop_check (test);
-
-	/************************************************************/
-	egg_test_title (test, "check current mode");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_DIM)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check x_idle");
-	egg_test_assert (test, (idle->priv->x_idle == TRUE));
-
-	egg_test_loop_wait (test, 15000);
-	egg_test_loop_check (test);
-
-	/************************************************************/
-	egg_test_title (test, "check current mode");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_BLANK)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "set dpms off");
-	dpms = gpm_dpms_new ();
-	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, NULL);
-	egg_test_assert (test, ret);
-
-	/* wait for normal event to be suppressed */
-	g_timeout_add (2000, (GSourceFunc) gpm_idle_test_delay_cb, test);
-	egg_test_loop_wait (test, G_MAXUINT);
-	egg_test_loop_check (test);
-
-	/************************************************************/
-	egg_test_title (test, "check current mode");
-	mode = gpm_idle_get_mode (idle);
-	if (mode == GPM_IDLE_MODE_BLANK)
-		egg_test_success (test, NULL);
-	else
-		egg_test_failed (test, "mode: %s", gpm_idle_mode_to_string (mode));
-
-	/************************************************************/
-	egg_test_title (test, "check x_idle");
-	egg_test_assert (test, (idle->priv->x_idle == TRUE));
-
-	gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, NULL);
-
-	g_object_unref (idle);
-	g_object_unref (dpms);
-
-	egg_test_end (test);
-}
-
-#endif
-
diff --git a/src/gpm-idle.h b/src/gpm-idle.h
index e186838..b0cb406 100644
--- a/src/gpm-idle.h
+++ b/src/gpm-idle.h
@@ -67,7 +67,7 @@ gboolean	 gpm_idle_set_timeout_blank		(GpmIdle	*idle,
 							 guint		 timeout);
 gboolean	 gpm_idle_set_timeout_sleep		(GpmIdle	*idle,
 							 guint		 timeout);
-void		 gpm_idle_test				(gpointer	 data);
+const gchar	*gpm_idle_mode_to_string		(GpmIdleMode	 mode);
 
 G_END_DECLS
 
diff --git a/src/gpm-idletime.c b/src/gpm-idletime.c
new file mode 100644
index 0000000..569b816
--- /dev/null
+++ b/src/gpm-idletime.c
@@ -0,0 +1,472 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007-2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
+#include <glib.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/sync.h>
+#include <gdk/gdkx.h>
+#include <gdk/gdk.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "gpm-idletime.h"
+
+static void     gpm_idletime_finalize   (GObject       *object);
+
+#define GPM_IDLETIME_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_IDLETIME_TYPE, GpmIdletimePrivate))
+
+struct GpmIdletimePrivate
+{
+	gint			 sync_event;
+	gboolean		 reset_set;
+	XSyncCounter		 idle_counter;
+	GPtrArray		*array;
+	Display			*dpy;
+};
+
+typedef struct
+{
+	guint			 id;
+	XSyncValue		 timeout;
+	XSyncAlarm		 xalarm;
+	GpmIdletime		*idletime;
+} GpmIdletimeAlarm;
+
+enum {
+	SIGNAL_ALARM_EXPIRED,
+	SIGNAL_RESET,
+	LAST_SIGNAL
+};
+
+typedef enum {
+	GPM_IDLETIME_ALARM_TYPE_POSITIVE,
+	GPM_IDLETIME_ALARM_TYPE_NEGATIVE,
+	GPM_IDLETIME_ALARM_TYPE_DISABLED
+} GpmIdletimeAlarmType;
+
+static guint signals [LAST_SIGNAL] = { 0 };
+static gpointer gpm_idletime_object = NULL;
+
+G_DEFINE_TYPE (GpmIdletime, gpm_idletime, G_TYPE_OBJECT)
+
+/**
+ * gpm_idletime_xsyncvalue_to_int64:
+ */
+static gint64
+gpm_idletime_xsyncvalue_to_int64 (XSyncValue value)
+{
+	return ((guint64) XSyncValueHigh32 (value)) << 32 | (guint64) XSyncValueLow32 (value);
+}
+
+/**
+ * gpm_idletime_get_time:
+ */
+gint64
+gpm_idletime_get_time (GpmIdletime *idletime)
+{
+	XSyncValue value;
+	XSyncQueryCounter (idletime->priv->dpy, idletime->priv->idle_counter, &value);
+	return gpm_idletime_xsyncvalue_to_int64 (value);
+}
+
+/**
+ * gpm_idletime_xsync_alarm_set:
+ */
+static void
+gpm_idletime_xsync_alarm_set (GpmIdletime *idletime, GpmIdletimeAlarm *alarm_item, GpmIdletimeAlarmType alarm_type)
+{
+	XSyncAlarmAttributes attr;
+	XSyncValue delta;
+	unsigned int flags;
+	XSyncTestType test;
+
+	/* just remove it */
+	if (alarm_type == GPM_IDLETIME_ALARM_TYPE_DISABLED) {
+		if (alarm_item->xalarm) {
+			XSyncDestroyAlarm (idletime->priv->dpy, alarm_item->xalarm);
+			alarm_item->xalarm = None;
+		}
+		return;
+	}
+
+	/* which way do we do the test? */
+	if (alarm_type == GPM_IDLETIME_ALARM_TYPE_POSITIVE)
+		test = XSyncPositiveTransition;
+	else
+		test = XSyncNegativeTransition;
+
+	XSyncIntToValue (&delta, 0);
+
+	attr.trigger.counter = idletime->priv->idle_counter;
+	attr.trigger.value_type = XSyncAbsolute;
+	attr.trigger.test_type = test;
+	attr.trigger.wait_value = alarm_item->timeout;
+	attr.delta = delta;
+
+	flags = XSyncCACounter | XSyncCAValueType | XSyncCATestType | XSyncCAValue | XSyncCADelta;
+
+	if (alarm_item->xalarm)
+		XSyncChangeAlarm (idletime->priv->dpy, alarm_item->xalarm, flags, &attr);
+	else
+		alarm_item->xalarm = XSyncCreateAlarm (idletime->priv->dpy, flags, &attr);
+}
+
+/**
+ * gpm_idletime_alarm_reset_all:
+ */
+void
+gpm_idletime_alarm_reset_all (GpmIdletime *idletime)
+{
+	guint i;
+	GpmIdletimeAlarm *alarm_item;
+
+	g_return_if_fail (GPM_IS_IDLETIME (idletime));
+
+	if (!idletime->priv->reset_set)
+		return;
+
+	/* reset all the alarms (except the reset alarm) to their timeouts */
+	for (i=1; i<idletime->priv->array->len; i++) {
+		alarm_item = g_ptr_array_index (idletime->priv->array, i);
+		gpm_idletime_xsync_alarm_set (idletime, alarm_item, GPM_IDLETIME_ALARM_TYPE_POSITIVE);
+	}
+
+	/* set the reset alarm to be disabled */
+	alarm_item = g_ptr_array_index (idletime->priv->array, 0);
+	gpm_idletime_xsync_alarm_set (idletime, alarm_item, GPM_IDLETIME_ALARM_TYPE_DISABLED);
+
+	/* emit signal so say we've reset all timers */
+	g_signal_emit (idletime, signals [SIGNAL_RESET], 0);
+
+	/* we need to be reset again on the next event */
+	idletime->priv->reset_set = FALSE;
+}
+
+/**
+ * gpm_idletime_alarm_find_id:
+ */
+static GpmIdletimeAlarm *
+gpm_idletime_alarm_find_id (GpmIdletime *idletime, guint id)
+{
+	guint i;
+	GpmIdletimeAlarm *alarm_item;
+	for (i=0; i<idletime->priv->array->len; i++) {
+		alarm_item = g_ptr_array_index (idletime->priv->array, i);
+		if (alarm_item->id == id)
+			return alarm_item;
+	}
+	return NULL;
+}
+
+/**
+ * gpm_idletime_set_reset_alarm:
+ */
+static void
+gpm_idletime_set_reset_alarm (GpmIdletime *idletime, XSyncAlarmNotifyEvent *alarm_event)
+{
+	GpmIdletimeAlarm *alarm_item;
+	int overflow;
+	XSyncValue add;
+	gint64 current, reset_threshold;
+
+	alarm_item = gpm_idletime_alarm_find_id (idletime, 0);
+
+	if (!idletime->priv->reset_set) {
+		/* don't match on the current value because
+		 * XSyncNegativeComparison means less or equal. */
+		XSyncIntToValue (&add, -1);
+		XSyncValueAdd (&alarm_item->timeout, alarm_event->counter_value, add, &overflow);
+
+		/* set the reset alarm to fire the next time
+		 * idletime->priv->idle_counter < the current counter value */
+		gpm_idletime_xsync_alarm_set (idletime, alarm_item, GPM_IDLETIME_ALARM_TYPE_NEGATIVE);
+
+		/* don't try to set this again if multiple timers are going off in sequence */
+		idletime->priv->reset_set = TRUE;
+
+		current = gpm_idletime_get_time (idletime);
+		reset_threshold = gpm_idletime_xsyncvalue_to_int64 (alarm_item->timeout);
+		if (current < reset_threshold) {
+			/* We've missed the alarm already */
+			gpm_idletime_alarm_reset_all (idletime);
+		}
+	}
+}
+
+/**
+ * gpm_idletime_alarm_find_event:
+ */
+static GpmIdletimeAlarm *
+gpm_idletime_alarm_find_event (GpmIdletime *idletime, XSyncAlarmNotifyEvent *alarm_event)
+{
+	guint i;
+	GpmIdletimeAlarm *alarm_item;
+	for (i=0; i<idletime->priv->array->len; i++) {
+		alarm_item = g_ptr_array_index (idletime->priv->array, i);
+		if (alarm_event->alarm == alarm_item->xalarm)
+			return alarm_item;
+	}
+	return NULL;
+}
+
+/**
+ * gpm_idletime_event_filter_cb:
+ */
+static GdkFilterReturn
+gpm_idletime_event_filter_cb (GdkXEvent *gdkxevent, GdkEvent *event, gpointer data)
+{
+	GpmIdletimeAlarm *alarm_item;
+	XEvent *xevent = (XEvent *) gdkxevent;
+	GpmIdletime *idletime = (GpmIdletime *) data;
+	XSyncAlarmNotifyEvent *alarm_event;
+
+	/* no point continuing */
+	if (xevent->type != idletime->priv->sync_event + XSyncAlarmNotify)
+		return GDK_FILTER_CONTINUE;
+
+	alarm_event = (XSyncAlarmNotifyEvent *) xevent;
+
+	/* did we match one of our alarms? */
+	alarm_item = gpm_idletime_alarm_find_event (idletime, alarm_event);
+	if (alarm_item == NULL)
+		return GDK_FILTER_CONTINUE;
+
+	/* are we the reset alarm? */
+	if (alarm_item->id == 0) {
+		gpm_idletime_alarm_reset_all (idletime);
+		goto out;
+	}
+
+	/* emit */
+	g_signal_emit (alarm_item->idletime, signals [SIGNAL_ALARM_EXPIRED], 0, alarm_item->id);
+
+	/* we need the first alarm to go off to set the reset alarm */
+	gpm_idletime_set_reset_alarm (idletime, alarm_event);
+out:
+	/* don't propagate */
+	return GDK_FILTER_REMOVE;
+}
+
+/**
+ * gpm_idletime_alarm_new:
+ */
+static GpmIdletimeAlarm *
+gpm_idletime_alarm_new (GpmIdletime *idletime, guint id)
+{
+	GpmIdletimeAlarm *alarm_item;
+
+	/* create a new alarm */
+	alarm_item = g_new0 (GpmIdletimeAlarm, 1);
+
+	/* set the default values */
+	alarm_item->id = id;
+	alarm_item->xalarm = None;
+	alarm_item->idletime = g_object_ref (idletime);
+
+	return alarm_item;
+}
+
+/**
+ * gpm_idletime_alarm_set:
+ */
+gboolean
+gpm_idletime_alarm_set (GpmIdletime *idletime, guint id, guint timeout)
+{
+	GpmIdletimeAlarm *alarm_item;
+
+	g_return_val_if_fail (GPM_IS_IDLETIME (idletime), FALSE);
+	g_return_val_if_fail (id != 0, FALSE);
+	g_return_val_if_fail (timeout != 0, FALSE);
+
+	/* see if we already created an alarm with this ID */
+	alarm_item = gpm_idletime_alarm_find_id (idletime, id);
+	if (alarm_item == NULL) {
+		/* create a new alarm */
+		alarm_item = gpm_idletime_alarm_new (idletime, id);
+
+		/* add to array */
+		g_ptr_array_add (idletime->priv->array, alarm_item);
+	}
+
+	/* set the timeout */
+	XSyncIntToValue (&alarm_item->timeout, (gint)timeout);
+
+	/* set, and start the timer */
+	gpm_idletime_xsync_alarm_set (idletime, alarm_item, GPM_IDLETIME_ALARM_TYPE_POSITIVE);
+	return TRUE;
+}
+
+/**
+ * gpm_idletime_alarm_free:
+ */
+static gboolean
+gpm_idletime_alarm_free (GpmIdletime *idletime, GpmIdletimeAlarm *alarm_item)
+{
+	g_return_val_if_fail (GPM_IS_IDLETIME (idletime), FALSE);
+	g_return_val_if_fail (alarm_item != NULL, FALSE);
+
+	if (alarm_item->xalarm)
+		XSyncDestroyAlarm (idletime->priv->dpy, alarm_item->xalarm);
+	g_object_unref (alarm_item->idletime);
+	g_free (alarm_item);
+	g_ptr_array_remove (idletime->priv->array, alarm_item);
+	return TRUE;
+}
+
+/**
+ * gpm_idletime_alarm_free:
+ */
+gboolean
+gpm_idletime_alarm_remove (GpmIdletime *idletime, guint id)
+{
+	GpmIdletimeAlarm *alarm_item;
+
+	g_return_val_if_fail (GPM_IS_IDLETIME (idletime), FALSE);
+
+	alarm_item = gpm_idletime_alarm_find_id (idletime, id);
+	if (alarm_item == NULL)
+		return FALSE;
+	gpm_idletime_alarm_free (idletime, alarm_item);
+	return TRUE;
+}
+
+/**
+ * gpm_idletime_class_init:
+ **/
+static void
+gpm_idletime_class_init (GpmIdletimeClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gpm_idletime_finalize;
+	g_type_class_add_private (klass, sizeof (GpmIdletimePrivate));
+
+	signals [SIGNAL_ALARM_EXPIRED] =
+		g_signal_new ("alarm-expired",
+			      G_TYPE_FROM_CLASS (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (GpmIdletimeClass, alarm_expired),
+			      NULL, NULL, g_cclosure_marshal_VOID__UINT,
+			      G_TYPE_NONE, 1, G_TYPE_UINT);
+	signals [SIGNAL_RESET] =
+		g_signal_new ("reset",
+			      G_TYPE_FROM_CLASS (object_class),
+			      G_SIGNAL_RUN_LAST,
+			      G_STRUCT_OFFSET (GpmIdletimeClass, reset),
+			      NULL, NULL, g_cclosure_marshal_VOID__VOID,
+			      G_TYPE_NONE, 0);
+}
+
+/**
+ * gpm_idletime_init:
+ **/
+static void
+gpm_idletime_init (GpmIdletime *idletime)
+{
+	int sync_error;
+	int ncounters;
+	XSyncSystemCounter *counters;
+	GpmIdletimeAlarm *alarm_item;
+	guint i;
+
+	idletime->priv = GPM_IDLETIME_GET_PRIVATE (idletime);
+
+	idletime->priv->array = g_ptr_array_new ();
+
+	idletime->priv->reset_set = FALSE;
+	idletime->priv->idle_counter = None;
+	idletime->priv->sync_event = 0;
+	idletime->priv->dpy = GDK_DISPLAY ();
+
+	/* get the sync event */
+	if (!XSyncQueryExtension (idletime->priv->dpy, &idletime->priv->sync_event, &sync_error)) {
+		g_warning ("No Sync extension.");
+		return;
+	}
+
+	/* gtk_init should do XSyncInitialize for us */
+	counters = XSyncListSystemCounters (idletime->priv->dpy, &ncounters);
+	for (i=0; i < ncounters && !idletime->priv->idle_counter; i++) {
+		if (strcmp(counters[i].name, "IDLETIME") == 0)
+			idletime->priv->idle_counter = counters[i].counter;
+	}
+	XSyncFreeSystemCounterList (counters);
+
+	/* arh. we don't have IDLETIME support */
+	if (!idletime->priv->idle_counter) {
+		g_warning ("No idle counter.");
+		return;
+	}
+
+	/* catch the timer alarm */
+	gdk_window_add_filter (NULL, gpm_idletime_event_filter_cb, idletime);
+
+	/* create a reset alarm */
+	alarm_item = gpm_idletime_alarm_new (idletime, 0);
+	g_ptr_array_add (idletime->priv->array, alarm_item);
+}
+
+/**
+ * gpm_idletime_finalize:
+ **/
+static void
+gpm_idletime_finalize (GObject *object)
+{
+	guint i;
+	GpmIdletime *idletime;
+	GpmIdletimeAlarm *alarm_item;
+
+	g_return_if_fail (object != NULL);
+	g_return_if_fail (GPM_IS_IDLETIME (object));
+
+	idletime = GPM_IDLETIME (object);
+	idletime->priv = GPM_IDLETIME_GET_PRIVATE (idletime);
+
+	/* free all counters, including reset counter */
+	for (i=0; i<idletime->priv->array->len; i++) {
+		alarm_item = g_ptr_array_index (idletime->priv->array, i);
+		gpm_idletime_alarm_free (idletime, alarm_item);
+	}
+	g_ptr_array_free (idletime->priv->array, TRUE);
+
+	G_OBJECT_CLASS (gpm_idletime_parent_class)->finalize (object);
+}
+
+/**
+ * gpm_idletime_new:
+ **/
+GpmIdletime *
+gpm_idletime_new (void)
+{
+	if (gpm_idletime_object != NULL) {
+		g_object_ref (gpm_idletime_object);
+	} else {
+		gpm_idletime_object = g_object_new (GPM_IDLETIME_TYPE, NULL);
+		g_object_add_weak_pointer (gpm_idletime_object, &gpm_idletime_object);
+	}
+	return GPM_IDLETIME (gpm_idletime_object);
+}
+
diff --git a/src/gpm-idletime.h b/src/gpm-idletime.h
new file mode 100644
index 0000000..a644fc9
--- /dev/null
+++ b/src/gpm-idletime.h
@@ -0,0 +1,65 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2007 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __GPM_IDLETIME_H
+#define __GPM_IDLETIME_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GPM_IDLETIME_TYPE		(gpm_idletime_get_type ())
+#define GPM_IDLETIME(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), GPM_IDLETIME_TYPE, GpmIdletime))
+#define GPM_IDLETIME_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GPM_IDLETIME_TYPE, GpmIdletimeClass))
+#define GPM_IS_IDLETIME(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GPM_IDLETIME_TYPE))
+#define GPM_IS_IDLETIME_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GPM_IDLETIME_TYPE))
+#define GPM_IDLETIME_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GPM_IDLETIME_TYPE, GpmIdletimeClass))
+
+typedef struct GpmIdletimePrivate GpmIdletimePrivate;
+
+typedef struct
+{
+	GObject			 parent;
+	GpmIdletimePrivate	*priv;
+} GpmIdletime;
+
+typedef struct
+{
+	GObjectClass	parent_class;
+	void		(* alarm_expired)		(GpmIdletime	*idletime,
+							 guint		 timer_id);
+	void		(* reset)			(GpmIdletime	*idletime);
+} GpmIdletimeClass;
+
+GType		 gpm_idletime_get_type			(void);
+GpmIdletime	*gpm_idletime_new			(void);
+
+void		 gpm_idletime_alarm_reset_all		(GpmIdletime	*idletime);
+gboolean	 gpm_idletime_alarm_set			(GpmIdletime	*idletime,
+							 guint		 alarm_id,
+							 guint		 timeout);
+gboolean	 gpm_idletime_alarm_remove		(GpmIdletime	*idletime,
+							 guint		 alarm_id);
+gint64		 gpm_idletime_get_time			(GpmIdletime	*idletime);
+
+G_END_DECLS
+
+#endif	/* __GPM_IDLETIME_H */
diff --git a/src/gpm-phone.c b/src/gpm-phone.c
index 22bf232..7abe45e 100644
--- a/src/gpm-phone.c
+++ b/src/gpm-phone.c
@@ -366,123 +366,3 @@ gpm_phone_new (void)
 	return GPM_PHONE (gpm_phone_object);
 }
 
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef EGG_TEST
-#include "egg-test.h"
-
-static gboolean test_got_refresh = FALSE;
-
-static void
-egg_test_mainloop_wait (guint ms)
-{
-	GMainLoop *loop;
-	loop = g_main_loop_new (NULL, FALSE);
-	g_timeout_add (ms, (GSourceFunc) g_main_loop_quit, loop);
-	g_main_loop_run (loop);
-}
-
-static void
-phone_device_refresh_cb (GpmPhone *phone, guint idx, gpointer *data)
-{
-	g_debug ("idx refresh = %i", idx);
-	if (idx == 0 && GPOINTER_TO_UINT (data) == 44)
-		test_got_refresh = TRUE;
-}
-
-void
-gpm_phone_test (gpointer data)
-{
-	GpmPhone *phone;
-	guint value;
-	gboolean ret;
-	EggTest *test = (EggTest *) data;
-
-	if (egg_test_start (test, "GpmPhone") == FALSE)
-		return;
-
-	/************************************************************/
-	egg_test_title (test, "make sure we get a non null phone");
-	phone = gpm_phone_new ();
-	if (phone != NULL)
-		egg_test_success (test, "got GpmPhone");
-	else
-		egg_test_failed (test, "could not get GpmPhone");
-
-	/* connect signals */
-	g_signal_connect (phone, "device-refresh",
-			  G_CALLBACK (phone_device_refresh_cb), GUINT_TO_POINTER(44));
-
-	/************************************************************/
-	egg_test_title (test, "make sure we got a connection");
-	if (phone->priv->proxy != NULL) {
-		egg_test_success (test, "got connection");
-	} else {
-		/* skip this part of the test */
-		egg_test_success (test, "could not get a connection!");
-		goto out;
-	}
-
-	/************************************************************/
-	egg_test_title (test, "coldplug the data");
-	ret = gpm_phone_coldplug (phone);
-	if (ret) {
-		egg_test_success (test, "coldplug okay");
-	} else {
-		egg_test_failed (test, "could not coldplug");
-	}
-
-	egg_test_mainloop_wait (500);
-
-	/************************************************************/
-	egg_test_title (test, "got refresh");
-	if (test_got_refresh) {
-		egg_test_success (test, NULL);
-	} else {
-		egg_test_failed (test, "did not get refresh");
-	}
-
-	/************************************************************/
-	egg_test_title (test, "check the connected phones");
-	value = gpm_phone_get_num_batteries (phone);
-	if (value == 1) {
-		egg_test_success (test, "connected phone");
-	} else {
-		egg_test_failed (test, "not connected with %i (phone not connected?)", value);
-	}
-
-	/************************************************************/
-	egg_test_title (test, "check the present value");
-	ret = gpm_phone_get_present (phone, 0);
-	if (ret) {
-		egg_test_success (test, "we are here!");
-	} else {
-		egg_test_failed (test, "not here...");
-	}
-
-	/************************************************************/
-	egg_test_title (test, "check the percentage");
-	value = gpm_phone_get_percentage (phone, 0);
-	if (value != 0) {
-		egg_test_success (test, "percentage is %i", phone->priv->percentage);
-	} else {
-		egg_test_failed (test, "could not get value");
-	}
-
-	/************************************************************/
-	egg_test_title (test, "check the ac value");
-	ret = gpm_phone_get_on_ac (phone, 0);
-	if (!ret) {
-		egg_test_success (test, "not charging, correct");
-	} else {
-		egg_test_failed (test, "charging?");
-	}
-out:
-	g_object_unref (phone);
-
-	egg_test_end (test);
-}
-
-#endif
-
diff --git a/src/gpm-screensaver.c b/src/gpm-screensaver.c
index ab1cb47..c42c014 100644
--- a/src/gpm-screensaver.c
+++ b/src/gpm-screensaver.c
@@ -424,59 +424,4 @@ gpm_screensaver_new (void)
 	}
 	return GPM_SCREENSAVER (gpm_screensaver_object);
 }
-/***************************************************************************
- ***                          MAKE CHECK TESTS                           ***
- ***************************************************************************/
-#ifdef EGG_TEST
-#include "egg-test.h"
-
-#if 0
-static gboolean test_got_request = FALSE;
-static void
-gpm_screensaver_test_auth_request_cb (GpmScreensaver *screensaver, gboolean auth, EggTest *test)
-{
-	egg_debug ("auth request = %i", auth);
-	test_got_request = auth;
-
-	egg_test_loop_quit (test);
-}
-#endif
-
-void
-gpm_screensaver_test (gpointer data)
-{
-	GpmScreensaver *screensaver;
-//	guint value;
-	gboolean ret;
-	EggTest *test = (EggTest *) data;
-
-	if (egg_test_start (test, "GpmScreensaver") == FALSE)
-		return;
-
-	/************************************************************/
-	egg_test_title (test, "make sure we get a non null screensaver");
-	screensaver = gpm_screensaver_new ();
-	egg_test_assert (test, (screensaver != NULL));
-
-#if 0
-	/* connect signals */
-	g_signal_connect (screensaver, "auth-request",
-			  G_CALLBACK (gpm_screensaver_test_auth_request_cb), test);
-#endif
-	/************************************************************/
-	egg_test_title (test, "lock screensaver");
-	ret = gpm_screensaver_lock (screensaver);
-	egg_test_assert (test, ret);
-
-	/************************************************************/
-	egg_test_title (test, "poke screensaver");
-	ret = gpm_screensaver_poke (screensaver);
-	egg_test_assert (test, ret);
-
-	g_object_unref (screensaver);
-
-	egg_test_end (test);
-}
-
-#endif
 
diff --git a/src/gpm-self-test.c b/src/gpm-self-test.c
index ef8c769..c3189e2 100644
--- a/src/gpm-self-test.c
+++ b/src/gpm-self-test.c
@@ -1,6 +1,6 @@
 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
  *
- * Copyright (C) 2007-2008 Richard Hughes <richard hughsie com>
+ * Copyright (C) 2007-2010 Richard Hughes <richard hughsie com>
  *
  * Licensed under the GNU General Public License Version 2
  *
@@ -22,63 +22,844 @@
 #include "config.h"
 
 #include <glib.h>
+#include <math.h>
 #include <glib-object.h>
 #include <gtk/gtk.h>
-#include "egg-test.h"
+
 #include "egg-debug.h"
 
 #include "gpm-screensaver.h"
+#include "gpm-dpms.h"
+#include "gpm-phone.h"
+#include "gpm-idle.h"
+#include "gpm-common.h"
+#include "gpm-idletime.h"
+#include "gpm-array-float.h"
+
+
+/** ver:1.0 ***********************************************************/
+static GMainLoop *_test_loop = NULL;
+static guint _test_loop_timeout_id = 0;
+
+static gboolean
+_g_test_hang_check_cb (gpointer user_data)
+{
+	guint timeout_ms = *((guint*) user_data);
+	g_main_loop_quit (_test_loop);
+	g_warning ("loop not completed in %ims", timeout_ms);
+	g_assert_not_reached ();
+	return FALSE;
+}
+
+/**
+ * _g_test_loop_run_with_timeout:
+ **/
+static void
+_g_test_loop_run_with_timeout (guint timeout_ms)
+{
+	g_assert (_test_loop_timeout_id == 0);
+	_test_loop = g_main_loop_new (NULL, FALSE);
+	_test_loop_timeout_id = g_timeout_add (timeout_ms, _g_test_hang_check_cb, &timeout_ms);
+	g_main_loop_run (_test_loop);
+}
+
+#if 0
+static gboolean
+_g_test_hang_wait_cb (gpointer user_data)
+{
+	g_main_loop_quit (_test_loop);
+	_test_loop_timeout_id = 0;
+	return FALSE;
+}
+
+/**
+ * _g_test_loop_wait:
+ **/
+static void
+_g_test_loop_wait (guint timeout_ms)
+{
+	g_assert (_test_loop_timeout_id == 0);
+	_test_loop = g_main_loop_new (NULL, FALSE);
+	_test_loop_timeout_id = g_timeout_add (timeout_ms, _g_test_hang_wait_cb, &timeout_ms);
+	g_main_loop_run (_test_loop);
+}
+#endif
+
+/**
+ * _g_test_loop_quit:
+ **/
+static void
+_g_test_loop_quit (void)
+{
+	if (_test_loop_timeout_id > 0) {
+		g_source_remove (_test_loop_timeout_id);
+		_test_loop_timeout_id = 0;
+	}
+	if (_test_loop != NULL) {
+		g_main_loop_quit (_test_loop);
+		g_main_loop_unref (_test_loop);
+		_test_loop = NULL;
+	}
+}
+
+/**********************************************************************/
+
+static void
+gpm_test_dpms_func (void)
+{
+	GpmDpms *dpms;
+	gboolean ret;
+	GError *error = NULL;
+
+	dpms = gpm_dpms_new ();
+	g_assert (dpms != NULL);
+
+	/* set on */
+	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error);
+	g_assert_no_error (error);
+	g_assert (ret);
+
+	g_usleep (2*1000*1000);
+
+	/* set STANDBY */
+	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_STANDBY, &error);
+	g_assert_no_error (error);
+	g_assert (ret);
+
+	g_usleep (2*1000*1000);
+
+	/* set SUSPEND */
+	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_SUSPEND, &error);
+	g_assert_no_error (error);
+	g_assert (ret);
+
+	g_usleep (2*1000*1000);
+
+	/* set OFF */
+	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, &error);
+	g_assert_no_error (error);
+	g_assert (ret);
+
+	g_usleep (2*1000*1000);
+
+	/* set on */
+	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, &error);
+	g_assert_no_error (error);
+	g_assert (ret);
+
+	g_usleep (2*1000*1000);
+
+	g_object_unref (dpms);
+}
+
+static GpmIdleMode _mode = 0;
+
+static void
+gpm_test_idle_func_idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, gpointer user_data)
+{
+	_mode = mode;
+	egg_debug ("idle-changed %s", gpm_idle_mode_to_string (mode));
+	_g_test_loop_quit ();
+}
+
+static void
+gpm_test_idle_func (void)
+{
+	GpmIdle *idle;
+	gboolean ret;
+	GpmDpms *dpms;
+
+	idle = gpm_idle_new ();
+	g_assert (idle != NULL);
+
+	/* set up defaults */
+	gpm_idle_set_check_cpu (idle, FALSE);
+	gpm_idle_set_timeout_dim (idle, 4);
+	gpm_idle_set_timeout_blank (idle, 5);
+	gpm_idle_set_timeout_sleep (idle, 15);
+	g_signal_connect (idle, "idle-changed",
+			  G_CALLBACK (gpm_test_idle_func_idle_changed_cb), NULL);
+
+	/* check normal at startup */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_NORMAL);
+
+	g_print ("*****************************\n");
+	g_print ("*** DO NOT MOVE THE MOUSE ***\n");
+	g_print ("*****************************\n");
+	_g_test_loop_run_with_timeout (2000 + 10000);
+
+	/* check callback mode */
+	g_assert_cmpint (_mode, ==, GPM_IDLE_MODE_DIM);
+
+	/* check current mode */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_DIM);
+
+	_g_test_loop_run_with_timeout (5000 + 1000);
+
+	/* check callback mode */
+	g_assert_cmpint (_mode, ==, GPM_IDLE_MODE_BLANK);
+
+	/* check current mode */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_BLANK);
+
+	g_print ("**********************\n");
+	g_print ("*** MOVE THE MOUSE ***\n");
+	g_print ("**********************\n");
+	_g_test_loop_run_with_timeout (G_MAXUINT);
+
+	/* check callback mode */
+	g_assert_cmpint (_mode, ==, GPM_IDLE_MODE_NORMAL);
+
+	/* check current mode */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_NORMAL);
+
+	g_print ("*****************************\n");
+	g_print ("*** DO NOT MOVE THE MOUSE ***\n");
+	g_print ("*****************************\n");
+	_g_test_loop_run_with_timeout (4000 + 1500);
+
+	/* check current mode */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_DIM);
+
+	_g_test_loop_run_with_timeout (15000);
+
+	/* check current mode */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_BLANK);
+
+	/* set dpms off */
+	dpms = gpm_dpms_new ();
+	ret = gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_OFF, NULL);
+	g_assert (ret);
+
+	/* wait for normal event to be suppressed */
+//	g_timeout_add (2000, (GSourceFunc) gpm_test_idle_func_delay_cb, NULL);
+	_g_test_loop_run_with_timeout (G_MAXUINT);
+
+	/* check current mode */
+	g_assert_cmpint (gpm_idle_get_mode (idle), ==, GPM_IDLE_MODE_BLANK);
+
+	gpm_dpms_set_mode (dpms, GPM_DPMS_MODE_ON, NULL);
+
+	g_object_unref (idle);
+	g_object_unref (dpms);
+}
+
+static gboolean _test_got_refresh = FALSE;
+
+static void
+gpm_test_phone_device_refresh_cb (GpmPhone *phone, guint idx, gpointer *data)
+{
+	g_debug ("idx refresh = %i", idx);
+	if (idx == 0 && GPOINTER_TO_UINT (data) == 44)
+		_test_got_refresh = TRUE;
+}
+
+static void
+gpm_test_phone_func (void)
+{
+	GpmPhone *phone;
+	guint value;
+	gboolean ret;
+
+	/* make sure we get a non null phone */
+	phone = gpm_phone_new ();
+	g_assert (phone != NULL);
+
+	/* connect signals */
+	g_signal_connect (phone, "device-refresh",
+			  G_CALLBACK (gpm_test_phone_device_refresh_cb), GUINT_TO_POINTER(44));
+
+	/* coldplug the data */
+	ret = gpm_phone_coldplug (phone);
+	g_assert (ret);
+
+	_g_test_loop_run_with_timeout (500);
+
+	/* got refresh */
+	g_assert (_test_got_refresh);
+
+	/* check the connected phones */
+	value = gpm_phone_get_num_batteries (phone);
+	g_assert_cmpint (value, ==, 1);
+
+	/* check the present value */
+	ret = gpm_phone_get_present (phone, 0);
+	g_assert (ret);
+
+	/* check the percentage */
+	value = gpm_phone_get_percentage (phone, 0);
+	g_assert_cmpint (value, !=, 0);
+
+	/* check the ac value */
+	ret = gpm_phone_get_on_ac (phone, 0);
+	g_assert (ret);
+//out:
+	g_object_unref (phone);
+}
+
+#if 0
+static void
+gpm_test_screensaver_func_auth_request_cb (GpmScreensaver *screensaver, gboolean auth, gpointer user_data)
+{
+	egg_debug ("auth request = %i", auth);
+	test_got_request = auth;
+
+	_g_test_loop_quit ();
+}
+#endif
+
+static void
+gpm_test_screensaver_func (void)
+{
+	GpmScreensaver *screensaver;
+//	guint value;
+	gboolean ret;
+
+	screensaver = gpm_screensaver_new ();
+	g_assert (screensaver != NULL);
+
+#if 0
+	/* connect signals */
+	g_signal_connect (screensaver, "auth-request",
+			  G_CALLBACK (gpm_test_screensaver_func_auth_request_cb), NULL);
+#endif
+	/* lock */
+	ret = gpm_screensaver_lock (screensaver);
+	g_assert (ret);
+
+	/* poke */
+	ret = gpm_screensaver_poke (screensaver);
+	g_assert (ret);
+
+	g_object_unref (screensaver);
+}
+
+static void
+gpm_test_precision_func (void)
+{
+	g_assert_cmpint (gpm_precision_round_down (0, 10), ==, 0);
+	g_assert_cmpint (gpm_precision_round_down (4, 10), ==, 0);
+	g_assert_cmpint (gpm_precision_round_down (11, 10), ==, 10);
+	g_assert_cmpint (gpm_precision_round_down (201, 2), ==, 200);
+	g_assert_cmpint (gpm_precision_round_down (100, 10), ==, 100);
+	g_assert_cmpint (gpm_precision_round_up (0, 10), ==, 0);
+	g_assert_cmpint (gpm_precision_round_up (4, 10), ==, 10);
+	g_assert_cmpint (gpm_precision_round_up (11, 10), ==, 20);
+	g_assert_cmpint (gpm_precision_round_up (201, 2), ==, 202);
+	g_assert_cmpint (gpm_precision_round_up (100, 10), ==, 100);
+}
+
+static void
+gpm_test_discrete_func (void)
+{
+	gfloat fvalue;
+
+	/* convert discrete levels */
+	g_assert_cmpint (gpm_discrete_to_percent (0, 10), ==, 0);
+	g_assert_cmpint (gpm_discrete_to_percent (9, 10), ==, 100);
+
+	/* convert discrete 20/10 levels */
+	g_assert_cmpint (gpm_discrete_to_percent (20, 10), ==, 100);
+
+	/* convert discrete 0/10 levels */
+	fvalue = gpm_discrete_to_fraction (0, 10);
+	g_assert_cmpfloat (fvalue, >, -0.01);
+	g_assert_cmpfloat (fvalue, <, 0.01);
+
+	/* convert discrete 9/10 levels */
+	fvalue = gpm_discrete_to_fraction (9, 10);
+	g_assert_cmpfloat (fvalue, >, -1.01);
+	g_assert_cmpfloat (fvalue, <, 1.01);
+}
+
+static void
+gpm_test_color_func (void)
+{
+	guint8 r, g, b;
+	guint32 color;
+
+	/* get red */
+	gpm_color_to_rgb (0xff0000, &r, &g, &b);
+	g_assert_cmpint (r, ==, 255);
+	g_assert_cmpint (g, ==, 0);
+	g_assert_cmpint (b, ==, 0);
+
+	/* get green */
+	gpm_color_to_rgb (0x00ff00, &r, &g, &b);
+	g_assert_cmpint (r, ==, 0);
+	g_assert_cmpint (g, ==, 255);
+	g_assert_cmpint (b, ==, 0);
+
+	/* get blue */
+	gpm_color_to_rgb (0x0000ff, &r, &g, &b);
+	g_assert_cmpint (r, ==, 0);
+	g_assert_cmpint (g, ==, 0);
+	g_assert_cmpint (b, ==, 255);
+
+	/* get black */
+	gpm_color_to_rgb (0x000000, &r, &g, &b);
+	g_assert_cmpint (r, ==, 0);
+	g_assert_cmpint (g, ==, 0);
+	g_assert_cmpint (b, ==, 0);
+
+	/* get white */
+	gpm_color_to_rgb (0xffffff, &r, &g, &b);
+	g_assert_cmpint (r, ==, 255);
+	g_assert_cmpint (g, ==, 255);
+	g_assert_cmpint (b, ==, 255);
+
+	/* set red */
+	color = gpm_color_from_rgb (0xff, 0x00, 0x00);
+	g_assert_cmpint (color, ==, 0xff0000);
+
+	/* set green */
+	color = gpm_color_from_rgb (0x00, 0xff, 0x00);
+	g_assert_cmpint (color, ==, 0x00ff00);
+
+	/* set blue */
+	color = gpm_color_from_rgb (0x00, 0x00, 0xff);
+	g_assert_cmpint (color, ==, 0x0000ff);
+
+	/* set white */
+	color = gpm_color_from_rgb (0xff, 0xff, 0xff);
+	g_assert_cmpint (color, ==, 0xffffff);
+}
+
+
+static void
+gpm_test_array_float_func (void)
+{
+	GpmArrayFloat *array;
+	GpmArrayFloat *kernel;
+	GpmArrayFloat *result;
+	gfloat value;
+	gfloat sigma;
+	guint size;
+
+	/* make sure we get a non null array */
+	array = gpm_array_float_new (10);
+	g_assert (array != NULL);
+
+	gpm_array_float_print (array);
+	gpm_array_float_free (array);
+
+	/* make sure we get the correct length array */
+	array = gpm_array_float_new (10);
+	g_assert_cmpint (array->len, ==, 10);
+
+	/* make sure we get the correct array sum */
+	value = gpm_array_float_sum (array);
+	g_assert_cmpfloat (value, ==, 0.0f);
+
+	/* remove outliers */
+	gpm_array_float_set (array, 0, 30.0);
+	gpm_array_float_set (array, 1, 29.0);
+	gpm_array_float_set (array, 2, 31.0);
+	gpm_array_float_set (array, 3, 33.0);
+	gpm_array_float_set (array, 4, 100.0);
+	gpm_array_float_set (array, 5, 27.0);
+	gpm_array_float_set (array, 6, 30.0);
+	gpm_array_float_set (array, 7, 29.0);
+	gpm_array_float_set (array, 8, 31.0);
+	gpm_array_float_set (array, 9, 30.0);
+	kernel = gpm_array_float_remove_outliers (array, 3, 10.0);
+	g_assert (kernel != NULL);
+	g_assert_cmpint (kernel->len, ==, 10);
+	gpm_array_float_print (array);
+	gpm_array_float_print (kernel);
+
+	/* make sure we removed the outliers */
+	value = gpm_array_float_sum (kernel);
+	g_assert_cmpfloat (fabs(value - 30*10), <, 1.0f);
+	gpm_array_float_free (kernel);
+
+	/* remove outliers step */
+	gpm_array_float_set (array, 0, 0.0);
+	gpm_array_float_set (array, 1, 0.0);
+	gpm_array_float_set (array, 2, 0.0);
+	gpm_array_float_set (array, 3, 0.0);
+	gpm_array_float_set (array, 4, 0.0);
+	gpm_array_float_set (array, 5, 0.0);
+	gpm_array_float_set (array, 6, 0.0);
+	gpm_array_float_set (array, 7, 10.0);
+	gpm_array_float_set (array, 8, 20.0);
+	gpm_array_float_set (array, 9, 50.0);
+	kernel = gpm_array_float_remove_outliers (array, 3, 20.0);
+	g_assert (kernel != NULL);
+	g_assert_cmpint (kernel->len, ==, 10);
+	gpm_array_float_print (array);
+	gpm_array_float_print (kernel);
+
+	/* make sure we removed the outliers */
+	value = gpm_array_float_sum (kernel);
+	g_assert_cmpfloat (fabs(value - 80), <, 1.0f);
+	gpm_array_float_free (kernel);
+
+	/* get gaussian 0.0, sigma 1.1 */
+	value = gpm_array_float_guassian_value (0.0, 1.1);
+	g_assert_cmpfloat (fabs (value - 0.36267), <, 0.0001f);
+
+	/* get gaussian 0.5, sigma 1.1 */
+	value = gpm_array_float_guassian_value (0.5, 1.1);
+	g_assert_cmpfloat (fabs (value - 0.32708), <, 0.0001f);
+
+	/* get gaussian 1.0, sigma 1.1 */
+	value = gpm_array_float_guassian_value (1.0, 1.1);
+	g_assert_cmpfloat (fabs (value - 0.23991), <, 0.0001f);
+
+	/* get gaussian 0.5, sigma 4.5 */
+	value = gpm_array_float_guassian_value (0.5, 4.5);
+	g_assert_cmpfloat (fabs (value - 0.088108), <, 0.0001f);
+
+	size = 5;
+	sigma = 1.1;
+	/* get inprecise gaussian array */
+	kernel = gpm_array_float_compute_gaussian (size, sigma);
+	g_assert (kernel == NULL);
+
+	size = 9;
+	sigma = 1.1;
+	/* get gaussian-9 array */
+	kernel = gpm_array_float_compute_gaussian (size, sigma);
+	g_assert (kernel != NULL);
+	g_assert_cmpint (kernel->len, ==, size);
+	gpm_array_float_print (kernel);
+
+	/* make sure we get an accurate gaussian */
+	value = gpm_array_float_sum (kernel);
+	g_assert_cmpfloat (fabs(value - 1.0), <, 0.01f);
+
+	/* make sure we get get and set */
+	gpm_array_float_set (array, 4, 100.0);
+	value = gpm_array_float_get (array, 4);
+	g_assert_cmpfloat (value, ==, 100.0f);
+	gpm_array_float_print (array);
+
+	/* make sure we get the correct array sum (2) */
+	gpm_array_float_set (array, 0, 20.0);
+	gpm_array_float_set (array, 1, 44.0);
+	gpm_array_float_set (array, 2, 45.0);
+	gpm_array_float_set (array, 3, 89.0);
+	gpm_array_float_set (array, 4, 100.0);
+	gpm_array_float_set (array, 5, 12.0);
+	gpm_array_float_set (array, 6, 76.0);
+	gpm_array_float_set (array, 7, 78.0);
+	gpm_array_float_set (array, 8, 1.20);
+	gpm_array_float_set (array, 9, 3.0);
+	value = gpm_array_float_sum (array);
+	g_assert_cmpfloat (fabs (value - 468.2), <, 0.0001f);
+
+	/* test convolving with kernel #1 */
+	gpm_array_float_set (array, 0, 0.0);
+	gpm_array_float_set (array, 1, 0.0);
+	gpm_array_float_set (array, 2, 0.0);
+	gpm_array_float_set (array, 3, 0.0);
+	gpm_array_float_set (array, 4, 100.0);
+	gpm_array_float_set (array, 5, 0.0);
+	gpm_array_float_set (array, 6, 0.0);
+	gpm_array_float_set (array, 7, 0.0);
+	gpm_array_float_set (array, 8, 0.0);
+	gpm_array_float_set (array, 9, 0.0);
+	result = gpm_array_float_convolve (array, kernel);
+	g_assert (result != NULL);
+	g_assert_cmpint (result->len, ==, 10);
+	gpm_array_float_print (result);
+
+	/* make sure we get the correct array sum of convolve #1 */
+	value = gpm_array_float_sum (result);
+	g_assert_cmpfloat (fabs(value - 100.0), <, 5.0);
+	gpm_array_float_free (result);
+
+	/* test convolving with kernel #2 */
+	gpm_array_float_set (array, 0, 100.0);
+	gpm_array_float_set (array, 1, 0.0);
+	gpm_array_float_set (array, 2, 0.0);
+	gpm_array_float_set (array, 3, 0.0);
+	gpm_array_float_set (array, 4, 0.0);
+	gpm_array_float_set (array, 5, 0.0);
+	gpm_array_float_set (array, 6, 0.0);
+	gpm_array_float_set (array, 7, 0.0);
+	gpm_array_float_set (array, 8, 0.0);
+	gpm_array_float_set (array, 9, 0.0);
+	result = gpm_array_float_convolve (array, kernel);
+	g_assert (result != NULL);
+	g_assert_cmpint (result->len, ==, 10);
+	gpm_array_float_print (array);
+	gpm_array_float_print (result);
+
+	/* make sure we get the correct array sum of convolve #2 */
+	value = gpm_array_float_sum (result);
+	g_assert_cmpfloat (fabs(value - 100.0), <, 10.0f);
+	gpm_array_float_free (result);
+
+	/* test convolving with kernel #3 */
+	gpm_array_float_set (array, 0, 0.0);
+	gpm_array_float_set (array, 1, 0.0);
+	gpm_array_float_set (array, 2, 0.0);
+	gpm_array_float_set (array, 3, 0.0);
+	gpm_array_float_set (array, 4, 0.0);
+	gpm_array_float_set (array, 5, 0.0);
+	gpm_array_float_set (array, 6, 0.0);
+	gpm_array_float_set (array, 7, 0.0);
+	gpm_array_float_set (array, 8, 0.0);
+	gpm_array_float_set (array, 9, 100.0);
+	result = gpm_array_float_convolve (array, kernel);
+	g_assert (result != NULL);
+	g_assert_cmpint (result->len, ==, 10);
+	gpm_array_float_print (array);
+	gpm_array_float_print (result);
+
+	/* make sure we get the correct array sum of convolve #3 */
+	value = gpm_array_float_sum (result);
+	g_assert_cmpfloat (fabs(value - 100.0), <, 10.0f);
+	gpm_array_float_free (result);
+
+	/* test convolving with kernel #4 */
+	gpm_array_float_set (array, 0, 10.0);
+	gpm_array_float_set (array, 1, 10.0);
+	gpm_array_float_set (array, 2, 10.0);
+	gpm_array_float_set (array, 3, 10.0);
+	gpm_array_float_set (array, 4, 10.0);
+	gpm_array_float_set (array, 5, 10.0);
+	gpm_array_float_set (array, 6, 10.0);
+	gpm_array_float_set (array, 7, 10.0);
+	gpm_array_float_set (array, 8, 10.0);
+	gpm_array_float_set (array, 9, 10.0);
+	result = gpm_array_float_convolve (array, kernel);
+	g_assert (result != NULL);
+	g_assert_cmpint (result->len, ==, 10);
+	gpm_array_float_print (array);
+	gpm_array_float_print (result);
+
+	/* make sure we get the correct array sum of convolve #4 */
+	value = gpm_array_float_sum (result);
+	g_assert_cmpfloat (fabs(value - 100.0), <, 1.0f);
+
+	/* test convolving with kernel #5 */
+	gpm_array_float_set (array, 0, 10.0);
+	gpm_array_float_set (array, 1, 10.0);
+	gpm_array_float_set (array, 2, 10.0);
+	gpm_array_float_set (array, 3, 10.0);
+	gpm_array_float_set (array, 4, 0.0);
+	gpm_array_float_set (array, 5, 10.0);
+	gpm_array_float_set (array, 6, 10.0);
+	gpm_array_float_set (array, 7, 10.0);
+	gpm_array_float_set (array, 8, 10.0);
+	gpm_array_float_set (array, 9, 10.0);
+	result = gpm_array_float_convolve (array, kernel);
+	g_assert (result != NULL);
+	g_assert_cmpint (result->len, ==, 10);
+	gpm_array_float_print (array);
+	gpm_array_float_print (result);
 
-/* prototypes */
-void egg_precision_test (EggTest *test);
-void egg_discrete_test (EggTest *test);
-void egg_color_test (EggTest *test);
-void egg_array_float_test (EggTest *test);
-void egg_idletime_test (EggTest *test);
-
-void gpm_common_test (EggTest *test);
-void gpm_idle_test (EggTest *test);
-void gpm_phone_test (EggTest *test);
-void gpm_dpms_test (EggTest *test);
-void gpm_graph_widget_test (EggTest *test);
-void gpm_proxy_test (EggTest *test);
-void gpm_hal_manager_test (EggTest *test);
-void gpm_device_test (EggTest *test);
-void gpm_device_teststore (EggTest *test);
+	/* make sure we get the correct array sum of convolve #5 */
+	value = gpm_array_float_sum (result);
+	g_assert_cmpfloat (fabs(value - 90.0), <, 1.0f);
+
+	/* integration down */
+	gpm_array_float_set (array, 0, 0.0);
+	gpm_array_float_set (array, 1, 1.0);
+	gpm_array_float_set (array, 2, 2.0);
+	gpm_array_float_set (array, 3, 3.0);
+	gpm_array_float_set (array, 4, 4.0);
+	gpm_array_float_set (array, 5, 5.0);
+	gpm_array_float_set (array, 6, 6.0);
+	gpm_array_float_set (array, 7, 7.0);
+	gpm_array_float_set (array, 8, 8.0);
+	gpm_array_float_set (array, 9, 9.0);
+	size = gpm_array_float_compute_integral (array, 0, 4);
+	g_assert_cmpint (size, ==, 0+1+2+3+4);
+
+	/* integration up */
+	size = gpm_array_float_compute_integral (array, 5, 9);
+	g_assert_cmpint (size, ==, 5+6+7+8+9);
+
+	/* integration all */
+	size = gpm_array_float_compute_integral (array, 0, 9);
+	g_assert_cmpint (size, ==, 0+1+2+3+4+5+6+7+8+9);
+
+	/* average */
+	gpm_array_float_set (array, 0, 0.0);
+	gpm_array_float_set (array, 1, 1.0);
+	gpm_array_float_set (array, 2, 2.0);
+	gpm_array_float_set (array, 3, 3.0);
+	gpm_array_float_set (array, 4, 4.0);
+	gpm_array_float_set (array, 5, 5.0);
+	gpm_array_float_set (array, 6, 6.0);
+	gpm_array_float_set (array, 7, 7.0);
+	gpm_array_float_set (array, 8, 8.0);
+	gpm_array_float_set (array, 9, 9.0);
+	value = gpm_array_float_get_average (array);
+	g_assert_cmpfloat (value, ==, 4.5);
+
+	gpm_array_float_free (result);
+	gpm_array_float_free (array);
+	gpm_array_float_free (kernel);
+}
+
+
+static void
+gpm_test_idletime_wait (guint time_ms)
+{
+	GTimer *ltimer = g_timer_new ();
+	gfloat goal = time_ms / (gfloat) 1000.0f;
+	do {
+		g_main_context_iteration (NULL, FALSE);
+	} while (g_timer_elapsed (ltimer, NULL) < goal);
+	g_timer_destroy (ltimer);
+}
+
+static guint last_alarm = 0;
+static guint event_time;
+GTimer *timer;
+
+static void
+gpm_alarm_expired_cb (GpmIdletime *idletime, guint alarm_id, gpointer data)
+{
+	last_alarm = alarm_id;
+	event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
+//	g_print ("[evt %i in %ims]\n", alarm_id, event_time);
+}
+
+static void
+wait_until_alarm (void)
+{
+	g_print ("*****************************\n");
+	g_print ("*** DO NOT MOVE THE MOUSE ***\n");
+	g_print ("*****************************\n");
+	while (last_alarm == 0)
+		g_main_context_iteration (NULL, FALSE);
+}
+
+static void
+wait_until_reset (void)
+{
+	if (last_alarm == 0)
+		return;
+	g_print ("*****************************\n");
+	g_print ("***     MOVE THE MOUSE    ***\n");
+	g_print ("*****************************\n");
+	while (last_alarm != 0)
+		g_main_context_iteration (NULL, FALSE);
+	gpm_test_idletime_wait (1000);
+}
+
+static void
+gpm_test_idletime_func (void)
+{
+	GpmIdletime *idletime;
+	gboolean ret;
+	guint i;
+
+	timer = g_timer_new ();
+	gdk_init (NULL, NULL);
+
+	/* warn */
+
+	g_timer_start (timer);
+	/* check to see if delay works as expected */
+	gpm_test_idletime_wait (2000);
+	event_time = g_timer_elapsed (timer, NULL) * (gfloat) 1000.0f;
+	g_assert_cmpfloat (event_time, >, 1800);
+	g_assert_cmpfloat (event_time, <, 2200);
+
+	/* make sure we get a non null device */
+	idletime = gpm_idletime_new ();
+	g_assert (idletime != NULL);
+	g_signal_connect (idletime, "alarm-expired",
+			  G_CALLBACK (gpm_alarm_expired_cb), NULL);
+
+	/* check if we are alarm zero with no alarms */
+	g_assert_cmpint (last_alarm, ==, 0);
+
+	/* check if we can set an reset alarm */
+	ret = gpm_idletime_alarm_set (idletime, 0, 100);
+	g_assert (!ret);
+
+	/* check if we can set an alarm timeout of zero */
+	ret = gpm_idletime_alarm_set (idletime, 999, 0);
+	g_assert (!ret);
+
+	g_timer_start (timer);
+	/* check if we can set an alarm */
+	ret = gpm_idletime_alarm_set (idletime, 101, 5000);
+	g_assert (ret);
+
+	gpm_idletime_alarm_set (idletime, 101, 5000);
+	wait_until_alarm ();
+
+	/* loop this two times */
+	for (i=0; i<2; i++) {
+		/* just let it time out, and wait for human input */
+		wait_until_reset ();
+		g_timer_start (timer);
+
+			g_timer_start (timer);
+		/* check if we can set an alarm */
+		ret = gpm_idletime_alarm_set (idletime, 101, 5000);
+		g_assert (ret);
+
+		/* wait for alarm to go off */
+		wait_until_alarm ();
+		g_timer_start (timer);
+
+		/* check if correct alarm has gone off */
+		g_assert_cmpint (last_alarm, ==, 101);
+
+		/* check if alarm has gone off in correct time */
+		g_assert_cmpint (event_time, >, 3000);
+		g_assert_cmpint (event_time, <, 6000);
+	}
+
+	/* just let it time out, and wait for human input */
+	wait_until_reset ();
+	g_timer_start (timer);
+
+	g_timer_start (timer);
+	/* check if we can set an existing alarm */
+	ret = gpm_idletime_alarm_set (idletime, 101, 10000);
+	g_assert (ret);
+
+	/* wait for alarm to go off */
+	wait_until_alarm ();
+	g_timer_start (timer);
+
+	/* check if alarm has gone off in the old time */
+	g_assert_cmpint (event_time, >, 5000);
+
+	/* check if we can remove an invalid alarm */
+	ret = gpm_idletime_alarm_remove (idletime, 202);
+	g_assert (!ret);
+
+	/* check if we can remove an valid alarm */
+	ret = gpm_idletime_alarm_remove (idletime, 101);
+	g_assert (ret);
+
+	g_timer_destroy (timer);
+	g_object_unref (idletime);
+}
 
 int
 main (int argc, char **argv)
 {
-	EggTest *test;
-
 	g_type_init ();
-	test = egg_test_init ();
-	egg_debug_init (TRUE);
+	g_test_init (&argc, &argv, NULL);
 
 	/* needed for DPMS checks */
 	gtk_init (&argc, &argv);
 
 	/* tests go here */
-	egg_precision_test (test);
-	egg_discrete_test (test);
-	egg_color_test (test);
-	egg_array_float_test (test);
-//	egg_idletime_test (test);
-
-	gpm_common_test (test);
-	gpm_idle_test (test);
-	gpm_phone_test (test);
-//	gpm_dpms_test (test);
-//	gpm_graph_widget_test (test);
-//	gpm_screensaver_test (test);
-
-#if 0
-	gpm_proxy_test (test);
-	gpm_hal_manager_test (test);
-	gpm_device_test (test);
-	gpm_device_teststore (test);
-#endif
+	g_test_add_func ("/power/precision", gpm_test_precision_func);
+	g_test_add_func ("/power/discrete", gpm_test_discrete_func);
+	g_test_add_func ("/power/color", gpm_test_color_func);
+	g_test_add_func ("/power/array_float", gpm_test_array_float_func);
+	g_test_add_func ("/power/idle", gpm_test_idle_func);
+	g_test_add_func ("/power/idletime", gpm_test_idletime_func);
+	g_test_add_func ("/power/dpms", gpm_test_dpms_func);
+	g_test_add_func ("/power/phone", gpm_test_phone_func);
+//	g_test_add_func ("/power/graph-widget", gpm_graph_widget_test);
+	g_test_add_func ("/power/screensaver", gpm_test_screensaver_func);
 
-	return (egg_test_finish (test));
+	return g_test_run ();
 }
 
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index 37e13d7..2f7edd2 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -32,9 +32,8 @@
 #include <libupower-glib/upower.h>
 
 #include "egg-debug.h"
-#include "egg-color.h"
-#include "egg-array-float.h"
 
+#include "gpm-array-float.h"
 #include "gpm-common.h"
 #include "gpm-stock-icons.h"
 #include "gpm-upower.h"
@@ -235,24 +234,24 @@ gpm_stats_update_smooth_data (GPtrArray *list)
 	GpmPointObj *point;
 	GpmPointObj *point_new;
 	GPtrArray *new;
-	EggArrayFloat *raw;
-	EggArrayFloat *convolved;
-	EggArrayFloat *outliers;
-	EggArrayFloat *gaussian = NULL;
+	GpmArrayFloat *raw;
+	GpmArrayFloat *convolved;
+	GpmArrayFloat *outliers;
+	GpmArrayFloat *gaussian = NULL;
 
-	/* convert the y data to a EggArrayFloat array */
-	raw = egg_array_float_new (list->len);
+	/* convert the y data to a GpmArrayFloat array */
+	raw = gpm_array_float_new (list->len);
 	for (i=0; i<list->len; i++) {
 		point = (GpmPointObj *) g_ptr_array_index (list, i);
-		egg_array_float_set (raw, i, point->y);
+		gpm_array_float_set (raw, i, point->y);
 	}
 
 	/* remove any outliers */
-	outliers = egg_array_float_remove_outliers (raw, 3, 0.1);
+	outliers = gpm_array_float_remove_outliers (raw, 3, 0.1);
 
 	/* convolve with gaussian */
-	gaussian = egg_array_float_compute_gaussian (15, sigma_smoothing);
-	convolved = egg_array_float_convolve (outliers, gaussian);
+	gaussian = gpm_array_float_compute_gaussian (15, sigma_smoothing);
+	convolved = gpm_array_float_convolve (outliers, gaussian);
 
 	/* add the smoothed data back into a new array */
 	new = g_ptr_array_new_with_free_func ((GDestroyNotify) gpm_point_obj_free);
@@ -261,15 +260,15 @@ gpm_stats_update_smooth_data (GPtrArray *list)
 		point_new = g_new0 (GpmPointObj, 1);
 		point_new->color = point->color;
 		point_new->x = point->x;
-		point_new->y = egg_array_float_get (convolved, i);
+		point_new->y = gpm_array_float_get (convolved, i);
 		g_ptr_array_add (new, point_new);
 	}
 
 	/* free data */
-	egg_array_float_free (gaussian);
-	egg_array_float_free (raw);
-	egg_array_float_free (convolved);
-	egg_array_float_free (outliers);
+	gpm_array_float_free (gaussian);
+	gpm_array_float_free (raw);
+	gpm_array_float_free (convolved);
+	gpm_array_float_free (outliers);
 
 	return new;
 }
@@ -620,18 +619,18 @@ gpm_stats_update_info_page_history (UpDevice *device)
 		point->x = (gint32) up_history_item_get_time (item) - offset;
 		point->y = up_history_item_get_value (item);
 		if (up_history_item_get_state (item) == UP_DEVICE_STATE_CHARGING)
-			point->color = egg_color_from_rgb (255, 0, 0);
+			point->color = gpm_color_from_rgb (255, 0, 0);
 		else if (up_history_item_get_state (item) == UP_DEVICE_STATE_DISCHARGING)
-			point->color = egg_color_from_rgb (0, 0, 255);
+			point->color = gpm_color_from_rgb (0, 0, 255);
 		else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_CHARGE)
-			point->color = egg_color_from_rgb (200, 0, 0);
+			point->color = gpm_color_from_rgb (200, 0, 0);
 		else if (up_history_item_get_state (item) == UP_DEVICE_STATE_PENDING_DISCHARGE)
-			point->color = egg_color_from_rgb (0, 0, 200);
+			point->color = gpm_color_from_rgb (0, 0, 200);
 		else {
 			if (g_strcmp0 (history_type, GPM_HISTORY_RATE_VALUE) == 0)
-				point->color = egg_color_from_rgb (255, 255, 255);
+				point->color = gpm_color_from_rgb (255, 255, 255);
 			else
-				point->color = egg_color_from_rgb (0, 255, 0);
+				point->color = gpm_color_from_rgb (0, 255, 0);
 		}
 		g_ptr_array_add (new, point);
 	}
@@ -723,7 +722,7 @@ gpm_stats_update_info_page_stats (UpDevice *device)
 			point->y = up_stats_item_get_value (item);
 		else
 			point->y = up_stats_item_get_accuracy (item);
-		point->color = egg_color_from_rgb (255, 0, 0);
+		point->color = gpm_color_from_rgb (255, 0, 0);
 		g_ptr_array_add (new, point);
 	}
 
diff --git a/src/gpm-upower.c b/src/gpm-upower.c
index d5556f5..e31e90d 100644
--- a/src/gpm-upower.c
+++ b/src/gpm-upower.c
@@ -25,7 +25,6 @@
 #include <libupower-glib/upower.h>
 
 #include "egg-debug.h"
-#include "egg-precision.h"
 
 #include "gpm-upower.h"
 #include "gpm-common.h"
@@ -256,8 +255,8 @@ gpm_upower_get_device_summary (UpDevice *device)
 	}
 
 	/* precalculate so we don't get Unknown time remaining */
-	time_to_full_round = egg_precision_round_down (time_to_full, GPM_UP_TIME_PRECISION);
-	time_to_empty_round = egg_precision_round_down (time_to_empty, GPM_UP_TIME_PRECISION);
+	time_to_full_round = gpm_precision_round_down (time_to_full, GPM_UP_TIME_PRECISION);
+	time_to_empty_round = gpm_precision_round_down (time_to_empty, GPM_UP_TIME_PRECISION);
 
 	/* we always display "Laptop battery 16 minutes remaining" as we need to clarify what device we are refering to */
 	if (state == UP_DEVICE_STATE_FULLY_CHARGED) {



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