robotgo
robotgo copied to clipboard
Fixed macro definition bug in `mouse_c.h`
Please provide Issues links to:
- Issues: #696
Provide test code:
No test code needed.
Description
screengrab_c.h has a pointer implicit conversion behavior at line 93 (from void* to uint8_t *). I added an explicit conversion to it.
I found a new bug in mouse_c.h.
In line 101 definition of macro MOUSE_COORD_TO_ABS:
#define MOUSE_COORD_TO_ABS(coord, width_or_height) ( \
((65536 * coord) / width_or_height) + (coord < 0 ? -1 : 1))
It's obvious that coord and width_or_height are not wrapped by brackets.
But follow code:
int32_t x = MOUSE_COORD_TO_ABS(point.x - rect.origin.x, rect.size.w);
int32_t y = MOUSE_COORD_TO_ABS(point.y - rect.origin.y, rect.size.h);
The desired behavior is 65536 * (point.x - rect.origin.x).
But actually it's 65536 * point.x - rect.origin.x.
It's a big bug that would lead to mouse position problem as mentioned in issue #479 and issue #631 .
I don't know whether my fix could solve them completely, but it's definitely a big step forward.
Would you review this PR soon? @vcaesar
Very helpful for my project
Fixed by a most clearly code.