aboutsummaryrefslogtreecommitdiffstats
path: root/src/gestures.c
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-05-13 23:21:37 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-05-14 01:41:39 +0200
commita2ef8bcda6cd3864b4c367579defb52ecad19657 (patch)
tree902391874bd1982f99854c33728abdee77913004 /src/gestures.c
parent32dea71a85ac1b46c35bf85f456f3c4772b30e76 (diff)
downloadxorg-input-kobomultitouch-a2ef8bcda6cd3864b4c367579defb52ecad19657.tar.gz
xorg-input-kobomultitouch-a2ef8bcda6cd3864b4c367579defb52ecad19657.tar.bz2
xorg-input-kobomultitouch-a2ef8bcda6cd3864b4c367579defb52ecad19657.zip
Add scale gesture
Moving two fingers apart or closer together will trigger the gesture. This patch computes the scaling gesture and maps it to mouse buttons 12 and 13. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/gestures.c')
-rw-r--r--src/gestures.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/gestures.c b/src/gestures.c
index 977655c..03ec96d 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -70,22 +70,32 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt)
int npoint = bitcount(mt->mem.pointing);
int nmove = bitcount(mt->mem.moving);
int i;
+ float xp[DIM_FINGER], yp[DIM_FINGER];
float xm[DIM_FINGER], ym[DIM_FINGER];
- float xmove = 0, ymove = 0;
+ float xpos = 0, ypos = 0;
+ float move, xmove = 0, ymove = 0;
+ float rad, rad2 = 0, scale = 0;
if (!nmove || nmove != npoint)
return;
foreach_bit(i, mt->mem.moving) {
+ xp[i] = mt->state.finger[i].hw.position_x - xpos;
+ yp[i] = mt->state.finger[i].hw.position_y - ypos;
xm[i] = mt->mem.dx[i];
ym[i] = mt->mem.dy[i];
mt->mem.dx[i] = 0;
mt->mem.dy[i] = 0;
+ xpos += xp[i];
+ ypos += yp[i];
xmove += xm[i];
ymove += ym[i];
}
+ xpos /= nmove;
+ ypos /= nmove;
xmove /= nmove;
ymove /= nmove;
+ move = sqrt(xmove * xmove + ymove * ymove);
if (nmove == 1) {
if (mt->mem.moving & mt->mem.thumb) {
@@ -96,6 +106,28 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt)
gs->dy = ymove;
if (gs->dx || gs->dy)
SETBIT(gs->type, GS_MOVE);
+ return;
+ }
+
+ foreach_bit(i, mt->mem.moving) {
+ xp[i] -= xpos;
+ yp[i] -= ypos;
+ rad2 += xp[i] * xp[i];
+ rad2 += yp[i] * yp[i];
+ scale += xp[i] * xm[i];
+ scale += yp[i] * ym[i];
+ }
+ rad2 /= nmove;
+ scale /= nmove;
+ rad = sqrt(rad2);
+ scale /= rad;
+
+ if (abs(scale) > move) {
+ gs->scale = scale;
+ if (gs->scale) {
+ if (nmove == 2)
+ SETBIT(gs->type, GS_SCALE);
+ }
} else {
if (mt->mem.moving & mt->mem.thumb) {
mt_skip_movement(mt, FINGER_THUMB_MS);