Skip to main content

Module display_mode

Module display_mode 

Source
Expand description

The backend-agnostic display-mode list behind the “Resolution” settings row. A backend enumerates the modes (width x height at refresh rate) the display it renders to supports; this module holds the shared shaping: the row/list label format, the dedup + sort that turns a raw enumeration into the menu list, the persisted-choice -> list-index recovery, and the static fallback a backend without enumeration (or an embedded view with no window) uses so the row still drives the windowed resize path.

How a chosen mode is applied stays per window mode: windowed resizes the window’s content area to the resolution; fullscreen switches the display to the mode itself (resolution + refresh rate); borderless always covers the display’s current mode, so the row is inert there.

Structs§

DisplayMode
One display mode the hardware supports: pixel dimensions plus refresh rate. refresh_hz of 0 means unknown (some built-in panels report none); the label then omits the rate and a fullscreen apply keeps the display’s current rate.

Functions§

best_native_index
The index in modes of the native mode to apply for want: an exact (resolution, rate) match wins; a want with an unknown rate (0) or a rate the display no longer offers takes the matching resolution’s highest rate; None when no mode has that resolution (e.g. a stale persisted choice from another monitor), so the caller leaves the display alone. Used by the DirectX + Vulkan apply paths; Metal does the same matching natively over CGDisplayModes (find_native_mode), so this is dead on a Metal-only build.
fallback_modes
The static list used when the backend cannot enumerate the display (DirectX / Vulkan today, or an embedded view with no window). Common resolutions with no rate, so the row keeps driving the windowed resize path.
index_of
The list index for a (possibly persisted) choice. An exact match wins; a choice whose resolution is listed but whose rate is not (the display changed) snaps to that resolution’s nearest rate; otherwise the nearest resolution by pixel count, so a stale persisted mode still lands somewhere sensible. Returns 0 for an empty list (callers guard, but stay total).
normalize
The menu list for a raw enumeration: duplicates collapsed, ordered by width, then height, then refresh rate ascending (each resolution’s rate variants group together).