Skip to content

gui: the Linux, Mac and Windows shells brought level - #949

Open
danifunker wants to merge 4 commits into
mainfrom
gtk-pointer-capture
Open

danifunker wants to merge 4 commits into
mainfrom
gtk-pointer-capture

Conversation

@danifunker

@danifunker danifunker commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

The Linux, Mac and Windows front ends, brought level with each other: bluu's
notes of 2026-11-29 in full, plus the Linux mouse capture that turned out to
be a bug rather than a missing feature.

Three commits, each readable on its own.

gtk: capture the mouse for real, on Wayland and on X11

On Linux the mouse did not reach the guest at all on a fresh install, and it
looked like a missing feature. Three correct-looking pieces:

  • the GTK shell only ever sent DisplayAction::PointerAt, an absolute
    position, 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_with drops PointerAt unless the pointer mode
    is Follow;
  • PointerMode::Capture is #[default].

The GTK shell was also the only shell that never consulted follows_pointer,
which is what let the mismatch go unnoticed.

Capture now works below GTK, through GDK's own connection, so no second
display is opened and no second event loop runs. On Wayland,
zwp_pointer_constraints_v1 locks the pointer and zwp_relative_pointer_v1
reports deltas, both managers bound on an event queue 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_pending
what is already ours — never a blocking dispatch that would 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. On X11, a confining
XGrabPointer with a warp back to the middle.

A clanker/ note had recorded "GTK 4 has no pointer lock, so use Follow" as a
design decision. This supersedes it — Follow being the only mode the shell
could drive left Capture, the default, silently dead — and the note is now
filed as history saying so.

gui: pick the moment the guest clock starts, on the Machine page

The real-time clock was a tab of its own holding six signed number boxes, one
per unit, and you worked out the date you wanted by arithmetic. It is now one
date-and-time control on the Machine page, beside the memory and the PROM,
with Use the host clock next to it.

[rtc_offset] is unchanged on disk: RtcOffset::between turns the moment
picked back into a calendar offset, whole months first and the remainder as a
duration, so a date eighteen years back to the day still writes years = -18
as someone editing the file by hand would.

Two new field kinds carry it, so no shell special-cases a section again:
DateTime, reported as Unix seconds in a Value::Number, and Action, a
button named by its label. The Mac draws an NSDatePicker in UTC, text style
rather than with a stepper, which would fire its action on every click while
the page is rebuilt under it; Linux a GtkCalendar and three spin buttons in
a popover that applies once, for the same reason; Windows a box in the format
the preview used, refused if it is not a date. The GTK and Win32 Reset buttons
that were bolted onto the clock page are gone.

The clock still starts a fixed distance from host time rather than at a fixed
moment, so the row reads a day later tomorrow; the help text says so. Pinning
it to an absolute moment would need a new config key and is not in here.

The calendar arithmetic all of this rests on moves out of src/config.rs into
iris-time, a leaf crate depending on nothing but serde: RtcOffset, the
UTC format the configuration and the monitor print, and the
proleptic-Gregorian day helpers the DS1687, DS1744 and DS1x86 models share.
iris::config re-exports every name, so no caller changes. Testing it through
iris::config meant building the emulator as a test binary, minutes and
gigabytes for integer arithmetic; cargo test -p iris-time is ten tests in a
second.

That paid for itself immediately: RtcOffset::between walked its month step
back one month too far when the remainder was exactly zero, so exactly
eighteen years came out as -17y -11mo -30d while still landing on the right
second. The test now checks the parts, not just the result, and fuzzes 20,000
pairs across the RTC's whole range.

gui: one wizard size, the real library in full screen, a quiet release hint

  • The New Machine wizard kept one size whatever step it showed, with room
    to spare, and the buttons followed the form down the window. The Mac window
    now holds the form at the top and Cancel/Back/Continue at the bottom, and
    takes the largest fittingSize of its four steps; the Linux dialog asks its
    content for its height (-1) through a clamp and a scroller that propagates
    it, the homogeneous stack giving the tallest step; the Windows window
    measures each step and resizes to the tallest.
  • Full screen on Windows: the library button and menu item flipped a flag
    the full-screen layout ignored, so only the floating library at the left
    edge was reachable. They now dock the real one beside the guest, and the
    floating one stays out of the way while it is there. Full screen still
    starts without it, as on the Mac.
  • Full screen on Linux takes the library out of the split and puts back
    what the window had on the way out.
  • The release hint is advice, not state: Windows drew it in the accent
    colour, and the Linux app only toasted it once. Both now show it in the
    status bar's quiet tone for as long as the guest holds the mouse, and all
    three shells take the text from DisplayController::release_hint.

