From b6c8bf3be71e2770ae3ac885a134a050b8557487 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 29 Nov 2022 13:08:59 -0500 Subject: [PATCH] input-device: Only allow one renderer to consume input at a time Right now if there are two graphics cards, there ends up with two renderers active at the same time. Both process keyboard inputs and both end up sending those events to plymouthd, resulting in duplicate input. This commit changes the input handlers so the first one wins, and the rest don't get input. Closes https://gitlab.freedesktop.org/plymouth/plymouth/-/issues/197 --- src/libply-splash-core/ply-input-device.h | 12 +++++++++--- src/plugins/renderers/drm/plugin.c | 14 ++++++++------ src/plugins/renderers/frame-buffer/plugin.c | 10 +++++++--- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/libply-splash-core/ply-input-device.h b/src/libply-splash-core/ply-input-device.h index ecc88982..7101895d 100644 --- a/src/libply-splash-core/ply-input-device.h +++ b/src/libply-splash-core/ply-input-device.h @@ -38,10 +38,16 @@ typedef enum PLY_KEY_HELD, } ply_key_direction_t; +typedef enum +{ + PLY_INPUT_RESULT_PROPAGATED = false, + PLY_INPUT_RESULT_CONSUMED = true, +} ply_input_device_input_result_t; + typedef struct _ply_input_device ply_input_device_t; -typedef void (*ply_input_device_input_handler_t) (void *user_data, - ply_input_device_t *input_device, - const char *buf); +typedef ply_input_device_input_result_t (*ply_input_device_input_handler_t) (void *user_data, + ply_input_device_t *input_device, + const char *buf); typedef void (*ply_input_device_leds_changed_handler_t) (void *user_data, ply_input_device_t *input_device); typedef void (*ply_input_device_disconnect_handler_t) (void *user_data, diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c index 9a04a8f5..af94df38 100644 --- a/src/plugins/renderers/drm/plugin.c +++ b/src/plugins/renderers/drm/plugin.c @@ -1768,17 +1768,19 @@ on_terminal_key_event (ply_renderer_input_source_t *input_source) input_source->handler (input_source->user_data, input_source->key_buffer, input_source); } -static void +static ply_input_device_input_result_t on_input_device_key (ply_renderer_input_source_t *input_source, ply_input_device_t *input_device, const char *text) { - int len = strlen (text); - if (len > 0) - ply_buffer_append_bytes (input_source->key_buffer, text, len); + ply_buffer_append_bytes (input_source->key_buffer, text, strlen (text)); - if (input_source->handler != NULL) - input_source->handler (input_source->user_data, input_source->key_buffer, input_source); + if (input_source->handler == NULL) + return PLY_INPUT_RESULT_PROPAGATED; + + input_source->handler (input_source->user_data, input_source->key_buffer, input_source); + + return PLY_INPUT_RESULT_CONSUMED; } static void diff --git a/src/plugins/renderers/frame-buffer/plugin.c b/src/plugins/renderers/frame-buffer/plugin.c index 553a4107..1cd83ec4 100644 --- a/src/plugins/renderers/frame-buffer/plugin.c +++ b/src/plugins/renderers/frame-buffer/plugin.c @@ -676,15 +676,19 @@ on_terminal_key_event (ply_renderer_input_source_t *input_source) input_source->handler (input_source->user_data, input_source->key_buffer, input_source); } -static void +static ply_input_device_input_result_t on_input_device_key (ply_renderer_input_source_t *input_source, ply_input_device_t *input_device, const char *text) { ply_buffer_append_bytes (input_source->key_buffer, text, strlen (text)); - if (input_source->handler != NULL) - input_source->handler (input_source->user_data, input_source->key_buffer, input_source); + if (input_source->handler == NULL) + return PLY_INPUT_RESULT_PROPAGATED; + + input_source->handler (input_source->user_data, input_source->key_buffer, input_source); + + return PLY_INPUT_RESULT_CONSUMED; } static void -- 2.47.3