Skip to content

fix(render): treat delivered input as proof the surface is visible - #3025

Merged
Xuepoo merged 1 commit into
mainfrom
ctx-3023/fix-input-reveal
Nov 8, 2026
Merged

Xuepoo merged 1 commit into
mainfrom
ctx-3023/fix-input-reveal

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Closes #3024.

Root cause

Switching away from Bitty's Hyprland workspace stops the compositor's frame callbacks. OcclusionProbe (OCCLUSION_STARVE = 300 ms) turns the unanswered request_redraw into a synthetic Occluded(true), which closes the surface gate. On return, Hyprland may deliver none of the qualifying reveal edges — native Occluded(false) needs the xdg-shell suspended state, and the synthetic path needs RedrawRequested, Focused(true), Resized or ScaleFactorChanged — so the gate stays closed, damage accumulates, present_owed() stays false, and the loop parks on an old frame.

Evidence from the live instance (0.0.36): the main thread sat in do_epoll_wait at 0.0 % CPU for a 10 s / 32-sample window, bitty ctl answered, the window was mapped and focused, and keys pressed during the freeze took effect once something finally repainted.

Fix

A delivered input event is proof the surface is visible: keys, pointer buttons, pointer motion, scroll, and focus gain are only delivered to a mapped, focused surface. TerminalApp::handle_event_inner now checks that before the chrome-key intercept, the capture fall-through and Runtime::handle_platform_event, and reopens the gate through set_surface_gate(true, "input"), which already queues the from-truth repaint.

Deliberately excluded: ModifiersChanged, IME enable/disable, CursorEntered, and every non-input event — plus timer (AboutToWait), PtyReadable and IPC wakes, which say nothing about visibility.

The reveal branch also clears a #2989 confirmation bound left over from the hidden incarnation; the new frame re-arms it on commit, so no duplicate corrective repaint follows.

Tests

  • delivered_input_reveals_a_surface_the_occlusion_probe_closed — closes the gate through the exact transition the Occluded(true) edge applies, retains damage, arms the hidden-repair probe and a confirmation bound, then delivers a key. Asserts the gate reopens, the app probe and both deadlines clear, a from-truth deadline is queued, and drive_tick() presents exactly one frame. Fails today: with the classifier forced to false it stops at a delivered key reopens the gate.
  • timer_and_ipc_wakes_do_not_reveal_a_closed_surface — AboutToWait + PtyReadable leave the gate closed and present nothing.

Gates

cargo fmt --all -- --check clean; RUSTFLAGS="-D warnings" cargo clippy -p bitty-terminal --all-targets and -p bitty-runtime --all-targets clean; cargo test -p bitty-terminal --features input-vm-test-support --bin bitty 1510 passed; cargo test -p bitty-runtime --lib runtime::present 158 passed; RUSTDOCFLAGS="-D warnings" cargo doc -p bitty-terminal --no-deps clean.

Not verified

No live compositor run: whether Hyprland delivers any covered event while the surface is still marked suspended, and whether input can arrive on a surface the compositor has not yet resumed, are unverified here. The fix relies on the xdg-shell guarantee that a suspended surface receives no key or pointer input.

Switching away stops frame callbacks, so the 300 ms starvation probe closes the surface gate; returning to the workspace can deliver none of the qualifying reveal edges, and the gate then stays closed while damage accumulates and the loop parks - the window keeps an old frame until an unrelated event. A key press, pointer button or motion, scroll, or focus gain can only be delivered to a mapped, focused surface, so any of them reopens the gate and queues the from-truth redraw. Timer, PTY-readable and IPC wakes are excluded: they say nothing about visibility. The reveal also clears a confirmation bound left over from the hidden incarnation, which the new frame re-arms on commit.
@Xuepoo Xuepoo added this to the v0.1.0 milestone Nov 8, 2026
@Xuepoo Xuepoo added fix Bug fix P1 Priority: high area:render Area: rendering labels Nov 8, 2026
@coderabbitai

coderabbitai Bot commented Nov 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c1a67eae-f59a-449f-9ec2-871ede9ce37d
Commits

Reviewing files that changed from the base of the PR and between dd109b8 and 5dfad4d.

Files selected for processing: 3

  • crates/bitty-runtime/src/runtime/present.rs
  • crates/bitty-terminal/src/terminal_app.rs
  • crates/bitty-terminal/src/tests.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@Xuepoo Xuepoo left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guard review — PR #3025 (input delivery as a reveal edge, #3024)

Independent checks against the tree at 5dfad4d4.

  1. Gate transition is the real one. reveal_surface_from_input early-returns when the
    surface is already visible and otherwise calls set_surface_gate(true, "input")
    (terminal_app.rs:1468), which is the same transition every native reveal edge uses: it
    clears the hidden-incarnation hidden_repair_probe_at and calls
    runtime.set_surface_visibility(true) (terminal_app.rs:1449-1458). No second gate path is
    introduced.
  2. Ordering is correct. The new block sits at terminal_app.rs:4961-4973, i.e. before the
    chrome intercept (:5002) and before the capture fall-through (:5025), so an input event
    that is consumed downstream still reveals first. That is the case the bug report needs — keys
    pressed during the freeze were applied but never presented.
  3. The exclusion set is the defensible one. is_input_visibility_proof matches
    KeyboardInput, MouseInput, MouseWheel, CursorMoved, Focused(true) only. Timer
    (AboutToWait), PtyReadable and IPC wakes are excluded, which is exactly the property the
    negative test asserts (timer_and_ipc_wakes_do_not_reveal_a_closed_surface). ModifiersChanged,
    IME bookkeeping, and CursorEntered are excluded and documented as such.
  4. The positive test discriminates. It closes the gate through the same runtime transition
    the Occluded(true) edge applies, arms both the repair probe and a #2989 confirmation bound,
    then delivers one unbound key. Without the new branch nothing sets visibility true, so the
    a delivered key reopens the gate assertion cannot pass — the test is not tautological, and
    it is not derived from the same container as the gate value it checks.
  5. Confirmation-bound cleanup is right. clear_present_confirmation() on the reveal branch
    (present.rs) drops a bound armed for the hidden incarnation; the reveal frame queues a
    from-truth present (present_coalescing_deadline is asserted Some), so a duplicate
    corrective repaint would only be noise. The test asserts the deadline is None afterwards.
  6. Residual risk, accepted. Focused(true) and CursorMoved can arrive on a surface a
    compositor still considers occluded (stacking-order occlusion with focus retained). Worst case
    is a few frames presented to an occluded surface — wasted work, no truth mutation — and it is
    the same assumption the native Focused(true) reveal edge already makes. The PR body
    correctly flags live-compositor behaviour as unverified.
  7. Checks. 13 pass / 0 fail at review time; Quality gates (1) and Windows check and test
    still pending. Merge watcher requires the full set green.

VERDICT: APPROVE

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

Labels

area:render Area: rendering fix Bug fix P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

render: returning to a Hyprland workspace leaves the window on a stale frame

1 participant