Expand description
Application windows: several OS windows in one process, each almost an application of its own (ADR 0025).
Experimental: may change in any release
(docs/stability.md).
The application opens a window with AppHandle::open_window, giving
a WindowSpec and the window’s content: a closure drawing it each
pass, which may hold Rc state. Each window is an egui deferred
viewport: it repaints on its own, so an idle window sleeps while
another animates. The windows are declared from the main window’s pass
(App::show); the main window is the root, always
the first window, and its content is the application’s shell.
- The
Rcshim. egui asks a deferred window’s callback to beSend + Sync. eframe runs it on the main thread, so the callback holds only the window’s viewport id and finds the window and the application in a thread-local registry; it asserts (in debug builds) that it runs on the thread that opened the window. Off that thread the registry is empty and the window draws nothing. - Titles come from the content.
WindowUi::set_titlenames the window after what it does (“Import — card 3”), and a change reaches the system’s title bar at once. - Closing. A window’s close button closes it, unless its content
calls
WindowUi::keep_openin the pass that sees the request (WindowUi::close_requested). Closing the main window while other windows are open does not quit: the close is cancelled and the window worked in last moves into the main window (its content, title, id, size and, where the platform tells it, position), its own window closing. Closing the last window quits. Raising the main window (WindowId::main) then sends that content back to a window of its own and draws the shell again, at the main window’s own size;AppHandle::quitcloses everything, moving nothing. - Geometry is read from each window’s own pass (egui’s
ViewportInforects stay empty for deferred windows on Wayland) and saved per window id in the persistence directory (windows.json), then given back when a window of that id opens again. The position only where the platform tells it (never on Wayland). - Frame. When the application draws the frame
(
FramePlugin::own), each window is built without the system’s decorations and draws the main window’s title bar (its title, minimize, maximize, close); so does a window’s content moved into the main window, the shell’s bar having left with the shell. - Per window: its keys are dispatched in its own pass, with the
appWindowcontext key naming it (when: "appWindow == 'import'"); dialogs, the palette and popup menus open over the window worked in last; a modal open in one application window blocks that window only (the main window and its detached panels block one another, as before). - Present mode. On Wayland, a FIFO present waits on the compositor
in the one UI thread and can stall every window (seen on headless
mutter).
AppBuilder::multi_windowmakesrun_nativeuse wgpu’sAutoNoVsyncthere (paced by winit’s frame callbacks), keepingAutoVsyncelsewhere;present_modedoes it for an application running eframe itself.
Where the backend has no windows of its own (the web, kittest), egui
embeds each window in the main one as an egui::Window: the same
content runs there.
Structs§
- Geometry
- A window’s place, as saved.
- Window
Id - An application window’s id: stable across runs, as its geometry is saved under it.
- Window
Info - An open window, as
AppHandle::windowslists it. - Window
Spec - What a window opens with.
- Window
Ui - The window being drawn, for its content.
- Windows
Plugin - The window menu and its commands, for an application opening windows
of its own: Window lists the open windows by title (the active one
ticked) and switches to one;
window.switchandwindow.closeare offered to agents and the palette;window.pick(Switch to Window…) lists the open windows in a choice with a filter field, opened in the window it is asked in (with the dialogs plugin).
Constants§
- CMD_
CLOSE - Closes a window:
{ "window": id }, or the active one. - CMD_
PICK - A quick pick of the open windows by title, as the palette lists
commands: the one chosen comes to the front (
CMD_SWITCH). - CMD_
SWITCH - Brings a window to the front:
{ "window": id }, or, without one, the next open window after the active one (cycling). - CONTEXT_
APP_ WINDOW - The context key naming the application window being drawn (its
WindowId;mainin the main window until another moves into it). - GEOMETRY_
DOC - Where the windows’ geometry is kept, under the persistence directory.
- LIST_
WINDOWS - The list of open windows, by title, in the Window menu.
- MENU_
WINDOW - The Window menu.
Functions§
- present_
mode - Sets the options’ present mode for several windows
(
wanted_present_mode, Wayland read from the environment), unless the application chose one other than eframe’s default. Returns the mode in force. - wanted_
present_ mode - The wgpu present mode a multi-window application should use: on
Wayland (
WAYLAND_DISPLAYset),AutoNoVsync, as a FIFO present can stall every window behind one surface;AutoVsyncelsewhere.
Type Aliases§
- Content
- A window’s content: drawn each pass of its window.