ei: Send sync done event on last event unref

This allows the application to hold the sync event for a while longer,
e.g. to ensure previous events from ei have passed through relevant
plumbing and reached their internally intended targets, which might
happen synchronously between each processed ei event.

Part-of: <https://gitlab.freedesktop.org/libinput/libei/-/merge_requests/340>
This commit is contained in:
Jonas Ådahl 2025-07-15 19:43:39 +02:00
parent 1010cdff3c
commit 8d86ada12d
3 changed files with 16 additions and 10 deletions

View file

@ -102,6 +102,7 @@ ei_event_destroy(struct ei_event *event)
ei_ping_unref(event->pong.ping);
break;
case EI_EVENT_SYNC:
ei_sync_event_send_done(event);
ei_pingpong_unref(event->sync.pingpong);
break;
}

View file

@ -243,6 +243,8 @@ ei_queue_touch_up_event(struct ei_device *device, uint32_t touchid);
void
ei_queue_touch_cancel_event(struct ei_device *device, uint32_t touchid);
void
ei_sync_event_send_done(struct ei_event *e);
_printf_(6, 7) void
ei_log_msg(struct ei *ei,

View file

@ -336,6 +336,19 @@ ei_queue_pong_event(struct ei *ei, struct ei_ping *ping)
queue_event(ei, e);
}
void
ei_sync_event_send_done(struct ei_event *e)
{
struct ei *ei = ei_event_get_context(e);
_unref_(ei_pingpong) *pp = steal(&e->sync.pingpong);
log_debug(ei_event_get_context(e),
"object %#" PRIx64 ": ping pong done",
ei_pingpong_get_id(pp));
if (ei->state < EI_STATE_DISCONNECTED)
ei_pingpong_request_done(pp, 0);
}
void
ei_queue_sync_event(struct ei *ei, struct ei_pingpong *ping)
{
@ -693,16 +706,6 @@ ei_get_event(struct ei *ei)
struct ei_event *e = list_first_entry(&ei->event_queue, e, link);
list_remove(&e->link);
if (e->type == EI_EVENT_SYNC) {
_unref_(ei_pingpong) *pp = steal(&e->sync.pingpong);
log_debug(ei_event_get_context(e),
"object %#" PRIx64 ": ping pong done",
ei_pingpong_get_id(pp));
if (ei->state < EI_STATE_DISCONNECTED)
ei_pingpong_request_done(pp, 0);
}
return e;
}