Expand description
Window management plugin for Bevy.
This plugin provides multi-monitor support, window state persistence, and utilities for managing window position and size across application sessions.
§The Problem
On macOS with multiple monitors that have different scale factors (e.g., a Retina display at scale 2.0 and an external monitor at scale 1.0), Bevy’s window positioning has issues:
-
Window.positionis unreliable at startup: When a window is created,Window.positionisAutomatic(notAt(pos)), even though winit has placed the window at a specific physical position. -
Scale factor conversion in
changed_windows: When you modifyWindow.resolution, Bevy’schanged_windowssystem applies scale factor conversion ifscale_factor != cached_scale_factor. This corrupts the size when moving windows between monitors with different scale factors. -
Timing of scale factor updates: The
CachedWindowis updated after winit events are processed, but our systems run before we receive theScaleFactorChangedevent.
§The Solution
This plugin uses winit directly to capture the actual window position at startup, compensates for scale factor conversions, and properly restores windows across monitors.
§Usage
use bevy::prelude::*;
use bevy_window_manager::WindowManagerPlugin;
App::new()
.add_plugins(DefaultPlugins)
.add_plugins(WindowManagerPlugin)
.run();The plugin automatically hides the window during startup and shows it after positioning is complete, preventing any visual flash at the default position.
See examples/custom_app_name.rs for how to override the app_name used in the path
(default is to choose executable name).
See examples/custom_path.rs for how to override the full path to the state file.
Structs§
- Current
Monitor - Component storing the current monitor for a window.
- Monitor
Info - Information about a single monitor.
- Monitors
- Sorted monitor list, updated when monitors change.
- Window
Manager Plugin - The main plugin. See module docs for usage.
- Window
Target Loaded - Event fired when window target state is loaded from the save file.
Traits§
- Window
Ext - Extension trait for
Windowproviding monitor-aware methods.