Update macOS backend to removal of Send+Sync and addition of EventsLoopProxy

This commit is contained in:
mitchmindtree 2017-05-31 15:00:49 +10:00
parent 9ca2f83784
commit 339318f295
2 changed files with 33 additions and 24 deletions

View file

@ -1,3 +1,4 @@
use EventsLoopClosed;
use cocoa::{self, appkit, foundation};
use cocoa::appkit::{NSApplication, NSEvent, NSView, NSWindow};
use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, ModifiersState, KeyboardInput};
@ -23,6 +24,8 @@ pub struct EventsLoop {
user_callback: UserCallback,
}
pub struct Proxy {}
struct Modifiers {
shift_pressed: bool,
ctrl_pressed: bool,
@ -40,9 +43,6 @@ pub struct UserCallback {
}
unsafe impl Send for UserCallback {}
unsafe impl Sync for UserCallback {}
impl UserCallback {
// Here we store user's `callback` behind the mutex so that they may be safely shared between
@ -197,25 +197,6 @@ impl EventsLoop {
pub fn interrupt(&self) {
self.interrupted.store(true, std::sync::atomic::Ordering::Relaxed);
// Awaken the event loop by triggering `NSApplicationActivatedEventType`.
unsafe {
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
let event =
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
cocoa::base::nil,
appkit::NSApplicationDefined,
foundation::NSPoint::new(0.0, 0.0),
appkit::NSEventModifierFlags::empty(),
0.0,
0,
cocoa::base::nil,
appkit::NSEventSubtype::NSApplicationActivatedEventType,
0,
0);
appkit::NSApp().postEvent_atStart_(event, cocoa::base::NO);
foundation::NSAutoreleasePool::drain(pool);
}
}
// Removes the window with the given `Id` from the `windows` list.
@ -505,7 +486,7 @@ impl EventsLoop {
appkit::NSApplicationDefined => match ns_event.subtype() {
appkit::NSEventSubtype::NSApplicationActivatedEventType => {
Some(into_event(WindowEvent::Awakened))
Some(Event::Awakened)
},
_ => None,
},
@ -514,6 +495,34 @@ impl EventsLoop {
}
}
pub fn create_proxy(&self) -> Proxy {
Proxy {}
}
}
impl Proxy {
pub fn wakeup(&self) -> Result<(), EventsLoopClosed> {
// Awaken the event loop by triggering `NSApplicationActivatedEventType`.
unsafe {
let pool = foundation::NSAutoreleasePool::new(cocoa::base::nil);
let event =
NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_(
cocoa::base::nil,
appkit::NSApplicationDefined,
foundation::NSPoint::new(0.0, 0.0),
appkit::NSEventModifierFlags::empty(),
0.0,
0,
cocoa::base::nil,
appkit::NSEventSubtype::NSApplicationActivatedEventType,
0,
0);
appkit::NSApp().postEvent_atStart_(event, cocoa::base::NO);
foundation::NSAutoreleasePool::drain(pool);
}
Ok(())
}
}

View file

@ -1,6 +1,6 @@
#![cfg(target_os = "macos")]
pub use self::events_loop::EventsLoop;
pub use self::events_loop::{EventsLoop, Proxy as EventsLoopProxy};
pub use self::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window};