From e61e4c4e754f804f872e64e05c94b293b9afe47f Mon Sep 17 00:00:00 2001 From: Jens Peters Date: Fri, 29 Dec 2023 22:38:05 +0100 Subject: [PATCH] input: add rotate transformation for tablet coordinates Co-authored-by: Consolatis <35009135+Consolatis@users.noreply.github.com> --- src/input/tablet.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/input/tablet.c b/src/input/tablet.c index 14ee9566..1cbe1cde 100644 --- a/src/input/tablet.c +++ b/src/input/tablet.c @@ -11,6 +11,30 @@ #include "input/cursor.h" #include "input/tablet.h" +static void +adjust_for_rotation(enum rotation rotation, double *x, double *y) +{ + double tmp; + switch (rotation) { + case LAB_ROTATE_NONE: + break; + case LAB_ROTATE_90: + tmp = *x; + *x = 1.0 - *y; + *y = tmp; + break; + case LAB_ROTATE_180: + *x = 1.0 - *x; + *y = 1.0 - *y; + break; + case LAB_ROTATE_270: + tmp = *x; + *x = *y; + *y = 1.0 - tmp; + break; + } +} + static void handle_axis(struct wl_listener *listener, void *data) { @@ -26,6 +50,7 @@ handle_axis(struct wl_listener *listener, void *data) double x = tablet->x; double y = tablet->y; + adjust_for_rotation(rc.tablet.rotation, &x, &y); cursor_emulate_move_absolute(tablet->seat, &ev->tablet->base, x, y, ev->time_msec); } // Ignore other events