[gnome-color-manager] Set the brightness to 100% on internal LCD panels before we generate a output profile



commit 2483fe7fbb827a85bf7bec695c3b545fde080883
Author: Richard Hughes <richard hughsie com>
Date:   Wed Nov 4 09:59:46 2009 +0000

    Set the brightness to 100% on internal LCD panels before we generate a output profile

 src/Makefile.am      |    2 +
 src/gcm-brightness.c |  243 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-brightness.h |   69 ++++++++++++++
 src/gcm-prefs.c      |   42 +++++++++-
 4 files changed, 355 insertions(+), 1 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 235ed20..2dac665 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -81,6 +81,8 @@ gcm_import_CFLAGS =					\
 gcm_prefs_SOURCES =					\
 	gcm-calibrate.c					\
 	gcm-calibrate.h					\
+	gcm-brightness.c				\
+	gcm-brightness.h				\
 	gcm-prefs.c
 
 gcm_prefs_LDADD =					\
diff --git a/src/gcm-brightness.c b/src/gcm-brightness.c
new file mode 100644
index 0000000..0298b34
--- /dev/null
+++ b/src/gcm-brightness.c
@@ -0,0 +1,243 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 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 brightness.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:gcm-brightness
+ * @short_description: Object to allow setting the brightness using gnome-power-manager
+ *
+ * This object sets the laptop panel brightness using gnome-power-manager.
+ */
+
+#include "config.h"
+
+#include <glib-object.h>
+//#include <math.h>
+//#include <string.h>
+//#include <gio/gio.h>
+//#include <stdlib.h>
+#include <dbus/dbus-glib.h>
+
+#include "gcm-brightness.h"
+
+#include "egg-debug.h"
+
+static void     gcm_brightness_finalize	(GObject     *object);
+
+#define GCM_BRIGHTNESS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_BRIGHTNESS, GcmBrightnessPrivate))
+
+/**
+ * GcmBrightnessPrivate:
+ *
+ * Private #GcmBrightness data
+ **/
+struct _GcmBrightnessPrivate
+{
+	guint				 percentage;
+	DBusGProxy			*proxy;
+	DBusGConnection			*connection;
+};
+
+enum {
+	PROP_0,
+	PROP_PERCENTAGE,
+	PROP_LAST
+};
+
+G_DEFINE_TYPE (GcmBrightness, gcm_brightness, G_TYPE_OBJECT)
+
+#define	GPM_DBUS_SERVICE		"org.gnome.PowerManager"
+#define	GPM_DBUS_INTERFACE_BACKLIGHT	"org.gnome.PowerManager.Backlight"
+#define	GPM_DBUS_PATH_BACKLIGHT		"/org/gnome/PowerManager/Backlight"
+
+/**
+ * gcm_brightness_set_percentage:
+ **/
+gboolean
+gcm_brightness_set_percentage (GcmBrightness *brightness, guint percentage, GError **error)
+{
+	GcmBrightnessPrivate *priv = brightness->priv;
+	gboolean ret = FALSE;
+
+	g_return_val_if_fail (GCM_IS_BRIGHTNESS (brightness), FALSE);
+	g_return_val_if_fail (percentage <= 100, FALSE);
+
+	/* are we connected */
+	if (priv->proxy == NULL) {
+		if (error != NULL)
+			*error = g_error_new (1, 0, "not connected to gnome-power-manager");
+		goto out;
+	}
+
+	/* set the brightness */
+	ret = dbus_g_proxy_call (priv->proxy, "SetBrightness", error,
+				 G_TYPE_UINT, percentage,
+				 G_TYPE_INVALID,
+				 G_TYPE_INVALID);
+	if (!ret)
+		goto out;
+out:
+	return ret;
+}
+
+/**
+ * gcm_brightness_get_percentage:
+ **/
+gboolean
+gcm_brightness_get_percentage (GcmBrightness *brightness, guint *percentage, GError **error)
+{
+	GcmBrightnessPrivate *priv = brightness->priv;
+	gboolean ret = FALSE;
+
+	g_return_val_if_fail (GCM_IS_BRIGHTNESS (brightness), FALSE);
+
+	/* are we connected */
+	if (priv->proxy == NULL) {
+		if (error != NULL)
+			*error = g_error_new (1, 0, "not connected to gnome-power-manager");
+		goto out;
+	}
+
+	/* get the brightness */
+	ret = dbus_g_proxy_call (priv->proxy, "GetBrightness", error,
+				 G_TYPE_INVALID,
+				 G_TYPE_UINT, &priv->percentage,
+				 G_TYPE_INVALID);
+	if (!ret)
+		goto out;
+
+	/* copy if set */
+	if (percentage != NULL)
+		*percentage = priv->percentage;
+out:
+	return ret;
+}
+
+/**
+ * gcm_brightness_get_property:
+ **/
+static void
+gcm_brightness_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+	GcmBrightness *brightness = GCM_BRIGHTNESS (object);
+	GcmBrightnessPrivate *priv = brightness->priv;
+
+	switch (prop_id) {
+	case PROP_PERCENTAGE:
+		g_value_set_uint (value, priv->percentage);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+/**
+ * gcm_brightness_set_property:
+ **/
+static void
+gcm_brightness_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+	switch (prop_id) {
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+/**
+ * gcm_brightness_class_init:
+ **/
+static void
+gcm_brightness_class_init (GcmBrightnessClass *klass)
+{
+	GParamSpec *pspec;
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	object_class->finalize = gcm_brightness_finalize;
+	object_class->get_property = gcm_brightness_get_property;
+	object_class->set_property = gcm_brightness_set_property;
+
+	/**
+	 * GcmBrightness:percentage:
+	 */
+	pspec = g_param_spec_uint ("percentage", NULL, NULL,
+				   0, 100, 0,
+				   G_PARAM_READABLE);
+	g_object_class_install_property (object_class, PROP_PERCENTAGE, pspec);
+
+	g_type_class_add_private (klass, sizeof (GcmBrightnessPrivate));
+}
+
+/**
+ * gcm_brightness_init:
+ **/
+static void
+gcm_brightness_init (GcmBrightness *brightness)
+{
+	GError *error = NULL;
+
+	brightness->priv = GCM_BRIGHTNESS_GET_PRIVATE (brightness);
+	brightness->priv->percentage = 0;
+
+	/* get a session connection */
+	brightness->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+	if (brightness->priv->connection == NULL) {
+		egg_warning ("Could not connect to DBUS daemon: %s", error->message);
+		g_error_free (error);
+		return;
+	}
+
+	/* get a proxy to gnome-power-manager */
+	brightness->priv->proxy = dbus_g_proxy_new_for_name_owner (brightness->priv->connection,
+								   GPM_DBUS_SERVICE, GPM_DBUS_PATH_BACKLIGHT, GPM_DBUS_INTERFACE_BACKLIGHT, &error);
+	if (brightness->priv->proxy == NULL) {
+		egg_warning ("Cannot connect, maybe gnome-power-manager is not running: %s\n", error->message);
+		g_error_free (error);
+	}
+}
+
+/**
+ * gcm_brightness_finalize:
+ **/
+static void
+gcm_brightness_finalize (GObject *object)
+{
+	GcmBrightness *brightness = GCM_BRIGHTNESS (object);
+	GcmBrightnessPrivate *priv = brightness->priv;
+
+	if (priv->proxy != NULL)
+		g_object_unref (priv->proxy);
+
+	G_OBJECT_CLASS (gcm_brightness_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_brightness_new:
+ *
+ * Return value: a new GcmBrightness object.
+ **/
+GcmBrightness *
+gcm_brightness_new (void)
+{
+	GcmBrightness *brightness;
+	brightness = g_object_new (GCM_TYPE_BRIGHTNESS, NULL);
+	return GCM_BRIGHTNESS (brightness);
+}
+
diff --git a/src/gcm-brightness.h b/src/gcm-brightness.h
new file mode 100644
index 0000000..0c98236
--- /dev/null
+++ b/src/gcm-brightness.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 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 brightness.
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GCM_BRIGHTNESS_H
+#define __GCM_BRIGHTNESS_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_BRIGHTNESS		(gcm_brightness_get_type ())
+#define GCM_BRIGHTNESS(o)		(G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_BRIGHTNESS, GcmBrightness))
+#define GCM_BRIGHTNESS_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_BRIGHTNESS, GcmBrightnessClass))
+#define GCM_IS_BRIGHTNESS(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_BRIGHTNESS))
+#define GCM_IS_BRIGHTNESS_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_BRIGHTNESS))
+#define GCM_BRIGHTNESS_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_BRIGHTNESS, GcmBrightnessClass))
+
+typedef struct _GcmBrightnessPrivate	GcmBrightnessPrivate;
+typedef struct _GcmBrightness		GcmBrightness;
+typedef struct _GcmBrightnessClass	GcmBrightnessClass;
+
+struct _GcmBrightness
+{
+	 GObject		 parent;
+	 GcmBrightnessPrivate	*priv;
+};
+
+struct _GcmBrightnessClass
+{
+	GObjectClass	parent_class;
+	/* padding for future expansion */
+	void (*_gcm_reserved1) (void);
+	void (*_gcm_reserved2) (void);
+	void (*_gcm_reserved3) (void);
+	void (*_gcm_reserved4) (void);
+	void (*_gcm_reserved5) (void);
+};
+
+GType		 gcm_brightness_get_type		(void);
+GcmBrightness	*gcm_brightness_new			(void);
+gboolean	 gcm_brightness_set_percentage		(GcmBrightness		*brightness,
+							 guint			 percentage,
+							 GError			**error);
+gboolean	 gcm_brightness_get_percentage		(GcmBrightness		*brightness,
+							 guint			*percentage,
+							 GError			**error);
+
+G_END_DECLS
+
+#endif /* __GCM_BRIGHTNESS_H */
+
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index f03c134..df3ed5b 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -31,6 +31,7 @@
 #include "gcm-utils.h"
 #include "gcm-profile.h"
 #include "gcm-calibrate.h"
+#include "gcm-brightness.h"
 
 static GtkBuilder *builder = NULL;
 static GtkListStore *list_store_devices = NULL;
@@ -84,6 +85,7 @@ static void
 gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 {
 	GcmCalibrate *calib = NULL;
+	GcmBrightness *brightness = NULL;
 	gboolean ret;
 	GError *error = NULL;
 	GtkWindow *window;
@@ -93,6 +95,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	gchar *filename = NULL;
 	gchar *destination = NULL;
 	guint i;
+	guint percentage = G_MAXUINT;
 
 	/* get the device */
 	output = gnome_rr_screen_get_output_by_id (rr_screen, current_device);
@@ -101,8 +104,9 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 		goto out;
 	}
 
-	/* create new calibration object */
+	/* create new calibration and brightness objects */
 	calib = gcm_calibrate_new ();
+	brightness = gcm_brightness_new ();
 
 	/* set the proper output name */
 	output_name = gnome_rr_output_get_name (output);
@@ -119,6 +123,28 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 		goto finish_calibrate;
 	}
 
+	/* if we are an internal LCD, we need to set the brightness to maximum */
+	ret = gcm_utils_output_is_lcd_internal (output_name);
+	if (ret) {
+		/* get the old brightness so we can restore state */
+		ret = gcm_brightness_get_percentage (brightness, &percentage, &error);
+		if (!ret) {
+			egg_warning ("failed to get brightness: %s", error->message);
+			g_error_free (error);
+			/* not fatal */
+			error = NULL;
+		}
+
+		/* set the new brightness */
+		ret = gcm_brightness_set_percentage (brightness, 100, &error);
+		if (!ret) {
+			egg_warning ("failed to set brightness: %s", error->message);
+			g_error_free (error);
+			/* not fatal */
+			error = NULL;
+		}
+	}
+
 	/* step 1 */
 	ret = gcm_calibrate_task (calib, GCM_CALIBRATE_TASK_NEUTRALISE, &error);
 	if (!ret) {
@@ -152,6 +178,18 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
 	}
 
 finish_calibrate:
+	/* restore brightness */
+	if (percentage != G_MAXUINT) {
+		/* set the new brightness */
+		ret = gcm_brightness_set_percentage (brightness, percentage, &error);
+		if (!ret) {
+			egg_warning ("failed to restore brightness: %s", error->message);
+			g_error_free (error);
+			/* not fatal */
+			error = NULL;
+		}
+	}
+
 	/* step 4 */
 	filename = gcm_calibrate_finish (calib, &error);
 	if (filename == NULL) {
@@ -195,6 +233,8 @@ finish_calibrate:
 out:
 	if (calib != NULL)
 		g_object_unref (calib);
+	if (brightness != NULL)
+		g_object_unref (brightness);
 
 	/* need to set the gamma back to the default after calibration */
 	ret = gcm_utils_set_output_gamma (output, &error);



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