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

[X11] Fix mouse events triggered by non-popup or non-focused window #94688

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
39 changes: 10 additions & 29 deletions platform/linuxbsd/x11/display_server_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4968,7 +4968,7 @@ void DisplayServerX11::process_events() {
Ref<InputEventMouseMotion> mm;
mm.instantiate();

mm->set_window_id(window_id);
mm->set_window_id(focused_window_id);
if (xi.pressure_supported) {
mm->set_pressure(xi.pressure);
} else {
Expand All @@ -4989,37 +4989,18 @@ void DisplayServerX11::process_events() {

last_mouse_pos = pos;

// printf("rel: %d,%d\n", rel.x, rel.y );
// Don't propagate the motion event unless we have focus
// this is so that the relative motion doesn't get messed up
// after we regain focus.
if (focused) {
Input::get_singleton()->parse_input_event(mm);
if (windows[focused_window_id].mpass || wd.is_popup) {
mm->set_window_id(window_id);
} else {
// Propagate the event to the focused window,
// because it's received only on the topmost window.
// Note: This is needed for drag & drop to work between windows,
// because the engine expects events to keep being processed
// on the same window dragging started.
for (const KeyValue<WindowID, WindowData> &E : windows) {
const WindowData &wd_other = E.value;
if (wd_other.focused) {
int x, y;
Window child;
XTranslateCoordinates(x11_display, wd.x11_window, wd_other.x11_window, event.xmotion.x, event.xmotion.y, &x, &y, &child);

Point2i pos_focused(x, y);

mm->set_window_id(E.key);
mm->set_position(pos_focused);
mm->set_global_position(pos_focused);
mm->set_velocity(Input::get_singleton()->get_last_mouse_velocity());
Input::get_singleton()->parse_input_event(mm);
int x, y;
Window child;
XTranslateCoordinates(x11_display, wd.x11_window, windows[focused_window_id].x11_window, event.xmotion.x, event.xmotion.y, &x, &y, &child);

break;
}
}
Point2i pos_focused(x, y);
mm->set_position(pos_focused);
mm->set_global_position(pos_focused);
}
Input::get_singleton()->parse_input_event(mm);

} break;
case KeyPress:
Expand Down
Loading