2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.,
6 * Copyright 2001, 2002, 2003 Ximian, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include "dbus/dbus-glib-lowlevel.h"
28 #include <X11/Xatom.h>
35 #include <atk/atkobject.h>
36 #include <atk/atknoopobject.h>
37 #include "accessible.h"
39 #undef SPI_BRIDGE_DEBUG
41 #define DBG(a,b) if(_dbg>=(a))b
43 #define bridge_threads_leave() \
44 if (!during_init_shutdown && !g_main_context_is_owner (NULL)) atk_misc_threads_leave(misc);
45 #define bridge_threads_enter() \
46 if (!during_init_shutdown && !g_main_context_is_owner (NULL)) atk_misc_threads_enter(misc);
48 typedef struct _SpiAppData SpiAppData;
56 static const char *registry = NULL;
57 static char *device_event_controller = NULL;
58 static SpiAppData *this_app = NULL;
59 static gboolean registry_died = FALSE;
60 static gboolean atk_listeners_registered = FALSE;
61 static gint toplevels = 0;
62 static gboolean exiting = FALSE;
63 static AtkMisc *misc = NULL;
64 static gboolean during_init_shutdown = TRUE;
66 static guint atk_signal_text_changed;
67 static guint atk_signal_children_changed;
68 static guint atk_signal_active_descendant_changed;
69 static guint atk_signal_text_selection_changed;
72 static guint atk_signal_row_reordered;
73 static guint atk_signal_row_inserted;
74 static guint atk_signal_row_deleted;
75 static guint atk_signal_column_reordered;
76 static guint atk_signal_column_inserted;
77 static guint atk_signal_column_deleted;
80 static guint atk_signal_link_selected;
81 static guint atk_signal_bounds_changed;
83 static const char *spi_atk_bridge_get_registry (void);
84 static gboolean spi_atk_bridge_do_registration (void);
85 static void spi_atk_bridge_toplevel_added (AtkObject *object,
88 static void spi_atk_bridge_toplevel_removed (AtkObject *object,
92 static void spi_atk_bridge_exit_func (void);
93 static void spi_atk_register_event_listeners (void);
94 static void spi_atk_bridge_focus_tracker (AtkObject *object);
95 static gchar *spi_atk_bridge_get_registry_ior (void);
96 static void spi_atk_bridge_register_application (const char *registry);
97 static gboolean spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
99 const GValue *param_values,
103 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
104 guint n_param_values,
105 const GValue *param_values,
108 spi_atk_bridge_document_event_listener (GSignalInvocationHint *signal_hint,
109 guint n_param_values,
110 const GValue *param_values,
113 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
114 guint n_param_values,
115 const GValue *param_values,
117 static gboolean spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
118 guint n_param_values,
119 const GValue *param_values,
121 static gint spi_atk_bridge_key_listener (AtkKeyEventStruct *event,
123 static void spi_atk_tidy_windows (void);
124 static void deregister_application (SpiAppData *app);
125 static void reinit_register_vars (void);
127 /* For automatic libgnome init */
128 extern void gnome_accessibility_module_init (void);
129 extern void gnome_accessibility_module_shutdown (void);
131 static int atk_bridge_initialized = FALSE;
132 static pid_t atk_bridge_pid = 0;
133 static guint atk_bridge_focus_tracker_id = 0;
134 static guint atk_bridge_key_event_listener_id = 0;
135 static GArray *listener_ids = NULL;
138 * These exported symbols are hooked by gnome-program
139 * to provide automatic module initialization and shutdown.
141 extern void gnome_accessibility_module_init (void);
142 extern void gnome_accessibility_module_shutdown (void);
145 spi_atk_bridge_init_event_type_consts ()
147 static gboolean done = FALSE;
152 atk_signal_children_changed = g_signal_lookup ("children_changed",
154 atk_signal_text_changed = g_signal_lookup ("text_changed",
156 atk_signal_bounds_changed = g_signal_lookup ("bounds_changed",
158 atk_signal_active_descendant_changed =
159 g_signal_lookup ("active_descendant_changed",
161 atk_signal_link_selected = g_signal_lookup ("link_selected",
163 atk_signal_text_selection_changed = g_signal_lookup ("text_selection_changed",
169 post_init (gpointer data)
171 during_init_shutdown = FALSE;
175 static DBusObjectPathVTable droute_vtable =
179 NULL, NULL, NULL, NULL
182 static gchar* atspi_dbus_name;
183 static gboolean atspi_no_register;
185 static GOptionEntry atspi_option_entries[] =
187 {"atspi-dbus-name", 0, 0, G_OPTION_ARG_STRING, &atspi_dbus_name, "D-Bus bus name to register as", NULL},
188 {"atspi-no-register", 0, 0, G_OPTION_ARG_NONE, &atspi_no_register, "Do not register with Registry Daemon", NULL},
193 spi_app_init (AtkObject *root, gint *argc, gchar **argv[])
196 SpiAppData *ad = g_new0(SpiAppData, 1);
201 opt = g_option_context_new(NULL);
202 g_option_context_add_main_entries(opt, atspi_option_entries, NULL);
203 g_option_context_set_ignore_unknown_options(opt, TRUE);
204 if (!g_option_context_parse(opt, argc, argv, &err))
205 g_warning("Option parsing failed: %s\n", err->message);
207 dbus_error_init(&error);
209 ad->droute.bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
213 g_warning("Couldn't connect to dbus: %s\n", error.message);
217 if (atspi_dbus_name != NULL && dbus_bus_request_name(ad->droute.bus,
222 g_print("\nRecieved D-Bus name - %s\n", atspi_dbus_name);
224 spi_register_tree_object(ad->droute.bus, &ad->droute, "/org/freedesktop/atspi/tree");
225 if (!dbus_connection_try_register_fallback (ad->droute.bus,
226 "/org/freedesktop/atspi/accessible",
231 g_warning("Couldn't register droute.\n");
236 dbus_connection_setup_with_g_main(ad->droute.bus, g_main_context_default());
238 spi_dbus_initialize (&ad->droute);
243 atk_bridge_init (gint *argc, gchar **argv[])
245 const char *debug_env_string = g_getenv ("AT_SPI_DEBUG");
247 gboolean success = FALSE;
249 if (atk_bridge_initialized)
253 atk_bridge_initialized = TRUE;
254 atk_bridge_pid = getpid ();
256 misc = atk_misc_get_instance();
258 if (g_getenv ("ATK_BRIDGE_REDIRECT_LOG"))
260 fname = g_strconcat ("/tmp/", g_get_prgname (), ".at-spi-log", NULL);
261 /* make sure we're not being redirected - security issue */
262 if (!g_file_test (fname, G_FILE_TEST_IS_SYMLINK))
263 freopen (fname, "w", stderr);
267 if (debug_env_string)
268 _dbg = (int) g_ascii_strtod (debug_env_string, NULL);
270 /* Connect to dbus */
271 this_app = spi_app_init (atk_get_root (), argc, argv);
274 * We only want to enable the bridge for top level
275 * applications, we detect bonobo components by seeing
276 * if they were activated with the intention of extracting
277 * an impl. by IID - very solid.
280 // TODO: Figure out if this is still needed
281 if (bonobo_activation_iid_get ())
286 DBG (1, g_message ("Found Bonobo component\n"));
287 g_signal_connect (atk_get_root (),
288 "children-changed::add",
289 (GCallback) spi_atk_bridge_toplevel_added,
291 g_signal_connect (atk_get_root (),
292 "children-changed::remove",
293 (GCallback) spi_atk_bridge_toplevel_removed,
295 /* in this case we redefine 'success' to mean 'registry is present' */
296 success = (spi_atk_bridge_get_registry () != NULL);
300 success = spi_atk_bridge_do_registration ();
303 * we must emit events even if we are not registered as a
304 * full-fledged app; See bugzilla #400709.
308 spi_atk_register_event_listeners ();
309 spi_atk_bridge_init_event_type_consts ();
313 atk_bridge_initialized = FALSE;
315 g_idle_add (post_init, NULL);
321 spi_atk_bridge_do_registration (void)
323 if (spi_atk_bridge_get_registry () == NULL)
325 g_warning ("Could not locate registry");
329 /* Create the accessible application server object */
330 if (this_app == NULL)
331 this_app = spi_app_init (atk_get_root (), 0, NULL);
333 DBG (1, g_message ("About to register application\n"));
335 spi_atk_bridge_register_application (spi_atk_bridge_get_registry ());
337 g_atexit (spi_atk_bridge_exit_func);
339 DBG (1, g_message ("Application registered & listening\n"));
344 spi_atk_bridge_toplevel_added (AtkObject *object,
350 spi_atk_bridge_do_registration ();
356 spi_atk_bridge_toplevel_removed (AtkObject *object,
363 deregister_application (this_app);
364 reinit_register_vars ();
368 g_warning ("More toplevels removed than added\n");
374 spi_atk_bridge_register_application (const char *registry)
376 bridge_threads_leave ();
378 bridge_threads_enter ();
382 * Returns a 'canonicalized' value for DISPLAY,
383 * with the screen number stripped off if present.
386 spi_display_name (void)
388 static const char *canonical_display_name = NULL;
389 if (!canonical_display_name)
391 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
394 display_env = g_getenv ("DISPLAY");
395 if (!display_env || !display_env[0])
396 canonical_display_name = ":0";
399 gchar *display_p, *screen_p;
400 canonical_display_name = g_strdup (display_env);
401 display_p = strrchr (canonical_display_name, ':');
402 screen_p = strrchr (canonical_display_name, '.');
403 if (screen_p && display_p && (screen_p > display_p))
411 canonical_display_name = display_env;
414 return canonical_display_name;
417 static Display *bridge_display = NULL;
420 spi_atk_bridge_get_registry_ior (void)
426 unsigned char *data = NULL;
427 unsigned long nitems;
428 unsigned long leftover;
430 bridge_display = XOpenDisplay (spi_display_name ());
432 AT_SPI_IOR = XInternAtom (bridge_display, "AT_SPI_IOR", False);
433 XGetWindowProperty(bridge_display,
434 XDefaultRootWindow (bridge_display),
437 (Atom) 31, &actual_type, &actual_format,
438 &nitems, &leftover, &data);
440 g_warning (_("AT_SPI_REGISTRY was not started at session startup."));
442 return (gchar *) data;
448 spi_atk_bridge_get_registry (void)
450 // TODO: check for registry dying, as the old code attempted to do
451 return "org.freedesktop.atspi.registry";
455 spi_atk_bridge_get_dec (void)
461 gtk_module_init (gint *argc, gchar **argv[])
463 //printf("Pointer to argc %x %x\n", (short) ((argc && 0xffff0000) >> 16), (short) (argc && 0xffff));
464 return atk_bridge_init (argc, argv);
468 add_signal_listener (const char *signal_name)
472 id = atk_add_global_event_listener (
473 spi_atk_bridge_signal_listener, signal_name);
475 g_array_append_val (listener_ids, id);
479 spi_atk_register_event_listeners (void)
482 * kludge to make sure the Atk interface types are registered, otherwise
483 * the AtkText signal handlers below won't get registered
486 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
487 AtkObject *bo = atk_no_op_object_new (ao);
490 if (atk_listeners_registered)
492 g_object_unref (G_OBJECT (bo));
497 atk_listeners_registered = TRUE;
499 /* Register for focus event notifications, and register app with central registry */
501 listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
503 atk_bridge_focus_tracker_id = atk_add_focus_tracker (spi_atk_bridge_focus_tracker);
505 id = atk_add_global_event_listener (spi_atk_bridge_property_event_listener,
506 "Gtk:AtkObject:property-change");
507 g_array_append_val (listener_ids, id);
508 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
510 g_array_append_val (listener_ids, id);
511 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
513 g_array_append_val (listener_ids, id);
514 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
516 g_array_append_val (listener_ids, id);
517 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
519 g_array_append_val (listener_ids, id);
520 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
522 g_array_append_val (listener_ids, id);
523 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
525 g_array_append_val (listener_ids, id);
526 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
527 "window:deactivate");
528 g_array_append_val (listener_ids, id);
529 id = atk_add_global_event_listener (spi_atk_bridge_document_event_listener,
530 "Gtk:AtkDocument:load-complete");
531 g_array_append_val (listener_ids, id);
532 id = atk_add_global_event_listener (spi_atk_bridge_document_event_listener,
533 "Gtk:AtkDocument:reload");
534 g_array_append_val (listener_ids, id);
535 id = atk_add_global_event_listener (spi_atk_bridge_document_event_listener,
536 "Gtk:AtkDocument:load-stopped");
537 g_array_append_val (listener_ids, id);
538 id = atk_add_global_event_listener (spi_atk_bridge_state_event_listener,
539 "Gtk:AtkObject:state-change");
540 g_array_append_val (listener_ids, id);
542 add_signal_listener ("Gtk:AtkObject:children-changed");
543 add_signal_listener ("Gtk:AtkObject:visible-data-changed");
544 add_signal_listener ("Gtk:AtkObject:active-descendant-changed");
545 add_signal_listener ("Gtk:AtkComponent:bounds-changed");
546 add_signal_listener ("Gtk:AtkSelection:selection-changed");
547 add_signal_listener ("Gtk:AtkText:text-selection-changed");
548 add_signal_listener ("Gtk:AtkText:text-changed");
549 add_signal_listener ("Gtk:AtkText:text-caret-moved");
550 add_signal_listener ("Gtk:AtkTable:row-inserted");
551 add_signal_listener ("Gtk:AtkTable:row-reordered");
552 add_signal_listener ("Gtk:AtkTable:row-deleted");
553 add_signal_listener ("Gtk:AtkTable:column-inserted");
554 add_signal_listener ("Gtk:AtkTable:column-reordered");
555 add_signal_listener ("Gtk:AtkTable:column-deleted");
556 add_signal_listener ("Gtk:AtkTable:model-changed");
557 add_signal_listener ("Gtk:AtkHypertext:link-selected");
559 * May add the following listeners to implement preemptive key listening for GTK+
561 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
562 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
564 atk_bridge_key_event_listener_id = atk_add_key_event_listener (
565 spi_atk_bridge_key_listener, NULL);
567 g_object_unref (G_OBJECT (bo));
572 deregister_application (SpiAppData *app)
574 const char *registry = spi_atk_bridge_get_registry ();
575 bridge_threads_leave ();
577 bridge_threads_enter ();
581 spi_atk_bridge_exit_func (void)
583 SpiAppData *app = (SpiAppData *) this_app;
585 DBG (1, g_message ("exiting bridge\n"));
591 if (atk_bridge_pid != getpid ())
596 during_init_shutdown = TRUE;
599 * Check whether we still have windows which have not been deleted.
601 spi_atk_tidy_windows ();
603 * FIXME: this may be incorrect for apps that do their own bonobo
604 * shutdown, until we can explicitly shutdown to get the ordering
608 deregister_application (this_app);
610 DBG (1, g_message ("bridge exit func complete.\n"));
612 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
616 XCloseDisplay (bridge_display);
620 gnome_accessibility_module_init (void)
622 atk_bridge_init (0, NULL);
624 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
626 g_print("Atk Accessibility bridge initialized\n");
631 gnome_accessibility_module_shutdown (void)
634 GArray *ids = listener_ids;
636 if (!atk_bridge_initialized)
640 during_init_shutdown = TRUE;
641 atk_bridge_initialized = FALSE;
643 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
645 g_print("Atk Accessibility bridge shutdown\n");
649 if (atk_bridge_focus_tracker_id)
650 atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
652 for (i = 0; ids && i < ids->len; i++)
654 atk_remove_global_event_listener (g_array_index (ids, guint, i));
657 if (atk_bridge_key_event_listener_id)
658 atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
660 deregister_application (this_app);
666 static void emit(AtkObject *object, const char *name, const char *detail, dbus_int32_t detail1, dbus_int32_t detail2, int type, const void *val)
669 char *path = spi_dbus_get_path(object);
670 DBusMessageIter iter, sub;
671 const char *type_as_string = NULL;
672 dbus_int32_t dummy = 0;
674 spi_dbus_update_cache(&this_app->droute);
675 if (type == DBUS_TYPE_OBJECT_PATH)
677 type_as_string = "o";
680 else if (type == DBUS_TYPE_STRING) type_as_string = "s";
681 else if (type == DBUS_TYPE_INT32) type_as_string = "i";
682 else if (type == DBUS_TYPE_UINT32) type_as_string = "u";
683 else if (type == DBUS_TYPE_INVALID)
685 type = DBUS_TYPE_UINT32;
686 type_as_string = "u";
687 if (!val) val = &dummy;
691 g_warning("Unknown type %d in property change signal", type);
693 sig = dbus_message_new_signal(path, "org.freedesktop.atspi.Accessible", name);
694 dbus_message_iter_init_append(sig, &iter);
695 if (!detail) detail = "";
696 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &detail);
697 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
698 dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
699 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, type_as_string, &sub);
700 dbus_message_iter_append_basic(&sub, type, &val);
701 dbus_message_iter_close_container(&iter, &sub);
702 printf("emit: %s %s\n", name, detail);
703 dbus_connection_send(this_app->droute.bus, sig, NULL);
705 dbus_message_unref(sig);
709 spi_atk_bridge_focus_tracker (AtkObject *object)
711 emit(object, "focus", NULL, 0, 0, DBUS_TYPE_INVALID, NULL);
714 static void emit_rect(AtkObject *object, const char *name, const char *detail, AtkRectangle *rect)
717 char *path = spi_dbus_get_path(object);
718 DBusMessageIter iter, iter_variant, sub;
719 dbus_uint32_t x, y, width, height;
720 dbus_int32_t dummy = 0;
722 spi_dbus_update_cache(&this_app->droute);
726 height = rect->height;
727 sig = dbus_message_new_signal(path, "org.freedesktop.atspi.Accessible", name);
728 if (!detail) detail = "";
731 dbus_message_iter_init_append (sig, &iter);
732 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &detail);
733 dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &dummy);
734 dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &dummy);
735 if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(iiii)", &iter_variant))
737 if (!dbus_message_iter_open_container (&iter_variant, DBUS_TYPE_STRUCT, NULL, &sub))
739 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &x);
740 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &y);
741 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &width);
742 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &height);
743 if (!dbus_message_iter_close_container (&iter_variant, &sub))
745 if (!dbus_message_iter_close_container (&iter, &iter_variant))
748 dbus_connection_send(this_app->droute.bus, sig, NULL);
751 dbus_message_unref(sig);
754 static const char *PropertyChange = "object_property_change";
757 spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
758 guint n_param_values,
759 const GValue *param_values,
762 AtkPropertyValues *values;
764 const gchar *prop_name;
765 const gchar *sp = NULL;
769 const gchar *name = NULL;
771 #ifdef SPI_BRIDGE_DEBUG
772 GSignalQuery signal_query;
773 const gchar *signame;
776 g_signal_query (signal_hint->signal_id, &signal_query);
777 signame = signal_query.signal_name;
779 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
780 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
781 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
782 DBG (2, g_message ("Received (property) signal %s:%s:%s from object %s (gail %s)\n",
783 g_type_name (signal_query.itype), signame, values->property_name, s, s2));
787 obj = g_value_get_object (param_values + 0);
788 name = atk_object_get_name (obj);
789 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
791 prop_name = values->property_name;
792 if (strcmp (prop_name, "accessible-name") == 0)
794 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
796 else if (strcmp (prop_name, "accessible-description") == 0)
798 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
800 else if (strcmp (prop_name, "accessible-parent") == 0)
802 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
804 else if (strcmp (prop_name, "accessible-table-summary") == 0)
806 ao = atk_table_get_summary (ATK_TABLE (obj));
807 s_ao = spi_dbus_get_path(ao);
808 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_OBJECT_PATH, s_ao);
810 else if (strcmp (prop_name, "accessible-table-column-header") == 0)
812 i = g_value_get_int (&(values->new_value));
813 ao = atk_table_get_column_header (ATK_TABLE (obj), i);
814 s_ao = spi_dbus_get_path(ao);
815 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_OBJECT_PATH, s_ao);
817 else if (strcmp (prop_name, "accessible-table-row-header") == 0)
819 i = g_value_get_int (&(values->new_value));
820 ao = atk_table_get_row_header (ATK_TABLE (obj), i);
821 s_ao = spi_dbus_get_path(ao);
822 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_OBJECT_PATH, s_ao);
824 else if (strcmp (prop_name, "accessible-table-row-description") == 0)
826 i = g_value_get_int (&(values->new_value));
827 sp = atk_table_get_row_description (ATK_TABLE (obj), i);
828 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_STRING, sp);
830 else if (strcmp (prop_name, "accessible-table-column-description") == 0)
832 i = g_value_get_int (&(values->new_value));
833 sp = atk_table_get_column_description (ATK_TABLE(obj), i);
834 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_STRING, sp);
836 else if (strcmp (prop_name, "accessible-table-caption-object") == 0)
838 ao = atk_table_get_caption (ATK_TABLE(obj));
839 sp = atk_object_get_name (ao);
840 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_STRING, sp);
844 emit(obj, PropertyChange, prop_name, 0, 0, DBUS_TYPE_INVALID, NULL);
846 if (s_ao) g_free(s_ao);
851 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
852 guint n_param_values,
853 const GValue *param_values,
857 gchar *property_name;
858 unsigned long detail1;
859 #ifdef SPI_BRIDGE_DEBUG
860 GSignalQuery signal_query;
863 g_signal_query (signal_hint->signal_id, &signal_query);
864 name = signal_query.signal_name;
865 fprintf (stderr, "Received (state) signal %s:%s\n",
866 g_type_name (signal_query.itype), name);
869 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
870 property_name = g_strdup (g_value_get_string (param_values + 1));
871 /* Ignore defunct for now; we'll send a tree update to remove it when
872 the object goes away */
873 /* Also ignore state changes for objects not yet broadcast */
874 if ((property_name && !strcmp(property_name, "defunct")) ||
875 !spi_dbus_object_is_known(obj))
877 g_free(property_name);
880 detail1 = (g_value_get_boolean (param_values + 2))
882 emit(obj, "object_state_changed", property_name, detail1, 0, DBUS_TYPE_INVALID, NULL);
883 g_free (property_name);
888 spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent *keystroke,
889 AtkKeyEventStruct *event)
894 g_print ("event %c (%d)\n", (int) event->keyval, (int) event->keycode);
899 { /* this doesn't really need translating */
900 g_print (_("WARNING: NULL key event reported."));
903 keystroke->id = (dbus_int32_t) event->keyval;
904 keystroke->hw_code = (dbus_int16_t) event->keycode;
905 keystroke->timestamp = (dbus_uint32_t) event->timestamp;
906 keystroke->modifiers = (dbus_uint16_t) (event->state & 0xFFFF);
911 keystroke->event_string = g_strdup (event->string);
912 c = g_utf8_get_char_validated (event->string, -1);
913 if (c > 0 && g_unichar_isprint (c))
914 keystroke->is_text = TRUE;
916 keystroke->is_text = FALSE;
920 keystroke->event_string = g_strdup ("");
921 keystroke->is_text = FALSE;
925 case (ATK_KEY_EVENT_PRESS):
926 keystroke->type = Accessibility_KEY_PRESSED_EVENT;
928 case (ATK_KEY_EVENT_RELEASE):
929 keystroke->type = Accessibility_KEY_RELEASED_EVENT;
936 g_print ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
937 (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
938 (int) keystroke->modifiers,
939 keystroke->event_string, (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
943 static gboolean Accessibility_DeviceEventController_notifyListenersSync(const Accessibility_DeviceEvent *key_event)
945 DBusMessage *message = dbus_message_new_method_call(SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_REGISTRY, "org.freedesktop.atspi.DeviceEventController", "notifyListenersSync");
947 dbus_bool_t consumed = FALSE;
949 dbus_error_init(&error);
950 if (spi_dbus_marshal_deviceEvent(message, key_event))
952 DBusMessage *reply = dbus_connection_send_with_reply_and_block(this_app->droute.bus, message, 1000, &error);
956 dbus_error_init(&error);
957 dbus_message_get_args(reply, &error, DBUS_TYPE_BOOLEAN, &consumed, DBUS_TYPE_INVALID);
958 dbus_message_unref(reply);
961 dbus_message_unref(message);
966 spi_atk_bridge_key_listener (AtkKeyEventStruct *event, gpointer data)
969 Accessibility_DeviceEvent key_event;
971 spi_init_keystroke_from_atk_key_event (&key_event, event);
973 bridge_threads_leave ();
974 result = Accessibility_DeviceEventController_notifyListenersSync (&key_event);
975 bridge_threads_enter ();
977 if (key_event.event_string) g_free (key_event.event_string);
983 spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
984 guint n_param_values,
985 const GValue *param_values,
989 GSignalQuery signal_query;
991 const gchar *detail = NULL;
994 gint detail1 = 0, detail2 = 0;
998 #ifdef SPI_BRIDGE_DEBUG
1002 g_signal_query (signal_hint->signal_id, &signal_query);
1004 name = signal_query.signal_name;
1005 if (signal_hint->detail)
1007 detail = g_quark_to_string (signal_hint->detail);
1009 sig_name = g_strdup_printf("object_%s", name);
1010 while ((p = strchr(sig_name, '-')) != NULL) *p = '_';
1012 #ifdef SPI_BRIDGE_DEBUG
1013 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
1014 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
1015 fprintf (stderr, "Received signal %s:%s detail: %s from object %s (gail %s)\n",
1016 g_type_name (signal_query.itype), name,
1017 detail ? detail : "<NULL>", s ? s : "<NULL>" , s2);
1020 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
1022 if (signal_query.signal_id == atk_signal_active_descendant_changed)
1024 gpointer child = g_value_get_pointer (param_values + 1);
1026 g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
1028 ao = ATK_OBJECT (child);
1030 detail1 = atk_object_get_index_in_parent (ao);
1031 s_ao = spi_dbus_get_path(child);
1032 emit(obj, sig_name, detail, detail1, 0, DBUS_TYPE_OBJECT_PATH, s_ao);
1035 else if (signal_query.signal_id == atk_signal_link_selected)
1037 if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
1038 detail1 = g_value_get_int (param_values + 1);
1039 emit(obj, sig_name, detail, detail1, 0, DBUS_TYPE_INVALID, NULL);
1041 else if (signal_query.signal_id == atk_signal_bounds_changed)
1043 AtkRectangle *atk_rect = NULL;
1045 if (G_VALUE_HOLDS_BOXED (param_values + 1))
1046 atk_rect = g_value_get_boxed (param_values + 1);
1047 emit_rect(obj, sig_name, detail, atk_rect);
1049 else if ((signal_query.signal_id == atk_signal_children_changed) && obj)
1051 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
1055 if (n_param_values >= 2)
1057 if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
1058 detail1 = g_value_get_int (param_values + 1);
1059 if (n_param_values >= 3)
1061 if (G_VALUE_TYPE (param_values + 2) == G_TYPE_INT)
1062 detail2 = g_value_get_int (param_values + 2);
1066 if (signal_query.signal_id == atk_signal_text_changed)
1068 sp = atk_text_get_text (ATK_TEXT (obj),
1071 emit(obj, sig_name, detail, detail1, detail2, DBUS_TYPE_STRING, sp);
1073 else if (signal_query.signal_id == atk_signal_text_selection_changed)
1075 /* Return NULL as the selected string */
1076 emit(obj, sig_name, detail, detail1, detail2, DBUS_TYPE_STRING, "");
1080 emit(obj, sig_name, detail, 0, 0, DBUS_TYPE_INVALID, NULL);
1095 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
1096 guint n_param_values,
1097 const GValue *param_values,
1101 GSignalQuery signal_query;
1102 const gchar *name, *s;
1103 #ifdef SPI_BRIDGE_DEBUG
1107 g_signal_query (signal_hint->signal_id, &signal_query);
1109 name = signal_query.signal_name;
1112 #ifdef SPI_BRIDGE_DEBUG
1113 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
1114 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
1115 fprintf (stderr, "Received signal %s:%s from object %s (gail %s)\n",
1116 g_type_name (signal_query.itype), name, s ? s : "<NULL>" , s2);
1119 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
1121 s = atk_object_get_name (obj);
1122 sig_name = g_strdup_printf("window_%s", name);
1123 emit(obj, sig_name, NULL, 0, 0, DBUS_TYPE_STRING, s);
1130 spi_atk_bridge_document_event_listener (GSignalInvocationHint *signal_hint,
1131 guint n_param_values,
1132 const GValue *param_values,
1136 GSignalQuery signal_query;
1137 const gchar *name, *s;
1139 #ifdef SPI_BRIDGE_DEBUG
1143 g_signal_query (signal_hint->signal_id, &signal_query);
1145 name = signal_query.signal_name;
1147 #ifdef SPI_BRIDGE_DEBUG
1148 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
1149 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
1150 fprintf (stderr, "Received signal %s:%s from object %s (gail %s)\n",
1151 g_type_name (signal_query.itype), name, s ? s : "<NULL>" , s2);
1154 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
1156 s = atk_object_get_name (obj);
1157 sig_name = g_strdup_printf("document_%s", name);
1158 emit(obj, sig_name, NULL, 0, 0, DBUS_TYPE_STRING, s);
1164 spi_atk_tidy_windows (void)
1170 root = atk_get_root ();
1171 n_children = atk_object_get_n_accessible_children (root);
1172 for (i = 0; i < n_children; i++)
1175 AtkStateSet *stateset;
1178 child = atk_object_ref_accessible_child (root, i);
1179 stateset = atk_object_ref_state_set (child);
1181 name = atk_object_get_name (child);
1182 if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
1184 emit(child, "window:deactivate", NULL, 0, 0, DBUS_TYPE_STRING, name);
1186 g_object_unref (stateset);
1188 emit(child, "window:destroy", NULL, 0, 0, DBUS_TYPE_STRING, name);
1189 g_object_unref (child);
1194 reinit_register_vars (void)
1197 device_event_controller = NULL;