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

[macOS] Fix mouse position in captured mode. #42327

Merged
merged 1 commit into from
Sep 28, 2020

Conversation

bruvzg
Copy link
Member

@bruvzg bruvzg commented Sep 25, 2020

Move mouse cursor to the center of main window when switching to captured mode (similar to Linux and Windows behavior).

Fixes: #42321

@akien-mga akien-mga merged commit 0ba4a8b into godotengine:master Sep 28, 2020
@akien-mga
Copy link
Member

Thanks!

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 };
Copy link
Contributor

@jamie-pate jamie-pate Sep 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not possible to stack displays vertically in MacOS?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or am I misinterpreting the reason behind this code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's possible to arrange displays vertically, but it does not matter. This code is needed to convert coordinates to global space (which is relative to the upper-left corner of the main display).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have checked it with vertically aligned displays just to be sure, it works fine.

@aaronfranke
Copy link
Member

What about the case of setting the mouse position when tabbing out and in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Captured mouse mode fails to capture mouse if it's outside the window on OSX
4 participants