feat(x11-capture): implement X11 input capture backend#457
Open
lgobatto wants to merge 1 commit into
Open
Conversation
Replaces the stub that always returned `NotImplemented` with a working implementation using XQueryPointer polling + XGrabPointer/XGrabKeyboard. Architecture mirrors the Windows backend: a dedicated OS thread runs the X11 event loop and communicates with the async runtime via two channels (std::sync::mpsc for requests, tokio::sync::mpsc for events). Phase 1 (no active client): polls XQueryPointer at ~1 ms to detect when the cursor crosses a screen edge towards a configured client, then calls XGrabPointer + XGrabKeyboard and sends CaptureEvent::Begin. Phase 2 (active client): drains XNextEvent. MotionNotify events compute a relative delta from the locked entry point and warp the cursor back; ButtonPress/Release and KeyPress/Release are forwarded as input events. X11 keycodes are translated to Linux evdev by subtracting 8. The right/bottom boundary detection uses `>= w-1` / `>= h-1` rather than `>= w` / `>= h` because X11 clamps cursor coordinates to the range [0, w-1] × [0, h-1] — the larger values are never returned by XQueryPointer on a single monitor. 13 unit tests cover boundary detection, coordinate clamping, and button mapping.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.Suggestion cannot be applied right now. Please check back later.
Summary
Replaces the
X11InputCapturestub (which always returnedNotImplementedand fell through to theDummybackend) with a working implementation. With this change, lan-mouse on X11/Xorg sessions captures mouse and keyboard properly, allowing the cursor to cross back to the host by moving to the screen edge — no release keybind required.Fixes the root cause of #125 and #315 (Xorg users stuck on the client, needing manual release to return).
How it works
A dedicated OS thread runs the X11 event loop alongside the async runtime — the same pattern used by the Windows backend.
Phase 1 — edge detection (no active client):
Polls
XQueryPointerat ~1 ms. When the cursor crosses a screen edge toward a configured client, callsXGrabPointer+XGrabKeyboardand sendsCaptureEvent::Begin.Phase 2 — forwarding (active client):
Drains
XNextEvent.MotionNotifycomputes a relative delta from the locked entry point and warps the cursor back.ButtonPress/ButtonReleaseandKeyPress/KeyReleaseare forwarded as input events. X11 keycodes are converted to Linux evdev by subtracting 8.Key subtlety: The right/bottom boundary check uses
>= w-1/>= h-1instead of>= w/>= h. X11 clamps cursor coordinates to[0, w-1] × [0, h-1]— the larger values are never returned byXQueryPointeron a single monitor, so the original>= wcondition was dead code and the return journey never triggered.Changes
input-capture/src/x11.rsinput-capture/src/error.rsNotImplementedwithOpenDisplayFailedvariant13 unit tests cover boundary detection, coordinate clamping, and button mapping.
Tested on
Tested with one host + one client; other X11 distros and multi-client setups have not been validated yet.