From bf6b981367e45c3f926d3e667bba3f3ed6e9dc37 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Thu, 22 Oct 2015 19:36:26 +1100 Subject: [PATCH] w32_common: disable IME The IME is not useful for key-bindings. Handle the base ASCII chars instead and don't show the IME window. For the sake of libmpv users, the IME should only be disabled on mpv's GUI thread and not application- wide. No IME on the GUI thread should also mean that VK_PROCESSKEY will never have to be handled, so the logic for that can be removed as well. --- video/out/w32_common.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/video/out/w32_common.c b/video/out/w32_common.c index 361717a2de..c0396b2fa2 100644 --- a/video/out/w32_common.c +++ b/video/out/w32_common.c @@ -835,21 +835,12 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, return DefWindowProcW(hWnd, message, wParam, lParam); } -static bool is_key_message(UINT msg) -{ - return msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN || - msg == WM_KEYUP || msg == WM_SYSKEYUP; -} - // Dispatch incoming window events and handle them. // This returns only when the thread is asked to terminate. static void run_message_loop(struct vo_w32_state *w32) { MSG msg; while (GetMessageW(&msg, 0, 0, 0) > 0) { - // Only send IME messages to TranslateMessage - if (is_key_message(msg.message) && msg.wParam == VK_PROCESSKEY) - TranslateMessage(&msg); DispatchMessageW(&msg); if (w32->parent) { @@ -1104,6 +1095,20 @@ int vo_w32_config(struct vo *vo) return 0; } +static void thread_disable_ime(void) +{ + // Disables the IME for windows on this thread. imm32.dll must be loaded + // dynamically to account for machines without East Asian language support. + HMODULE imm32 = LoadLibraryW(L"imm32.dll"); + if (!imm32) + return; + BOOL (WINAPI *pImmDisableIME)(DWORD) = (BOOL (WINAPI*)(DWORD)) + GetProcAddress(imm32, "ImmDisableIME"); + if (pImmDisableIME) + pImmDisableIME(0); + FreeLibrary(imm32); +} + static void *gui_thread(void *ptr) { struct vo_w32_state *w32 = ptr; @@ -1112,6 +1117,8 @@ static void *gui_thread(void *ptr) mpthread_set_name("win32 window"); + thread_disable_ime(); + HINSTANCE hInstance = GetModuleHandleW(NULL); WNDCLASSEXW wcex = {