mirror of
https://github.com/rust-windowing/winit.git
synced 2026-09-02 23:00:05 -04:00
Update macOS backend to removal of Send+Sync and addition of EventsLoopProxy
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
use EventsLoopClosed;
|
||||||
use cocoa::{self, appkit, foundation};
|
use cocoa::{self, appkit, foundation};
|
||||||
use cocoa::appkit::{NSApplication, NSEvent, NSView, NSWindow};
|
use cocoa::appkit::{NSApplication, NSEvent, NSView, NSWindow};
|
||||||
use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, ModifiersState, KeyboardInput};
|
use events::{self, ElementState, Event, MouseButton, TouchPhase, WindowEvent, ModifiersState, KeyboardInput};
|
||||||
@@ -23,6 +24,8 @@ pub struct EventsLoop {
|
|||||||
user_callback: UserCallback,
|
user_callback: UserCallback,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct Proxy {}
|
||||||
|
|
||||||
struct Modifiers {
|
struct Modifiers {
|
||||||
shift_pressed: bool,
|
shift_pressed: bool,
|
||||||
ctrl_pressed: bool,
|
ctrl_pressed: bool,
|
||||||
@@ -40,9 +43,6 @@ pub struct UserCallback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unsafe impl Send for UserCallback {}
|
|
||||||
unsafe impl Sync for UserCallback {}
|
|
||||||
|
|
||||||
impl UserCallback {
|
impl UserCallback {
|
||||||
|
|
||||||
// Here we store user's `callback` behind the mutex so that they may be safely shared between
|
// 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) {
|
pub fn interrupt(&self) {
|
||||||
self.interrupted.store(true, std::sync::atomic::Ordering::Relaxed);
|
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.
|
// Removes the window with the given `Id` from the `windows` list.
|
||||||
@@ -505,7 +486,7 @@ impl EventsLoop {
|
|||||||
|
|
||||||
appkit::NSApplicationDefined => match ns_event.subtype() {
|
appkit::NSApplicationDefined => match ns_event.subtype() {
|
||||||
appkit::NSEventSubtype::NSApplicationActivatedEventType => {
|
appkit::NSEventSubtype::NSApplicationActivatedEventType => {
|
||||||
Some(into_event(WindowEvent::Awakened))
|
Some(Event::Awakened)
|
||||||
},
|
},
|
||||||
_ => None,
|
_ => 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(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#![cfg(target_os = "macos")]
|
#![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::monitor::{MonitorId, get_available_monitors, get_primary_monitor};
|
||||||
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window};
|
pub use self::window::{Id as WindowId, PlatformSpecificWindowBuilderAttributes, Window};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user