[gtk+] gdk: Add gdk_cursor_hash() and gdk_cursor_equal()
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] gdk: Add gdk_cursor_hash() and gdk_cursor_equal()
- Date: Fri, 3 Nov 2017 23:26:15 +0000 (UTC)
commit 428547e14fc69bc13a0665aeb68d9438403261b1
Author: Benjamin Otte <otte redhat com>
Date: Fri Nov 3 03:08:04 2017 +0100
gdk: Add gdk_cursor_hash() and gdk_cursor_equal()
This is so GDK backends can put cursors into hash tables and avoid
duplicates.
gdk/gdkcursor.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
gdk/gdkcursorprivate.h | 4 ++++
2 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/gdk/gdkcursor.c b/gdk/gdkcursor.c
index decba09..f199df8 100644
--- a/gdk/gdkcursor.c
+++ b/gdk/gdkcursor.c
@@ -235,6 +235,52 @@ gdk_cursor_init (GdkCursor *cursor)
{
}
+guint
+gdk_cursor_hash (gconstpointer pointer)
+{
+ const GdkCursor *cursor = pointer;
+ guint hash;
+
+ if (cursor->fallback)
+ hash = gdk_cursor_hash (cursor->fallback) << 16;
+ else
+ hash = 0;
+
+ if (cursor->name)
+ hash ^= g_str_hash (cursor->name);
+ else if (cursor->texture)
+ hash ^= g_direct_hash (cursor->texture);
+
+ hash ^= (cursor->hotspot_x << 8) | cursor->hotspot_y;
+
+ return hash;
+}
+
+gboolean
+gdk_cursor_equal (gconstpointer a,
+ gconstpointer b)
+{
+ const GdkCursor *ca = a;
+ const GdkCursor *cb = b;
+
+ if ((ca->fallback != NULL) != (cb->fallback != NULL))
+ return FALSE;
+ if (ca->fallback != NULL && !gdk_cursor_equal (ca->fallback, cb->fallback))
+ return FALSE;
+
+ if (g_strcmp0 (ca->name, cb->name) != 0)
+ return FALSE;
+
+ if (ca->texture != cb->texture)
+ return FALSE;
+
+ if (ca->hotspot_x != cb->hotspot_x ||
+ ca->hotspot_y != cb->hotspot_y)
+ return FALSE;
+
+ return TRUE;
+}
+
/**
* gdk_cursor_new_from_name:
* @display: the #GdkDisplay for which the cursor will be created
diff --git a/gdk/gdkcursorprivate.h b/gdk/gdkcursorprivate.h
index 6edf841..aaac316 100644
--- a/gdk/gdkcursorprivate.h
+++ b/gdk/gdkcursorprivate.h
@@ -52,6 +52,10 @@ struct _GdkCursorClass
GObjectClass parent_class;
};
+guint gdk_cursor_hash (gconstpointer pointer);
+gboolean gdk_cursor_equal (gconstpointer a,
+ gconstpointer b);
+
G_END_DECLS
#endif /* __GDK_CURSOR_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]