feat: SuggestedBounds event
This commit is contained in:
parent
b961e4877d
commit
66dc0eab25
3 changed files with 42 additions and 5 deletions
|
|
@ -368,6 +368,13 @@ pub enum WindowEvent {
|
|||
surface_size_writer: SurfaceSizeWriter,
|
||||
},
|
||||
|
||||
/// The suggested bounds of the window's surface has changed.
|
||||
///
|
||||
/// Contains the new bounds of the surface
|
||||
///
|
||||
/// - **iOS / Android / Web / Orbital / Windows:** Unsupported.
|
||||
SuggestedBounds(Option<PhysicalSize<u32>>),
|
||||
|
||||
/// The system window theme has changed.
|
||||
///
|
||||
/// Applications might wish to react to this to change the theme of the content of the window
|
||||
|
|
|
|||
|
|
@ -379,6 +379,22 @@ impl EventLoop {
|
|||
}
|
||||
}
|
||||
|
||||
if compositor_update.suggested_bounds {
|
||||
let suggested_bounds = self.with_state(|state| {
|
||||
let windows = state.windows.get_mut();
|
||||
let window = windows.get(&window_id).unwrap().lock().unwrap();
|
||||
|
||||
window
|
||||
.last_configure
|
||||
.as_ref()
|
||||
.and_then(|c| c.suggested_bounds)
|
||||
.map(|b| dpi::PhysicalSize::new(b.0, b.1))
|
||||
.clone()
|
||||
});
|
||||
let event = WindowEvent::SuggestedBounds(suggested_bounds);
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -301,15 +301,20 @@ impl WindowHandler for WinitState {
|
|||
self.window_compositor_updates.len() - 1
|
||||
};
|
||||
|
||||
// Populate the configure to the window.
|
||||
self.window_compositor_updates[pos].resized |= self
|
||||
let mut winit_window = self
|
||||
.windows
|
||||
.get_mut()
|
||||
.get_mut(&window_id)
|
||||
.expect("got configure for dead window.")
|
||||
.lock()
|
||||
.unwrap()
|
||||
.configure(configure, &self.shm, &self.subcompositor_state);
|
||||
.unwrap();
|
||||
// Populate the configure to the window.
|
||||
|
||||
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].resized |=
|
||||
winit_window.configure(configure, &self.shm, &self.subcompositor_state);
|
||||
|
||||
// NOTE: configure demands wl_surface::commit, however winit doesn't commit on behalf of the
|
||||
// users, since it can break a lot of things, thus it'll ask users to redraw instead.
|
||||
|
|
@ -437,11 +442,20 @@ pub struct WindowCompositorUpdate {
|
|||
|
||||
/// Close the window.
|
||||
pub close_window: bool,
|
||||
|
||||
/// New suggested bounds.
|
||||
pub suggested_bounds: bool,
|
||||
}
|
||||
|
||||
impl WindowCompositorUpdate {
|
||||
fn new(window_id: WindowId) -> Self {
|
||||
Self { window_id, resized: false, scale_changed: false, close_window: false }
|
||||
Self {
|
||||
window_id,
|
||||
resized: false,
|
||||
scale_changed: false,
|
||||
close_window: false,
|
||||
suggested_bounds: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue