fix: Adjust OS X MouseMove handling to use live cursor position.

This commit is contained in:
Brett Lawson 2025-11-05 14:56:31 -08:00 committed by Chris Rizzitello
parent 859af720c9
commit 6a86c2990e
2 changed files with 14 additions and 5 deletions

View file

@ -111,7 +111,7 @@ private:
void sendClipboardEvent(EventTypes type, ClipboardID id) const; void sendClipboardEvent(EventTypes type, ClipboardID id) const;
// message handlers // message handlers
bool onMouseMove(CGFloat mx, CGFloat my); bool onMouseMove();
// mouse button handler. pressed is true if this is a mousedown // mouse button handler. pressed is true if this is a mousedown
// event, false if it is a mouseup event. macButton is the index // event, false if it is a mouseup event. macButton is the index
// of the button pressed using the mac button mapping. // of the button pressed using the mac button mapping.

View file

@ -913,8 +913,17 @@ void OSXScreen::handleSystemEvent(const Event &event)
} }
} }
bool OSXScreen::onMouseMove(CGFloat mx, CGFloat my) bool OSXScreen::onMouseMove()
{ {
// when we receive a mouse-move event, it is possible it was queued for a period
// and that the mouse has already moved again since then. to handle this, we need
// to query the current mouse position rather than using the position in the event.
CGEventRef event = CGEventCreate(NULL);
CGPoint pos = CGEventGetLocation(event);
CFRelease(event);
CGFloat mx = pos.x;
CGFloat my = pos.y;
LOG_DEBUG2("mouse move %+f,%+f", mx, my); LOG_DEBUG2("mouse move %+f,%+f", mx, my);
CGFloat x = mx - m_xCursor; CGFloat x = mx - m_xCursor;
@ -1613,7 +1622,6 @@ OSXScreen::handleCGInputEventSecondary(CGEventTapProxy proxy, CGEventType type,
CGEventRef OSXScreen::handleCGInputEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon) CGEventRef OSXScreen::handleCGInputEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{ {
OSXScreen *screen = (OSXScreen *)refcon; OSXScreen *screen = (OSXScreen *)refcon;
CGPoint pos;
switch (type) { switch (type) {
case kCGEventLeftMouseDown: case kCGEventLeftMouseDown:
@ -1630,8 +1638,9 @@ CGEventRef OSXScreen::handleCGInputEvent(CGEventTapProxy proxy, CGEventType type
case kCGEventRightMouseDragged: case kCGEventRightMouseDragged:
case kCGEventOtherMouseDragged: case kCGEventOtherMouseDragged:
case kCGEventMouseMoved: case kCGEventMouseMoved:
pos = CGEventGetLocation(event); // we intentionally ignore the position in the event here as the events are
screen->onMouseMove(pos.x, pos.y); // queued and will no longer be accurate when we process them.
screen->onMouseMove();
// The system ignores our cursor-centering calls if // The system ignores our cursor-centering calls if
// we don't return the event. This should be harmless, // we don't return the event. This should be harmless,