int32_t cursor;
} pending_preedit;
+ int32_t cursor_position;
+
struct
{
int x;
static void
update_state(WaylandIMContext *imcontext)
{
- char *surrounding = NULL;
- char *selection = NULL;
- int cursor_pos;
-
if (!imcontext->ctx)
return;
- /* cursor_pos is a byte index */
- if (ecore_imf_context_surrounding_get(imcontext->ctx, &surrounding, &cursor_pos)) {
- if (imcontext->text_input)
- wl_text_input_set_surrounding_text(imcontext->text_input, surrounding,
- cursor_pos, cursor_pos);
-
- if (surrounding)
- free(surrounding);
- }
-
- ecore_imf_context_selection_get(imcontext->ctx, &selection);
- if (imcontext->text_input)
- wl_text_input_set_selection_text(imcontext->text_input, selection ? selection : "");
-
- if (selection)
- free(selection);
-
send_cursor_location (imcontext);
if (imcontext->text_input) {
show_input_panel(Ecore_IMF_Context *ctx)
{
WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
+
char *surrounding = NULL;
int cursor_pos;
new_purpose);
if (ecore_imf_context_surrounding_get(imcontext->ctx, &surrounding, &cursor_pos)) {
- if (imcontext->text_input)
- wl_text_input_set_surrounding_text(imcontext->text_input, surrounding,
- cursor_pos, cursor_pos);
+ if (surrounding)
+ free (surrounding);
- if (surrounding) {
- free(surrounding);
- surrounding = NULL;
- }
+ imcontext->cursor_position = cursor_pos;
+ wl_text_input_set_cursor_position(imcontext->text_input, cursor_pos);
}
-
// TIZEN_ONLY(20150716): Support return key type
wl_text_input_set_return_key_type(imcontext->text_input,
imcontext->return_key_type);
memcpy(imcontext->input_panel_data, input_panel_data, length);
imcontext->input_panel_data_length = length;
}
+
+static void
+text_input_get_selection_text (void *data,
+ struct wl_text_input *text_input EINA_UNUSED,
+ uint32_t serial)
+{
+ char *selection = NULL;
+ LOGD ("%d", serial);
+ WaylandIMContext *imcontext = (WaylandIMContext *)data;
+ if (!imcontext || !imcontext->ctx) {
+ LOGD ("");
+ return;
+ }
+
+ ecore_imf_context_selection_get (imcontext->ctx, &selection);
+ if (imcontext->text_input) {
+ LOGD ("selection :%s", selection ? selection : "");
+ wl_text_input_set_selection_text (imcontext->text_input, serial, selection ? selection : "");
+ }
+
+ if (selection)
+ free (selection);
+}
+
+static void
+text_input_get_surrounding_text (void *data,
+ struct wl_text_input *text_input EINA_UNUSED,
+ uint32_t serial,
+ uint32_t maxlen_before,
+ uint32_t maxlen_after)
+{
+ int cursor_pos;
+ char *surrounding = NULL;
+ LOGD ("serial: %d maxlen_before: %d maxlen_after: %d", serial, maxlen_before, maxlen_after);
+ WaylandIMContext *imcontext = (WaylandIMContext *)data;
+ if (!imcontext || !imcontext->ctx) {
+ LOGD ("");
+ return;
+ }
+
+ /* cursor_pos is a byte index */
+ if (ecore_imf_context_surrounding_get (imcontext->ctx, &surrounding, &cursor_pos)) {
+ LOGD ("surrounding :%s, cursor: %d", surrounding? surrounding : "", cursor_pos);
+ if (imcontext->text_input) {
+ Eina_Unicode *wide_surrounding = eina_unicode_utf8_to_unicode (surrounding, NULL);
+ size_t wlen = eina_unicode_strlen (wide_surrounding);
+
+ if (cursor_pos > (int)wlen || cursor_pos < 0)
+ cursor_pos = 0;
+
+ if (maxlen_before > cursor_pos)
+ maxlen_before = 0;
+ else
+ maxlen_before = cursor_pos - maxlen_before;
+
+ if (maxlen_after > wlen - cursor_pos)
+ maxlen_after = wlen;
+ else
+ maxlen_after = cursor_pos + maxlen_after;
+
+ char *req_surrounding = eina_unicode_unicode_to_utf8_range (wide_surrounding + maxlen_before, maxlen_after - maxlen_before, NULL);
+
+ wl_text_input_set_surrounding_text (imcontext->text_input,
+ serial, req_surrounding ? req_surrounding : "", cursor_pos);
+
+ if (req_surrounding)
+ free (req_surrounding);
+
+ if (wide_surrounding)
+ free (wide_surrounding);
+ }
+
+ if (surrounding)
+ free (surrounding);
+ }
+}
//
static const struct wl_text_input_listener text_input_listener =
text_input_selection_region,
text_input_private_command,
text_input_input_panel_geometry,
- text_input_input_panel_data
+ text_input_input_panel_data,
+ text_input_get_selection_text,
+ text_input_get_surrounding_text
//
};
}
EAPI void
-wayland_im_context_del(Ecore_IMF_Context *ctx)
+wayland_im_context_del (Ecore_IMF_Context *ctx)
{
WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
- LOGD("context_del. ctx : %p", ctx);
+ LOGD ("context_del. ctx : %p", ctx);
// TIZEN_ONLY(20150708): Support back key
if (_focused_ctx == ctx)
//
if (imcontext->language) {
- free(imcontext->language);
+ free (imcontext->language);
imcontext->language = NULL;
}
// TIZEN_ONLY(20150922): Support to set input panel data
if (imcontext->imdata) {
- free(imcontext->imdata);
+ free (imcontext->imdata);
imcontext->imdata = NULL;
imcontext->imdata_size = 0;
}
if (imcontext->input_panel_data) {
- free(imcontext->input_panel_data);
+ free (imcontext->input_panel_data);
imcontext->input_panel_data = NULL;
imcontext->input_panel_data_length = 0;
}
//
if (imcontext->text_input)
- wl_text_input_destroy(imcontext->text_input);
+ wl_text_input_destroy (imcontext->text_input);
- clear_preedit(imcontext);
+ clear_preedit (imcontext);
}
EAPI void
{
WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
+ LOGD("ctx : %p", ctx);
+
commit_preedit(imcontext);
clear_preedit(imcontext);
}
EAPI void
-wayland_im_context_cursor_position_set(Ecore_IMF_Context *ctx,
+wayland_im_context_cursor_position_set (Ecore_IMF_Context *ctx,
int cursor_pos)
{
WaylandIMContext *imcontext = (WaylandIMContext *)ecore_imf_context_data_get(ctx);
- LOGD("set cursor position (cursor: %d)", cursor_pos);
-
- update_state(imcontext);
+ LOGD ("set cursor position (cursor: %d)", cursor_pos);
+ if (imcontext->cursor_position != cursor_pos) {
+ imcontext->cursor_position = cursor_pos;
+ wl_text_input_set_cursor_position (imcontext->text_input, cursor_pos);
+ }
}
EAPI void
void isf_wsc_context_del (WSCContextISF *wsc_ctx);
void isf_wsc_context_focus_in (WSCContextISF *wsc_ctx);
void isf_wsc_context_focus_out (WSCContextISF *wsc_ctx);
-void isf_wsc_context_cursor_position_set (WSCContextISF *wsc_ctx, int cursor_pos);
void isf_wsc_context_preedit_string_get (WSCContextISF *wsc_ctx, char** str, int *cursor_pos);
void isf_wsc_context_autocapital_type_set (WSCContextISF* wsc_ctx, Ecore_IMF_Autocapital_Type autocapital_type);
void isf_wsc_context_bidi_direction_set (WSCContextISF* wsc_ctx, Ecore_IMF_BiDi_Direction direction);
const WideString &str,
const AttributeList &attrs,
int caret);
-static void _get_surrounding_text (int context,
- int maxlen_before,
- int maxlen_after);
-static void panel_req_update_cursor_position (WSCContextISF *ic, int cursor_pos);
static void panel_req_update_bidi_direction (WSCContextISF *ic, int direction);
/* Panel iochannel handler*/
static void send_wl_key_event (WSCContextISF *ic, const KeyEvent &key, bool fake);
static void _hide_preedit_string (int context, bool update_preedit);
-static bool slot_get_surrounding_text (WideString &text,
- int &cursor,
- int maxlen_before,
- int maxlen_after);
-
/* Local variables declaration */
static String _language;
static WSCContextISFImpl *_used_ic_impl_list = 0;
// Implementation of Wayland Input Method functions.
/////////////////////////////////////////////////////////////////////////////
static void
-_wsc_im_ctx_surrounding_text(void *data, struct wl_input_method_context *im_ctx, const char *text, uint32_t cursor, uint32_t anchor)
+_wsc_im_ctx_surrounding_text(void *data, struct wl_input_method_context *im_ctx, uint32_t serial, const char *text, uint32_t cursor_position)
{
LOGD ("");
WSCContextISF *wsc_ctx = (WSCContextISF*)data;
free (wsc_ctx->surrounding_text);
wsc_ctx->surrounding_text = strdup (text ? text : "");
- wsc_ctx->surrounding_cursor = cursor;
+ wsc_ctx->surrounding_cursor = cursor_position;
g_info_manager->socket_update_surrounding_text (wsc_ctx->surrounding_text, wsc_ctx->surrounding_cursor);
- isf_wsc_context_cursor_position_set(wsc_ctx, cursor);
-
- LOGD ("text : '%s', cursor : %d\n", text, cursor);
+ LOGD ("text : '%s', cursor : %d\n", text, cursor_position);
}
static void
wsc_ctx->serial = serial;
- if (wsc_ctx->surrounding_text)
- LOGD ("Surrounding text updated: '%s'\n", wsc_ctx->surrounding_text);
-
if (wsc_ctx->language)
wl_input_method_context_language (im_ctx, wsc_ctx->serial, wsc_ctx->language);
}
}
static void
-_wsc_im_ctx_selection_text(void *data, struct wl_input_method_context *im_ctx, const char *text)
+_wsc_im_ctx_selection_text(void *data, struct wl_input_method_context *im_ctx, uint32_t serial, const char *text)
{
WSCContextISF *wsc_ctx = (WSCContextISF*)data;
g_info_manager->socket_update_selection (text);
}
+static void
+_wsc_im_ctx_cursor_position(void *data, struct wl_input_method_context *im_ctx, uint32_t cursor_pos)
+{
+ WSCContextISF *wsc_ctx = (WSCContextISF*)data;
+
+ LOGD ("im_context = %p cursor_pos = %d\n", im_ctx, cursor_pos);
+ if (!wsc_ctx) return;
+ caps_mode_check (wsc_ctx, EINA_FALSE, EINA_TRUE);
+ g_info_manager->socket_update_cursor_position (cursor_pos);
+}
+
static const struct wl_input_method_context_listener wsc_im_context_listener = {
_wsc_im_ctx_surrounding_text,
_wsc_im_ctx_reset,
_wsc_im_ctx_return_key_disabled,
_wsc_im_ctx_input_panel_data,
_wsc_im_ctx_bidi_direction,
- _wsc_im_ctx_selection_text
+ _wsc_im_ctx_selection_text,
+ _wsc_im_ctx_cursor_position,
};
static void
_x_key_event_is_valid = false;
}
-void
-isf_wsc_context_cursor_position_set (WSCContextISF *wsc_ctx, int cursor_pos)
-{
- SCIM_DEBUG_FRONTEND (1) << __FUNCTION__ << "...\n";
- LOGD ("");
- WSCContextISF* context_scim = wsc_ctx;
-
- if (context_scim && context_scim->impl && context_scim == _focused_ic) {
- if (context_scim->impl->cursor_pos != cursor_pos) {
- LOGD ("ctx : %p, cursor pos : %d\n", wsc_ctx, cursor_pos);
- context_scim->impl->cursor_pos = cursor_pos;
-
- caps_mode_check (wsc_ctx, EINA_FALSE, EINA_TRUE);
-
- if (context_scim->impl->preedit_updating)
- return;
- panel_req_update_cursor_position (context_scim, cursor_pos);
- }
- }
-}
-
void
isf_wsc_context_preedit_string_get (WSCContextISF *wsc_ctx, char** str, int *cursor_pos)
{
}
#endif
-static void
-panel_req_update_cursor_position (WSCContextISF *ic, int cursor_pos)
-{
- SCIM_DEBUG_FRONTEND (1) << __FUNCTION__ << "...\n";
- LOGD ("");
-
- if (ic)
- g_info_manager->socket_update_cursor_position (cursor_pos);
-}
-
static void
panel_req_update_bidi_direction (WSCContextISF *ic, int direction)
{
}
}
-static void
-_get_surrounding_text (int context, int maxlen_before, int maxlen_after)
-{
- SCIM_DEBUG_FRONTEND (1) << __FUNCTION__ << "...\n";
- LOGD ("");
- WSCContextISF* ic = find_ic (context);
-
- if (ic && ic->impl && _focused_ic == ic) {
- int cursor = 0;
- WideString text = WideString ();
- slot_get_surrounding_text (text, cursor, maxlen_before, maxlen_after);
- String _str = utf8_wcstombs (text);
- g_info_manager->socket_update_surrounding_text (_str, (uint32)cursor);
- }
-}
-
void
initialize (void)
{
wsc_context_send_key (ic, key.code, modifiers, time, key.is_key_press ());
}
-static bool
-slot_get_surrounding_text (WideString &text,
- int &cursor,
- int maxlen_before,
- int maxlen_after)
-{
- SCIM_DEBUG_FRONTEND (1) << __FUNCTION__ << "...\n";
- LOGD ("");
-
- char *surrounding = NULL;
- int cursor_index;
- if (wsc_context_surrounding_get (_focused_ic, &surrounding, &cursor_index)) {
- SCIM_DEBUG_FRONTEND(2) << "Surrounding text: " << surrounding <<"\n";
- SCIM_DEBUG_FRONTEND(2) << "Cursor Index : " << cursor_index <<"\n";
-
- if (!surrounding)
- return false;
-
- if (cursor_index < 0) {
- free (surrounding);
- surrounding = NULL;
- return false;
- }
-
- WideString before = utf8_mbstowcs (String (surrounding));
- free (surrounding);
- surrounding = NULL;
-
- if (cursor_index > (int)before.length ())
- return false;
- WideString after = before;
- before = before.substr (0, cursor_index);
- after = after.substr (cursor_index, after.length () - cursor_index);
- if (maxlen_before > 0 && ((unsigned int)maxlen_before) < before.length ())
- before = WideString (before.begin () + (before.length () - maxlen_before), before.end ());
- else if (maxlen_before == 0)
- before = WideString ();
- if (maxlen_after > 0 && ((unsigned int)maxlen_after) < after.length ())
- after = WideString (after.begin (), after.begin () + maxlen_after);
- else if (maxlen_after == 0)
- after = WideString ();
- text = before + after;
- cursor = before.length ();
- return true;
- }
-
- return false;
-}
-
static void
reload_config_callback (const ConfigPointer &config)
{
void
socket_helper_get_surrounding_text (int id, uint32 context_id, uint32 maxlen_before, uint32 maxlen_after) {
LOGD ("client id:%d", id);
- _get_surrounding_text (context_id, maxlen_before, maxlen_after);
+ WSCContextISF* ic = find_ic (context_id);
+ wl_input_method_context_get_surrounding_text(ic->im_ctx, ic->serial, maxlen_before, maxlen_after);
}
void
}
}
+ void
+ socket_helper_get_selection (int id, uint32 context_id) {
+ LOGD ("client id:%d", id);
+ WSCContextISF* ic = find_ic (context_id);
+ wl_input_method_context_get_selection_text (ic->im_ctx, ic->serial);
+ }
};
static scim::PanelAgentPointer instance;
{
LOGD ("");
String _text;
- thiz->get_selection (_text);
+ thiz->get_selection_text (_text);
text = utf8_mbstowcs (_text);
return true;
}
uint32 cursor_pos;
if (m_impl->recv.get_data (cursor_pos)) {
m_impl->cursor_pos = cursor_pos;
+ LOGD ("update cursor position %d", cursor_pos);
m_impl->signal_update_cursor_position (this, ic, ic_uuid, (int) cursor_pos);
if (!m_impl->si.null ()) m_impl->si->update_cursor_position(cursor_pos);
}
free (m_impl->surrounding_text);
m_impl->surrounding_text = strdup (text.c_str ());
m_impl->cursor_pos = cursor;
- LOGD ("surrounding text: %s, %d", m_impl->surrounding_text, m_impl->cursor_pos);
+ LOGD ("surrounding text: %s, %d", m_impl->surrounding_text, cursor);
if (m_impl->need_update_surrounding_text) {
m_impl->need_update_surrounding_text = false;
m_impl->signal_update_surrounding_text (this, ic, text, (int) cursor);
const KeyEvent &key) const
{
LOGD ("");
+
//FIXME: remove shift_mode_off, shift_mode_on, shift_mode_lock from ISE side
if (key.code == SHIFT_MODE_OFF ||
key.code == SHIFT_MODE_ON ||
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 || !m_impl->surrounding_text) {
- text = utf8_wcstombs (WideString ());
- cursor = 0;
+ if (!m_impl->socket_active.is_connected ())
return;
- }
- WideString before = utf8_mbstowcs (String (m_impl->surrounding_text));
+ m_impl->send.clear ();
+ m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
+ m_impl->send.put_data (m_impl->magic_active);
+ m_impl->send.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
+ m_impl->send.put_data ("");
+ m_impl->send.put_data (maxlen_before);
+ m_impl->send.put_data (maxlen_after);
+ m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
+
+ for (int i = 0; i < 3; i++) {
+ if (filter_event () && m_impl->surrounding_text) {
+ text = m_impl->surrounding_text;
+ cursor = m_impl->cursor_pos;
+ break;
+ }
+ }
- if (m_impl->cursor_pos > before.length ())
- return;
- WideString after = before;
- before = before.substr (0, m_impl->cursor_pos);
- after = after.substr (m_impl->cursor_pos, after.length () - m_impl->cursor_pos);
- if (maxlen_before > 0 && ((unsigned int)maxlen_before) < before.length ())
- before = WideString (before.begin () + (before.length () - maxlen_before), before.end ());
- else if (maxlen_before == 0)
- before = WideString ();
- if (maxlen_after > 0 && ((unsigned int)maxlen_after) < after.length ())
- after = WideString (after.begin (), after.begin () + maxlen_after);
- else if (maxlen_after == 0)
- after = WideString ();
- text = utf8_wcstombs (before + after);
- cursor = before.length ();
+ if (m_impl->surrounding_text) {
+ free (m_impl->surrounding_text);
+ m_impl->surrounding_text = NULL;
+ }
}
/**
{
LOGD ("offset = %d, len = %d", offset, len);
- if (!m_impl)
- return;
-
- WideString ws;
-
- if (!m_impl->surrounding_text)
- ws = utf8_mbstowcs (String (""));
- else
- ws = utf8_mbstowcs (String (m_impl->surrounding_text));
-
- int _offset = offset + m_impl->cursor_pos;
-
- if (len <= 0 || _offset < 0 || _offset + len > (int)ws.length ()) {
- LOGW ("invalid offset and len");
- return;
- }
-
- WideString sub_ws_before = ws.substr (0, _offset);
- WideString sub_ws_after = ws.substr (_offset + len, ws.length ());
- WideString new_ws = sub_ws_before + sub_ws_after;
-
- if (m_impl->surrounding_text)
- free (m_impl->surrounding_text);
- m_impl->surrounding_text = strdup (utf8_wcstombs (new_ws).c_str ());
- m_impl->cursor_pos = _offset;
-
if (m_impl->socket_active.is_connected ()) {
m_impl->send.clear ();
m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
* @param text The selection text.
*/
void
-HelperAgent::get_selection (String &text) const
+HelperAgent::get_selection_text (String &text)
{
LOGD ("");
- if (m_impl->selection_text)
- text = m_impl->selection_text;
+ if (m_impl->selection_text) {
+ free (m_impl->selection_text);
+ m_impl->selection_text = NULL;
+ }
+
+ if (!m_impl->socket_active.is_connected ())
+ return;
+
+ m_impl->send.clear ();
+ m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
+ m_impl->send.put_data (m_impl->magic_active);
+ 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);
+
+ for (int i = 0; i < 3; i++) {
+ if (filter_event () && m_impl->selection_text) {
+ text = m_impl->selection_text;
+ break;
+ }
+ }
+
+ if (m_impl->selection_text) {
+ free (m_impl->selection_text);
+ m_impl->selection_text = NULL;
+ }
}
/**
*
* @param text The selection text.
*/
- void get_selection (String &text) const;
+ void get_selection_text (String &text);
/**
* @brief Request to selected text.