robotgo icon indicating copy to clipboard operation
robotgo copied to clipboard

Fixed macro definition bug in `mouse_c.h`

Open xuehaonan27 opened this issue 1 year ago • 2 comments

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.

xuehaonan27 avatar Oct 08 '24 03:10 xuehaonan27

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Oct 08 '24 03:10 CLAassistant

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.

xuehaonan27 avatar Oct 10 '24 12:10 xuehaonan27

Would you review this PR soon? @vcaesar

xuehaonan27 avatar Dec 03 '24 02:12 xuehaonan27

Very helpful for my project

PekingSpades avatar Dec 07 '24 04:12 PekingSpades

Fixed by a most clearly code.

vcaesar avatar Mar 08 '25 23:03 vcaesar