From 28cdce99c09a4c6ac8e55a591bee9293e81a4878 Mon Sep 17 00:00:00 2001 From: gzp Date: Fri, 28 Jul 2017 13:09:50 +0200 Subject: [PATCH 1/5] replace wm_destroy by wm_close --- src/platform/windows/events_loop.rs | 2 +- src/platform/windows/window.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/platform/windows/events_loop.rs b/src/platform/windows/events_loop.rs index 6f34c0a0..e9374fa4 100644 --- a/src/platform/windows/events_loop.rs +++ b/src/platform/windows/events_loop.rs @@ -281,7 +281,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, -> winapi::LRESULT { match msg { - winapi::WM_DESTROY => { + winapi::WM_CLOSE => { use events::WindowEvent::Closed; send_event(Event::WindowEvent { window_id: SuperWindowId(WindowId(window)), diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs index d0f1189b..16ac42c1 100644 --- a/src/platform/windows/window.rs +++ b/src/platform/windows/window.rs @@ -282,7 +282,7 @@ impl Drop for Window { #[inline] fn drop(&mut self) { unsafe { - user32::PostMessageW(self.window.0, winapi::WM_DESTROY, 0, 0); + user32::PostMessageW(self.window.0, winapi::WM_CLOSE, 0, 0); } } } From c57ec33c009660826a11a8e0fce19505b7931e0d Mon Sep 17 00:00:00 2001 From: gzp Date: Fri, 28 Jul 2017 13:12:16 +0200 Subject: [PATCH 2/5] also call default window handle on wm_close --- src/platform/windows/events_loop.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/windows/events_loop.rs b/src/platform/windows/events_loop.rs index e9374fa4..11716bac 100644 --- a/src/platform/windows/events_loop.rs +++ b/src/platform/windows/events_loop.rs @@ -291,7 +291,7 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, let mut context_stash = context_stash.borrow_mut(); context_stash.as_mut().unwrap().windows.remove(&window); }); - 0 + user32::DefWindowProcW(window, msg, wparam, lparam) }, winapi::WM_ERASEBKGND => { From 491bc891e8319ff730f42ee2f57d01714c12cf06 Mon Sep 17 00:00:00 2001 From: gzp Date: Fri, 28 Jul 2017 13:28:55 +0200 Subject: [PATCH 3/5] test explicit drop --- examples/multiwindow.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index c020f69d..54ac1d47 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -6,8 +6,14 @@ fn main() { let window1 = winit::Window::new(&events_loop).unwrap(); let window2 = winit::Window::new(&events_loop).unwrap(); let window3 = winit::Window::new(&events_loop).unwrap(); + let window4 = winit::Window::new(&events_loop).unwrap(); - let mut num_windows = 3; + let window4_id = window4.id(); + let mut window4_opt = Some(window4); + + let mut num_windows = 4; + + println!("Press any key on any window to drop the 4th window explicitly. (Testing impl Drop for Window)"); if cfg!(target_os = "linux") { println!("Running this example under wayland may not display a window at all.\n\ @@ -24,6 +30,8 @@ fn main() { println!("Window 2 has been closed") } else if window_id == window3.id() { println!("Window 3 has been closed"); + } else if window_id == window4_id { + println!("Window 4 has been closed"); } else { unreachable!() } @@ -33,6 +41,12 @@ fn main() { return winit::ControlFlow::Break; } }, + + winit::Event::WindowEvent { event: winit::WindowEvent::KeyboardInput{..}, .. } => { + println!("Dropping window 4 explicitly"); + window4_opt = None; + }, + _ => (), } winit::ControlFlow::Continue From 8f03fb7a34d6e1a720ace443d3b9ed49cf3fc011 Mon Sep 17 00:00:00 2001 From: gzp Date: Mon, 31 Jul 2017 12:25:49 +0200 Subject: [PATCH 4/5] Revert "test explicit drop" This reverts commit 491bc891e8319ff730f42ee2f57d01714c12cf06. --- examples/multiwindow.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/examples/multiwindow.rs b/examples/multiwindow.rs index 54ac1d47..c020f69d 100644 --- a/examples/multiwindow.rs +++ b/examples/multiwindow.rs @@ -6,14 +6,8 @@ fn main() { let window1 = winit::Window::new(&events_loop).unwrap(); let window2 = winit::Window::new(&events_loop).unwrap(); let window3 = winit::Window::new(&events_loop).unwrap(); - let window4 = winit::Window::new(&events_loop).unwrap(); - let window4_id = window4.id(); - let mut window4_opt = Some(window4); - - let mut num_windows = 4; - - println!("Press any key on any window to drop the 4th window explicitly. (Testing impl Drop for Window)"); + let mut num_windows = 3; if cfg!(target_os = "linux") { println!("Running this example under wayland may not display a window at all.\n\ @@ -30,8 +24,6 @@ fn main() { println!("Window 2 has been closed") } else if window_id == window3.id() { println!("Window 3 has been closed"); - } else if window_id == window4_id { - println!("Window 4 has been closed"); } else { unreachable!() } @@ -41,12 +33,6 @@ fn main() { return winit::ControlFlow::Break; } }, - - winit::Event::WindowEvent { event: winit::WindowEvent::KeyboardInput{..}, .. } => { - println!("Dropping window 4 explicitly"); - window4_opt = None; - }, - _ => (), } winit::ControlFlow::Continue From d868510cc8dcd80b32e8e0f0cad8df50dfa1ace5 Mon Sep 17 00:00:00 2001 From: zpgaal Date: Mon, 31 Jul 2017 18:00:29 +0200 Subject: [PATCH 5/5] Comment to describe message order --- src/platform/windows/window.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/platform/windows/window.rs b/src/platform/windows/window.rs index 16ac42c1..d737a36b 100644 --- a/src/platform/windows/window.rs +++ b/src/platform/windows/window.rs @@ -282,6 +282,8 @@ impl Drop for Window { #[inline] fn drop(&mut self) { unsafe { + // We are sending WM_CLOSE, and our callback will process this by calling DefWindowProcW, + // which in turn will send a WM_DESTROY. user32::PostMessageW(self.window.0, winapi::WM_CLOSE, 0, 0); } }