[gnome-settings-daemon] color: Set the internal panel brightness if specified in the profile



commit c8d0be6b86762a92e5546d7feece08cfb1cac065
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jan 28 22:36:25 2012 +0000

    color: Set the internal panel brightness if specified in the profile
    
    Hardcore color geeks know that a color profile is only valid for the same
    display luminance that was used during the calibration. If a user has gone to
    the trouble of adding the extra metadata, then assume they want this specific
    panel brightness set for a given profile.
    
    This should keep the studios happy, as different luminance values should be used
    by different industry defined spaces. When we know the display luminance for
    the display percentage, we can ask the profile vendors to include this in thier
    profiles as extra metadata. Until then, we can use the panel-specific percentage
    values to be used as an effective workaround.
    
    NOTE: We only support changing the internal panel, as this is all that the
    gnome-settings-daemon interface controls. Even if the DBus interface was
    cleverer, we've got no way of telling X to adjust the brightness of external
    panels just yet.

 plugins/color/gsd-color-manager.c |   65 +++++++++++++++++++++++++++++++++++++
 1 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/plugins/color/gsd-color-manager.c b/plugins/color/gsd-color-manager.c
index 89f2fb8..efb0add 100644
--- a/plugins/color/gsd-color-manager.c
+++ b/plugins/color/gsd-color-manager.c
@@ -990,16 +990,69 @@ gcm_session_use_output_profile_for_screen (GsdColorManager *manager,
         return gnome_rr_output_get_id (outputs[0]) == gnome_rr_output_get_id (output);
 }
 
+/* TODO: remove when we can dep on a released version of colord */
+#ifndef CD_PROFILE_METADATA_SCREEN_BRIGHTNESS
+#define CD_PROFILE_METADATA_SCREEN_BRIGHTNESS		"SCREEN_brightness"
+#endif
+
+#define GSD_DBUS_SERVICE		"org.gnome.SettingsDaemon"
+#define GSD_DBUS_INTERFACE_POWER_SCREEN	"org.gnome.SettingsDaemon.Power.Screen"
+#define GSD_DBUS_PATH_POWER		"/org/gnome/SettingsDaemon/Power"
+
+static void
+gcm_session_set_output_percentage_cb (GObject *source_object,
+                                      GAsyncResult *res,
+                                      gpointer user_data)
+{
+        GDBusConnection *connection = G_DBUS_CONNECTION (source_object);
+        GError *error = NULL;
+        GVariant *retval;
+        retval = g_dbus_connection_call_finish (connection,
+                                                res,
+                                                &error);
+        if (retval == NULL) {
+                g_warning ("failed to set output brightness: %s",
+                           error->message);
+                g_error_free (error);
+                return;
+        }
+        g_variant_unref (retval);
+}
+
+static void
+gcm_session_set_output_percentage (guint percentage)
+{
+        GDBusConnection *connection;
+
+        /* get a ref to the existing bus connection */
+        connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+        if (connection == NULL)
+                return;
+        g_dbus_connection_call (connection,
+                                GSD_DBUS_SERVICE,
+                                GSD_DBUS_PATH_POWER,
+                                GSD_DBUS_INTERFACE_POWER_SCREEN,
+                                "SetPercentage",
+                                g_variant_new ("(u)", percentage),
+                                NULL,
+                                G_DBUS_CALL_FLAGS_NONE,
+                                -1, NULL,
+                                gcm_session_set_output_percentage_cb, NULL);
+        g_object_unref (connection);
+}
+
 static void
 gcm_session_device_assign_profile_connect_cb (GObject *object,
                                               GAsyncResult *res,
                                               gpointer user_data)
 {
         CdProfile *profile = CD_PROFILE (object);
+        const gchar *brightness_profile;
         const gchar *filename;
         gboolean ret;
         GError *error = NULL;
         GnomeRROutput *output;
+        guint brightness_percentage;
         GcmSessionAsyncHelper *helper = (GcmSessionAsyncHelper *) user_data;
         GsdColorManager *manager = GSD_COLOR_MANAGER (helper->manager);
 
@@ -1023,6 +1076,18 @@ gcm_session_device_assign_profile_connect_cb (GObject *object,
         if (output == NULL)
                 goto out;
 
+        /* if output is a laptop screen and the profile has a
+         * calibration brightness then set this new brightness */
+        brightness_profile = cd_profile_get_metadata_item (profile,
+                                                           CD_PROFILE_METADATA_SCREEN_BRIGHTNESS);
+        if (gnome_rr_output_is_laptop (output) &&
+            brightness_profile != NULL) {
+                /* the percentage is stored in the profile metadata as
+                 * a string, not ideal, but it's all we have... */
+                brightness_percentage = atoi (brightness_profile);
+                gcm_session_set_output_percentage (brightness_percentage);
+        }
+
         /* set the _ICC_PROFILE atom */
         ret = gcm_session_use_output_profile_for_screen (manager, output);
         if (ret) {



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