Skip to content

Commit

Permalink
Fix restoring ImmOpenStatus completely
Browse files Browse the repository at this point in the history
  • Loading branch information
ryancheung committed Aug 24, 2020
1 parent a91f86f commit abd08c5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions ImeSharp/Imm32Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ private IntPtr DefaultImc
private static ImmCompositionStringHandler _compositionStringHandler;
private static ImmCompositionIntHandler _compositionCursorHandler;

private bool _lastImmOpenStatus;

public Imm32Manager(IntPtr windowHandle)
{
_windowHandle = windowHandle;
Expand Down Expand Up @@ -197,7 +199,7 @@ internal bool ProcessMessage(IntPtr hWnd, uint msg, ref IntPtr wParam, ref IntPt
// Must re-associate ime context or things won't work.
NativeMethods.ImmAssociateContext(_windowHandle, DefaultImc);

if (!NativeMethods.ImmGetOpenStatus(DefaultImc))
if (_lastImmOpenStatus)
NativeMethods.ImmSetOpenStatus(DefaultImc, true);

var lParam64 = lParam.ToInt64();
Expand All @@ -207,8 +209,9 @@ internal bool ProcessMessage(IntPtr hWnd, uint msg, ref IntPtr wParam, ref IntPt
lParam64 &= ~NativeMethods.ISC_SHOWUICOMPOSITIONWINDOW;
lParam = (IntPtr)(int)lParam64;
}
else
NativeMethods.ImmSetOpenStatus(DefaultImc, false);
break;
case NativeMethods.WM_KILLFOCUS:
_lastImmOpenStatus = NativeMethods.ImmGetOpenStatus(DefaultImc);
break;
case NativeMethods.WM_IME_NOTIFY:
IMENotify(wParam.ToInt32());
Expand Down

0 comments on commit abd08c5

Please sign in to comment.