@@ -59,29 +59,33 @@ ibus_disconnected_cb(IBusBus *unused_bus, gpointer unused_data) {
5959}
6060
6161static void
62- start_component (void ) {
63- GList * engines , * p ;
64- IBusComponent * component ;
62+ add_single_keyboard (gpointer data , gpointer user_data ) {
63+ IBusEngineDesc * engine = IBUS_ENGINE_DESC (data );
64+ #if IBUS_CHECK_VERSION (1 , 3 , 99 )
65+ const gchar * engine_name = ibus_engine_desc_get_name (engine );
66+ #else
67+ const gchar * engine_name = engine -> name ;
68+ #endif /* !IBUS_CHECK_VERSION(1,3,99) */
69+ ibus_factory_add_engine (factory , engine_name , IBUS_TYPE_KEYMAN_ENGINE );
70+ }
6571
66- ibus_init ();
72+ static void
73+ add_keyboards (IBusBus * bus , gpointer user_data ) {
74+ GList * engines ;
75+ IBusComponent * component ;
6776
68- bus = ibus_bus_new ();
69- g_signal_connect (bus , "disconnected" , G_CALLBACK (ibus_disconnected_cb ), NULL );
77+ g_message ("Adding keyboards to ibus" );
7078
7179 component = ibus_keyman_get_component ();
7280
73- factory = ibus_factory_new (ibus_bus_get_connection (bus ));
81+ GDBusConnection * connection = ibus_bus_get_connection (bus );
82+ factory = ibus_factory_new (connection );
83+
84+ g_signal_connect (bus , "disconnected" , G_CALLBACK (ibus_disconnected_cb ), NULL );
7485
7586 engines = ibus_component_get_engines (component );
76- for (p = engines ; p != NULL ; p = p -> next ) {
77- IBusEngineDesc * engine = (IBusEngineDesc * )p -> data ;
78- #if IBUS_CHECK_VERSION (1 , 3 , 99 )
79- const gchar * engine_name = ibus_engine_desc_get_name (engine );
80- #else
81- const gchar * engine_name = engine -> name ;
82- #endif /* !IBUS_CHECK_VERSION(1,3,99) */
83- ibus_factory_add_engine (factory , engine_name , IBUS_TYPE_KEYMAN_ENGINE );
84- }
87+ g_list_foreach (engines , add_single_keyboard , NULL );
88+ g_list_free (engines );
8589
8690 if (ibus ) {
8791 ibus_bus_request_name (bus , "org.freedesktop.IBus.Keyman" , 0 );
@@ -91,6 +95,22 @@ start_component(void) {
9195
9296 g_object_unref (component );
9397 km_service_get_default (NULL ); // initialise dbus service
98+ }
99+
100+ static void
101+ start_component (void ) {
102+ g_message ("Starting ibus-engine-keyman" );
103+
104+ ibus_init ();
105+
106+ bus = ibus_bus_new ();
107+
108+ if (ibus_bus_is_connected (bus )) {
109+ add_keyboards (bus , NULL );
110+ } else {
111+ g_message ("Waiting for ibus-daemon to start up..." );
112+ g_signal_connect (bus , "connected" , G_CALLBACK (add_keyboards ), NULL );
113+ }
94114
95115 ibus_main ();
96116}
@@ -126,14 +146,19 @@ main(gint argc, gchar **argv) {
126146
127147 if (!g_option_context_parse (context , & argc , & argv , & error )) {
128148 g_print ("Option parsing failed: %s\n" , error -> message );
149+ g_option_context_free (context );
129150 exit (-1 );
130151 }
131152
132153 if (xml ) {
133154 print_engines_xml ();
155+ g_option_context_free (context );
134156 exit (0 );
135157 }
136158
137159 start_component ();
160+
161+ g_option_context_free (context );
162+ g_message ("Exiting ibus-engine-keyman" );
138163 return 0 ;
139164}
0 commit comments