mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-12 05:31:31 +11:00
Fixes #358
This commit is contained in:
parent
70d36a3d3d
commit
53663d0ecc
|
@ -32,7 +32,7 @@ use std::sync::Mutex;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel};
|
use events::Event::{Awakened, MouseInput, MouseMoved, ReceivedCharacter, KeyboardInput, MouseWheel, Closed};
|
||||||
use events::ElementState::{Pressed, Released};
|
use events::ElementState::{Pressed, Released};
|
||||||
use events::MouseButton;
|
use events::MouseButton;
|
||||||
use events;
|
use events;
|
||||||
|
@ -56,6 +56,9 @@ struct DelegateState {
|
||||||
view: IdRef,
|
view: IdRef,
|
||||||
window: IdRef,
|
window: IdRef,
|
||||||
resize_handler: Option<fn(u32, u32)>,
|
resize_handler: Option<fn(u32, u32)>,
|
||||||
|
|
||||||
|
/// Events that have been retreived with XLib but not dispatched with iterators yet
|
||||||
|
pending_events: Mutex<VecDeque<Event>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct WindowDelegate {
|
struct WindowDelegate {
|
||||||
|
@ -73,6 +76,8 @@ impl WindowDelegate {
|
||||||
let state: *mut libc::c_void = *this.get_ivar("glutinState");
|
let state: *mut libc::c_void = *this.get_ivar("glutinState");
|
||||||
let state = state as *mut DelegateState;
|
let state = state as *mut DelegateState;
|
||||||
(*state).is_closed = true;
|
(*state).is_closed = true;
|
||||||
|
|
||||||
|
(*state).pending_events.lock().unwrap().push_back(Closed);
|
||||||
}
|
}
|
||||||
YES
|
YES
|
||||||
}
|
}
|
||||||
|
@ -147,9 +152,6 @@ pub struct Window {
|
||||||
window: IdRef,
|
window: IdRef,
|
||||||
context: IdRef,
|
context: IdRef,
|
||||||
delegate: WindowDelegate,
|
delegate: WindowDelegate,
|
||||||
|
|
||||||
/// Events that have been retreived with XLib but not dispatched with iterators yet
|
|
||||||
pending_events: Mutex<VecDeque<Event>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
|
@ -183,7 +185,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
type Item = Event;
|
type Item = Event;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() {
|
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
||||||
return Some(ev);
|
return Some(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -231,7 +233,7 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
let vkey = event::vkeycode_to_element(NSEvent::keyCode(event));
|
let vkey = event::vkeycode_to_element(NSEvent::keyCode(event));
|
||||||
events.push_back(KeyboardInput(Pressed, NSEvent::keyCode(event) as u8, vkey));
|
events.push_back(KeyboardInput(Pressed, NSEvent::keyCode(event) as u8, vkey));
|
||||||
let event = events.pop_front();
|
let event = events.pop_front();
|
||||||
self.window.pending_events.lock().unwrap().extend(events.into_iter());
|
self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter());
|
||||||
event
|
event
|
||||||
},
|
},
|
||||||
NSKeyUp => {
|
NSKeyUp => {
|
||||||
|
@ -261,13 +263,15 @@ impl<'a> Iterator for PollEventsIterator<'a> {
|
||||||
events.push_back(alt_modifier.unwrap());
|
events.push_back(alt_modifier.unwrap());
|
||||||
}
|
}
|
||||||
let event = events.pop_front();
|
let event = events.pop_front();
|
||||||
self.window.pending_events.lock().unwrap().extend(events.into_iter());
|
self.window.delegate.state.pending_events.lock().unwrap().extend(events.into_iter());
|
||||||
event
|
event
|
||||||
},
|
},
|
||||||
NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaY() as i32)) },
|
NSScrollWheel => { Some(MouseWheel(event.scrollingDeltaY() as i32)) },
|
||||||
_ => { None },
|
_ => { None },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
event
|
event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -282,7 +286,7 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Event> {
|
fn next(&mut self) -> Option<Event> {
|
||||||
loop {
|
loop {
|
||||||
if let Some(ev) = self.window.pending_events.lock().unwrap().pop_front() {
|
if let Some(ev) = self.window.delegate.state.pending_events.lock().unwrap().pop_front() {
|
||||||
return Some(ev);
|
return Some(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,6 +351,7 @@ impl Window {
|
||||||
view: view.clone(),
|
view: view.clone(),
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
resize_handler: None,
|
resize_handler: None,
|
||||||
|
pending_events: Mutex::new(VecDeque::new()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let window = Window {
|
let window = Window {
|
||||||
|
@ -354,8 +359,6 @@ impl Window {
|
||||||
window: window,
|
window: window,
|
||||||
context: context,
|
context: context,
|
||||||
delegate: WindowDelegate::new(ds),
|
delegate: WindowDelegate::new(ds),
|
||||||
|
|
||||||
pending_events: Mutex::new(VecDeque::new()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(window)
|
Ok(window)
|
||||||
|
|
Loading…
Reference in a new issue