From 7320d4f114d17239844be87c9bef55c99ac24373 Mon Sep 17 00:00:00 2001 From: InHong Han Date: Mon, 23 Jan 2017 19:08:01 +0900 Subject: [PATCH] Modified to receive both remote_surrounding_text and cursor_position Change-Id: Idb77e9704368bc687c54b1dcfdca0a55cbfbb1c1 --- .../panelagent/wayland/wayland_panel_agent_module.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp index 4243e49..f6a56f8 100644 --- a/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp +++ b/ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp @@ -1769,19 +1769,24 @@ remote_surrounding_text_fd_read_func (void* data, Ecore_Fd_Handler* fd_handler) if (len == 0) { LOGD ("update"); + LOGD ("remote_surrounding_text : %s, surrounding_cursor : %d\n", wsc_ctx->remote_surrounding_text, wsc_ctx->surrounding_cursor); isf_wsc_context_send_surrounding_text (wsc_ctx, wsc_ctx->remote_surrounding_text ? wsc_ctx->remote_surrounding_text : "", wsc_ctx->surrounding_cursor); } else if (len < 0) { LOGW ("failed"); } else { buff[len] = '\0'; if (wsc_ctx->remote_surrounding_text == NULL) { - wsc_ctx->remote_surrounding_text = (char*)malloc (len + 1); - if (wsc_ctx->remote_surrounding_text) { - memcpy (wsc_ctx->remote_surrounding_text, buff, len); - wsc_ctx->remote_surrounding_text[len] = '\0'; - return ECORE_CALLBACK_RENEW; - } else { - LOGE ("malloc failed"); + if (len >= (int)sizeof(int)) { + /* Add one byte for terminating NULL character and subtract byte for cursor position */ + wsc_ctx->remote_surrounding_text = (char*)malloc (len + 1 - sizeof(int)); + if (wsc_ctx->remote_surrounding_text) { + memcpy(&(wsc_ctx->surrounding_cursor), buff, sizeof(int)); + memcpy (wsc_ctx->remote_surrounding_text, buff + sizeof(int), len - sizeof(int)); + wsc_ctx->remote_surrounding_text[len - sizeof(int)] = '\0'; + return ECORE_CALLBACK_RENEW; + } else { + LOGE ("malloc failed"); + } } } else { int old_len = strlen (wsc_ctx->remote_surrounding_text); -- 2.7.4