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

Windows: implement Window.set_ime_position() with IMM API. #1790

Merged
merged 4 commits into from
Dec 9, 2020

Conversation

moko256
Copy link
Contributor

@moko256 moko256 commented Dec 7, 2020

  • Tested on all platforms changed
  • Compilation warnings were addressed
  • cargo fmt has been run on this branch
  • cargo doc builds successfully
  • Added an entry to CHANGELOG.md if knowledge of this change could be valuable to users
  • Updated documentation to reflect any user-facing changes, including notes of platform-specific behavior
  • Created or updated an example program if it would help users understand this functionality
  • Updated feature matrix, if new features were added or implemented

I tested in Windows 10 18363.1198 with Microsoft Japanese IME. I am not tested without IME. I followed IMM documentation and implementation will not call IMM API if Windows has no IME.

IMM docs: https://docs.microsoft.com/ja-jp/windows/win32/intl/about-input-method-manager
ImmSetCompositionWindow docs: https://docs.microsoft.com/en-us/windows/win32/api/imm/nf-imm-immsetcompositionwindow
COMPOSITIONFORM docs: https://docs.microsoft.com/en-us/windows/win32/api/imm/ns-imm-compositionform
GetSystemMetrics and SM_IMMENABLED docs: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics

@moko256
Copy link
Contributor Author

moko256 commented Dec 7, 2020

New example set_ime_position.rs screenshots.
This is not enable IME but tell position to IME. I enabled IME outside of this application.

Environments Before call set_ime_position() IME following mouse cursor Setting IME position to (10, 10)
Windows 10 (18363.1198, MS IME Japanese) set_ime_position_win10_case_0_default set_ime_position_win10_case_1_follow_cursor set_ime_position_win10_case_2_10x10
Ubuntu 20.04.1 (Gnome 3.36.3, X11, Mozc 2.23.2815.102) set_ime_position_ubuntu2004_case_0_default set_ime_position_ubuntu2004_case_1_follow_cursor set_ime_position_ubuntu2004_case_2_10x10

Copy link
Member

@msiglreith msiglreith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for the contribution 👋
I played a bit with the provided demo and works ok overall. I noticed a bit of flickering when moving around the mouse cursor, not sure if this is platform specific, also the candidate window doesn't seem to follow (how does unix handle this?) - overall not sure how important this is in a real application. I assume 'static' composition windows are more common on text input. It might make sense to adjust the demo a bit to only set the position on click?

Also, please add a changelog entry please for other users to know!

@@ -616,9 +618,25 @@ impl Window {
self.window_state.lock().taskbar_icon = taskbar_icon;
}

pub(crate) fn set_ime_position_physical(&self, x: i32, y: i32) {
if unsafe { winuser::GetSystemMetrics(winuser::SM_DBCSENABLED) } != 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I installed an east asian language pack for testing and it only worked when switching to SM_IMMENABLED here.

Copy link
Contributor Author

@moko256 moko256 Dec 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I made a mistake. Thanks,

@moko256
Copy link
Contributor Author

moko256 commented Dec 8, 2020

I fixed that demo based on your review, and add to changelog. Thank a lot!
(In Some platform, candidate window handle mouse cursor event and window may not receive it.)

@moko256
Copy link
Contributor Author

moko256 commented Dec 9, 2020

I ran the demo in Windows 10 1809, Windows 8.1, and it worked.

@moko256 moko256 marked this pull request as ready for review December 9, 2020 03:33
@kchibisov kchibisov merged commit db038d9 into rust-windowing:master Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants