[gnome-color-manager] Conform to ICC Profiles in X Specification 0.3



commit 8e6b21862553ee50b7b63522d3b66a65db30dd71
Author: Richard Hughes <richard hughsie com>
Date:   Wed Feb 24 11:43:50 2010 +0000

    Conform to ICC Profiles in X Specification 0.3

 src/gcm-device-xrandr.c |   11 +++
 src/gcm-inspect.c       |   16 +++++-
 src/gcm-xserver.c       |  155 +++++++++++++++++++++++++++++++++++++++++++++++
 src/gcm-xserver.h       |   10 +++
 4 files changed, 191 insertions(+), 1 deletions(-)
---
diff --git a/src/gcm-device-xrandr.c b/src/gcm-device-xrandr.c
index fc99014..8d3d2b2 100644
--- a/src/gcm-device-xrandr.c
+++ b/src/gcm-device-xrandr.c
@@ -69,6 +69,8 @@ enum {
 
 G_DEFINE_TYPE (GcmDeviceXrandr, gcm_device_xrandr, GCM_TYPE_DEVICE)
 
+#define GCM_ICC_PROFILE_IN_X_VERSION_MAJOR	0
+#define GCM_ICC_PROFILE_IN_X_VERSION_MINOR	3
 
 /**
  * gcm_device_xrandr_get_output_name:
@@ -564,6 +566,9 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
 			ret = gcm_xserver_remove_root_window_profile (priv->xserver, error);
 			if (!ret)
 				goto out;
+			ret = gcm_xserver_remove_protocol_version (priv->xserver, error);
+			if (!ret)
+				goto out;
 		}
 	} else {
 		/* set the per-output and per screen profile atoms */
@@ -576,6 +581,12 @@ gcm_device_xrandr_apply (GcmDevice *device, GError **error)
 			ret = gcm_xserver_set_root_window_profile (priv->xserver, filename, error);
 			if (!ret)
 				goto out;
+			ret = gcm_xserver_set_protocol_version (priv->xserver,
+								GCM_ICC_PROFILE_IN_X_VERSION_MAJOR,
+								GCM_ICC_PROFILE_IN_X_VERSION_MINOR,
+								error);
+			if (!ret)
+				goto out;
 		}
 	}
 out:
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index 3f270f9..6634ecc 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -94,6 +94,8 @@ gcm_inspect_show_x11_atoms (void)
 	const gchar *output_name;
 	gchar *title;
 	GError *error = NULL;
+	guint major;
+	guint minor;
 
 	/* setup object to access X */
 	xserver = gcm_xserver_new ();
@@ -107,7 +109,19 @@ gcm_inspect_show_x11_atoms (void)
 		error = NULL;
 	} else {
 		/* TRANSLATORS: the root window of all the screens */
-		gcm_inspect_print_data_info (_("Root window profile (deprecated):"), data, length);
+		gcm_inspect_print_data_info (_("Root window profile:"), data, length);
+	}
+
+	/* get profile from XServer */
+	ret = gcm_xserver_get_protocol_version (xserver, &major, &minor, &error);
+	if (!ret) {
+		egg_warning ("failed to get XServer protocol version: %s", error->message);
+		g_error_free (error);
+		/* non-fatal */
+		error = NULL;
+	} else {
+		/* TRANSLATORS: the root window of all the screens */
+		g_print ("%s %i.%i\n", _("Root window protocol version:"), major, minor);
 	}
 
 	/* coldplug devices */
