Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/platform/OSXScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OSXScreen : public PlatformScreen
void sendClipboardEvent(EventTypes type, ClipboardID id) const;

// message handlers
bool onMouseMove(CGFloat mx, CGFloat my);
bool onMouseMove();
// mouse button handler. pressed is true if this is a mousedown
// event, false if it is a mouseup event. macButton is the index
// of the button pressed using the mac button mapping.
Expand Down
17 changes: 13 additions & 4 deletions src/lib/platform/OSXScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -913,8 +913,17 @@
}
}

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);
Comment thread
nbolton marked this conversation as resolved.
CFRelease(event);
CGFloat mx = pos.x;
CGFloat my = pos.y;

LOG_DEBUG2("mouse move %+f,%+f", mx, my);

CGFloat x = mx - m_xCursor;
Expand Down Expand Up @@ -1613,7 +1622,6 @@
CGEventRef OSXScreen::handleCGInputEvent(CGEventTapProxy proxy, CGEventType type, CGEventRef event, void *refcon)
{
OSXScreen *screen = (OSXScreen *)refcon;
CGPoint pos;

switch (type) {
case kCGEventLeftMouseDown:
Expand All @@ -1630,8 +1638,9 @@
case kCGEventRightMouseDragged:
case kCGEventOtherMouseDragged:
case kCGEventMouseMoved:
pos = CGEventGetLocation(event);
screen->onMouseMove(pos.x, pos.y);
// we intentionally ignore the position in the event here as the events are
// queued and will no longer be accurate when we process them.
screen->onMouseMove();

// The system ignores our cursor-centering calls if
// we don't return the event. This should be harmless,
Expand Down