summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper St. Pierre <jstpierre@mecheye.net>2014-08-10 12:15:40 -0400
committerJasper St. Pierre <jstpierre@mecheye.net>2014-08-10 12:34:56 -0400
commita07fc2f85d276aa2c9a8ff05fe50e788bb948f2c (patch)
tree775678af6f0f1404d0099985d1261d99f63689ff
parentcb60da5f6bf310d9ac8875e439cfe8e19327b801 (diff)
downloadgtk+-a07fc2f85d276aa2c9a8ff05fe50e788bb948f2c.tar.gz
wayland: Remove overly complex cursor cache
-rw-r--r--gdk/wayland/gdkcursor-wayland.c80
-rw-r--r--gdk/wayland/gdkdisplay-wayland.c1
-rw-r--r--gdk/wayland/gdkdisplay-wayland.h2
-rw-r--r--gdk/wayland/gdkprivate-wayland.h1
4 files changed, 19 insertions, 65 deletions
diff --git a/gdk/wayland/gdkcursor-wayland.c b/gdk/wayland/gdkcursor-wayland.c
index 5d92732783..6702ce71ca 100644
--- a/gdk/wayland/gdkcursor-wayland.c
+++ b/gdk/wayland/gdkcursor-wayland.c
@@ -68,66 +68,16 @@ struct _GdkWaylandCursorClass
G_DEFINE_TYPE (GdkWaylandCursor, _gdk_wayland_cursor, GDK_TYPE_CURSOR)
-struct cursor_cache_key
-{
- GdkCursorType type;
- const char *name;
-};
-
-static void
-add_to_cache (GdkWaylandDisplay *display, GdkWaylandCursor *cursor)
-{
- display->cursor_cache = g_slist_prepend (display->cursor_cache, cursor);
-
- g_object_ref (cursor);
-}
-
-static gint
-cache_compare_func (gconstpointer listelem,
- gconstpointer target)
-{
- GdkWaylandCursor *cursor = (GdkWaylandCursor *) listelem;
- struct cursor_cache_key* key = (struct cursor_cache_key *) target;
-
- if (cursor->cursor.type != key->type)
- return 1; /* No match */
-
- /* Elements marked as pixmap must be named cursors
- * (since we don't store normal pixmap cursors
- */
- if (key->type == GDK_CURSOR_IS_PIXMAP)
- return strcmp (key->name, cursor->name);
-
- return 0; /* Match */
-}
-
-static GdkWaylandCursor*
-find_in_cache (GdkWaylandDisplay *display,
- GdkCursorType type,
- const char *name)
+void
+_gdk_wayland_display_init_cursors (GdkWaylandDisplay *display)
{
- GSList* res;
- struct cursor_cache_key key;
-
- key.type = type;
- key.name = name;
-
- res = g_slist_find_custom (display->cursor_cache, &key, cache_compare_func);
-
- if (res)
- return (GdkWaylandCursor *) res->data;
-
- return NULL;
+ display->cursor_cache = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_object_unref);
}
-/* Called by gdk_wayland_display_finalize to flush any cached cursors
- * for a dead display.
- */
void
_gdk_wayland_display_finalize_cursors (GdkWaylandDisplay *display)
{
- g_slist_foreach (display->cursor_cache, (GFunc) g_object_unref, NULL);
- g_slist_free (display->cursor_cache);
+ g_hash_table_destroy (display->cursor_cache);
}
static gboolean
@@ -156,7 +106,14 @@ void
_gdk_wayland_display_update_cursors (GdkWaylandDisplay *display,
struct wl_cursor_theme *theme)
{
- g_slist_foreach (display->cursor_cache, (GFunc) set_cursor_from_theme, theme);
+ GHashTableIter iter;
+ const char *name;
+ GdkWaylandCursor *cursor;
+
+ g_hash_table_iter_init (&iter, display->cursor_cache);
+
+ while (g_hash_table_iter_next (&iter, (gpointer *) &name, (gpointer *) &cursor))
+ set_cursor_from_theme (cursor, theme);
}
static void
@@ -302,14 +259,9 @@ _gdk_wayland_display_get_cursor_for_name (GdkDisplay *display,
g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
- private = find_in_cache (wayland_display, GDK_CURSOR_IS_PIXMAP, name);
+ private = g_hash_table_lookup (wayland_display->cursor_cache, name);
if (private)
- {
- /* Cache had it, add a ref for this user */
- g_object_ref (private);
-
- return (GdkCursor*) private;
- }
+ return GDK_CURSOR (g_object_ref (private));
private = g_object_new (GDK_TYPE_WAYLAND_CURSOR,
"cursor-type", GDK_CURSOR_IS_PIXMAP,
@@ -325,8 +277,8 @@ _gdk_wayland_display_get_cursor_for_name (GdkDisplay *display,
if (!set_cursor_from_theme (private, wayland_display->cursor_theme))
return GDK_CURSOR (private);
- add_to_cache (wayland_display, private);
-
+ /* Insert into cache. */
+ g_hash_table_insert (wayland_display->cursor_cache, private->name, g_object_ref (private));
return GDK_CURSOR (private);
}
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 1d62160f79..50fda75286 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -232,6 +232,7 @@ _gdk_wayland_display_open (const gchar *display_name)
/* Wait until the dust has settled during init... */
wl_display_roundtrip (display_wayland->wl_display);
+ _gdk_wayland_display_init_cursors (display_wayland);
gdk_input_init (display);
g_signal_emit_by_name (display, "opened");
diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h
index 1a3a8cfa27..3098e544e0 100644
--- a/gdk/wayland/gdkdisplay-wayland.h
+++ b/gdk/wayland/gdkdisplay-wayland.h
@@ -64,7 +64,7 @@ struct _GdkWaylandDisplay
struct wl_data_device_manager *data_device_manager;
struct wl_cursor_theme *cursor_theme;
- GSList *cursor_cache;
+ GHashTable *cursor_cache;
GSource *event_source;
diff --git a/gdk/wayland/gdkprivate-wayland.h b/gdk/wayland/gdkprivate-wayland.h
index d6d2375429..aaaa8d700d 100644
--- a/gdk/wayland/gdkprivate-wayland.h
+++ b/gdk/wayland/gdkprivate-wayland.h
@@ -52,6 +52,7 @@ struct xkb_keymap *_gdk_wayland_keymap_get_xkb_keymap (GdkKeymap *keymap);
gboolean _gdk_wayland_keymap_key_is_modifier (GdkKeymap *keymap,
guint keycode);
+void _gdk_wayland_display_init_cursors (GdkWaylandDisplay *display);
void _gdk_wayland_display_finalize_cursors (GdkWaylandDisplay *display);
void _gdk_wayland_display_update_cursors (GdkWaylandDisplay *display,
struct wl_cursor_theme *theme);