Merge pull request #80279 from Sauermann/fix-x11-mouse-window-event-crash

Track hovered `Window` in `DisplayServerX11`
This commit is contained in:
Rémi Verschelde 2023-08-10 00:43:00 +02:00
commit 49f0d8cee3
No known key found for this signature in database
GPG Key ID: C3336907360768E1
2 changed files with 18 additions and 3 deletions

View File

@ -379,7 +379,11 @@ void DisplayServerX11::mouse_set_mode(MouseMode p_mode) {
if (show_cursor && !previously_shown) {
WindowID window_id = get_window_at_screen_position(mouse_get_position());
if (window_id != INVALID_WINDOW_ID) {
if (window_id != INVALID_WINDOW_ID && window_mouseover_id != window_id) {
if (window_mouseover_id != INVALID_WINDOW_ID) {
_send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}
window_mouseover_id = window_id;
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_ENTER);
}
}
@ -1449,6 +1453,11 @@ void DisplayServerX11::delete_sub_window(WindowID p_id) {
DEBUG_LOG_X11("delete_sub_window: %lu (%u) \n", wd.x11_window, p_id);
if (window_mouseover_id == p_id) {
window_mouseover_id = INVALID_WINDOW_ID;
_send_window_event(windows[p_id], WINDOW_EVENT_MOUSE_EXIT);
}
window_set_rect_changed_callback(Callable(), p_id);
window_set_window_event_callback(Callable(), p_id);
window_set_input_event_callback(Callable(), p_id);
@ -4292,7 +4301,8 @@ void DisplayServerX11::process_events() {
break;
}
if (!mouse_mode_grab) {
if (!mouse_mode_grab && window_mouseover_id == window_id) {
window_mouseover_id = INVALID_WINDOW_ID;
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_EXIT);
}
@ -4304,7 +4314,11 @@ void DisplayServerX11::process_events() {
break;
}
if (!mouse_mode_grab) {
if (!mouse_mode_grab && window_mouseover_id != window_id) {
if (window_mouseover_id != INVALID_WINDOW_ID) {
_send_window_event(windows[window_mouseover_id], WINDOW_EVENT_MOUSE_EXIT);
}
window_mouseover_id = window_id;
_send_window_event(windows[window_id], WINDOW_EVENT_MOUSE_ENTER);
}
} break;

View File

@ -225,6 +225,7 @@ class DisplayServerX11 : public DisplayServer {
List<WindowID> popup_list;
WindowID window_mouseover_id = INVALID_WINDOW_ID;
WindowID last_focused_window = INVALID_WINDOW_ID;
WindowID window_id_counter = MAIN_WINDOW_ID;