summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gestures.c34
-rw-r--r--src/gestures.h3
-rw-r--r--src/hwdata.h4
-rw-r--r--src/multitouch.c13
4 files changed, 49 insertions, 5 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)
70 int npoint = bitcount(mt->mem.pointing); 70 int npoint = bitcount(mt->mem.pointing);
71 int nmove = bitcount(mt->mem.moving); 71 int nmove = bitcount(mt->mem.moving);
72 int i; 72 int i;
73 float xp[DIM_FINGER], yp[DIM_FINGER];
73 float xm[DIM_FINGER], ym[DIM_FINGER]; 74 float xm[DIM_FINGER], ym[DIM_FINGER];
74 float xmove = 0, ymove = 0; 75 float xpos = 0, ypos = 0;
76 float move, xmove = 0, ymove = 0;
77 float rad, rad2 = 0, scale = 0;
75 78
76 if (!nmove || nmove != npoint) 79 if (!nmove || nmove != npoint)
77 return; 80 return;
78 81
79 foreach_bit(i, mt->mem.moving) { 82 foreach_bit(i, mt->mem.moving) {
83 xp[i] = mt->state.finger[i].hw.position_x - xpos;
84 yp[i] = mt->state.finger[i].hw.position_y - ypos;
80 xm[i] = mt->mem.dx[i]; 85 xm[i] = mt->mem.dx[i];
81 ym[i] = mt->mem.dy[i]; 86 ym[i] = mt->mem.dy[i];
82 mt->mem.dx[i] = 0; 87 mt->mem.dx[i] = 0;
83 mt->mem.dy[i] = 0; 88 mt->mem.dy[i] = 0;
89 xpos += xp[i];
90 ypos += yp[i];
84 xmove += xm[i]; 91 xmove += xm[i];
85 ymove += ym[i]; 92 ymove += ym[i];
86 } 93 }
94 xpos /= nmove;
95 ypos /= nmove;
87 xmove /= nmove; 96 xmove /= nmove;
88 ymove /= nmove; 97 ymove /= nmove;
98 move = sqrt(xmove * xmove + ymove * ymove);
89 99
90 if (nmove == 1) { 100 if (nmove == 1) {
91 if (mt->mem.moving & mt->mem.thumb) { 101 if (mt->mem.moving & mt->mem.thumb) {
@@ -96,6 +106,28 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt)
96 gs->dy = ymove; 106 gs->dy = ymove;
97 if (gs->dx || gs->dy) 107 if (gs->dx || gs->dy)
98 SETBIT(gs->type, GS_MOVE); 108 SETBIT(gs->type, GS_MOVE);
109 return;
110 }
111
112 foreach_bit(i, mt->mem.moving) {
113 xp[i] -= xpos;
114 yp[i] -= ypos;
115 rad2 += xp[i] * xp[i];
116 rad2 += yp[i] * yp[i];
117 scale += xp[i] * xm[i];
118 scale += yp[i] * ym[i];
119 }
120 rad2 /= nmove;
121 scale /= nmove;
122 rad = sqrt(rad2);
123 scale /= rad;
124
125 if (abs(scale) > move) {
126 gs->scale = scale;
127 if (gs->scale) {
128 if (nmove == 2)
129 SETBIT(gs->type, GS_SCALE);
130 }
99 } else { 131 } else {
100 if (mt->mem.moving & mt->mem.thumb) { 132 if (mt->mem.moving & mt->mem.thumb) {
101 mt_skip_movement(mt, FINGER_THUMB_MS); 133 mt_skip_movement(mt, FINGER_THUMB_MS);
diff --git a/src/gestures.h b/src/gestures.h
index 5630d4c..5739d45 100644
--- a/src/gestures.h
+++ b/src/gestures.h
@@ -30,10 +30,11 @@
30#define GS_HSCROLL 3 30#define GS_HSCROLL 3
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 34
34struct Gestures { 35struct Gestures {
35 unsigned type, btmask, btdata; 36 unsigned type, btmask, btdata;
36 int same_fingers, dx, dy; 37 int same_fingers, dx, dy, scale;
37}; 38};
38 39
39void extract_gestures(struct Gestures *gs, struct MTouch* mt); 40void extract_gestures(struct Gestures *gs, struct MTouch* mt);
diff --git a/src/hwdata.h b/src/hwdata.h
index 5dd99cf..867a295 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 11 27#define DIM_BUTTON 13
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
@@ -37,6 +37,8 @@
37#define MT_BUTTON_SWIPE_DOWN 8 37#define MT_BUTTON_SWIPE_DOWN 8
38#define MT_BUTTON_SWIPE_LEFT 9 38#define MT_BUTTON_SWIPE_LEFT 9
39#define MT_BUTTON_SWIPE_RIGHT 10 39#define MT_BUTTON_SWIPE_RIGHT 10
40#define MT_BUTTON_SCALE_DOWN 11
41#define MT_BUTTON_SCALE_UP 12
40 42
41#define BIT_MT_TOUCH_MAJOR 0 43#define BIT_MT_TOUCH_MAJOR 0
42#define BIT_MT_TOUCH_MINOR 1 44#define BIT_MT_TOUCH_MINOR 1
diff --git a/src/multitouch.c b/src/multitouch.c
index a11b8da..6281a5b 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -31,6 +31,7 @@ static const float vscroll_fraction = 0.05;
31static const float hscroll_fraction = 0.05; 31static 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;
34 35
35/* flip these to enable event debugging */ 36/* flip these to enable event debugging */
36#if 1 37#if 1
@@ -81,6 +82,9 @@ static void initButtonLabels(Atom map[DIM_BUTTON])
81 PROPMAP(map, MT_BUTTON_SWIPE_DOWN, BTN_LABEL_PROP_BTN_1); 82 PROPMAP(map, MT_BUTTON_SWIPE_DOWN, BTN_LABEL_PROP_BTN_1);
82 PROPMAP(map, MT_BUTTON_SWIPE_LEFT, BTN_LABEL_PROP_BTN_2); 83 PROPMAP(map, MT_BUTTON_SWIPE_LEFT, BTN_LABEL_PROP_BTN_2);
83 PROPMAP(map, MT_BUTTON_SWIPE_RIGHT, BTN_LABEL_PROP_BTN_3); 84 PROPMAP(map, MT_BUTTON_SWIPE_RIGHT, BTN_LABEL_PROP_BTN_3);
85 /* how to map scale and rotate? */
86 PROPMAP(map, MT_BUTTON_SCALE_DOWN, BTN_LABEL_PROP_BTN_4);
87 PROPMAP(map, MT_BUTTON_SCALE_UP, BTN_LABEL_PROP_BTN_5);
84} 88}
85#endif 89#endif
86 90
@@ -88,7 +92,7 @@ static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
88{ 92{
89 struct MTouch *mt = local->private; 93 struct MTouch *mt = local->private;
90 unsigned char btmap[DIM_BUTTON + 1] = { 94 unsigned char btmap[DIM_BUTTON + 1] = {
91 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 95 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13
92 }; 96 };
93#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7 97#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
94 Atom axes_labels[2], btn_labels[DIM_BUTTON]; 98 Atom axes_labels[2], btn_labels[DIM_BUTTON];
@@ -209,11 +213,12 @@ static void handle_gestures(LocalDevicePtr local,
209 const struct Gestures *gs, 213 const struct Gestures *gs,
210 const struct Capabilities *caps) 214 const struct Capabilities *caps)
211{ 215{
212 static int vscroll, hscroll, vswipe, hswipe; 216 static int vscroll, hscroll, vswipe, hswipe, scale;
213 int vscrollstep = 1 + vscroll_fraction * get_cap_ysize(caps); 217 int vscrollstep = 1 + vscroll_fraction * get_cap_ysize(caps);
214 int hscrollstep = 1 + hscroll_fraction * get_cap_xsize(caps); 218 int hscrollstep = 1 + hscroll_fraction * get_cap_xsize(caps);
215 int vswipestep = 1 + vswipe_fraction * get_cap_ysize(caps); 219 int vswipestep = 1 + vswipe_fraction * get_cap_ysize(caps);
216 int hswipestep = 1 + hswipe_fraction * get_cap_xsize(caps); 220 int hswipestep = 1 + hswipe_fraction * get_cap_xsize(caps);
221 int scalestep = 1 + scale_fraction * get_cap_xsize(caps);
217 int i; 222 int i;
218 if (!gs->same_fingers) { 223 if (!gs->same_fingers) {
219 vscroll = 0; 224 vscroll = 0;
@@ -249,6 +254,10 @@ static void handle_gestures(LocalDevicePtr local,
249 button_scroll(local, 10, 11, &hswipe, hswipestep, gs->dx); 254 button_scroll(local, 10, 11, &hswipe, hswipestep, gs->dx);
250 TRACE1("hswipe: %d\n", gs->dx); 255 TRACE1("hswipe: %d\n", gs->dx);
251 } 256 }
257 if (GETBIT(gs->type, GS_SCALE)) {
258 button_scroll(local, 12, 13, &scale, scalestep, gs->scale);
259 TRACE1("scale: %d\n", gs->scale);
260 }
252} 261}
253 262
254/* called for each full received packet from the touchpad */ 263/* called for each full received packet from the touchpad */