]> git.mdlowis.com Git - proto/labwc.git/commitdiff
Add mouse emulation for touch devices (#2277)
authorSimon Long <simon@raspberrypi.com>
Tue, 29 Oct 2024 19:22:01 +0000 (19:22 +0000)
committerGitHub <noreply@github.com>
Tue, 29 Oct 2024 19:22:01 +0000 (19:22 +0000)
docs/labwc-config.5.scd
docs/rc.xml.all
include/config/touch.h
src/config/rcxml.c
src/input/touch.c

index 6c073c85cbe72198472774cf1074e6fc881b5a76..636172e7e1c464c512364301c4383af822d468c4 100644 (file)
@@ -690,7 +690,7 @@ extending outward from the snapped edge.
 ## TOUCH
 
 ```
-<touch deviceName="" mapToOutput="" />
+<touch deviceName="" mapToOutput="" mouseEmulation="no"/>
 ```
 
 *<touch deviceName="" />*
@@ -704,6 +704,10 @@ extending outward from the snapped edge.
        Direct cursor movement to a specified output. If the compositor is
        running in nested mode, this does not take effect.
 
+*<touch mouseEmulation="" />*
+       If mouseEmulation is enabled, all touch up/down/motion events are
+       translated to mouse button and motion events.
+
 ## TABLET
 
 ```
index 10e0bd80d6693003fc3c20f51d27d6517f84bd9c..b1a8bae6a88119795a029b5715b37c9165e71921 100644 (file)
 
     Direct cursor movement to a specified output. If the compositor is
     running in nested mode, this does not take effect.
+
+    If mouseEmulation is enabled, all touch up/down/motion events are
+    translated to mouse button and motion events.
   -->
-  <touch deviceName="" mapToOutput="" />
+  <touch deviceName="" mapToOutput="" mouseEmulation="no"/>
 
   <!--
     The tablet cursor movement can be restricted to a single output.
index e9880820857209b417287736a4242a07107b6b3b..12f7b032de17303f0b7e5b9b4586f8c18f0a342f 100644 (file)
@@ -8,6 +8,7 @@
 struct touch_config_entry {
        char *device_name;
        char *output_name;
+       bool force_mouse_emulation;
 
        struct wl_list link;     /* struct rcxml.touch_configs */
 };
index ab221c1be51f585e187c0dcbed5471dee6f7e8f9..d6d9c76fcd4a331bd37f915a070472ea2b8b30ea 100644 (file)
@@ -633,6 +633,8 @@ fill_touch(char *nodename, char *content)
                current_touch->device_name = xstrdup(content);
        } else if (!strcasecmp(nodename, "mapToOutput.touch")) {
                current_touch->output_name = xstrdup(content);
+       } else if (!strcasecmp(nodename, "mouseEmulation.touch")) {
+               set_bool(content, &current_touch->force_mouse_emulation);
        } else {
                wlr_log(WLR_ERROR, "Unexpected data in touch parser: %s=\"%s\"",
                        nodename, content);
index f99b013ed1b90d1174ab85e31a840fc0409dc00d..8557d9c7bead8a0302f97d4315a6ec6ab65911d7 100644 (file)
@@ -24,6 +24,17 @@ static struct wlr_surface*
 touch_get_coords(struct seat *seat, struct wlr_touch *touch, double x, double y,
                double *x_offset, double *y_offset)
 {
+       /*
+        * Do not return a surface when mouse emulation is enforced. Not
+        * having a surface will trigger the fallback to cursor move/button
+        * emulation in the touch signal handlers.
+        */
+       struct touch_config_entry *config_entry =
+               touch_find_config_for_device(touch->base.name);
+       if (config_entry && config_entry->force_mouse_emulation) {
+               return NULL;
+       }
+
        /* Convert coordinates: first [0, 1] => layout, then layout => surface */
        double lx, ly;
        wlr_cursor_absolute_to_layout_coords(seat->cursor, &touch->base,
@@ -93,7 +104,7 @@ handle_touch_down(struct wl_listener *listener, void *data)
 
        /* Compute layout => surface offset and save for this touch point */
        struct touch_point *touch_point = znew(*touch_point);
-       double x_offset, y_offset;
+       double x_offset = 0.0, y_offset = 0.0;
        touch_point->surface = touch_get_coords(seat, event->touch,
                        event->x, event->y, &x_offset, &y_offset);
        touch_point->touch_id = event->touch_id;