1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-28 18:12:22 +00:00

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.
This commit is contained in:
James Ross-Gowan 2015-10-22 19:36:26 +11:00 committed by wm4
parent 72ded5ccef
commit bf6b981367

View File

@ -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 = {