X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=atk-adaptor%2Fevent.c;h=6cf19faf202bf1327c24d1e6c244385c4abb5655;hb=85af8a25e4fa1c4a65cdbe145b70c334aac97e48;hp=e940e009b0d757bba45cd1164f2f96aebbb67f0d;hpb=a1a316d1ef4167dbca147bc3477ed22305c83743;p=platform%2Fcore%2Fuifw%2Fat-spi2-atk.git diff --git a/atk-adaptor/event.c b/atk-adaptor/event.c index e940e00..6cf19fa 100644 --- a/atk-adaptor/event.c +++ b/atk-adaptor/event.c @@ -2,6 +2,7 @@ * AT-SPI - Assistive Technology Service Provider Interface * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap) * + * Copyright 2011, F123 Consulting & Mais Diferenças * Copyright 2008, 2009, Codethink Ltd. * Copyright 2001, 2002, 2003 Sun Microsystems Inc., * Copyright 2001, 2002, 2003 Ximian, Inc. @@ -52,8 +53,10 @@ static gint atk_bridge_focus_tracker_id; typedef struct _SpiReentrantCallClosure { + DBusConnection *bus; GMainLoop *loop; DBusMessage *reply; + guint timeout; } SpiReentrantCallClosure; static void @@ -80,25 +83,45 @@ set_reply (DBusPendingCall * pending, void *user_data) g_main_loop_quit (closure->loop); } +static gboolean +timeout_reply (void *data) +{ + SpiReentrantCallClosure *closure = data; + + if (!dbus_connection_get_is_connected (closure->bus)) + g_main_loop_quit (closure->loop); + closure->timeout = -1; + return FALSE; +} + static DBusMessage * send_and_allow_reentry (DBusConnection * bus, DBusMessage * message) { DBusPendingCall *pending; SpiReentrantCallClosure closure; GMainContext *main_context; + GSource *source; main_context = (g_getenv ("AT_SPI_CLIENT") ? NULL : spi_global_app_data->main_context); + closure.bus = bus; closure.loop = g_main_loop_new (main_context, FALSE); + closure.reply = NULL; switch_main_context (main_context); - if (!dbus_connection_send_with_reply (bus, message, &pending, -1) || !pending) + if (!dbus_connection_send_with_reply (bus, message, &pending, 9000) || !pending) { switch_main_context (NULL); return NULL; } dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL); + source = g_timeout_source_new (500); + g_source_set_callback (source, timeout_reply, &closure, NULL); + closure.timeout = g_source_attach (source, main_context); + g_source_unref (source); g_main_loop_run (closure.loop); + if (closure.timeout != -1) + g_source_destroy (source); g_main_loop_unref (closure.loop); return closure.reply; @@ -398,6 +421,18 @@ signal_is_needed (const gchar *klass, const gchar *major, const gchar *minor) return ret; } +/* Convert a : to a / so that listeners can use arg0path to match only + * * the prefix */ +static char * +adapt_minor_for_dbus (const char *source) +{ + gchar *ret = g_strdup (source); + int i = strcspn (ret, ":"); + if (ret[i] == ':') + ret[i] = '/'; + return ret; +} + /* * Emits an AT-SPI event. * AT-SPI events names are split into three parts: @@ -421,6 +456,7 @@ emit_event (AtkObject *obj, { DBusConnection *bus = spi_global_app_data->bus; const char *path; + char *minor_dbus; gchar *cname, *t; DBusMessage *sig; @@ -446,7 +482,9 @@ emit_event (AtkObject *obj, dbus_message_iter_init_append(sig, &iter); - dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor); + minor_dbus = adapt_minor_for_dbus (minor); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor_dbus); + g_free (minor_dbus); dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1); dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2); append_variant (&iter, type, val); @@ -612,7 +650,7 @@ state_event_listener (GSignalInvocationHint * signal_hint, emit_event (accessible, ITF_EVENT_OBJECT, STATE_CHANGED, pname, detail1, 0, DBUS_TYPE_INT32_AS_STRING, 0, append_basic); - if (!g_strcmp0 (pname, "defunct")) + if (!g_strcmp0 (pname, "defunct") && detail1) spi_register_deregister_object (spi_global_register, G_OBJECT (accessible), TRUE); return TRUE; @@ -1069,13 +1107,17 @@ generic_event_listener (GSignalInvocationHint * signal_hint, * and stores the signal id returned so that the function may be * de-registered later. */ -static void +static guint add_signal_listener (GSignalEmissionHook listener, const char *signal_name) { guint id; id = atk_add_global_event_listener (listener, signal_name); - g_array_append_val (listener_ids, id); + + if (id > 0) /* id == 0 is a failure */ + g_array_append_val (listener_ids, id); + + return id; } /* @@ -1092,6 +1134,7 @@ spi_atk_register_event_listeners (void) */ GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL); AtkObject *bo = atk_no_op_object_new (ao); + guint id = 0; g_object_unref (G_OBJECT (bo)); g_object_unref (ao); @@ -1109,13 +1152,37 @@ spi_atk_register_event_listeners (void) add_signal_listener (property_event_listener, "Gtk:AtkObject:property-change"); - add_signal_listener (window_event_listener, "window:create"); - add_signal_listener (window_event_listener, "window:destroy"); - add_signal_listener (window_event_listener, "window:minimize"); - add_signal_listener (window_event_listener, "window:maximize"); - add_signal_listener (window_event_listener, "window:restore"); - add_signal_listener (window_event_listener, "window:activate"); - add_signal_listener (window_event_listener, "window:deactivate"); + + /* window events: we tentative try to register using the old format */ + id = add_signal_listener (window_event_listener, "window:create"); + + if (id != 0) + { + /* If we are able to register using the old format, we assume + * that the ATK implementor is managing window events without + * AtkWindow. We can't use the opposite test because after + * including AtkWindow on ATK you would be able to register to + * that event, although the ATK implementor could or not use it. + */ + + add_signal_listener (window_event_listener, "window:destroy"); + add_signal_listener (window_event_listener, "window:minimize"); + add_signal_listener (window_event_listener, "window:maximize"); + add_signal_listener (window_event_listener, "window:restore"); + add_signal_listener (window_event_listener, "window:activate"); + add_signal_listener (window_event_listener, "window:deactivate"); + } + else + { + add_signal_listener (window_event_listener, "Atk:AtkWindow:create"); + add_signal_listener (window_event_listener, "Atk:AtkWindow:destroy"); + add_signal_listener (window_event_listener, "Atk:AtkWindow:minimize"); + add_signal_listener (window_event_listener, "Atk:AtkWindow:maximize"); + add_signal_listener (window_event_listener, "Atk:AtkWindow:restore"); + add_signal_listener (window_event_listener, "Atk:AtkWindow:activate"); + add_signal_listener (window_event_listener, "Atk:AtkWindow:deactivate"); + } + add_signal_listener (document_event_listener, "Gtk:AtkDocument:load-complete"); add_signal_listener (document_event_listener, "Gtk:AtkDocument:reload");