Repository navigation
gtk: capture the mouse for real, on Wayland and on X11 - #949
Open
danifunker wants to merge 1 commit into
Open
danifunker wants to merge 1 commit into
danifunker wants to merge 1 commit into
Conversation
A fresh Linux install had no working mouse in the guest. The GTK shell could
only send DisplayAction::PointerAt, an absolute position, because GDK 4
exposes no way to grab, lock, confine or warp a pointer; the core drops
PointerAt unless the pointer mode is Follow; and PointerMode::Capture is the
default. Three correct-looking pieces, no mouse. The GTK shell was also the
only shell that never consulted follows_pointer, which is what let the
mismatch go unnoticed.
Capture now happens below GTK, through GDK's own connection, so no second
display is opened and no second event loop runs:
- Wayland: zwp_pointer_constraints_v1 locks the pointer and
zwp_relative_pointer_v1 reports deltas. Both managers are bound on an
event queue of our own, so their children's events arrive there and not
in GDK's queue. GDK reads the socket as part of its main loop, so a tick
callback only has to dispatch what is already ours. Under a lock the
compositor sends no position at all, which is why the deltas cannot come
from GTK -- the bug QEMU's GTK backend has.
- X11: a confining XGrabPointer, with the pointer warped back to the middle
of the view after each motion event, so the delta is how far it got
before the warp. Device pixels, not logical ones, or it drifts on HiDPI.
Buttons and the wheel need none of this; both servers keep delivering them to
the surface while the pointer is held. Only motion and the cursor change.
A desktop that allows neither mechanism is not left without a mouse: the
capture is given up, the pointer mode falls back to Follow, and a message
says which it is. The release chord is shown once per run, since the Mac
shows the hint beside the display and Windows inside it.
Preferences > Mouse no longer describes itself in macOS terms: the catalog is
shared by all four shells, so "the Mac pointer" and "Command shortcuts stay
with the Mac" are now host-neutral.
The four crates this needs are already in the graph through
third_party/winit-0.30.13, at the versions used there, so nothing resolves a
second copy. wayland-backend/client_system is required rather than preferred:
only the libwayland backend can wrap GDK's display and its existing proxies.
Verified: cargo check -p iris-gui-gtk clean, cargo check --tests clean for
iris-gui-core and iris-gui-gtk, iris-gui/scripts/check-boundaries.sh at 0,
every t! id in the shell resolves against the catalogs. The capture itself
needs a human at a Wayland and an X11 session; the core's own display tests
could not be run here for want of memory and need CI.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
On Linux the mouse did not reach the guest at all on a fresh install, and it
looked like a missing feature rather than a bug. Three correct-looking pieces:
DisplayAction::PointerAt, an absoluteposition, because GDK 4 exposes no way to grab, lock, confine or warp a
pointer (GTK 4.22's headers have only the read-only
gdk_display_device_is_grabbed);DisplayController::apply_withdropsPointerAtunless the pointer modeis Follow;
PointerMode::Captureis#[default].The GTK shell was also the only shell that never consulted
follows_pointer,which is what let the mismatch go unnoticed. A
clanker/note had recorded"GTK 4 has no pointer lock, so use Follow" as a design decision; this PR
supersedes it, because Follow being the only mode the shell could drive left
Capture — the default — silently dead.
What capture does now
Below GTK, through GDK's own connection, so no second display is opened and no
second event loop runs.
Wayland —
zwp_pointer_constraints_v1locks the pointer andzwp_relative_pointer_v1reports deltas. Both managers are bound on an eventqueue of our own; because a new Wayland object inherits the queue of the object
that created it, their children's events arrive there and never in GDK's
queue. GDK reads the socket as part of its main loop, so a tick callback only
has to
dispatch_pendingwhat is already ours — never a blocking dispatch thatwould fight GDK. Under a lock the compositor sends no position at all, which is
why the deltas cannot come from GTK; that is the bug QEMU's GTK backend has.
X11 — a confining
XGrabPointerwithowner_events: true, so GTK's ownhandlers keep working, and the pointer warped back to the middle of the view
after each motion event. The delta is how far it got before the warp; the
warp's own event reports the middle, so a zero delta is the echo and is
dropped. Device pixels, not logical ones, or capture drifts on HiDPI.
Buttons and the wheel need none of this — both servers keep delivering them to
the surface while the pointer is held. Only motion and the cursor change.
Neither available — the capture is given up rather than silently doing
nothing: the pointer mode falls back to Follow so the mouse still reaches the
guest, and a message says which it is. The release chord (Ctrl+Alt) is shown
once per run, since the Mac shows that hint beside the display and Windows
inside it.
This is the same mechanism spice-gtk adopted for the same reason
(rhbz#1674311), and the
two protocols are what the Arch Wiki lists for input grabbing in VM windows.
VirtualBox and VMware avoid the problem by being X11 apps under XWayland,
which a native GTK 4 app cannot do without giving up native scaling.
Wording
Preferences > Mousedescribed itself in macOS terms on every platform — "Followthe Mac pointer", "Command shortcuts stay with the Mac" — because the Fluent
catalog is shared by all four shells. Those are now host-neutral, and
prefs-pointer-no-lockis new.Dependencies
wayland-client,wayland-backend,wayland-protocolsandx11-dl, in theLinux-only target section, at the versions
third_party/winit-0.30.13alreadybrings into the graph — so nothing resolves a second copy.
wayland-backend/client_systemis required rather than preferred: only thelibwayland backend can wrap GDK's
wl_displayand its existing proxies.x11-dlloads Xlib at run time, which keeps X11 headers out of the build; itdoes not save the host a libX11 install, as the commit message claims -- GTK
links libX11 itself for its own X11 backend, confirmed with
lddon the builtbinary.
Verification
cargo check -p iris-gui-gtk— clean, no warnings.cargo check --tests -p iris-gui-core -p iris-gui-gtk— clean.iris-gui/scripts/check-boundaries.sh— 0, the shell still names neither theemulator nor the model.
t!id in the shell (127) resolves against the catalogs.Not verified here, and this needs saying: the capture itself wants a human
at a Wayland session and at an X11 one — a lock is not something a test
asserts. And
cargo test -p iris-gui-corecould not be built on the machine Iworked on (the
iristest binary exceeds the memory I could safely give it),so the core's display and i18n tests need CI.
🤖 Generated with Claude Code