mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Fix events handling on win32
This commit is contained in:
parent
24baf4d104
commit
c67ab381bf
|
@ -381,6 +381,10 @@ extern "system" {
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa366730(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa366730(v=vs.85).aspx
|
||||||
pub fn LocalFree(hMem: HLOCAL) -> HLOCAL;
|
pub fn LocalFree(hMem: HLOCAL) -> HLOCAL;
|
||||||
|
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644943(v=vs.85).aspx
|
||||||
|
pub fn PeekMessageW(lpMsg: *mut MSG, hWnd: HWND, wMsgFilterMin: UINT, wMsgFilterMax: UINT,
|
||||||
|
wRemoveMsg: UINT) -> BOOL;
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644945(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644945(v=vs.85).aspx
|
||||||
pub fn PostQuitMessage(nExitCode: libc::c_int);
|
pub fn PostQuitMessage(nExitCode: libc::c_int);
|
||||||
|
|
||||||
|
|
|
@ -198,13 +198,35 @@ impl Window {
|
||||||
|
|
||||||
// TODO: return iterator
|
// TODO: return iterator
|
||||||
pub fn poll_events(&self) -> Vec<Event> {
|
pub fn poll_events(&self) -> Vec<Event> {
|
||||||
unimplemented!()
|
use std::mem;
|
||||||
|
|
||||||
|
loop {
|
||||||
|
let mut msg = unsafe { mem::uninitialized() };
|
||||||
|
|
||||||
|
if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 1) } == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe { ffi::TranslateMessage(&msg) };
|
||||||
|
unsafe { ffi::DispatchMessageW(&msg) };
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut events = Vec::new();
|
||||||
|
loop {
|
||||||
|
match self.events_receiver.try_recv() {
|
||||||
|
Ok(ev) => events.push(ev),
|
||||||
|
Err(_) => break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return iterator
|
// TODO: return iterator
|
||||||
pub fn wait_events(&self) -> Vec<Event> {
|
pub fn wait_events(&self) -> Vec<Event> {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
|
||||||
|
loop {
|
||||||
{
|
{
|
||||||
let mut msg = unsafe { mem::uninitialized() };
|
let mut msg = unsafe { mem::uninitialized() };
|
||||||
|
|
||||||
|
@ -227,7 +249,11 @@ impl Window {
|
||||||
Err(_) => break
|
Err(_) => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
events
|
|
||||||
|
if events.len() >= 1 {
|
||||||
|
return events
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn make_current(&self) {
|
pub fn make_current(&self) {
|
||||||
|
@ -276,8 +302,8 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT,
|
||||||
match msg {
|
match msg {
|
||||||
ffi::WM_DESTROY => {
|
ffi::WM_DESTROY => {
|
||||||
use Closed;
|
use Closed;
|
||||||
send_event(window, Closed);
|
|
||||||
unsafe { ffi::PostQuitMessage(0); }
|
unsafe { ffi::PostQuitMessage(0); }
|
||||||
|
send_event(window, Closed);
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue