Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged mouse drift fix from synergy-core #424

Merged
merged 1 commit into from
Sep 3, 2019
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 @@ -118,7 +118,7 @@ class OSXScreen : public PlatformScreen {
void sendClipboardEvent(Event::Type type, ClipboardID id) const;

// message handlers
bool onMouseMove(SInt32 mx, SInt32 my);
bool onMouseMove(CGFloat mx, CGFloat my);
// 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
28 changes: 21 additions & 7 deletions src/lib/platform/OSXScreen.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1077,20 +1077,20 @@
}

bool
OSXScreen::onMouseMove(SInt32 mx, SInt32 my)
OSXScreen::onMouseMove(CGFloat mx, CGFloat my)
{
LOG((CLOG_DEBUG2 "mouse move %+d,%+d", mx, my));
LOG((CLOG_DEBUG2 "mouse move %+f,%+f", mx, my));

SInt32 x = mx - m_xCursor;
SInt32 y = my - m_yCursor;
CGFloat x = mx - m_xCursor;
CGFloat y = my - m_yCursor;

if ((x == 0 && y == 0) || (mx == m_xCenter && mx == m_yCenter)) {
return true;
}

// save position to compute delta of next motion
m_xCursor = mx;
m_yCursor = my;
m_xCursor = (SInt32)mx;
m_yCursor = (SInt32)my;

if (m_isOnScreen) {
// motion on primary screen
Expand Down Expand Up @@ -1119,7 +1119,21 @@
}
else {
// send motion
sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), MotionInfo::alloc(x, y));
// Accumulate together the move into the running total
static CGFloat m_xFractionalMove = 0;
static CGFloat m_yFractionalMove = 0;

m_xFractionalMove += x;
m_yFractionalMove += y;

// Return the integer part
SInt32 intX = (SInt32)m_xFractionalMove;
SInt32 intY = (SInt32)m_yFractionalMove;

// And keep only the fractional part
m_xFractionalMove -= intX;
m_yFractionalMove -= intY;
sendEvent(m_events->forIPrimaryScreen().motionOnSecondary(), MotionInfo::alloc(intX, intY));
}
}

Expand Down