From: Attila Fidan dev@print0.net
--- dlls/winewayland.drv/wayland_text_input.c | 58 +++++++++++++++++++++++ dlls/winewayland.drv/waylanddrv.h | 3 ++ 2 files changed, 61 insertions(+)
diff --git a/dlls/winewayland.drv/wayland_text_input.c b/dlls/winewayland.drv/wayland_text_input.c index 50d056a2206..4cb4df4e94c 100644 --- a/dlls/winewayland.drv/wayland_text_input.c +++ b/dlls/winewayland.drv/wayland_text_input.c @@ -24,7 +24,19 @@
#include "config.h"
+#include <assert.h> +#include <stdlib.h> + #include "waylanddrv.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(textinput); + +static void post_ime_update(HWND hwnd, UINT cursor_pos, WCHAR *comp_str, WCHAR *result_str) +{ + NtUserMessageCall(hwnd, WINE_IME_POST_UPDATE, cursor_pos, (LPARAM)comp_str, result_str, + NtUserImeDriverCall, FALSE); +}
static void text_input_enter(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, struct wl_surface *surface) @@ -38,6 +50,8 @@ static void text_input_enter(void *data, struct zwp_text_input_v3 *zwp_text_inpu ZWP_TEXT_INPUT_V3_CONTENT_PURPOSE_NORMAL); zwp_text_input_v3_set_cursor_rectangle(text_input->zwp_text_input_v3, 0, 0, 0, 0); zwp_text_input_v3_commit(text_input->zwp_text_input_v3); + text_input->serial++; + text_input->wl_surface = surface; pthread_mutex_unlock(&text_input->mutex); }
@@ -49,6 +63,8 @@ static void text_input_leave(void *data, struct zwp_text_input_v3 *zwp_text_inpu pthread_mutex_lock(&text_input->mutex); zwp_text_input_v3_disable(text_input->zwp_text_input_v3); zwp_text_input_v3_commit(text_input->zwp_text_input_v3); + text_input->serial++; + text_input->wl_surface = NULL; pthread_mutex_unlock(&text_input->mutex); }
@@ -60,6 +76,18 @@ static void text_input_preedit_string(void *data, struct zwp_text_input_v3 *zwp_ static void text_input_commit_string(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, const char *text) { + struct wayland_text_input *text_input = data; + + pthread_mutex_lock(&text_input->mutex); + text_input->commit_string = malloc(strlen(text) + 1); + if (!text_input->commit_string) + { + ERR("Failed to allocate memory for IME commit string.\n"); + pthread_mutex_unlock(&text_input->mutex); + return; + } + strcpy(text_input->commit_string, text); + pthread_mutex_unlock(&text_input->mutex); }
static void text_input_delete_surrounding_text(void *data, @@ -70,6 +98,35 @@ static void text_input_delete_surrounding_text(void *data, static void text_input_done(void *data, struct zwp_text_input_v3 *zwp_text_input_v3, uint32_t serial) { + struct wayland_text_input *text_input = data; + size_t commit_len; + WCHAR *output; + DWORD len; + HWND hwnd; + + pthread_mutex_lock(&text_input->mutex); + assert(text_input->wl_surface); + hwnd = wl_surface_get_user_data(text_input->wl_surface); + + if (!text_input->commit_string || text_input->serial != serial) + goto done; + + commit_len = strlen(text_input->commit_string); + if (!(output = malloc((commit_len + 1) * sizeof(WCHAR)))) + { + ERR("Failed to allocate memory for wide IME commit string.\n"); + goto done; + } + + len = ntdll_umbstowcs(text_input->commit_string, commit_len, output, commit_len); + output[len] = 0; + post_ime_update(hwnd, 0, NULL, output); + free(output); + +done: + free(text_input->commit_string); + text_input->commit_string = NULL; + pthread_mutex_unlock(&text_input->mutex); }
static const struct zwp_text_input_v3_listener text_input_listener = @@ -100,5 +157,6 @@ void wayland_text_input_deinit(void) pthread_mutex_lock(&text_input->mutex); zwp_text_input_v3_destroy(text_input->zwp_text_input_v3); text_input->zwp_text_input_v3 = NULL; + text_input->wl_surface = NULL; pthread_mutex_unlock(&text_input->mutex); }; diff --git a/dlls/winewayland.drv/waylanddrv.h b/dlls/winewayland.drv/waylanddrv.h index c5dec335485..6f8b07aa3a8 100644 --- a/dlls/winewayland.drv/waylanddrv.h +++ b/dlls/winewayland.drv/waylanddrv.h @@ -115,6 +115,9 @@ struct wayland_pointer struct wayland_text_input { struct zwp_text_input_v3 *zwp_text_input_v3; + uint32_t serial; + char *commit_string; + struct wl_surface *wl_surface; pthread_mutex_t mutex; };