Skip to main content

Module windows

Module windows 

Source
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 Rc shim. egui asks a deferred window’s callback to be Send + 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_title names 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_open in 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::quit closes everything, moving nothing.
  • Geometry is read from each window’s own pass (egui’s ViewportInfo rects 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 appWindow context 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_window makes run_native use wgpu’s AutoNoVsync there (paced by winit’s frame callbacks), keeping AutoVsync elsewhere; present_mode does 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.
WindowId
An application window’s id: stable across runs, as its geometry is saved under it.
WindowInfo
An open window, as AppHandle::windows lists it.
WindowSpec
What a window opens with.
WindowUi
The window being drawn, for its content.
WindowsPlugin
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.switch and window.close are 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; main in 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_DISPLAY set), AutoNoVsync, as a FIFO present can stall every window behind one surface; AutoVsync elsewhere.

Type Aliases§

Content
A window’s content: drawn each pass of its window.