fix: window state events

This commit is contained in:
Ashley Wulber 2025-09-25 15:38:16 -04:00
parent 43f4760b0e
commit ec30b8004f
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
5 changed files with 28 additions and 1 deletions

View file

@ -375,6 +375,11 @@ pub enum WindowEvent {
/// - **iOS / Android / Web / Orbital / Windows:** Unsupported.
SuggestedBounds(Option<PhysicalSize<u32>>),
/// The window state has changed.
///
/// - **iOS / Android / Web / Orbital / Windows:** Unsupported.
WindowStateChanged,
/// The system window theme has changed.
///
/// Applications might wish to react to this to change the theme of the content of the window

View file

@ -395,6 +395,11 @@ impl EventLoop {
app.window_event(&self.active_event_loop, window_id, event);
}
if compositor_update.xdg_window_state.is_some() {
let event = WindowEvent::WindowStateChanged;
app.window_event(&self.active_event_loop, window_id, event);
}
// NOTE: Rescale changed the physical size which winit operates in, thus we should
// resize.
if compositor_update.resized || compositor_update.scale_changed {

View file

@ -313,6 +313,12 @@ impl WindowHandler for WinitState {
self.window_compositor_updates[pos].suggested_bounds |= configure.suggested_bounds
!= winit_window.last_configure.as_ref().and_then(|last| last.suggested_bounds);
self.window_compositor_updates[pos].xdg_window_state = winit_window
.last_configure
.as_ref()
.is_none_or(|last| last.state != configure.state)
.then_some(configure.state);
self.window_compositor_updates[pos].resized |=
winit_window.configure(configure, &self.shm, &self.subcompositor_state);
@ -445,6 +451,9 @@ pub struct WindowCompositorUpdate {
/// New suggested bounds.
pub suggested_bounds: bool,
/// New xdg window state.
pub xdg_window_state: Option<sctk::reexports::csd_frame::WindowState>,
}
impl WindowCompositorUpdate {
@ -455,6 +464,7 @@ impl WindowCompositorUpdate {
scale_changed: false,
close_window: false,
suggested_bounds: false,
xdg_window_state: None,
}
}
}

View file

@ -252,6 +252,11 @@ impl Window {
pub fn surface(&self) -> &WlSurface {
self.window.wl_surface()
}
#[inline]
pub fn xdg_window_state(&self) -> Option<sctk::reexports::csd_frame::WindowState> {
self.window_state.lock().unwrap().last_configure.as_ref().map(|c| c.state)
}
}
impl Drop for Window {

View file

@ -557,7 +557,9 @@ impl ApplicationHandler for Application {
| WindowEvent::DragDropped { .. }
| WindowEvent::Destroyed
| WindowEvent::Ime(_)
| WindowEvent::Moved(_) => (),
| WindowEvent::Moved(_)
| WindowEvent::SuggestedBounds(_)
| WindowEvent::WindowStateChanged => (),
}
}