XInput2: Accept input from keyboards other than the first master #11758
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
This is a fix for a bug I found while putting together a series that reworks XInput2 to fix https://bugs.dolphin-emu.org/issues/10668 (and two duplicates). Because this fix is necessary regardless of whether you take that series, I've sent it as its own pull request for ease of review and merging.
XInput2 was created to support multiple pointer/keyboard pairs (often called MPX for multi-pointer X). Dolphin's XInput2 implementation has always supported MPX by creating a KeyboardMouse object per master pointer. Since commit bbb12a7, Dolphin's keyboard state is filtered by the output of XQueryKeymap. As a core X function, XQueryKeymap queries "the" keyboard, which by default is the first master keyboard. As a result, Dolphin will ignore keys pressed on other master keyboards unless the first master is simultaneously pressing the same keys.
XInput2 doesn't provide a function to query the keyboard state. There is no XIQueryKeymap and the current state is not a member of the XIKeyClassInfo returned by XIQueryDevice. Instead, XInput2 allows a master pointer to be nominated as "the" pointer on a per-client basis, with "the" keyboard automatically becoming the associated master keyboard. The "documentation" 1 says passing None for the window is only for debugging purposes, but it is documented in the XISetClientPointer man page and seems to be the only way to query keyboards beyond the first.
With this commit, Dolphin correctly reads keys from keyboards other than the first master keyboard. To test, use the xinput command-line utility to create a master pointer and reattach a keyboard to the associated master keyboard.