diff --git a/src/gcm-xserver.c b/src/gcm-xserver.c
index c895dc6..80c8d9e 100644
--- a/src/gcm-xserver.c
+++ b/src/gcm-xserver.c
@@ -220,6 +220,161 @@ out:
 }
 
 /**
+ * gcm_xserver_set_protocol_version:
+ * @xserver: a valid %GcmXserver instance
+ * @major: the major version
+ * @minor: the minor version
+ * @error: a %GError that is set in the result of an error, or %NULL
+ * Return value: %TRUE for success.
+ *
+ * Sets the ICC Profiles in X supported version to the XServer.
+ **/
+gboolean
+gcm_xserver_set_protocol_version (GcmXserver *xserver, guint major, guint minor, GError **error)
+{
+	gboolean ret = FALSE;
+	const gchar *atom_name;
+	gint rc;
+	Atom atom = None;
+	guint data;
+	GcmXserverPrivate *priv = xserver->priv;
+
+	g_return_val_if_fail (GCM_IS_XSERVER (xserver), FALSE);
+
+	/* get the atom name */
+	atom_name = "_ICC_PROFILE_IN_X_VERSION";
+	data = major * 100 + minor * 1;
+
+	/* get the value */
+	gdk_error_trap_push ();
+	atom = gdk_x11_get_xatom_by_name_for_display (priv->display_gdk, atom_name);
+	rc = XChangeProperty (priv->display, priv->window, atom, XA_CARDINAL, 8, PropModeReplace, (unsigned char*) &data, 1);
+	gdk_error_trap_pop ();
+
+	/* for some reason this fails with BadRequest, but actually sets the value */
+	if (rc == BadRequest)
+		rc = Success;
+
+	/* did the call fail */
+	if (rc != Success) {
+		g_set_error (error, 1, 0, "failed to set %s atom with rc %i", atom_name, rc);
+		goto out;
+	}
+
+	/* success */
+	ret = TRUE;
+out:
+	return ret;
+}
+
+/**
+ * gcm_xserver_remove_protocol_version:
+ * @xserver: a valid %GcmXserver instance
+ * @error: a %GError that is set in the result of an error, or %NULL
+ * Return value: %TRUE for success.
+ *
+ * Removes the ICC profile version data from the XServer.
+ **/
+gboolean
+gcm_xserver_remove_protocol_version (GcmXserver *xserver, GError **error)
+{
+	const gchar *atom_name;
+	Atom atom = None;
+	gint rc;
+	gboolean ret = TRUE;
+	GcmXserverPrivate *priv = xserver->priv;
+
+	g_return_val_if_fail (GCM_IS_XSERVER (xserver), FALSE);
+
+	egg_debug ("removing root window ICC profile atom");
+
+	/* get the atom name */
+	atom_name = "_ICC_PROFILE_IN_X_VERSION";
+
+	/* get the value */
+	gdk_error_trap_push ();
+	atom = gdk_x11_get_xatom_by_name_for_display (priv->display_gdk, atom_name);
+	rc = XDeleteProperty(priv->display, priv->window, atom);
+	gdk_error_trap_pop ();
+
+	/* this fails with BadRequest if the atom was not set */
+	if (rc == BadRequest)
+		rc = Success;
+
+	/* did the call fail */
+	if (rc != Success) {
+		ret = FALSE;
+		g_set_error (error, 1, 0, "failed to delete %s root window atom with rc %i", atom_name, rc);
+		goto out;
+	}
+out:
+	return ret;
+}
+
+/**
+ * gcm_xserver_get_protocol_version:
+ *
+ * @xserver: a valid %GcmXserver instance
+ * @major: the major version
+ * @minor: the minor version
+ * @error: a %GError that is set in the result of an error, or %NULL
+ * Return value: %TRUE for success.
+ *
+ * Gets the ICC profile data from the XServer.
+ **/
+gboolean
+gcm_xserver_get_protocol_version (GcmXserver *xserver, guint *major, guint *minor, GError **error)
+{
+	gboolean ret = FALSE;
+	const gchar *atom_name;
+	gchar *data_tmp;
+	gint format;
+	gint rc;
+	gulong bytes_after;
+	gulong nitems;
+	Atom atom = None;
+	Atom type;
+	GcmXserverPrivate *priv = xserver->priv;
+
+	g_return_val_if_fail (GCM_IS_XSERVER (xserver), FALSE);
+	g_return_val_if_fail (major != NULL, FALSE);
+	g_return_val_if_fail (minor != NULL, FALSE);
+
+	/* get the atom name */
+	atom_name = "_ICC_PROFILE_IN_X_VERSION";
+
+	/* get the value */
+	gdk_error_trap_push ();
+	atom = gdk_x11_get_xatom_by_name_for_display (priv->display_gdk, atom_name);
+	rc = XGetWindowProperty (priv->display, priv->window, atom, 0, G_MAXLONG, False, XA_CARDINAL,
+				 &type, &format, &nitems, &bytes_after, (unsigned char **) &data_tmp);
+	gdk_error_trap_pop ();
+
+	/* did the call fail */
+	if (rc != Success) {
+		g_set_error (error, 1, 0, "failed to get %s atom with rc %i", atom_name, rc);
+		goto out;
+	}
+
+	/* was nothing found */
+	if (nitems == 0) {
+		g_set_error (error, 1, 0, "%s atom has not been set", atom_name);
+		goto out;
+	}
+
+	/* set total */
+	*major = (guint) data_tmp[0] / 100;
+	*minor = (guint) data_tmp[0] % 100;
+
+	/* success */
+	ret = TRUE;
+out:
+	if (data_tmp != NULL)
+		XFree (data_tmp);
+	return ret;
+}
+
+/**
  * gcm_xserver_remove_root_window_profile:
  * @xserver: a valid %GcmXserver instance
  * @error: a %GError that is set in the result of an error, or %NULL
diff --git a/src/gcm-xserver.h b/src/gcm-xserver.h
index e01a4df..a05ca0c 100644
--- a/src/gcm-xserver.h
+++ b/src/gcm-xserver.h
@@ -71,6 +71,16 @@ gboolean	 gcm_xserver_set_root_window_profile		(GcmXserver		*xserver,
 								 GError			**error);
 gboolean	 gcm_xserver_remove_root_window_profile		(GcmXserver		*xserver,
 								 GError			**error);
+gboolean	 gcm_xserver_set_protocol_version		(GcmXserver		*xserver,
+								 guint			 major,
+								 guint			 minor,
+								 GError			**error);
+gboolean	 gcm_xserver_remove_protocol_version		(GcmXserver		*xserver,
+								 GError			**error);
+gboolean	 gcm_xserver_get_protocol_version		(GcmXserver		*xserver,
+								 guint			*major,
+								 guint			*minor,
+								 GError			**error);
 
 /* per output */
 gboolean	 gcm_xserver_get_output_profile_data		(GcmXserver		*xserver,



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