Window and renderer lifecycle #
The host may have one committed native window. A <window> in the UI tree is
the desired state; WindowManager
owns the committed native::Window, while
WindowState owns its renderer and last
presented frame.
Teardown rule #
Release the installed renderer before calling Window::close() on its
window. WindowCompositor owns
a layer surface attached to that window's content view, and drops it before its
retained Rc<Window>. Window::close() calls the platform backend's close
method but keeps the Rust window handle until it is dropped. Dropping the
renderer first avoids asking the backend to close a window while its installed
presentation surface is still live.
The host applies this order in four paths:
| Path | Order |
|---|---|
| Replace | Prepare a candidate window and renderer; commit them together; discard the old frame; drop the old renderer; close the old window. A recoverable candidate failure leaves the committed pair in place. |
Remove <window> |
Clear the renderer and presented frame before WindowManager closes the committed window. The host then clears pointer state and requests exit if a window has existed. |
Close (close() or the close button) |
The same teardown as removal, and the GPU state resets so open() initializes graphics from scratch. The element stays connected, so the app keeps running and open() creates a new window. Its elements stay too, so the pointer leaves the ones it was over, with pointerleave, as when the cursor leaves the window. The close button fires a cancelable close event; unless a listener cancels it, the host closes the element on its next turn, as close() does. The event goes to the tree's window element: after a replacement failed and left the old window on screen, that is the element that replaced it, and closing it closes the old window. |
| Shutdown or fatal error | Clear the renderer and frame, then close the committed window. |
A window that is replaced, removed, or closed also ends the input under way
in it. The host queues a pointer cancel for the press, and a Cancelled
wheel for a trackpad gesture that fingers rest in, since the platform sends
the gesture's end to the window that went. It also ends an IME composition,
keeping its marked text.
Initial creation is different: the window exists before asynchronous graphics initialization can create its renderer. The host installs the result only if it still matches the desired window.
A layout, scene, window sync, or renderer resize failure is recoverable once the active renderer has presented a frame, even while that frame is of an old size, as it is from a resize until the next frame: the host keeps the window and the frame on screen, and tries again on the next revision. Before the renderer's first frame, the same failure is fatal.
The headless tests
replacing_and_closing_drop_renderer_before_window
and
removing_window_drops_renderer_before_closing_window
observe renderer Drop and the backend close() call. The removal test failed
when removal closed the window first. These tests guard host ordering; they do
not exercise a real OS window or prove when the platform compositor releases
its layers.