From 93e1a5a3904ef2f14110d8b807bcd7d107b3b2a4 Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Mon, 14 Feb 2011 12:51:01 +0100 Subject: Map device coordinates onto target surface The current implementation outputs most touch attributes in device coordinates. However, the primary use case is to map the input device onto an area on the screen, needed in particular for multihead setups. Moreover, the XI2.1 backend works with screen coordinates, creating an unnecessary discrepancy between backends. This patch adds the basic transformation layer to the utouch surface, thus serving as the master point of device-to-surface mapping. Signed-off-by: Henrik Rydberg --- src/frame.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/frame.c') diff --git a/src/frame.c b/src/frame.c index 9c4be97..e722adf 100644 --- a/src/frame.c +++ b/src/frame.c @@ -205,6 +205,25 @@ int utouch_frame_set_current_slot(utouch_frame_handle fh, int slot) return 0; } +static void transform_slot(struct utouch_contact *slot, + const struct utouch_surface *s) +{ + float fx = (s->mapped_max_x - s->mapped_min_x) / (s->max_x - s->min_x); + float fy = (s->mapped_max_y - s->mapped_min_y) / (s->max_y - s->min_y); + /* assume clipped view for asymmetrical scaling */ + float f = MAX(fx, fy); + + slot->x = fx * (slot->x - s->min_x) + s->mapped_min_x; + slot->y = fy * (slot->y - s->min_y) + s->mapped_min_y; + slot->touch_major *= f; + slot->touch_minor *= f; + slot->width_major *= f; + slot->width_minor *= f; + slot->orientation *= M_PI_2 / s->max_orient; + slot->pressure *= s->mapped_max_pressure / s->max_pressure; + slot->distance *= f; +} + static void copy_contact(utouch_frame_handle fh, struct utouch_contact *a, const struct utouch_contact *b) @@ -225,6 +244,8 @@ static void copy_contact(utouch_frame_handle fh, a->orientation = b->orientation; a->pressure = b->pressure; a->distance = b->distance; + + transform_slot(a, s); } static int detect_addrem(const struct utouch_contact *a, -- cgit v1.2.3