From ad9648769d2b4b0e812883320721d78d7fb9279f Mon Sep 17 00:00:00 2001 From: Daniel Collin Date: Mon, 14 Mar 2022 15:28:55 +0100 Subject: [PATCH] Fixed button hold on window exit On Windows when moving the cursor out of the window while holding a mouse button down it would still be set to true when entering the window even if the button had been released outside of the window. Closes #280 --- src/os/windows/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index 01fb69e..1d91f14 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -217,6 +217,18 @@ unsafe extern "system" fn wnd_proc( winuser::WM_LBUTTONUP => wnd.mouse.state[0] = false, + winuser::WM_MOUSEMOVE => { + let button_checks = [winuser::MK_LBUTTON, winuser::MK_MBUTTON, winuser::MK_RBUTTON]; + + for i in 0..3 { + if (wparam & button_checks[i]) == button_checks[i] { + wnd.mouse.state[i] = true; + } else { + wnd.mouse.state[i] = false; + } + } + } + winuser::WM_MBUTTONDOWN => wnd.mouse.state[1] = true, winuser::WM_MBUTTONUP => wnd.mouse.state[1] = false,