2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2011, F123 Consulting & Mais Diferenças
6 * Copyright 2008, 2009, Codethink Ltd.
7 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
8 * Copyright 2001, 2002, 2003 Ximian, Inc.
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Library General Public
12 * License as published by the Free Software Foundation; either
13 * version 2 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Library General Public License for more details.
20 * You should have received a copy of the GNU Library General Public
21 * License along with this library; if not, write to the
22 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 * Boston, MA 02111-1307, USA.
30 #include <droute/droute.h>
31 #include <atspi/atspi.h>
34 #include "accessible-register.h"
40 static GArray *listener_ids = NULL;
42 static gint atk_bridge_key_event_listener_id;
43 static gint atk_bridge_focus_tracker_id;
45 /*---------------------------------------------------------------------------*/
47 #define ITF_EVENT_OBJECT "org.a11y.atspi.Event.Object"
48 #define ITF_EVENT_WINDOW "org.a11y.atspi.Event.Window"
49 #define ITF_EVENT_DOCUMENT "org.a11y.atspi.Event.Document"
50 #define ITF_EVENT_FOCUS "org.a11y.atspi.Event.Focus"
52 /*---------------------------------------------------------------------------*/
54 typedef struct _SpiReentrantCallClosure
60 } SpiReentrantCallClosure;
63 switch_main_context (GMainContext *cnx)
68 atspi_dbus_server_setup_with_g_main (spi_global_app_data->server, cnx);
70 atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, cnx);
71 for (list = spi_global_app_data->direct_connections; list; list = list->next)
72 atspi_dbus_connection_setup_with_g_main (list->data, cnx);
76 set_reply (DBusPendingCall * pending, void *user_data)
78 SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
80 closure->reply = dbus_pending_call_steal_reply (pending);
81 dbus_pending_call_unref (pending);
82 switch_main_context (NULL);
83 g_main_loop_quit (closure->loop);
87 timeout_reply (void *data)
89 SpiReentrantCallClosure *closure = data;
91 if (!dbus_connection_get_is_connected (closure->bus))
92 g_main_loop_quit (closure->loop);
93 closure->timeout = -1;
98 send_and_allow_reentry (DBusConnection * bus, DBusMessage * message)
100 DBusPendingCall *pending;
101 SpiReentrantCallClosure closure;
102 GMainContext *main_context;
105 main_context = (g_getenv ("AT_SPI_CLIENT") ? NULL :
106 spi_global_app_data->main_context);
108 closure.loop = g_main_loop_new (main_context, FALSE);
109 closure.reply = NULL;
110 switch_main_context (main_context);
112 if (!dbus_connection_send_with_reply (bus, message, &pending, 9000) || !pending)
114 switch_main_context (NULL);
117 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
118 source = g_timeout_source_new (500);
119 g_source_set_callback (source, timeout_reply, &closure, NULL);
120 closure.timeout = g_source_attach (source, main_context);
121 g_source_unref (source);
122 g_main_loop_run (closure.loop);
123 if (closure.timeout != -1)
124 g_source_destroy (source);
126 g_main_loop_unref (closure.loop);
127 return closure.reply;
130 /*---------------------------------------------------------------------------*/
133 * Functionality related to sending device events from the application.
135 * This is used for forwarding key events on to the registry daemon.
139 Accessibility_DeviceEventController_NotifyListenersSync (const
143 DBusMessage *message;
145 dbus_bool_t consumed = FALSE;
148 dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
150 ATSPI_DBUS_INTERFACE_DEC,
151 "NotifyListenersSync");
153 dbus_error_init (&error);
154 if (spi_dbus_marshal_deviceEvent (message, key_event))
157 send_and_allow_reentry (spi_global_app_data->bus, message);
161 dbus_error_init (&error);
162 dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &consumed,
164 dbus_message_unref (reply);
167 dbus_message_unref (message);
172 spi_init_keystroke_from_atk_key_event (AtspiDeviceEvent * keystroke,
173 AtkKeyEventStruct * event)
175 keystroke->id = (dbus_int32_t) event->keyval;
176 keystroke->hw_code = (dbus_int16_t) event->keycode;
177 keystroke->timestamp = (dbus_uint32_t) event->timestamp;
178 keystroke->modifiers = (dbus_uint16_t) (event->state & 0xFFFF);
183 keystroke->event_string = g_strdup (event->string);
184 c = g_utf8_get_char_validated (event->string, -1);
185 if (c > 0 && g_unichar_isprint (c))
186 keystroke->is_text = TRUE;
188 keystroke->is_text = FALSE;
192 keystroke->event_string = g_strdup ("");
193 keystroke->is_text = FALSE;
197 case (ATK_KEY_EVENT_PRESS):
198 keystroke->type = ATSPI_KEY_PRESSED;
200 case (ATK_KEY_EVENT_RELEASE):
201 keystroke->type = ATSPI_KEY_RELEASED;
209 ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
210 (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
211 (int) keystroke->modifiers, keystroke->event_string,
212 (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
218 spi_atk_bridge_key_listener (AtkKeyEventStruct * event, gpointer data)
221 AtspiDeviceEvent key_event;
223 spi_init_keystroke_from_atk_key_event (&key_event, event);
226 Accessibility_DeviceEventController_NotifyListenersSync (&key_event);
228 if (key_event.event_string)
229 g_free (key_event.event_string);
234 /*---------------------------------------------------------------------------*/
237 convert_signal_name (const gchar * s)
239 gchar *ret = g_strdup (s);
244 ret[0] = toupper (ret[0]);
245 while ((t = strchr (ret, '-')) != NULL)
247 memmove (t, t + 1, strlen (t));
254 validate_for_dbus (const gint type,
259 case DBUS_TYPE_STRING:
260 case DBUS_TYPE_OBJECT_PATH:
263 else if (!g_utf8_validate (val, -1, NULL))
265 g_warning ("atk-bridge: Received bad UTF-8 string when emitting event");
276 append_basic (DBusMessageIter *iter,
282 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &sub);
284 val = validate_for_dbus ((int) *type, val);
285 dbus_message_iter_append_basic(&sub, (int) *type, &val);
287 dbus_message_iter_close_container(iter, &sub);
291 append_rect (DBusMessageIter *iter,
295 DBusMessageIter variant, sub;
296 const AtkRectangle *rect = (const AtkRectangle *) val;
298 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &variant);
300 dbus_message_iter_open_container (&variant, DBUS_TYPE_STRUCT, NULL, &sub);
302 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->x));
303 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->y));
304 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->width));
305 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->height));
307 dbus_message_iter_close_container (&variant, &sub);
309 dbus_message_iter_close_container(iter, &variant);
313 append_object (DBusMessageIter *iter,
317 spi_object_append_v_reference (iter, ATK_OBJECT (val));
321 signal_name_to_dbus (const gchar *s)
323 gchar *ret = g_strdup (s);
328 ret [0] = toupper (ret [0]);
329 while ((t = strchr (ret, '-')) != NULL)
331 memmove (t, t + 1, strlen (t));
338 * Converts names of the form "active-descendant-changed" to
339 * "ActiveDescendantChanged"
342 ensure_proper_format (const char *name)
344 gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
346 gboolean need_upper = TRUE;
354 *p++ = toupper (*name);
357 else if (*name == '-')
359 else if (*name == ':')
373 signal_is_needed (const gchar *klass, const gchar *major, const gchar *minor)
378 gboolean ret = FALSE;
381 if (!spi_global_app_data->events_initialized)
384 data [0] = ensure_proper_format (klass + 21);
385 data [1] = ensure_proper_format (major);
386 data [2] = ensure_proper_format (minor);
389 /* Hack: Always pass events that update the cache.
390 * TODO: FOr 2.2, have at-spi2-core define a special "cache listener" for
391 * this instead, so that we don't send these if no one is listening */
392 if (!g_strcmp0 (data [1], "ChildrenChanged") ||
393 !g_strcmp0 (data [1], "PropertyChange") ||
394 !g_strcmp0 (data [1], "StateChanged"))
402 /* Hack: events such as "object::text-changed::insert:system" as
403 generated by Gecko */
404 data [2][strcspn (data [2], ":")] = '\0';
405 for (list = spi_global_app_data->events; list; list = list->next)
408 if (spi_event_is_subtype (data, evdata->data))
416 g_print("event: %s %s %s: %d\n", data[0], data[1], data[2], ret);
425 * Emits an AT-SPI event.
426 * AT-SPI events names are split into three parts:
428 * This is mapped onto D-Bus events as:
429 * D-Bus Interface:Signal Name:Detail argument
431 * Marshals a basic type into the 'any_data' attribute of
435 emit_event (AtkObject *obj,
439 dbus_int32_t detail1,
440 dbus_int32_t detail2,
443 void (*append_variant) (DBusMessageIter *, const char *, const void *))
445 DBusConnection *bus = spi_global_app_data->bus;
450 DBusMessageIter iter, iter_struct;
452 if (!klass) klass = "";
453 if (!major) major = "";
454 if (!minor) minor = "";
455 if (!type) type = "u";
457 if (!signal_is_needed (klass, major, minor))
460 path = spi_register_object_to_path (spi_global_register, G_OBJECT (obj));
463 * This is very annoying, but as '-' isn't a legal signal
464 * name in D-Bus (Why not??!?) The names need converting
465 * on this side, and again on the client side.
467 cname = signal_name_to_dbus (major);
468 sig = dbus_message_new_signal(path, klass, cname);
470 dbus_message_iter_init_append(sig, &iter);
472 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
473 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
474 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
475 append_variant (&iter, type, val);
476 spi_object_append_reference (&iter, spi_global_app_data->root);
478 dbus_connection_send(bus, sig, NULL);
479 dbus_message_unref(sig);
481 if (g_strcmp0 (cname, "ChildrenChanged") != 0)
482 spi_object_lease_if_needed (G_OBJECT (obj));
488 /*---------------------------------------------------------------------------*/
491 * The focus listener handles the ATK 'focus' signal and forwards it
492 * as the AT-SPI event, 'focus:'
495 focus_tracker (AtkObject * accessible)
497 emit_event (accessible, ITF_EVENT_FOCUS, "focus", "", 0, 0,
498 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
501 /*---------------------------------------------------------------------------*/
503 #define PCHANGE "PropertyChange"
506 * This handler handles the following ATK signals and
507 * converts them to AT-SPI events:
509 * Gtk:AtkObject:property-change -> object:property-change:(property-name)
511 * The property-name is part of the ATK property-change signal.
514 property_event_listener (GSignalInvocationHint * signal_hint,
515 guint n_param_values,
516 const GValue * param_values, gpointer data)
518 AtkObject *accessible;
519 AtkPropertyValues *values;
521 const gchar *pname = NULL;
527 accessible = g_value_get_object (¶m_values[0]);
528 values = (AtkPropertyValues *) g_value_get_pointer (¶m_values[1]);
530 pname = values[0].property_name;
532 /* TODO Could improve this control statement by matching
533 * on only the end of the signal names,
535 if (strcmp (pname, "accessible-name") == 0)
537 s1 = atk_object_get_name (accessible);
539 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
540 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
542 else if (strcmp (pname, "accessible-description") == 0)
544 s1 = atk_object_get_description (accessible);
546 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
547 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
549 else if (strcmp (pname, "accessible-parent") == 0)
551 otemp = atk_object_get_parent (accessible);
553 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
554 "(so)", otemp, append_object);
556 else if (strcmp (pname, "accessible-role") == 0)
558 i = atk_object_get_role (accessible);
559 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
560 DBUS_TYPE_UINT32_AS_STRING, GINT_TO_POINTER(i), append_basic);
562 else if (strcmp (pname, "accessible-table-summary") == 0)
564 otemp = atk_table_get_summary (ATK_TABLE (accessible));
566 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
567 "(so)", otemp, append_object);
569 else if (strcmp (pname, "accessible-table-column-header") == 0)
571 i = g_value_get_int (&(values->new_value));
572 otemp = atk_table_get_column_header (ATK_TABLE (accessible), i);
574 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
575 "(so)", otemp, append_object);
577 else if (strcmp (pname, "accessible-table-row-header") == 0)
579 i = g_value_get_int (&(values->new_value));
580 otemp = atk_table_get_row_header (ATK_TABLE (accessible), i);
582 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
583 "(so)", otemp, append_object);
585 else if (strcmp (pname, "accessible-table-row-description") == 0)
587 i = g_value_get_int (&(values->new_value));
588 s1 = atk_table_get_row_description (ATK_TABLE (accessible), i);
589 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
590 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
592 else if (strcmp (pname, "accessible-table-column-description") == 0)
594 i = g_value_get_int (&(values->new_value));
595 s1 = atk_table_get_column_description (ATK_TABLE (accessible), i);
596 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
597 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
599 else if (strcmp (pname, "accessible-table-caption-object") == 0)
601 otemp = atk_table_get_caption (ATK_TABLE (accessible));
602 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
603 "(so)", otemp, append_object);
607 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
608 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
613 /*---------------------------------------------------------------------------*/
615 #define STATE_CHANGED "state-changed"
618 * The state event listener handles 'Gtk:AtkObject:state-change' ATK signals
619 * and forwards them as object:state-changed:(param-name) AT-SPI events. Where
620 * the param-name is part of the ATK state-change signal.
623 state_event_listener (GSignalInvocationHint * signal_hint,
624 guint n_param_values,
625 const GValue * param_values, gpointer data)
627 AtkObject *accessible;
631 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
632 pname = g_value_get_string (¶m_values[1]);
634 detail1 = (g_value_get_boolean (¶m_values[2])) ? 1 : 0;
635 emit_event (accessible, ITF_EVENT_OBJECT, STATE_CHANGED, pname, detail1, 0,
636 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
638 if (!g_strcmp0 (pname, "defunct"))
639 spi_register_deregister_object (spi_global_register, G_OBJECT (accessible),
644 /*---------------------------------------------------------------------------*/
647 * The window event listener handles the following ATK signals and forwards
648 * them as AT-SPI events:
650 * window:create -> window:create
651 * window:destroy -> window:destroy
652 * window:minimize -> window:minimize
653 * window:maximize -> window:maximize
654 * window:activate -> window:activate
655 * window:deactivate -> window:deactivate
658 window_event_listener (GSignalInvocationHint * signal_hint,
659 guint n_param_values,
660 const GValue * param_values, gpointer data)
662 AtkObject *accessible;
663 GSignalQuery signal_query;
664 const gchar *name, *s;
666 g_signal_query (signal_hint->signal_id, &signal_query);
667 name = signal_query.signal_name;
669 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
670 s = atk_object_get_name (accessible);
671 emit_event (accessible, ITF_EVENT_WINDOW, name, "", 0, 0,
672 DBUS_TYPE_STRING_AS_STRING, s, append_basic);
677 /*---------------------------------------------------------------------------*/
680 * The document event listener handles the following ATK signals
681 * and converts them to AT-SPI events:
683 * Gtk:AtkDocument:load-complete -> document:load-complete
684 * Gtk:AtkDocument:load-stopped -> document:load-stopped
685 * Gtk:AtkDocument:reload -> document:reload
688 document_event_listener (GSignalInvocationHint * signal_hint,
689 guint n_param_values,
690 const GValue * param_values, gpointer data)
692 AtkObject *accessible;
693 GSignalQuery signal_query;
694 const gchar *name, *s;
696 g_signal_query (signal_hint->signal_id, &signal_query);
697 name = signal_query.signal_name;
699 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
700 s = atk_object_get_name (accessible);
701 emit_event (accessible, ITF_EVENT_DOCUMENT, name, "", 0, 0,
702 DBUS_TYPE_STRING_AS_STRING, s, append_basic);
707 /*---------------------------------------------------------------------------*/
710 * Signal handler for "Gtk:AtkComponent:bounds-changed". Converts
711 * this to an AT-SPI event - "object:bounds-changed".
714 bounds_event_listener (GSignalInvocationHint * signal_hint,
715 guint n_param_values,
716 const GValue * param_values, gpointer data)
718 AtkObject *accessible;
719 AtkRectangle *atk_rect;
720 GSignalQuery signal_query;
721 const gchar *name, *s;
723 g_signal_query (signal_hint->signal_id, &signal_query);
724 name = signal_query.signal_name;
726 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
728 if (G_VALUE_HOLDS_BOXED (param_values + 1))
730 atk_rect = g_value_get_boxed (param_values + 1);
732 emit_event (accessible, ITF_EVENT_OBJECT, name, "", 0, 0,
733 "(iiii)", atk_rect, append_rect);
738 /*---------------------------------------------------------------------------*/
741 * Handles the ATK signal 'Gtk:AtkObject:active-descendant-changed' and
742 * converts it to the AT-SPI signal - 'object:active-descendant-changed'.
746 active_descendant_event_listener (GSignalInvocationHint * signal_hint,
747 guint n_param_values,
748 const GValue * param_values, gpointer data)
750 AtkObject *accessible;
752 GSignalQuery signal_query;
753 const gchar *name, *minor;
756 g_signal_query (signal_hint->signal_id, &signal_query);
757 name = signal_query.signal_name;
759 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
760 child = ATK_OBJECT (g_value_get_pointer (¶m_values[1]));
761 g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
762 minor = g_quark_to_string (signal_hint->detail);
764 detail1 = atk_object_get_index_in_parent (child);
766 emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, 0,
767 "(so)", child, append_object);
771 /*---------------------------------------------------------------------------*/
774 * Handles the ATK signal 'Gtk:AtkHypertext:link-selected' and
775 * converts it to the AT-SPI signal - 'object:link-selected'
779 link_selected_event_listener (GSignalInvocationHint * signal_hint,
780 guint n_param_values,
781 const GValue * param_values, gpointer data)
783 AtkObject *accessible;
784 GSignalQuery signal_query;
785 const gchar *name, *minor;
788 g_signal_query (signal_hint->signal_id, &signal_query);
789 name = signal_query.signal_name;
791 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
792 minor = g_quark_to_string (signal_hint->detail);
794 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
795 detail1 = g_value_get_int (¶m_values[1]);
797 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, 0,
798 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
802 /*---------------------------------------------------------------------------*/
805 * Handles the ATK signal 'Gtk:AtkText:text-changed' and
806 * converts it to the AT-SPI signal - 'object:text-changed'
807 * This signal is deprecated by Gtk:AtkText:text-insert
808 * and Gtk:AtkText:text-remove
812 text_changed_event_listener (GSignalInvocationHint * signal_hint,
813 guint n_param_values,
814 const GValue * param_values, gpointer data)
816 AtkObject *accessible;
817 GSignalQuery signal_query;
818 const gchar *name, *minor;
820 gint detail1 = 0, detail2 = 0;
822 g_signal_query (signal_hint->signal_id, &signal_query);
823 name = signal_query.signal_name;
825 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
826 minor = g_quark_to_string (signal_hint->detail);
828 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
829 detail1 = g_value_get_int (¶m_values[1]);
831 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
832 detail2 = g_value_get_int (¶m_values[2]);
835 atk_text_get_text (ATK_TEXT (accessible), detail1, detail1 + detail2);
837 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
838 DBUS_TYPE_STRING_AS_STRING, selected, append_basic);
845 * Handles the ATK signal 'Gtk:AtkText:text-insert' and
846 * converts it to the AT-SPI signal - 'object:text-changed'
850 text_insert_event_listener (GSignalInvocationHint * signal_hint,
851 guint n_param_values,
852 const GValue * param_values, gpointer data)
854 AtkObject *accessible;
855 guint text_changed_signal_id;
856 GSignalQuery signal_query;
859 gint detail1 = 0, detail2 = 0;
861 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
862 /* Get signal name for 'Gtk:AtkText:text-changed' so
863 * we convert it to the AT-SPI signal - 'object:text-changed'
865 text_changed_signal_id = g_signal_lookup ("text-changed", G_OBJECT_TYPE (accessible));
866 g_signal_query (text_changed_signal_id, &signal_query);
867 name = signal_query.signal_name;
870 /* Add the insert and keep any detail coming from atk */
871 minor = g_quark_to_string (signal_hint->detail);
873 minor = g_strconcat ("insert:", minor, NULL);
875 minor = g_strdup ("insert");
877 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
878 detail1 = g_value_get_int (¶m_values[1]);
880 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
881 detail2 = g_value_get_int (¶m_values[2]);
883 if (G_VALUE_TYPE (¶m_values[3]) == G_TYPE_STRING)
884 text = g_value_get_string (¶m_values[3]);
886 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
887 DBUS_TYPE_STRING_AS_STRING, text, append_basic);
893 * Handles the ATK signal 'Gtk:AtkText:text-remove' and
894 * converts it to the AT-SPI signal - 'object:text-changed'
898 text_remove_event_listener (GSignalInvocationHint * signal_hint,
899 guint n_param_values,
900 const GValue * param_values, gpointer data)
902 AtkObject *accessible;
903 guint text_changed_signal_id;
904 GSignalQuery signal_query;
907 gint detail1 = 0, detail2 = 0;
909 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
910 /* Get signal name for 'Gtk:AtkText:text-changed' so
911 * we convert it to the AT-SPI signal - 'object:text-changed'
913 text_changed_signal_id = g_signal_lookup ("text-changed", G_OBJECT_TYPE (accessible));
914 g_signal_query (text_changed_signal_id, &signal_query);
915 name = signal_query.signal_name;
917 minor = g_quark_to_string (signal_hint->detail);
919 /* Add the delete and keep any detail coming from atk */
920 minor = g_quark_to_string (signal_hint->detail);
922 minor = g_strconcat ("delete:", minor, NULL);
924 minor = g_strdup ("delete");
926 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
927 detail1 = g_value_get_int (¶m_values[1]);
929 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
930 detail2 = g_value_get_int (¶m_values[2]);
932 if (G_VALUE_TYPE (¶m_values[3]) == G_TYPE_STRING)
933 text = g_value_get_string (¶m_values[3]);
935 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
936 DBUS_TYPE_STRING_AS_STRING, text, append_basic);
942 /*---------------------------------------------------------------------------*/
945 * Handles the ATK signal 'Gtk:AtkText:text-selection-changed' and
946 * converts it to the AT-SPI signal - 'object:text-selection-changed'
950 text_selection_changed_event_listener (GSignalInvocationHint * signal_hint,
951 guint n_param_values,
952 const GValue * param_values,
955 AtkObject *accessible;
956 GSignalQuery signal_query;
957 const gchar *name, *minor;
958 gint detail1 = 0, detail2 = 0;
960 g_signal_query (signal_hint->signal_id, &signal_query);
961 name = signal_query.signal_name;
963 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
964 minor = g_quark_to_string (signal_hint->detail);
966 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
967 detail1 = g_value_get_int (¶m_values[1]);
969 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
970 detail2 = g_value_get_int (¶m_values[2]);
972 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
973 DBUS_TYPE_STRING_AS_STRING, "", append_basic);
977 /*---------------------------------------------------------------------------*/
980 * Children changed signal converter and forwarder.
982 * Klass (Interface) org.a11y.atspi.Event.Object
983 * Major is the signal name.
984 * Minor is 'add' or 'remove'
985 * detail1 is the index.
987 * any_data is the child reference.
990 children_changed_event_listener (GSignalInvocationHint * signal_hint,
991 guint n_param_values,
992 const GValue * param_values, gpointer data)
994 GSignalQuery signal_query;
995 const gchar *name, *minor;
996 gint detail1 = 0, detail2 = 0;
998 AtkObject *accessible, *ao=NULL;
1001 g_signal_query (signal_hint->signal_id, &signal_query);
1002 name = signal_query.signal_name;
1004 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
1005 minor = g_quark_to_string (signal_hint->detail);
1007 detail1 = g_value_get_uint (param_values + 1);
1008 child = g_value_get_pointer (param_values + 2);
1010 if (ATK_IS_OBJECT (child))
1012 ao = ATK_OBJECT (child);
1013 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1014 "(so)", ao, append_object);
1016 else if ((minor != NULL) && (strcmp (minor, "add") == 0))
1018 ao = atk_object_ref_accessible_child (accessible,
1020 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1021 "(so)", ao, append_object);
1025 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1026 "(so)", ao, append_object);
1032 /*---------------------------------------------------------------------------*/
1035 toplevel_added_event_listener (AtkObject * accessible,
1036 guint index, AtkObject * child)
1038 emit_event (accessible, ITF_EVENT_OBJECT, "children-changed", "add", index, 0,
1039 "(so)", child, append_object);
1043 toplevel_removed_event_listener (AtkObject * accessible,
1044 guint index, AtkObject * child)
1046 emit_event (accessible, ITF_EVENT_OBJECT, "children-changed", "remove", index, 0,
1047 "(so)", child, append_object);
1050 /*---------------------------------------------------------------------------*/
1053 * Generic signal converter and forwarder.
1055 * Klass (Interface) org.a11y.atspi.Event.Object
1056 * Major is the signal name.
1063 generic_event_listener (GSignalInvocationHint * signal_hint,
1064 guint n_param_values,
1065 const GValue * param_values, gpointer data)
1067 AtkObject *accessible;
1068 GSignalQuery signal_query;
1070 int detail1 = 0, detail2 = 0;
1072 g_signal_query (signal_hint->signal_id, &signal_query);
1073 name = signal_query.signal_name;
1075 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
1077 if (n_param_values > 1 && G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
1078 detail1 = g_value_get_int (¶m_values[1]);
1080 if (n_param_values > 2 && G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
1081 detail2 = g_value_get_int (¶m_values[2]);
1083 emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, detail2,
1084 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
1088 /*---------------------------------------------------------------------------*/
1091 * Registers the provided function as a handler for the given signal name
1092 * and stores the signal id returned so that the function may be
1093 * de-registered later.
1096 add_signal_listener (GSignalEmissionHook listener, const char *signal_name)
1100 id = atk_add_global_event_listener (listener, signal_name);
1102 if (id > 0) /* id == 0 is a failure */
1103 g_array_append_val (listener_ids, id);
1109 * Initialization for the signal handlers.
1111 * Registers all required signal handlers.
1114 spi_atk_register_event_listeners (void)
1117 * Kludge to make sure the Atk interface types are registered, otherwise
1118 * the AtkText signal handlers below won't get registered
1120 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
1121 AtkObject *bo = atk_no_op_object_new (ao);
1124 g_object_unref (G_OBJECT (bo));
1125 g_object_unref (ao);
1129 g_warning ("atk_bridge: spi_atk-register_event_listeners called multiple times");
1133 /* Register for focus event notifications, and register app with central registry */
1134 listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
1136 atk_bridge_focus_tracker_id = atk_add_focus_tracker (focus_tracker);
1138 add_signal_listener (property_event_listener,
1139 "Gtk:AtkObject:property-change");
1141 /* window events: we tentative try to register using the old format */
1142 id = add_signal_listener (window_event_listener, "window:create");
1146 /* If we are able to register using the old format, we assume
1147 * that the ATK implementor is managing window events without
1148 * AtkWindow. We can't use the opposite test because after
1149 * including AtkWindow on ATK you would be able to register to
1150 * that event, although the ATK implementor could or not use it.
1153 add_signal_listener (window_event_listener, "window:destroy");
1154 add_signal_listener (window_event_listener, "window:minimize");
1155 add_signal_listener (window_event_listener, "window:maximize");
1156 add_signal_listener (window_event_listener, "window:restore");
1157 add_signal_listener (window_event_listener, "window:activate");
1158 add_signal_listener (window_event_listener, "window:deactivate");
1162 add_signal_listener (window_event_listener, "Atk:AtkWindow:create");
1163 add_signal_listener (window_event_listener, "Atk:AtkWindow:destroy");
1164 add_signal_listener (window_event_listener, "Atk:AtkWindow:minimize");
1165 add_signal_listener (window_event_listener, "Atk:AtkWindow:maximize");
1166 add_signal_listener (window_event_listener, "Atk:AtkWindow:restore");
1167 add_signal_listener (window_event_listener, "Atk:AtkWindow:activate");
1168 add_signal_listener (window_event_listener, "Atk:AtkWindow:deactivate");
1171 add_signal_listener (document_event_listener,
1172 "Gtk:AtkDocument:load-complete");
1173 add_signal_listener (document_event_listener, "Gtk:AtkDocument:reload");
1174 add_signal_listener (document_event_listener,
1175 "Gtk:AtkDocument:load-stopped");
1176 /* TODO Fake this event on the client side */
1177 add_signal_listener (state_event_listener, "Gtk:AtkObject:state-change");
1179 add_signal_listener (active_descendant_event_listener,
1180 "Gtk:AtkObject:active-descendant-changed");
1181 add_signal_listener (bounds_event_listener,
1182 "Gtk:AtkComponent:bounds-changed");
1183 add_signal_listener (text_selection_changed_event_listener,
1184 "Gtk:AtkText:text-selection-changed");
1185 add_signal_listener (text_changed_event_listener,
1186 "Gtk:AtkText:text-changed");
1187 add_signal_listener (text_insert_event_listener,
1188 "Gtk:AtkText:text-insert");
1189 add_signal_listener (text_remove_event_listener,
1190 "Gtk:AtkText:text-remove");
1191 add_signal_listener (link_selected_event_listener,
1192 "Gtk:AtkHypertext:link-selected");
1193 add_signal_listener (generic_event_listener,
1194 "Gtk:AtkObject:visible-data-changed");
1195 add_signal_listener (generic_event_listener,
1196 "Gtk:AtkSelection:selection-changed");
1197 add_signal_listener (generic_event_listener,
1198 "Gtk:AtkText:text-attributes-changed");
1199 add_signal_listener (generic_event_listener,
1200 "Gtk:AtkText:text-caret-moved");
1201 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-inserted");
1202 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-reordered");
1203 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-deleted");
1204 add_signal_listener (generic_event_listener,
1205 "Gtk:AtkTable:column-inserted");
1206 add_signal_listener (generic_event_listener,
1207 "Gtk:AtkTable:column-reordered");
1208 add_signal_listener (generic_event_listener, "Gtk:AtkTable:column-deleted");
1209 add_signal_listener (generic_event_listener, "Gtk:AtkTable:model-changed");
1210 add_signal_listener (children_changed_event_listener, "Gtk:AtkObject:children-changed");
1213 g_signal_connect (G_OBJECT (spi_global_app_data->root),
1214 "children-changed::add",
1215 (GCallback) toplevel_added_event_listener, NULL);
1217 g_signal_connect (G_OBJECT (spi_global_app_data->root),
1218 "children-changed::remove",
1219 (GCallback) toplevel_removed_event_listener, NULL);
1223 * May add the following listeners to implement preemptive key listening for GTK+
1225 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
1226 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
1228 atk_bridge_key_event_listener_id =
1229 atk_add_key_event_listener (spi_atk_bridge_key_listener, NULL);
1232 /*---------------------------------------------------------------------------*/
1235 * De-registers all ATK signal handlers.
1238 spi_atk_deregister_event_listeners (void)
1241 GArray *ids = listener_ids;
1242 listener_ids = NULL;
1244 if (atk_bridge_focus_tracker_id)
1246 atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
1247 atk_bridge_focus_tracker_id = 0;
1252 for (i = 0; i < ids->len; i++)
1254 atk_remove_global_event_listener (g_array_index (ids, guint, i));
1256 g_array_free (ids, TRUE);
1259 if (atk_bridge_key_event_listener_id)
1261 atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
1262 atk_bridge_key_event_listener_id = 0;
1266 /*---------------------------------------------------------------------------*/
1269 * TODO This function seems out of place here.
1271 * Emits fake deactivate signals on all top-level windows.
1272 * Used when shutting down AT-SPI, ensuring that all
1273 * windows have been removed on the client side.
1276 spi_atk_tidy_windows (void)
1282 root = atk_get_root ();
1283 n_children = atk_object_get_n_accessible_children (root);
1284 for (i = 0; i < n_children; i++)
1287 AtkStateSet *stateset;
1290 child = atk_object_ref_accessible_child (root, i);
1291 stateset = atk_object_ref_state_set (child);
1293 name = atk_object_get_name (child);
1294 if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
1296 emit_event (child, ITF_EVENT_WINDOW, "deactivate", NULL, 0, 0,
1297 DBUS_TYPE_STRING_AS_STRING, name, append_basic);
1299 g_object_unref (stateset);
1301 emit_event (child, ITF_EVENT_WINDOW, "destroy", NULL, 0, 0,
1302 DBUS_TYPE_STRING_AS_STRING, name, append_basic);
1303 g_object_unref (child);
1308 spi_event_is_subtype (gchar **needle, gchar **haystack)
1310 while (*haystack && **haystack)
1312 if (g_strcmp0 (*needle, *haystack))
1320 /*END------------------------------------------------------------------------*/