366
459
{ "PageDownLookupTable", PAGE_DOWN_LOOKUP_TABLE },
367
460
{ "CursorUpLookupTable", CURSOR_UP_LOOKUP_TABLE },
368
461
{ "CursorDownLookupTable", CURSOR_DOWN_LOOKUP_TABLE },
462
{ "RequireSurroundingText", REQUIRE_SURROUNDING_TEXT },
371
engine = BUS_ENGINE_PROXY (proxy);
372
interface = ibus_message_get_interface (message);
373
name = ibus_message_get_member (message);
375
if (interface != NULL && g_strcmp0 (interface, IBUS_INTERFACE_ENGINE) != 0)
378
466
for (i = 0; i < G_N_ELEMENTS (signals); i++) {
379
if (g_strcmp0 (name, signals[i].member) == 0) {
467
if (g_strcmp0 (signal_name, signals[i].signal_name) == 0) {
380
468
g_signal_emit (engine, engine_signals[signals[i].signal_id], 0);
385
if (g_strcmp0 (name, "CommitText") == 0) {
473
/* Handle D-Bus signals with parameters. Deserialize them and emit a glib signal. */
474
if (g_strcmp0 (signal_name, "CommitText") == 0) {
475
GVariant *arg0 = NULL;
476
g_variant_get (parameters, "(v)", &arg0);
477
g_return_if_fail (arg0 != NULL);
389
retval = ibus_message_get_args (message,
391
IBUS_TYPE_TEXT, &text,
479
IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (arg0));
480
g_variant_unref (arg0);
481
g_return_if_fail (text != NULL);
395
482
g_signal_emit (engine, engine_signals[COMMIT_TEXT], 0, text);
396
g_object_unref (text);
483
_g_object_unref_if_floating (text);
398
else if (g_strcmp0 (name, "ForwardKeyEvent") == 0) {
404
retval = ibus_message_get_args (message,
406
G_TYPE_UINT, &keyval,
407
G_TYPE_UINT, &keycode,
408
G_TYPE_UINT, &states,
487
if (g_strcmp0 (signal_name, "ForwardKeyEvent") == 0) {
491
g_variant_get (parameters, "(uuu)", &keyval, &keycode, &states);
413
493
g_signal_emit (engine,
414
494
engine_signals[FORWARD_KEY_EVENT],
420
else if (g_strcmp0 (name, "DeleteSurroundingText") == 0) {
421
gint offset_from_cursor;
425
retval = ibus_message_get_args (message,
427
G_TYPE_INT, &offset_from_cursor,
428
G_TYPE_UINT, &nchars,
433
g_signal_emit (engine, engine_signals[DELETE_SURROUNDING_TEXT], 0, offset_from_cursor, nchars);
435
else if (g_strcmp0 (name, "UpdatePreeditText") == 0) {
442
retval = ibus_message_get_args (message,
444
IBUS_TYPE_TEXT, &text,
445
G_TYPE_UINT, &cursor_pos,
446
G_TYPE_BOOLEAN, &visible,
453
g_signal_emit (engine, engine_signals[UPDATE_PREEDIT_TEXT], 0,
454
text, cursor_pos, visible, mode);
455
if (g_object_is_floating (text))
456
g_object_unref (text);
458
else if (g_strcmp0 (name, "UpdateAuxiliaryText") == 0) {
463
retval = ibus_message_get_args (message,
465
IBUS_TYPE_TEXT, &text,
466
G_TYPE_BOOLEAN, &visible,
502
if (g_strcmp0 (signal_name, "DeleteSurroundingText") == 0) {
503
gint offset_from_cursor = 0;
505
g_variant_get (parameters, "(iu)", &offset_from_cursor, &nchars);
507
g_signal_emit (engine,
508
engine_signals[DELETE_SURROUNDING_TEXT],
509
0, offset_from_cursor, nchars);
513
if (g_strcmp0 (signal_name, "UpdatePreeditText") == 0) {
514
GVariant *arg0 = NULL;
515
guint cursor_pos = 0;
516
gboolean visible = FALSE;
519
g_variant_get (parameters, "(vubu)", &arg0, &cursor_pos, &visible, &mode);
520
g_return_if_fail (arg0 != NULL);
522
IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (arg0));
523
g_variant_unref (arg0);
524
g_return_if_fail (text != NULL);
526
g_signal_emit (engine,
527
engine_signals[UPDATE_PREEDIT_TEXT],
528
0, text, cursor_pos, visible, mode);
530
_g_object_unref_if_floating (text);
534
if (g_strcmp0 (signal_name, "UpdateAuxiliaryText") == 0) {
535
GVariant *arg0 = NULL;
536
gboolean visible = FALSE;
538
g_variant_get (parameters, "(vb)", &arg0, &visible);
539
g_return_if_fail (arg0 != NULL);
541
IBusText *text = IBUS_TEXT (ibus_serializable_deserialize (arg0));
542
g_variant_unref (arg0);
543
g_return_if_fail (text != NULL);
472
545
g_signal_emit (engine, engine_signals[UPDATE_AUXILIARY_TEXT], 0, text, visible);
473
if (g_object_is_floating (text))
474
g_object_unref (text);
546
_g_object_unref_if_floating (text);
476
else if (g_strcmp0 (name, "UpdateLookupTable") == 0) {
477
IBusLookupTable *table;
481
retval = ibus_message_get_args (message,
483
IBUS_TYPE_LOOKUP_TABLE, &table,
484
G_TYPE_BOOLEAN, &visible,
550
if (g_strcmp0 (signal_name, "UpdateLookupTable") == 0) {
551
GVariant *arg0 = NULL;
552
gboolean visible = FALSE;
554
g_variant_get (parameters, "(vb)", &arg0, &visible);
555
g_return_if_fail (arg0 != NULL);
557
IBusLookupTable *table = IBUS_LOOKUP_TABLE (ibus_serializable_deserialize (arg0));
558
g_variant_unref (arg0);
559
g_return_if_fail (table != NULL);
490
561
g_signal_emit (engine, engine_signals[UPDATE_LOOKUP_TABLE], 0, table, visible);
491
if (g_object_is_floating (table))
492
g_object_unref (table);
562
_g_object_unref_if_floating (table);
494
else if (g_strcmp0 (name, "RegisterProperties") == 0) {
496
IBusPropList *prop_list;
498
retval = ibus_message_get_args (message,
500
IBUS_TYPE_PROP_LIST, &prop_list,
566
if (g_strcmp0 (signal_name, "RegisterProperties") == 0) {
567
GVariant *arg0 = NULL;
568
g_variant_get (parameters, "(v)", &arg0);
569
g_return_if_fail (arg0 != NULL);
571
IBusPropList *prop_list = IBUS_PROP_LIST (ibus_serializable_deserialize (arg0));
572
g_variant_unref (arg0);
573
g_return_if_fail (prop_list != NULL);
505
575
g_signal_emit (engine, engine_signals[REGISTER_PROPERTIES], 0, prop_list);
507
if (g_object_is_floating (prop_list))
508
g_object_unref (prop_list);
576
_g_object_unref_if_floating (prop_list);
511
else if (g_strcmp0 (name, "UpdateProperty") == 0) {
515
retval = ibus_message_get_args (message,
517
IBUS_TYPE_PROPERTY, &prop,
580
if (g_strcmp0 (signal_name, "UpdateProperty") == 0) {
581
GVariant *arg0 = NULL;
582
g_variant_get (parameters, "(v)", &arg0);
583
g_return_if_fail (arg0 != NULL);
585
IBusProperty *prop = IBUS_PROPERTY (ibus_serializable_deserialize (arg0));
586
g_variant_unref (arg0);
587
g_return_if_fail (prop != NULL);
523
589
g_signal_emit (engine, engine_signals[UPDATE_PROPERTY], 0, prop);
524
if (g_object_is_floating (prop))
525
g_object_unref (prop);
531
g_signal_stop_emission_by_name (engine, "ibus-signal");
535
g_warning ("%s: %s", error->name, error->message);
536
ibus_error_free (error);
590
_g_object_unref_if_floating (prop);
594
g_return_if_reached ();
597
static BusEngineProxy *
598
bus_engine_proxy_new_internal (const gchar *path,
599
IBusEngineDesc *desc,
600
GDBusConnection *connection)
603
g_assert (IBUS_IS_ENGINE_DESC (desc));
604
g_assert (G_IS_DBUS_CONNECTION (connection));
607
BusEngineProxy *engine =
608
(BusEngineProxy *) g_initable_new (BUS_TYPE_ENGINE_PROXY,
612
"g-connection", connection,
613
"g-interface-name", IBUS_INTERFACE_ENGINE,
614
"g-object-path", path,
615
"g-default-timeout", g_gdbus_timeout,
616
"g-flags", G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
618
const gchar *layout = ibus_engine_desc_get_layout (desc);
619
if (layout != NULL && layout[0] != '\0') {
620
engine->keymap = ibus_keymap_get (layout);
543
BusEngineProxy *engine;
547
bus_engine_proxy_process_key_event_reply_cb (IBusPendingCall *pending,
550
IBusMessage *reply_message;
552
gboolean retval = FALSE;
554
reply_message = dbus_pending_call_steal_reply (pending);
556
if (reply_message == NULL) {
558
IBusObject *connection;
559
connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine);
560
ibus_object_destroy (connection);
563
else if ((error = ibus_error_new_from_message (reply_message)) != NULL) {
564
if (g_strcmp0 (error->name, DBUS_ERROR_NO_REPLY) == 0) {
566
IBusObject *connection;
567
connection = (IBusObject *) ibus_proxy_get_connection ((IBusProxy *)call_data->engine);
569
ibus_object_destroy (connection);
626
GSimpleAsyncResult *simple;
627
IBusEngineDesc *desc;
628
BusComponent *component;
629
BusFactoryProxy *factory;
630
GCancellable *cancellable;
631
gulong cancelled_handler_id;
635
} EngineProxyNewData;
638
engine_proxy_new_data_free (EngineProxyNewData *data)
640
if (data->simple != NULL) {
641
if (data->handler_id != 0)
642
g_signal_handler_disconnect (data->component, data->handler_id);
643
g_object_unref (data->simple);
646
if (data->component != NULL)
647
g_object_unref (data->component);
649
if (data->factory != NULL)
650
g_object_unref (data->factory);
652
if (data->timeout_id != 0)
653
g_source_remove (data->timeout_id);
655
if (data->cancellable != NULL) {
656
if (data->cancelled_handler_id != 0)
657
g_cancellable_disconnect (data->cancellable,
658
data->cancelled_handler_id);
659
g_object_unref (data->cancellable);
662
g_slice_free (EngineProxyNewData, data);
666
* create_engine_ready_cb:
668
* A callback function to be called when bus_factory_proxy_create_engine finishes.
669
* Create an BusEngineProxy object and call the GAsyncReadyCallback.
672
create_engine_ready_cb (BusFactoryProxy *factory,
674
EngineProxyNewData *data)
676
g_return_if_fail (data->simple != NULL);
678
GError *error = NULL;
679
gchar *path = bus_factory_proxy_create_engine_finish (factory,
683
g_simple_async_result_set_from_error (data->simple, error);
684
g_simple_async_result_complete_in_idle (data->simple);
685
engine_proxy_new_data_free (data);
689
BusEngineProxy *engine =
690
bus_engine_proxy_new_internal (path,
692
g_dbus_proxy_get_connection ((GDBusProxy *)data->factory));
695
/* FIXME: set destroy callback ? */
696
g_simple_async_result_set_op_res_gpointer (data->simple, engine, NULL);
697
g_simple_async_result_complete_in_idle (data->simple);
699
engine_proxy_new_data_free (data);
705
* A callback function to be called when bus_component_start() emits "notify::factory" signal within 5 seconds.
706
* Call bus_factory_proxy_create_engine to create the engine proxy asynchronously.
709
notify_factory_cb (BusComponent *component,
711
EngineProxyNewData *data)
713
data->factory = bus_component_get_factory (data->component);
715
if (data->factory != NULL) {
716
g_object_ref (data->factory);
717
/* Timeout should be removed */
718
if (data->timeout_id != 0) {
719
g_source_remove (data->timeout_id);
720
data->timeout_id = 0;
722
/* Handler of notify::factory should be removed. */
723
if (data->handler_id != 0) {
724
g_signal_handler_disconnect (data->component, data->handler_id);
725
data->handler_id = 0;
728
/* We *have to* disconnect the cancelled_cb here, since g_dbus_proxy_call
729
* calls create_engine_ready_cb even if the proxy call is cancelled, and
730
* in this case, create_engine_ready_cb itself will return error using
731
* g_simple_async_result_set_from_error and g_simple_async_result_complete.
732
* Otherwise, g_simple_async_result_complete might be called twice for a
733
* single data->simple twice (first in cancelled_cb and later in
734
* create_engine_ready_cb). */
735
if (data->cancellable && data->cancelled_handler_id != 0) {
736
g_cancellable_disconnect (data->cancellable, data->cancelled_handler_id);
737
data->cancelled_handler_id = 0;
740
/* Create engine from factory. */
741
bus_factory_proxy_create_engine (data->factory,
745
(GAsyncReadyCallback) create_engine_ready_cb,
748
/* If factory is NULL, we will continue wait for
749
* factory notify signal or timeout */
755
* A callback function to be called when bus_component_start() does not emit "notify::factory" signal within 5 seconds.
756
* Call the GAsyncReadyCallback and stop the 5 sec timer.
759
timeout_cb (EngineProxyNewData *data)
761
g_simple_async_result_set_error (data->simple,
764
"Timeout was reached");
765
g_simple_async_result_complete_in_idle (data->simple);
767
engine_proxy_new_data_free (data);
775
* A callback function to be called when someone calls g_cancellable_cancel() for the cancellable object for bus_engine_proxy_new.
776
* Call the GAsyncReadyCallback.
779
cancelled_idle_cb (EngineProxyNewData *data)
781
g_simple_async_result_set_error (data->simple,
784
"Operation was cancelled");
785
g_simple_async_result_complete_in_idle (data->simple);
787
engine_proxy_new_data_free (data);
793
cancelled_cb (GCancellable *cancellable,
794
EngineProxyNewData *data)
796
/* Cancel the bus_engine_proxy_new() in idle to avoid deadlock */
797
g_idle_add ((GSourceFunc) cancelled_idle_cb, data);
801
bus_engine_proxy_new (IBusEngineDesc *desc,
803
GCancellable *cancellable,
804
GAsyncReadyCallback callback,
807
g_assert (IBUS_IS_ENGINE_DESC (desc));
808
g_assert (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
811
GSimpleAsyncResult *simple =
812
g_simple_async_result_new (NULL,
815
bus_engine_proxy_new);
817
if (g_cancellable_is_cancelled (cancellable)) {
818
g_simple_async_result_set_error (simple,
821
"Operation was cancelled");
822
g_simple_async_result_complete_in_idle (simple);
823
g_object_unref (simple);
827
EngineProxyNewData *data = g_slice_new0 (EngineProxyNewData);
828
data->desc = g_object_ref (desc);
829
data->component = bus_component_from_engine_desc (desc);
830
g_object_ref (data->component);
831
data->simple = simple;
832
data->timeout = timeout;
834
g_object_set_data ((GObject *)data->simple, "EngineProxyNewData", data);
836
data->factory = bus_component_get_factory (data->component);
838
if (data->factory == NULL) {
839
/* The factory is not ready yet. Create the factory first, and wait for the "notify::factory" signal.
840
* In the handler of "notify::factory", we'll create the engine proxy. */
841
data->handler_id = g_signal_connect (data->component,
843
G_CALLBACK (notify_factory_cb),
845
data->timeout_id = g_timeout_add (timeout,
846
(GSourceFunc) timeout_cb,
849
data->cancellable = (GCancellable *) g_object_ref (cancellable);
850
data->cancelled_handler_id = g_cancellable_connect (cancellable,
851
(GCallback) cancelled_cb,
855
bus_component_start (data->component, g_verbose);
858
/* The factory is ready. We'll create the engine proxy directly. */
859
g_object_ref (data->factory);
861
/* We don't have to connect to cancelled_cb here, since g_dbus_proxy_call
862
* calls create_engine_ready_cb even if the proxy call is cancelled, and
863
* in this case, create_engine_ready_cb itself can return error using
864
* g_simple_async_result_set_from_error and g_simple_async_result_complete. */
865
bus_factory_proxy_create_engine (data->factory,
869
(GAsyncReadyCallback) create_engine_ready_cb,
875
bus_engine_proxy_new_finish (GAsyncResult *res,
878
GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
880
g_assert (error == NULL || *error == NULL);
881
g_assert (g_simple_async_result_get_source_tag (simple) == bus_engine_proxy_new);
883
if (g_simple_async_result_propagate_error (simple, error))
886
return (BusEngineProxy *) g_simple_async_result_get_op_res_gpointer(simple);
890
bus_engine_proxy_process_key_event (BusEngineProxy *engine,
894
GAsyncReadyCallback callback,
897
g_assert (BUS_IS_ENGINE_PROXY (engine));
899
if (keycode != 0 && bus_ibus_impl_is_use_sys_layout (BUS_DEFAULT_IBUS) == FALSE) {
900
/* Since use_sys_layout is false, we don't rely on XKB. Try to convert keyval from keycode by using our own mapping. */
901
IBusKeymap *keymap = engine->keymap;
903
keymap = BUS_DEFAULT_KEYMAP;
904
if (keymap != NULL) {
905
guint t = ibus_keymap_lookup_keysym (engine->keymap, keycode, state);
906
if (t != IBUS_VoidSymbol) {
572
g_warning ("%s: %s", error->name, error->message);
573
ibus_error_free (error);
577
if (!ibus_message_get_args (reply_message,
579
G_TYPE_BOOLEAN, &retval,
581
g_warning ("%s: %s", error->name, error->message);
582
ibus_error_free (error);
588
ibus_message_unref (reply_message);
590
g_object_unref (call_data->engine);
591
call_data->func (GINT_TO_POINTER (retval), call_data->user_data);
592
g_slice_free (CallData, call_data);
596
bus_engine_proxy_process_key_event (BusEngineProxy *engine,
603
g_assert (BUS_IS_ENGINE_PROXY (engine));
604
g_assert (return_cb);
606
IBusPendingCall *pending = NULL;
611
if (keycode != 0 && !BUS_DEFAULT_IBUS->use_sys_layout && engine->keymap != NULL) {
612
guint t = ibus_keymap_lookup_keysym (engine->keymap, keycode, state);
613
if (t != IBUS_VoidSymbol) {
618
retval = ibus_proxy_call_with_reply ((IBusProxy *) engine,
623
G_TYPE_UINT, &keyval,
624
G_TYPE_UINT, &keycode,
628
g_warning ("%s: %s", error->name, error->message);
629
ibus_error_free (error);
630
return_cb (GINT_TO_POINTER (FALSE), user_data);
634
call_data = g_slice_new0 (CallData);
635
call_data->func = return_cb;
636
call_data->user_data = user_data;
637
g_object_ref (engine);
638
call_data->engine = engine;
640
retval = ibus_pending_call_set_notify (pending,
641
(IBusPendingCallNotifyFunction) bus_engine_proxy_process_key_event_reply_cb,
644
ibus_pending_call_unref (pending);
647
g_object_unref (call_data->engine);
648
g_slice_free (CallData, call_data);
649
g_warning ("%s : ProcessKeyEvent", DBUS_ERROR_NO_MEMORY);
650
return_cb (GINT_TO_POINTER (FALSE), user_data);
912
g_dbus_proxy_call ((GDBusProxy *)engine,
914
g_variant_new ("(uuu)", keyval, keycode, state),
915
G_DBUS_CALL_FLAGS_NONE,