initial macos porting work

This commit is contained in:
Will Temple
2026-03-23 15:16:20 -04:00
parent 4193457fc4
commit 861bf63621
40 changed files with 4575 additions and 233 deletions

View File

@@ -32,7 +32,7 @@ pub struct PlatformProxy {
pub struct PlatformRuntime {
proxy: PlatformProxy,
events: mpsc::Receiver<PlatformEvent>,
_worker: WorkerHandle,
worker: Option<WorkerHandle>,
}
pub struct PlatformEndpoint {
@@ -73,6 +73,7 @@ pub enum PlatformEvent {
window_id: WindowId,
text: String,
},
#[cfg(target_os = "linux")]
PrimarySelectionText {
window_id: WindowId,
text: String,
@@ -118,10 +119,12 @@ pub enum PlatformRequest {
RequestClipboardText {
window_id: WindowId,
},
#[cfg(target_os = "linux")]
SetPrimarySelectionText {
window_id: WindowId,
text: String,
},
#[cfg(target_os = "linux")]
RequestPrimarySelectionText {
window_id: WindowId,
},
@@ -203,7 +206,30 @@ impl PlatformRuntime {
Self {
proxy,
events: event_rx,
_worker: worker,
worker: Some(worker),
}
}
/// Creates a platform runtime hosted by the current runtime thread.
///
/// This is useful for backends that must run on a specific host thread
/// (for example, AppKit on macOS main thread).
pub fn custom_local(start: impl FnOnce(PlatformEndpoint)) -> Self {
let (command_tx, command_rx) = mpsc::unbounded_channel::<PlatformRequest>();
let (event_tx, event_rx) = mpsc::unbounded_channel::<PlatformEvent>();
let proxy = PlatformProxy {
command_tx,
next_window_id: Arc::new(AtomicU64::new(1)),
};
start(PlatformEndpoint {
commands: command_rx,
events: event_tx,
});
Self {
proxy,
events: event_rx,
worker: None,
}
}
@@ -216,6 +242,7 @@ impl PlatformRuntime {
}
pub fn take_pending_events(&mut self) -> Vec<PlatformEvent> {
let _ = self.worker.as_ref();
let mut events = Vec::new();
while let Ok(event) = self.events.try_recv() {
events.push(event);
@@ -247,6 +274,7 @@ impl PlatformProxy {
self.send(PlatformRequest::ReplaceScene { window_id, scene })
}
#[cfg(target_os = "linux")]
pub fn set_primary_selection_text(
&self,
window_id: WindowId,
@@ -258,6 +286,7 @@ impl PlatformProxy {
})
}
#[cfg(target_os = "linux")]
pub fn request_primary_selection_text(
&self,
window_id: WindowId,
@@ -356,7 +385,9 @@ pub fn start_headless() -> PlatformRuntime {
}
PlatformRequest::SetClipboardText { .. } => {}
PlatformRequest::RequestClipboardText { .. } => {}
#[cfg(target_os = "linux")]
PlatformRequest::SetPrimarySelectionText { .. } => {}
#[cfg(target_os = "linux")]
PlatformRequest::RequestPrimarySelectionText { .. } => {}
PlatformRequest::SetCursorIcon { .. } => {}
PlatformRequest::EmitCloseRequested { window_id } => {