mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
Fix win32 panicking all the time and make events work
This commit is contained in:
parent
f4d0a26495
commit
712b27086f
|
@ -126,16 +126,30 @@ pub unsafe extern "system" fn callback(window: winapi::HWND, msg: winapi::UINT,
|
||||||
|
|
||||||
winapi::WM_MOUSEMOVE => {
|
winapi::WM_MOUSEMOVE => {
|
||||||
use events::Event::{MouseEntered, MouseMoved};
|
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();
|
let mut context_stash = context_stash.borrow_mut();
|
||||||
if let Some(context_stash) = context_stash.as_mut() {
|
if let Some(context_stash) = context_stash.as_mut() {
|
||||||
if !context_stash.mouse_in_window {
|
if !context_stash.mouse_in_window {
|
||||||
send_event(window, MouseEntered);
|
|
||||||
context_stash.mouse_in_window = true;
|
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::<winapi::TRACKMOUSEEVENT>() as winapi::DWORD,
|
||||||
|
dwFlags: winapi::TME_LEAVE,
|
||||||
|
hwndTrack: window,
|
||||||
|
dwHoverTime: winapi::HOVER_DEFAULT,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let x = winapi::GET_X_LPARAM(lparam) as i32;
|
let x = winapi::GET_X_LPARAM(lparam) as i32;
|
||||||
let y = winapi::GET_Y_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 => {
|
winapi::WM_MOUSELEAVE => {
|
||||||
use events::Event::MouseLeft;
|
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();
|
let mut context_stash = context_stash.borrow_mut();
|
||||||
if let Some(context_stash) = context_stash.as_mut() {
|
if let Some(context_stash) = context_stash.as_mut() {
|
||||||
if context_stash.mouse_in_window {
|
if context_stash.mouse_in_window {
|
||||||
send_event(window, MouseLeft);
|
|
||||||
context_stash.mouse_in_window = false;
|
context_stash.mouse_in_window = false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if mouse_in_window {
|
||||||
|
send_event(window, MouseLeft);
|
||||||
|
}
|
||||||
|
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue