#![doc = include_str!("../README.md")]
mod constants;
#[cfg(target_os = "macos")]
mod macos_tabbing_fix;
mod monitors;
mod observers;
mod platform;
mod restore_plan;
mod state;
mod state_format;
mod systems;
#[allow(
clippy::used_underscore_binding,
reason = "false positive on enum variant fields"
)]
mod types;
#[cfg(all(target_os = "windows", feature = "workaround-winit-4341"))]
mod windows_dpi_fix;
#[cfg(all(target_os = "linux", feature = "workaround-winit-4445"))]
mod x11_frame_extents;
use std::path::PathBuf;
use bevy::prelude::*;
pub use monitors::CurrentMonitor;
pub use monitors::MonitorInfo;
pub use monitors::Monitors;
pub use platform::Platform;
pub use state_format::WindowKey;
pub use types::ManagedWindow;
pub use types::ManagedWindowPersistence;
pub use types::WindowRestoreMismatch;
pub use types::WindowRestored;
pub struct WindowManagerPlugin;
impl WindowManagerPlugin {
#[must_use]
#[expect(clippy::expect_used, reason = "fail fast if path cannot be determined")]
pub fn with_app_name(app_name: impl Into<String>) -> impl Plugin {
WindowManagerPluginCustomPath {
path: state::get_state_path_for_app(&app_name.into())
.expect("Could not determine state file path"),
persistence: ManagedWindowPersistence::default(),
}
}
#[must_use]
pub fn with_path(path: impl Into<PathBuf>) -> impl Plugin {
WindowManagerPluginCustomPath {
path: path.into(),
persistence: ManagedWindowPersistence::default(),
}
}
#[must_use]
#[expect(clippy::expect_used, reason = "fail fast if path cannot be determined")]
pub fn with_persistence(persistence: ManagedWindowPersistence) -> impl Plugin {
WindowManagerPluginCustomPath {
path: state::get_default_state_path().expect("Could not determine state file path"),
persistence,
}
}
}
impl Plugin for WindowManagerPlugin {
#[expect(clippy::expect_used, reason = "fail fast if path cannot be determined")]
fn build(&self, app: &mut App) {
let path = state::get_default_state_path().expect("Could not determine state file path");
observers::build_plugin(app, path, ManagedWindowPersistence::default());
}
}
struct WindowManagerPluginCustomPath {
path: PathBuf,
persistence: ManagedWindowPersistence,
}
impl Plugin for WindowManagerPluginCustomPath {
fn build(&self, app: &mut App) {
observers::build_plugin(app, self.path.clone(), self.persistence.clone());
}
}