mirror of
https://github.com/rust-windowing/winit.git
synced 2026-06-26 22:53:15 -04:00
Remove symlinking between winit-appkit and winit-uikit (#4530)
This commit is contained in:
@@ -20,6 +20,9 @@ xkb = ["dep:xkbcommon-dl", "dep:smol_str"]
|
||||
# CoreFoundation
|
||||
core-foundation = ["dep:block2", "dep:objc2", "dep:objc2-core-foundation"]
|
||||
|
||||
# Foundation
|
||||
foundation = ["dep:block2", "dep:objc2", "dep:objc2-foundation"]
|
||||
|
||||
[dependencies]
|
||||
smol_str = { workspace = true, optional = true }
|
||||
tracing.workspace = true
|
||||
@@ -30,7 +33,7 @@ memmap2 = { workspace = true, optional = true }
|
||||
x11-dl = { workspace = true, optional = true }
|
||||
xkbcommon-dl = { workspace = true, optional = true }
|
||||
|
||||
# CoreFoundation
|
||||
# Foundation / CoreFoundation
|
||||
block2 = { workspace = true, optional = true }
|
||||
objc2 = { workspace = true, optional = true }
|
||||
objc2-core-foundation = { workspace = true, optional = true, features = [
|
||||
@@ -40,6 +43,13 @@ objc2-core-foundation = { workspace = true, optional = true, features = [
|
||||
"CFRunLoop",
|
||||
"CFString",
|
||||
] }
|
||||
objc2-foundation = { workspace = true, optional = true, features = [
|
||||
"std",
|
||||
"block2",
|
||||
"NSNotification",
|
||||
"NSString",
|
||||
"NSOperation",
|
||||
] }
|
||||
|
||||
[package.metadata.docs.rs]
|
||||
all-features = true
|
||||
|
||||
3
winit-common/src/foundation/mod.rs
Normal file
3
winit-common/src/foundation/mod.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
mod notification_center;
|
||||
|
||||
pub use self::notification_center::*;
|
||||
30
winit-common/src/foundation/notification_center.rs
Normal file
30
winit-common/src/foundation/notification_center.rs
Normal file
@@ -0,0 +1,30 @@
|
||||
use std::ptr::NonNull;
|
||||
|
||||
use block2::RcBlock;
|
||||
use objc2::rc::Retained;
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_foundation::{
|
||||
NSNotification, NSNotificationCenter, NSNotificationName, NSObjectProtocol,
|
||||
};
|
||||
|
||||
/// Observe the given notification.
|
||||
///
|
||||
/// This is used in Winit as an alternative to declaring an application delegate, as we want to
|
||||
/// give the user full control over those.
|
||||
pub fn create_observer(
|
||||
center: &NSNotificationCenter,
|
||||
name: &NSNotificationName,
|
||||
handler: impl Fn(&NSNotification) + 'static,
|
||||
) -> Retained<ProtocolObject<dyn NSObjectProtocol>> {
|
||||
let block = RcBlock::new(move |notification: NonNull<NSNotification>| {
|
||||
handler(unsafe { notification.as_ref() });
|
||||
});
|
||||
unsafe {
|
||||
center.addObserverForName_object_queue_usingBlock(
|
||||
Some(name),
|
||||
None, // No sender filter
|
||||
None, // No queue, run on posting thread (i.e. main thread)
|
||||
&block,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -4,5 +4,7 @@
|
||||
pub mod core_foundation;
|
||||
#[cfg(feature = "event-handler")]
|
||||
pub mod event_handler;
|
||||
#[cfg(feature = "foundation")]
|
||||
pub mod foundation;
|
||||
#[cfg(feature = "xkb")]
|
||||
pub mod xkb;
|
||||
|
||||
Reference in New Issue
Block a user