mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-26 03:36:32 +11:00
Better events handling for win32
This commit is contained in:
parent
7a8e7a7922
commit
1e615b59a6
2 changed files with 11 additions and 31 deletions
|
@ -564,6 +564,9 @@ extern "system" {
|
||||||
// http://msdn.microsoft.com/en-us/library/dd145167(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/dd145167(v=vs.85).aspx
|
||||||
pub fn UpdateWindow(hWnd: HWND) -> BOOL;
|
pub fn UpdateWindow(hWnd: HWND) -> BOOL;
|
||||||
|
|
||||||
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms644956(v=vs.85).aspx
|
||||||
|
pub fn WaitMessage() -> BOOL;
|
||||||
|
|
||||||
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd374379(v=vs.85).aspx
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd374379(v=vs.85).aspx
|
||||||
pub fn wglCreateContext(hdc: HDC) -> HGLRC;
|
pub fn wglCreateContext(hdc: HDC) -> HGLRC;
|
||||||
|
|
||||||
|
|
|
@ -204,7 +204,7 @@ impl Window {
|
||||||
loop {
|
loop {
|
||||||
let mut msg = unsafe { mem::uninitialized() };
|
let mut msg = unsafe { mem::uninitialized() };
|
||||||
|
|
||||||
if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 1) } == 0 {
|
if unsafe { ffi::PeekMessageW(&mut msg, ptr::mut_null(), 0, 0, 0x1) } == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,37 +220,20 @@ impl Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if events.iter().find(|e| match e { &&::Closed => true, _ => false }).is_some() {
|
||||||
|
use std::sync::atomics::Relaxed;
|
||||||
|
self.should_close.store(true, Relaxed);
|
||||||
|
}
|
||||||
|
|
||||||
events
|
events
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: return iterator
|
// TODO: return iterator
|
||||||
pub fn wait_events(&self) -> Vec<Event> {
|
pub fn wait_events(&self) -> Vec<Event> {
|
||||||
use std::mem;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
{
|
unsafe { ffi::WaitMessage() };
|
||||||
let mut msg = unsafe { mem::uninitialized() };
|
|
||||||
|
|
||||||
if unsafe { ffi::GetMessageW(&mut msg, ptr::mut_null(), 0, 0) } == 0 {
|
|
||||||
use std::sync::atomics::Relaxed;
|
|
||||||
use Closed;
|
|
||||||
|
|
||||||
self.should_close.store(true, Relaxed);
|
|
||||||
return vec![Closed]
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
let events = self.poll_events();
|
||||||
if events.len() >= 1 {
|
if events.len() >= 1 {
|
||||||
return events
|
return events
|
||||||
}
|
}
|
||||||
|
@ -316,12 +299,6 @@ extern "stdcall" fn callback(window: ffi::HWND, msg: ffi::UINT,
|
||||||
0
|
0
|
||||||
},
|
},
|
||||||
|
|
||||||
ffi::WM_PAINT => {
|
|
||||||
/*use NeedRefresh;
|
|
||||||
send_event(window, NeedRefresh);*/
|
|
||||||
0
|
|
||||||
},
|
|
||||||
|
|
||||||
ffi::WM_CHAR => {
|
ffi::WM_CHAR => {
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use events::ReceivedCharacter;
|
use events::ReceivedCharacter;
|
||||||
|
|
Loading…
Add table
Reference in a new issue