summaryrefslogtreecommitdiffstats
path: root/master/marek-15901bb725ac072ca24569a27d8086924bf2888b
blob: 26c418d10b2c1059151af8913ebed509d3e0d576 (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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
diff --git a/driver/kobomultitouch_drv.c b/driver/kobomultitouch_drv.c
index 4a034c6..bca2b51 100644
--- a/driver/kobomultitouch_drv.c
+++ b/driver/kobomultitouch_drv.c
@@ -279,12 +279,17 @@ static void read_input(LocalDevicePtr local)
 {
 	struct Gestures gs;
 	struct MTouch *mt = local->private;
+
+	//while (read_packet(mt, local->fd) > 0) {
+	//	extract_gestures(&gs, mt);
+	//	handle_gestures(local, &gs, &mt->caps);
+	//}
+	//if (has_delayed_gestures(mt, local->fd)) {
+	//	extract_delayed_gestures(&gs, mt);
+	//	handle_gestures(local, &gs, &mt->caps);
+	//}
 	while (read_packet(mt, local->fd) > 0) {
-		extract_gestures(&gs, mt);
-		handle_gestures(local, &gs, &mt->caps);
-	}
-	if (has_delayed_gestures(mt, local->fd)) {
-		extract_delayed_gestures(&gs, mt);
+		extract_mouse_gestures(&gs, mt);
 		handle_gestures(local, &gs, &mt->caps);
 	}
 }
diff --git a/include/gestures.h b/include/gestures.h
index 659c95a..1ef2176 100644
--- a/include/gestures.h
+++ b/include/gestures.h
@@ -44,6 +44,7 @@ struct Gestures {
 };
 
 void extract_gestures(struct Gestures *gs, struct MTouch* mt);
+void extract_mouse_gestures(struct Gestures *gs, struct MTouch* mt);
 void extract_delayed_gestures(struct Gestures *gs, struct MTouch* mt);
 void output_gesture(const struct Gestures *gs);
 
diff --git a/src/gestures.c b/src/gestures.c
index cbc5ac6..bf19bdf 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -29,6 +29,51 @@ static const int FINGER_THUMB_MS = 600;
 static const int BUTTON_HOLD_MS = 200;
 
 /**
+ *
+ * Extract mouse gestures.
+ *
+ */
+void extract_mouse(struct Gestures *gs, struct MTouch* mt)
+{
+	int nmove = bitcount(mt->mem.moving);
+
+	if (GETBIT(mt->mem.added, 0)) {
+		// pressed first finger
+		
+		// lmb pressed
+		gs->posx = mt->state.finger[0].position_x;
+		gs->posy = mt->state.finger[0].position_y;
+		SETBIT(gs->btmask, MT_BUTTON_LEFT);
+		SETBIT(gs->btdata, MT_BUTTON_LEFT);
+		mt->mem.btdata = BITMASK(MT_BUTTON_LEFT);
+
+		return;
+	}
+
+	if (GETBIT(mt->mem.btdata, MT_BUTTON_LEFT) && !GETBIT(mt->mem.fingers, 0)) {
+		// released first finger
+
+		// 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;
+
+		return;
+	}
+
+	if (GETBIT(mt->mem.btdata, MT_BUTTON_LEFT)) {
+		if (nmove == 1) {
+			// mouse move
+			gs->posx = mt->state.finger[0].position_x;
+			gs->posy = mt->state.finger[0].position_y;
+			SETBIT(gs->type, GS_MOVE);
+		}
+	}
+}
+
+/**
  * extract_buttons
  *
  * Set the button gesture.
@@ -171,6 +216,25 @@ static void extract_movement(struct Gestures *gs, struct MTouch* mt)
 }
 
 /**
+ * extract_mouse_gestures
+ *
+ * Extract the mouse gestures.
+ *
+ * Reset memory after use.
+ *
+ */
+void extract_mouse_gestures(struct Gestures *gs, struct MTouch* mt)
+{
+	memset(gs, 0, sizeof(struct Gestures));
+
+	gs->same_fingers = mt->mem.same;
+
+	extract_mouse(gs, mt);
+
+	mt->prev_state = mt->state;
+}
+
+/**
  * extract_gestures
  *
  * Extract the gestures.
@@ -233,11 +297,10 @@ void output_gesture(const struct Gestures *gs)
 {
 	int i;
 	foreach_bit(i, gs->btmask)
-		xf86Msg(X_INFO, "button bit: %d %d\n",
-			i, GETBIT(gs->btdata, i));
+		xf86Msg(X_INFO, "button bit: %d %d (pos: %d %d)\n",
+			i, GETBIT(gs->btdata, i), gs->posx, gs->posy);
 	if (GETBIT(gs->type, GS_MOVE)) {
-		xf86Msg(X_INFO, "position: %d %d\n", gs->posx, gs->posy);
-		xf86Msg(X_INFO, "motion: %d %d\n", gs->dx, gs->dy);
+		xf86Msg(X_INFO, "position: %d %d (motion: %d %d)\n", gs->posx, gs->posy, gs->dx, gs->dy);
 	}
 	if (GETBIT(gs->type, GS_VSCROLL))
 		xf86Msg(X_INFO, "vscroll: %d\n", gs->dy);
@@ -253,4 +316,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, "+");
 }
diff --git a/src/test.c b/src/test.c
index 1b67986..5afa8b4 100644
--- a/src/test.c
+++ b/src/test.c
@@ -36,12 +36,16 @@ static void loop_device(int fd)
 		return;
 	}
 	while (!mtdev_idle(&mt.dev, fd, 5000)) {
+		//while (read_packet(&mt, fd) > 0) {
+		//	extract_gestures(&gs, &mt);
+		//	output_gesture(&gs);
+		//}
+		//if (has_delayed_gestures(&mt, fd)) {
+		//	extract_delayed_gestures(&gs, &mt);
+		//	output_gesture(&gs);
+		//}
 		while (read_packet(&mt, fd) > 0) {
-			extract_gestures(&gs, &mt);
-			output_gesture(&gs);
-		}
-		if (has_delayed_gestures(&mt, fd)) {
-			extract_delayed_gestures(&gs, &mt);
+			extract_mouse_gestures(&gs, &mt);
 			output_gesture(&gs);
 		}
 	}