Skip to content

Fix incorrect CandidateWindow position when using Pinyin IMEs in Windows #18759

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

Merged
merged 1 commit into from
May 9, 2025
Merged
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
29 changes: 1 addition & 28 deletions src/Windows/Avalonia.Win32/Input/Imm32InputMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,6 @@ private void MoveImeWindow(Rect rect, IntPtr himc)
var s = _parent?.DesktopScaling ?? 1;
var (x1, y1, x2, y2) = ((int) (p1.X * s), (int) (p1.Y * s), (int) (p2.X * s), (int) (p2.Y * s));

if (!ShowCompositionWindow && _langId == LANG_ZH)
{
// Chinese IMEs ignore function calls to ::ImmSetCandidateWindow()
// when a user disables TSF (Text Service Framework) and CUAS (Cicero
// Unaware Application Support).
// On the other hand, when a user enables TSF and CUAS, Chinese IMEs
// ignore the position of the current system caret and uses the
// parameters given to ::ImmSetCandidateWindow() with its 'dwStyle'
// parameter CFS_CANDIDATEPOS.
// Therefore, we do not only call ::ImmSetCandidateWindow() but also
// set the positions of the temporary system caret.
var candidateForm = new CANDIDATEFORM
{
dwIndex = 0,
dwStyle = CFS_CANDIDATEPOS,
ptCurrentPos = new POINT {X = x2, Y = y2}
};

ImmSetCandidateWindow(himc, ref candidateForm);
}

_caretManager.TryMove(x2, y2);

if (ShowCompositionWindow)
Expand All @@ -250,14 +229,8 @@ private void MoveImeWindow(Rect rect, IntPtr himc)
y2 += CaretMargin;
}

// Need to return here since some Chinese IMEs would stuck if set
// candidate window position with CFS_EXCLUDE style.
if (_langId == LANG_ZH)
{
return;
}

// Japanese IMEs and Korean IMEs also use the rectangle given to
// Chinese, Japanese, and Korean(CJK) IMEs also use the rectangle given to
// ::ImmSetCandidateWindow() with its 'dwStyle' parameter CFS_EXCLUDE
// to move their candidate windows when a user disables TSF and CUAS.
// Therefore, we also set this parameter here.
Expand Down
Loading