Skip to content

armgit / godot

Public Imported from GitHub
0

Godot Engine – Multi-platform 2D and 3D game engine

macOS: Fix mouseMoved events for multiple displays; reduce IPC calls

Stuart Carniea6dda6ceb0e9
diff --git a/platform/macos/display_server_macos.h b/platform/macos/display_server_macos.h
index 05e4ee3ae37..b9aaa09c235 100644
--- a/platform/macos/display_server_macos.h
+++ b/platform/macos/display_server_macos.h
@@ -270,6 +270,7 @@ public:
DisplayServerEnums::WindowID _get_focused_window_or_popup() const;
void mouse_enter_window(DisplayServerEnums::WindowID p_window);
void mouse_exit_window(DisplayServerEnums::WindowID p_window);
+ DisplayServerEnums::WindowID get_mouseover_window() const { return window_mouseover_id; }
void update_presentation_mode();
bool is_always_on_top_recursive(DisplayServerEnums::WindowID p_window) const;
diff --git a/platform/macos/godot_content_view.mm b/platform/macos/godot_content_view.mm
index 15f68017a17..844f918de2c 100644
--- a/platform/macos/godot_content_view.mm
+++ b/platform/macos/godot_content_view.mm
@@ -523,7 +523,9 @@
DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
NSPoint delta = NSMakePoint([event deltaX], [event deltaY]);
- NSPoint mpos = [event locationInWindow];
+ const CGPoint cg_pos = CGEventGetLocation([event CGEvent]);
+ const NSPoint screen_pos = NSMakePoint(cg_pos.x, CGDisplayBounds(CGMainDisplayID()).size.height - cg_pos.y);
+ NSPoint mpos = [wd.window_object convertPointFromScreen:screen_pos];
if (ds->update_mouse_wrap(wd, delta, mpos, [event timestamp])) {
return;
@@ -555,9 +557,11 @@
mm->set_relative_screen_position(relativeMotion);
ds->get_key_modifier_state([event modifierFlags], mm);
- const NSRect contentRect = [wd.window_view frame];
- if (NSPointInRect([event locationInWindow], contentRect) && [NSWindow windowNumberAtPoint:[NSEvent mouseLocation] belowWindowWithWindowNumber:0 /*topmost*/] == [wd.window_object windowNumber]) {
- ds->mouse_enter_window(window_id);
+ if (ds->get_mouseover_window() != window_id) {
+ const NSRect contentRect = [wd.window_view frame];
+ if (NSPointInRect(mpos, contentRect) && [NSWindow windowNumberAtPoint:[NSEvent mouseLocation] belowWindowWithWindowNumber:0 /*topmost*/] == [wd.window_object windowNumber]) {
+ ds->mouse_enter_window(window_id);
+ }
}
Input::get_singleton()->parse_input_event(mm);