From c6c5e5b091506d756f831682811d9c25ca39b1f2 Mon Sep 17 00:00:00 2001 From: Ji-hoon Lee Date: Tue, 13 Dec 2016 17:16:16 +0900 Subject: [PATCH] Modified to send cursor position together with surrounding_text Change-Id: I1a771c3cbf8427de55f7dbfb602a4718194148f3 --- ism/extras/wayland_immodule/wayland_imcontext.c | 5 ++++- .../panelagent/wayland/wayland_panel_agent_module.cpp | 14 ++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/ism/extras/wayland_immodule/wayland_imcontext.c b/ism/extras/wayland_immodule/wayland_imcontext.c index eabd06c..8973c4d 100644 --- a/ism/extras/wayland_immodule/wayland_imcontext.c +++ b/ism/extras/wayland_immodule/wayland_imcontext.c @@ -2147,7 +2147,10 @@ text_input_get_surrounding_text (void *data, char *req_surrounding = eina_unicode_unicode_to_utf8_range (wide_surrounding + maxlen_before, maxlen_after - maxlen_before, NULL); - if (req_surrounding) { + ssize_t ret = write(fd, &cursor_pos, sizeof(cursor_pos)); + if (ret <= 0) { + LOGW ("write pipe failed, errno: %d", errno); + } else if (req_surrounding) { char *_surrounding = req_surrounding; size_t len = strlen(req_surrounding); while (len) { diff --git a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp index 8b47851..2a2094c 100644 --- a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp +++ b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp @@ -389,6 +389,7 @@ _wsc_im_ctx_cursor_position (void *data, struct wl_input_method_context *im_ctx, if (!wsc_ctx || !wsc_ctx->impl) return; wsc_ctx->impl->cursor_pos = cursor_pos; wsc_ctx->surrounding_cursor = cursor_pos; + LOGD ("wsc_ctx->surrounding_cursor = %d\n", wsc_ctx->surrounding_cursor); g_info_manager->socket_update_cursor_position (cursor_pos); #if ENABLE_REMOTE_INPUT @@ -643,6 +644,7 @@ _wsc_im_activate (void *data, struct wl_input_method *input_method, struct wl_in wsc_ctx->surrounding_text = NULL; wsc_ctx->remote_surrounding_text = NULL; wsc_ctx->surrounding_cursor = 0; + LOGD ("wsc_ctx->surrounding_cursor = %d\n", wsc_ctx->surrounding_cursor); get_language (&wsc_ctx->language); @@ -1605,9 +1607,11 @@ wsc_commit_preedit (WSCContextISF* wsc_ctx) free (wsc_ctx->surrounding_text); wsc_ctx->surrounding_text = surrounding_text; wsc_ctx->surrounding_cursor += strlen (wsc_ctx->preedit_str); + LOGD ("wsc_ctx->surrounding_cursor = %d\n", wsc_ctx->surrounding_cursor); } else { wsc_ctx->surrounding_text = strdup (wsc_ctx->preedit_str); wsc_ctx->surrounding_cursor = strlen (wsc_ctx->preedit_str); + LOGD ("wsc_ctx->surrounding_cursor = %d\n", wsc_ctx->surrounding_cursor); } if (wsc_ctx->preedit_str) @@ -2815,17 +2819,19 @@ public: char buff[512]; int len = read (fd, buff, sizeof (buff) - 1); if (len == 0) { - LOGD ("update"); + LOGD ("update, wsc_ctx->surrounding_cursor = %d\n", wsc_ctx->surrounding_cursor); g_info_manager->socket_update_surrounding_text (wsc_ctx->surrounding_text ? wsc_ctx->surrounding_text : "", wsc_ctx->surrounding_cursor); } else if (len < 0) { LOGW ("failed"); } else { buff[len] = '\0'; if (wsc_ctx->surrounding_text == NULL) { - wsc_ctx->surrounding_text = (char*)malloc (len + 1); + /* Add one byte for terminating NULL character and subtract byte for cursor position */ + wsc_ctx->surrounding_text = (char*)malloc (len + 1 - sizeof(int)); if (wsc_ctx->surrounding_text) { - memcpy (wsc_ctx->surrounding_text, buff, len); - wsc_ctx->surrounding_text[len] = '\0'; + memcpy(&(wsc_ctx->surrounding_cursor), buff, sizeof(int)); + memcpy (wsc_ctx->surrounding_text, buff + sizeof(int), len - sizeof(int)); + wsc_ctx->surrounding_text[len - sizeof(int)] = '\0'; return ECORE_CALLBACK_RENEW; } else { LOGE ("malloc failed"); -- 2.7.4