# HG changeset patch # User Michael Lutz # Date 2021-02-07 13:00:59 # Node ID e3830561ecd196094ffd3dcee5d5a189c06b992e # Parent ede24664c30a3c7e90f76ea639f2817234b69f1a Codechange: [OSX] Use relative mouse handling during scrolling. diff --git a/src/video/cocoa/cocoa_wnd.mm b/src/video/cocoa/cocoa_wnd.mm --- a/src/video/cocoa/cocoa_wnd.mm +++ b/src/video/cocoa/cocoa_wnd.mm @@ -524,20 +524,23 @@ void CocoaDialog(const char *title, cons - (void)internalMouseMoveEvent:(NSEvent *)event { - NSPoint pt = [ self mousePositionFromEvent:event ]; + if (_cursor.fix_at) { + _cursor.UpdateCursorPositionRelative(event.deltaX, event.deltaY); + } else { + NSPoint pt = [ self mousePositionFromEvent:event ]; + _cursor.UpdateCursorPosition(pt.x, pt.y, false); + } - if (_cursor.UpdateCursorPosition(pt.x, pt.y, false) && [ NSApp isActive ]) { - /* Warping cursor when in foreground */ - NSPoint warp = [ self convertPoint:NSMakePoint(_cursor.pos.x, self.bounds.size.height - _cursor.pos.y) toView:nil ]; - warp = [ self.window convertRectToScreen:NSMakeRect(warp.x, warp.y, 0, 0) ].origin; - warp.y = NSScreen.screens[0].frame.size.height - warp.y; + HandleMouseEvents(); +} - /* Do the actual warp */ - CGWarpMouseCursorPosition(NSPointToCGPoint(warp)); - /* this is the magic call that fixes cursor "freezing" after warp */ - CGAssociateMouseAndMouseCursorPosition(true); - } +- (void)internalMouseButtonEvent +{ + bool cur_fix = _cursor.fix_at; HandleMouseEvents(); + + /* Cursor fix mode was changed, synchronize with OS. */ + if (cur_fix != _cursor.fix_at) CGAssociateMouseAndMouseCursorPosition(!_cursor.fix_at); } - (BOOL)emulateRightButton:(NSEvent *)event @@ -564,7 +567,7 @@ void CocoaDialog(const char *title, cons [ self rightMouseDown:event ]; } else { _left_button_down = true; - [ self internalMouseMoveEvent:event ]; + [ self internalMouseButtonEvent ]; } } - (void)mouseUp:(NSEvent *)event @@ -574,7 +577,7 @@ void CocoaDialog(const char *title, cons } else { _left_button_down = false; _left_button_clicked = false; - [ self internalMouseMoveEvent:event ]; + [ self internalMouseButtonEvent ]; } } @@ -586,12 +589,12 @@ void CocoaDialog(const char *title, cons { _right_button_down = true; _right_button_clicked = true; - [ self internalMouseMoveEvent:event ]; + [ self internalMouseButtonEvent ]; } - (void)rightMouseUp:(NSEvent *)event { _right_button_down = false; - [ self internalMouseMoveEvent:event ]; + [ self internalMouseButtonEvent ]; } - (void)scrollWheel:(NSEvent *)event