For the implementation of `mouse-autoselect-window', the entered window is remembered and then compared when an mouse motion event is received. Up to Emacs 28, this value was stored in a static local variable named `last_mouse_window' in the block handling MotionNotify within `handle_one_xevent'. With the introduction of XInput 2, `handle_one_xevent' was adjusted to account for XI_Motion events, with the oversight that a new local static `last_mouse_window' variable was declared in the new handler block for XI_Motion. As a result, when Emacs receives motion events from XInput and XInput2 sources alternatively the value of each `last_mouse_window’ differs, leading to the window under the motion sometimes not being selected, as the value `last_mouse_window' is out-of-date for the particular XInput version. This bug impacts the GNU ELPA package EXWM. EXWM tries to extrapolate applicable Emacs functionality to X window management; among others assigns an Emacs buffer to each managed X window, and positions the X window over the Emacs window in which the buffer is displayed. When `mouse-autoselect-windows’ and the user moves the mouse pointer over one X window managed by EXWM, this X window receives the mouse events and not Emacs, therefore the Emacs window is not selected. In order to overcome this, EXWM sends a synthetic MotionNotify event to Emacs. The attached patch fixes the issue. Thank you, Adrián Medraño Calvo.