linuxOS_AP06/buildroot/package/weston/0031-Support-setting-touch-calibration-through-environmen.patch
2025-06-03 12:28:32 +08:00

117 lines
3.4 KiB
Diff

From 81336eb8b33cbff94f347f6bbf003ee8542c1897 Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Tue, 4 Aug 2020 14:30:33 +0800
Subject: [PATCH 31/95] Support setting touch calibration through environment
Tested on RK3588 EVB with:
1/ killall weston
2/ WESTON_TOUCH_CALIBRATION="1 0 0 0 0.5 0" /usr/bin/weston
3/ WESTON_TOUCH_CALIBRATION="event7:1 0 0 0 0.5 0" /usr/bin/weston
4/ WESTON_TOUCH_CALIBRATION="1 0 0 0 0.5 0,event7:0.5 0 0 0 1 0" /usr/bin/weston
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
clients/calibrator.c | 9 +++++++++
clients/touch-calibrator.c | 12 ++++++++----
libweston/libinput-device.c | 29 +++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 4 deletions(-)
diff --git a/clients/calibrator.c b/clients/calibrator.c
index be65d9b..20fc1e7 100644
--- a/clients/calibrator.c
+++ b/clients/calibrator.c
@@ -106,6 +106,7 @@ finish_calibration (struct calibrator *calibrator)
struct weston_matrix m;
struct weston_matrix inverse;
struct weston_vector x_calib, y_calib;
+ struct rectangle allocation;
int i;
@@ -141,6 +142,14 @@ finish_calibration (struct calibrator *calibrator)
x_calib.f[0], x_calib.f[1], x_calib.f[2],
y_calib.f[0], y_calib.f[1], y_calib.f[2]);
+ widget_get_allocation(calibrator->widget, &allocation);
+ x_calib.f[2] /= allocation.width;
+ y_calib.f[2] /= allocation.height;
+
+ printf ("Final calibration values: %f %f %f %f %f %f\n",
+ x_calib.f[0], x_calib.f[1], x_calib.f[2],
+ y_calib.f[0], y_calib.f[1], y_calib.f[2]);
+
exit(0);
}
diff --git a/clients/touch-calibrator.c b/clients/touch-calibrator.c
index a15b941..815b89a 100644
--- a/clients/touch-calibrator.c
+++ b/clients/touch-calibrator.c
@@ -772,15 +772,19 @@ touch_device_handler(void *data, struct weston_touch_calibration *c,
if (!cal->match_name) {
printf("device \"%s\" - head \"%s\"\n", device, head);
- return;
- }
- if (cal->device_name)
+ if (!cal->device_name)
+ cal->device_name = strdup(device);
return;
+ }
if (strcmp(cal->match_name, device) == 0 ||
- strcmp(cal->match_name, head) == 0)
+ strcmp(cal->match_name, head) == 0) {
+ if (cal->device_name)
+ free(cal->device_name);
+
cal->device_name = strdup(device);
+ }
}
struct weston_touch_calibration_listener touch_calibration_listener = {
diff --git a/libweston/libinput-device.c b/libweston/libinput-device.c
index 31b88ac..0d9ba2e 100644
--- a/libweston/libinput-device.c
+++ b/libweston/libinput-device.c
@@ -887,6 +887,35 @@ evdev_device_set_calibration(struct evdev_device *device)
return;
}
+ calibration_values = getenv("WESTON_TOUCH_CALIBRATION");
+ if (calibration_values) {
+ const char *values;
+ char prefix[256];
+
+ snprintf(prefix, sizeof(prefix), "%s:",
+ libinput_device_get_name(device->device));
+ if ((values = strstr(calibration_values, prefix))) {
+ values += strlen(prefix);
+ } else {
+ snprintf(prefix, sizeof(prefix), "%s:", sysname);
+ if ((values = strstr(calibration_values, prefix)))
+ values += strlen(prefix);
+ else
+ values = calibration_values;
+ }
+
+ if ((sscanf(values, "%f %f %f %f %f %f",
+ &calibration.m[0],
+ &calibration.m[1],
+ &calibration.m[2],
+ &calibration.m[3],
+ &calibration.m[4],
+ &calibration.m[5]) == 6)) {
+ do_set_calibration(device, &calibration);
+ return;
+ }
+ }
+
width = device->output->width;
height = device->output->height;
if (width == 0 || height == 0)
--
2.20.1