Add xkb_key_repeats Does what it says on the box. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/include/xkbcommon/xkbcommon.h b/include/xkbcommon/xkbcommon.h
index 4c148d5..31d0dcf 100644
--- a/include/xkbcommon/xkbcommon.h
+++ b/include/xkbcommon/xkbcommon.h
@@ -367,6 +367,12 @@ xkb_group_index_t
xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t key);
/**
+ * Returns 1 if the key should repeat, or 0 otherwise.
+ */
+int
+xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key);
+
+/**
* Returns the number of LEDs in the given map.
*/
xkb_led_index_t
diff --git a/src/map.c b/src/map.c
index d4c8f3d..d9afc1a 100644
--- a/src/map.c
+++ b/src/map.c
@@ -351,3 +351,12 @@ err:
*syms_out = NULL;
return 0;
}
+
+/**
+ * Simple boolean specifying whether or not the key should repeat.
+ */
+_X_EXPORT int
+xkb_key_repeats(struct xkb_keymap *keymap, xkb_keycode_t key)
+{
+ return !!(keymap->ctrls->per_key_repeat[key / 8] & (1 << (key % 8)));
+}
diff --git a/test/state.c b/test/state.c
index 2409a23..d32a1ea 100644
--- a/test/state.c
+++ b/test/state.c
@@ -227,6 +227,18 @@ test_serialisation(struct xkb_keymap *keymap)
xkb_state_unref(state);
}
+static void
+test_repeat(struct xkb_keymap *keymap)
+{
+ xkb_keycode_t key;
+ fprintf(stderr, "%s\n", xkb_map_get_as_string(keymap));
+ for (key = keymap->min_key_code; key < keymap->max_key_code; key++)
+ if (xkb_key_repeats(keymap, key))
+ fprintf(stderr, "%d repeats!\n", key);
+ assert(!xkb_key_repeats(keymap, KEY_LEFTSHIFT + 8));
+ assert(xkb_key_repeats(keymap, KEY_A + 8));
+}
+
int
main(void)
{
@@ -248,6 +260,7 @@ main(void)
test_update_key(keymap);
test_serialisation(keymap);
+ test_repeat(keymap);
xkb_map_unref(keymap);
xkb_context_unref(context);