@@ -171,7 +171,7 @@ static double calcualte_velocity(struct input_event event1, struct input_event e
171171 return distance / time_delta ;
172172}
173173
174- static void process_abs_event (struct input_event event ) {
174+ static void process_abs_event (struct input_event event , point_t offsets ) {
175175 if (event .code == ABS_MT_SLOT ) {
176176 // store the current mt_slot
177177 mt_slots .active = event .value ;
@@ -191,7 +191,7 @@ static void process_abs_event(struct input_event event) {
191191 }
192192 mt_slots .last_points [mt_slots .active ].x = mt_slots .points [mt_slots .active ].x ;
193193 // store the current x position for the current mt_slot
194- mt_slots .points [mt_slots .active ].x = event .value ;
194+ mt_slots .points [mt_slots .active ].x = event .value - offsets . x ;
195195 break ;
196196 case ABS_MT_POSITION_Y :
197197 // if finger count matches SCROLL_FINGER_COUNT and the ABS_MT_POSITION_Y is for the first finger
@@ -205,7 +205,7 @@ static void process_abs_event(struct input_event event) {
205205 }
206206 mt_slots .last_points [mt_slots .active ].y = mt_slots .points [mt_slots .active ].y ;
207207 // store the current y position for the current mt_slot
208- mt_slots .points [mt_slots .active ].y = event .value ;
208+ mt_slots .points [mt_slots .active ].y = event .value - offsets . y ;
209209 break ;
210210 }
211211 }
@@ -315,9 +315,12 @@ static bool check_mt_slots() {
315315 if (result && finger_count > 1 ) {
316316 result = is_valid_point (mt_slots .last_points [1 ]) && is_valid_point (mt_slots .points [1 ]);
317317 }
318+
318319 return result ;
319320}
320321
322+ uint32_t syn_counter = 0 ;
323+
321324static input_event_array_t * process_syn_event (struct input_event event ,
322325 configuration_t config ,
323326 point_t thresholds ) {
@@ -415,6 +418,14 @@ static int32_t get_axix_threshold(int fd, int axis, uint8_t percentage) {
415418 return (absinfo .maximum - absinfo .minimum ) * percentage / 100 ;
416419}
417420
421+ static int32_t get_axix_offset (int fd , int axis ) {
422+ struct input_absinfo absinfo ;
423+ if (ioctl (fd , EVIOCGABS (axis ), & absinfo ) < 0 ) {
424+ return -1 ;
425+ }
426+ return absinfo .minimum ;
427+ }
428+
418429#define slowdown_scroll (velocity , thread_params ) \
419430 while (velocity != 0) { \
420431 struct timespec tim = { \
@@ -456,6 +467,10 @@ void process_events(int fd, configuration_t config, void (*callback)(input_event
456467 thresholds .x = get_axix_threshold (fd , ABS_X , config .horz_threshold_percentage );
457468 thresholds .y = get_axix_threshold (fd , ABS_Y , config .vert_threshold_percentage );
458469
470+ point_t offsets ;
471+ offsets .x = get_axix_offset (fd , ABS_X );
472+ offsets .y = get_axix_offset (fd , ABS_Y );
473+
459474 pthread_t scroll_thread = NULL ;
460475
461476 if (thresholds .x < 0 || thresholds .y < 0 ) {
@@ -500,7 +515,7 @@ void process_events(int fd, configuration_t config, void (*callback)(input_event
500515 }
501516 break ;
502517 case EV_ABS :
503- process_abs_event (ev [i ]);
518+ process_abs_event (ev [i ], offsets );
504519 break ;
505520 case EV_SYN : {
506521 input_event_array_t * input_events = process_syn_event (ev [i ], config , thresholds );
0 commit comments