mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-23 10:26:34 +11:00
Add a method to simplify emitting an event from the macos poll_events and run_forever methods
This commit is contained in:
parent
fd0ddee63c
commit
c03311fa2d
1 changed files with 11 additions and 12 deletions
|
@ -58,9 +58,7 @@ impl EventsLoop {
|
||||||
loop {
|
loop {
|
||||||
// First, yield all pending events.
|
// First, yield all pending events.
|
||||||
while let Some(event) = self.pending_events.lock().unwrap().pop_front() {
|
while let Some(event) = self.pending_events.lock().unwrap().pop_front() {
|
||||||
if let Ok(mut callback) = self.callback.lock() {
|
self.emit_event(event);
|
||||||
callback.as_mut().unwrap()(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -79,9 +77,7 @@ impl EventsLoop {
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
// Call the user's callback.
|
// Call the user's callback.
|
||||||
Some(event) => if let Ok(mut callback) = self.callback.lock() {
|
Some(event) => self.emit_event(event),
|
||||||
callback.as_mut().unwrap()(event);
|
|
||||||
},
|
|
||||||
None => break,
|
None => break,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,9 +104,7 @@ impl EventsLoop {
|
||||||
loop {
|
loop {
|
||||||
// First, yield all pending events.
|
// First, yield all pending events.
|
||||||
while let Some(event) = self.pending_events.lock().unwrap().pop_front() {
|
while let Some(event) = self.pending_events.lock().unwrap().pop_front() {
|
||||||
if let Ok(mut callback) = self.callback.lock() {
|
self.emit_event(event);
|
||||||
callback.as_mut().unwrap()(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -124,9 +118,7 @@ impl EventsLoop {
|
||||||
cocoa::base::YES);
|
cocoa::base::YES);
|
||||||
|
|
||||||
if let Some(event) = self.ns_event_to_event(ns_event) {
|
if let Some(event) = self.ns_event_to_event(ns_event) {
|
||||||
if let Ok(mut callback) = self.callback.lock() {
|
self.emit_event(event);
|
||||||
callback.as_mut().unwrap()(event);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let _: () = msg_send![pool, release];
|
let _: () = msg_send![pool, release];
|
||||||
|
@ -183,6 +175,13 @@ impl EventsLoop {
|
||||||
*self.callback.lock().unwrap() = Some(boxed);
|
*self.callback.lock().unwrap() = Some(boxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Emits the given event via the user-given callback.
|
||||||
|
fn emit_event(&self, event: Event) {
|
||||||
|
if let Ok(mut callback) = self.callback.lock() {
|
||||||
|
callback.as_mut().unwrap()(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Convert some given `NSEvent` into a winit `Event`.
|
// Convert some given `NSEvent` into a winit `Event`.
|
||||||
unsafe fn ns_event_to_event(&self, ns_event: cocoa::base::id) -> Option<Event> {
|
unsafe fn ns_event_to_event(&self, ns_event: cocoa::base::id) -> Option<Event> {
|
||||||
if ns_event == cocoa::base::nil {
|
if ns_event == cocoa::base::nil {
|
||||||
|
|
Loading…
Add table
Reference in a new issue