diff --git a/crates/bevy_window/src/event.rs b/crates/bevy_window/src/event.rs index d92516d731e42..0bd07191cf42c 100644 --- a/crates/bevy_window/src/event.rs +++ b/crates/bevy_window/src/event.rs @@ -57,7 +57,7 @@ pub struct WindowCreated { /// be closed. This will be sent when the close button of the window is pressed. /// /// If the default [`WindowPlugin`] is used, these events are handled -/// by closing the corresponding [`Window`]. +/// by closing the corresponding [`Window`]. /// To disable this behavior, set `close_when_requested` on the [`WindowPlugin`] /// to `false`. /// @@ -236,6 +236,29 @@ pub struct WindowFocused { pub focused: bool, } +/// The window has been occluded (completely hidden from view). +/// +/// This is different to window visibility as it depends on +/// whether the window is closed, minimised, set invisible, +/// or fully occluded by another window. +/// +/// It is the translated version of [`WindowEvent::Occluded`] from the `winit` crate. +/// +/// [`WindowEvent::Occluded`]: https://docs.rs/winit/latest/winit/event/enum.WindowEvent.html#variant.Occluded +#[derive(Event, Debug, Clone, PartialEq, Eq, Reflect)] +#[reflect(Debug, PartialEq)] +#[cfg_attr( + feature = "serialize", + derive(serde::Serialize, serde::Deserialize), + reflect(Serialize, Deserialize) +)] +pub struct WindowOccluded { + /// Window that changed occluded state. + pub window: Entity, + /// Whether it was occluded (true) or not occluded (false). + pub occluded: bool, +} + /// An event that indicates a window's scale factor has changed. #[derive(Event, Debug, Clone, PartialEq, Reflect)] #[reflect(Debug, PartialEq)] diff --git a/crates/bevy_window/src/lib.rs b/crates/bevy_window/src/lib.rs index 3846814097388..ae83d4f5016b9 100644 --- a/crates/bevy_window/src/lib.rs +++ b/crates/bevy_window/src/lib.rs @@ -93,6 +93,7 @@ impl Plugin for WindowPlugin { .add_event::() .add_event::() .add_event::() + .add_event::() .add_event::() .add_event::() .add_event::() @@ -137,6 +138,7 @@ impl Plugin for WindowPlugin { .register_type::() .register_type::() .register_type::() + .register_type::() .register_type::() .register_type::() .register_type::() diff --git a/crates/bevy_winit/src/lib.rs b/crates/bevy_winit/src/lib.rs index 2f043727321f3..49754ec29bd4d 100644 --- a/crates/bevy_winit/src/lib.rs +++ b/crates/bevy_winit/src/lib.rs @@ -40,7 +40,8 @@ use bevy_window::{ exit_on_all_closed, ApplicationLifetime, CursorEntered, CursorLeft, CursorMoved, FileDragAndDrop, Ime, ReceivedCharacter, RequestRedraw, Window, WindowBackendScaleFactorChanged, WindowCloseRequested, WindowCreated, WindowDestroyed, - WindowFocused, WindowMoved, WindowResized, WindowScaleFactorChanged, WindowThemeChanged, + WindowFocused, WindowMoved, WindowOccluded, WindowResized, WindowScaleFactorChanged, + WindowThemeChanged, }; #[cfg(target_os = "android")] use bevy_window::{PrimaryWindow, RawHandleWrapper}; @@ -275,6 +276,7 @@ struct WindowAndInputEventWriters<'w> { window_scale_factor_changed: EventWriter<'w, WindowScaleFactorChanged>, window_backend_scale_factor_changed: EventWriter<'w, WindowBackendScaleFactorChanged>, window_focused: EventWriter<'w, WindowFocused>, + window_occluded: EventWriter<'w, WindowOccluded>, window_moved: EventWriter<'w, WindowMoved>, window_theme_changed: EventWriter<'w, WindowThemeChanged>, window_destroyed: EventWriter<'w, WindowDestroyed>, @@ -658,6 +660,12 @@ pub fn winit_runner(mut app: App) { focused, }); } + WindowEvent::Occluded(occluded) => { + event_writers.window_occluded.send(WindowOccluded { + window: window_entity, + occluded, + }); + } WindowEvent::DroppedFile(path_buf) => { event_writers .file_drag_and_drop