[macOS] Ignore mouse move event caused by mouse mode switch.

This commit is contained in:
bruvzg 2021-02-15 00:19:47 +02:00
parent 5bec2cf3d4
commit bc04bbbe2a
No known key found for this signature in database
GPG Key ID: 009E1BFE42239B95
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;
}