winit-win32: prevent inner size reported as (0,0) when minimized

This commit is contained in:
Diggory Hardy 2025-11-01 14:39:57 +00:00 committed by GitHub
parent 9d9d21cfdb
commit a9c189a423
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 37 additions and 10 deletions

View file

@ -1301,7 +1301,6 @@ unsafe fn public_window_callback_inner(
use winit_core::event::WindowEvent::SurfaceResized;
let w = util::loword(lparam as u32) as u32;
let h = util::hiword(lparam as u32) as u32;
let physical_size = PhysicalSize::new(w, h);
{
@ -1313,7 +1312,14 @@ unsafe fn public_window_callback_inner(
w.set_window_flags_in_place(|f| f.set(WindowFlags::MAXIMIZED, maximized));
}
}
userdata.send_window_event(window, SurfaceResized(physical_size));
let mut state = userdata.window_state_lock();
if (w, h) != (0, 0) && physical_size != state.surface_size {
// WM_SIZE is received with size (0, 0) when a window is minimized; ignore.
state.surface_size = physical_size;
drop(state);
userdata.send_window_event(window, SurfaceResized(physical_size));
}
result = ProcResult::Value(0);
},

View file

@ -509,14 +509,7 @@ impl CoreWindow for Window {
}
fn surface_size(&self) -> PhysicalSize<u32> {
let mut rect: RECT = unsafe { mem::zeroed() };
if unsafe { GetClientRect(self.hwnd(), &mut rect) } == false.into() {
panic!(
"Unexpected GetClientRect failure: please report this error to \
rust-windowing/winit"
)
}
PhysicalSize::new((rect.right - rect.left) as u32, (rect.bottom - rect.top) as u32)
self.window_state_lock().surface_size
}
fn outer_size(&self) -> PhysicalSize<u32> {

View file

@ -33,6 +33,9 @@ pub(crate) struct WindowState {
pub min_size: Option<Size>,
pub max_size: Option<Size>,
/// The last known size of the window surface
pub surface_size: PhysicalSize<u32>,
pub surface_resize_increments: Option<Size>,
pub window_icon: Option<Icon>,
@ -166,6 +169,8 @@ impl WindowState {
min_size: attributes.min_surface_size,
max_size: attributes.max_surface_size,
surface_size: PhysicalSize::default(),
surface_resize_increments: attributes.surface_resize_increments,
window_icon: attributes.window_icon.clone(),