26
26
#include <stdio.h>
27
27
#include <unistd.h>
28
28
#include <math.h>
29
+ #include <string.h>
30
+ #include <stdlib.h>
29
31
30
32
#include <linux/input.h>
31
33
32
34
#include "gesture_detection.h"
35
+ #include "input_event_array.h"
33
36
34
37
typedef struct point {
35
38
int x ;
@@ -115,12 +118,13 @@ static void process_abs_event(struct input_event event,
115
118
}
116
119
}
117
120
118
- static void process_syn_event (struct input_event event ,
119
- configuration_t config ,
120
- gesture_start_t gesture_start ,
121
- point_t slot_points [2 ],
122
- point_t thresholds ,
123
- uint8_t * finger_count ) {
121
+ static input_event_array_t * process_syn_event (struct input_event event ,
122
+ configuration_t config ,
123
+ gesture_start_t gesture_start ,
124
+ point_t slot_points [2 ],
125
+ point_t thresholds ,
126
+ uint8_t * finger_count ) {
127
+ input_event_array_t * result = NULL ;
124
128
if (* finger_count > 0 && event .code == SYN_REPORT ) {
125
129
direction_t direction = NONE ;
126
130
@@ -141,18 +145,22 @@ static void process_syn_event(struct input_event event,
141
145
}
142
146
}
143
147
if (direction != NONE ) {
144
- printf ("fingers: %d, direction: %d\n" , * finger_count , direction );
145
148
uint8_t i ;
146
- for (i = 0 ; i < MAX_KEYS_PER_GESTURE ; i ++ ) {
147
- int key = config .swipe_keys [* finger_count ][direction ].keys [i ];
149
+ for (i = MAX_KEYS_PER_GESTURE ; i > 0 ; i -- ) {
150
+ int key = config .swipe_keys [* finger_count ][direction ].keys [i - 1 ];
148
151
if (key > 0 ) {
149
- printf ("%d " , key );
152
+ if (!result ) {
153
+ result = new_input_event_array (i );
154
+ }
155
+ memset (& result -> data [i - 1 ], 0 , sizeof (struct input_event ));
156
+ result -> data [i - 1 ].type = EV_KEY ;
157
+ result -> data [i - 1 ].code = key ;
150
158
}
151
159
}
152
- printf ("\n" );
153
160
* finger_count = 0 ;
154
161
}
155
162
}
163
+ return result ? result : new_input_event_array (0 );
156
164
}
157
165
158
166
static int32_t get_axix_threshold (int fd , int axis , uint8_t percentage ) {
@@ -201,8 +209,17 @@ void process_events(int fd, configuration_t config) {
201
209
case EV_ABS :
202
210
process_abs_event (ev [i ], & mt_slots );
203
211
break ;
204
- case EV_SYN :
205
- process_syn_event (ev [i ], config , gesture_start , mt_slots .points , thresholds , & finger_count );
212
+ case EV_SYN : {
213
+ input_event_array_t * input_events = process_syn_event (ev [i ], config , gesture_start , mt_slots .points , thresholds , & finger_count );
214
+ int i ;
215
+ for (i = 0 ; i < input_events -> length ; i ++ ) {
216
+ printf ("%s%d" , i > 0 ? " + " : "" , input_events -> data [i ].code );
217
+ }
218
+ if (input_events -> length ) {
219
+ printf ("\n" );
220
+ }
221
+ free (input_events );
222
+ }
206
223
break ;
207
224
}
208
225
}
0 commit comments