Modified to send cursor position together with surrounding_text 82/104382/1
authorJi-hoon Lee <dalton.lee@samsung.com>
Tue, 13 Dec 2016 08:16:16 +0000 (17:16 +0900)
committerJi-hoon Lee <dalton.lee@samsung.com>
Tue, 13 Dec 2016 08:16:27 +0000 (17:16 +0900)
Change-Id: I1a771c3cbf8427de55f7dbfb602a4718194148f3

ism/extras/wayland_immodule/wayland_imcontext.c
ism/modules/panelagent/wayland/wayland_panel_agent_module.cpp

index eabd06c..8973c4d 100644 (file)
@@ -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) {
index 8b47851..2a2094c 100644 (file)
@@ -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 <int> 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");