Browse Source
Merge pull request #8206 from MarchingCube/fix-imm32-window-leak
Clear IMM state when window is closed.
pull/8209/head
Nikita Tsukanov
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
24 additions and
0 deletions
-
src/Windows/Avalonia.Win32/Input/Imm32InputMethod.cs
-
src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs
|
|
|
@ -37,6 +37,24 @@ namespace Avalonia.Win32.Input |
|
|
|
IsComposing = false; |
|
|
|
} |
|
|
|
|
|
|
|
public void ClearLanguageAndWindow() |
|
|
|
{ |
|
|
|
if (HWND != IntPtr.Zero && _defaultImc != IntPtr.Zero) |
|
|
|
{ |
|
|
|
ImmReleaseContext(HWND, _defaultImc); |
|
|
|
} |
|
|
|
|
|
|
|
_defaultImc = IntPtr.Zero; |
|
|
|
HWND = IntPtr.Zero; |
|
|
|
_parent = null; |
|
|
|
_active = false; |
|
|
|
_langId = 0; |
|
|
|
_showCompositionWindow = false; |
|
|
|
_showCandidateList = false; |
|
|
|
|
|
|
|
IsComposing = false; |
|
|
|
} |
|
|
|
|
|
|
|
//Dependant on CurrentThread. When Avalonia will support Multiple Dispatchers -
|
|
|
|
//every Dispatcher should have their own InputMethod.
|
|
|
|
public static Imm32InputMethod Current { get; } = new Imm32InputMethod(); |
|
|
|
|
|
|
|
@ -82,6 +82,12 @@ namespace Avalonia.Win32 |
|
|
|
case WindowsMessage.WM_DESTROY: |
|
|
|
{ |
|
|
|
UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, IntPtr.Zero, IntPtr.Zero, null); |
|
|
|
|
|
|
|
// We need to release IMM context and state to avoid leaks.
|
|
|
|
if (Imm32InputMethod.Current.HWND == _hwnd) |
|
|
|
{ |
|
|
|
Imm32InputMethod.Current.ClearLanguageAndWindow(); |
|
|
|
} |
|
|
|
|
|
|
|
//Window doesn't exist anymore
|
|
|
|
_hwnd = IntPtr.Zero; |
|
|
|
|