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 missing mouse exit events on window close. #80439

Merged
merged 1 commit into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions platform/macos/display_server_macos.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class DisplayServerMacOS : public DisplayServer {
int current_layout = 0;
bool keyboard_layout_dirty = true;

WindowID window_mouseover_id = INVALID_WINDOW_ID;
WindowID last_focused_window = INVALID_WINDOW_ID;
WindowID window_id_counter = MAIN_WINDOW_ID;
float display_max_scale = 1.f;
Expand Down Expand Up @@ -240,6 +241,8 @@ class DisplayServerMacOS : public DisplayServer {
bool get_is_resizing() const;
void reparent_check(WindowID p_window);
WindowID _get_focused_window_or_popup() const;
void mouse_enter_window(WindowID p_window);
void mouse_exit_window(WindowID p_window);

void window_update(WindowID p_window);
void window_destroy(WindowID p_window);
Expand Down
23 changes: 20 additions & 3 deletions platform/macos/display_server_macos.mm
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,25 @@
return last_focused_window;
}

void DisplayServerMacOS::mouse_enter_window(WindowID p_window) {
if (window_mouseover_id != p_window) {
if (window_mouseover_id != INVALID_WINDOW_ID) {
send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}
window_mouseover_id = p_window;
if (p_window != INVALID_WINDOW_ID) {
send_window_event(windows[p_window], WINDOW_EVENT_MOUSE_ENTER);
}
}
}

void DisplayServerMacOS::mouse_exit_window(WindowID p_window) {
if (window_mouseover_id == p_window && p_window != INVALID_WINDOW_ID) {
send_window_event(windows[p_window], WINDOW_EVENT_MOUSE_EXIT);
}
window_mouseover_id = INVALID_WINDOW_ID;
}

void DisplayServerMacOS::_dispatch_input_events(const Ref<InputEvent> &p_event) {
((DisplayServerMacOS *)(get_singleton()))->_dispatch_input_event(p_event);
}
Expand Down Expand Up @@ -2069,9 +2088,7 @@

if (show_cursor && !previously_shown) {
window_id = get_window_at_screen_position(mouse_get_position());
if (window_id != INVALID_WINDOW_ID) {
send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_ENTER);
}
mouse_enter_window(window_id);
}

if (p_mode == MOUSE_MODE_CAPTURED) {
Expand Down
6 changes: 2 additions & 4 deletions platform/macos/godot_content_view.mm
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,8 @@ - (void)mouseExited:(NSEvent *)event {
return;
}

DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_CAPTURED) {
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_MOUSE_EXIT);
ds->mouse_exit_window(window_id);
}
}

Expand All @@ -517,9 +516,8 @@ - (void)mouseEntered:(NSEvent *)event {
return;
}

DisplayServerMacOS::WindowData &wd = ds->get_window(window_id);
if (ds->mouse_get_mode() != DisplayServer::MOUSE_MODE_CAPTURED) {
ds->send_window_event(wd, DisplayServerMacOS::WINDOW_EVENT_MOUSE_ENTER);
ds->mouse_enter_window(window_id);
}

ds->cursor_update_shape();
Expand Down
1 change: 1 addition & 0 deletions platform/macos/godot_window_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ - (void)windowWillClose:(NSNotification *)notification {
ds->window_set_transient(window_id, DisplayServerMacOS::INVALID_WINDOW_ID);
}

ds->mouse_exit_window(window_id);
ds->window_destroy(window_id);
}

Expand Down
Loading