Skip to content

Commit

Permalink
Track hovered Window in DisplayServerX11
Browse files Browse the repository at this point in the history
Send mouse-entered/exited window-events only when necessary
  • Loading branch information
Sauermann committed Aug 9, 2023
1 parent 16a9356 commit a7c5849
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
20 changes: 17 additions & 3 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -4291,7 +4300,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);
}

Expand All @@ -4303,7 +4313,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;
Expand Down
1 change: 1 addition & 0 deletions platform/linuxbsd/x11/display_server_x11.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a7c5849

Please sign in to comment.