Start removing the Send impl for App

Co-authored-by: Antonio <antonio@zed.dev>
Co-authored-by: Nathan <nathan@zed.dev>
This commit is contained in:
Max Brunsfeld 2023-11-01 11:31:23 -07:00 committed by Nathan Sobo
parent ea7fdef417
commit 57ffa8201e
38 changed files with 506 additions and 932 deletions

View file

@ -1,10 +1,10 @@
use super::{display_bounds_from_native, ns_string, MacDisplay, MetalRenderer, NSRange};
use crate::{
display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, Executor, ExternalPaths,
FileDropEvent, GlobalPixels, InputEvent, KeyDownEvent, Keystroke, Modifiers,
ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent, Pixels,
PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, Scene, Size,
Timer, WindowAppearance, WindowBounds, WindowKind, WindowOptions, WindowPromptLevel,
display_bounds_to_native, point, px, size, AnyWindowHandle, Bounds, ExternalPaths,
FileDropEvent, ForegroundExecutor, GlobalPixels, InputEvent, KeyDownEvent, Keystroke,
Modifiers, ModifiersChangedEvent, MouseButton, MouseDownEvent, MouseMoveEvent, MouseUpEvent,
Pixels, PlatformAtlas, PlatformDisplay, PlatformInputHandler, PlatformWindow, Point, Scene,
Size, Timer, WindowAppearance, WindowBounds, WindowKind, WindowOptions, WindowPromptLevel,
};
use block::ConcreteBlock;
use cocoa::{
@ -315,7 +315,7 @@ struct InsertText {
struct MacWindowState {
handle: AnyWindowHandle,
executor: Executor,
executor: ForegroundExecutor,
native_window: id,
renderer: MetalRenderer,
scene_to_render: Option<Scene>,
@ -451,7 +451,11 @@ unsafe impl Send for MacWindowState {}
pub struct MacWindow(Arc<Mutex<MacWindowState>>);
impl MacWindow {
pub fn open(handle: AnyWindowHandle, options: WindowOptions, executor: Executor) -> Self {
pub fn open(
handle: AnyWindowHandle,
options: WindowOptions,
executor: ForegroundExecutor,
) -> Self {
unsafe {
let pool = NSAutoreleasePool::new(nil);
@ -674,13 +678,10 @@ impl MacWindow {
impl Drop for MacWindow {
fn drop(&mut self) {
let this = self.0.clone();
let executor = self.0.lock().executor.clone();
executor
.run_on_main(move || unsafe {
this.lock().native_window.close();
})
.detach();
let native_window = self.0.lock().native_window;
unsafe {
native_window.close();
}
}
}
@ -807,7 +808,7 @@ impl PlatformWindow for MacWindow {
let native_window = self.0.lock().native_window;
let executor = self.0.lock().executor.clone();
executor
.spawn_on_main_local(async move {
.spawn(async move {
let _: () = msg_send![
alert,
beginSheetModalForWindow: native_window
@ -824,7 +825,7 @@ impl PlatformWindow for MacWindow {
let window = self.0.lock().native_window;
let executor = self.0.lock().executor.clone();
executor
.spawn_on_main_local(async move {
.spawn(async move {
unsafe {
let _: () = msg_send![window, makeKeyAndOrderFront: nil];
}
@ -872,25 +873,17 @@ impl PlatformWindow for MacWindow {
fn zoom(&self) {
let this = self.0.lock();
let window = this.native_window;
this.executor
.spawn_on_main_local(async move {
unsafe {
window.zoom_(nil);
}
})
.detach();
unsafe {
window.zoom_(nil);
}
}
fn toggle_full_screen(&self) {
let this = self.0.lock();
let window = this.native_window;
this.executor
.spawn_on_main_local(async move {
unsafe {
window.toggleFullScreen_(nil);
}
})
.detach();
unsafe {
window.toggleFullScreen_(nil);
}
}
fn on_input(&self, callback: Box<dyn FnMut(InputEvent) -> bool>) {
@ -1189,7 +1182,7 @@ extern "C" fn handle_view_event(this: &Object, _: Sel, native_event: id) {
lock.synthetic_drag_counter += 1;
let executor = lock.executor.clone();
executor
.spawn_on_main_local(synthetic_drag(
.spawn(synthetic_drag(
weak_window_state,
lock.synthetic_drag_counter,
event.clone(),
@ -1317,7 +1310,7 @@ extern "C" fn window_did_change_key_status(this: &Object, selector: Sel, _: id)
let executor = lock.executor.clone();
drop(lock);
executor
.spawn_on_main_local(async move {
.spawn(async move {
let mut lock = window_state.as_ref().lock();
if let Some(mut callback) = lock.activate_callback.take() {
drop(lock);