From d774dba68acda5dbed0ad2136e760f931419f272 Mon Sep 17 00:00:00 2001 From: liang zhou Date: Fri, 15 May 2026 13:10:13 +0800 Subject: [PATCH] libweston: add API to get touch device list Add API for plugins to retrieve touch device list for initializing touch devices at startup. Signed-off-by: liang zhou --- include/libweston/libweston.h | 14 +++++++++ libweston/compositor.c | 54 +++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index 700a7ebb8..1625cb49a 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -2919,6 +2919,20 @@ uint64_t weston_client_new_internal_id(struct weston_compositor *compositor, struct weston_client *client); +/** Container for an array of touch devices. */ +struct weston_touch_device_list { + /** Length of \c array. */ + size_t len; + /** Pointer to an array of touch device pointers. */ + struct weston_touch_device **array; +}; + +struct weston_touch_device_list +weston_compositor_get_touch_devices(struct weston_compositor *compositor); + +void +weston_touch_device_list_release(struct weston_touch_device_list *list); + #ifdef __cplusplus } #endif diff --git a/libweston/compositor.c b/libweston/compositor.c index 90c827c74..d3896358b 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -11257,3 +11257,57 @@ weston_backend_clear_deferred(struct weston_backend *backend, weston_output_schedule_repaint(output); } } + +/** + * Get a list of all touch devices as an array of pointers. + * + * The pointers in the array remain valid until any touch device is + * destroyed. Do not store the array or any of the pointers for later + * use without adding destroy signal handlers for each stored pointer. + * + * \param compositor The compositor instance. + * + * \return A list of touch devices. + * + * \ingroup compositor + */ +WL_EXPORT struct weston_touch_device_list +weston_compositor_get_touch_devices(struct weston_compositor *compositor) +{ + struct wl_array arr; + struct weston_seat *seat; + struct weston_touch_device *device; + struct weston_touch_device **entry; + + wl_array_init(&arr); + + wl_list_for_each(seat, &compositor->seat_list, link) { + if (!seat->touch_state) + continue; + wl_list_for_each(device, &seat->touch_state->device_list, link) { + entry = wl_array_add(&arr, sizeof *entry); + abort_oom_if_null(entry); + *entry = device; + } + } + + return (struct weston_touch_device_list){ + .len = arr.size / sizeof(struct weston_touch_device *), + .array = arr.data + }; +} + +/** + * Free the memory allocated by weston_compositor_get_touch_devices + * + * \param list List of touch devices + * + * \ingroup compositor + */ +WL_EXPORT void +weston_touch_device_list_release(struct weston_touch_device_list *list) +{ + free(list->array); + list->len = 0; + list->array = NULL; +}