Skip to content

Commit f34437d

Browse files
author
Robin Müller
committed
Let process_syn_events return an array of input_event
- the method process_syn_events return now an array of input_events containing the keys/events for the detected gesture
1 parent d32da59 commit f34437d

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

src/gesture_detection.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@
2626
#include <stdio.h>
2727
#include <unistd.h>
2828
#include <math.h>
29+
#include <string.h>
30+
#include <stdlib.h>
2931

3032
#include <linux/input.h>
3133

3234
#include "gesture_detection.h"
35+
#include "input_event_array.h"
3336

3437
typedef struct point {
3538
int x;
@@ -115,12 +118,13 @@ static void process_abs_event(struct input_event event,
115118
}
116119
}
117120

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;
124128
if (*finger_count > 0 && event.code == SYN_REPORT) {
125129
direction_t direction = NONE;
126130

@@ -141,18 +145,22 @@ static void process_syn_event(struct input_event event,
141145
}
142146
}
143147
if (direction != NONE) {
144-
printf("fingers: %d, direction: %d\n", *finger_count, direction);
145148
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];
148151
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;
150158
}
151159
}
152-
printf("\n");
153160
*finger_count = 0;
154161
}
155162
}
163+
return result ? result : new_input_event_array(0);
156164
}
157165

158166
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) {
201209
case EV_ABS:
202210
process_abs_event(ev[i], &mt_slots);
203211
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+
}
206223
break;
207224
}
208225
}

0 commit comments

Comments
 (0)