input: add area transformation for tablet coordinates

This commit is contained in:
Jens Peters 2024-01-01 18:26:44 +01:00 committed by Johan Malm
parent f0abd9304f
commit 28e7cd3006

View file

@ -11,6 +11,34 @@
#include "input/cursor.h" #include "input/cursor.h"
#include "input/tablet.h" #include "input/tablet.h"
static void
adjust_for_tablet_area(double tablet_width, double tablet_height,
struct wlr_fbox box, double *x, double *y)
{
if ((!box.x && !box.y && !box.width && !box.height)
|| !tablet_width || !tablet_height) {
return;
}
if (!box.width) {
box.width = tablet_width - box.x;
}
if (!box.height) {
box.height = tablet_height - box.y;
}
if (box.x + box.width <= tablet_width) {
const double max_x = 1;
double width_offset = max_x * box.x / tablet_width;
*x = (*x - width_offset) * tablet_width / box.width;
}
if (box.y + box.height <= tablet_height) {
const double max_y = 1;
double height_offset = max_y * box.y / tablet_height;
*y = (*y - height_offset) * tablet_height / box.height;
}
}
static void static void
adjust_for_rotation(enum rotation rotation, double *x, double *y) adjust_for_rotation(enum rotation rotation, double *x, double *y)
{ {
@ -50,6 +78,8 @@ handle_axis(struct wl_listener *listener, void *data)
double x = tablet->x; double x = tablet->x;
double y = tablet->y; double y = tablet->y;
adjust_for_tablet_area(tablet->tablet->width_mm, tablet->tablet->height_mm,
rc.tablet.box, &x, &y);
adjust_for_rotation(rc.tablet.rotation, &x, &y); adjust_for_rotation(rc.tablet.rotation, &x, &y);
cursor_emulate_move_absolute(tablet->seat, &ev->tablet->base, x, y, ev->time_msec); cursor_emulate_move_absolute(tablet->seat, &ev->tablet->base, x, y, ev->time_msec);
} }