From: Louis-Francis Ratté-Boulianne <l...@collabora.com>

Add an option to enable the touchscreen calibrator interface. This is a
global on/off toggle, in lack of more fine-grained access restrictions.

As Weston should not hardcode system specifics, the actual permanent
saving of a new calibration is left for a user supplied script or a
program. Usually this script would write an appropriate udev rule to set
LIBINPUT_CALIBRATION_MATRIX for the touch device.

Co-developed by Louis-Francis and Pekka.

Signed-off-by: Louis-Francis Ratté-Boulianne <l...@collabora.com>
Signed-off-by: Pekka Paalanen <pekka.paala...@collabora.co.uk>
---
 compositor/main.c  | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 man/weston.ini.man | 36 +++++++++++++++++++++++++++++
 2 files changed, 104 insertions(+)

diff --git a/compositor/main.c b/compositor/main.c
index 6650676a..caea25b9 100644
--- a/compositor/main.c
+++ b/compositor/main.c
@@ -792,6 +792,64 @@ load_modules(struct weston_compositor *ec, const char 
*modules,
        return 0;
 }
 
+static int
+save_touch_device_calibration(struct weston_compositor *compositor,
+                             struct weston_touch_device *device,
+                             const struct weston_touch_device_matrix 
*calibration)
+{
+       struct weston_config_section *s;
+       struct weston_config *config = wet_get_config(compositor);
+       char *helper = NULL;
+       char *helper_cmd = NULL;
+       int ret = -1;
+       int status;
+       const float *m = calibration->m;
+
+       s = weston_config_get_section(config,
+                                     "libinput", NULL, NULL);
+
+       weston_config_section_get_string(s, "calibration_helper",
+                                        &helper, NULL);
+
+       if (!helper || strlen(helper) == 0) {
+               ret = 0;
+               goto out;
+       }
+
+       if (asprintf(&helper_cmd, "\"%s\" '%s' %f %f %f %f %f %f",
+                    helper, device->devpath,
+                    m[0], m[1], m[2],
+                    m[3], m[4], m[5]) < 0)
+               goto out;
+
+       status = system(helper_cmd);
+       free(helper_cmd);
+
+       if (status < 0) {
+               weston_log("Error: failed to run calibration helper '%s'.\n",
+                          helper);
+               goto out;
+       }
+
+       if (!WIFEXITED(status)) {
+               weston_log("Error: calibration helper '%s' possibly killed.\n",
+                          helper);
+               goto out;
+       }
+
+       if (WEXITSTATUS(status) == 0) {
+               ret = 0;
+       } else {
+               weston_log("Calibration helper '%s' exited with status %d.\n",
+                          helper, WEXITSTATUS(status));
+       }
+
+out:
+       free(helper);
+
+       return ret;
+}
+
 static int
 weston_compositor_init_config(struct weston_compositor *ec,
                              struct weston_config *config)
@@ -800,7 +858,9 @@ weston_compositor_init_config(struct weston_compositor *ec,
        struct weston_config_section *s;
        int repaint_msec;
        int vt_switching;
+       int cal;
 
+       /* weston.ini [keyboard] */
        s = weston_config_get_section(config, "keyboard", NULL, NULL);
        weston_config_section_get_string(s, "keymap_rules",
                                         (char **) &xkb_names.rules, NULL);
@@ -825,6 +885,7 @@ weston_compositor_init_config(struct weston_compositor *ec,
                                       &vt_switching, true);
        ec->vt_switching = vt_switching;
 
+       /* weston.ini [core] */
        s = weston_config_get_section(config, "core", NULL, NULL);
        weston_config_section_get_int(s, "repaint-window", &repaint_msec,
                                      ec->repaint_msec);
@@ -837,6 +898,13 @@ weston_compositor_init_config(struct weston_compositor *ec,
        weston_log("Output repaint window is %d ms maximum.\n",
                   ec->repaint_msec);
 
+       /* weston.ini [libinput] */
+       s = weston_config_get_section(config, "libinput", NULL, NULL);
+       weston_config_section_get_bool(s, "touchscreen_calibrator", &cal, 0);
+       if (cal)
+               weston_compositor_enable_touch_calibrator(ec,
+                                               save_touch_device_calibration);
+
        return 0;
 }
 
diff --git a/man/weston.ini.man b/man/weston.ini.man
index f237fd60..2d261fb9 100644
--- a/man/weston.ini.man
+++ b/man/weston.ini.man
@@ -200,8 +200,44 @@ Available configuration are:
 .TP 7
 .BI "enable_tap=" true
 enables tap to click on touchpad devices
+.TP 7
+.BI "touchscreen_calibrator=" true
+Advertise the touchscreen calibrator interface to all clients. This is a
+potential denial-of-service attack vector, so it should only be enabled on
+trusted userspace. Boolean, defaults to
+.BR false .
+
+The interface is required for running touchscreen calibrator applications. It
+provides the application raw touch events, bypassing the normal touch handling.
+It also allows the application to upload a new calibration into the compositor.
+
+Even though this option is listed in the libinput section, it does affect all
+Weston configurations regardless of the used backend. If the backend does not
+use libinput, the interface can still be advertised, but it will not list any
+devices.
+.TP 7
+.BI "calibration_helper=" /bin/echo
+An optional calibration helper program to permanently save a new touchscreen
+calibration. String, defaults to unset.
+
+The given program will be executed with seven arguments when a calibrator
+application requests the server to take a new calibration matrix into use.
+The program is executed synchronously and will therefore block Weston for its
+duration. If the program exit status is non-zero, Weston will not apply the
+new calibration. If the helper is unset or the program exit status is zero,
+Weston will use the new calibration immediately.
+
+The program is invoked as:
+.PP
+.RS 10
+.I calibration_helper devpath m1 m2 m3 m4 m5 m6
+.RE
 .RS
 .PP
+.RI "where " devpath " is the udev devpath and " m1 "  through " m6
+are the calibration matrix elements in libinput's
+.BR LIBINPUT_CALIBRATION_MATRIX " udev property format."
+.RE
 
 .SH "SHELL SECTION"
 The
-- 
2.16.1

_______________________________________________
wayland-devel mailing list
wayland-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to