From 712b27086f0205d1ce0cb41cfde80c2e16d5ce0b Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 5 Nov 2016 13:44:23 +0100 Subject: [PATCH 1/2] Fix win32 panicking all the time and make events work --- src/platform/windows/callback.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/platform/windows/callback.rs b/src/platform/windows/callback.rs index 26e1e95e..00296a6a 100644 --- a/src/platform/windows/callback.rs +++ b/src/platform/windows/callback.rs @@ -126,16 +126,30 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, winapi::WM_MOUSEMOVE => { use events::Event::{MouseEntered, MouseMoved}; - CONTEXT_STASH.with(|context_stash| { + let mouse_outside_window = CONTEXT_STASH.with(|context_stash| { let mut context_stash = context_stash.borrow_mut(); if let Some(context_stash) = context_stash.as_mut() { if !context_stash.mouse_in_window { - send_event(window, MouseEntered); context_stash.mouse_in_window = true; + return true; } } + + false }); + if mouse_outside_window { + send_event(window, MouseEntered); + + // Calling TrackMouseEvent in order to receive mouse leave events. + user32::TrackMouseEvent(&mut winapi::TRACKMOUSEEVENT { + cbSize: mem::size_of::() as winapi::DWORD, + dwFlags: winapi::TME_LEAVE, + hwndTrack: window, + dwHoverTime: winapi::HOVER_DEFAULT, + }); + } + let x = winapi::GET_X_LPARAM(lparam) as i32; let y = winapi::GET_Y_LPARAM(lparam) as i32; @@ -146,16 +160,22 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT, winapi::WM_MOUSELEAVE => { use events::Event::MouseLeft; - CONTEXT_STASH.with(|context_stash| { + let mouse_in_window = CONTEXT_STASH.with(|context_stash| { let mut context_stash = context_stash.borrow_mut(); if let Some(context_stash) = context_stash.as_mut() { if context_stash.mouse_in_window { - send_event(window, MouseLeft); context_stash.mouse_in_window = false; + return true; } } + + false }); + if mouse_in_window { + send_event(window, MouseLeft); + } + 0 }, From 38ad236df0aa36f4edda352db02d91bee5702571 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 5 Nov 2016 13:44:36 +0100 Subject: [PATCH 2/2] Publish 0.5.5 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 2326ff3d..02eb93ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "winit" -version = "0.5.4" +version = "0.5.5" authors = ["The winit contributors, Pierre Krieger "] description = "Cross-platform window creation library." keywords = ["windowing"]