Skip to content

Commit

Permalink
On Windows, fix IME APIs MT-safety
Browse files Browse the repository at this point in the history
Execute the calls to the IME from the main thread.

Fixes #3123.
  • Loading branch information
kchibisov committed Oct 21, 2023
1 parent 74fcf7f commit 0656c54
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ And please only add new entries to the top of this list, right below the `# Unre
- On Windows, updated `WM_MOUSEMOVE` to detect when cursor Enter or Leave window client area while captured and send the corresponding events. (#3153)
- On macOS, fix crash when accessing tabbing APIs.
- On Windows, fix `RedrawRequested` not being delivered when calling `Window::request_redraw` from `RedrawRequested`.
- On Windows, fix IME APIs not working when from non event loop thread.

# 0.29.1-beta

Expand Down
19 changes: 12 additions & 7 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,17 +872,22 @@ impl Window {

#[inline]
pub fn set_ime_cursor_area(&self, spot: Position, size: Size) {
unsafe {
ImeContext::current(self.hwnd()).set_ime_cursor_area(spot, size, self.scale_factor());
}
let window = self.window.clone();
let state = self.window_state.clone();
self.thread_executor.execute_in_thread(move || unsafe {
let scale_factor = state.lock().unwrap().scale_factor;
ImeContext::current(window.0).set_ime_cursor_area(spot, size, scale_factor);
});
}

#[inline]
pub fn set_ime_allowed(&self, allowed: bool) {
self.window_state_lock().ime_allowed = allowed;
unsafe {
ImeContext::set_ime_allowed(self.hwnd(), allowed);
}
let window = self.window.clone();
let state = self.window_state.clone();
self.thread_executor.execute_in_thread(move || unsafe {
state.lock().unwrap().ime_allowed = allowed;
ImeContext::set_ime_allowed(window.0, allowed);
})
}

#[inline]
Expand Down

0 comments on commit 0656c54

Please sign in to comment.