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.
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 /* spi_registry.c: Global functions wrapping the registry */
26 #include <cspi/spi-private.h>
28 static GArray *desktops;
31 * SPI_getDesktopCount:
33 * Get the number of virtual desktops.
34 * NOTE: currently multiple virtual desktops are not implemented, this
35 * function always returns '1'.
37 * Returns: an integer indicating the number of active virtual desktops.
40 SPI_getDesktopCount ()
42 if (!desktops) SPI_getDesktopList (NULL);
43 if (!desktops) return -1;
49 * @i: an integer indicating which of the accessible desktops is to be returned.
51 * Get the virtual desktop indicated by index @i.
52 * NOTE: currently multiple virtual desktops are not implemented, this
53 * function always returns '1'.
55 * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
58 SPI_getDesktop (int i)
60 if (!desktops) SPI_getDesktopList (NULL);
61 if (!desktops) return NULL;
62 return cspi_ref_accessible (spi_bus_registry, g_array_index (desktops, char *, i));
67 * @desktop_list: a pointer to an array of #Accessible references.
69 * Get the list of virtual desktops. On return, @list will point
70 * to a newly-created, NULL terminated array of virtual desktop
72 * It is the responsibility of the caller to free this array when
73 * it is no longer needed.
75 * Not Yet Implemented : this implementation always returns a single
76 * #Accessible desktop.
78 * Returns: an integer indicating how many virtual desktops have been
79 * placed in the list pointed to by parameter @list.
82 SPI_getDesktopList (Accessible ***desktop_list)
87 if (desktop_list) *desktop_list = NULL;
91 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_registry, spi_interface_registry, "getDesktopList", NULL, "=>ao", &desktops);
92 if (!desktops) return 0;
95 list = g_new0 (Accessible *, desktops->len + 1);
97 if (!desktop_list) return desktops->len;
98 for (i = 0; i < desktops->len; i++)
100 list [i] = cspi_ref_accessible (spi_bus_registry, g_array_index (desktops, char *, i));
104 *desktop_list = list;
110 * SPI_freeDesktopList:
111 * @desktop_list: a pointer to an array of #Accessible objects
112 * as returned from @SPI_getDesktopList
114 * This routine frees the memory associated with the list.
117 SPI_freeDesktopList (Accessible **desktop_list)
121 for (p = desktop_list; p && *p; p++)
123 cspi_object_unref (*p);
125 g_free (desktop_list);
129 * SPI_KEYSET_ALL_KEYS:
130 * @SPI_KEYSET_ALL_KEYS: A special value for an AccessibleKeySet type, which tacitly
131 * includes all keycodes and keyvals for the specified modifier set.
135 * SPI_registerAccessibleKeystrokeListener:
136 * @listener: a pointer to the #AccessibleKeystrokeListener for which
137 * keystroke events are requested.
138 * @keys: a pointer to the #AccessibleKeySet indicating which
139 * keystroke events are requested, or #SPI_KEYSET_ALL_KEYS
140 * to indicate that all keycodes and keyvals for the specified
141 * modifier set are to be included.
142 * @modmask: an #AccessibleKeyMaskType mask indicating which
143 * key event modifiers must be set in combination with @keys,
144 * events will only be reported for key events for which all
145 * modifiers in @modmask are set. If you wish to listen for
146 * events with multiple modifier combinations you must call
147 * registerAccessibleKeystrokeListener() once for each combination.
148 * @eventmask: an #AccessibleKeyMaskType mask indicating which
149 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
150 * @sync_type: a #AccessibleKeyListenerSyncType parameter indicating
151 * the behavior of the notification/listener transaction.
153 * Register a listener for keystroke events, either pre-emptively for
154 * all windows (SPI_KEYLISTENER_ALL_WINDOWS),
155 * non-preemptively (SPI_KEYLISTENER_NOSYNC), or
156 * pre-emptively at the toolkit level (SPI_KEYLISTENER_CANCONSUME).
157 * If ALL_WINDOWS or CANCONSUME are used, the event is consumed
158 * upon receipt if one of @listener's callbacks returns #TRUE.
159 * ( Other sync_type values may be available in the future )
161 * Returns: #TRUE if successful, otherwise #FALSE.
164 SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
165 AccessibleKeySet *keys,
166 AccessibleKeyMaskType modmask,
167 AccessibleKeyEventMask eventmask,
168 AccessibleKeyListenerSyncType sync_type)
170 gchar *path = cspi_device_listener_get_path (listener);
173 dbus_uint32_t key_events = 0;
174 Accessibility_ControllerEventMask controller_event_mask;
175 Accessibility_EventListenerMode listener_mode;
177 SPIBoolean retval = FALSE;
184 /* copy the keyval filter values from the C api into the DBind KeySet */
187 key_set = g_array_sized_new (FALSE, TRUE, sizeof (Accessibility_KeyDefinition), keys->len);
188 key_set->len = keys->len;
189 for (i = 0; i < keys->len; ++i)
191 Accessibility_KeyDefinition *kd = ((Accessibility_KeyDefinition *) key_set->data) + i;
192 kd->keycode = keys->keycodes[i];
193 kd->keysym = keys->keysyms[i];
194 if (keys->keystrings && keys->keystrings[i])
196 kd->keystring = keys->keystrings[i];
206 key_set = g_array_sized_new (FALSE, TRUE, sizeof (Accessibility_KeyDefinition), 0);
209 /* copy the event filter values from the C api into the DBus key_events */
210 if (eventmask & SPI_KEY_PRESSED)
212 key_events |= (1 << Accessibility_KEY_PRESSED_EVENT);
214 if (eventmask & SPI_KEY_RELEASED)
216 key_events |= (1 << Accessibility_KEY_RELEASED_EVENT);
219 controller_event_mask = (dbus_uint32_t) modmask;
221 listener_mode.synchronous =
222 (dbus_bool_t) ((sync_type & SPI_KEYLISTENER_SYNCHRONOUS)!=0);
223 listener_mode.preemptive =
224 (dbus_bool_t) ((sync_type & SPI_KEYLISTENER_CANCONSUME)!=0);
225 listener_mode.global =
226 (dbus_bool_t) ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0);
228 dbus_error_init (&error);
229 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "registerKeystrokeListener", &error, "oa(iisi)uu(bbb)=>b", path, key_set, controller_event_mask, key_set, &listener_mode, &retval);
231 g_array_free (key_set, TRUE);
238 * SPI_deregisterAccessibleKeystrokeListener:
239 * @listener: a pointer to the #AccessibleKeystrokeListener for which
240 * keystroke events are requested.
241 * @modmask: the key modifier mask for which this listener is to be
242 * 'deregistered' (of type #AccessibleeyMaskType).
244 * Removes a keystroke event listener from the registry's listener queue,
245 * ceasing notification of events with modifiers matching @modmask.
247 * Returns: #TRUE if successful, otherwise #FALSE.
250 SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
251 AccessibleKeyMaskType modmask)
253 gchar *path = cspi_device_listener_get_path (listener);
254 Accessibility_ControllerEventMask controller_event_mask;
256 dbus_uint32_t key_events = 0;
265 controller_event_mask = (dbus_uint32_t) modmask;
267 key_set = g_array_sized_new (FALSE, TRUE, sizeof (Accessibility_KeyDefinition), 0);
268 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "deregisterKeystrokeListener", &error, "oa(iisi)uu", path, &key_set, key_events, controller_event_mask);
274 * SPI_registerDeviceEventListener:
275 * @listener: a pointer to the #AccessibleDeviceListener which requests
277 * @eventmask: an #AccessibleDeviceEventMask mask indicating which
278 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
279 * @filter: Unused parameter.
281 * Register a listener for device events, for instance button events.
283 * Returns: #TRUE if successful, otherwise #FALSE.
286 SPI_registerDeviceEventListener (AccessibleDeviceListener *listener,
287 AccessibleDeviceEventMask eventmask,
290 SPIBoolean retval = FALSE;
291 dbus_uint32_t event_types = 0;
293 gchar *path = cspi_device_listener_get_path (listener);
301 /* copy the event filter values from the C api into the CORBA KeyEventTypeSeq */
303 if (eventmask & SPI_BUTTON_PRESSED)
305 event_types |= (1 << Accessibility_BUTTON_PRESSED_EVENT);
307 if (eventmask & SPI_BUTTON_RELEASED)
309 event_types |= (1 << Accessibility_BUTTON_RELEASED_EVENT);
312 dbus_error_init (&error);
313 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "registerDeviceEventListener", &error, "ou=>b", path, event_types, &retval);
319 * SPI_deregisterDeviceEventListener:
320 * @listener: a pointer to the #AccessibleDeviceListener for which
321 * device events are requested.
322 * @filter: Unused parameter.
324 * Removes a device event listener from the registry's listener queue,
325 * ceasing notification of events of the specified type.
327 * Returns: #TRUE if successful, otherwise #FALSE.
330 SPI_deregisterDeviceEventListener (AccessibleDeviceListener *listener,
333 dbus_uint32_t event_types = 0;
334 gchar *path = cspi_device_listener_get_path (listener);
342 event_types |= (1 << Accessibility_BUTTON_PRESSED_EVENT);
343 event_types |= (1 << Accessibility_BUTTON_RELEASED_EVENT);
345 dbus_error_init (&error);
346 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "deregisterDeviceEventListener", &error, "ou", path, event_types);
352 * SPI_generateKeyboardEvent:
353 * @keyval: a long integer indicating the keycode or keysym of the key event
355 * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
356 * indicates a 'composed' keyboard input string which is
357 * being synthesized; this type of keyboard event synthesis does
358 * not emulate hardware keypresses but injects the string
359 * as though a composing input method (such as XIM) were used.
360 * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
361 * is to be interpreted as a keysym rather than a keycode
362 * (CSPI_KEYSYM), or whether to synthesize
363 * SPI_KEY_PRESS, SPI_KEY_RELEASE, or both (SPI_KEY_PRESSRELEASE).
365 * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
366 * current UI context).
368 * Returns: #TRUE if successful, otherwise #FALSE.
371 SPI_generateKeyboardEvent (long int keyval,
373 AccessibleKeySynthType synth_type)
375 dbus_uint32_t keysynth_type;
376 dbus_int32_t keycode = keyval;
382 keysynth_type = Accessibility_KEY_PRESS;
384 case SPI_KEY_RELEASE:
385 keysynth_type = Accessibility_KEY_RELEASE;
387 case SPI_KEY_PRESSRELEASE:
388 keysynth_type = Accessibility_KEY_PRESSRELEASE;
391 keysynth_type = Accessibility_KEY_SYM;
394 keysynth_type = Accessibility_KEY_STRING;
400 if (!keystring) keystring = "";
401 dbus_error_init (&error);
402 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "generateKeyboardEvent", &error, "isu", keycode, keystring, keysynth_type);
408 * SPI_generateMouseEvent:
409 * @x: a #long indicating the screen x coordinate of the mouse event.
410 * @y: a #long indicating the screen y coordinate of the mouse event.
411 * @name: a string indicating which mouse event to be synthesized
412 * (e.g. "b1p", "b1c", "b2r", "rel", "abs").
414 * Synthesize a mouse event at a specific screen coordinate.
415 * Most AT clients should use the #AccessibleAction interface when
416 * tempted to generate mouse events, rather than this method.
417 * Event names: b1p = button 1 press; b2r = button 2 release;
418 * b3c = button 3 click; b2d = button 2 double-click;
419 * abs = absolute motion; rel = relative motion.
421 * Returns: #TRUE if successful, otherwise #FALSE.
424 SPI_generateMouseEvent (long x, long y, char *name)
426 dbus_int32_t dbus_x = x, dbus__y = y;
429 dbus_error_init (&error);
430 dbind_connection_method_call (cspi_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "generateMouseEvent", &error, "iis", x, y, name);
435 cspi_device_listener_get_path (CSpiDeviceListener *listener)
437 return g_strdup_printf ("/org/freedesktop/atspi/listeners/%d", listener->id);