diff options
-rw-r--r-- | bus/engineproxy.c | 34 | ||||
-rw-r--r-- | bus/engineproxy.h | 19 | ||||
-rw-r--r-- | bus/inputcontext.c | 38 | ||||
-rw-r--r-- | src/ibusengine.c | 104 | ||||
-rw-r--r-- | src/ibusengine.h | 9 | ||||
-rw-r--r-- | src/ibusinputcontext.c | 46 | ||||
-rw-r--r-- | src/ibusinputcontext.h | 36 | ||||
-rw-r--r-- | src/ibusmarshalers.list | 1 |
8 files changed, 285 insertions, 2 deletions
diff --git a/bus/engineproxy.c b/bus/engineproxy.c index 33ebf2a4..0c6f45d9 100644 --- a/bus/engineproxy.c +++ b/bus/engineproxy.c @@ -945,6 +945,40 @@ bus_engine_proxy_set_cursor_location (BusEngineProxy *engine, } void +bus_engine_proxy_process_hand_writing_event + (BusEngineProxy *engine, + GVariant *coordinates) +{ + g_assert (BUS_IS_ENGINE_PROXY (engine)); + + g_dbus_proxy_call ((GDBusProxy *)engine, + "ProcessHandWritingEvent", + coordinates, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); +} + +void +bus_engine_proxy_cancel_hand_writing + (BusEngineProxy *engine, + guint n_strokes) +{ + g_assert (BUS_IS_ENGINE_PROXY (engine)); + + g_dbus_proxy_call ((GDBusProxy *)engine, + "CancelHandWriting", + g_variant_new ("(u)", n_strokes), + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, + NULL, + NULL); +} + +void bus_engine_proxy_set_capabilities (BusEngineProxy *engine, guint caps) { diff --git a/bus/engineproxy.h b/bus/engineproxy.h index 0680917a..6980f081 100644 --- a/bus/engineproxy.h +++ b/bus/engineproxy.h @@ -222,6 +222,25 @@ void bus_engine_proxy_set_surrounding_text IBusText *text, guint cursor_pos); +/** + * bus_engine_proxy_process_hand_writing_event: + * + * Call "ProcessHandWritingEvent" method of an engine asynchronously. The type of the GVariant should be "(ad)". + * See ibus_input_context_process_hand_writing_event for details. + */ +void bus_engine_proxy_process_hand_writing_event + (BusEngineProxy *engine, + GVariant *coordinates); + +/** + * bus_engine_proxy_cancel_hand_writing: + * + * Call "CancelHandWriting" method of an engine asynchronously. + * See ibus_input_context_cancel_hand_writing for details. + */ +void bus_engine_proxy_cancel_hand_writing + (BusEngineProxy *engine, + guint n_strokes); G_END_DECLS #endif diff --git a/bus/inputcontext.c b/bus/inputcontext.c index 73ded00b..bad90ec8 100644 --- a/bus/inputcontext.c +++ b/bus/inputcontext.c @@ -238,6 +238,12 @@ static const gchar introspection_xml[] = " <arg direction='in' type='i' name='w' />" " <arg direction='in' type='i' name='h' />" " </method>" + " <method name='ProcessHandWritingEvent'>" + " <arg direction='in' type='ad' name='coordinates' />" + " </method>" + " <method name='CancelHandWriting'>" + " <arg direction='in' type='u' name='n_strokes' />" + " </method>" " <method name='FocusIn' />" " <method name='FocusOut' />" " <method name='Reset' />" @@ -779,6 +785,35 @@ _ic_set_cursor_location (BusInputContext *context, } } +static void +_ic_process_hand_writing_event (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + /* do nothing if it is a fake input context */ + if (context->has_focus && context->enabled && + context->engine && context->fake == FALSE) { + bus_engine_proxy_process_hand_writing_event (context->engine, parameters); + } + g_dbus_method_invocation_return_value (invocation, NULL); +} + +static void +_ic_cancel_hand_writing (BusInputContext *context, + GVariant *parameters, + GDBusMethodInvocation *invocation) +{ + guint n_strokes = 0; + g_variant_get (parameters, "(u)", &n_strokes); + + /* do nothing if it is a fake input context */ + if (context->has_focus && context->enabled && + context->engine && context->fake == FALSE) { + bus_engine_proxy_cancel_hand_writing (context->engine, n_strokes); + } + g_dbus_method_invocation_return_value (invocation, NULL); +} + /** * _ic_focus_in: * @@ -1070,6 +1105,9 @@ bus_input_context_service_method_call (IBusService *service, } methods [] = { { "ProcessKeyEvent", _ic_process_key_event }, { "SetCursorLocation", _ic_set_cursor_location }, + { "ProcessHandWritingEvent", + _ic_process_hand_writing_event }, + { "CancelHandWriting", _ic_cancel_hand_writing }, { "FocusIn", _ic_focus_in }, { "FocusOut", _ic_focus_out }, { "Reset", _ic_reset }, diff --git a/src/ibusengine.c b/src/ibusengine.c index 73b64730..f545befa 100644 --- a/src/ibusengine.c +++ b/src/ibusengine.c @@ -47,6 +47,8 @@ enum { PROPERTY_HIDE, CANDIDATE_CLICKED, SET_SURROUNDING_TEXT, + PROCESS_HAND_WRITING_EVENT, + CANCEL_HAND_WRITING, LAST_SIGNAL, }; @@ -148,6 +150,13 @@ static void ibus_engine_set_surrounding_text (IBusEngine *engine, IBusText *text, guint cursor_pos); +static void ibus_engine_process_hand_writing_event + (IBusEngine *engine, + const gdouble *coordinates, + guint coordinates_len); +static void ibus_engine_cancel_hand_writing + (IBusEngine *engine, + guint n_strokes); static void ibus_engine_emit_signal (IBusEngine *engine, const gchar *signal_name, GVariant *parameters); @@ -171,6 +180,12 @@ static const gchar introspection_xml[] = " <arg direction='in' type='i' name='w' />" " <arg direction='in' type='i' name='h' />" " </method>" + " <method name='ProcessHandWritingEvent'>" + " <arg direction='in' type='ad' name='coordinates' />" + " </method>" + " <method name='CancelHandWriting'>" + " <arg direction='in' type='u' name='n_strokes' />" + " </method>" " <method name='SetCapabilities'>" " <arg direction='in' type='u' name='caps' />" " </method>" @@ -268,6 +283,9 @@ ibus_engine_class_init (IBusEngineClass *class) 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; + class->process_hand_writing_event + = ibus_engine_process_hand_writing_event; + class->cancel_hand_writing = ibus_engine_cancel_hand_writing; /* install properties */ /** @@ -633,6 +651,50 @@ ibus_engine_class_init (IBusEngineClass *class) 1, G_TYPE_STRING); + /** + * IBusEngine::process-hand-writing-event: + * @engine: An IBusEngine. + * @coordinates: An array of double (0.0 to 1.0) which represents a stroke (i.e. [x1, y1, x2, y2, x3, y3, ...]). + * @coordinates_len: The number of elements in the array. + * + * Emitted when a hand writing operation is cancelled. + * Implement the member function cancel_hand_writing() in extended class to receive this signal. + * + * <note><para>Argument @user_data is ignored in this function.</para></note> + */ + engine_signals[PROCESS_HAND_WRITING_EVENT] = + g_signal_new (I_("process-hand-writing-event"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IBusEngineClass, process_hand_writing_event), + NULL, NULL, + _ibus_marshal_VOID__POINTER_UINT, + G_TYPE_NONE, + 2, + G_TYPE_POINTER, + G_TYPE_UINT); + + /** + * IBusEngine::cancel-hand-writing: + * @engine: An IBusEngine. + * @n_strokes: The number of strokes to be removed. 0 means "remove all". + * + * Emitted when a hand writing operation is cancelled. + * Implement the member function cancel_hand_writing() in extended class to receive this signal. + * + * <note><para>Argument @user_data is ignored in this function.</para></note> + */ + engine_signals[CANCEL_HAND_WRITING] = + g_signal_new (I_("cancel-hand-writing"), + G_TYPE_FROM_CLASS (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (IBusEngineClass, cancel_hand_writing), + NULL, NULL, + _ibus_marshal_VOID__UINT, + G_TYPE_NONE, + 1, + G_TYPE_UINT); + g_type_class_add_private (class, sizeof (IBusEnginePrivate)); /** @@ -871,6 +933,30 @@ ibus_engine_service_method_call (IBusService *service, return; } + if (g_strcmp0 (method_name, "ProcessHandWritingEvent") == 0) { + const gdouble *coordinates; + gsize coordinates_len = 0; + + coordinates = g_variant_get_fixed_array (g_variant_get_child_value (parameters, 0), &coordinates_len, sizeof (gdouble)); + g_return_if_fail (coordinates != NULL); + g_return_if_fail (coordinates_len >= 4); /* The array should contain at least one line. */ + g_return_if_fail (coordinates_len <= G_MAXUINT); /* to prevent overflow in the cast in g_signal_emit */ + g_return_if_fail ((coordinates_len & 1) == 0); + + g_signal_emit (engine, engine_signals[PROCESS_HAND_WRITING_EVENT], 0, + coordinates, (guint) coordinates_len); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + + if (g_strcmp0 (method_name, "CancelHandWriting") == 0) { + guint n_strokes = 0; + g_variant_get (parameters, "(u)", &n_strokes); + g_signal_emit (engine, engine_signals[CANCEL_HAND_WRITING], 0, n_strokes); + g_dbus_method_invocation_return_value (invocation, NULL); + return; + } + /* should not be reached */ g_return_if_reached (); } @@ -1045,6 +1131,24 @@ ibus_engine_set_surrounding_text (IBusEngine *engine, } static void +ibus_engine_process_hand_writing_event (IBusEngine *engine, + const gdouble *coordinates, + guint coordinates_len) +{ + // guint i; + // g_debug ("process-hand-writing-event (%u)", coordinates_len); + // for (i = 0; i < coordinates_len; i++) + // g_debug (" %lf", coordinates[i]); +} + +static void +ibus_engine_cancel_hand_writing (IBusEngine *engine, + guint n_strokes) +{ + // g_debug ("cancel-hand-writing (%u)", n_strokes); +} + +static void ibus_engine_emit_signal (IBusEngine *engine, const gchar *signal_name, GVariant *parameters) diff --git a/src/ibusengine.h b/src/ibusengine.h index a5f5aea2..29b8f1d5 100644 --- a/src/ibusengine.h +++ b/src/ibusengine.h @@ -140,10 +140,17 @@ struct _IBusEngineClass { (IBusEngine *engine, IBusText *text, guint cursor_index); + void (* process_hand_writing_event) + (IBusEngine *engine, + const gdouble *coordinates, + guint coordinates_len); + void (* cancel_hand_writing) + (IBusEngine *engine, + guint n_strokes); /*< private >*/ /* padding */ - gpointer pdummy[7]; + gpointer pdummy[5]; }; GType ibus_engine_get_type (void); diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c index 439d1b78..e6f97e8c 100644 --- a/src/ibusinputcontext.c +++ b/src/ibusinputcontext.c @@ -805,6 +805,51 @@ ibus_input_context_get_input_context_async_finish (GAsyncResult *res, } void +ibus_input_context_process_hand_writing_event (IBusInputContext *context, + const gdouble *coordinates, + guint coordinates_len) +{ + g_assert (IBUS_IS_INPUT_CONTEXT (context)); + g_return_if_fail (coordinates != NULL); + g_return_if_fail (coordinates_len >= 4); /* The array should contain at least one line. */ + g_return_if_fail ((coordinates_len & 1) == 0); + + guint i; + GVariantBuilder builder; + g_variant_builder_init (&builder, G_VARIANT_TYPE ("ad")); + for (i = 0; i < coordinates_len; i++) { + g_variant_builder_add (&builder, "d", coordinates[i]); + } + + g_dbus_proxy_call ((GDBusProxy *) context, + "ProcessHandWritingEvent", /* method_name */ + g_variant_new ("(ad)", &builder), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); +} + +void +ibus_input_context_cancel_hand_writing (IBusInputContext *context, + guint n_strokes) +{ + g_assert (IBUS_IS_INPUT_CONTEXT (context)); + + g_dbus_proxy_call ((GDBusProxy *) context, + "CancelHandWriting", /* method_name */ + g_variant_new ("(u)", n_strokes), /* parameters */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + -1, /* timeout */ + NULL, /* cancellable */ + NULL, /* callback */ + NULL /* user_data */ + ); +} + +void ibus_input_context_process_key_event_async (IBusInputContext *context, guint32 keyval, guint32 keycode, @@ -826,7 +871,6 @@ ibus_input_context_process_key_event_async (IBusInputContext *context, callback, /* callback */ user_data /* user_data */ ); - } gboolean diff --git a/src/ibusinputcontext.h b/src/ibusinputcontext.h index 67a95d66..e5c76f84 100644 --- a/src/ibusinputcontext.h +++ b/src/ibusinputcontext.h @@ -180,6 +180,42 @@ IBusInputContext * GError **error); /** + * ibus_input_context_process_hand_writing_event + * @context: An IBusInputContext. + * @coordinates: An array of gdouble (0.0 to 1.0) which represents a stroke (i.e. [x1, y1, x2, y2, x3, y3, ...]). + * @coordinates_len: The number of elements in the array. The number should be even and >= 4. + * + * Pass a handwriting stroke to an input method engine. + * + * In this API, a coordinate (0.0, 0.0) represents the top-left corner of an area for + * handwriting, and (1.0, 1.0) does the bottom-right. Therefore, for example, if + * a user writes a character 'L', the array would be something like [0.0, 0.0, 0.0, 1.0, 1.0, 1.0] + * and coordinates_len would be 6. + * + * The function is usually called when a user releases the mouse button in a hand + * writing area. + * + * see_also: #IBusEngine::process-hand-writing-event + */ +void ibus_input_context_process_hand_writing_event + (IBusInputContext *context, + const gdouble *coordinates, + guint coordinates_len); + +/** + * ibus_input_context_cancel_hand_writing + * @context: An IBusInputContext. + * @n_strokes: The number of strokes to be removed. Pass 0 to remove all. + * + * Clear handwriting stroke(s) in the current input method engine. + * + * see_also: #IBusEngine::cancel-hand-writing + */ +void ibus_input_context_cancel_hand_writing + (IBusInputContext *context, + guint n_strokes); + +/** * ibus_input_context_process_key_event_async: * @context: An IBusInputContext. * @keyval: Key symbol of a key event. diff --git a/src/ibusmarshalers.list b/src/ibusmarshalers.list index 5dc7fc2f..c073c6e9 100644 --- a/src/ibusmarshalers.list +++ b/src/ibusmarshalers.list @@ -23,3 +23,4 @@ VOID:STRING,STRING,VARIANT VOID:STRING,STRING,STRING VOID:UINT VOID:UINT,POINTER +VOID:POINTER,UINT |