Skip to content

Commit 0a37f24

Browse files
author
Robin Müller
committed
Use global vars for gesture_start and mt_slots instead of passing them as pointers to different internal functions
1 parent 43015c4 commit 0a37f24

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

src/gesture_detection.c

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ typedef struct gesture_start {
4848
uint32_t distance;
4949
} gesture_start_t;
5050

51+
mt_slots_t mt_slots;
52+
gesture_start_t gesture_start;
5153

5254
static int test_grab(int fd) {
5355
int rc;
@@ -58,17 +60,15 @@ static int test_grab(int fd) {
5860
return rc;
5961
}
6062

61-
static void init_gesture(point_t slot_points[2],
62-
uint8_t finger_count,
63-
gesture_start_t *gesture_start) {
63+
static void init_gesture(uint8_t finger_count) {
6464
int32_t x_distance, y_distance;
65-
gesture_start->point.x = slot_points[0].x;
66-
gesture_start->point.y = slot_points[0].y;
65+
gesture_start.point.x = mt_slots.points[0].x;
66+
gesture_start.point.y = mt_slots.points[0].y;
6767

6868
if (finger_count == 2) {
69-
x_distance = slot_points[0].x - slot_points[1].x;
70-
y_distance = slot_points[0].y - slot_points[1].y;
71-
gesture_start->distance = (uint32_t) sqrt((x_distance * x_distance) + (y_distance * y_distance));
69+
x_distance = mt_slots.points[0].x - mt_slots.points[1].x;
70+
y_distance = mt_slots.points[0].y - mt_slots.points[1].y;
71+
gesture_start.distance = (uint32_t) sqrt((x_distance * x_distance) + (y_distance * y_distance));
7272
}
7373
}
7474

@@ -100,17 +100,16 @@ static uint8_t process_key_event(struct input_event event) {
100100
return finger_count;
101101
}
102102

103-
static void process_abs_event(struct input_event event,
104-
mt_slots_t *mt_slots) {
103+
static void process_abs_event(struct input_event event) {
105104
if (event.code == ABS_MT_SLOT) {
106-
mt_slots->active = event.value;
107-
} else if (mt_slots->active < 2) {
105+
mt_slots.active = event.value;
106+
} else if (mt_slots.active < 2) {
108107
switch (event.code) {
109108
case ABS_MT_POSITION_X:
110-
mt_slots->points[mt_slots->active].x = event.value;
109+
mt_slots.points[mt_slots.active].x = event.value;
111110
break;
112111
case ABS_MT_POSITION_Y:
113-
mt_slots->points[mt_slots->active].y = event.value;
112+
mt_slots.points[mt_slots.active].y = event.value;
114113
break;
115114
}
116115
}
@@ -131,17 +130,15 @@ static void set_key_event(struct input_event *key_event, int code, int value) {
131130

132131
static input_event_array_t *process_syn_event(struct input_event event,
133132
configuration_t config,
134-
gesture_start_t gesture_start,
135-
point_t slot_points[2],
136133
point_t thresholds,
137134
uint8_t *finger_count) {
138135
input_event_array_t *result = NULL;
139136
if (*finger_count > 0 && event.code == SYN_REPORT) {
140137
direction_t direction = NONE;
141138

142139
int32_t x_distance, y_distance;
143-
x_distance = gesture_start.point.x - slot_points[0].x;
144-
y_distance = gesture_start.point.y - slot_points[0].y;
140+
x_distance = gesture_start.point.x - mt_slots.points[0].x;
141+
y_distance = gesture_start.point.y - mt_slots.points[0].y;
145142
if (fabs(x_distance) > fabs(y_distance)) {
146143
if (x_distance > thresholds.x) {
147144
direction = LEFT;
@@ -191,8 +188,6 @@ void process_events(int fd, configuration_t config, void (*callback)(input_event
191188
struct input_event ev[64];
192189
int i, rd;
193190
uint8_t finger_count;
194-
gesture_start_t gesture_start;
195-
mt_slots_t mt_slots;
196191

197192
point_t thresholds;
198193
thresholds.x = get_axix_threshold(fd, ABS_X, config.horz_threshold_percentage);
@@ -219,14 +214,14 @@ void process_events(int fd, configuration_t config, void (*callback)(input_event
219214
case EV_KEY:
220215
finger_count = process_key_event(ev[i]);
221216
if (finger_count > 0) {
222-
init_gesture(mt_slots.points, finger_count, &gesture_start);
217+
init_gesture(finger_count);
223218
}
224219
break;
225220
case EV_ABS:
226-
process_abs_event(ev[i], &mt_slots);
221+
process_abs_event(ev[i]);
227222
break;
228223
case EV_SYN: {
229-
input_event_array_t *input_events = process_syn_event(ev[i], config, gesture_start, mt_slots.points, thresholds, &finger_count);
224+
input_event_array_t *input_events = process_syn_event(ev[i], config, thresholds, &finger_count);
230225
callback(input_events);
231226
free(input_events);
232227
}

src/gestures_device.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ int init_uinput(int_array_t *keys) {
4646
ioctl(fd, UI_SET_EVBIT, EV_REL);
4747

4848
ioctl(fd, UI_SET_RELBIT, REL_WHEEL);
49-
50-
ioctl(fd, UI_SET_KEYBIT, BTN_LEFT);
51-
ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT);
52-
ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE);
49+
ioctl(fd, UI_SET_RELBIT, REL_HWHEEL);
5350

5451
int i;
5552
for (i = 0; i < keys->length; i++) {

0 commit comments

Comments
 (0)