summaryrefslogtreecommitdiff
path: root/ism/src/scim_helper.cpp
diff options
context:
space:
mode:
authorJihoon Kim <jihoon48.kim@samsung.com>2016-06-12 21:29:38 -0700
committerJihoon Kim <jihoon48.kim@samsung.com>2016-06-12 21:33:20 -0700
commit471734d91bc7ef65502398b848d36f7a309e0805 (patch)
treeeb7a96a31d7f48d7032fe12b6c50fbefff66f730 /ism/src/scim_helper.cpp
parent1067086d40b96c72f8e58aefa67eeaf72addfdf0 (diff)
downloadisf-471734d91bc7ef65502398b848d36f7a309e0805.tar.gz
isf-471734d91bc7ef65502398b848d36f7a309e0805.tar.bz2
isf-471734d91bc7ef65502398b848d36f7a309e0805.zip
Get surrounding and selection text by fd
Change-Id: Id013a66b8492876a639ba975636574820ae4b603
Diffstat (limited to 'ism/src/scim_helper.cpp')
-rw-r--r--ism/src/scim_helper.cpp94
1 files changed, 85 insertions, 9 deletions
diff --git a/ism/src/scim_helper.cpp b/ism/src/scim_helper.cpp
index a7537fdb..760b20a9 100644
--- a/ism/src/scim_helper.cpp
+++ b/ism/src/scim_helper.cpp
@@ -48,6 +48,7 @@
#include <string.h>
#include <unistd.h>
+#include <fcntl.h>
#include "scim_private.h"
#include "scim.h"
@@ -1955,10 +1956,6 @@ void
HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &text, int &cursor)
{
LOGD ("");
- if (m_impl->surrounding_text) {
- free (m_impl->surrounding_text);
- m_impl->surrounding_text = NULL;
- }
if (!m_impl->socket_active.is_connected ())
return;
@@ -1972,6 +1969,48 @@ HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &
m_impl->send.put_data (maxlen_after);
m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
+#ifdef WAYLAND
+ int filedes[2];
+ if (pipe2(filedes,O_CLOEXEC|O_NONBLOCK) ==-1 ) {
+ LOGD ("create pipe failed");
+ return;
+ }
+ LOGD("%d,%d",filedes[0],filedes[1]);
+
+ m_impl->socket_active.write_fd (filedes[1]);
+ close (filedes[1]);
+
+ for (int i = 0; i < 3; i++) {
+ int fds[3];
+ fds[0] = m_impl->socket_active.get_id();
+ fds[1] = filedes[0];
+ fds[2] = 0;
+ if (!scim_wait_for_data (fds)) {
+ LOGE ("");
+ break;
+ }
+
+ if (fds[1]) {
+ char buff[512];
+ int len = read (fds[1], buff, sizeof(buff));
+ if (len <= 0)
+ break;
+ else {
+ buff[len] = '\0';
+ text.append (buff);
+ }
+ }
+ if (fds[0])
+ filter_event ();
+ }
+ close (filedes[0]);
+ cursor = m_impl->cursor_pos;
+#else
+ if (m_impl->surrounding_text) {
+ free (m_impl->surrounding_text);
+ m_impl->surrounding_text = NULL;
+ }
+
for (int i = 0; i < 3; i++) {
if (filter_event () && m_impl->surrounding_text) {
text = m_impl->surrounding_text;
@@ -1984,6 +2023,7 @@ HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &
free (m_impl->surrounding_text);
m_impl->surrounding_text = NULL;
}
+#endif
}
/**
@@ -2038,10 +2078,6 @@ void
HelperAgent::get_selection_text (String &text)
{
LOGD ("");
- if (m_impl->selection_text) {
- free (m_impl->selection_text);
- m_impl->selection_text = NULL;
- }
if (!m_impl->socket_active.is_connected ())
return;
@@ -2052,6 +2088,46 @@ HelperAgent::get_selection_text (String &text)
m_impl->send.put_command (SCIM_TRANS_CMD_GET_SELECTION);
m_impl->send.put_data ("");
m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
+#ifdef WAYLAND
+ int filedes[2];
+ if (pipe2 (filedes,O_CLOEXEC|O_NONBLOCK) == -1 ) {
+ LOGD ("create pipe failed");
+ return;
+ }
+ LOGD("%d,%d", filedes[0], filedes[1]);
+
+ m_impl->socket_active.write_fd (filedes[1]);
+ close (filedes[1]);
+
+ for (int i = 0; i < 3; i++) {
+ int fds[3];
+ fds[0] = m_impl->socket_active.get_id();
+ fds[1] = filedes[0];
+ fds[2] = 0;
+ if (!scim_wait_for_data (fds)) {
+ LOGE ("");
+ break;
+ }
+
+ if (fds[1]) {
+ char buff[512];
+ int len = read (fds[1], buff, sizeof(buff));
+ if (len <= 0)
+ break;
+ else {
+ buff[len] = '\0';
+ text.append (buff);
+ }
+ }
+ if (fds[0])
+ filter_event ();
+ }
+ close (filedes[0]);
+#else
+ if (m_impl->selection_text) {
+ free (m_impl->selection_text);
+ m_impl->selection_text = NULL;
+ }
for (int i = 0; i < 3; i++) {
if (filter_event () && m_impl->selection_text) {
@@ -2059,11 +2135,11 @@ HelperAgent::get_selection_text (String &text)
break;
}
}
-
if (m_impl->selection_text) {
free (m_impl->selection_text);
m_impl->selection_text = NULL;
}
+#endif
}
/**