2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2008, 2009, Codethink Ltd.
6 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
7 * Copyright 2001, 2002, 2003 Ximian, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
28 #include <droute/droute.h>
31 #include "accessible-register.h"
33 #include "common/spi-dbus.h"
35 static GArray *listener_ids = NULL;
37 static gint atk_bridge_key_event_listener_id;
38 static gint atk_bridge_focus_tracker_id;
40 /*---------------------------------------------------------------------------*/
42 #define ITF_EVENT_OBJECT "org.freedesktop.atspi.Event.Object"
43 #define ITF_EVENT_WINDOW "org.freedesktop.atspi.Event.Window"
44 #define ITF_EVENT_DOCUMENT "org.freedesktop.atspi.Event.Document"
45 #define ITF_EVENT_FOCUS "org.freedesktop.atspi.Event.Focus"
47 /*---------------------------------------------------------------------------*/
49 typedef struct _SpiReentrantCallClosure
53 } SpiReentrantCallClosure;
56 set_reply (DBusPendingCall * pending, void *user_data)
58 SpiReentrantCallClosure* closure = (SpiReentrantCallClosure *) user_data;
60 closure->reply = dbus_pending_call_steal_reply (pending);
61 g_main_loop_quit (closure->loop);
65 send_and_allow_reentry (DBusConnection * bus, DBusMessage * message)
67 DBusPendingCall *pending;
68 SpiReentrantCallClosure closure;
70 if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
72 dbus_pending_call_set_notify (pending, set_reply, (void *) &closure, NULL);
73 closure.loop = g_main_loop_new (NULL, FALSE);
75 g_main_loop_run (closure.loop);
77 g_main_loop_unref (closure.loop);
81 /*---------------------------------------------------------------------------*/
84 * Functionality related to sending device events from the application.
86 * This is used for forwarding key events on to the registry daemon.
90 Accessibility_DeviceEventController_NotifyListenersSync (const
91 Accessibility_DeviceEvent
96 dbus_bool_t consumed = FALSE;
99 dbus_message_new_method_call (SPI_DBUS_NAME_REGISTRY,
101 SPI_DBUS_INTERFACE_DEC,
102 "NotifyListenersSync");
104 dbus_error_init (&error);
105 if (spi_dbus_marshal_deviceEvent (message, key_event))
108 send_and_allow_reentry (spi_global_app_data->bus, message);
112 dbus_error_init (&error);
113 dbus_message_get_args (reply, &error, DBUS_TYPE_BOOLEAN, &consumed,
115 dbus_message_unref (reply);
118 dbus_message_unref (message);
123 spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent * keystroke,
124 AtkKeyEventStruct * event)
126 keystroke->id = (dbus_int32_t) event->keyval;
127 keystroke->hw_code = (dbus_int16_t) event->keycode;
128 keystroke->timestamp = (dbus_uint32_t) event->timestamp;
129 keystroke->modifiers = (dbus_uint16_t) (event->state & 0xFFFF);
134 keystroke->event_string = g_strdup (event->string);
135 c = g_utf8_get_char_validated (event->string, -1);
136 if (c > 0 && g_unichar_isprint (c))
137 keystroke->is_text = TRUE;
139 keystroke->is_text = FALSE;
143 keystroke->event_string = g_strdup ("");
144 keystroke->is_text = FALSE;
148 case (ATK_KEY_EVENT_PRESS):
149 keystroke->type = Accessibility_KEY_PRESSED_EVENT;
151 case (ATK_KEY_EVENT_RELEASE):
152 keystroke->type = Accessibility_KEY_RELEASED_EVENT;
160 ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
161 (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
162 (int) keystroke->modifiers, keystroke->event_string,
163 (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
169 spi_atk_bridge_key_listener (AtkKeyEventStruct * event, gpointer data)
172 Accessibility_DeviceEvent key_event;
174 spi_init_keystroke_from_atk_key_event (&key_event, event);
177 Accessibility_DeviceEventController_NotifyListenersSync (&key_event);
179 if (key_event.event_string)
180 g_free (key_event.event_string);
185 /*---------------------------------------------------------------------------*/
188 convert_signal_name (const gchar * s)
190 gchar *ret = g_strdup (s);
195 ret[0] = toupper (ret[0]);
196 while ((t = strchr (ret, '-')) != NULL)
198 memmove (t, t + 1, strlen (t));
205 replace_null (const gint type,
210 case DBUS_TYPE_STRING:
211 case DBUS_TYPE_OBJECT_PATH:
222 append_basic (DBusMessageIter *iter,
228 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &sub);
230 val = replace_null ((int) *type, val);
231 dbus_message_iter_append_basic(&sub, (int) *type, &val);
233 dbus_message_iter_close_container(iter, &sub);
237 append_rect (DBusMessageIter *iter,
241 DBusMessageIter variant, sub;
242 const AtkRectangle *rect = (const AtkRectangle *) val;
244 dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, type, &variant);
246 dbus_message_iter_open_container (&variant, DBUS_TYPE_STRUCT, NULL, &sub);
248 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->x));
249 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->y));
250 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->width));
251 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &(rect->height));
253 dbus_message_iter_close_container (&variant, &sub);
255 dbus_message_iter_close_container(iter, &variant);
259 append_object (DBusMessageIter *iter,
263 spi_object_append_v_reference (iter, ATK_OBJECT (val));
267 signal_name_to_dbus (const gchar *s)
269 gchar *ret = g_strdup (s);
274 ret [0] = toupper (ret [0]);
275 while ((t = strchr (ret, '-')) != NULL)
277 memmove (t, t + 1, strlen (t));
284 * Emits an AT-SPI event.
285 * AT-SPI events names are split into three parts:
287 * This is mapped onto D-Bus events as:
288 * D-Bus Interface:Signal Name:Detail argument
290 * Marshals a basic type into the 'any_data' attribute of
294 emit_event (AtkObject *obj,
298 dbus_int32_t detail1,
299 dbus_int32_t detail2,
302 void (*append_variant) (DBusMessageIter *, const char *, const void *))
304 DBusConnection *bus = spi_global_app_data->bus;
305 const char *path = spi_register_object_to_path (spi_global_register,
310 DBusMessageIter iter, iter_struct;
312 if (!klass) klass = "";
313 if (!major) major = "";
314 if (!minor) minor = "";
315 if (!type) type = "u";
318 * This is very annoying, but as '-' isn't a legal signal
319 * name in D-Bus (Why not??!?) The names need converting
320 * on this side, and again on the client side.
322 cname = signal_name_to_dbus (major);
323 sig = dbus_message_new_signal(path, klass, cname);
326 dbus_message_iter_init_append(sig, &iter);
328 spi_object_append_reference (&iter, spi_global_app_data->root);
329 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
330 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
331 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
333 append_variant (&iter, type, val);
335 dbus_connection_send(bus, sig, NULL);
336 dbus_message_unref(sig);
339 /*---------------------------------------------------------------------------*/
342 * The focus listener handles the ATK 'focus' signal and forwards it
343 * as the AT-SPI event, 'focus:'
346 focus_tracker (AtkObject * accessible)
348 emit_event (accessible, ITF_EVENT_FOCUS, "focus", "", 0, 0,
349 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
352 /*---------------------------------------------------------------------------*/
354 #define PCHANGE "property_change"
357 * This handler handles the following ATK signals and
358 * converts them to AT-SPI events:
360 * Gtk:AtkObject:property-change -> object:property-change:(property-name)
362 * The property-name is part of the ATK property-change signal.
365 property_event_listener (GSignalInvocationHint * signal_hint,
366 guint n_param_values,
367 const GValue * param_values, gpointer data)
369 AtkObject *accessible;
370 AtkPropertyValues *values;
372 const gchar *pname = NULL;
378 accessible = g_value_get_object (¶m_values[0]);
379 values = (AtkPropertyValues *) g_value_get_pointer (¶m_values[1]);
381 pname = values[0].property_name;
383 /* TODO Could improve this control statement by matching
384 * on only the end of the signal names,
386 if (strcmp (pname, "accessible-name") == 0)
388 s1 = atk_object_get_name (accessible);
390 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
391 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
393 if (strcmp (pname, "accessible-description") == 0)
395 s1 = atk_object_get_description (accessible);
397 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
398 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
400 if (strcmp (pname, "accessible-parent") == 0)
402 otemp = atk_object_get_parent (accessible);
404 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
405 "(so)", otemp, append_object);
407 if (strcmp (pname, "accessible-table-summary") == 0)
409 otemp = atk_table_get_summary (ATK_TABLE (accessible));
411 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
412 "(so)", otemp, append_object);
414 else if (strcmp (pname, "accessible-table-column-header") == 0)
416 i = g_value_get_int (&(values->new_value));
417 otemp = atk_table_get_column_header (ATK_TABLE (accessible), i);
419 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
420 "(so)", otemp, append_object);
422 else if (strcmp (pname, "accessible-table-row-header") == 0)
424 i = g_value_get_int (&(values->new_value));
425 otemp = atk_table_get_row_header (ATK_TABLE (accessible), i);
427 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
428 "(so)", otemp, append_object);
430 else if (strcmp (pname, "accessible-table-row-description") == 0)
432 i = g_value_get_int (&(values->new_value));
433 s1 = atk_table_get_row_description (ATK_TABLE (accessible), i);
434 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
435 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
437 else if (strcmp (pname, "accessible-table-column-description") == 0)
439 i = g_value_get_int (&(values->new_value));
440 s1 = atk_table_get_column_description (ATK_TABLE (accessible), i);
441 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
442 DBUS_TYPE_STRING_AS_STRING, s1, append_basic);
444 else if (strcmp (pname, "accessible-table-caption-object") == 0)
446 otemp = atk_table_get_caption (ATK_TABLE (accessible));
447 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
448 "(so)", otemp, append_object);
452 emit_event (accessible, ITF_EVENT_OBJECT, PCHANGE, pname, 0, 0,
453 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
458 /*---------------------------------------------------------------------------*/
460 #define STATE_CHANGED "state-changed"
463 * The state event listener handles 'Gtk:AtkObject:state-change' ATK signals
464 * and forwards them as object:state-changed:(param-name) AT-SPI events. Where
465 * the param-name is part of the ATK state-change signal.
468 state_event_listener (GSignalInvocationHint * signal_hint,
469 guint n_param_values,
470 const GValue * param_values, gpointer data)
472 AtkObject *accessible;
476 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
477 pname = g_strdup (g_value_get_string (¶m_values[1]));
479 /* TODO - Possibly ignore a change to the 'defunct' state.
480 * This is because without reference counting defunct objects should be removed.
482 detail1 = (g_value_get_boolean (¶m_values[2])) ? 1 : 0;
483 emit_event (accessible, ITF_EVENT_OBJECT, STATE_CHANGED, pname, detail1, 0,
484 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
489 /*---------------------------------------------------------------------------*/
492 * The window event listener handles the following ATK signals and forwards
493 * them as AT-SPI events:
495 * window:create -> window:create
496 * window:destroy -> window:destroy
497 * window:minimize -> window:minimize
498 * window:maximize -> window:maximize
499 * window:activate -> window:activate
500 * window:deactivate -> window:deactivate
503 window_event_listener (GSignalInvocationHint * signal_hint,
504 guint n_param_values,
505 const GValue * param_values, gpointer data)
507 AtkObject *accessible;
508 GSignalQuery signal_query;
509 const gchar *name, *s;
511 g_signal_query (signal_hint->signal_id, &signal_query);
512 name = signal_query.signal_name;
514 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
515 s = atk_object_get_name (accessible);
516 emit_event (accessible, ITF_EVENT_WINDOW, name, "", 0, 0,
517 DBUS_TYPE_STRING_AS_STRING, s, append_basic);
522 /*---------------------------------------------------------------------------*/
525 * The document event listener handles the following ATK signals
526 * and converts them to AT-SPI events:
528 * Gtk:AtkDocument:load-complete -> document:load-complete
529 * Gtk:AtkDocument:load-stopped -> document:load-stopped
530 * Gtk:AtkDocument:reload -> document:reload
533 document_event_listener (GSignalInvocationHint * signal_hint,
534 guint n_param_values,
535 const GValue * param_values, gpointer data)
537 AtkObject *accessible;
538 GSignalQuery signal_query;
539 const gchar *name, *s;
541 g_signal_query (signal_hint->signal_id, &signal_query);
542 name = signal_query.signal_name;
544 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
545 s = atk_object_get_name (accessible);
546 emit_event (accessible, ITF_EVENT_DOCUMENT, name, "", 0, 0,
547 DBUS_TYPE_STRING_AS_STRING, s, append_basic);
552 /*---------------------------------------------------------------------------*/
555 * Signal handler for "Gtk:AtkComponent:bounds-changed". Converts
556 * this to an AT-SPI event - "object:bounds-changed".
559 bounds_event_listener (GSignalInvocationHint * signal_hint,
560 guint n_param_values,
561 const GValue * param_values, gpointer data)
563 AtkObject *accessible;
564 AtkRectangle *atk_rect;
565 GSignalQuery signal_query;
566 const gchar *name, *s;
568 g_signal_query (signal_hint->signal_id, &signal_query);
569 name = signal_query.signal_name;
571 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
573 if (G_VALUE_HOLDS_BOXED (param_values + 1))
575 atk_rect = g_value_get_boxed (param_values + 1);
577 emit_event (accessible, ITF_EVENT_OBJECT, name, "", 0, 0,
578 "(iiii)", atk_rect, append_rect);
583 /*---------------------------------------------------------------------------*/
586 * Handles the ATK signal 'Gtk:AtkObject:active-descendant-changed' and
587 * converts it to the AT-SPI signal - 'object:active-descendant-changed'.
591 active_descendant_event_listener (GSignalInvocationHint * signal_hint,
592 guint n_param_values,
593 const GValue * param_values, gpointer data)
595 AtkObject *accessible;
597 GSignalQuery signal_query;
598 const gchar *name, *minor;
602 g_signal_query (signal_hint->signal_id, &signal_query);
603 name = signal_query.signal_name;
605 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
606 child = ATK_OBJECT (g_value_get_pointer (¶m_values[1]));
607 g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
608 minor = g_quark_to_string (signal_hint->detail);
610 detail1 = atk_object_get_index_in_parent (child);
612 emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, 0,
613 "(so)", child, append_object);
618 /*---------------------------------------------------------------------------*/
621 * Handles the ATK signal 'Gtk:AtkHypertext:link-selected' and
622 * converts it to the AT-SPI signal - 'object:link-selected'
626 link_selected_event_listener (GSignalInvocationHint * signal_hint,
627 guint n_param_values,
628 const GValue * param_values, gpointer data)
630 AtkObject *accessible;
631 GSignalQuery signal_query;
632 const gchar *name, *minor;
635 g_signal_query (signal_hint->signal_id, &signal_query);
636 name = signal_query.signal_name;
638 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
639 minor = g_quark_to_string (signal_hint->detail);
641 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
642 detail1 = g_value_get_int (¶m_values[1]);
644 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, 0,
645 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
649 /*---------------------------------------------------------------------------*/
652 * Handles the ATK signal 'Gtk:AtkText:text-changed' and
653 * converts it to the AT-SPI signal - 'object:text-changed'
657 text_changed_event_listener (GSignalInvocationHint * signal_hint,
658 guint n_param_values,
659 const GValue * param_values, gpointer data)
661 AtkObject *accessible;
662 GSignalQuery signal_query;
663 const gchar *name, *minor;
665 gint detail1, detail2;
667 g_signal_query (signal_hint->signal_id, &signal_query);
668 name = signal_query.signal_name;
670 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
671 minor = g_quark_to_string (signal_hint->detail);
673 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
674 detail1 = g_value_get_int (¶m_values[1]);
676 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
677 detail2 = g_value_get_int (¶m_values[2]);
680 atk_text_get_text (ATK_TEXT (accessible), detail1, detail1 + detail2);
682 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
683 DBUS_TYPE_STRING_AS_STRING, selected, append_basic);
687 /*---------------------------------------------------------------------------*/
690 * Handles the ATK signal 'Gtk:AtkText:text-selection-changed' and
691 * converts it to the AT-SPI signal - 'object:text-selection-changed'
695 text_selection_changed_event_listener (GSignalInvocationHint * signal_hint,
696 guint n_param_values,
697 const GValue * param_values,
700 AtkObject *accessible;
701 GSignalQuery signal_query;
702 const gchar *name, *minor;
703 gint detail1, detail2;
705 g_signal_query (signal_hint->signal_id, &signal_query);
706 name = signal_query.signal_name;
708 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
709 minor = g_quark_to_string (signal_hint->detail);
711 if (G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
712 detail1 = g_value_get_int (¶m_values[1]);
714 if (G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
715 detail2 = g_value_get_int (¶m_values[2]);
717 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
718 DBUS_TYPE_STRING_AS_STRING, "", append_basic);
722 /*---------------------------------------------------------------------------*/
725 * Children changed signal converter and forwarder.
727 * Klass (Interface) org.freedesktop.atspi.Event.Object
728 * Major is the signal name.
729 * Minor is 'add' or 'remove'
730 * detail1 is the index.
732 * any_data is the child reference.
735 children_changed_event_listener (GSignalInvocationHint * signal_hint,
736 guint n_param_values,
737 const GValue * param_values, gpointer data)
739 GSignalQuery signal_query;
740 const gchar *name, *minor;
741 gint detail1, detail2 = 0;
743 AtkObject *accessible, *ao;
746 g_signal_query (signal_hint->signal_id, &signal_query);
747 name = signal_query.signal_name;
749 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
750 minor = g_quark_to_string (signal_hint->detail);
752 detail1 = g_value_get_uint (param_values + 1);
753 child = g_value_get_pointer (param_values + 2);
755 if (ATK_IS_OBJECT (child))
757 ao = ATK_OBJECT (child);
758 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
759 "(so)", ao, append_object);
761 else if ((minor != NULL) && (strcmp (minor, "add") == 0))
763 ao = atk_object_ref_accessible_child (accessible,
765 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
766 "(so)", ao, append_object);
770 emit_event (accessible, ITF_EVENT_OBJECT, name, minor, detail1, detail2,
771 "(so)", ao, append_object);
777 /*---------------------------------------------------------------------------*/
780 toplevel_added_event_listener (AtkObject * accessible,
781 guint index, AtkObject * child)
783 emit_event (accessible, ITF_EVENT_OBJECT, "children-changed", "add", index, 0,
784 "(so)", child, append_object);
788 toplevel_removed_event_listener (AtkObject * accessible,
789 guint index, AtkObject * child)
791 emit_event (accessible, ITF_EVENT_OBJECT, "children-changed", "remove", index, 0,
792 "(so)", child, append_object);
795 /*---------------------------------------------------------------------------*/
798 * Generic signal converter and forwarder.
800 * Klass (Interface) org.freedesktop.atspi.Event.Object
801 * Major is the signal name.
808 generic_event_listener (GSignalInvocationHint * signal_hint,
809 guint n_param_values,
810 const GValue * param_values, gpointer data)
812 AtkObject *accessible;
813 GSignalQuery signal_query;
815 int detail1 = 0, detail2 = 0;
817 g_signal_query (signal_hint->signal_id, &signal_query);
818 name = signal_query.signal_name;
820 accessible = ATK_OBJECT (g_value_get_object (¶m_values[0]));
822 if (n_param_values > 1 && G_VALUE_TYPE (¶m_values[1]) == G_TYPE_INT)
823 detail1 = g_value_get_int (¶m_values[1]);
825 if (n_param_values > 2 && G_VALUE_TYPE (¶m_values[2]) == G_TYPE_INT)
826 detail2 = g_value_get_int (¶m_values[2]);
828 emit_event (accessible, ITF_EVENT_OBJECT, name, "", detail1, detail2,
829 DBUS_TYPE_INT32_AS_STRING, 0, append_basic);
833 /*---------------------------------------------------------------------------*/
836 * Registers the provided function as a handler for the given signal name
837 * and stores the signal id returned so that the function may be
838 * de-registered later.
841 add_signal_listener (GSignalEmissionHook listener, const char *signal_name)
845 id = atk_add_global_event_listener (listener, signal_name);
846 g_array_append_val (listener_ids, id);
850 * Initialization for the signal handlers.
852 * Registers all required signal handlers.
855 spi_atk_register_event_listeners (void)
858 * Kludge to make sure the Atk interface types are registered, otherwise
859 * the AtkText signal handlers below won't get registered
861 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
862 AtkObject *bo = atk_no_op_object_new (ao);
864 g_object_unref (G_OBJECT (bo));
867 /* Register for focus event notifications, and register app with central registry */
868 listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
870 atk_bridge_focus_tracker_id = atk_add_focus_tracker (focus_tracker);
872 add_signal_listener (property_event_listener,
873 "Gtk:AtkObject:property-change");
874 add_signal_listener (window_event_listener, "window:create");
875 add_signal_listener (window_event_listener, "window:destroy");
876 add_signal_listener (window_event_listener, "window:minimize");
877 add_signal_listener (window_event_listener, "window:maximize");
878 add_signal_listener (window_event_listener, "window:restore");
879 add_signal_listener (window_event_listener, "window:activate");
880 add_signal_listener (window_event_listener, "window:deactivate");
881 add_signal_listener (document_event_listener,
882 "Gtk:AtkDocument:load-complete");
883 add_signal_listener (document_event_listener, "Gtk:AtkDocument:reload");
884 add_signal_listener (document_event_listener,
885 "Gtk:AtkDocument:load-stopped");
886 /* TODO Fake this event on the client side */
887 add_signal_listener (state_event_listener, "Gtk:AtkObject:state-change");
889 add_signal_listener (active_descendant_event_listener,
890 "Gtk:AtkObject:active-descendant-changed");
891 add_signal_listener (bounds_event_listener,
892 "Gtk:AtkComponent:bounds-changed");
893 add_signal_listener (text_selection_changed_event_listener,
894 "Gtk:AtkText:text-selection-changed");
895 add_signal_listener (text_changed_event_listener,
896 "Gtk:AtkText:text-changed");
897 add_signal_listener (link_selected_event_listener,
898 "Gtk:AtkHypertext:link-selected");
899 add_signal_listener (generic_event_listener,
900 "Gtk:AtkObject:visible-data-changed");
901 add_signal_listener (generic_event_listener,
902 "Gtk:AtkSelection:selection-changed");
903 add_signal_listener (generic_event_listener,
904 "Gtk:AtkText:text-attributes-changed");
905 add_signal_listener (generic_event_listener,
906 "Gtk:AtkText:text-caret-moved");
907 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-inserted");
908 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-reordered");
909 add_signal_listener (generic_event_listener, "Gtk:AtkTable:row-deleted");
910 add_signal_listener (generic_event_listener,
911 "Gtk:AtkTable:column-inserted");
912 add_signal_listener (generic_event_listener,
913 "Gtk:AtkTable:column-reordered");
914 add_signal_listener (generic_event_listener, "Gtk:AtkTable:column-deleted");
915 add_signal_listener (generic_event_listener, "Gtk:AtkTable:model-changed");
917 /* Children signal listeners */
918 atk_add_global_event_listener (children_changed_event_listener,
919 "Gtk:AtkObject:children-changed");
922 g_signal_connect (G_OBJECT (spi_global_app_data->root),
923 "children-changed::add",
924 (GCallback) toplevel_added_event_listener, NULL);
926 g_signal_connect (G_OBJECT (spi_global_app_data->root),
927 "children-changed::remove",
928 (GCallback) toplevel_removed_event_listener, NULL);
932 * May add the following listeners to implement preemptive key listening for GTK+
934 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
935 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
937 atk_bridge_key_event_listener_id =
938 atk_add_key_event_listener (spi_atk_bridge_key_listener, NULL);
941 /*---------------------------------------------------------------------------*/
944 * De-registers all ATK signal handlers.
947 spi_atk_deregister_event_listeners (void)
950 GArray *ids = listener_ids;
953 if (atk_bridge_focus_tracker_id)
954 atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
956 for (i = 0; ids && i < ids->len; i++)
958 atk_remove_global_event_listener (g_array_index (ids, guint, i));
961 if (atk_bridge_key_event_listener_id)
962 atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
965 /*---------------------------------------------------------------------------*/
968 * TODO This function seems out of place here.
970 * Emits fake deactivate signals on all top-level windows.
971 * Used when shutting down AT-SPI, ensuring that all
972 * windows have been removed on the client side.
975 spi_atk_tidy_windows (void)
981 root = atk_get_root ();
982 n_children = atk_object_get_n_accessible_children (root);
983 for (i = 0; i < n_children; i++)
986 AtkStateSet *stateset;
989 child = atk_object_ref_accessible_child (root, i);
990 stateset = atk_object_ref_state_set (child);
992 name = atk_object_get_name (child);
993 if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
995 emit_event (child, ITF_EVENT_WINDOW, "deactivate", NULL, 0, 0,
996 DBUS_TYPE_STRING_AS_STRING, name, append_basic);
998 g_object_unref (stateset);
1000 emit_event (child, ITF_EVENT_WINDOW, "destroy", NULL, 0, 0,
1001 DBUS_TYPE_STRING_AS_STRING, name, append_basic);
1002 g_object_unref (child);
1006 /*END------------------------------------------------------------------------*/