summaryrefslogtreecommitdiff
path: root/gdk/wayland/gdkkeys-wayland.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-04-30 00:33:06 -0400
committerMatthias Clasen <mclasen@redhat.com>2020-04-30 13:05:52 -0400
commit99c3928cecb0bf4dd7c33c1f7fd078b256aa8a78 (patch)
tree23c25d6f74a4352ccbd3bf6c37d2092a3ad25495 /gdk/wayland/gdkkeys-wayland.c
parente5c430266e71289765de6d8bfc40166bcbeff4e7 (diff)
downloadgtk+-99c3928cecb0bf4dd7c33c1f7fd078b256aa8a78.tar.gz
keymap: Cache key info
We currently calling gdk_display_map_keyval up to once per key event per shortcut trigger, and that function does an expensive loop over the entire keymap and allocates an array. Avoid this by caching the entries in a single array, and have a lookup table for finding the entries for a keyval. To do this, change the GdkKeymap.get_entries_for_keyval signature, and change the ::keys-changed signal to be RUN_FIRST, since we want to clear the cache in the class handler before running signal handlers. These changes are possible now, since keymaps are no longer public API.
Diffstat (limited to 'gdk/wayland/gdkkeys-wayland.c')
-rw-r--r--gdk/wayland/gdkkeys-wayland.c16
1 files changed, 5 insertions, 11 deletions
diff --git a/gdk/wayland/gdkkeys-wayland.c b/gdk/wayland/gdkkeys-wayland.c
index 1b98c73e85..802463298e 100644
--- a/gdk/wayland/gdkkeys-wayland.c
+++ b/gdk/wayland/gdkkeys-wayland.c
@@ -126,17 +126,14 @@ gdk_wayland_keymap_get_scroll_lock_state (GdkKeymap *keymap)
}
static gboolean
-gdk_wayland_keymap_get_entries_for_keyval (GdkKeymap *keymap,
- guint keyval,
- GdkKeymapKey **keys,
- gint *n_keys)
+gdk_wayland_keymap_get_entries_for_keyval (GdkKeymap *keymap,
+ guint keyval,
+ GArray *retval)
{
struct xkb_keymap *xkb_keymap = GDK_WAYLAND_KEYMAP (keymap)->xkb_keymap;
- GArray *retval;
guint keycode;
xkb_keycode_t min_keycode, max_keycode;
-
- retval = g_array_new (FALSE, FALSE, sizeof (GdkKeymapKey));
+ guint len = retval->len;
min_keycode = xkb_keymap_min_keycode (xkb_keymap);
max_keycode = xkb_keymap_max_keycode (xkb_keymap);
@@ -170,10 +167,7 @@ gdk_wayland_keymap_get_entries_for_keyval (GdkKeymap *keymap,
}
}
- *n_keys = retval->len;
- *keys = (GdkKeymapKey*) g_array_free (retval, FALSE);
-
- return TRUE;
+ return retval->len > len;
}
static gboolean