From 0e5a55b55bddae76d691655323dc4feb859f2870 Mon Sep 17 00:00:00 2001 From: Mohamad Rajabifard Date: Fri, 21 May 2021 23:41:33 +0430 Subject: [PATCH] Fix getMousePos for negative numbers --- src/macos/mouse.c | 4 ++-- src/types.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/macos/mouse.c b/src/macos/mouse.c index 7f4bc2b..4bcbb59 100644 --- a/src/macos/mouse.c +++ b/src/macos/mouse.c @@ -110,7 +110,7 @@ MMPoint getMousePos() CFRelease(event); CFRelease(src); - return MMPointFromCGPoint(point); + return MMSignedPointFromCGPoint(point); } /** @@ -120,7 +120,7 @@ MMPoint getMousePos() */ void toggleMouse(bool down, MMMouseButton button) { - const CGPoint currentPos = CGPointFromMMPoint(getMousePos()); + const CGPoint currentPos = CGPointFromMMSignedPoint(getMousePos()); const CGEventType mouseType = MMMouseToCGEventType(down, button); CGEventSourceRef src = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); CGEventRef event = CGEventCreateMouseEvent(src, mouseType, currentPos, (CGMouseButton)button); diff --git a/src/types.h b/src/types.h index 7dc4cde..92e07c3 100644 --- a/src/types.h +++ b/src/types.h @@ -61,6 +61,9 @@ H_INLINE MMRect MMRectMake(int64_t x, int64_t y, int64_t width, int64_t height) #define CGPointFromMMPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) #define MMPointFromCGPoint(p) MMPointMake((size_t)(p).x, (size_t)(p).y) +#define CGPointFromMMSignedPoint(p) CGPointMake((CGFloat)(p).x, (CGFloat)(p).y) +#define MMSignedPointFromCGPoint(p) MMPointMake((int32_t)(p).x, (int32_t)(p).y) + #elif defined(IS_WINDOWS) #define MMPointFromPOINT(p) MMPointMake((size_t)p.x, (size_t)p.y)