From d978d940416845dc9b6e552374d2707efe8ae254 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 29 Nov 2020 18:58:21 +0000 Subject: [PATCH] keyboard: Extract function 'keyboard_feed_code()' --- include/keyboard.h | 2 ++ src/keyboard.c | 28 +++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/keyboard.h b/include/keyboard.h index 59b1d4b..3804f52 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -42,3 +42,5 @@ struct keyboard { int keyboard_init(struct keyboard* self, const char* layout, const char* variant); void keyboard_destroy(struct keyboard* self); void keyboard_feed(struct keyboard* self, xkb_keysym_t symbol, bool is_pressed); +void keyboard_feed_code(struct keyboard* self, xkb_keycode_t code, + bool is_pressed); diff --git a/src/keyboard.c b/src/keyboard.c index 9a6f5b4..ab76675 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -346,25 +346,31 @@ void keyboard_feed(struct keyboard* self, xkb_keysym_t symbol, bool is_pressed) entry = level_entry; } - bool was_pressed = intset_is_set(&self->key_state, entry->code); - if (was_pressed == is_pressed) - return; - - if (is_pressed) - intset_set(&self->key_state, entry->code); - else - intset_clear(&self->key_state, entry->code); - #ifndef NDEBUG keyboard__dump_entry(self, entry); #endif + keyboard_feed_code(self, entry->code, is_pressed); +} + +void keyboard_feed_code(struct keyboard* self, xkb_keycode_t code, + bool is_pressed) +{ + bool was_pressed = intset_is_set(&self->key_state, code); + if (was_pressed == is_pressed) + return; + + if (is_pressed) + intset_set(&self->key_state, code); + else + intset_clear(&self->key_state, code); + // TODO: This could cause some synchronisation problems with other // keyboards in the seat. - keyboard_apply_mods(self, entry->code, is_pressed); + keyboard_apply_mods(self, code, is_pressed); // TODO: Handle errors - zwp_virtual_keyboard_v1_key(self->virtual_keyboard, 0, entry->code - 8, + zwp_virtual_keyboard_v1_key(self->virtual_keyboard, 0, code - 8, is_pressed ? WL_KEYBOARD_KEY_STATE_PRESSED : WL_KEYBOARD_KEY_STATE_RELEASED); }