Use native Windows API for converting keystrokes to characters

Instead of using the incomplete GTK-internal emulation, use the WM_CHAR
messages sent by Windows. Make the IME input method the default for all
languages on Windows.
This commit is contained in:
Philip Zander
2019-07-09 17:44:05 +02:00
committed by Philip Zander
parent dd5fd12343
commit e6f05da6ef
5 changed files with 61 additions and 113 deletions

View File

@ -2595,6 +2595,35 @@ gdk_event_translate (MSG *msg,
gdk_event_set_device (event, device_manager_win32->core_keyboard);
gdk_event_set_source_device (event, device_manager_win32->system_keyboard);
gdk_event_set_seat (event, gdk_device_get_seat (device_manager_win32->core_keyboard));
/* Get the WinAPI translation of the WM_KEY messages to characters.
The WM_CHAR messages are generated by a previous call to TranslateMessage() and always
follow directly after the corresponding WM_KEY* messages.
There could be 0 or more WM_CHAR messages following (for example dead keys don't generate
WM_CHAR messages - they generate WM_DEAD_CHAR instead, but we are not interested in those
messages). */
if (gdk_event_is_allocated(event)) { /* Should always be true */
GdkEventPrivate *event_priv = (GdkEventPrivate*)event;
MSG msg2;
while (PeekMessageW(&msg2, msg->hwnd, 0, 0, 0) && (msg2.message == WM_CHAR || msg2.message == WM_SYSCHAR)) {
/* The character is encoded in WPARAM as UTF-16. */
gunichar2 c = msg2.wParam;
if (!g_unichar_iscntrl(c)) { /* Ignore control sequences like Backspace */
/* Append character to translation string. */
event_priv->translation_len++;
event_priv->translation = g_realloc(event_priv->translation, event_priv->translation_len*sizeof(event_priv->translation[0]));
event_priv->translation[event_priv->translation_len-1] = c;
}
/* Remove message from queue */
GetMessageW(&msg2, msg->hwnd, 0, 0);
}
}
if (HIWORD (msg->lParam) & KF_EXTENDED)
{
switch (msg->wParam)