Testing

cargo test -p iris-time 10/10
cargo check -p iris --lib --tests clean, no warnings
cargo check -p iris-gui-core -p iris-gui-gtk clean, no warnings
iris-gui/scripts/check-boundaries.sh 0
every t! id against locales/en/*.ftl resolves

The GTK capture paths were exercised on Wayland and on X11. The AppKit and
Win32 changes parse and follow each shell's existing patterns, but have not
been built or run on their platforms
— worth a look from someone on a Mac or
a Windows box before this lands.

The egui app (iris-gui/src) keeps its six clock boxes and its own pointer
handling: it draws its own forms and is on its way out.

🤖 Generated with Claude Code

danifunker and others added 3 commits December 3, 2026 12:05
…e hint

From bluu's notes of 2026-11-29, the parts not yet done on every shell.

- The New Machine wizard kept one size whatever step it showed, with room
  to spare, and the buttons followed the form down the window. The Mac
  window now holds the form at the top and Cancel/Back/Continue at the
  bottom, and takes the largest `fittingSize` of its four steps; the Linux
  dialog asks its content for its height (-1) through a clamp and a
  scroller that propagates it, the homogeneous stack giving the tallest
  step; the Windows window measures each step and resizes to the tallest.
- Full screen on Windows: the library button and menu item flipped a flag
  the full-screen layout ignored, so only the floating library at the left
  edge was reachable. They now dock the real one beside the guest, which
  gives it the room, and the floating one stays out of the way while it is
  there. Full screen still starts without it, as on the Mac.
- Full screen on Linux now takes the library out of the split and puts back
  what the window had on the way out.
- The release hint is advice, not state: Windows drew it in the accent
  colour, and the Linux app only toasted it once. Both now show it in the
  status bar's quiet tone, for as long as the guest holds the mouse. All
  three shells take the text from `DisplayController::release_hint`.

Checked with `cargo check` on the core and the GTK shell, and
`check-boundaries.sh`. The AppKit and Win32 changes parse but have not been
built or run on their platforms.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The last of bluu's notes of 2026-11-29: the real-time clock was a tab of its
own holding six signed number boxes, one per unit, and you worked out the
date you wanted by arithmetic.

It is now one date-and-time control, on the Machine page beside the memory
and the PROM, with "Use the host clock" next to it. `[rtc_offset]` is
unchanged on disk: `RtcOffset::between` turns the moment picked back into a
calendar offset, whole months first and the remainder as a duration, so a
date eighteen years back to the day still writes `years = -18` as someone
editing the file by hand would. `apply` now shares `step_months` with it.

Two new field kinds carry it, so no shell special-cases a section again:
`DateTime`, reported as Unix seconds in a `Value::Number`, and `Action`, a
button named by its label. The Mac draws an `NSDatePicker` in UTC, text
style rather than with a stepper, which would fire on every click while the
page is rebuilt under it; Linux a `GtkCalendar` and three spin buttons in a
popover that applies once, for the same reason; Windows a box in the format
the preview used, refused if it is not a date. The GTK and Win32 Reset
buttons that were bolted onto the clock page are gone.

The clock still starts a fixed distance from host time, not at a fixed
moment, so the row reads a day later tomorrow; the help text says so.

The calendar arithmetic all of this rests on moves out of `src/config.rs`
into `iris-time`, a leaf crate depending on nothing but serde: `RtcOffset`,
the UTC format the configuration and the monitor print, and the
proleptic-Gregorian day helpers the DS1687, DS1744 and DS1x86 models share.
`iris::config` re-exports every name, so no caller changes. Testing it
through `iris::config` meant building the emulator as a test binary, minutes
and gigabytes for integer arithmetic; `cargo test -p iris-time` is ten tests
in a second. `src/config.rs` keeps the one test that needs a whole
`MachineConfig`.

That paid for itself immediately: `RtcOffset::between` walked its month step
back one month too far when the remainder was exactly zero, so exactly
eighteen years came out as -17y -11mo -30d while still landing on the right
second. The test now checks the parts, not just the result, and fuzzes
20_000 pairs across the RTC's whole range.

Checked with `cargo test -p iris-time`, `cargo check` on `-p iris --lib
--tests` and on the core and the GTK shell, `check-boundaries.sh`, and every
`t!` id against the catalogue. The AppKit and Win32 changes parse but have
not been built or run on their platforms.

The egui app keeps its six boxes: it draws its own forms and is on its way
out.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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>
@danifunker danifunker changed the title gtk: capture the mouse for real, on Wayland and on X11 gui: the Linux, Mac and Windows shells brought level Dec 3, 2026
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.

1 participant