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)
67 if (spi_global_app_data->server)
68 atspi_dbus_server_setup_with_g_main (spi_global_app_data->server, cnx);
69 atspi_dbus_connection_setup_with_g_main (spi_global_app_data->bus, cnx);
70 atspi_set_main_context (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 switch_main_context (NULL);
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;
105 closure.loop = g_main_loop_new (spi_global_app_data->main_context, FALSE);
106 closure.reply = NULL;
107 switch_main_context (spi_global_app_data->main_context);
109 if (!dbus_connection_send_with_reply (bus, message, &pending, 9000) || !pending)
111 switch_main_context (NULL);
114 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
115 source = g_timeout_source_new (500);
116 g_source_set_callback (source, timeout_reply, &closure, NULL);
117 closure.timeout = g_source_attach (source, spi_global_app_data->main_context);
118 g_source_unref (source);
119 g_main_loop_run (closure.loop);
120 if (closure.timeout != -1)
121 g_source_destroy (source);
123 g_main_loop_unref (closure.loop);
125 dbus_pending_call_cancel (pending);
126 return closure.reply;
129 /*---------------------------------------------------------------------------*/
132 * Functionality related to sending device events from the application.
134 * This is used for forwarding key events on to the registry daemon.
138 Accessibility_DeviceEventController_NotifyListenersSync (const
142 DBusMessage *message;
143 dbus_bool_t consumed = FALSE;
146 dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
148 ATSPI_DBUS_INTERFACE_DEC,
149 "NotifyListenersSync");
151 if (spi_dbus_marshal_deviceEvent (message, key_event))
154 send_and_allow_reentry (spi_global_app_data->bus, message);
158 dbus_error_init (&error);
159 if (!dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN,
160 &consumed, DBUS_TYPE_INVALID))
162 /* TODO: print a warning */
163 dbus_error_free (&error);
165 dbus_message_unref (reply);
168 dbus_message_unref (message);
173 spi_init_keystroke_from_atk_key_event (AtspiDeviceEvent * keystroke,
174 AtkKeyEventStruct * event)
176 keystroke->id = (dbus_int32_t) event->keyval;
177 keystroke->hw_code = (dbus_int16_t) event->keycode;
178 keystroke->timestamp = (dbus_uint32_t) event->timestamp;
179 keystroke->modifiers = (dbus_uint16_t) (event->state & 0xFFFF);
184 keystroke->event_string = g_strdup (event->string);
185 c = g_utf8_get_char_validated (event->string, -1);
186 if (c > 0 && g_unichar_isprint (c))
187 keystroke->is_text = TRUE;
189 keystroke->is_text = FALSE;
193 keystroke->event_string = g_strdup ("");
194 keystroke->is_text = FALSE;
198 case (ATK_KEY_EVENT_PRESS):
199 keystroke->type = ATSPI_KEY_PRESSED;
201 case (ATK_KEY_EVENT_RELEASE):
202 keystroke->type = ATSPI_KEY_RELEASED;
210 ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
211 (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
212 (int) keystroke->modifiers, keystroke->event_string,
213 (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
219 spi_atk_bridge_key_listener (AtkKeyEventStruct * event, gpointer data)
222 AtspiDeviceEvent key_event;
224 spi_init_keystroke_from_atk_key_event (&key_event, event);
227 Accessibility_DeviceEventController_NotifyListenersSync (&key_event);
229 if (key_event.event_string)
230 g_free (key_event.event_string);
235 /*---------------------------------------------------------------------------*/
238 validate_for_dbus (const gint type,
243 case DBUS_TYPE_STRING:
244 case DBUS_TYPE_OBJECT_PATH:
247 else if (!g_utf8_validate (val, -1, NULL))
249 g_warning ("atk-bridge: Received bad UTF-8 string when emitting event");
260 append_basic (DBusMessageIter *iter,
266 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &sub);
268 val = validate_for_dbus ((int) *type, val);
269 dbus_message_iter_append_basic(&sub, (int) *type, &val);
271 dbus_message_iter_close_container(iter, &sub);
275 append_rect (DBusMessageIter *iter,
279 DBusMessageIter variant, sub;
280 const AtkRectangle *rect = (const AtkRectangle *) val;
282 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &variant);
284 dbus_message_iter_open_container (&variant, DBUS_TYPE_STRUCT, NULL, &sub);
286 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->x));
287 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->y));
288 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->width));
289 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->height));
291 dbus_message_iter_close_container (&variant, &sub);
293 dbus_message_iter_close_container(iter, &variant);
297 append_object (DBusMessageIter *iter,
301 spi_object_append_v_reference (iter, ATK_OBJECT (val));
305 signal_name_to_dbus (const gchar *s)
307 gchar *ret = g_strdup (s);
312 ret [0] = toupper (ret [0]);
313 while ((t = strchr (ret, '-')) != NULL)
315 memmove (t, t + 1, strlen (t));
322 * Converts names of the form "active-descendant-changed" to
323 * "ActiveDescendantChanged"
326 ensure_proper_format (const char *name)
328 gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
330 gboolean need_upper = TRUE;
338 *p++ = toupper (*name);
341 else if (*name == '-')
343 else if (*name == ':')
357 append_properties (GArray *properties, event_data *evdata)
362 for (ls = evdata->properties; ls; ls = ls->next)
364 gboolean dup = FALSE;
365 for (i = 0; i < properties->len; i++)
367 if (ls->data == g_array_index (properties, AtspiPropertyDefinition *, i))
374 g_array_append_val (properties, ls->data);
379 signal_is_needed (AtkObject *obj, const gchar *klass, const gchar *major,
380 const gchar *minor, GArray **properties)
384 gboolean ret = FALSE;
386 GArray *props = NULL;
388 if (!spi_global_app_data->events_initialized)
391 data [0] = ensure_proper_format (klass + 21);
392 data [1] = ensure_proper_format (major);
393 data [2] = ensure_proper_format (minor);
396 /* Hack: Always pass events that update the cache.
397 * TODO: FOr 2.2, have at-spi2-core define a special "cache listener" for
398 * this instead, so that we don't send these if no one is listening */
399 if (!g_strcmp0 (data [1], "ChildrenChanged") ||
400 ((!g_strcmp0 (data [1], "PropertyChange")) &&
401 (!g_strcmp0 (data [2], "accessible-name") ||
402 !g_strcmp0 (data [2], "accessible-description") ||
403 !g_strcmp0 (data [2], "accessible-parent") ||
404 !g_strcmp0 (data [2], "accessible-role"))) ||
405 !g_strcmp0 (data [1], "StateChanged"))
407 if (minor && !g_strcmp0 (minor, "defunct"))
411 AtkStateSet *set = atk_object_ref_state_set (obj);
412 AtkState state = ((!g_strcmp0 (data[1], "ChildrenChanged")) ?
413 ATK_STATE_MANAGES_DESCENDANTS : ATK_STATE_TRANSIENT);
414 ret = !atk_state_set_contains_state (set, state);
415 g_object_unref (set);
419 /* Hack: events such as "object::text-changed::insert:system" as
420 generated by Gecko */
421 data [2][strcspn (data [2], ":")] = '\0';
423 for (list = spi_global_app_data->events; list; list = list->next)
426 if (spi_event_is_subtype (data, evdata->data))
430 props = g_array_new (TRUE, TRUE, sizeof (AtspiPropertyDefinition *));
431 append_properties (props, evdata);
442 /* Convert a : to a / so that listeners can use arg0path to match only
445 adapt_minor_for_dbus (const char *source)
447 gchar *ret = g_strdup (source);
448 int i = strcspn (ret, ":");
455 open_variant (DBusMessageIter *iter, const char *name, const char *type,
456 DBusMessageIter *out)
458 dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &name);
459 dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, type, out);
463 * Emits an AT-SPI event.
464 * AT-SPI events names are split into three parts:
466 * This is mapped onto D-Bus events as:
467 * D-Bus Interface:Signal Name:Detail argument
469 * Marshals a basic type into the 'any_data' attribute of
473 emit_event (AtkObject *obj,
477 dbus_int32_t detail1,
478 dbus_int32_t detail2,
481 void (*append_variant) (DBusMessageIter *, const char *, const void *))
483 DBusConnection *bus = spi_global_app_data->bus;
489 DBusMessageIter iter, iter_dict, iter_dict_entry, iter_variant, iter_array;
490 GArray *properties = NULL;
492 if (!klass) klass = "";
493 if (!major) major = "";
494 if (!minor) minor = "";
495 if (!type) type = "u";
497 if (!signal_is_needed (obj, klass, major, minor, &properties))
500 path = spi_register_object_to_path (spi_global_register, G_OBJECT (obj));
501 g_return_if_fail (path != NULL);
504 * This is very annoying, but as '-' isn't a legal signal
505 * name in D-Bus (Why not??!?) The names need converting
506 * on this side, and again on the client side.
508 cname = signal_name_to_dbus (major);
509 sig = dbus_message_new_signal(path, klass, cname);
511 dbus_message_iter_init_append(sig, &iter);
513 minor_dbus = adapt_minor_for_dbus (minor);
514 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor_dbus);
516 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
517 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
518 append_variant (&iter, type, val);
520 dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{sv}", &iter_dict);
521 /* Add requested properties, unless the object is being marked defunct, in
522 which case it's safest not to touch it */
523 if (minor == NULL || strcmp (minor, "defunct") != 0 || detail1 == 0)
528 for (i = 0; i < properties->len; i++)
530 AtspiPropertyDefinition *prop = g_array_index (properties, AtspiPropertyDefinition *, i);
531 dbus_message_iter_open_container (&iter_dict, DBUS_TYPE_DICT_ENTRY, NULL,
533 dbus_message_iter_append_basic (&iter_dict_entry, DBUS_TYPE_STRING, &prop->name);
534 prop->func (&iter_dict_entry, obj);
535 dbus_message_iter_close_container (&iter_dict, &iter_dict_entry);
537 g_array_free (properties, TRUE);
540 dbus_message_iter_close_container (&iter, &iter_dict);
542 dbus_connection_send(bus, sig, NULL);
543 dbus_message_unref(sig);
545 if (g_strcmp0 (cname, "ChildrenChanged") != 0)
546 spi_object_lease_if_needed (G_OBJECT (obj));
552 /*---------------------------------------------------------------------------*/
555 * The focus listener handles the ATK 'focus' signal and forwards it
556 * as the AT-SPI event, 'focus:'
559 focus_tracker (AtkObject * accessible)
561 emit_event (accessible, ITF_EVENT_FOCUS, "focus", "", 0, 0,
562 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
565 /*---------------------------------------------------------------------------*/
567 #define PCHANGE "PropertyChange"
570 * This handler handles the following ATK signals and
571 * converts them to AT-SPI events:
573 * Gtk:AtkObject:property-change -> object:property-change:(property-name)
575 * The property-name is part of the ATK property-change signal.
578 property_event_listener (GSignalInvocationHint * signal_hint,
579 guint n_param_values,
580 const GValue * param_values, gpointer data)
582 AtkObject *accessible;
583 AtkPropertyValues *values;
585 const gchar *pname = NULL;
591 accessible = g_value_get_object (¶m_values[0]);
592 values = (AtkPropertyValues *) g_value_get_pointer (¶m_values[1]);
594 pname = values[0].property_name;
596 /* TODO Could improve this control statement by matching
597 * on only the end of the signal names,
599 if (strcmp (pname, "accessible-name") == 0)
601 s1 = atk_object_get_name (accessible);
603 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
604 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
606 else if (strcmp (pname, "accessible-description") == 0)
608 s1 = atk_object_get_description (accessible);
610 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
611 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
613 else if (strcmp (pname, "accessible-parent") == 0)
615 otemp = atk_object_get_parent (accessible);
617 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
618 "(so)", otemp, append_object);
620 else if (strcmp (pname, "accessible-role") == 0)
622 i = atk_object_get_role (accessible);
623 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
624 DBUS_TYPE_UINT32_AS_STRING, GINT_TO_POINTER(i), append_basic);
626 else if (strcmp (pname, "accessible-table-summary") == 0)
628 otemp = atk_table_get_summary (ATK_TABLE (accessible));
630 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
631 "(so)", otemp, append_object);
633 else if (strcmp (pname, "accessible-table-column-header") == 0)
635 i = g_value_get_int (&(values->new_value));
636 otemp = atk_table_get_column_header (ATK_TABLE (accessible), i);
638 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
639 "(so)", otemp, append_object);
641 else if (strcmp (pname, "accessible-table-row-header") == 0)
643 i = g_value_get_int (&(values->new_value));
644 otemp = atk_table_get_row_header (ATK_TABLE (accessible), i);
646 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
647 "(so)", otemp, append_object);
649 else if (strcmp (pname, "accessible-table-row-description") == 0)
651 i = g_value_get_int (&(values->new_value));
652 s1 = atk_table_get_row_description (ATK_TABLE (accessible), i);
653 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
654 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
656 else if (strcmp (pname, "accessible-table-column-description") == 0)
658 i = g_value_get_int (&(values->new_value));
659 s1 = atk_table_get_column_description (ATK_TABLE (accessible), i);
660 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
661 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
663 else if (strcmp (pname, "accessible-table-caption-object") == 0)
665 otemp = atk_table_get_caption (ATK_TABLE (accessible));
666 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
667 "(so)", otemp, append_object);
671 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
672 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
677 /*---------------------------------------------------------------------------*/
679 #define STATE_CHANGED "state-changed"
682 * The state event listener handles 'Gtk:AtkObject:state-change' ATK signals
683 * and forwards them as object:state-changed:(param-name) AT-SPI events. Where
684 * the param-name is part of the ATK state-change signal.
687 state_event_listener (GSignalInvocationHint * signal_hint,
688 guint n_param_values,
689 const GValue * param_values, gpointer data)
691 AtkObject *accessible;
695 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
696 pname = g_value_get_string (¶m_values[1]);
698 detail1 = (g_value_get_boolean (¶m_values[2])) ? 1 : 0;
699 emit_event (accessible, ITF_EVENT_OBJECT, STATE_CHANGED, pname, detail1, 0,
700 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
702 if (!g_strcmp0 (pname, "defunct") && detail1)
703 spi_register_deregister_object (spi_global_register, G_OBJECT (accessible),
708 /*---------------------------------------------------------------------------*/
711 * The window event listener handles the following ATK signals and forwards
712 * them as AT-SPI events:
714 * window:create -> window:create
715 * window:destroy -> window:destroy
716 * window:minimize -> window:minimize
717 * window:maximize -> window:maximize
718 * window:activate -> window:activate
719 * window:deactivate -> window:deactivate
722 window_event_listener (GSignalInvocationHint * signal_hint,
723 guint n_param_values,
724 const GValue * param_values, gpointer data)
726 AtkObject *accessible;
727 GSignalQuery signal_query;
728 const gchar *name, *s;
730 g_signal_query (signal_hint->signal_id, &signal_query);
731 name = signal_query.signal_name;
733 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
734 s = atk_object_get_name (accessible);
735 emit_event (accessible, ITF_EVENT_WINDOW, name, "", 0, 0,
736 DBUS_TYPE_STRING_AS_STRING, s, append_basic);
741 /*---------------------------------------------------------------------------*/
744 * The document event listener handles the following ATK signals
745 * and converts them to AT-SPI events:
747 * Gtk:AtkDocument:load-complete -> document:load-complete
748 * Gtk:AtkDocument:load-stopped -> document:load-stopped
749 * Gtk:AtkDocument:reload -> document:reload
750 * Gtk:AtkDocument:page-changed -> document:page-changed
753 document_event_listener (GSignalInvocationHint * signal_hint,
754 guint n_param_values,
755 const GValue * param_values, gpointer data)
757 AtkObject *accessible;
758 GSignalQuery signal_query;
759 const gchar *name, *s;
762 g_signal_query (signal_hint->signal_id, &signal_query);
763 name = signal_query.signal_name;
765 if (n_param_values > 0) // on the case of page-changed
766 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
767 detail1 = g_value_get_int (¶m_values[1]);
769 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
770 s = atk_object_get_name (accessible);
771 emit_event (accessible, ITF_EVENT_DOCUMENT, name, "", detail1, 0,
772 DBUS_TYPE_STRING_AS_STRING, s, append_basic);
777 /*---------------------------------------------------------------------------*/
780 * Signal handler for "Gtk:AtkComponent:bounds-changed". Converts
781 * this to an AT-SPI event - "object:bounds-changed".
784 bounds_event_listener (GSignalInvocationHint * signal_hint,
785 guint n_param_values,
786 const GValue * param_values, gpointer data)
788 AtkObject *accessible;
789 AtkRectangle *atk_rect;
790 GSignalQuery signal_query;
793 g_signal_query (signal_hint->signal_id, &signal_query);
794 name = signal_query.signal_name;
796 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
798 if (G_VALUE_HOLDS_BOXED (param_values + 1))
800 atk_rect = g_value_get_boxed (param_values + 1);
802 emit_event (accessible, ITF_EVENT_OBJECT, name, "", 0, 0,
803 "(iiii)", atk_rect, append_rect);
808 /*---------------------------------------------------------------------------*/
811 * Handles the ATK signal 'Gtk:AtkObject:active-descendant-changed' and
812 * converts it to the AT-SPI signal - 'object:active-descendant-changed'.
816 active_descendant_event_listener (GSignalInvocationHint * signal_hint,
817 guint n_param_values,
818 const GValue * param_values, gpointer data)
820 AtkObject *accessible;
822 GSignalQuery signal_query;
826 g_signal_query (signal_hint->signal_id, &signal_query);
827 name = signal_query.signal_name;
829 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
830 child = ATK_OBJECT (g_value_get_pointer (¶m_values[1]));
831 g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
833 detail1 = atk_object_get_index_in_parent (child);
835 emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, 0,
836 "(so)", child, append_object);
840 /*---------------------------------------------------------------------------*/
843 * Handles the ATK signal 'Gtk:AtkHypertext:link-selected' and
844 * converts it to the AT-SPI signal - 'object:link-selected'
848 link_selected_event_listener (GSignalInvocationHint * signal_hint,
849 guint n_param_values,
850 const GValue * param_values, gpointer data)
852 AtkObject *accessible;
853 GSignalQuery signal_query;
854 const gchar *name, *minor;
857 g_signal_query (signal_hint->signal_id, &signal_query);
858 name = signal_query.signal_name;
860 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
861 minor = g_quark_to_string (signal_hint->detail);
863 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
864 detail1 = g_value_get_int (¶m_values[1]);
866 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, 0,
867 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
871 /*---------------------------------------------------------------------------*/
874 * Handles the ATK signal 'Gtk:AtkText:text-changed' and
875 * converts it to the AT-SPI signal - 'object:text-changed'
876 * This signal is deprecated by Gtk:AtkText:text-insert
877 * and Gtk:AtkText:text-remove
881 text_changed_event_listener (GSignalInvocationHint * signal_hint,
882 guint n_param_values,
883 const GValue * param_values, gpointer data)
885 AtkObject *accessible;
886 GSignalQuery signal_query;
887 const gchar *name, *minor;
889 gint detail1 = 0, detail2 = 0;
891 g_signal_query (signal_hint->signal_id, &signal_query);
892 name = signal_query.signal_name;
894 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
895 minor = g_quark_to_string (signal_hint->detail);
897 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
898 detail1 = g_value_get_int (¶m_values[1]);
900 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
901 detail2 = g_value_get_int (¶m_values[2]);
904 atk_text_get_text (ATK_TEXT (accessible), detail1, detail1 + detail2);
906 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
907 DBUS_TYPE_STRING_AS_STRING, selected, append_basic);
914 * Handles the ATK signal 'Gtk:AtkText:text-insert' and
915 * converts it to the AT-SPI signal - 'object:text-changed'
919 text_insert_event_listener (GSignalInvocationHint * signal_hint,
920 guint n_param_values,
921 const GValue * param_values, gpointer data)
923 AtkObject *accessible;
924 guint text_changed_signal_id;
925 GSignalQuery signal_query;
927 const gchar *minor_raw, *text;
929 gint detail1 = 0, detail2 = 0;
931 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
932 /* Get signal name for 'Gtk:AtkText:text-changed' so
933 * we convert it to the AT-SPI signal - 'object:text-changed'
935 text_changed_signal_id = g_signal_lookup ("text-changed", G_OBJECT_TYPE (accessible));
936 g_signal_query (text_changed_signal_id, &signal_query);
937 name = signal_query.signal_name;
940 /* Add the insert and keep any detail coming from atk */
941 minor_raw = g_quark_to_string (signal_hint->detail);
943 minor = g_strconcat ("insert:", minor_raw, NULL);
945 minor = g_strdup ("insert");
947 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
948 detail1 = g_value_get_int (¶m_values[1]);
950 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
951 detail2 = g_value_get_int (¶m_values[2]);
953 if (G_VALUE_TYPE (¶m_values[3]) == G_TYPE_STRING)
954 text = g_value_get_string (¶m_values[3]);
956 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
957 DBUS_TYPE_STRING_AS_STRING, text, append_basic);
963 * Handles the ATK signal 'Gtk:AtkText:text-remove' and
964 * converts it to the AT-SPI signal - 'object:text-changed'
968 text_remove_event_listener (GSignalInvocationHint * signal_hint,
969 guint n_param_values,
970 const GValue * param_values, gpointer data)
972 AtkObject *accessible;
973 guint text_changed_signal_id;
974 GSignalQuery signal_query;
976 const gchar *minor_raw, *text;
978 gint detail1 = 0, detail2 = 0;
980 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
981 /* Get signal name for 'Gtk:AtkText:text-changed' so
982 * we convert it to the AT-SPI signal - 'object:text-changed'
984 text_changed_signal_id = g_signal_lookup ("text-changed", G_OBJECT_TYPE (accessible));
985 g_signal_query (text_changed_signal_id, &signal_query);
986 name = signal_query.signal_name;
988 minor_raw = g_quark_to_string (signal_hint->detail);
990 /* Add the delete and keep any detail coming from atk */
992 minor = g_strconcat ("delete:", minor_raw, NULL);
994 minor = g_strdup ("delete");
996 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
997 detail1 = g_value_get_int (¶m_values[1]);
999 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
1000 detail2 = g_value_get_int (¶m_values[2]);
1002 if (G_VALUE_TYPE (¶m_values[3]) == G_TYPE_STRING)
1003 text = g_value_get_string (¶m_values[3]);
1005 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1006 DBUS_TYPE_STRING_AS_STRING, text, append_basic);
1012 /*---------------------------------------------------------------------------*/
1015 * Handles the ATK signal 'Gtk:AtkText:text-selection-changed' and
1016 * converts it to the AT-SPI signal - 'object:text-selection-changed'
1020 text_selection_changed_event_listener (GSignalInvocationHint * signal_hint,
1021 guint n_param_values,
1022 const GValue * param_values,
1025 AtkObject *accessible;
1026 GSignalQuery signal_query;
1027 const gchar *name, *minor;
1028 gint detail1 = 0, detail2 = 0;
1030 g_signal_query (signal_hint->signal_id, &signal_query);
1031 name = signal_query.signal_name;
1033 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
1034 minor = g_quark_to_string (signal_hint->detail);
1036 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
1037 detail1 = g_value_get_int (¶m_values[1]);
1039 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
1040 detail2 = g_value_get_int (¶m_values[2]);
1042 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1043 DBUS_TYPE_STRING_AS_STRING, "", append_basic);
1047 /*---------------------------------------------------------------------------*/
1050 * Children changed signal converter and forwarder.
1052 * Klass (Interface) org.a11y.atspi.Event.Object
1053 * Major is the signal name.
1054 * Minor is 'add' or 'remove'
1055 * detail1 is the index.
1057 * any_data is the child reference.
1060 children_changed_event_listener (GSignalInvocationHint * signal_hint,
1061 guint n_param_values,
1062 const GValue * param_values, gpointer data)
1064 GSignalQuery signal_query;
1065 const gchar *name, *minor;
1066 gint detail1 = 0, detail2 = 0;
1068 AtkObject *accessible, *ao=NULL;
1071 g_signal_query (signal_hint->signal_id, &signal_query);
1072 name = signal_query.signal_name;
1074 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
1075 minor = g_quark_to_string (signal_hint->detail);
1077 detail1 = g_value_get_uint (param_values + 1);
1078 child = g_value_get_pointer (param_values + 2);
1080 if (ATK_IS_OBJECT (child))
1082 ao = ATK_OBJECT (child);
1083 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1084 "(so)", ao, append_object);
1086 else if ((minor != NULL) && (strcmp (minor, "add") == 0))
1088 ao = atk_object_ref_accessible_child (accessible,
1090 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1091 "(so)", ao, append_object);
1092 g_object_unref (ao);
1096 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
1097 "(so)", ao, append_object);
1103 /*---------------------------------------------------------------------------*/
1106 * Generic signal converter and forwarder.
1108 * Klass (Interface) org.a11y.atspi.Event.Object
1109 * Major is the signal name.
1116 generic_event_listener (GSignalInvocationHint * signal_hint,
1117 guint n_param_values,
1118 const GValue * param_values, gpointer data)
1120 AtkObject *accessible;
1121 GSignalQuery signal_query;
1123 int detail1 = 0, detail2 = 0;
1125 g_signal_query (signal_hint->signal_id, &signal_query);
1126 name = signal_query.signal_name;
1128 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
1130 if (n_param_values > 1 && G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
1131 detail1 = g_value_get_int (¶m_values[1]);
1133 if (n_param_values > 2 && G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
1134 detail2 = g_value_get_int (¶m_values[2]);
1136 emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, detail2,
1137 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
1141 /*---------------------------------------------------------------------------*/
1144 * Registers the provided function as a handler for the given signal name
1145 * and stores the signal id returned so that the function may be
1146 * de-registered later.
1149 add_signal_listener (GSignalEmissionHook listener, const char *signal_name)
1153 id = atk_add_global_event_listener (listener, signal_name);
1155 if (id > 0) /* id == 0 is a failure */
1156 g_array_append_val (listener_ids, id);
1162 * Initialization for the signal handlers.
1164 * Registers all required signal handlers.
1167 spi_atk_register_event_listeners (void)
1170 * Kludge to make sure the Atk interface types are registered, otherwise
1171 * the AtkText signal handlers below won't get registered
1173 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
1174 AtkObject *bo = atk_no_op_object_new (ao);
1177 g_object_unref (G_OBJECT (bo));
1178 g_object_unref (ao);
1182 g_warning ("atk_bridge: spi_atk-register_event_listeners called multiple times");
1186 /* Register for focus event notifications, and register app with central registry */
1187 listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
1189 atk_bridge_focus_tracker_id = atk_add_focus_tracker (focus_tracker);
1191 add_signal_listener (property_event_listener,
1192 "Gtk:AtkObject:property-change");
1194 /* window events: we tentative try to register using the old format */
1195 id = add_signal_listener (window_event_listener, "window:create");
1199 /* If we are able to register using the old format, we assume
1200 * that the ATK implementor is managing window events without
1201 * AtkWindow. We can't use the opposite test because after
1202 * including AtkWindow on ATK you would be able to register to
1203 * that event, although the ATK implementor could or not use it.
1206 add_signal_listener (window_event_listener, "window:destroy");
1207 add_signal_listener (window_event_listener, "window:minimize");
1208 add_signal_listener (window_event_listener, "window:maximize");
1209 add_signal_listener (window_event_listener, "window:restore");
1210 add_signal_listener (window_event_listener, "window:activate");
1211 add_signal_listener (window_event_listener, "window:deactivate");
1215 add_signal_listener (window_event_listener, "Atk:AtkWindow:create");
1216 add_signal_listener (window_event_listener, "Atk:AtkWindow:destroy");
1217 add_signal_listener (window_event_listener, "Atk:AtkWindow:minimize");
1218 add_signal_listener (window_event_listener, "Atk:AtkWindow:maximize");
1219 add_signal_listener (window_event_listener, "Atk:AtkWindow:restore");
1220 add_signal_listener (window_event_listener, "Atk:AtkWindow:activate");
1221 add_signal_listener (window_event_listener, "Atk:AtkWindow:deactivate");
1224 add_signal_listener (document_event_listener,
1225 "Gtk:AtkDocument:load-complete");
1226 add_signal_listener (document_event_listener, "Gtk:AtkDocument:reload");
1227 add_signal_listener (document_event_listener,
1228 "Gtk:AtkDocument:load-stopped");
1229 add_signal_listener (document_event_listener,
1230 "Gtk:AtkDocument:page-changed");
1231 /* TODO Fake this event on the client side */
1232 add_signal_listener (state_event_listener, "Gtk:AtkObject:state-change");
1234 add_signal_listener (active_descendant_event_listener,
1235 "Gtk:AtkObject:active-descendant-changed");
1236 add_signal_listener (bounds_event_listener,
1237 "Gtk:AtkComponent:bounds-changed");
1238 add_signal_listener (text_selection_changed_event_listener,
1239 "Gtk:AtkText:text-selection-changed");
1240 add_signal_listener (text_changed_event_listener,
1241 "Gtk:AtkText:text-changed");
1242 add_signal_listener (text_insert_event_listener,
1243 "Gtk:AtkText:text-insert");
1244 add_signal_listener (text_remove_event_listener,
1245 "Gtk:AtkText:text-remove");
1246 add_signal_listener (link_selected_event_listener,
1247 "Gtk:AtkHypertext:link-selected");
1248 add_signal_listener (generic_event_listener,
1249 "Gtk:AtkObject:visible-data-changed");
1250 add_signal_listener (generic_event_listener,
1251 "Gtk:AtkSelection:selection-changed");
1252 add_signal_listener (generic_event_listener,
1253 "Gtk:AtkText:text-attributes-changed");
1254 add_signal_listener (generic_event_listener,
1255 "Gtk:AtkText:text-caret-moved");
1256 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-inserted");
1257 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-reordered");
1258 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-deleted");
1259 add_signal_listener (generic_event_listener,
1260 "Gtk:AtkTable:column-inserted");
1261 add_signal_listener (generic_event_listener,
1262 "Gtk:AtkTable:column-reordered");
1263 add_signal_listener (generic_event_listener, "Gtk:AtkTable:column-deleted");
1264 add_signal_listener (generic_event_listener, "Gtk:AtkTable:model-changed");
1265 add_signal_listener (children_changed_event_listener, "Gtk:AtkObject:children-changed");
1268 g_signal_connect (G_OBJECT (spi_global_app_data->root),
1269 "children-changed::add",
1270 (GCallback) toplevel_added_event_listener, NULL);
1272 g_signal_connect (G_OBJECT (spi_global_app_data->root),
1273 "children-changed::remove",
1274 (GCallback) toplevel_removed_event_listener, NULL);
1278 * May add the following listeners to implement preemptive key listening for GTK+
1280 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
1281 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
1283 atk_bridge_key_event_listener_id =
1284 atk_add_key_event_listener (spi_atk_bridge_key_listener, NULL);
1287 /*---------------------------------------------------------------------------*/
1290 * De-registers all ATK signal handlers.
1293 spi_atk_deregister_event_listeners (void)
1296 GArray *ids = listener_ids;
1297 listener_ids = NULL;
1299 if (atk_bridge_focus_tracker_id)
1301 atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
1302 atk_bridge_focus_tracker_id = 0;
1307 for (i = 0; i < ids->len; i++)
1309 atk_remove_global_event_listener (g_array_index (ids, guint, i));
1311 g_array_free (ids, TRUE);
1314 if (atk_bridge_key_event_listener_id)
1316 atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
1317 atk_bridge_key_event_listener_id = 0;
1321 /*---------------------------------------------------------------------------*/
1324 * TODO This function seems out of place here.
1326 * Emits fake deactivate signals on all top-level windows.
1327 * Used when shutting down AT-SPI, ensuring that all
1328 * windows have been removed on the client side.
1331 spi_atk_tidy_windows (void)
1337 root = atk_get_root ();
1338 n_children = atk_object_get_n_accessible_children (root);
1339 for (i = 0; i < n_children; i++)
1342 AtkStateSet *stateset;
1345 child = atk_object_ref_accessible_child (root, i);
1346 stateset = atk_object_ref_state_set (child);
1348 name = atk_object_get_name (child);
1349 if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
1351 emit_event (child, ITF_EVENT_WINDOW, "deactivate", NULL, 0, 0,
1352 DBUS_TYPE_STRING_AS_STRING, name, append_basic);
1354 g_object_unref (stateset);
1356 emit_event (child, ITF_EVENT_WINDOW, "destroy", NULL, 0, 0,
1357 DBUS_TYPE_STRING_AS_STRING, name, append_basic);
1358 g_object_unref (child);
1363 spi_event_is_subtype (gchar **needle, gchar **haystack)
1365 while (*haystack && **haystack)
1367 if (g_strcmp0 (*needle, *haystack))
1375 /*END------------------------------------------------------------------------*/