diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-08-09 00:18:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-09 00:18:09 +0200 |
commit | 7fc570b5ac4527e10a394da578f649b1f577b4dc (patch) | |
tree | c5c8bd59a5bdabc16419f96d8d5ba90828c152dd /platform/osx/display_server_osx.mm | |
parent | e010e05b3dd842ba86a68dee60e0d7be6f9aae50 (diff) | |
parent | ae7dbb678ce30c3786e935663a7d34f60c0a0642 (diff) |
Merge pull request #51405 from bruvzg/macos_recenter_mouse
[macOS] Move captured mouse cursor to the center when window gain focus.
Diffstat (limited to 'platform/osx/display_server_osx.mm')
-rw-r--r-- | platform/osx/display_server_osx.mm | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/platform/osx/display_server_osx.mm b/platform/osx/display_server_osx.mm index 73aa013701..974f4d3018 100644 --- a/platform/osx/display_server_osx.mm +++ b/platform/osx/display_server_osx.mm @@ -318,8 +318,16 @@ static NSCursor *_cursorFromSelector(SEL selector, SEL fallback = nil) { } DisplayServerOSX::WindowData &wd = DS_OSX->windows[window_id]; - _get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]); - Input::get_singleton()->set_mouse_position(wd.mouse_pos); + if (DS_OSX->mouse_mode == DisplayServer::MOUSE_MODE_CAPTURED) { + const NSRect contentRect = [wd.window_view frame]; + NSRect pointInWindowRect = NSMakeRect(contentRect.size.width / 2, contentRect.size.height / 2, 0, 0); + NSPoint pointOnScreen = [[wd.window_view window] convertRectToScreen:pointInWindowRect].origin; + CGPoint lMouseWarpPos = { pointOnScreen.x, CGDisplayBounds(CGMainDisplayID()).size.height - pointOnScreen.y }; + CGWarpMouseCursorPosition(lMouseWarpPos); + } else { + _get_mouse_pos(wd, [wd.window_object mouseLocationOutsideOfEventStream]); + Input::get_singleton()->set_mouse_position(wd.mouse_pos); + } DS_OSX->window_focused = true; DS_OSX->_send_window_event(wd, DisplayServerOSX::WINDOW_EVENT_FOCUS_IN); |