From c2db5954c41e5e1b53770dac27923fe7acd4c7fd Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Tue, 28 Apr 2026 17:22:24 +0200 Subject: [PATCH] Use shared pixdata helper for drag cursors Replace the deprecated gdk_pixbuf_new_from_inline() call used for GTK drag cursor pixbufs with the internal pixdata helper. Keep the existing embedded cursor data and lazy per-cursor pixbuf creation. The helper reads the embedded pixdata length from the stream header and then uses the shared validating decoder, avoiding extra per-cursor metadata or runtime resources. --- gtk/gtkdnd.c | 5 +++-- gtk/gtkpixdatautils.c | 20 ++++++++++++++++++++ gtk/gtkpixdatautils.h | 3 +++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index 144ec2bff..a2dbea105 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -45,6 +45,7 @@ #include "gtkimage.h" #include "gtkinvisible.h" #include "gtkmain.h" +#include "gtkpixdatautils.h" #include "gtkplug.h" #include "gtkstock.h" #include "gtktooltip.h" @@ -743,8 +744,8 @@ gtk_drag_get_cursor (GdkDisplay *display, break; if (drag_cursors[i].pixbuf == NULL) - drag_cursors[i].pixbuf = - gdk_pixbuf_new_from_inline (-1, drag_cursors[i].data, FALSE, NULL); + drag_cursors[i].pixbuf = + _gtk_pixbuf_new_from_inline_pixdata (drag_cursors[i].data, NULL); if (drag_cursors[i].cursor != NULL) { diff --git a/gtk/gtkpixdatautils.c b/gtk/gtkpixdatautils.c index 9d546d6ae..f648dcc83 100644 --- a/gtk/gtkpixdatautils.c +++ b/gtk/gtkpixdatautils.c @@ -221,6 +221,26 @@ _gtk_pixbuf_new_from_pixdata_stream (const guint8 *stream, return NULL; } +GdkPixbuf * +_gtk_pixbuf_new_from_inline_pixdata (const guint8 *stream, + GError **error) +{ + guint32 length; + + g_return_val_if_fail (stream != NULL, NULL); + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + if (memcmp (stream, GTK_PIXDATA_MAGIC, 4) != 0) + { + pixdata_set_error (error); + return NULL; + } + + length = pixdata_get_uint32 (stream + 4); + + return _gtk_pixbuf_new_from_pixdata_stream (stream, length, error); +} + guint8 * _gtk_pixdata_serialize_from_pixbuf (GdkPixbuf *pixbuf, gsize *length_p) diff --git a/gtk/gtkpixdatautils.h b/gtk/gtkpixdatautils.h index 8c5159152..59126d7b9 100644 --- a/gtk/gtkpixdatautils.h +++ b/gtk/gtkpixdatautils.h @@ -9,6 +9,9 @@ GdkPixbuf *_gtk_pixbuf_new_from_pixdata_stream (const guint8 *stream, gsize stream_length, GError **error); +GdkPixbuf *_gtk_pixbuf_new_from_inline_pixdata (const guint8 *stream, + GError **error); + guint8 *_gtk_pixdata_serialize_from_pixbuf (GdkPixbuf *pixbuf, gsize *length_p);