@@ -48,6 +48,8 @@ typedef struct gesture_start {
48
48
uint32_t distance ;
49
49
} gesture_start_t ;
50
50
51
+ mt_slots_t mt_slots ;
52
+ gesture_start_t gesture_start ;
51
53
52
54
static int test_grab (int fd ) {
53
55
int rc ;
@@ -58,17 +60,15 @@ static int test_grab(int fd) {
58
60
return rc ;
59
61
}
60
62
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 ) {
64
64
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 ;
67
67
68
68
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 ));
72
72
}
73
73
}
74
74
@@ -100,17 +100,16 @@ static uint8_t process_key_event(struct input_event event) {
100
100
return finger_count ;
101
101
}
102
102
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 ) {
105
104
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 ) {
108
107
switch (event .code ) {
109
108
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 ;
111
110
break ;
112
111
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 ;
114
113
break ;
115
114
}
116
115
}
@@ -131,17 +130,15 @@ static void set_key_event(struct input_event *key_event, int code, int value) {
131
130
132
131
static input_event_array_t * process_syn_event (struct input_event event ,
133
132
configuration_t config ,
134
- gesture_start_t gesture_start ,
135
- point_t slot_points [2 ],
136
133
point_t thresholds ,
137
134
uint8_t * finger_count ) {
138
135
input_event_array_t * result = NULL ;
139
136
if (* finger_count > 0 && event .code == SYN_REPORT ) {
140
137
direction_t direction = NONE ;
141
138
142
139
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 ;
145
142
if (fabs (x_distance ) > fabs (y_distance )) {
146
143
if (x_distance > thresholds .x ) {
147
144
direction = LEFT ;
@@ -191,8 +188,6 @@ void process_events(int fd, configuration_t config, void (*callback)(input_event
191
188
struct input_event ev [64 ];
192
189
int i , rd ;
193
190
uint8_t finger_count ;
194
- gesture_start_t gesture_start ;
195
- mt_slots_t mt_slots ;
196
191
197
192
point_t thresholds ;
198
193
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
219
214
case EV_KEY :
220
215
finger_count = process_key_event (ev [i ]);
221
216
if (finger_count > 0 ) {
222
- init_gesture (mt_slots . points , finger_count , & gesture_start );
217
+ init_gesture (finger_count );
223
218
}
224
219
break ;
225
220
case EV_ABS :
226
- process_abs_event (ev [i ], & mt_slots );
221
+ process_abs_event (ev [i ]);
227
222
break ;
228
223
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 );
230
225
callback (input_events );
231
226
free (input_events );
232
227
}
0 commit comments