2010-12-09 06:42:20 +00:00
|
|
|
From 3ac76032c89fc3062a84fd824b4e53a7ae023841 Mon Sep 17 00:00:00 2001
|
2010-09-14 01:52:06 +00:00
|
|
|
From: Daiki Ueno <ueno@unixuser.org>
|
2010-12-09 06:42:20 +00:00
|
|
|
Date: Thu, 9 Dec 2010 15:03:54 +0900
|
2010-09-14 01:52:06 +00:00
|
|
|
Subject: [PATCH] Support surrounding-text retrieval.
|
|
|
|
|
|
|
|
This change adds a new API function ibus_engine_get_surrounding_text().
|
|
|
|
In the implementation, engines do not proactively requests surrounding-text to
|
|
|
|
target applications via the GTK+ client (IBusIMContext) every time the
|
|
|
|
function is called. Instead, IBusIMContext retrieves surrounding-text when
|
|
|
|
certain events occur in the input context (IBusInputContext) and maintains
|
|
|
|
it within the input context.
|
|
|
|
|
|
|
|
This logic is similar to Qt's QInputContext. The following events trigger
|
|
|
|
surrounding-text retrieval:
|
|
|
|
|
|
|
|
- focus_in
|
|
|
|
- commit_text
|
|
|
|
- show_preedit_text
|
|
|
|
- (just before) process_key_event
|
|
|
|
|
|
|
|
Also,
|
|
|
|
- destroy
|
|
|
|
resets the current surrounding-text.
|
|
|
|
---
|
2010-11-22 03:45:59 +00:00
|
|
|
bus/engineproxy.c | 43 +++++++++++++
|
2010-12-09 06:42:20 +00:00
|
|
|
bus/engineproxy.h | 11 +++
|
2010-11-22 03:45:59 +00:00
|
|
|
bus/inputcontext.c | 32 +++++++++
|
|
|
|
client/gtk2/ibusimcontext.c | 93 ++++++++++++++++++++++++---
|
2010-11-26 05:38:39 +00:00
|
|
|
configure.ac | 14 ++++
|
2010-09-28 02:32:30 +00:00
|
|
|
ibus/engine.py | 6 ++
|
2010-09-14 11:20:08 +00:00
|
|
|
ibus/interface/iengine.py | 3 +
|
|
|
|
ibus/interface/iinputcontext.py | 3 +
|
2010-11-22 03:45:59 +00:00
|
|
|
src/ibusengine.c | 134 +++++++++++++++++++++++++++++++++++++++
|
|
|
|
src/ibusengine.h | 21 ++++++-
|
|
|
|
src/ibusinputcontext.c | 61 ++++++++++++++++++
|
|
|
|
src/ibusinputcontext.h | 11 +++
|
2010-09-14 11:20:08 +00:00
|
|
|
src/ibusmarshalers.list | 1 +
|
2010-12-09 06:42:20 +00:00
|
|
|
13 files changed, 421 insertions(+), 12 deletions(-)
|
2010-09-14 01:52:06 +00:00
|
|
|
|
|
|
|
diff --git a/bus/engineproxy.c b/bus/engineproxy.c
|
2010-12-09 06:42:20 +00:00
|
|
|
index 59d495d..01116c2 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/bus/engineproxy.c
|
|
|
|
+++ b/bus/engineproxy.c
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -47,6 +47,10 @@ struct _BusEngineProxy {
|
|
|
|
/* a key mapping for the engine that converts keycode into keysym. the mapping is used only when use_sys_layout is FALSE. */
|
2010-11-26 05:38:39 +00:00
|
|
|
IBusKeymap *keymap;
|
2010-11-04 14:32:23 +00:00
|
|
|
/* private member */
|
|
|
|
+
|
|
|
|
+ /* surrounding text */
|
|
|
|
+ IBusText *surrounding_text;
|
|
|
|
+ guint surrounding_cursor_pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _BusEngineProxyClass {
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -83,6 +87,8 @@ enum {
|
|
|
|
|
2010-09-28 02:32:30 +00:00
|
|
|
static guint engine_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
+static IBusText *text_empty = NULL;
|
|
|
|
+
|
|
|
|
/* functions prototype */
|
2010-11-26 05:38:39 +00:00
|
|
|
static void bus_engine_proxy_set_property (BusEngineProxy *engine,
|
|
|
|
guint prop_id,
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -330,11 +336,16 @@ bus_engine_proxy_class_init (BusEngineProxyClass *class)
|
2010-11-26 05:38:39 +00:00
|
|
|
G_TYPE_NONE,
|
2010-09-28 02:32:30 +00:00
|
|
|
1,
|
|
|
|
IBUS_TYPE_PROPERTY);
|
2010-11-26 05:38:39 +00:00
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ text_empty = ibus_text_new_from_static_string ("");
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_object_ref_sink (text_empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 14:32:23 +00:00
|
|
|
bus_engine_proxy_init (BusEngineProxy *engine)
|
|
|
|
{
|
2010-09-28 02:32:30 +00:00
|
|
|
+ engine->surrounding_text = g_object_ref_sink (text_empty);
|
|
|
|
+ engine->surrounding_cursor_pos = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -393,6 +404,11 @@ bus_engine_proxy_real_destroy (IBusProxy *proxy)
|
2010-09-28 02:32:30 +00:00
|
|
|
engine->keymap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (engine->surrounding_text) {
|
|
|
|
+ g_object_unref (engine->surrounding_text);
|
|
|
|
+ engine->surrounding_text = NULL;
|
|
|
|
+ }
|
|
|
|
+
|
2010-11-26 05:38:39 +00:00
|
|
|
IBUS_PROXY_CLASS (bus_engine_proxy_parent_class)->destroy ((IBusProxy *)engine);
|
2010-09-28 02:32:30 +00:00
|
|
|
}
|
|
|
|
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -926,6 +942,33 @@ void bus_engine_proxy_property_hide (BusEngineProxy *engine,
|
2010-11-04 14:32:23 +00:00
|
|
|
NULL);
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
2010-09-29 05:47:35 +00:00
|
|
|
+void bus_engine_proxy_set_surrounding_text (BusEngineProxy *engine,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint cursor_pos)
|
2010-09-14 01:52:06 +00:00
|
|
|
+{
|
|
|
|
+ g_assert (BUS_IS_ENGINE_PROXY (engine));
|
|
|
|
+ g_assert (text != NULL);
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ if (!engine->surrounding_text ||
|
|
|
|
+ g_strcmp0 (text->text, engine->surrounding_text->text) != 0 ||
|
|
|
|
+ cursor_pos != engine->surrounding_cursor_pos) {
|
2010-11-04 14:32:23 +00:00
|
|
|
+ GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text);
|
2010-09-29 05:47:35 +00:00
|
|
|
+ if (engine->surrounding_text)
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_object_unref (engine->surrounding_text);
|
|
|
|
+ engine->surrounding_text = (IBusText *) g_object_ref_sink (text);
|
|
|
|
+ engine->surrounding_cursor_pos = cursor_pos;
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
+ g_dbus_proxy_call ((GDBusProxy *)engine,
|
|
|
|
+ "SetSurroundingText",
|
|
|
|
+ g_variant_new ("(vu)", variant, cursor_pos),
|
|
|
|
+ G_DBUS_CALL_FLAGS_NONE,
|
|
|
|
+ -1,
|
|
|
|
+ NULL,
|
|
|
|
+ NULL,
|
|
|
|
+ NULL);
|
2010-09-28 02:32:30 +00:00
|
|
|
+ }
|
2010-09-14 01:52:06 +00:00
|
|
|
+}
|
|
|
|
+
|
2010-12-09 06:42:20 +00:00
|
|
|
/* a macro to generate a function to call a nullary D-Bus method. */
|
2010-09-14 01:52:06 +00:00
|
|
|
#define DEFINE_FUNCTION(Name, name) \
|
|
|
|
void \
|
|
|
|
diff --git a/bus/engineproxy.h b/bus/engineproxy.h
|
2010-12-09 06:42:20 +00:00
|
|
|
index 5e658a4..2ad6ed4 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/bus/engineproxy.h
|
|
|
|
+++ b/bus/engineproxy.h
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -210,5 +210,16 @@ void bus_engine_proxy_property_hide (BusEngineProxy *engine,
|
|
|
|
*/
|
2010-09-14 01:52:06 +00:00
|
|
|
gboolean bus_engine_proxy_is_enabled (BusEngineProxy *engine);
|
2010-12-09 06:42:20 +00:00
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * bus_engine_proxy_set_surrounding_text:
|
|
|
|
+ *
|
|
|
|
+ * Call "SetSurroundingText" method of an engine asynchronously.
|
|
|
|
+ */
|
2010-09-14 01:52:06 +00:00
|
|
|
+void bus_engine_proxy_set_surrounding_text
|
|
|
|
+ (BusEngineProxy *engine,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint cursor_pos);
|
2010-12-09 06:42:20 +00:00
|
|
|
+
|
|
|
|
+
|
2010-09-14 01:52:06 +00:00
|
|
|
G_END_DECLS
|
|
|
|
#endif
|
|
|
|
diff --git a/bus/inputcontext.c b/bus/inputcontext.c
|
2010-12-09 06:42:20 +00:00
|
|
|
index 7e522f3..de9f31f 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/bus/inputcontext.c
|
|
|
|
+++ b/bus/inputcontext.c
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -247,6 +247,11 @@ static const gchar introspection_xml[] =
|
2010-11-04 14:32:23 +00:00
|
|
|
" <method name='GetEngine'>"
|
|
|
|
" <arg direction='out' type='v' name='desc' />"
|
|
|
|
" </method>"
|
|
|
|
+ " <method name='SetSurroundingText'>"
|
|
|
|
+ " <arg direction='in' type='v' name='text' />"
|
|
|
|
+ " <arg direction='in' type='u' name='cursor_pos' />"
|
|
|
|
+ " </method>"
|
|
|
|
+
|
|
|
|
/* signals */
|
|
|
|
" <signal name='CommitText'>"
|
|
|
|
" <arg type='v' name='text' />"
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -961,6 +966,32 @@ _ic_get_engine (BusInputContext *context,
|
|
|
|
* Handle a D-Bus method call whose destination and interface name are both "org.freedesktop.IBus.InputContext"
|
|
|
|
*/
|
2010-11-04 14:32:23 +00:00
|
|
|
static void
|
|
|
|
+_ic_set_surrounding_text (BusInputContext *context,
|
|
|
|
+ GVariant *parameters,
|
|
|
|
+ GDBusMethodInvocation *invocation)
|
2010-09-14 01:52:06 +00:00
|
|
|
+{
|
2010-11-04 14:32:23 +00:00
|
|
|
+ GVariant *variant = NULL;
|
2010-09-14 01:52:06 +00:00
|
|
|
+ IBusText *text;
|
|
|
|
+ guint cursor_pos = 0;
|
2010-11-04 14:32:23 +00:00
|
|
|
+
|
|
|
|
+ g_variant_get (parameters, "(vu)", &variant, &cursor_pos);
|
|
|
|
+ text = IBUS_TEXT (ibus_serializable_deserialize (variant));
|
|
|
|
+ g_variant_unref (variant);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
|
|
|
+ if ((context->capabilities & IBUS_CAP_SURROUNDING_TEXT) &&
|
2010-11-04 14:32:23 +00:00
|
|
|
+ context->has_focus && context->enabled && context->engine) {
|
2010-09-28 02:32:30 +00:00
|
|
|
+ bus_engine_proxy_set_surrounding_text (context->engine,
|
|
|
|
+ text,
|
|
|
|
+ cursor_pos);
|
2010-09-14 01:52:06 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (g_object_is_floating (text))
|
|
|
|
+ g_object_unref (text);
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
+ g_dbus_method_invocation_return_value (invocation, NULL);
|
2010-09-14 01:52:06 +00:00
|
|
|
+}
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
+static void
|
|
|
|
bus_input_context_service_method_call (IBusService *service,
|
|
|
|
GDBusConnection *connection,
|
|
|
|
const gchar *sender,
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -999,6 +1030,7 @@ bus_input_context_service_method_call (IBusService *service,
|
2010-11-04 14:32:23 +00:00
|
|
|
{ "IsEnabled", _ic_is_enabled },
|
|
|
|
{ "SetEngine", _ic_set_engine },
|
|
|
|
{ "GetEngine", _ic_get_engine },
|
|
|
|
+ { "SetSurroundingText", _ic_set_surrounding_text},
|
2010-09-14 01:52:06 +00:00
|
|
|
};
|
|
|
|
|
2010-11-04 14:32:23 +00:00
|
|
|
gint i;
|
2010-09-14 01:52:06 +00:00
|
|
|
diff --git a/client/gtk2/ibusimcontext.c b/client/gtk2/ibusimcontext.c
|
2010-12-09 06:42:20 +00:00
|
|
|
index a6a11b4..0c15df9 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/client/gtk2/ibusimcontext.c
|
|
|
|
+++ b/client/gtk2/ibusimcontext.c
|
2010-11-26 05:38:39 +00:00
|
|
|
@@ -106,6 +106,12 @@ static void ibus_im_context_set_cursor_location
|
2010-09-14 01:52:06 +00:00
|
|
|
static void ibus_im_context_set_use_preedit
|
|
|
|
(GtkIMContext *context,
|
|
|
|
gboolean use_preedit);
|
|
|
|
+static void ibus_im_context_set_surrounding
|
|
|
|
+ (GtkIMContext *slave,
|
|
|
|
+ const gchar *text,
|
|
|
|
+ gint len,
|
|
|
|
+ gint cursor_index);
|
|
|
|
+
|
|
|
|
|
|
|
|
/* static methods*/
|
|
|
|
static void _create_input_context (IBusIMContext *context);
|
2010-11-26 05:38:39 +00:00
|
|
|
@@ -124,14 +130,15 @@ static void _slave_preedit_start_cb (GtkIMContext *slave,
|
2010-09-14 01:52:06 +00:00
|
|
|
IBusIMContext *context);
|
|
|
|
static void _slave_preedit_end_cb (GtkIMContext *slave,
|
|
|
|
IBusIMContext *context);
|
|
|
|
-static void _slave_retrieve_surrounding_cb
|
|
|
|
+static gboolean _slave_retrieve_surrounding_cb
|
|
|
|
(GtkIMContext *slave,
|
2010-11-22 03:45:59 +00:00
|
|
|
- IBusIMContext *context);
|
2010-09-14 01:52:06 +00:00
|
|
|
-static void _slave_delete_surrounding_cb
|
2010-11-22 03:45:59 +00:00
|
|
|
+ IBusIMContext *context);
|
2010-09-14 01:52:06 +00:00
|
|
|
+static gboolean _slave_delete_surrounding_cb
|
|
|
|
(GtkIMContext *slave,
|
2010-11-22 03:45:59 +00:00
|
|
|
- gint offset_from_cursor,
|
|
|
|
- guint nchars,
|
|
|
|
- IBusIMContext *context);
|
|
|
|
+ gint offset_from_cursor,
|
|
|
|
+ guint nchars,
|
|
|
|
+ IBusIMContext *context);
|
2010-09-28 02:32:30 +00:00
|
|
|
+static void _request_surrounding_text (IBusIMContext *context);
|
|
|
|
|
2010-11-22 03:45:59 +00:00
|
|
|
static GType _ibus_type_im_context = 0;
|
2010-11-26 05:38:39 +00:00
|
|
|
static GtkIMContextClass *parent_class = NULL;
|
|
|
|
@@ -196,6 +203,17 @@ ibus_im_context_new (void)
|
2010-09-28 02:32:30 +00:00
|
|
|
return IBUS_IM_CONTEXT (obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
+static void
|
|
|
|
+_request_surrounding_text (IBusIMContext *context)
|
|
|
|
+{
|
2010-11-22 03:45:59 +00:00
|
|
|
+ if (context->enable &&
|
|
|
|
+ (context->caps & IBUS_CAP_SURROUNDING_TEXT)) {
|
2010-09-14 01:52:06 +00:00
|
|
|
+ gboolean return_value;
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_signal_emit (context, _signal_retrieve_surrounding_id, 0,
|
2010-09-14 01:52:06 +00:00
|
|
|
+ &return_value);
|
|
|
|
+ }
|
2010-09-28 02:32:30 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
static gint
|
|
|
|
_key_snooper_cb (GtkWidget *widget,
|
|
|
|
GdkEventKey *event,
|
2010-11-26 05:38:39 +00:00
|
|
|
@@ -223,6 +241,8 @@ _key_snooper_cb (GtkWidget *widget,
|
|
|
|
if (G_UNLIKELY (event->state & IBUS_IGNORED_MASK))
|
|
|
|
return FALSE;
|
2010-09-28 02:32:30 +00:00
|
|
|
|
|
|
|
+ _request_surrounding_text (ibusimcontext);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
|
|
|
switch (event->type) {
|
|
|
|
case GDK_KEY_RELEASE:
|
|
|
|
retval = ibus_input_context_process_key_event (ibuscontext,
|
2010-11-26 05:38:39 +00:00
|
|
|
@@ -269,6 +289,7 @@ ibus_im_context_class_init (IBusIMContextClass *class)
|
2010-09-14 01:52:06 +00:00
|
|
|
im_context_class->set_client_window = ibus_im_context_set_client_window;
|
|
|
|
im_context_class->set_cursor_location = ibus_im_context_set_cursor_location;
|
|
|
|
im_context_class->set_use_preedit = ibus_im_context_set_use_preedit;
|
|
|
|
+ im_context_class->set_surrounding = ibus_im_context_set_surrounding;
|
|
|
|
gobject_class->finalize = ibus_im_context_finalize;
|
|
|
|
|
|
|
|
_signal_commit_id =
|
2010-11-26 05:38:39 +00:00
|
|
|
@@ -367,7 +388,11 @@ ibus_im_context_init (GObject *obj)
|
2010-11-22 03:45:59 +00:00
|
|
|
|
|
|
|
ibusimcontext->ibuscontext = NULL;
|
|
|
|
ibusimcontext->has_focus = FALSE;
|
|
|
|
+#ifdef ENABLE_SURROUNDING
|
|
|
|
ibusimcontext->caps = IBUS_CAP_PREEDIT_TEXT | IBUS_CAP_FOCUS | IBUS_CAP_SURROUNDING_TEXT;
|
|
|
|
+#else
|
|
|
|
+ ibusimcontext->caps = IBUS_CAP_PREEDIT_TEXT | IBUS_CAP_FOCUS;
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
|
// Create slave im context
|
2010-11-26 05:38:39 +00:00
|
|
|
@@ -459,6 +484,8 @@ ibus_im_context_filter_keypress (GtkIMContext *context,
|
2010-09-14 01:52:06 +00:00
|
|
|
if (ibusimcontext->client_window == NULL && event->window != NULL)
|
|
|
|
gtk_im_context_set_client_window ((GtkIMContext *)ibusimcontext, event->window);
|
|
|
|
|
2010-09-28 02:32:30 +00:00
|
|
|
+ _request_surrounding_text (ibusimcontext);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
|
|
|
switch (event->type) {
|
|
|
|
case GDK_KEY_RELEASE:
|
|
|
|
retval = ibus_input_context_process_key_event (ibusimcontext->ibuscontext,
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -516,6 +543,8 @@ ibus_im_context_focus_in (GtkIMContext *context)
|
|
|
|
(gpointer *) &_focus_im_context);
|
2010-09-14 01:52:06 +00:00
|
|
|
_focus_im_context = context;
|
|
|
|
}
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ _request_surrounding_text (ibusimcontext);
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -689,6 +718,39 @@ ibus_im_context_set_use_preedit (GtkIMContext *context, gboolean use_preedit)
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
+ibus_im_context_set_surrounding (GtkIMContext *context,
|
|
|
|
+ const gchar *text,
|
|
|
|
+ gint len,
|
|
|
|
+ gint cursor_index)
|
|
|
|
+{
|
|
|
|
+ g_return_if_fail (context != NULL);
|
|
|
|
+ g_return_if_fail (IBUS_IS_IM_CONTEXT (context));
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_return_if_fail (text != NULL);
|
|
|
|
+ g_return_if_fail (strlen (text) >= len);
|
|
|
|
+ g_return_if_fail (0 <= cursor_index && cursor_index <= len);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ IBusIMContext *ibusimcontext = IBUS_IM_CONTEXT (context);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
|
|
|
+ if (ibusimcontext->enable && ibusimcontext->ibuscontext) {
|
|
|
|
+ IBusText *ibustext;
|
|
|
|
+ guint cursor_pos;
|
2010-09-28 02:32:30 +00:00
|
|
|
+ gchar *p;
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ p = g_strndup (text, len);
|
|
|
|
+ cursor_pos = g_utf8_strlen (p, cursor_index);
|
|
|
|
+ ibustext = ibus_text_new_from_string (p);
|
|
|
|
+ g_free (p);
|
2010-09-14 01:52:06 +00:00
|
|
|
+ ibus_input_context_set_surrounding_text (ibusimcontext->ibuscontext,
|
|
|
|
+ ibustext,
|
|
|
|
+ cursor_pos);
|
|
|
|
+ }
|
|
|
|
+ gtk_im_context_set_surrounding (ibusimcontext->slave,
|
|
|
|
+ text,
|
|
|
|
+ len,
|
|
|
|
+ cursor_index);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
_bus_connected_cb (IBusBus *bus,
|
|
|
|
IBusIMContext *ibusimcontext)
|
|
|
|
{
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -704,6 +766,8 @@ _ibus_context_commit_text_cb (IBusInputContext *ibuscontext,
|
2010-09-14 01:52:06 +00:00
|
|
|
IDEBUG ("%s", __FUNCTION__);
|
|
|
|
|
|
|
|
g_signal_emit (ibusimcontext, _signal_commit_id, 0, text->text);
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ _request_surrounding_text (ibusimcontext);
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -976,6 +1040,8 @@ _ibus_context_show_preedit_text_cb (IBusInputContext *ibuscontext,
|
2010-09-14 01:52:06 +00:00
|
|
|
ibusimcontext->preedit_visible = TRUE;
|
|
|
|
g_signal_emit (ibusimcontext, _signal_preedit_start_id, 0);
|
|
|
|
g_signal_emit (ibusimcontext, _signal_preedit_changed_id, 0);
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ _request_surrounding_text (ibusimcontext);
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -1139,17 +1205,21 @@ _slave_preedit_end_cb (GtkIMContext *slave,
|
2010-09-14 01:52:06 +00:00
|
|
|
g_signal_emit (ibusimcontext, _signal_preedit_end_id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
-static void
|
|
|
|
+static gboolean
|
|
|
|
_slave_retrieve_surrounding_cb (GtkIMContext *slave,
|
|
|
|
IBusIMContext *ibusimcontext)
|
|
|
|
{
|
|
|
|
+ gboolean return_value;
|
|
|
|
+
|
|
|
|
if (ibusimcontext->enable && ibusimcontext->ibuscontext) {
|
|
|
|
- return;
|
|
|
|
+ return FALSE;
|
|
|
|
}
|
|
|
|
- g_signal_emit (ibusimcontext, _signal_retrieve_surrounding_id, 0);
|
|
|
|
+ g_signal_emit (ibusimcontext, _signal_retrieve_surrounding_id, 0,
|
|
|
|
+ &return_value);
|
|
|
|
+ return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
-static void
|
|
|
|
+static gboolean
|
|
|
|
_slave_delete_surrounding_cb (GtkIMContext *slave,
|
|
|
|
gint offset_from_cursor,
|
|
|
|
guint nchars,
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -1158,8 +1228,9 @@ _slave_delete_surrounding_cb (GtkIMContext *slave,
|
2010-09-14 01:52:06 +00:00
|
|
|
gboolean return_value;
|
|
|
|
|
|
|
|
if (ibusimcontext->enable && ibusimcontext->ibuscontext) {
|
|
|
|
- return;
|
|
|
|
+ return FALSE;
|
|
|
|
}
|
|
|
|
g_signal_emit (ibusimcontext, _signal_delete_surrounding_id, 0, offset_from_cursor, nchars, &return_value);
|
|
|
|
+ return return_value;
|
|
|
|
}
|
|
|
|
|
2010-11-22 03:45:59 +00:00
|
|
|
diff --git a/configure.ac b/configure.ac
|
2010-11-26 05:38:39 +00:00
|
|
|
index ea0d32b..1347991 100644
|
2010-11-22 03:45:59 +00:00
|
|
|
--- a/configure.ac
|
|
|
|
+++ b/configure.ac
|
|
|
|
@@ -405,6 +405,19 @@ AC_ARG_WITH(no-snooper-apps,
|
|
|
|
AC_DEFINE_UNQUOTED(NO_SNOOPER_APPS, "$NO_SNOOPER_APPS",
|
|
|
|
[Does not enbale keyboard snooper in those applications])
|
|
|
|
|
|
|
|
+# option for enable surrounding-text
|
|
|
|
+AC_ARG_ENABLE(surrounding-text,
|
|
|
|
+ AS_HELP_STRING([--enable-surrounding-text],
|
|
|
|
+ [Enable surrounding-text support]),
|
|
|
|
+ [enable_surrounding_text=$enableval],
|
|
|
|
+ [enable_surrounding_text=no]
|
|
|
|
+)
|
|
|
|
+if test x"$enable_surrounding_text" = x"yes"; then
|
|
|
|
+ AC_DEFINE(ENABLE_SURROUNDING, TRUE, [Enable surrounding-text support])
|
|
|
|
+else
|
|
|
|
+ enable_surrounding_text="no (disabled, use --enable-surrounding-text to enable)"
|
|
|
|
+fi
|
|
|
|
+
|
|
|
|
# check iso-codes
|
|
|
|
PKG_CHECK_MODULES(ISOCODES, [
|
|
|
|
iso-codes
|
|
|
|
@@ -477,5 +490,6 @@ Build options:
|
|
|
|
Build document $enable_gtk_doc
|
|
|
|
Enable key snooper $enable_key_snooper
|
|
|
|
No snooper regexes "$NO_SNOOPER_APPS"
|
|
|
|
+ Enable surrounding-text $enable_surrounding_text
|
|
|
|
])
|
|
|
|
|
2010-09-14 11:20:08 +00:00
|
|
|
diff --git a/ibus/engine.py b/ibus/engine.py
|
|
|
|
index b1df2fe..ec42fa4 100644
|
|
|
|
--- a/ibus/engine.py
|
|
|
|
+++ b/ibus/engine.py
|
|
|
|
@@ -46,6 +46,9 @@ class EngineBase(object.Object):
|
|
|
|
def set_cursor_location(self, x, y, w, h):
|
|
|
|
pass
|
|
|
|
|
|
|
|
+ def set_surrounding_text(self, text, cursor_index):
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
def set_capabilities(self, cap):
|
|
|
|
pass
|
|
|
|
|
|
|
|
@@ -163,6 +166,9 @@ class EngineProxy(interface.IEngine):
|
|
|
|
def SetCursorLocation(self, x, y, w, h):
|
|
|
|
return self.__engine.set_cursor_location(x, y, w, h)
|
|
|
|
|
|
|
|
+ def SetSurroundingText(self, text, cursor_index):
|
|
|
|
+ return self.__engine.set_surrounding_text(text, cursor_index)
|
|
|
|
+
|
|
|
|
def SetCapabilities(self, caps):
|
|
|
|
return self.__engine.set_capabilities(caps)
|
|
|
|
|
|
|
|
diff --git a/ibus/interface/iengine.py b/ibus/interface/iengine.py
|
2010-11-04 14:32:23 +00:00
|
|
|
index 2386c0f..5db2012 100644
|
2010-09-14 11:20:08 +00:00
|
|
|
--- a/ibus/interface/iengine.py
|
|
|
|
+++ b/ibus/interface/iengine.py
|
|
|
|
@@ -50,6 +50,9 @@ class IEngine(dbus.service.Object):
|
|
|
|
@method(in_signature="iiii")
|
|
|
|
def SetCursorLocation(self, x, y, w, h): pass
|
|
|
|
|
|
|
|
+ @method(in_signature="vu")
|
|
|
|
+ def SetSurroundingText(self, text, cursor_index): pass
|
|
|
|
+
|
|
|
|
@method(in_signature="u")
|
|
|
|
def SetCapabilities(self, cap): pass
|
|
|
|
|
|
|
|
diff --git a/ibus/interface/iinputcontext.py b/ibus/interface/iinputcontext.py
|
|
|
|
index 89f6dbd..2db1c9b 100644
|
|
|
|
--- a/ibus/interface/iinputcontext.py
|
|
|
|
+++ b/ibus/interface/iinputcontext.py
|
|
|
|
@@ -49,6 +49,9 @@ class IInputContext(dbus.service.Object):
|
|
|
|
@method(in_signature="iiii")
|
|
|
|
def SetCursorLocation(self, x, y, w, h): pass
|
|
|
|
|
|
|
|
+ @method(in_signature="vu")
|
|
|
|
+ def SetSurroundingText(self, text, cursor_index): pass
|
|
|
|
+
|
|
|
|
@method()
|
|
|
|
def FocusIn(self): pass
|
|
|
|
|
2010-09-14 01:52:06 +00:00
|
|
|
diff --git a/src/ibusengine.c b/src/ibusengine.c
|
2010-11-22 03:45:59 +00:00
|
|
|
index ae07393..777d404 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/src/ibusengine.c
|
|
|
|
+++ b/src/ibusengine.c
|
2010-09-28 02:32:30 +00:00
|
|
|
@@ -45,6 +45,7 @@ enum {
|
2010-09-14 01:52:06 +00:00
|
|
|
PROPERTY_SHOW,
|
|
|
|
PROPERTY_HIDE,
|
|
|
|
CANDIDATE_CLICKED,
|
|
|
|
+ SET_SURROUNDING_TEXT,
|
|
|
|
LAST_SIGNAL,
|
|
|
|
};
|
|
|
|
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -58,10 +59,15 @@ enum {
|
2010-09-14 01:52:06 +00:00
|
|
|
struct _IBusEnginePrivate {
|
2010-11-04 14:32:23 +00:00
|
|
|
gchar *engine_name;
|
|
|
|
GDBusConnection *connection;
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
|
|
|
+ IBusText *surrounding_text;
|
|
|
|
+ guint surrounding_cursor_pos;
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint engine_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
+static IBusText *text_empty = NULL;
|
|
|
|
+
|
|
|
|
/* functions prototype */
|
2010-11-04 14:32:23 +00:00
|
|
|
static void ibus_engine_destroy (IBusEngine *engine);
|
|
|
|
static void ibus_engine_set_property (IBusEngine *engine,
|
|
|
|
@@ -135,6 +141,10 @@ static void ibus_engine_property_show (IBusEngine *engine,
|
|
|
|
const gchar *prop_name);
|
|
|
|
static void ibus_engine_property_hide (IBusEngine *engine,
|
|
|
|
const gchar *prop_name);
|
|
|
|
+static void ibus_engine_set_surrounding_text
|
2010-09-14 01:52:06 +00:00
|
|
|
+ (IBusEngine *engine,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint cursor_pos);
|
2010-11-04 14:32:23 +00:00
|
|
|
static void ibus_engine_emit_signal (IBusEngine *engine,
|
|
|
|
const gchar *signal_name,
|
|
|
|
GVariant *parameters);
|
|
|
|
@@ -245,6 +255,7 @@ ibus_engine_class_init (IBusEngineClass *class)
|
|
|
|
class->property_hide = ibus_engine_property_hide;
|
|
|
|
class->set_cursor_location = ibus_engine_set_cursor_location;
|
|
|
|
class->set_capabilities = ibus_engine_set_capabilities;
|
|
|
|
+ class->set_surrounding_text = ibus_engine_set_surrounding_text;
|
2010-09-14 01:52:06 +00:00
|
|
|
|
|
|
|
/* install properties */
|
2010-11-04 14:32:23 +00:00
|
|
|
/**
|
|
|
|
@@ -611,12 +622,39 @@ ibus_engine_class_init (IBusEngineClass *class)
|
2010-09-14 01:52:06 +00:00
|
|
|
G_TYPE_STRING);
|
|
|
|
|
2010-11-04 14:32:23 +00:00
|
|
|
g_type_class_add_private (class, sizeof (IBusEnginePrivate));
|
|
|
|
+
|
2010-09-14 01:52:06 +00:00
|
|
|
+ /**
|
|
|
|
+ * IBusEngine::set-surrounding-text:
|
|
|
|
+ * @engine: An IBusEngine.
|
|
|
|
+ *
|
|
|
|
+ * Emitted when a surrounding text is set.
|
|
|
|
+ * Implement the member function set_surrounding_text() in extended class to receive this signal.
|
|
|
|
+ *
|
|
|
|
+ * <note><para>Argument @user_data is ignored in this function.</para></note>
|
|
|
|
+ */
|
|
|
|
+ engine_signals[SET_SURROUNDING_TEXT] =
|
|
|
|
+ g_signal_new (I_("set-surrounding-text"),
|
|
|
|
+ G_TYPE_FROM_CLASS (gobject_class),
|
|
|
|
+ G_SIGNAL_RUN_LAST,
|
|
|
|
+ G_STRUCT_OFFSET (IBusEngineClass, set_surrounding_text),
|
|
|
|
+ NULL, NULL,
|
2010-11-04 14:32:23 +00:00
|
|
|
+ _ibus_marshal_VOID__OBJECT_UINT,
|
2010-09-14 01:52:06 +00:00
|
|
|
+ G_TYPE_NONE,
|
|
|
|
+ 2,
|
2010-09-28 02:32:30 +00:00
|
|
|
+ G_TYPE_OBJECT,
|
2010-09-14 01:52:06 +00:00
|
|
|
+ G_TYPE_UINT);
|
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ text_empty = ibus_text_new_from_static_string ("");
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_object_ref_sink (text_empty);
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 14:32:23 +00:00
|
|
|
ibus_engine_init (IBusEngine *engine)
|
|
|
|
{
|
|
|
|
engine->priv = IBUS_ENGINE_GET_PRIVATE (engine);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
+ engine->priv->surrounding_text = g_object_ref_sink (text_empty);
|
|
|
|
+ engine->priv->surrounding_cursor_pos = 0;
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -625,6 +663,11 @@ ibus_engine_destroy (IBusEngine *engine)
|
|
|
|
g_free (engine->priv->engine_name);
|
|
|
|
engine->priv->engine_name = NULL;
|
2010-09-14 01:52:06 +00:00
|
|
|
|
2010-11-04 14:32:23 +00:00
|
|
|
+ if (engine->priv->surrounding_text) {
|
|
|
|
+ g_object_unref (engine->priv->surrounding_text);
|
|
|
|
+ engine->priv->surrounding_text = NULL;
|
2010-09-14 01:52:06 +00:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
IBUS_OBJECT_CLASS(ibus_engine_parent_class)->destroy (IBUS_OBJECT (engine));
|
|
|
|
}
|
|
|
|
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -796,6 +839,25 @@ ibus_engine_service_method_call (IBusService *service,
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ if (g_strcmp0 (method_name, "SetSurroundingText") == 0) {
|
|
|
|
+ GVariant *variant = NULL;
|
|
|
|
+ IBusText *text;
|
|
|
|
+ guint cursor_pos;
|
|
|
|
+
|
|
|
|
+ g_variant_get (parameters, "(vu)", &variant, &cursor_pos);
|
|
|
|
+ text = IBUS_TEXT (ibus_serializable_deserialize (variant));
|
|
|
|
+ g_variant_unref (variant);
|
|
|
|
+
|
|
|
|
+ g_signal_emit (engine, engine_signals[SET_SURROUNDING_TEXT], 0,
|
|
|
|
+ text,
|
|
|
|
+ cursor_pos);
|
|
|
|
+ if (g_object_is_floating (text)) {
|
|
|
|
+ g_object_unref (text);
|
2010-09-14 01:52:06 +00:00
|
|
|
+ }
|
2010-11-04 14:32:23 +00:00
|
|
|
+ g_dbus_method_invocation_return_value (invocation, NULL);
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
/* should not be reached */
|
|
|
|
g_return_if_reached ();
|
|
|
|
}
|
|
|
|
@@ -950,6 +1012,26 @@ ibus_engine_property_hide (IBusEngine *engine, const gchar *prop_name)
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
+ibus_engine_set_surrounding_text (IBusEngine *engine,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint cursor_pos)
|
|
|
|
+{
|
2010-09-29 05:47:35 +00:00
|
|
|
+ g_assert (IBUS_IS_ENGINE (engine));
|
|
|
|
+
|
|
|
|
+ IBusEnginePrivate *priv;
|
|
|
|
+
|
|
|
|
+ priv = IBUS_ENGINE_GET_PRIVATE (engine);
|
|
|
|
+
|
|
|
|
+ if (priv->surrounding_text) {
|
|
|
|
+ g_object_unref (priv->surrounding_text);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ priv->surrounding_text = (IBusText *) g_object_ref_sink (text ? text : text_empty);
|
|
|
|
+ priv->surrounding_cursor_pos = cursor_pos;
|
2010-09-14 01:52:06 +00:00
|
|
|
+ // g_debug ("set-surrounding-text ('%s', %d)", text->text, cursor_pos);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void
|
2010-11-04 14:32:23 +00:00
|
|
|
ibus_engine_emit_signal (IBusEngine *engine,
|
|
|
|
const gchar *signal_name,
|
|
|
|
GVariant *parameters)
|
2010-11-22 03:45:59 +00:00
|
|
|
@@ -1133,14 +1215,66 @@ void ibus_engine_delete_surrounding_text (IBusEngine *engine,
|
2010-09-29 05:47:35 +00:00
|
|
|
gint offset_from_cursor,
|
|
|
|
guint nchars)
|
2010-09-28 02:32:30 +00:00
|
|
|
{
|
2010-09-29 05:47:35 +00:00
|
|
|
+ IBusEnginePrivate *priv;
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
g_return_if_fail (IBUS_IS_ENGINE (engine));
|
|
|
|
|
2010-09-28 02:32:30 +00:00
|
|
|
+ priv = IBUS_ENGINE_GET_PRIVATE (engine);
|
|
|
|
+
|
2010-11-22 03:45:59 +00:00
|
|
|
+ /* Update surrounding-text cache. This is necessary since some
|
|
|
|
+ engines call ibus_engine_get_surrounding_text() immediately
|
|
|
|
+ after ibus_engine_delete_surrounding_text(). */
|
2010-09-28 02:32:30 +00:00
|
|
|
+ if (priv->surrounding_text) {
|
2010-11-22 03:45:59 +00:00
|
|
|
+ IBusText *text;
|
|
|
|
+ glong cursor_pos, len;
|
|
|
|
+
|
|
|
|
+ cursor_pos = priv->surrounding_cursor_pos + offset_from_cursor;
|
|
|
|
+ len = ibus_text_get_length (priv->surrounding_text);
|
|
|
|
+ if (cursor_pos >= 0 && len - cursor_pos >= nchars) {
|
|
|
|
+ gunichar *ucs;
|
|
|
|
+
|
|
|
|
+ ucs = g_utf8_to_ucs4_fast (priv->surrounding_text->text,
|
|
|
|
+ -1,
|
|
|
|
+ NULL);
|
|
|
|
+ memmove (&ucs[cursor_pos],
|
|
|
|
+ &ucs[cursor_pos + nchars],
|
|
|
|
+ sizeof(gunichar) * (len - cursor_pos - nchars));
|
|
|
|
+ ucs[len - nchars] = 0;
|
|
|
|
+ text = ibus_text_new_from_ucs4 (ucs);
|
|
|
|
+ g_free (ucs);
|
|
|
|
+ priv->surrounding_cursor_pos = cursor_pos;
|
|
|
|
+ } else {
|
|
|
|
+ text = text_empty;
|
|
|
|
+ priv->surrounding_cursor_pos = 0;
|
|
|
|
+ }
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_object_unref (priv->surrounding_text);
|
2010-11-22 03:45:59 +00:00
|
|
|
+ priv->surrounding_text = g_object_ref_sink (text);
|
2010-09-28 02:32:30 +00:00
|
|
|
+ }
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
ibus_engine_emit_signal (engine,
|
|
|
|
"DeleteSurroundingText",
|
|
|
|
g_variant_new ("(iu)", offset_from_cursor, nchars));
|
2010-09-28 02:32:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
+ibus_engine_get_surrounding_text (IBusEngine *engine,
|
|
|
|
+ IBusText **text,
|
|
|
|
+ guint *cursor_pos)
|
2010-09-14 01:52:06 +00:00
|
|
|
+{
|
|
|
|
+ IBusEnginePrivate *priv;
|
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ g_return_if_fail (IBUS_IS_ENGINE (engine));
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_return_if_fail (text != NULL);
|
|
|
|
+ g_return_if_fail (cursor_pos != NULL);
|
|
|
|
+
|
2010-09-14 01:52:06 +00:00
|
|
|
+ priv = IBUS_ENGINE_GET_PRIVATE (engine);
|
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ *text = g_object_ref (priv->surrounding_text);
|
2010-09-14 01:52:06 +00:00
|
|
|
+ *cursor_pos = priv->surrounding_cursor_pos;
|
|
|
|
+}
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+void
|
2010-09-14 01:52:06 +00:00
|
|
|
ibus_engine_register_properties (IBusEngine *engine,
|
|
|
|
IBusPropList *prop_list)
|
2010-09-28 02:32:30 +00:00
|
|
|
{
|
2010-09-14 01:52:06 +00:00
|
|
|
diff --git a/src/ibusengine.h b/src/ibusengine.h
|
2010-11-04 14:32:23 +00:00
|
|
|
index 46d0a04..a5f5aea 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/src/ibusengine.h
|
|
|
|
+++ b/src/ibusengine.h
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -136,10 +136,14 @@ struct _IBusEngineClass {
|
2010-09-14 01:52:06 +00:00
|
|
|
guint index,
|
|
|
|
guint button,
|
|
|
|
guint state);
|
|
|
|
+ void (* set_surrounding_text)
|
|
|
|
+ (IBusEngine *engine,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint cursor_index);
|
|
|
|
|
|
|
|
/*< private >*/
|
|
|
|
/* padding */
|
|
|
|
- gpointer pdummy[8];
|
|
|
|
+ gpointer pdummy[7];
|
|
|
|
};
|
|
|
|
|
|
|
|
GType ibus_engine_get_type (void);
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -394,6 +398,21 @@ void ibus_engine_delete_surrounding_text(IBusEngine *engine,
|
2010-09-14 01:52:06 +00:00
|
|
|
guint nchars);
|
|
|
|
|
|
|
|
/**
|
|
|
|
+ * ibus_engine_get_surrounding_text:
|
|
|
|
+ * @engine: An IBusEngine.
|
|
|
|
+ * @text: Location to store surrounding text.
|
|
|
|
+ * @cursor_pos: Cursor position in characters in @text.
|
|
|
|
+ *
|
|
|
|
+ * Get surrounding text.
|
|
|
|
+ *
|
|
|
|
+ * @see_also #IBusEngine::set-surrounding-text
|
|
|
|
+ */
|
|
|
|
+void ibus_engine_get_surrounding_text(IBusEngine *engine,
|
|
|
|
+ IBusText **text,
|
|
|
|
+ guint *cursor_pos);
|
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+
|
2010-09-14 01:52:06 +00:00
|
|
|
+/**
|
|
|
|
* ibus_engine_get_name:
|
|
|
|
* @engine: An IBusEngine.
|
|
|
|
* @returns: Name of IBusEngine.
|
|
|
|
diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c
|
2010-11-22 03:45:59 +00:00
|
|
|
index fc26a7c..4f08401 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/src/ibusinputcontext.c
|
|
|
|
+++ b/src/ibusinputcontext.c
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -59,13 +59,20 @@ enum {
|
2010-09-28 02:32:30 +00:00
|
|
|
/* BusInputContextPriv */
|
|
|
|
struct _IBusInputContextPrivate {
|
2010-09-29 05:47:35 +00:00
|
|
|
gboolean own;
|
2010-09-28 02:32:30 +00:00
|
|
|
+
|
|
|
|
+ /* surrounding text */
|
|
|
|
+ IBusText *surrounding_text;
|
|
|
|
+ guint surrounding_cursor_pos;
|
|
|
|
};
|
|
|
|
typedef struct _IBusInputContextPrivate IBusInputContextPrivate;
|
|
|
|
|
|
|
|
static guint context_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
// static guint context_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
+static IBusText *text_empty = NULL;
|
|
|
|
+
|
|
|
|
/* functions prototype */
|
2010-11-04 14:32:23 +00:00
|
|
|
+static void ibus_input_context_real_destroy (IBusProxy *context);
|
|
|
|
static void ibus_input_context_g_signal (GDBusProxy *proxy,
|
|
|
|
const gchar *sender_name,
|
|
|
|
const gchar *signal_name,
|
|
|
|
@@ -76,10 +83,13 @@ G_DEFINE_TYPE (IBusInputContext, ibus_input_context, IBUS_TYPE_PROXY)
|
|
|
|
static void
|
|
|
|
ibus_input_context_class_init (IBusInputContextClass *class)
|
|
|
|
{
|
|
|
|
+ IBusProxyClass *ibus_proxy_class = IBUS_PROXY_CLASS (class);
|
|
|
|
GDBusProxyClass *g_dbus_proxy_class = G_DBUS_PROXY_CLASS (class);
|
|
|
|
|
|
|
|
g_type_class_add_private (class, sizeof (IBusInputContextPrivate));
|
|
|
|
|
|
|
|
+ ibus_proxy_class->destroy = ibus_input_context_real_destroy;
|
|
|
|
+
|
|
|
|
g_dbus_proxy_class->g_signal = ibus_input_context_g_signal;
|
|
|
|
|
|
|
|
/* install signals */
|
|
|
|
@@ -442,6 +452,9 @@ ibus_input_context_class_init (IBusInputContextClass *class)
|
2010-09-28 02:32:30 +00:00
|
|
|
G_TYPE_NONE,
|
|
|
|
1,
|
|
|
|
IBUS_TYPE_PROPERTY);
|
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ text_empty = ibus_text_new_from_static_string ("");
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_object_ref_sink (text_empty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -450,6 +463,22 @@ ibus_input_context_init (IBusInputContext *context)
|
2010-09-28 02:32:30 +00:00
|
|
|
IBusInputContextPrivate *priv;
|
|
|
|
priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
|
|
|
|
priv->own = TRUE;
|
|
|
|
+ priv->surrounding_text = g_object_ref_sink (text_empty);
|
|
|
|
+ priv->surrounding_cursor_pos = 0;
|
2010-11-04 14:32:23 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void
|
|
|
|
+ibus_input_context_real_destroy (IBusProxy *context)
|
|
|
|
+{
|
|
|
|
+ IBusInputContextPrivate *priv;
|
|
|
|
+ priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (IBUS_INPUT_CONTEXT (context));
|
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ if (priv->surrounding_text) {
|
|
|
|
+ g_object_unref (priv->surrounding_text);
|
|
|
|
+ priv->surrounding_text = NULL;
|
|
|
|
+ }
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
+ IBUS_PROXY_CLASS(ibus_input_context_parent_class)->destroy (context);
|
2010-09-28 02:32:30 +00:00
|
|
|
}
|
|
|
|
|
2010-11-04 14:32:23 +00:00
|
|
|
static void
|
|
|
|
@@ -821,6 +850,38 @@ ibus_input_context_property_hide (IBusInputContext *context,
|
|
|
|
);
|
2010-09-14 01:52:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
+void
|
|
|
|
+ibus_input_context_set_surrounding_text (IBusInputContext *context,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint32 cursor_pos)
|
|
|
|
+{
|
|
|
|
+ g_assert (IBUS_IS_INPUT_CONTEXT (context));
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_assert (IBUS_IS_TEXT (text));
|
|
|
|
+
|
2010-09-29 05:47:35 +00:00
|
|
|
+ IBusInputContextPrivate *priv;
|
2010-09-28 02:32:30 +00:00
|
|
|
+ priv = IBUS_INPUT_CONTEXT_GET_PRIVATE (context);
|
2010-09-14 01:52:06 +00:00
|
|
|
+
|
2010-09-28 02:32:30 +00:00
|
|
|
+ if (priv->surrounding_text == NULL ||
|
|
|
|
+ g_strcmp0 (text->text, priv->surrounding_text->text) != 0 ||
|
|
|
|
+ cursor_pos != priv->surrounding_cursor_pos) {
|
2010-11-04 14:32:23 +00:00
|
|
|
+ GVariant *variant = ibus_serializable_serialize ((IBusSerializable *)text);
|
2010-09-29 05:47:35 +00:00
|
|
|
+ if (priv->surrounding_text)
|
2010-09-28 02:32:30 +00:00
|
|
|
+ g_object_unref (priv->surrounding_text);
|
|
|
|
+ priv->surrounding_text = (IBusText *) g_object_ref_sink (text);
|
|
|
|
+ priv->surrounding_cursor_pos = cursor_pos;
|
|
|
|
+
|
2010-11-04 14:32:23 +00:00
|
|
|
+ g_dbus_proxy_call ((GDBusProxy *) context,
|
|
|
|
+ "SetSurroundingText", /* method_name */
|
|
|
|
+ g_variant_new ("(vu)", variant, cursor_pos), /* parameters */
|
|
|
|
+ G_DBUS_CALL_FLAGS_NONE, /* flags */
|
|
|
|
+ -1, /* timeout */
|
|
|
|
+ NULL, /* cancellable */
|
|
|
|
+ NULL, /* callback */
|
|
|
|
+ NULL /* user_data */
|
|
|
|
+ );
|
2010-09-28 02:32:30 +00:00
|
|
|
+ }
|
2010-09-14 01:52:06 +00:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
gboolean
|
|
|
|
ibus_input_context_is_enabled (IBusInputContext *context)
|
|
|
|
{
|
|
|
|
diff --git a/src/ibusinputcontext.h b/src/ibusinputcontext.h
|
2010-12-09 06:42:20 +00:00
|
|
|
index 8b1f16c..fb65348 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/src/ibusinputcontext.h
|
|
|
|
+++ b/src/ibusinputcontext.h
|
2010-11-04 14:32:23 +00:00
|
|
|
@@ -41,6 +41,7 @@
|
2010-09-14 01:52:06 +00:00
|
|
|
|
|
|
|
#include "ibusproxy.h"
|
|
|
|
#include "ibusenginedesc.h"
|
|
|
|
+#include "ibustext.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Type macros.
|
2010-12-09 06:42:20 +00:00
|
|
|
@@ -279,6 +280,16 @@ IBusEngineDesc
|
2010-09-14 01:52:06 +00:00
|
|
|
void ibus_input_context_set_engine (IBusInputContext *context,
|
|
|
|
const gchar *name);
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * ibus_input_context_set_surrounding_text:
|
|
|
|
+ * @context: An IBusInputContext.
|
|
|
|
+ * @text: An IBusText surrounding the current cursor on the application.
|
|
|
|
+ * @cursor_po: Current cursor position in characters in @text.
|
|
|
|
+*/
|
|
|
|
+void ibus_input_context_set_surrounding_text
|
|
|
|
+ (IBusInputContext *context,
|
|
|
|
+ IBusText *text,
|
|
|
|
+ guint32 cursor_pos);
|
|
|
|
|
|
|
|
G_END_DECLS
|
|
|
|
#endif
|
|
|
|
diff --git a/src/ibusmarshalers.list b/src/ibusmarshalers.list
|
2010-11-04 14:32:23 +00:00
|
|
|
index 5184278..5dc7fc2 100644
|
2010-09-14 01:52:06 +00:00
|
|
|
--- a/src/ibusmarshalers.list
|
|
|
|
+++ b/src/ibusmarshalers.list
|
2010-09-28 02:32:30 +00:00
|
|
|
@@ -13,6 +13,7 @@ VOID:INT,INT,INT,INT
|
|
|
|
VOID:UINT,UINT
|
|
|
|
VOID:INT,UINT
|
|
|
|
VOID:UINT,UINT,UINT
|
|
|
|
+VOID:OBJECT,UINT
|
|
|
|
VOID:OBJECT,UINT,BOOL
|
|
|
|
VOID:OBJECT,UINT,BOOL,UINT
|
|
|
|
VOID:OBJECT,BOOL
|
2010-09-14 01:52:06 +00:00
|
|
|
--
|
2010-12-09 06:42:20 +00:00
|
|
|
1.7.3.2
|
2010-09-14 01:52:06 +00:00
|
|
|
|