summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common.h3
-rw-r--r--src/hwdata.h1
-rw-r--r--src/multitouch.c2
-rw-r--r--src/state.c72
-rw-r--r--src/state.h3
5 files changed, 72 insertions, 9 deletions
diff --git a/src/common.h b/src/common.h
index 5a83f95..c57ae1a 100644
--- a/src/common.h
+++ b/src/common.h
@@ -7,6 +7,7 @@
7#include <xf86Xinput.h> 7#include <xf86Xinput.h>
8#include <linux/input.h> 8#include <linux/input.h>
9#include <errno.h> 9#include <errno.h>
10#include <match/match.h>
10//#include <exevents.h> 11//#include <exevents.h>
11 12
12//////////////////////////////////////////////////////// 13////////////////////////////////////////////////////////
@@ -27,8 +28,6 @@
27#define ABS_MT_POSITION_X 0x35 28#define ABS_MT_POSITION_X 0x35
28#define ABS_MT_POSITION_Y 0x36 29#define ABS_MT_POSITION_Y 0x36
29 30
30typedef int bool;
31
32#define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) 31#define SYSCALL(call) while (((call) == -1) && (errno == EINTR))
33 32
34//////////////////////////////////////////////////////// 33////////////////////////////////////////////////////////
diff --git a/src/hwdata.h b/src/hwdata.h
index 239e022..59cff0d 100644
--- a/src/hwdata.h
+++ b/src/hwdata.h
@@ -3,7 +3,6 @@
3 3
4#include "common.h" 4#include "common.h"
5 5
6#define DIM_FINGER 16
7#define DIM_BUTTON 3 6#define DIM_BUTTON 3
8 7
9#define MT_BUTTON_LEFT 0 8#define MT_BUTTON_LEFT 0
diff --git a/src/multitouch.c b/src/multitouch.c
index f6e3d05..21f3e1e 100644
--- a/src/multitouch.c
+++ b/src/multitouch.c
@@ -82,7 +82,7 @@ static void read_input(LocalDevicePtr local)
82 if (local->fd >= 0) { 82 if (local->fd >= 0) {
83 while (read_synchronized_event(mt, local->fd)) { 83 while (read_synchronized_event(mt, local->fd)) {
84 modify_state(&mt->ns, &mt->hw); 84 modify_state(&mt->ns, &mt->hw);
85 // and something in between here 85 output_state(&mt->ns);
86 mt->os = mt->ns; 86 mt->os = mt->ns;
87 } 87 }
88 } 88 }
diff --git a/src/state.c b/src/state.c
index 46b7fef..fc3580d 100644
--- a/src/state.c
+++ b/src/state.c
@@ -1,4 +1,5 @@
1#include "state.h" 1#include "state.h"
2#include <stdlib.h>
2 3
3/******************************************************/ 4/******************************************************/
4 5
@@ -9,11 +10,58 @@ void init_state(struct State *s)
9 10
10/******************************************************/ 11/******************************************************/
11 12
13inline int fincomp(const struct FingerState* a,const struct FingerState* b)
14{
15 return a->id - b->id;
16}
17
18inline float dist2(const struct FingerData* a,const struct FingerData* b)
19{
20 float dx = a->position_x - b->position_x;
21 float dy = a->position_y - b->position_y;
22
23 return dx * dx + dy * dy;
24}
25
12void modify_state(struct State *s, const struct HWData* hw) 26void modify_state(struct State *s, const struct HWData* hw)
13{ 27{
14 int i; 28 float A[DIM2_FINGER], *row;
15 if (s->button[0] != hw->button[0]) 29 int id[DIM_FINGER], index[DIM_FINGER], i, j;
16 xf86Msg(X_INFO, "multitouch: button changed\n"); 30
31 for (j = 0; j < s->nfinger; j++) {
32 id[j] = s->finger[j].id;
33 row = A + hw->nfinger * j;
34 for (i = 0; i < hw->nfinger; i++)
35 row[i] = dist2(&hw->finger[i], &s->finger[j].hw);
36 }
37
38 match_fingers(index, A, hw->nfinger, s->nfinger);
39
40 s->nfinger = 0;
41
42 /* update matched fingers */
43 for (i = 0; i < hw->nfinger; i++) {
44 if ((j = index[i]) >= 0) {
45 s->finger[s->nfinger].id = id[j];
46 s->finger[s->nfinger].hw = hw->finger[i];
47 s->nfinger++;
48 }
49 }
50
51 /* create new fingers */
52 for (i = 0; i < hw->nfinger; i++) {
53 if (index[i] < 0) {
54 s->finger[s->nfinger].id = ++s->lastid;
55 s->finger[s->nfinger].hw = hw->finger[i];
56 s->nfinger++;
57 }
58 }
59
60 /* sort fingers in touching order */
61 qsort(s->finger, s->nfinger, sizeof(struct FingerState),
62 (int (*)(const void*,const void*))fincomp);
63
64 /* copy buttons */
17 for (i = 0; i < DIM_BUTTON; i++) 65 for (i = 0; i < DIM_BUTTON; i++)
18 s->button[i] = hw->button[i]; 66 s->button[i] = hw->button[i];
19} 67}
@@ -23,9 +71,11 @@ void modify_state(struct State *s, const struct HWData* hw)
23const struct FingerState *find_finger(const struct State *s, int id) 71const struct FingerState *find_finger(const struct State *s, int id)
24{ 72{
25 int i; 73 int i;
74
26 for (i = 0; i < s->nfinger; i++) 75 for (i = 0; i < s->nfinger; i++)
27 if (s->finger[i].id == id) 76 if (s->finger[i].id == id)
28 return s->finger+i; 77 return s->finger + i;
78
29 return NULL; 79 return NULL;
30} 80}
31 81
@@ -33,6 +83,20 @@ const struct FingerState *find_finger(const struct State *s, int id)
33 83
34void output_state(const struct State *s) 84void output_state(const struct State *s)
35{ 85{
86 int i;
87 printf("buttons: %d%d%d\n", s->button[0], s->button[1], s->button[2]);
88 printf("fingers: %d\n", s->nfinger);
89 for (i = 0; i < s->nfinger; i++) {
90 printf(" %+02d %+05d:%+05d +%05d:%+05d %+05d %+05d:%+05d\n",
91 s->finger[i].id,
92 s->finger[i].hw.touch_major,
93 s->finger[i].hw.touch_minor,
94 s->finger[i].hw.width_major,
95 s->finger[i].hw.width_minor,
96 s->finger[i].hw.orientation,
97 s->finger[i].hw.position_x,
98 s->finger[i].hw.position_y);
99 }
36} 100}
37 101
38/******************************************************/ 102/******************************************************/
diff --git a/src/state.h b/src/state.h
index 9c36617..8b41920 100644
--- a/src/state.h
+++ b/src/state.h
@@ -14,7 +14,8 @@ struct FingerState {
14 14
15struct State { 15struct State {
16 struct FingerState finger[DIM_FINGER]; 16 struct FingerState finger[DIM_FINGER];
17 int nfinger, button[DIM_BUTTON]; 17 int button[DIM_BUTTON];
18 int nfinger, lastid;
18}; 19};
19 20
20//////////////////////////////////////////////////////// 21////////////////////////////////////////////////////////