From bc674721dcc9b5b5461443c1b519333b4585fa7d Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 30 Dec 2021 15:03:39 +0100 Subject: [PATCH] Make process_text() optional Not all key processors support text injection (HID keyboard does not support it). Instead of providing a dummy op function, set it to NULL and check on the caller side before calling it. --- app/src/hid_keyboard.c | 13 +++---------- app/src/input_manager.c | 6 ++++++ app/src/trait/key_processor.h | 9 ++++++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/hid_keyboard.c b/app/src/hid_keyboard.c index be5f8a19..4a0e64ba 100644 --- a/app/src/hid_keyboard.c +++ b/app/src/hid_keyboard.c @@ -387,15 +387,6 @@ sc_key_processor_process_key(struct sc_key_processor *kp, } } -static void -sc_key_processor_process_text(struct sc_key_processor *kp, - const struct sc_text_event *event) { - (void) kp; - (void) event; - - // Never forward text input via HID (all the keys are injected separately) -} - bool sc_hid_keyboard_init(struct sc_hid_keyboard *kb, struct sc_aoa *aoa) { kb->aoa = aoa; @@ -415,7 +406,9 @@ sc_hid_keyboard_init(struct sc_hid_keyboard *kb, struct sc_aoa *aoa) { static const struct sc_key_processor_ops ops = { .process_key = sc_key_processor_process_key, - .process_text = sc_key_processor_process_text, + // Never forward text input via HID (all the keys are injected + // separately) + .process_text = NULL, }; // Clipboard synchronization is requested over the control socket, while HID diff --git a/app/src/input_manager.c b/app/src/input_manager.c index 4dc8c4eb..aa0708c0 100644 --- a/app/src/input_manager.c +++ b/app/src/input_manager.c @@ -384,6 +384,11 @@ rotate_client_right(struct screen *screen) { static void input_manager_process_text_input(struct input_manager *im, const SDL_TextInputEvent *event) { + if (!im->kp->ops->process_text) { + // The key processor does not support text input + return; + } + if (is_shortcut_mod(im, SDL_GetModState())) { // A shortcut must never generate text events return; @@ -620,6 +625,7 @@ input_manager_process_key(struct input_manager *im, .mods_state = sc_mods_state_from_sdl(event->keysym.mod), }; + assert(im->kp->ops->process_key); im->kp->ops->process_key(im->kp, &evt, ack_to_wait); } diff --git a/app/src/trait/key_processor.h b/app/src/trait/key_processor.h index 045e5e7b..8c51b11d 100644 --- a/app/src/trait/key_processor.h +++ b/app/src/trait/key_processor.h @@ -29,17 +29,24 @@ struct sc_key_processor { struct sc_key_processor_ops { /** - * Process the keyboard event + * Process a keyboard event * * The `sequence` number (if different from `SC_SEQUENCE_INVALID`) indicates * the acknowledgement number to wait for before injecting this event. * This allows to ensure that the device clipboard is set before injecting * Ctrl+v on the device. + * + * This function is mandatory. */ void (*process_key)(struct sc_key_processor *kp, const struct sc_key_event *event, uint64_t ack_to_wait); + /** + * Process an input text + * + * This function is optional. + */ void (*process_text)(struct sc_key_processor *kp, const struct sc_text_event *event);