From bc0451634a1584d3b763e10ad049bee848cce58c Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 22 Nov 2021 14:32:19 +0900 Subject: [PATCH] [input] Drop unfocused evdev axis/button events The kernel knows nothing about X11 application focus, so we need to take care of it ourselves. Device add/remove events are unaffected: the are always passed on. --- libs/input/in_evdev.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libs/input/in_evdev.c b/libs/input/in_evdev.c index a2c6a7faa..6666cedd7 100644 --- a/libs/input/in_evdev.c +++ b/libs/input/in_evdev.c @@ -56,6 +56,7 @@ typedef struct devmap_s { } devmap_t; static int evdev_driver_handle = -1; +static int evdev_have_focus; static PR_RESMAP (devmap_t) devmap; static devmap_t *devmap_list; @@ -96,6 +97,10 @@ in_evdev_get_device_event_data (void *device, void *data) static void in_evdev_axis_event (axis_t *axis, void *_dm) { + if (!evdev_have_focus) { + return; + } + devmap_t *dm = _dm; //Sys_Printf ("in_evdev_axis_event: %d %d\n", axis->num, axis->value); @@ -115,6 +120,10 @@ in_evdev_axis_event (axis_t *axis, void *_dm) static void in_evdev_button_event (button_t *button, void *_dm) { + if (!evdev_have_focus) { + return; + } + devmap_t *dm = _dm; //Sys_Printf ("in_evdev_button_event: %d %d\n", button->num, button->state); @@ -252,10 +261,25 @@ static in_driver_t in_evdev_driver = { .button_info = in_evdev_button_info, }; +static int +in_evdev_evend_handler (const IE_event_t *event, void *data) +{ + if (event->type == ie_app_gain_focus) { + evdev_have_focus = 1; + return 1; + } else if (event->type == ie_app_lose_focus) { + evdev_have_focus = 0; + return 1; + } + return 0; +} + static void __attribute__((constructor)) in_evdev_register_driver (void) { evdev_driver_handle = IN_RegisterDriver (&in_evdev_driver, 0); + //FIXME probably shouldn't be here + IE_Add_Handler (in_evdev_evend_handler, 0); } int in_evdev_force_link;