[gtk/matthiasc/color-profile-rebased: 22/46] x11: Implement support for color profiles
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/color-profile-rebased: 22/46] x11: Implement support for color profiles
- Date: Tue, 10 May 2022 13:15:49 +0000 (UTC)
commit 46a4a31cbc52a8f2113c308fc2bc6286adc4b83e
Author: Benjamin Otte <otte redhat com>
Date: Fri Oct 1 06:26:59 2021 +0200
x11: Implement support for color profiles
Stole the implementation from eog.
This doesn't yet update the profile when it changes though.
gdk/x11/gdkdisplay-x11.c | 80 +++++++++++++++++++++++++++++++++++++++++++++---
gdk/x11/gdkdisplay-x11.h | 3 ++
gdk/x11/gdksurface-x11.c | 2 ++
3 files changed, 80 insertions(+), 5 deletions(-)
---
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 84a45dc814..0d8e126a8a 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -1403,6 +1403,71 @@ gdk_x11_display_init_leader_surface (GdkX11Display *self)
self->leader_window_title_set = FALSE;
}
+static void
+voidXFree (gpointer data)
+{
+ XFree (data);
+}
+
+static void
+gdk_x11_display_check_color_profile (GdkX11Display *self)
+{
+ GdkDisplay *display = GDK_DISPLAY (self);
+ GdkX11Screen *screen;
+ char *atom_name;
+ Atom type;
+ int result;
+ int format;
+ gulong nitems;
+ gulong bytes_after;
+ guchar *data;
+ GBytes *bytes;
+
+ screen = self->screen;
+ if (screen->screen_num > 0)
+ atom_name = g_strdup_printf ("_ICC_PROFILE_%d", screen->screen_num);
+ else
+ atom_name = g_strdup ("_ICC_PROFILE");
+
+ g_clear_object (&self->color_profile);
+ self->color_profile = g_object_ref (gdk_color_profile_get_srgb ());
+
+ gdk_x11_display_error_trap_push (display);
+ result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
+ screen->xroot_window,
+ gdk_x11_get_xatom_by_name_for_display (display, atom_name),
+ 0, G_MAXLONG, False, XA_CARDINAL, &type,
+ &format, &nitems,
+ &bytes_after, &data);
+ gdk_x11_display_error_trap_pop_ignored (display);
+
+ g_free (atom_name);
+
+ if (result != Success || type != XA_CARDINAL || nitems <= 0)
+ return;
+
+ switch (format)
+ {
+ case 8:
+ bytes = g_bytes_new_with_free_func (data, nitems, voidXFree, data);
+ break;
+ case 16:
+ bytes = g_bytes_new_with_free_func (data, sizeof (short) * nitems, voidXFree, data);
+ break;
+ case 32:
+ bytes = g_bytes_new_with_free_func (data, sizeof (long) * nitems, voidXFree, data);
+ break;
+ default:
+ XFree (data);
+ return;
+ }
+
+ g_clear_object (&self->color_profile);
+ self->color_profile = gdk_color_profile_new_from_icc_bytes (bytes, NULL);
+ if (!self->color_profile)
+ self->color_profile = g_object_ref (gdk_color_profile_get_srgb ());
+}
+
/**
* gdk_x11_display_open:
* @display_name: (nullable): name of the X display.
@@ -1470,6 +1535,9 @@ gdk_x11_display_open (const char *display_name)
/* initialize the display's screens */
display_x11->screen = _gdk_x11_screen_new (display, DefaultScreen (display_x11->xdisplay));
+ /* We want this for the leader surface already */
+ gdk_x11_display_check_color_profile (display_x11);
+
/* If GL is available we want to pick better default/rgba visuals,
* as we care about GLX details such as alpha/depth/stencil depth,
* stereo and double buffering
@@ -1915,15 +1983,17 @@ gdk_x11_display_ungrab (GdkDisplay *display)
static void
gdk_x11_display_dispose (GObject *object)
{
- GdkX11Display *display_x11 = GDK_X11_DISPLAY (object);
+ GdkX11Display *self = GDK_X11_DISPLAY (object);
- if (display_x11->event_source)
+ if (self->event_source)
{
- g_source_destroy (display_x11->event_source);
- g_source_unref (display_x11->event_source);
- display_x11->event_source = NULL;
+ g_source_destroy (self->event_source);
+ g_source_unref (self->event_source);
+ self->event_source = NULL;
}
+ g_clear_object (&self->color_profile);
+
G_OBJECT_CLASS (gdk_x11_display_parent_class)->dispose (object);
}
diff --git a/gdk/x11/gdkdisplay-x11.h b/gdk/x11/gdkdisplay-x11.h
index 654a708231..b8c428a57e 100644
--- a/gdk/x11/gdkdisplay-x11.h
+++ b/gdk/x11/gdkdisplay-x11.h
@@ -128,6 +128,9 @@ struct _GdkX11Display
guint have_damage;
#endif
+ /* Stored in the ICC_PROFILE rootwindow prop */
+ GdkColorProfile *color_profile;
+
/* If GL is not supported, store the error here */
GError *gl_error;
diff --git a/gdk/x11/gdksurface-x11.c b/gdk/x11/gdksurface-x11.c
index 2f4a2799b0..e157d1f3c1 100644
--- a/gdk/x11/gdksurface-x11.c
+++ b/gdk/x11/gdksurface-x11.c
@@ -1011,6 +1011,8 @@ setup_toplevel_window (GdkSurface *surface,
/* This will set WM_CLIENT_MACHINE and WM_LOCALE_NAME */
XSetWMProperties (xdisplay, xid, NULL, NULL, NULL, 0, NULL, NULL, NULL);
+
+ gdk_surface_set_color_profile (surface, GDK_X11_DISPLAY (display)->color_profile);
if (!gdk_running_in_sandbox ())
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]