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., 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.
24 /* desktop.c: implements SpiDesktop.idl */
29 #include <atk/atkcomponent.h>
30 #include <gdk/gdkscreen.h>
33 #include <spi-common/spi-dbus.h>
38 G_DEFINE_TYPE(SpiDesktop, spi_desktop, G_TYPE_OBJECT)
40 /* SpiDesktop signals */
46 static guint spi_desktop_signals[LAST_SIGNAL];
49 /* Our parent Gtk object type */
50 #define PARENT_TYPE SPI_ACCESSIBLE_TYPE
57 static gboolean exiting = FALSE;
59 /* A pointer to our parent object class */
60 static GObjectClass *parent_class;
62 #define SPI_TYPE_ATK_DESKTOP (spi_atk_desktop_get_type ())
63 #define SPI_ATK_DESKTOP(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SPI_TYPE_ATK_DESKTOP, SpiAtkDesktop))
64 #define SPI_IS_ATK_DESKTOP(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SPI_TYPE_ATK_DESKTOP))
73 AtkObjectClass parent;
76 static void spi_atk_desktop_init (SpiAtkDesktop *desktop);
77 static void atk_component_interface_init (AtkComponentIface *iface);
78 static void spi_atk_desktop_get_extents (AtkComponent *component,
83 AtkCoordType coord_type);
86 spi_atk_desktop_get_type (void)
88 static GType type = 0;
92 static const GTypeInfo typeInfo =
94 sizeof (SpiAtkDesktopClass),
96 (GBaseFinalizeFunc) NULL,
97 (GClassInitFunc) NULL,
98 (GClassFinalizeFunc) NULL,
100 sizeof (SpiAtkDesktop),
102 (GInstanceInitFunc) spi_atk_desktop_init,
104 static const GInterfaceInfo atk_component_info =
106 (GInterfaceInitFunc) atk_component_interface_init,
107 (GInterfaceFinalizeFunc) NULL,
111 type = g_type_register_static (ATK_TYPE_OBJECT,
112 "SpiAtkDesktop", &typeInfo, 0);
113 g_type_add_interface_static (type, ATK_TYPE_COMPONENT,
114 &atk_component_info);
120 spi_atk_desktop_init (SpiAtkDesktop *desktop)
124 atk_object_set_name (ATK_OBJECT (desktop), "main");
125 display = gdk_x11_lookup_xdisplay (GDK_DISPLAY ());
126 desktop->screen = gdk_display_get_default_screen (display);
130 atk_component_interface_init (AtkComponentIface *iface)
132 g_return_if_fail (iface != NULL);
134 iface->get_extents = spi_atk_desktop_get_extents;
138 spi_atk_desktop_get_extents (AtkComponent *component,
143 AtkCoordType coord_type)
145 SpiAtkDesktop *desktop;
147 g_return_if_fail (SPI_IS_ATK_DESKTOP (component));
148 desktop = SPI_ATK_DESKTOP (component);
151 *width = gdk_screen_get_width (desktop->screen);
152 *height = gdk_screen_get_height (desktop->screen);
156 spi_desktop_init (SpiDesktop *desktop)
158 desktop->applications = NULL;
162 spi_desktop_dispose (GObject *object)
164 SpiDesktop *desktop = (SpiDesktop *) object;
166 while (desktop->applications)
168 Application *app = desktop->applications->data;
169 g_assert (app != NULL);
170 spi_desktop_remove_application (desktop, app->path);
173 G_OBJECT_CLASS (parent_class)->dispose (object);
177 impl_desktop_get_child_count (const char *path, DBusMessageIter * iter,
180 SpiDesktop *desktop = SPI_REGISTRY(user_data)->desktop;
182 if (desktop->applications)
184 return droute_return_v_int32(iter, g_list_length (desktop->applications));
188 return droute_return_v_int32(iter, 0);
193 impl_desktop_get_child_at_index (DBusConnection *bus, DBusMessage *message, void *user_data)
195 SpiDesktop *desktop = SPI_REGISTRY(user_data)->desktop;
202 dbus_error_init (&error);
203 if (!dbus_message_get_args (message, &error, DBUS_TYPE_INT32, &index, DBUS_TYPE_INVALID))
205 return spi_dbus_general_error (message);
207 app = g_list_nth_data (desktop->applications, index);
208 path = (app? app->path: SPI_DBUS_PATH_NULL);
210 reply = dbus_message_new_method_return (message);
213 dbus_message_append_args (reply, DBUS_TYPE_STRING, &path, DBUS_TYPE_INVALID);
220 impl_desktop_get_children (DBusConnection *bus, DBusMessage *message, void *user_data)
222 SpiDesktop *desktop = SPI_REGISTRY(user_data)->desktop;
229 DBusMessageIter iter, iter_array;
231 reply = dbus_message_new_method_return (message);
232 if (!reply) return NULL;
233 dbus_message_iter_init_append (reply, &iter);
234 if (!dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "o", &iter_array))
238 count = g_list_length (desktop->applications);
239 for (i = 0; i < count; i++)
241 app = g_list_nth_data (desktop->applications, i);
242 path = (app? app->path: SPI_DBUS_PATH_NULL);
243 dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_OBJECT_PATH, &path);
245 if (!dbus_message_iter_close_container (&iter, &iter_array))
251 // TODO: Handle out of memory
256 spi_desktop_exiting (void)
262 spi_desktop_class_init (SpiDesktopClass *klass)
264 GObjectClass * object_class = (GObjectClass *) klass;
266 object_class->dispose = spi_desktop_dispose;
268 parent_class = g_type_class_ref (G_TYPE_OBJECT);
270 spi_desktop_signals[APPLICATION_ADDED] =
271 g_signal_new ("application_added",
272 G_TYPE_FROM_CLASS (klass),
274 G_STRUCT_OFFSET (SpiDesktopClass, application_added),
276 g_cclosure_marshal_VOID__UINT,
279 spi_desktop_signals[APPLICATION_REMOVED] =
280 g_signal_new ("application_removed",
281 G_TYPE_FROM_CLASS (klass),
283 G_STRUCT_OFFSET (SpiDesktopClass, application_removed),
285 g_cclosure_marshal_VOID__UINT,
288 g_atexit (spi_desktop_exiting);
292 spi_desktop_new (void)
294 return g_object_new (SPI_DESKTOP_TYPE, NULL);
298 abnormal_application_termination (gpointer object, Application *app)
300 g_return_if_fail (SPI_IS_DESKTOP (app->desktop));
303 spi_desktop_remove_application (app->desktop, app->path);
307 spi_desktop_add_application (SpiDesktop *desktop,
308 const char *application)
312 g_return_if_fail (SPI_IS_DESKTOP (desktop));
314 spi_desktop_remove_application (desktop, application);
316 app = g_new (Application, 1);
317 app->desktop = desktop;
318 app->path = application;
320 desktop->applications = g_list_append (desktop->applications, app);
322 // TODO: Listen for termination, and call abnormal_application_termination
324 g_signal_emit (G_OBJECT (desktop),
325 spi_desktop_signals[APPLICATION_ADDED], 0,
326 g_list_index (desktop->applications, app));
330 spi_desktop_remove_application (SpiDesktop *desktop,
336 g_return_if_fail (path != NULL);
337 g_return_if_fail (SPI_IS_DESKTOP (desktop));
340 for (l = desktop->applications; l; l = l->next)
342 Application *app = (Application *) l->data;
344 if (!strcmp(app->path, path))
353 Application *app = (Application *) l->data;
355 desktop->applications = g_list_delete_link (desktop->applications, l);
357 // TODO: unlisten for broken app, if appropriate
360 g_signal_emit (G_OBJECT (desktop), spi_desktop_signals[APPLICATION_REMOVED], 0, idx);
364 static DRouteMethod methods[] =
366 { impl_desktop_get_child_at_index, "getChildAtIndex" },
367 { impl_desktop_get_children, "getChildren" },
371 static DRouteProperty properties[] =
373 { impl_desktop_get_child_count, NULL, "getChildCount" },
378 spi_registry_initialize_desktop_interface (DRouteData * data)
380 droute_add_interface (data, "org.freedesktop.atspi.Accessible", methods,
381 properties, NULL, NULL);