2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001, 2002 Sun Microsystems Inc.,
6 * Copyright 2001, 2002 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.
26 #include <libbonobo.h>
27 #include "../cspi-lowlevel.h"
29 #include <X11/Xatom.h>
32 cspi_dup_ref (CORBA_Object object)
34 return bonobo_object_dup_ref (object, cspi_ev ());
38 cspi_release_unref (CORBA_Object object)
40 bonobo_object_release_unref (object, NULL);
44 cspi_check_ev (const char *error_string)
46 CORBA_Environment *ev = cspi_peek_ev ();
48 if (ev->_major != CORBA_NO_EXCEPTION)
52 err = bonobo_exception_get_text (ev);
54 if (!cspi_exception_throw (ev, (char *) error_string)) {
55 fprintf (stderr, "Warning: AT-SPI error: %s: %s\n",
61 CORBA_exception_free (ev);
72 cspi_exception_get_text (void)
76 txt = bonobo_exception_get_text (cspi_ev ());
84 * Returns a 'canonicalized' value for DISPLAY,
85 * with the screen number stripped off if present.
88 cspi_display_name (void)
90 static const char *canonical_display_name = NULL;
91 if (!canonical_display_name)
93 const gchar *display_env = g_getenv ("AT_SPI_DISPLAY");
96 display_env = g_getenv ("DISPLAY");
97 if (!display_env || !display_env[0])
98 canonical_display_name = ":0";
101 gchar *display_p, *screen_p;
102 canonical_display_name = g_strdup (display_env);
103 display_p = strrchr (canonical_display_name, ':');
104 screen_p = strrchr (canonical_display_name, '.');
105 if (screen_p && display_p && (screen_p > display_p))
113 canonical_display_name = display_env;
116 return canonical_display_name;
120 cspi_get_registry_ior (void)
125 unsigned char *data = NULL;
126 unsigned long nitems;
127 unsigned long leftover;
128 static Display *display = NULL;
130 display = XOpenDisplay (cspi_display_name ());
132 AT_SPI_IOR = XInternAtom (display, "AT_SPI_IOR", False);
133 XGetWindowProperty(display,
134 XDefaultRootWindow (display),
137 (Atom) 31, &actual_type, &actual_format,
138 &nitems, &leftover, &data);
140 g_warning ("AT_SPI_REGISTRY was not started at session startup.");
142 return (gchar *) data;
148 CORBA_Object registry = NULL;
149 CORBA_Environment ev;
152 if (!bonobo_init (NULL, NULL))
154 g_error ("Could not initialize Bonobo");
157 CORBA_exception_init (&ev);
159 ior = (char *) cspi_get_registry_ior ();
162 registry = CORBA_ORB_string_to_object (bonobo_activation_orb_get (),
166 if (ev._major != CORBA_NO_EXCEPTION)
168 g_error ("AT-SPI error: during registry activation: %s\n",
169 bonobo_exception_get_text (&ev));
172 if (registry == CORBA_OBJECT_NIL)
174 g_warning ("Could not locate registry");
183 cspi_ping (CORBA_Object object)
185 return bonobo_unknown_ping (object, NULL);
195 cspi_main_quit (void)