From 3427788c40617e0e5e36a083d7efe3358d4cd291 Mon Sep 17 00:00:00 2001 From: liang zhou Date: Fri, 15 May 2026 13:51:59 +0800 Subject: [PATCH] libweston: add API to find weston output by head serial Add new API weston_compositor_find_output_by_head_serial for touch binding. Signed-off-by: liang zhou --- include/libweston/libweston.h | 4 ++++ libweston/compositor.c | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index d97bd8399..f65460fd1 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -2936,6 +2936,10 @@ weston_compositor_get_touch_devices(struct weston_compositor *compositor); void weston_touch_device_list_release(struct weston_touch_device_list *list); +struct weston_output * +weston_compositor_find_output_by_head_serial(struct weston_compositor *compositor, + const char *serial); + #ifdef __cplusplus } #endif diff --git a/libweston/compositor.c b/libweston/compositor.c index 76a4f4ed4..78e920661 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -11324,3 +11324,29 @@ weston_touch_device_list_release(struct weston_touch_device_list *list) list->len = 0; list->array = NULL; } + +/** + * Find an output by its head serial number + * \param compositor Weston compositor object + * \param serial Serial number of the head + * \return Output; NULL if not found + * + * \ingroup compositor + */ +WL_EXPORT struct weston_output * +weston_compositor_find_output_by_head_serial(struct weston_compositor *compositor, + const char *serial) +{ + struct weston_output *output; + struct weston_head *head; + + /* Check active outputs */ + wl_list_for_each(output, &compositor->output_list, link) { + wl_list_for_each(head, &output->head_list, output_link) { + if (head->serial_number && strcmp(head->serial_number, serial) == 0) + return output; + } + } + + return NULL; +}