From d828523b394069ba91a369c856160fce41c0acb4 Mon Sep 17 00:00:00 2001 From: Rodrigo Rivas Costa Date: Thu, 21 Nov 2024 12:04:55 +0100 Subject: [PATCH] x11: move up XInput2 event registration It should be done before mapping the window, or we could lose the firsst XInput2 events, such as the first FocusIn. Fixes #2841. --- src/changelog/unreleased.md | 1 + src/platform_impl/linux/x11/window.rs | 28 +++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/changelog/unreleased.md b/src/changelog/unreleased.md index a6ac8e617..d3380d34b 100644 --- a/src/changelog/unreleased.md +++ b/src/changelog/unreleased.md @@ -59,3 +59,4 @@ changelog entry. - On Windows, make `ControlFlow::WaitUntil` work more precisely using `CREATE_WAITABLE_TIMER_HIGH_RESOLUTION`. - On X11, creating windows on screen that is not the first one (e.g. `DISPLAY=:0.1`) works again. - On X11, creating windows while passing `with_x11_screen(non_default_screen)` works again. +- On X11, fix XInput handling that prevented a new window from getting the focus in some cases. diff --git a/src/platform_impl/linux/x11/window.rs b/src/platform_impl/linux/x11/window.rs index fcadf5805..9eff6dd02 100644 --- a/src/platform_impl/linux/x11/window.rs +++ b/src/platform_impl/linux/x11/window.rs @@ -490,6 +490,20 @@ impl UnownedWindow { ); leap!(result).ignore_error(); + // Select XInput2 events + let mask = xinput::XIEventMask::MOTION + | xinput::XIEventMask::BUTTON_PRESS + | xinput::XIEventMask::BUTTON_RELEASE + | xinput::XIEventMask::ENTER + | xinput::XIEventMask::LEAVE + | xinput::XIEventMask::FOCUS_IN + | xinput::XIEventMask::FOCUS_OUT + | xinput::XIEventMask::TOUCH_BEGIN + | xinput::XIEventMask::TOUCH_UPDATE + | xinput::XIEventMask::TOUCH_END; + leap!(xconn.select_xinput_events(window.xwindow, super::ALL_MASTER_DEVICES, mask)) + .ignore_error(); + // Set visibility (map window) if window_attrs.visible { leap!(xconn.xcb_connection().map_window(window.xwindow)).ignore_error(); @@ -513,20 +527,6 @@ impl UnownedWindow { } } - // Select XInput2 events - let mask = xinput::XIEventMask::MOTION - | xinput::XIEventMask::BUTTON_PRESS - | xinput::XIEventMask::BUTTON_RELEASE - | xinput::XIEventMask::ENTER - | xinput::XIEventMask::LEAVE - | xinput::XIEventMask::FOCUS_IN - | xinput::XIEventMask::FOCUS_OUT - | xinput::XIEventMask::TOUCH_BEGIN - | xinput::XIEventMask::TOUCH_UPDATE - | xinput::XIEventMask::TOUCH_END; - leap!(xconn.select_xinput_events(window.xwindow, super::ALL_MASTER_DEVICES, mask)) - .ignore_error(); - // Try to create input context for the window. if let Some(ime) = event_loop.ime.as_ref() { let result = ime.borrow_mut().create_context(window.xwindow as ffi::Window, false);