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 --- include/utouch/frame.h | 30 ++++++++++++++++++++++++------ src/frame-impl.h | 1 - src/frame-mtdev.c | 22 ++++++++++++---------- src/frame.c | 21 +++++++++++++++++++++ 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/include/utouch/frame.h b/include/utouch/frame.h index f136eb1..5b5f4d2 100644 --- a/include/utouch/frame.h +++ b/include/utouch/frame.h @@ -28,7 +28,7 @@ extern "C" { #include -#define UTOUCH_FRAME_VERSION 0x00001000 +#define UTOUCH_FRAME_VERSION 0x00001010 /** * struct utouch_surface - device surface details @@ -46,11 +46,23 @@ extern "C" { * @phys_width: physical width in millimeters (mm) * @phys_height: physical height in millimeters (mm) * @phys_pressure: maximal physical pressure (N/cm^2) - * @min_x: minimum horizontal coordinate value - * @min_y: minimum vertical coordinate value - * @max_x: maximum horizontal coordinate value - * @max_y: maximum vertical coordinate value - * @max_pressure: maximum pressure coordinate value + * @min_x: minimum horizontal device coordinate + * @min_y: minimum vertical device coordinate + * @max_x: maximum horizontal device coordinate + * @max_y: maximum vertical device coordinate + * @max_pressure: maximum pressure device coordinate + * @max_orient: maximum orientation device coordinate + * @mapped_min_x: minimum horizontal mapped coordinate + * @mapped_min_y: minimum vertical mapped coordinate + * @mapped_max_x: maximum horizontal mapped coordinate + * @mapped_max_y: maximum vertical mapped coordinate + * @mapped_max_pressure: maximum pressure mapped coordinate + * + * The mutable contact given by utouch_frame_get_current_slot() should + * be set in device coordinates. The contact data is subsequently + * transformed to mapped (e.g., screen) coordinates in + * utouch_frame_sync(). To a frame user, all data will appear in + * mapped coordinates. * * Device properties and touch surface details. Later versions of this * struct may grow in size, but will remain binary compatible with @@ -76,6 +88,12 @@ struct utouch_surface { float max_x; float max_y; float max_pressure; + float max_orient; + float mapped_min_x; + float mapped_min_y; + float mapped_max_x; + float mapped_max_y; + float mapped_max_pressure; }; #define UTOUCH_TOOL_FINGER 0 diff --git a/src/frame-impl.h b/src/frame-impl.h index 63cbc7c..38affe7 100644 --- a/src/frame-impl.h +++ b/src/frame-impl.h @@ -30,7 +30,6 @@ struct utouch_frame_engine { int hold_ms; int frame; int slot; - float max_orient; struct utouch_surface *surface; struct utouch_frame **frames; struct utouch_frame *next; diff --git a/src/frame-mtdev.c b/src/frame-mtdev.c index 9192510..caf90ae 100644 --- a/src/frame-mtdev.c +++ b/src/frame-mtdev.c @@ -104,12 +104,12 @@ int utouch_frame_init_mtdev(utouch_frame_handle fh, } s->max_pressure = evemu_get_abs_maximum(dev, ABS_MT_PRESSURE); - if (s->use_pressure && s->max_pressure == 0) + if (s->max_pressure == 0) s->max_pressure = 256; - fh->max_orient = evemu_get_abs_maximum(dev, ABS_MT_ORIENTATION); - if (s->use_orientation && fh->max_orient == 0) - fh->max_orient = 1; + s->max_orient = evemu_get_abs_maximum(dev, ABS_MT_ORIENTATION); + if (s->max_orient == 0) + s->max_orient = 1; tmp = evemu_get_abs_resolution(dev, ABS_MT_POSITION_X); if (tmp > 0) @@ -133,12 +133,14 @@ int utouch_frame_init_mtdev(utouch_frame_handle fh, else s->phys_pressure = 10; - return 0; -} + /* defaults expected by initial frame version */ + s->mapped_min_x = s->min_x; + s->mapped_min_y = s->min_y; + s->mapped_max_x = s->max_x; + s->mapped_max_y = s->max_y; + s->mapped_max_pressure = s->max_pressure; -static float touch_angle(utouch_frame_handle fh, int orient) -{ - return orient / fh->max_orient * M_PI_2; + return 0; } static int handle_abs_event(utouch_frame_handle fh, @@ -169,7 +171,7 @@ static int handle_abs_event(utouch_frame_handle fh, t->width_minor = ev->value; return 1; case ABS_MT_ORIENTATION: - t->orientation = touch_angle(fh, ev->value); + t->orientation = ev->value; return 1; case ABS_MT_PRESSURE: t->pressure = ev->value; 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