[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.
This commit is contained in:
Bill Currie 2021-11-03 14:08:41 +09:00
parent fae9e043df
commit 14a5ec7b41
2 changed files with 15 additions and 0 deletions

View File

@ -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;

View File

@ -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);