Run Window::set_ime_position on main thread on macOS

Fixes #2756.
This commit is contained in:
Amandus Søve Thorsrud 2023-04-15 01:58:36 +02:00 committed by GitHub
parent 2486f0f1a1
commit 60e91b187a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 4 deletions

View file

@ -10,6 +10,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- Bump MSRV from `1.60` to `1.64`.
- On macOS, fixed potential panic when getting refresh rate.
- On macOS, fix crash when calling `Window::set_ime_position` from another thread.
# 0.28.3

View file

@ -2,10 +2,10 @@ use std::ops::Deref;
use dispatch::Queue;
use objc2::foundation::{is_main_thread, CGFloat, NSPoint, NSSize, NSString};
use objc2::rc::autoreleasepool;
use objc2::rc::{autoreleasepool, Id};
use crate::{
dpi::LogicalSize,
dpi::{LogicalPosition, LogicalSize},
platform_impl::platform::{
appkit::{NSScreen, NSWindow, NSWindowLevel, NSWindowStyleMask},
ffi,
@ -201,3 +201,11 @@ pub(crate) fn close_sync(window: &NSWindow) {
});
});
}
pub(crate) fn set_ime_position_sync(window: &WinitWindow, logical_spot: LogicalPosition<f64>) {
let window = MainThreadSafe(window);
run_on_main(move || {
// TODO(madsmtm): Remove the need for this
unsafe { Id::from_shared(window.view()) }.set_ime_position(logical_spot);
});
}

View file

@ -1165,8 +1165,7 @@ impl WinitWindow {
pub fn set_ime_position(&self, spot: Position) {
let scale_factor = self.scale_factor();
let logical_spot = spot.to_logical(scale_factor);
// TODO(madsmtm): Remove the need for this
unsafe { Id::from_shared(self.view()) }.set_ime_position(logical_spot);
util::set_ime_position_sync(self, logical_spot);
}
#[inline]