summaryrefslogtreecommitdiffstats
path: root/video/out/w32_common.c
diff options
context:
space:
mode:
authornanahi <130121847+na-na-hi@users.noreply.github.com>2023-12-16 11:23:32 -0500
committerDudemanguy <random342@airmail.cc>2024-01-15 16:06:06 +0000
commit758a9658d6d64573e9e7da24ba2f7b2509d84a7e (patch)
tree6953c0fa3edf4c5649076687160e8fbc1f9529e3 /video/out/w32_common.c
parent7ffd947830193977c70b0e6a561362f3365ff40a (diff)
downloadmpv-758a9658d6d64573e9e7da24ba2f7b2509d84a7e.tar.bz2
mpv-758a9658d6d64573e9e7da24ba2f7b2509d84a7e.tar.xz
win32: default to alphanumeric input when the IME is first initialized
Some IMEs initialize to composition mode for new windows, which is undesirable for keyboard control. Default to alphanumeric input to solve this.
Diffstat (limited to 'video/out/w32_common.c')
-rw-r--r--video/out/w32_common.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/video/out/w32_common.c b/video/out/w32_common.c
index d2972f9193..17a6a7ba9d 100644
--- a/video/out/w32_common.c
+++ b/video/out/w32_common.c
@@ -1220,6 +1220,20 @@ static void update_cursor_passthrough(const struct vo_w32_state *w32)
}
}
+static void set_ime_conversion_mode(const struct vo_w32_state *w32, DWORD mode)
+{
+ if (w32->parent)
+ return;
+
+ HIMC imc = ImmGetContext(w32->window);
+ if (imc) {
+ DWORD sentence_mode;
+ if (ImmGetConversionStatus(imc, NULL, &sentence_mode))
+ ImmSetConversionStatus(imc, mode, sentence_mode);
+ ImmReleaseContext(w32->window, imc);
+ }
+}
+
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
LPARAM lParam)
{
@@ -1560,6 +1574,22 @@ static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam,
}
break;
}
+ case WM_CREATE:
+ // The IME can only be changed to alphanumeric input after it's initialized.
+ // Unfortunately, there is no way to know when this happens, as
+ // none of the WM_CREATE, WM_INPUTLANGCHANGE, or WM_IME_* messages work.
+ // This works if the IME is initialized within a short time after
+ // the window is created. Otherwise, fallback to setting alphanumeric mode on
+ // the first keypress.
+ SetTimer(w32->window, (UINT_PTR)WM_CREATE, 250, NULL);
+ break;
+ case WM_TIMER:
+ if (wParam == WM_CREATE) {
+ // Default to alphanumeric input when the IME is first initialized.
+ set_ime_conversion_mode(w32, IME_CMODE_ALPHANUMERIC);
+ return 0;
+ }
+ break;
}
if (message == w32->tbtn_created_msg) {