win32: re-enable IME

The IME is useful for text input. Additionally, Alt+Shift input language
switching doesn't work when IME is disabled even when the languages don't
require IME.

Re-add the VK_PROCESSKEY logic to ensure that IME is handled properly.

Reverts bf6b981367.
This commit is contained in:
nanahi 2023-12-15 10:33:43 -05:00 committed by Dudemanguy
parent 9bf4b9d5d4
commit 33e922eabe
1 changed files with 11 additions and 12 deletions

View File

@ -77,7 +77,6 @@ typedef enum MONITOR_DPI_TYPE {
struct w32_api {
HRESULT (WINAPI *pGetDpiForMonitor)(HMONITOR, MONITOR_DPI_TYPE, UINT*, UINT*);
BOOL (WINAPI *pImmDisableIME)(DWORD);
BOOL (WINAPI *pAdjustWindowRectExForDpi)(LPRECT lpRect, DWORD dwStyle, BOOL bMenu, DWORD dwExStyle, UINT dpi);
BOOLEAN (WINAPI *pShouldAppsUseDarkMode)(void);
DWORD (WINAPI *pSetPreferredAppMode)(DWORD mode);
@ -1652,13 +1651,23 @@ static void remove_parent_hook(struct vo_w32_state *w32)
UnhookWinEvent(w32->parent_evt_hook);
}
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)
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);
}
// Even if the message loop somehow exits, we still have to respond to
// external requests until termination is requested.
@ -1748,12 +1757,6 @@ static void w32_api_load(struct vo_w32_state *w32)
w32->api.pAdjustWindowRectExForDpi = !user32_dll ? NULL :
(void *)GetProcAddress(user32_dll, "AdjustWindowRectExForDpi");
// imm32.dll must be loaded dynamically
// to account for machines without East Asian language support
HMODULE imm32_dll = LoadLibraryW(L"imm32.dll");
w32->api.pImmDisableIME = !imm32_dll ? NULL :
(void *)GetProcAddress(imm32_dll, "ImmDisableIME");
// Dark mode related functions, available since the 1809 Windows 10 update
// Check the Windows build version as on previous versions used ordinals
// may point to unexpected code/data. Alternatively could check uxtheme.dll
@ -1784,10 +1787,6 @@ static MP_THREAD_VOID gui_thread(void *ptr)
w32_api_load(w32);
// Disables the IME for windows on this thread
if (w32->api.pImmDisableIME)
w32->api.pImmDisableIME(0);
if (w32->opts->WinID >= 0)
w32->parent = (HWND)(intptr_t)(w32->opts->WinID);