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 ()
47 * @i: an integer indicating which of the accessible desktops is to be returned.
49 * Get the virtual desktop indicated by index @i.
50 * NOTE: currently multiple virtual desktops are not implemented, this
51 * function always returns '1'.
53 * Returns: a pointer to the 'i-th' virtual desktop's #Accessible representation.
56 SPI_getDesktop (int i)
58 if (i != 0) return NULL;
59 return cspi_ref_accessible (spi_bus_registry, NULL);
64 * @desktop_list: a pointer to an array of #Accessible references.
66 * Get the list of virtual desktops. On return, @list will point
67 * to a newly-created, NULL terminated array of virtual desktop
69 * It is the responsibility of the caller to free this array when
70 * it is no longer needed.
72 * Not Yet Implemented : this implementation always returns a single
73 * #Accessible desktop.
75 * Returns: an integer indicating how many virtual desktops have been
76 * placed in the list pointed to by parameter @list.
79 SPI_getDesktopList (Accessible ***desktop_list)
83 list = g_new0 (Accessible *, 2);
85 if (!desktop_list) return 1;
86 list [0] = cspi_ref_accessible (spi_bus_registry, NULL);
94 * SPI_freeDesktopList:
95 * @desktop_list: a pointer to an array of #Accessible objects
96 * as returned from @SPI_getDesktopList
98 * This routine frees the memory associated with the list.
101 SPI_freeDesktopList (Accessible **desktop_list)
105 for (p = desktop_list; p && *p; p++)
107 cspi_object_unref (*p);
109 g_free (desktop_list);
113 * SPI_KEYSET_ALL_KEYS:
114 * @SPI_KEYSET_ALL_KEYS: A special value for an AccessibleKeySet type, which tacitly
115 * includes all keycodes and keyvals for the specified modifier set.
119 * SPI_registerAccessibleKeystrokeListener:
120 * @listener: a pointer to the #AccessibleKeystrokeListener for which
121 * keystroke events are requested.
122 * @keys: a pointer to the #AccessibleKeySet indicating which
123 * keystroke events are requested, or #SPI_KEYSET_ALL_KEYS
124 * to indicate that all keycodes and keyvals for the specified
125 * modifier set are to be included.
126 * @modmask: an #AccessibleKeyMaskType mask indicating which
127 * key event modifiers must be set in combination with @keys,
128 * events will only be reported for key events for which all
129 * modifiers in @modmask are set. If you wish to listen for
130 * events with multiple modifier combinations you must call
131 * registerAccessibleKeystrokeListener() once for each combination.
132 * @eventmask: an #AccessibleKeyMaskType mask indicating which
133 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
134 * @sync_type: a #AccessibleKeyListenerSyncType parameter indicating
135 * the behavior of the notification/listener transaction.
137 * Register a listener for keystroke events, either pre-emptively for
138 * all windows (SPI_KEYLISTENER_ALL_WINDOWS),
139 * non-preemptively (SPI_KEYLISTENER_NOSYNC), or
140 * pre-emptively at the toolkit level (SPI_KEYLISTENER_CANCONSUME).
141 * If ALL_WINDOWS or CANCONSUME are used, the event is consumed
142 * upon receipt if one of @listener's callbacks returns #TRUE.
143 * ( Other sync_type values may be available in the future )
145 * Returns: #TRUE if successful, otherwise #FALSE.
148 SPI_registerAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
149 AccessibleKeySet *keys,
150 AccessibleKeyMaskType modmask,
151 AccessibleKeyEventMask eventmask,
152 AccessibleKeyListenerSyncType sync_type)
154 gchar *path = cspi_device_listener_get_path (listener);
157 dbus_uint32_t key_events = 0;
158 Accessibility_ControllerEventMask controller_event_mask;
159 Accessibility_EventListenerMode listener_mode;
161 SPIBoolean retval = FALSE;
168 /* copy the keyval filter values from the C api into the DBind KeySet */
171 key_set = g_array_sized_new (FALSE, TRUE, sizeof (Accessibility_KeyDefinition), keys->len);
172 key_set->len = keys->len;
173 for (i = 0; i < keys->len; ++i)
175 Accessibility_KeyDefinition *kd = ((Accessibility_KeyDefinition *) key_set->data) + i;
176 kd->keycode = keys->keycodes[i];
177 kd->keysym = keys->keysyms[i];
178 if (keys->keystrings && keys->keystrings[i])
180 kd->keystring = keys->keystrings[i];
190 key_set = g_array_sized_new (FALSE, TRUE, sizeof (Accessibility_KeyDefinition), 0);
193 /* copy the event filter values from the C api into the DBus key_events */
194 if (eventmask & SPI_KEY_PRESSED)
196 key_events |= (1 << Accessibility_KEY_PRESSED_EVENT);
198 if (eventmask & SPI_KEY_RELEASED)
200 key_events |= (1 << Accessibility_KEY_RELEASED_EVENT);
203 controller_event_mask = (dbus_uint32_t) modmask;
205 listener_mode.synchronous =
206 (dbus_bool_t) ((sync_type & SPI_KEYLISTENER_SYNCHRONOUS)!=0);
207 listener_mode.preemptive =
208 (dbus_bool_t) ((sync_type & SPI_KEYLISTENER_CANCONSUME)!=0);
209 listener_mode.global =
210 (dbus_bool_t) ((sync_type & SPI_KEYLISTENER_ALL_WINDOWS)!=0);
212 dbus_error_init (&error);
213 dbind_method_call_reentrant (SPI_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);
215 g_array_free (key_set, TRUE);
222 * SPI_deregisterAccessibleKeystrokeListener:
223 * @listener: a pointer to the #AccessibleKeystrokeListener for which
224 * keystroke events are requested.
225 * @modmask: the key modifier mask for which this listener is to be
226 * 'deregistered' (of type #AccessibleeyMaskType).
228 * Removes a keystroke event listener from the registry's listener queue,
229 * ceasing notification of events with modifiers matching @modmask.
231 * Returns: #TRUE if successful, otherwise #FALSE.
234 SPI_deregisterAccessibleKeystrokeListener (AccessibleKeystrokeListener *listener,
235 AccessibleKeyMaskType modmask)
237 gchar *path = cspi_device_listener_get_path (listener);
238 Accessibility_ControllerEventMask controller_event_mask;
240 dbus_uint32_t key_events = 0;
249 controller_event_mask = (dbus_uint32_t) modmask;
251 key_set = g_array_sized_new (FALSE, TRUE, sizeof (Accessibility_KeyDefinition), 0);
252 dbind_method_call_reentrant (SPI_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "deregisterKeystrokeListener", &error, "oa(iisi)uu", path, &key_set, key_events, controller_event_mask);
258 * SPI_registerDeviceEventListener:
259 * @listener: a pointer to the #AccessibleDeviceListener which requests
261 * @eventmask: an #AccessibleDeviceEventMask mask indicating which
262 * types of key events are requested (#SPI_KEY_PRESSED, etc.).
263 * @filter: Unused parameter.
265 * Register a listener for device events, for instance button events.
267 * Returns: #TRUE if successful, otherwise #FALSE.
270 SPI_registerDeviceEventListener (AccessibleDeviceListener *listener,
271 AccessibleDeviceEventMask eventmask,
274 SPIBoolean retval = FALSE;
275 dbus_uint32_t event_types = 0;
277 gchar *path = cspi_device_listener_get_path (listener);
285 /* copy the event filter values from the C api into the CORBA KeyEventTypeSeq */
287 if (eventmask & SPI_BUTTON_PRESSED)
289 event_types |= (1 << Accessibility_BUTTON_PRESSED_EVENT);
291 if (eventmask & SPI_BUTTON_RELEASED)
293 event_types |= (1 << Accessibility_BUTTON_RELEASED_EVENT);
296 dbus_error_init (&error);
297 dbind_method_call_reentrant (SPI_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "registerDeviceEventListener", &error, "ou=>b", path, event_types, &retval);
303 * SPI_deregisterDeviceEventListener:
304 * @listener: a pointer to the #AccessibleDeviceListener for which
305 * device events are requested.
306 * @filter: Unused parameter.
308 * Removes a device event listener from the registry's listener queue,
309 * ceasing notification of events of the specified type.
311 * Returns: #TRUE if successful, otherwise #FALSE.
314 SPI_deregisterDeviceEventListener (AccessibleDeviceListener *listener,
317 dbus_uint32_t event_types = 0;
318 gchar *path = cspi_device_listener_get_path (listener);
326 event_types |= (1 << Accessibility_BUTTON_PRESSED_EVENT);
327 event_types |= (1 << Accessibility_BUTTON_RELEASED_EVENT);
329 dbus_error_init (&error);
330 dbind_method_call_reentrant (SPI_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "deregisterDeviceEventListener", &error, "ou", path, event_types);
336 * SPI_generateKeyboardEvent:
337 * @keyval: a long integer indicating the keycode or keysym of the key event
339 * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
340 * indicates a 'composed' keyboard input string which is
341 * being synthesized; this type of keyboard event synthesis does
342 * not emulate hardware keypresses but injects the string
343 * as though a composing input method (such as XIM) were used.
344 * @synth_type: a #AccessibleKeySynthType flag indicating whether @keyval
345 * is to be interpreted as a keysym rather than a keycode
346 * (CSPI_KEYSYM), or whether to synthesize
347 * SPI_KEY_PRESS, SPI_KEY_RELEASE, or both (SPI_KEY_PRESSRELEASE).
349 * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
350 * current UI context).
352 * Returns: #TRUE if successful, otherwise #FALSE.
355 SPI_generateKeyboardEvent (long int keyval,
357 AccessibleKeySynthType synth_type)
359 dbus_uint32_t keysynth_type;
360 dbus_int32_t keycode = keyval;
366 keysynth_type = Accessibility_KEY_PRESS;
368 case SPI_KEY_RELEASE:
369 keysynth_type = Accessibility_KEY_RELEASE;
371 case SPI_KEY_PRESSRELEASE:
372 keysynth_type = Accessibility_KEY_PRESSRELEASE;
375 keysynth_type = Accessibility_KEY_SYM;
378 keysynth_type = Accessibility_KEY_STRING;
384 if (!keystring) keystring = "";
385 dbus_error_init (&error);
386 dbind_method_call_reentrant (SPI_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "generateKeyboardEvent", &error, "isu", keycode, keystring, keysynth_type);
392 * SPI_generateMouseEvent:
393 * @x: a #long indicating the screen x coordinate of the mouse event.
394 * @y: a #long indicating the screen y coordinate of the mouse event.
395 * @name: a string indicating which mouse event to be synthesized
396 * (e.g. "b1p", "b1c", "b2r", "rel", "abs").
398 * Synthesize a mouse event at a specific screen coordinate.
399 * Most AT clients should use the #AccessibleAction interface when
400 * tempted to generate mouse events, rather than this method.
401 * Event names: b1p = button 1 press; b2r = button 2 release;
402 * b3c = button 3 click; b2d = button 2 double-click;
403 * abs = absolute motion; rel = relative motion.
405 * Returns: #TRUE if successful, otherwise #FALSE.
408 SPI_generateMouseEvent (long x, long y, char *name)
410 dbus_int32_t dbus_x = x, dbus__y = y;
413 dbus_error_init (&error);
414 dbind_method_call_reentrant (SPI_bus(), spi_bus_registry, spi_path_dec, spi_interface_dec, "generateMouseEvent", &error, "iis", x, y, name);
419 cspi_device_listener_get_path (CSpiDeviceListener *listener)
421 return g_strdup_printf ("/org/freedesktop/atspi/listeners/%d", listener->id);