From 14a5ec7b41ec52b5a0fb0f75490331117b618a08 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 3 Nov 2021 14:08:41 +0900 Subject: [PATCH] [input] Make device add/remove events broadcast It proved necessary to support broadcasting events to all event handlers, with device add/remove being the first such events. --- include/QF/input/event.h | 5 +++++ libs/input/in_event.c | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/QF/input/event.h b/include/QF/input/event.h index 1f960bda8..d16e66ac2 100644 --- a/include/QF/input/event.h +++ b/include/QF/input/event.h @@ -71,6 +71,11 @@ typedef enum { ie_button, } IE_event_type; +#define IE_broadcast_events (0 \ + | (1 << ie_add_device) \ + | (1 << ie_remove_device) \ + ) + typedef struct { IE_event_type type; uint64_t when; diff --git a/libs/input/in_event.c b/libs/input/in_event.c index aa302cf5b..b2aaf362c 100644 --- a/libs/input/in_event.c +++ b/libs/input/in_event.c @@ -54,6 +54,16 @@ static unsigned focus; int IE_Send_Event (const IE_event_t *event) { + if ((1 << event->type) & IE_broadcast_events) { + for (size_t i = 0; i < ie_handlers.size; i++) { + ie_reghandler_t *reg = &ie_handlers.a[i]; + if (reg->handler) { + reg->handler (event, reg->data); + } + } + return 1; + } + if (focus < ie_handlers.size && ie_handlers.a[focus].handler) { ie_reghandler_t *reg = &ie_handlers.a[focus]; return reg->handler (event, reg->data);