Add xkb_key_repeats

Does what it says on the box.

Signed-off-by: Daniel Stone <daniel@fooishbar.org>
master
Daniel Stone 2012-06-22 15:27:05 +01:00
parent fe89d03154
commit 8e2c66e9ea
3 changed files with 28 additions and 0 deletions

View File

@ -366,6 +366,12 @@ xkb_map_group_get_index(struct xkb_keymap *keymap, const char *name);
xkb_group_index_t xkb_group_index_t
xkb_key_num_groups(struct xkb_keymap *keymap, xkb_keycode_t key); 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. * Returns the number of LEDs in the given map.
*/ */

View File

@ -351,3 +351,12 @@ err:
*syms_out = NULL; *syms_out = NULL;
return 0; 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)));
}

View File

@ -227,6 +227,18 @@ test_serialisation(struct xkb_keymap *keymap)
xkb_state_unref(state); 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 int
main(void) main(void)
{ {
@ -248,6 +260,7 @@ main(void)
test_update_key(keymap); test_update_key(keymap);
test_serialisation(keymap); test_serialisation(keymap);
test_repeat(keymap);
xkb_map_unref(keymap); xkb_map_unref(keymap);
xkb_context_unref(context); xkb_context_unref(context);