Skip to content

x11: slave pointer button events dropped when window lacks keyboard focus (breaks remote-control tools) #16242

Description

@Enaium

Problem

On X11, slave pointer device button events are dropped whenever the SDL window does not have keyboard focus. Remote-control tools (VNC, Sunflower, x11vnc) and automation tools inject clicks via virtual slave devices (XTEST/uinput); while the user is interacting with the remote machine, the local SDL window frequently does not hold keyboard focus, so every injected click is lost.

Root cause

src/video/x11/SDL_x11xinput2.c, in X11_HandleXinput2Event (XI_ButtonPress/XI_ButtonRelease handling):

if (SDL_GetMouseFocus() != windowdata->window || SDL_GetKeyboardFocus() != windowdata->window) {
    break;
}

Commit ef9a5b704 added the keyboard-focus requirement to protect the click-through suppression logic ("a window must have keyboard focus to grab the mouse anyway"). But XInput2 slave button events follow the pointer focus, not the keyboard focus — a window can legitimately receive clicks while not holding keyboard focus (that is exactly how remote tools work), and requiring keyboard focus drops those events.

Suggested fix

Keep the mouse-focus check (that is what guards the grab/click-through case) and drop the keyboard-focus requirement:

if (SDL_GetMouseFocus() != windowdata->window) {
    break;
}

Keyboard focus is still required where it actually matters (e.g. relative mouse motion is gated on SDL_GetKeyboardFocus() elsewhere in the same file).

Verification

  • Run an SDL app, don't give it keyboard focus, inject a click via XTEST → click is lost without the fix, delivered with it.
  • Grab/click-through behavior (the case ef9a5b704 protected) still works — the mouse-focus check remains.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions