]> git.mdlowis.com Git - proto/labwc.git/commitdiff
input: fix rotation for tilt
authorJens Peters <jp7677@gmail.com>
Fri, 5 Jul 2024 04:05:35 +0000 (06:05 +0200)
committerJohan Malm <johanmalm@users.noreply.github.com>
Fri, 19 Jul 2024 21:45:41 +0000 (22:45 +0100)
The transformation for relative coordinates
is different than for absolute coordinates.

src/input/tablet.c

index d75eea0eb18aef593047ab0e4fb7b638d459c468..3475fa6e67c6ccd6dcbc3405b845926b65b5b828 100644 (file)
@@ -83,6 +83,30 @@ adjust_for_rotation(enum rotation rotation, double *x, double *y)
        }
 }
 
+static void
+adjust_for_rotation_relative(enum rotation rotation, double *dx, double *dy)
+{
+       double tmp;
+       switch (rotation) {
+       case LAB_ROTATE_NONE:
+               break;
+       case LAB_ROTATE_90:
+               tmp = *dx;
+               *dx = -*dy;
+               *dy = tmp;
+               break;
+       case LAB_ROTATE_180:
+               *dx = -*dx;
+               *dy = -*dy;
+               break;
+       case LAB_ROTATE_270:
+               tmp = *dx;
+               *dx = *dy;
+               *dy = -tmp;
+               break;
+       }
+}
+
 static struct wlr_surface*
 tablet_get_coords(struct drawing_tablet *tablet, double *x, double *y)
 {
@@ -228,6 +252,9 @@ handle_axis(struct wl_listener *listener, void *data)
                return;
        }
 
+       tablet->tilt_x = 0;
+       tablet->tilt_y = 0;
+
        if (ev->updated_axes & WLR_TABLET_TOOL_AXIS_X) {
                tablet->x = ev->x;
        }
@@ -299,7 +326,7 @@ handle_axis(struct wl_listener *listener, void *data)
                         */
                        double tilt_x = tablet->tilt_x;
                        double tilt_y = tablet->tilt_y;
-                       adjust_for_rotation(rc.tablet.rotation, &tilt_x, &tilt_y);
+                       adjust_for_rotation_relative(rc.tablet.rotation, &tilt_x, &tilt_y);
 
                        wlr_tablet_v2_tablet_tool_notify_tilt(tool->tool_v2,
                                tilt_x, tilt_y);