Merge pull request #6469 from symless/v1-issue-6403-Mouse-drifts

Fixed mouse drift by switching from int to float
This commit is contained in:
Jnewbon 2019-04-04 11:29:07 +01:00 committed by GitHub
commit 82d5733c09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 8 deletions

View File

@ -118,7 +118,7 @@ private:
void sendClipboardEvent(Event::Type type, ClipboardID id) const; void sendClipboardEvent(Event::Type type, ClipboardID id) const;
// message handlers // 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 // 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

@ -1080,20 +1080,20 @@ OSXScreen::handleSystemEvent(const Event& event, void*)
} }
bool 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; CGFloat x = mx - m_xCursor;
SInt32 y = my - m_yCursor; CGFloat y = my - m_yCursor;
if ((x == 0 && y == 0) || (mx == m_xCenter && mx == m_yCenter)) { if ((x == 0 && y == 0) || (mx == m_xCenter && mx == m_yCenter)) {
return true; return true;
} }
// save position to compute delta of next motion // save position to compute delta of next motion
m_xCursor = mx; m_xCursor = (SInt32)mx;
m_yCursor = my; m_yCursor = (SInt32)my;
if (m_isOnScreen) { if (m_isOnScreen) {
// motion on primary screen // motion on primary screen
@ -1122,7 +1122,21 @@ OSXScreen::onMouseMove(SInt32 mx, SInt32 my)
} }
else { else {
// send motion // 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));
} }
} }