summaryrefslogtreecommitdiffstats
path: root/master/marek-d81b0fcb81100cd01728040529e90a21da5e189c
blob: 784d6d79cc4c15dd6a901573498deb14b490ccd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
diff --git a/driver/kobomultitouch_drv.c b/driver/kobomultitouch_drv.c
index bca2b51..1dbdb9d 100644
--- a/driver/kobomultitouch_drv.c
+++ b/driver/kobomultitouch_drv.c
@@ -229,9 +229,12 @@ static void handle_gestures(LocalDevicePtr local,
 		hswipe = 0;
 	}
 	foreach_bit(i, gs->btmask) {
-		xf86PostMotionEvent(local->dev, 1, 0, 2, gs->posx, gs->posy);
-		xf86PostButtonEvent(local->dev, 1,
-				    i + 1, GETBIT(gs->btdata, i), 0, 0);
+		if (GETBIT(gs->btdata, i)) {
+			xf86PostMotionEvent(local->dev, 1, 0, 2, gs->posx, gs->posy);
+			xf86PostButtonEvent(local->dev, 1, i + 1, 1, 0, 0);
+		} else {
+			xf86PostButtonEvent(local->dev, 1, i + 1, 0, 0, 0);
+		}
 	}
 	if (GETBIT(gs->type, GS_MOVE)) {
 		xf86PostMotionEvent(local->dev, 1, 0, 2, gs->posx, gs->posy);
diff --git a/src/gestures.c b/src/gestures.c
index bf19bdf..9ed2273 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -35,12 +35,13 @@ static const int BUTTON_HOLD_MS = 200;
  */
 void extract_mouse(struct Gestures *gs, struct MTouch* mt)
 {
-	int nmove = bitcount(mt->mem.moving);
+	static int tracking_id = -1;
+
+	if (mt->prev_state.nfinger == 0 && mt->state.nfinger == 1) {
+		// pressed exactly one finger
 
-	if (GETBIT(mt->mem.added, 0)) {
-		// pressed first finger
-		
 		// lmb pressed
+		tracking_id = mt->state.finger[0].tracking_id;
 		gs->posx = mt->state.finger[0].position_x;
 		gs->posy = mt->state.finger[0].position_y;
 		SETBIT(gs->btmask, MT_BUTTON_LEFT);
@@ -50,24 +51,24 @@ void extract_mouse(struct Gestures *gs, struct MTouch* mt)
 		return;
 	}
 
-	if (GETBIT(mt->mem.btdata, MT_BUTTON_LEFT) && !GETBIT(mt->mem.fingers, 0)) {
-		// released first finger
+	if (GETBIT(mt->mem.btdata, MT_BUTTON_LEFT)) {
+		// lmb is pressed
 
-		// lmb released
-		gs->posx = mt->state.finger[0].position_x;
-		gs->posy = mt->state.finger[0].position_y;
-		SETBIT(gs->btmask, MT_BUTTON_LEFT);
-		CLEARBIT(gs->btdata, MT_BUTTON_LEFT);
-		mt->mem.btdata = 0;
+		const struct FingerState *finger_state = find_finger(&mt->state, tracking_id);
 
-		return;
-	}
+		if (finger_state == NULL) {
+			// released first finger
 
-	if (GETBIT(mt->mem.btdata, MT_BUTTON_LEFT)) {
-		if (nmove == 1) {
+			// lmb released
+			tracking_id = -1;
+			SETBIT(gs->btmask, MT_BUTTON_LEFT);
+			CLEARBIT(gs->btdata, MT_BUTTON_LEFT);
+			mt->mem.btdata = 0;
+		}
+		else {
 			// mouse move
-			gs->posx = mt->state.finger[0].position_x;
-			gs->posy = mt->state.finger[0].position_y;
+			gs->posx = finger_state->position_x;
+			gs->posy = finger_state->position_y;
 			SETBIT(gs->type, GS_MOVE);
 		}
 	}
@@ -316,5 +317,5 @@ void output_gesture(const struct Gestures *gs)
 		xf86Msg(X_INFO, "rotate: %d\n", gs->rot);
 	foreach_bit(i, gs->tapmask)
 		xf86Msg(X_INFO, "tap: %d %d\n", i, gs->ntap);
-	xf86Msg(X_INFO, "+");
+	xf86Msg(X_INFO, "\n");
 }
diff --git a/src/mtstate.c b/src/mtstate.c
index e24a1e8..d2f9de5 100644
--- a/src/mtstate.c
+++ b/src/mtstate.c
@@ -103,25 +103,12 @@ const struct FingerState *find_finger(const struct MTState *s, int id)
 void output_mtstate(const struct MTState *s)
 {
 	int i;
-	xf86Msg(X_INFO, "buttons: %d%d%d\n",
-		GETBIT(s->button, MT_BUTTON_LEFT),
-		GETBIT(s->button, MT_BUTTON_MIDDLE),
-		GETBIT(s->button, MT_BUTTON_RIGHT));
-	xf86Msg(X_INFO, "fingers: %d\n",
-		s->nfinger);
-	xf86Msg(X_INFO, "evtime: %lld\n",
-		s->evtime);
+	xf86Msg(X_INFO, "-- fingers: %d, time: %lld\n",
+		s->nfinger, s->evtime);
 	for (i = 0; i < s->nfinger; i++) {
 		xf86Msg(X_INFO,
-			"  %+02d %+05d:%+05d +%05d:%+05d "
-			"%+06d %+06d %+05d:%+05d\n",
+			"   id: %+02d x: %+05d y: %+05d\n",
 			s->finger[i].tracking_id,
-			s->finger[i].touch_major,
-			s->finger[i].touch_minor,
-			s->finger[i].width_major,
-			s->finger[i].width_minor,
-			s->finger[i].orientation,
-			s->finger[i].pressure,
 			s->finger[i].position_x,
 			s->finger[i].position_y);
 	}
diff --git a/src/test.c b/src/test.c
index 5afa8b4..3597823 100644
--- a/src/test.c
+++ b/src/test.c
@@ -35,7 +35,7 @@ static void loop_device(int fd)
 		fprintf(stderr, "error: could not open device\n");
 		return;
 	}
-	while (!mtdev_idle(&mt.dev, fd, 5000)) {
+	while (1 == 1) { //(!mtdev_idle(&mt.dev, fd, 5000)) {
 		//while (read_packet(&mt, fd) > 0) {
 		//	extract_gestures(&gs, &mt);
 		//	output_gesture(&gs);