Merge pull request #46034 from bruvzg/ignore_warp_on_mode_change_3

[macOS, 3.2] Ignore mouse move event caused by mouse mode switch.
This commit is contained in:
Rémi Verschelde 2021-02-15 11:09:28 +01:00 committed by GitHub
commit 40c30adf04
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View file

@ -71,6 +71,7 @@ public:
};
List<WarpEvent> warp_events;
NSTimeInterval last_warp = 0;
bool ignore_warp = false;
Vector<KeyEvent> key_event_buffer;
int key_event_pos;

View file

@ -738,6 +738,15 @@ static void _mouseDownEvent(NSEvent *event, int index, int mask, bool pressed) {
NSPoint delta = NSMakePoint([event deltaX], [event deltaY]);
NSPoint mpos = [event locationInWindow];
if (OS_OSX::singleton->ignore_warp) {
// Discard late events, before warp
if (([event timestamp]) < OS_OSX::singleton->last_warp) {
return;
}
OS_OSX::singleton->ignore_warp = false;
return;
}
if (OS_OSX::singleton->mouse_mode == OS::MOUSE_MODE_CONFINED) {
// Discard late events
if (([event timestamp]) < OS_OSX::singleton->last_warp) {
@ -3306,6 +3315,8 @@ void OS_OSX::set_mouse_mode(MouseMode p_mode) {
CGAssociateMouseAndMouseCursorPosition(true);
}
last_warp = [[NSProcessInfo processInfo] systemUptime];
ignore_warp = true;
warp_events.clear();
mouse_mode = p_mode;
}