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.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 ();
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",
171 during_init_shutdown = FALSE;
175 static DBusObjectPathVTable droute_vtable =
179 NULL, NULL, NULL, NULL
183 spi_app_init (AtkObject *root)
186 dbus_error_init(&error);
187 SpiAppData *ad = (SpiAppData *)calloc(sizeof(SpiAppData), 1);
188 if (!ad) return NULL;
190 ad->droute.bus = dbus_bus_get(DBUS_BUS_SESSION, &error);
193 g_warning("Couldn't connect to dbus: %s\n", error.message);
197 //dbus_connection_set_exit_on_disconnect(ad->droute.bus, FALSE);
198 //dbus_bus_register(ad->droute.bus, &error);
199 spi_dbus_initialize (&ad->droute);
200 /* Below line for testing -- it should be removed once at-spi-registryd is working */
201 if (dbus_bus_request_name(ad->droute.bus, "test.atspi.tree", 0, &error)) printf("Got test name.\n");
202 spi_register_tree_object(ad->droute.bus, "/org/freedesktop/atspi/tree");
203 if (!dbus_connection_try_register_fallback (ad->droute.bus, "/org/freedesktop/atspi/accessible/", &droute_vtable, &ad->droute, &error))
205 g_warning("Couldn't register droute.\n");
207 dbus_connection_setup_with_g_main(ad->droute.bus, g_main_context_default());
212 atk_bridge_init (gint *argc, gchar **argv[])
214 const char *debug_env_string = g_getenv ("AT_SPI_DEBUG");
216 gboolean success = FALSE;
218 if (atk_bridge_initialized)
222 atk_bridge_initialized = TRUE;
223 atk_bridge_pid = getpid ();
225 misc = atk_misc_get_instance();
227 if (g_getenv ("ATK_BRIDGE_REDIRECT_LOG"))
229 fname = g_strconcat ("/tmp/", g_get_prgname (), ".at-spi-log", NULL);
230 /* make sure we're not being redirected - security issue */
231 if (!g_file_test (fname, G_FILE_TEST_IS_SYMLINK))
232 freopen (fname, "w", stderr);
236 if (debug_env_string)
237 _dbg = (int) g_ascii_strtod (debug_env_string, NULL);
239 /* Connect to dbus */
240 this_app = spi_app_init (atk_get_root ());
243 * We only want to enable the bridge for top level
244 * applications, we detect bonobo components by seeing
245 * if they were activated with the intention of extracting
246 * an impl. by IID - very solid.
249 // TODO: Figure out if this is still needed
250 if (bonobo_activation_iid_get ())
255 DBG (1, g_message ("Found Bonobo component\n"));
256 g_signal_connect (atk_get_root (),
257 "children-changed::add",
258 (GCallback) spi_atk_bridge_toplevel_added,
260 g_signal_connect (atk_get_root (),
261 "children-changed::remove",
262 (GCallback) spi_atk_bridge_toplevel_removed,
264 /* in this case we redefine 'success' to mean 'registry is present' */
265 success = (spi_atk_bridge_get_registry () != NULL);
269 success = spi_atk_bridge_do_registration ();
272 * we must emit events even if we are not registered as a
273 * full-fledged app; See bugzilla #400709.
277 spi_atk_register_event_listeners ();
278 spi_atk_bridge_init_event_type_consts ();
282 atk_bridge_initialized = FALSE;
284 g_idle_add (post_init, NULL);
290 spi_atk_bridge_do_registration (void)
292 if (spi_atk_bridge_get_registry () == NULL)
294 g_warning ("Could not locate registry");
298 /* Create the accessible application server object */
299 if (this_app == NULL)
300 this_app = spi_app_init (atk_get_root ());
302 DBG (1, g_message ("About to register application\n"));
304 spi_atk_bridge_register_application (spi_atk_bridge_get_registry ());
306 g_atexit (spi_atk_bridge_exit_func);
308 DBG (1, g_message ("Application registered & listening\n"));
313 spi_atk_bridge_toplevel_added (AtkObject *object,
319 spi_atk_bridge_do_registration ();
325 spi_atk_bridge_toplevel_removed (AtkObject *object,
332 deregister_application (this_app);
333 reinit_register_vars ();
337 g_warning ("More toplevels removed than added\n");
343 spi_atk_bridge_register_application (const char *registry)
345 bridge_threads_leave ();
347 bridge_threads_enter ();
351 * Returns a 'canonicalized' value for DISPLAY,
352 * with the screen number stripped off if present.
355 spi_display_name (void)
357 static const char *canonical_display_name = NULL;
358 if (!canonical_display_name)
360 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
363 display_env = g_getenv ("DISPLAY");
364 if (!display_env || !display_env[0])
365 canonical_display_name = ":0";
368 gchar *display_p, *screen_p;
369 canonical_display_name = g_strdup (display_env);
370 display_p = strrchr (canonical_display_name, ':');
371 screen_p = strrchr (canonical_display_name, '.');
372 if (screen_p && display_p && (screen_p > display_p))
380 canonical_display_name = display_env;
383 return canonical_display_name;
386 static Display *bridge_display = NULL;
389 spi_atk_bridge_get_registry_ior (void)
395 unsigned char *data = NULL;
396 unsigned long nitems;
397 unsigned long leftover;
399 bridge_display = XOpenDisplay (spi_display_name ());
401 AT_SPI_IOR = XInternAtom (bridge_display, "AT_SPI_IOR", False);
402 XGetWindowProperty(bridge_display,
403 XDefaultRootWindow (bridge_display),
406 (Atom) 31, &actual_type, &actual_format,
407 &nitems, &leftover, &data);
409 g_warning (_("AT_SPI_REGISTRY was not started at session startup."));
411 return (gchar *) data;
417 spi_atk_bridge_get_registry (void)
419 // TODO: check for registry dying, as the old code attempted to do
420 return "org.freedesktop.atspi.registry";
424 spi_atk_bridget_get_dec (void)
430 gtk_module_init (gint *argc, gchar **argv[])
432 return atk_bridge_init (argc, argv);
436 add_signal_listener (const char *signal_name)
440 id = atk_add_global_event_listener (
441 spi_atk_bridge_signal_listener, signal_name);
443 g_array_append_val (listener_ids, id);
447 spi_atk_register_event_listeners (void)
450 * kludge to make sure the Atk interface types are registered, otherwise
451 * the AtkText signal handlers below won't get registered
454 GObject *ao = g_object_new (ATK_TYPE_OBJECT, NULL);
455 AtkObject *bo = atk_no_op_object_new (ao);
458 if (atk_listeners_registered)
460 g_object_unref (G_OBJECT (bo));
465 atk_listeners_registered = TRUE;
467 /* Register for focus event notifications, and register app with central registry */
469 listener_ids = g_array_sized_new (FALSE, TRUE, sizeof (guint), 16);
471 atk_bridge_focus_tracker_id = atk_add_focus_tracker (spi_atk_bridge_focus_tracker);
473 id = atk_add_global_event_listener (spi_atk_bridge_property_event_listener,
474 "Gtk:AtkObject:property-change");
475 g_array_append_val (listener_ids, id);
476 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
478 g_array_append_val (listener_ids, id);
479 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
481 g_array_append_val (listener_ids, id);
482 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
484 g_array_append_val (listener_ids, id);
485 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
487 g_array_append_val (listener_ids, id);
488 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
490 g_array_append_val (listener_ids, id);
491 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
493 g_array_append_val (listener_ids, id);
494 id = atk_add_global_event_listener (spi_atk_bridge_window_event_listener,
495 "window:deactivate");
496 g_array_append_val (listener_ids, id);
497 id = atk_add_global_event_listener (spi_atk_bridge_document_event_listener,
498 "Gtk:AtkDocument:load-complete");
499 g_array_append_val (listener_ids, id);
500 id = atk_add_global_event_listener (spi_atk_bridge_document_event_listener,
501 "Gtk:AtkDocument:reload");
502 g_array_append_val (listener_ids, id);
503 id = atk_add_global_event_listener (spi_atk_bridge_document_event_listener,
504 "Gtk:AtkDocument:load-stopped");
505 g_array_append_val (listener_ids, id);
506 id = atk_add_global_event_listener (spi_atk_bridge_state_event_listener,
507 "Gtk:AtkObject:state-change");
508 g_array_append_val (listener_ids, id);
510 add_signal_listener ("Gtk:AtkObject:children-changed");
511 add_signal_listener ("Gtk:AtkObject:visible-data-changed");
512 add_signal_listener ("Gtk:AtkObject:active-descendant-changed");
513 add_signal_listener ("Gtk:AtkComponent:bounds-changed");
514 add_signal_listener ("Gtk:AtkSelection:selection-changed");
515 add_signal_listener ("Gtk:AtkText:text-selection-changed");
516 add_signal_listener ("Gtk:AtkText:text-changed");
517 add_signal_listener ("Gtk:AtkText:text-caret-moved");
518 add_signal_listener ("Gtk:AtkTable:row-inserted");
519 add_signal_listener ("Gtk:AtkTable:row-reordered");
520 add_signal_listener ("Gtk:AtkTable:row-deleted");
521 add_signal_listener ("Gtk:AtkTable:column-inserted");
522 add_signal_listener ("Gtk:AtkTable:column-reordered");
523 add_signal_listener ("Gtk:AtkTable:column-deleted");
524 add_signal_listener ("Gtk:AtkTable:model-changed");
525 add_signal_listener ("Gtk:AtkHypertext:link-selected");
527 * May add the following listeners to implement preemptive key listening for GTK+
529 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-press-event");
530 * atk_add_global_event_listener (spi_atk_bridge_widgetkey_listener, "Gtk:GtkWidget:key-release-event");
532 atk_bridge_key_event_listener_id = atk_add_key_event_listener (
533 spi_atk_bridge_key_listener, NULL);
535 g_object_unref (G_OBJECT (bo));
540 deregister_application (SpiAppData *app)
542 const char *registry = spi_atk_bridge_get_registry ();
543 bridge_threads_leave ();
545 bridge_threads_enter ();
549 spi_atk_bridge_exit_func (void)
551 SpiAppData *app = (SpiAppData *) this_app;
553 DBG (1, g_message ("exiting bridge\n"));
559 if (atk_bridge_pid != getpid ())
564 during_init_shutdown = TRUE;
567 * Check whether we still have windows which have not been deleted.
569 spi_atk_tidy_windows ();
571 * FIXME: this may be incorrect for apps that do their own bonobo
572 * shutdown, until we can explicitly shutdown to get the ordering
576 deregister_application (this_app);
578 DBG (1, g_message ("bridge exit func complete.\n"));
580 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
584 XCloseDisplay (bridge_display);
588 gnome_accessibility_module_init (void)
590 atk_bridge_init (NULL, NULL);
592 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
594 g_print("Atk Accessibility bridge initialized\n");
599 gnome_accessibility_module_shutdown (void)
602 GArray *ids = listener_ids;
604 if (!atk_bridge_initialized)
608 during_init_shutdown = TRUE;
609 atk_bridge_initialized = FALSE;
611 if (g_getenv ("AT_BRIDGE_SHUTDOWN"))
613 g_print("Atk Accessibility bridge shutdown\n");
617 if (atk_bridge_focus_tracker_id)
618 atk_remove_focus_tracker (atk_bridge_focus_tracker_id);
620 for (i = 0; ids && i < ids->len; i++)
622 atk_remove_global_event_listener (g_array_index (ids, guint, i));
625 if (atk_bridge_key_event_listener_id)
626 atk_remove_key_event_listener (atk_bridge_key_event_listener_id);
628 deregister_application (this_app);
634 static void emit(AtkObject *object, const char *name, int first_arg_type, ...)
638 char *path = spi_dbus_get_path(object);
640 spi_dbus_update_cache(&this_app->droute);
641 sig = dbus_message_new_signal(path, "org.freedesktop.atspi.Accessible", name);
642 va_start(args, first_arg_type);
643 if (first_arg_type != DBUS_TYPE_INVALID)
645 dbus_message_append_args_valist(sig, first_arg_type, args);
648 dbus_connection_send(this_app->droute.bus, sig, NULL);
650 dbus_message_unref(sig);
654 spi_atk_bridge_focus_tracker (AtkObject *object)
656 emit(object, "focus", DBUS_TYPE_INVALID);
659 static void emit_property_change(AtkObject *object, const char *name, int type, void *val)
662 char *path = spi_dbus_get_path(object);
663 DBusMessageIter iter, sub;
664 const char *type_as_string = NULL;
666 spi_dbus_update_cache(&this_app->droute);
667 if (type == DBUS_TYPE_OBJECT_PATH)
669 type_as_string = "o";
672 else if (type == DBUS_TYPE_STRING) type_as_string = "s";
673 else if (type == DBUS_TYPE_INT32) type_as_string = "i";
674 else if (type == DBUS_TYPE_UINT32) type_as_string = "o";
677 g_warning("Unknown type %d in property change signal", type);
679 sig = dbus_message_new_signal(path, "org.freedesktop.atspi.Accessible", "PropertyChanged");
680 dbus_message_iter_init_append(sig, &iter);
681 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
682 dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, type_as_string, &sub);
683 dbus_message_iter_append_basic(&sub, type, val);
684 dbus_message_iter_close_container(&iter, &sub);
685 dbus_connection_send(this_app->droute.bus, sig, NULL);
687 dbus_message_unref(sig);
690 static void emit_rect(AtkObject *object, const char *name, AtkRectangle *rect)
693 char *path = spi_dbus_get_path(object);
694 DBusMessageIter iter, sub;
695 dbus_uint32_t x, y, width, height;
697 spi_dbus_update_cache(&this_app->droute);
701 height = rect->height;
702 sig = dbus_message_new_signal(path, "org.freedesktop.atspi.Accessible", "PropertyChanged");
705 dbus_message_iter_init_append (sig, &iter);
706 dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
707 if (!dbus_message_iter_open_container
708 (&iter, DBUS_TYPE_STRUCT, NULL, &sub))
710 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &x);
711 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &y);
712 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &width);
713 dbus_message_iter_append_basic (&sub, DBUS_TYPE_INT32, &height);
714 if (!dbus_message_iter_close_container (&iter, &sub))
717 dbus_connection_send(this_app->droute.bus, sig, NULL);
720 dbus_message_unref(sig);
724 spi_atk_bridge_property_event_listener (GSignalInvocationHint *signal_hint,
725 guint n_param_values,
726 const GValue *param_values,
729 AtkPropertyValues *values;
731 const gchar *prop_name;
732 const gchar *sp = NULL;
736 const gchar *name = NULL;
738 #ifdef SPI_BRIDGE_DEBUG
739 GSignalQuery signal_query;
740 const gchar *signame;
743 g_signal_query (signal_hint->signal_id, &signal_query);
744 signame = signal_query.signal_name;
746 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
747 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
748 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
749 DBG (2, g_message ("Received (property) signal %s:%s:%s from object %s (gail %s)\n",
750 g_type_name (signal_query.itype), signame, values->property_name, s, s2));
754 obj = g_value_get_object (param_values + 0);
755 name = atk_object_get_name (obj);
756 values = (AtkPropertyValues*) g_value_get_pointer (param_values + 1);
758 prop_name = values->property_name;
759 if (strcmp (prop_name, "accessible-name") == 0)
761 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
763 else if (strcmp (prop_name, "accessible-description") == 0)
765 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
767 else if (strcmp (prop_name, "accessible-parent") == 0)
769 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
771 else if (strcmp (prop_name, "accessible-table-summary") == 0)
773 ao = atk_table_get_summary (ATK_TABLE (obj));
774 s_ao = spi_dbus_get_path(ao);
775 emit_property_change(obj, prop_name, DBUS_TYPE_OBJECT_PATH, s_ao);
777 else if (strcmp (prop_name, "accessible-table-column-header") == 0)
779 i = g_value_get_int (&(values->new_value));
780 ao = atk_table_get_column_header (ATK_TABLE (obj), i);
781 s_ao = spi_dbus_get_path(ao);
782 emit_property_change(obj, prop_name, DBUS_TYPE_OBJECT_PATH, s_ao);
784 else if (strcmp (prop_name, "accessible-table-row-header") == 0)
786 i = g_value_get_int (&(values->new_value));
787 ao = atk_table_get_row_header (ATK_TABLE (obj), i);
788 s_ao = spi_dbus_get_path(ao);
789 emit_property_change(obj, prop_name, DBUS_TYPE_OBJECT_PATH, s_ao);
791 else if (strcmp (prop_name, "accessible-table-row-description") == 0)
793 i = g_value_get_int (&(values->new_value));
794 sp = atk_table_get_row_description (ATK_TABLE (obj), i);
795 emit_property_change(obj, prop_name, DBUS_TYPE_STRING, (void *)&sp);
797 else if (strcmp (prop_name, "accessible-table-column-description") == 0)
799 i = g_value_get_int (&(values->new_value));
800 sp = atk_table_get_column_description (ATK_TABLE(obj), i);
801 emit_property_change(obj, prop_name, DBUS_TYPE_STRING, (void *)&sp);
803 else if (strcmp (prop_name, "accessible-table-caption-object") == 0)
805 ao = atk_table_get_caption (ATK_TABLE(obj));
806 sp = atk_object_get_name (ao);
807 emit_property_change(obj, prop_name, DBUS_TYPE_STRING, (void *)&sp);
812 emit_property_change(obj, prop_name, DBUS_TYPE_INT32, &v);
814 if (s_ao) g_free(s_ao);
819 spi_atk_bridge_state_event_listener (GSignalInvocationHint *signal_hint,
820 guint n_param_values,
821 const GValue *param_values,
825 gchar *property_name;
826 unsigned long detail1;
827 #ifdef SPI_BRIDGE_DEBUG
828 GSignalQuery signal_query;
831 g_signal_query (signal_hint->signal_id, &signal_query);
832 name = signal_query.signal_name;
833 fprintf (stderr, "Received (state) signal %s:%s\n",
834 g_type_name (signal_query.itype), name);
837 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
838 property_name = g_strdup (g_value_get_string (param_values + 1));
839 /* Ignore defunct for now; we'll send a tree update to remove it when
840 the object goes away */
841 /* Also ignore state changes for objects not yet broadcast */
842 if ((property_name && !strcmp(property_name, "defunct")) ||
843 !spi_dbus_object_is_known(obj))
845 g_free(property_name);
848 detail1 = (g_value_get_boolean (param_values + 2))
850 emit(obj, "StateChanged", DBUS_TYPE_STRING, &property_name, DBUS_TYPE_UINT32, &detail1, DBUS_TYPE_INVALID);
851 g_free (property_name);
857 spi_init_keystroke_from_atk_key_event (Accessibility_DeviceEvent *keystroke,
858 AtkKeyEventStruct *event)
863 g_print ("event %c (%d)\n", (int) event->keyval, (int) event->keycode);
868 { /* this doesn't really need translating */
869 g_print (_("WARNING: NULL key event reported."));
872 keystroke->id = (CORBA_long) event->keyval;
873 keystroke->hw_code = (CORBA_short) event->keycode;
874 keystroke->timestamp = (CORBA_unsigned_long) event->timestamp;
875 keystroke->modifiers = (CORBA_unsigned_short) (event->state & 0xFFFF);
880 keystroke->event_string = CORBA_string_dup (event->string);
881 c = g_utf8_get_char_validated (event->string, -1);
882 if (c > 0 && g_unichar_isprint (c))
883 keystroke->is_text = CORBA_TRUE;
885 keystroke->is_text = CORBA_FALSE;
889 keystroke->event_string = CORBA_string_dup ("");
890 keystroke->is_text = CORBA_FALSE;
894 case (ATK_KEY_EVENT_PRESS):
895 keystroke->type = Accessibility_KEY_PRESSED_EVENT;
897 case (ATK_KEY_EVENT_RELEASE):
898 keystroke->type = Accessibility_KEY_RELEASED_EVENT;
905 g_print ("key_event type %d; val=%d code=%d modifiers=%x name=%s is_text=%d, time=%lx\n",
906 (int) keystroke->type, (int) keystroke->id, (int) keystroke->hw_code,
907 (int) keystroke->modifiers,
908 keystroke->event_string, (int) keystroke->is_text, (unsigned long) keystroke->timestamp);
914 spi_atk_bridge_key_listener (AtkKeyEventStruct *event, gpointer data)
918 Accessibility_DeviceEvent key_event;
920 CORBA_exception_init (&ev);
922 spi_init_keystroke_from_atk_key_event (&key_event, event);
924 bridge_threads_leave ();
925 result = Accessibility_DeviceEventController_notifyListenersSync (
926 spi_atk_bridget_get_dec (), &key_event, &ev);
927 bridge_threads_enter ();
929 if (key_event.event_string) CORBA_free (key_event.event_string);
934 CORBA_exception_free (&ev);
942 spi_atk_bridge_signal_listener (GSignalInvocationHint *signal_hint,
943 guint n_param_values,
944 const GValue *param_values,
948 GSignalQuery signal_query;
953 gint detail1 = 0, detail2 = 0;
957 #ifdef SPI_BRIDGE_DEBUG
961 g_signal_query (signal_hint->signal_id, &signal_query);
963 name = signal_query.signal_name;
964 if (signal_hint->detail)
966 detail = g_quark_to_string (signal_hint->detail);
967 sig_name = g_strdup_printf("object_%s_%s", name, detail);
972 sig_name = g_strdup_printf("object_%s", name);
974 while ((p = strchr(sig_name, '-')) != NULL) *p = '_';
976 #ifdef SPI_BRIDGE_DEBUG
977 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
978 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
979 fprintf (stderr, "Received signal %s:%s detail: %s from object %s (gail %s)\n",
980 g_type_name (signal_query.itype), name,
981 detail ? detail : "<NULL>", s ? s : "<NULL>" , s2);
984 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
986 if (signal_query.signal_id == atk_signal_active_descendant_changed)
988 gpointer child = g_value_get_pointer (param_values + 1);
990 g_return_val_if_fail (ATK_IS_OBJECT (child), TRUE);
992 ao = ATK_OBJECT (child);
994 detail1 = atk_object_get_index_in_parent (ao);
995 s_ao = spi_dbus_get_path(child);
996 emit(obj, "name", DBUS_TYPE_OBJECT_PATH, s_ao, DBUS_TYPE_UINT32, &detail1, DBUS_TYPE_INVALID);
999 else if (signal_query.signal_id == atk_signal_link_selected)
1001 if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
1002 detail1 = g_value_get_int (param_values + 1);
1003 emit(obj, "LinkSelected", DBUS_TYPE_UINT32, &detail1, DBUS_TYPE_INVALID);
1005 else if (signal_query.signal_id == atk_signal_bounds_changed)
1007 AtkRectangle *atk_rect = NULL;
1009 if (G_VALUE_HOLDS_BOXED (param_values + 1))
1010 atk_rect = g_value_get_boxed (param_values + 1);
1011 emit_rect(obj, "BoundsChanged", atk_rect);
1013 else if ((signal_query.signal_id == atk_signal_children_changed) && obj)
1015 spi_dbus_notify_change(obj, FALSE, &this_app->droute);
1019 if (n_param_values >= 2)
1021 if (G_VALUE_TYPE (param_values + 1) == G_TYPE_INT)
1022 detail1 = g_value_get_int (param_values + 1);
1023 if (n_param_values >= 3)
1025 if (G_VALUE_TYPE (param_values + 2) == G_TYPE_INT)
1026 detail2 = g_value_get_int (param_values + 2);
1030 if (signal_query.signal_id == atk_signal_text_changed)
1032 sp = atk_text_get_text (ATK_TEXT (obj),
1035 emit(obj, sig_name, DBUS_TYPE_UINT32, &detail1, DBUS_TYPE_UINT32, &detail2, DBUS_TYPE_STRING, &sp, DBUS_TYPE_INVALID);
1037 else if (signal_query.signal_id == atk_signal_text_selection_changed)
1039 /* Return NULL as the selected string */
1041 emit(obj, sig_name, DBUS_TYPE_INVALID);
1045 emit(obj, sig_name, DBUS_TYPE_INVALID);
1060 spi_atk_bridge_window_event_listener (GSignalInvocationHint *signal_hint,
1061 guint n_param_values,
1062 const GValue *param_values,
1066 GSignalQuery signal_query;
1067 const gchar *name, *s;
1068 #ifdef SPI_BRIDGE_DEBUG
1072 g_signal_query (signal_hint->signal_id, &signal_query);
1074 name = signal_query.signal_name;
1077 #ifdef SPI_BRIDGE_DEBUG
1078 s2 = g_type_name (G_OBJECT_TYPE (g_value_get_object (param_values + 0)));
1079 s = atk_object_get_name (ATK_OBJECT (g_value_get_object (param_values + 0)));
1080 fprintf (stderr, "Received signal %s:%s from object %s (gail %s)\n",
1081 g_type_name (signal_query.itype), name, s ? s : "<NULL>" , s2);
1084 obj = ATK_OBJECT(g_value_get_object (param_values + 0));
1086 s = atk_object_get_name (obj);
1087 sig_name = g_strdup_printf("window_%s", name);
1088 emit(obj, sig_name, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
1095 spi_atk_bridge_document_event_listener (GSignalInvocationHint *signal_hint,
1096 guint n_param_values,
1097 const GValue *param_values,
1101 GSignalQuery signal_query;
1102 const gchar *name, *s;
1104 #ifdef SPI_BRIDGE_DEBUG
1108 g_signal_query (signal_hint->signal_id, &signal_query);
1110 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("document_%s", name);
1123 emit(obj, sig_name, DBUS_TYPE_STRING, &s, DBUS_TYPE_INVALID);
1129 spi_atk_tidy_windows (void)
1135 root = atk_get_root ();
1136 n_children = atk_object_get_n_accessible_children (root);
1137 for (i = 0; i < n_children; i++)
1140 AtkStateSet *stateset;
1143 child = atk_object_ref_accessible_child (root, i);
1144 stateset = atk_object_ref_state_set (child);
1146 name = atk_object_get_name (child);
1147 if (atk_state_set_contains_state (stateset, ATK_STATE_ACTIVE))
1149 emit(child, "window:deactivate", DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
1151 g_object_unref (stateset);
1153 emit(child, "window:destroy", DBUS_TYPE_STRING, &name, DBUS_TYPE_INVALID);
1154 g_object_unref (child);
1159 reinit_register_vars (void)
1162 device_event_controller = NULL;