From 751a5a5f74e39ffe5f68357251da0e2ef5504f64 Mon Sep 17 00:00:00 2001 From: liang zhou Date: Fri, 15 May 2026 14:16:33 +0800 Subject: [PATCH] libweston: add set_output param for weston_touch_create_touch_device Add the set_output function to weston_touch_device to allow touch binding interfaces to re-assign the touch-to-output mapping. Signed-off-by: liang zhou --- include/libweston/libweston.h | 8 ++++++++ libweston/backend-wayland/wayland.c | 2 +- libweston/input.c | 5 ++++- libweston/libinput-device.c | 15 ++++++++++++++- libweston/libweston-internal.h | 3 ++- tests/harness/weston-test.c | 2 +- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/libweston/libweston.h b/include/libweston/libweston.h index f65460fd1..2abe6ce45 100644 --- a/include/libweston/libweston.h +++ b/include/libweston/libweston.h @@ -869,6 +869,10 @@ enum weston_touch_mode { WESTON_TOUCH_MODE_PREP_NORMAL }; +typedef void (*weston_touch_device_set_output_func_t)( + struct weston_touch_device *, + struct weston_output *); + /** Represents a physical touchscreen input device */ struct weston_touch_device { char *syspath; /**< unique name */ @@ -880,6 +884,10 @@ struct weston_touch_device { void *backend_data; /**< backend-specific private */ const struct weston_touch_device_ops *ops; + + /** Set touch to specific output */ + weston_touch_device_set_output_func_t set_output; + struct weston_touch_device_matrix saved_calibration; }; diff --git a/libweston/backend-wayland/wayland.c b/libweston/backend-wayland/wayland.c index 60210fa66..6a400f9a2 100644 --- a/libweston/backend-wayland/wayland.c +++ b/libweston/backend-wayland/wayland.c @@ -2255,7 +2255,7 @@ create_touch_device(struct wayland_input *input) wl_proxy_get_id((struct wl_proxy *)input->parent.seat)); touch_device = weston_touch_create_touch_device(input->base.touch_state, - str, NULL, NULL); + str, NULL, NULL, NULL); return touch_device; } diff --git a/libweston/input.c b/libweston/input.c index 1652ddda4..6d6eb8a59 100644 --- a/libweston/input.c +++ b/libweston/input.c @@ -129,13 +129,15 @@ remove_input_resource_from_timestamps(struct wl_resource *input_resource, * \param syspath Unique device name. * \param backend_data Backend private data if necessary. * \param ops Calibration operations, or NULL for not able to run calibration. + * \param set_output Set output function. * \return New touch device, or NULL on failure. */ WL_EXPORT struct weston_touch_device * weston_touch_create_touch_device(struct weston_touch *touch, const char *syspath, void *backend_data, - const struct weston_touch_device_ops *ops) + const struct weston_touch_device_ops *ops, + weston_touch_device_set_output_func_t set_output) { struct weston_touch_device *device; @@ -161,6 +163,7 @@ weston_touch_create_touch_device(struct weston_touch *touch, device->backend_data = backend_data; device->ops = ops; + device->set_output = set_output; device->aggregate = touch; wl_list_insert(touch->device_list.prev, &device->link); diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c index dfd7517ec..ec04d43af 100644 --- a/libweston/libinput-device.c +++ b/libweston/libinput-device.c @@ -409,6 +409,18 @@ touch_set_calibration(struct weston_touch_device *device, do_set_calibration(evdev_device, cal); } +static void +touch_set_output(struct weston_touch_device *device, + struct weston_output *output) +{ + struct evdev_device *evdev_device = device->backend_data; + + if (!evdev_device || !output) + return; + + evdev_device_set_output(evdev_device, output); +} + static const struct weston_touch_device_ops touch_calibration_ops = { .get_output = touch_get_output, .get_calibration_head_name = touch_get_calibration_head_name, @@ -432,7 +444,8 @@ create_touch_device(struct evdev_device *device) touch_device = weston_touch_create_touch_device(device->seat->touch_state, udev_device_get_syspath(udev_device), - device, ops); + device, ops, + touch_set_output); udev_device_unref(udev_device); diff --git a/libweston/libweston-internal.h b/libweston/libweston-internal.h index bb7f08f02..eb4a8865b 100644 --- a/libweston/libweston-internal.h +++ b/libweston/libweston-internal.h @@ -480,7 +480,8 @@ struct weston_touch_device * weston_touch_create_touch_device(struct weston_touch *touch, const char *syspath, void *backend_data, - const struct weston_touch_device_ops *ops); + const struct weston_touch_device_ops *ops, + weston_touch_device_set_output_func_t set_output); void weston_touch_device_destroy(struct weston_touch_device *device); diff --git a/tests/harness/weston-test.c b/tests/harness/weston-test.c index 81b9d17e6..3acf2a36f 100644 --- a/tests/harness/weston-test.c +++ b/tests/harness/weston-test.c @@ -208,7 +208,7 @@ touch_device_add(struct weston_test *test) snprintf(buf, sizeof buf, "test-touch-device-%d", i); test->touch_device[i] = weston_touch_create_touch_device( - test->seat.touch_state, buf, NULL, NULL); + test->seat.touch_state, buf, NULL, NULL, NULL); test->nr_touch_devices++; }