]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
input-device: Only allow one renderer to consume input at a time
authorRay Strode <rstrode@redhat.com>
Tue, 29 Nov 2022 18:08:59 +0000 (13:08 -0500)
committerRay Strode <rstrode@redhat.com>
Tue, 29 Nov 2022 18:34:05 +0000 (13:34 -0500)
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
src/plugins/renderers/drm/plugin.c
src/plugins/renderers/frame-buffer/plugin.c

index ecc8898222346d3036cfc1ed321a16ec41c89922..7101895d22b979abdada4e7c7b5de135d5a7701b 100644 (file)
@@ -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,
index 9a04a8f59b38cc7063f69fd43235b4256f77240b..af94df3855f39f564c0e7dee214aee5206465a51 100644 (file)
@@ -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
index 553a41072e6f899243a7e3ef285fb503acfedd85..1cd83ec45a1a7093d86f83119a2d468945f3cad3 100644 (file)
@@ -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