Skip to content

fix(xorg): dispatch key events via XInput XTEST device for GDK3 compatibility#642

Open
rubenvereecken wants to merge 1 commit into
m1k1o:masterfrom
rubenvereecken:ruben/xinput-keyboard-device-selection
Open

fix(xorg): dispatch key events via XInput XTEST device for GDK3 compatibility#642
rubenvereecken wants to merge 1 commit into
m1k1o:masterfrom
rubenvereecken:ruben/xinput-keyboard-device-selection

Conversation

@rubenvereecken
Copy link
Copy Markdown

The problem

Neko's keyboard input doesn't reach Firefox (or any GTK3/GDK3 application). You can see the key events in xev, but the browser ignores them. Mouse works fine.

Why it happens

GDK3 selects XI2 (X Input Extension 2) for its seat keyboard at startup. Once XI2 is active, GDK3 only processes XI_KeyPress / XI_KeyRelease events — it stops listening for core-protocol KeyPress events entirely.

XTestFakeKeyEvent produces core-protocol key events. These are real X11 events (they show up in xev, they're sent by the X server), but GDK3's XI2 event loop never sees them.

The fix

At display open, discover the "Virtual core XTEST keyboard" XInput1 device via XListInputDevices() and cache it. In XKey(), dispatch via XTestFakeDeviceKeyEvent (which goes through the XI path) instead of XTestFakeKeyEvent (core path).

Falls back to the original XTestFakeKeyEvent if the XTEST device can't be found — preserves existing behaviour on unusual X server configurations.

Requires linking against libXi (-lXi added to CGO_LDFLAGS). Build dep: libxi-dev, runtime dep: libxi6.

GDK3 (used by Firefox/Camoufox) selects XI2 for the seat keyboard at
startup and ignores core-protocol KeyPress events. XTestFakeKeyEvent
produces core events, so typed characters from the Neko viewer silently
never reach Firefox.

Fix: discover the "Virtual core XTEST keyboard" XInput1 device at
startup, cache it, and dispatch key events via XTestFakeDeviceKeyEvent
which goes through the XI path. Falls back to the old core XTest path
if the device isn't found.

Requires -lXi (libxi-dev at build, libxi6 at runtime).
@rubenvereecken rubenvereecken marked this pull request as ready for review April 22, 2026 08:58
@m1k1o
Copy link
Copy Markdown
Owner

m1k1o commented Apr 24, 2026

How could we test this? Only a simple smoke test would be enough.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants