Skip to content

Commit

Permalink
fix(macos): make set_inner_size a sync operation
Browse files Browse the repository at this point in the history
  • Loading branch information
hut36 committed Dec 9, 2024
1 parent 6336179 commit 4be2236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 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 Down
2 changes: 1 addition & 1 deletion src/platform_impl/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4be2236

Please sign in to comment.