Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(macos): make set_outer_position and set_inner_size sync operations #1024

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/platform_impl/macos/util/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,17 @@ pub unsafe fn set_content_size_async(ns_window: id, size: LogicalSize<f64>) {
});
}

pub unsafe fn set_content_size_sync(ns_window: id, size: LogicalSize<f64>) {
if is_main_thread() {
ns_window.setContentSize_(NSSize::new(size.width as CGFloat, size.height as CGFloat));
} else {
let ns_window = MainThreadSafe(ns_window);
Queue::main().exec_sync(move || {
ns_window.setContentSize_(NSSize::new(size.width as CGFloat, size.height as CGFloat));
});
}
}

// `setFrameTopLeftPoint:` isn't thread-safe, but fortunately has the courtesy
// to log errors.
pub unsafe fn set_frame_top_left_point_async(ns_window: id, point: NSPoint) {
Expand All @@ -99,6 +110,19 @@ pub unsafe fn set_frame_top_left_point_async(ns_window: id, point: NSPoint) {
});
}

// `setFrameTopLeftPoint:` isn't thread-safe, but fortunately has the courtesy
// to log errors.
pub unsafe fn set_frame_top_left_point_sync(ns_window: id, point: NSPoint) {
if is_main_thread() {
ns_window.setFrameTopLeftPoint_(point);
} else {
let ns_window = MainThreadSafe(ns_window);
Queue::main().exec_sync(move || {
ns_window.setFrameTopLeftPoint_(point);
})
}
}

// `setFrameTopLeftPoint:` isn't thread-safe, and fails silently.
pub unsafe fn set_level_async(ns_window: id, level: ffi::NSWindowLevel) {
let ns_window = MainThreadSafe(ns_window);
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ impl UnownedWindow {
let scale_factor = self.scale_factor();
let position = position.to_logical(scale_factor);
unsafe {
util::set_frame_top_left_point_async(*self.ns_window, util::window_position(position));
util::set_frame_top_left_point_sync(*self.ns_window, util::window_position(position));
}
}

Expand All @@ -715,7 +715,7 @@ impl UnownedWindow {
pub fn set_inner_size(&self, size: Size) {
unsafe {
let scale_factor = self.scale_factor();
util::set_content_size_async(*self.ns_window, size.to_logical(scale_factor));
util::set_content_size_sync(*self.ns_window, size.to_logical(scale_factor));
}
}

Expand Down
Loading