summaryrefslogtreecommitdiff
path: root/src
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
commit2f23f280d5bff3d5aa3f6115ecc05fa73b1cc2bb (patch)
tree3b6c98868b0d663c24ebfd6706922a6e99c23404 /src
parenta2ef8bcda6cd3864b4c367579defb52ecad19657 (diff)
Add rotation gesturev1.0-alpha3
Moving two fingers around a center point will trigger the gesture. This patch computes the rotation gesture and maps it to mouse buttons 14 and 15. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src')
-rw-r--r--src/gestures.c15
-rw-r--r--src/gestures.h3
-rw-r--r--src/hwdata.h4
-rw-r--r--src/multitouch.c12
4 files changed, 28 insertions, 6 deletions
diff --git a/src/gestures.c b/src/gestures.c
index 03ec96d..2dafe79 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -74,7 +74,8 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt)
74 float xm[DIM_FINGER], ym[DIM_FINGER]; 74 float xm[DIM_FINGER], ym[DIM_FINGER];
75 float xpos = 0, ypos = 0; 75 float xpos = 0, ypos = 0;
76 float move, xmove = 0, ymove = 0; 76 float move, xmove = 0, ymove = 0;
77 float rad, rad2 = 0, scale = 0; 77 float rad, rad2 = 0, scale = 0, rot = 0;
78
78 79
79 if (!nmove || nmove != npoint) 80 if (!nmove || nmove != npoint)
80 return; 81 return;
@@ -116,13 +117,23 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt)
116 rad2 += yp[i] * yp[i]; 117 rad2 += yp[i] * yp[i];
117 scale += xp[i] * xm[i]; 118 scale += xp[i] * xm[i];
118 scale += yp[i] * ym[i]; 119 scale += yp[i] * ym[i];
120 rot += xp[i] * ym[i];
121 rot -= yp[i] * xm[i];
119 } 122 }
120 rad2 /= nmove; 123 rad2 /= nmove;
121 scale /= nmove; 124 scale /= nmove;
125 rot /= nmove;
122 rad = sqrt(rad2); 126 rad = sqrt(rad2);
123 scale /= rad; 127 scale /= rad;
128 rot /= rad;
124 129
125 if (abs(scale) > move) { 130 if (abs(rot) > move && abs(rot) > abs(scale)) {
131 gs->rot = rot;
132 if (gs->rot) {
133 if (nmove == 2)
134 SETBIT(gs->type, GS_ROTATE);
135 }
136 } else if (abs(scale) > move) {
126 gs->scale = scale; 137 gs->scale = scale;
127 if (gs->scale) { 138 if (gs->scale) {
128 if (nmove == 2) 139 if (nmove == 2)
diff --git a/src/gestures.h b/src/gestures.h
index 5739d45..2866ba4 100644
--- a/src/gestures.h
+++ b/src/gestures.h
@@ -31,10 +31,11 @@
31#define GS_VSWIPE 4 31#define GS_VSWIPE 4
32#define GS_HSWIPE 5 32#define GS_HSWIPE 5
33#define GS_SCALE 6 33#define GS_SCALE 6
34#define GS_ROTATE 7
34 35
35struct Gestures { 36struct Gestures {
36 unsigned type, btmask, btdata; 37 unsigned type, btmask, btdata;
37 int same_fingers, dx, dy, scale; 38 int same_fingers, dx, dy, scale, rot;
38}; 39};
39 40
40void extract_gestures(struct Gestures *gs, struct MTouch* mt); 41void extract_gestures(struct Gestures *gs, struct MTouch* mt);
diff --git a/src/hwdata.h b/src/hwdata.h
index 867a295..42d0a19 100644
--- a/src/hwdata.h
+++ b/src/hwdata.h
@@ -24,7 +24,7 @@
24 24
25#include "common.h" 25#include "common.h"
26 26
27#define DIM_BUTTON 13 27#define DIM_BUTTON 15
28 28
29#define MT_BUTTON_LEFT 0 29#define MT_BUTTON_LEFT 0
30#define MT_BUTTON_MIDDLE 1 30#define MT_BUTTON_MIDDLE 1
@@ -39,6 +39,8 @@
39#define MT_BUTTON_SWIPE_RIGHT 10 39#define MT_BUTTON_SWIPE_RIGHT 10
40#define MT_BUTTON_SCALE_DOWN 11 40#define MT_BUTTON_SCALE_DOWN 11
41#define MT_BUTTON_SCALE_UP 12 41#define MT_BUTTON_SCALE_UP 12
42#define MT_BUTTON_ROTATE_LEFT 13
43#define MT_BUTTON_ROTATE_RIGHT 14
42 44
43#define BIT_MT_TOUCH_MAJOR 0 45#define BIT_MT_TOUCH_MAJOR 0
44#define BIT_MT_TOUCH_MINOR 1 46#define BIT_MT_TOUCH_MINOR 1
diff --git a/src/multitouch.c b/src/multitouch.c
index 6281a5b..3dde667 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -32,6 +32,7 @@ static const float hscroll_fraction = 0.05;
32static const float vswipe_fraction = 0.25; 32static const float vswipe_fraction = 0.25;
33static const float hswipe_fraction = 0.25; 33static const float hswipe_fraction = 0.25;
34static const float scale_fraction = 0.05; 34static const float scale_fraction = 0.05;
35static const float rot_fraction = 0.05;
35 36
36/* flip these to enable event debugging */ 37/* flip these to enable event debugging */
37#if 1 38#if 1
@@ -85,6 +86,8 @@ static void initButtonLabels(Atom map[DIM_BUTTON])
85 /* how to map scale and rotate? */ 86 /* how to map scale and rotate? */
86 PROPMAP(map, MT_BUTTON_SCALE_DOWN, BTN_LABEL_PROP_BTN_4); 87 PROPMAP(map, MT_BUTTON_SCALE_DOWN, BTN_LABEL_PROP_BTN_4);
87 PROPMAP(map, MT_BUTTON_SCALE_UP, BTN_LABEL_PROP_BTN_5); 88 PROPMAP(map, MT_BUTTON_SCALE_UP, BTN_LABEL_PROP_BTN_5);
89 PROPMAP(map, MT_BUTTON_ROTATE_LEFT, BTN_LABEL_PROP_BTN_6);
90 PROPMAP(map, MT_BUTTON_ROTATE_RIGHT, BTN_LABEL_PROP_BTN_7);
88} 91}
89#endif 92#endif
90 93
@@ -92,7 +95,7 @@ static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
92{ 95{
93 struct MTouch *mt = local->private; 96 struct MTouch *mt = local->private;
94 unsigned char btmap[DIM_BUTTON + 1] = { 97 unsigned char btmap[DIM_BUTTON + 1] = {
95 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 98 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
96 }; 99 };
97#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7 100#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
98 Atom axes_labels[2], btn_labels[DIM_BUTTON]; 101 Atom axes_labels[2], btn_labels[DIM_BUTTON];
@@ -213,12 +216,13 @@ static void handle_gestures(LocalDevicePtr local,
213 const struct Gestures *gs, 216 const struct Gestures *gs,
214 const struct Capabilities *caps) 217 const struct Capabilities *caps)
215{ 218{
216 static int vscroll, hscroll, vswipe, hswipe, scale; 219 static int vscroll, hscroll, vswipe, hswipe, scale, rot;
217 int vscrollstep = 1 + vscroll_fraction * get_cap_ysize(caps); 220 int vscrollstep = 1 + vscroll_fraction * get_cap_ysize(caps);
218 int hscrollstep = 1 + hscroll_fraction * get_cap_xsize(caps); 221 int hscrollstep = 1 + hscroll_fraction * get_cap_xsize(caps);
219 int vswipestep = 1 + vswipe_fraction * get_cap_ysize(caps); 222 int vswipestep = 1 + vswipe_fraction * get_cap_ysize(caps);
220 int hswipestep = 1 + hswipe_fraction * get_cap_xsize(caps); 223 int hswipestep = 1 + hswipe_fraction * get_cap_xsize(caps);
221 int scalestep = 1 + scale_fraction * get_cap_xsize(caps); 224 int scalestep = 1 + scale_fraction * get_cap_xsize(caps);
225 int rotstep = 1 + rot_fraction * get_cap_xsize(caps);
222 int i; 226 int i;
223 if (!gs->same_fingers) { 227 if (!gs->same_fingers) {
224 vscroll = 0; 228 vscroll = 0;
@@ -258,6 +262,10 @@ static void handle_gestures(LocalDevicePtr local,
258 button_scroll(local, 12, 13, &scale, scalestep, gs->scale); 262 button_scroll(local, 12, 13, &scale, scalestep, gs->scale);
259 TRACE1("scale: %d\n", gs->scale); 263 TRACE1("scale: %d\n", gs->scale);
260 } 264 }
265 if (GETBIT(gs->type, GS_ROTATE)) {
266 button_scroll(local, 14, 15, &rot, rotstep, gs->rot);
267 TRACE1("rotate: %d\n", gs->rot);
268 }
261} 269}
262 270
263/* called for each full received packet from the touchpad */ 271/* called for each full received packet from the touchpad */