3 * AT-SPI - Assistive Technology Service Provider Interface
4 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
6 * Copyright 2001, 2002 Sun Microsystems Inc.,
7 * 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.
25 /* atspi_registry.c: Global functions wrapping the registry */
27 #include "atspi-private.h"
30 * atspi_get_desktop_count:
32 * Gets the number of virtual desktops.
33 * NOTE: multiple virtual desktops are not implemented yet; as a
34 * consequence, this function always returns 1.
36 * Returns: a #gint indicating the number of active virtual desktops.
39 atspi_get_desktop_count ()
46 * @i: a #gint indicating which of the accessible desktops is to be returned.
48 * Gets the virtual desktop indicated by index @i.
49 * NOTE: currently multiple virtual desktops are not implemented;
50 * as a consequence, any @i value different from 0 will not return a
51 * virtual desktop - instead it will return NULL.
53 * Returns: (transfer full): a pointer to the @i-th virtual desktop's
54 * #AtspiAccessible representation.
57 atspi_get_desktop (gint i)
59 if (i != 0) return NULL;
60 return _atspi_ref_accessible (atspi_bus_registry, atspi_path_root);
64 * atspi_get_desktop_list:
66 * Gets 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.
71 * NOTE: currently multiple virtual desktops are not implemented;
72 * this implementation always returns a #Garray with a single
73 * #AtspiAccessible desktop.
75 * Returns: (transfer full): a #GArray of desktops.
78 atspi_get_desktop_list ()
80 GArray *array = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
81 AtspiAccessible *desktop;
83 desktop = _atspi_ref_accessible (atspi_bus_registry, atspi_path_root);
85 g_array_index (array, AtspiAccessible *, 0) = desktop;
90 * atspi_register_keystroke_listener:
91 * @listener: a pointer to the #AtspiDeviceListener for which
92 * keystroke events are requested.
93 * @key_set: (element-type AtspiKeyDefinition) (allow-none): a pointer to the
94 * #AtspiKeyDefinition array indicating which keystroke events are
96 * to indicate that all keycodes and keyvals for the specified
97 * modifier set are to be included.
98 * @modmask: an #AtspiKeyMaskType mask indicating which
99 * key event modifiers must be set in combination with @keys,
100 * events will only be reported for key events for which all
101 * modifiers in @modmask are set. If you wish to listen for
102 * events with multiple modifier combinations, you must call
103 * #atspi_register_keystroke_listener once for each
105 * @event_types: an #AtspiKeyMaskType mask indicating which
106 * types of key events are requested (ATSPI_KEY_PRESSED etc.).
107 * @sync_type: an #AtspiKeyListenerSyncType parameter indicating
108 * the behavior of the notification/listener transaction.
110 * Registers a listener for keystroke events, either pre-emptively for
111 * all windows (ATSPI_KEYLISTENER_ALL_WINDOWS),
112 * non-preemptively (ATSPI_KEYLISTENER_NOSYNC), or
113 * pre-emptively at the toolkit level (ATSPI_KEYLISTENER_CANCONSUME).
114 * If ALL_WINDOWS or CANCONSUME are used, the event is consumed
115 * upon receipt if one of @listener's callbacks returns #TRUE
116 * (other sync_type values may be available in the future).
118 * Returns: #TRUE if successful, otherwise #FALSE.
121 atspi_register_keystroke_listener (AtspiDeviceListener *listener,
123 AtspiKeyMaskType modmask,
124 AtspiKeyEventMask event_types,
125 gint sync_type, GError **error)
128 gchar *path = _atspi_device_listener_get_path (listener);
130 dbus_uint32_t d_modmask = modmask;
131 dbus_uint32_t d_event_types = event_types;
132 AtspiEventListenerMode listener_mode;
133 gboolean retval = FALSE;
141 /* copy the keyval filter values from the C api into the DBind KeySet */
144 d_key_set = g_array_sized_new (FALSE, TRUE, sizeof (AtspiKeyDefinition), key_set->len);
145 d_key_set->len = key_set->len;
146 for (i = 0; i < key_set->len; ++i)
148 AtspiKeyDefinition *kd = ((AtspiKeyDefinition *) key_set->data) + i;
149 AtspiKeyDefinition *d_kd = ((AtspiKeyDefinition *) d_key_set->data) + i;
150 d_kd->keycode = kd->keycode;
151 d_kd->keysym = kd->keysym;
154 d_kd->keystring = kd->keystring;
158 d_kd->keystring = "";
164 d_key_set = g_array_sized_new (FALSE, TRUE, sizeof (AtspiKeyDefinition), 0);
167 listener_mode.synchronous =
168 (dbus_bool_t) ((sync_type & ATSPI_KEYLISTENER_SYNCHRONOUS)!=0);
169 listener_mode.preemptive =
170 (dbus_bool_t) ((sync_type & ATSPI_KEYLISTENER_CANCONSUME)!=0);
171 listener_mode.global =
172 (dbus_bool_t) ((sync_type & ATSPI_KEYLISTENER_ALL_WINDOWS)!=0);
174 dbus_error_init (&d_error);
175 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry, atspi_path_dec, atspi_interface_dec, "RegisterKeystrokeListener", &d_error, "oa(iisi)uu(bbb)=>b", path, d_key_set, d_modmask, d_event_types, &listener_mode, &retval);
177 g_array_free (d_key_set, TRUE);
184 * atspi_deregister_keystroke_listener:
185 * @listener: a pointer to the #AtspiDeviceListener for which
186 * keystroke events are requested.
187 * @key_set: (element-type AtspiKeyDefinition) (allow-none): a pointer to the
188 * #AtspiKeyDefinition array indicating which keystroke events are
190 * to indicate that all keycodes and keyvals for the specified
191 * modifier set are to be included.
192 * @modmask: the key modifier mask for which this listener is to be
193 * 'deregistered' (of type #AtspiKeyMaskType).
194 * @event_types: an #AtspiKeyMaskType mask indicating which
195 * types of key events were requested (#ATSPI_KEY_PRESSED, etc.).
197 * Removes a keystroke event listener from the registry's listener queue,
198 * ceasing notification of events with modifiers matching @modmask.
200 * Returns: #TRUE if successful, otherwise #FALSE.
203 atspi_deregister_keystroke_listener (AtspiDeviceListener *listener,
205 AtspiKeyMaskType modmask,
206 AtspiKeyEventMask event_types,
209 gchar *path = _atspi_device_listener_get_path (listener);
210 dbus_uint32_t d_modmask = modmask;
211 dbus_uint32_t d_event_types = event_types;
214 dbus_error_init (&d_error);
220 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry,
221 atspi_path_dec, atspi_interface_dec,
222 "DeregisterKeystrokeListener", &d_error,
223 "oa(iisi)uu", path, &key_set, d_modmask,
230 * atspi_register_device_event_listener:
231 * @listener: a pointer to the #AtspiDeviceListener which requests
233 * @event_types: an #AtspiDeviceEventMask mask indicating which
234 * types of key events are requested (#ATSPI_KEY_PRESSED, etc.).
235 * @filter: Unused parameter.
237 * Registers a listener for device events, for instance button events.
239 * Returns: #TRUE if successful, otherwise #FALSE.
242 atspi_register_device_event_listener (AtspiDeviceListener *listener,
243 AtspiDeviceEventMask event_types,
244 void *filter, GError **error)
246 gboolean retval = FALSE;
247 dbus_uint32_t d_event_types = event_types;
248 gchar *path = _atspi_device_listener_get_path (listener);
251 dbus_error_init (&d_error);
257 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry, atspi_path_dec, atspi_interface_dec, "RegisterDeviceEventListener", &d_error, "ou=>b", path, d_event_types, &retval);
263 * atspi_deregister_device_event_listener:
264 * @listener: a pointer to the #AtspiDeviceListener for which
265 * device events are requested.
266 * @filter: Unused parameter.
268 * Removes a device event listener from the registry's listener queue,
269 * ceasing notification of events of the specified type.
271 * Returns: #TRUE if successful, otherwise #FALSE.
274 atspi_deregister_device_event_listener (AtspiDeviceListener *listener,
275 void *filter, GError **error)
277 dbus_uint32_t event_types = 0;
278 gchar *path = _atspi_device_listener_get_path (listener);
281 dbus_error_init (&d_error);
288 event_types |= (1 << ATSPI_BUTTON_PRESSED_EVENT);
289 event_types |= (1 << ATSPI_BUTTON_RELEASED_EVENT);
291 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry, atspi_path_dec, atspi_interface_dec, "DeregisterDeviceEventListener", &d_error, "ou", path, event_types);
297 * atspi_generate_keyboard_event:
298 * @keyval: a #gint indicating the keycode or keysym of the key event
300 * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
301 * indicates a 'composed' keyboard input string
302 * being synthesized; this type of keyboard event synthesis does
303 * not emulate hardware keypresses but injects the string
304 * as though a composing input method (such as XIM) were used.
305 * @synth_type: an #AtspiKeySynthType flag indicating whether @keyval
306 * is to be interpreted as a keysym rather than a keycode
307 * (ATSPI_KEYSYM), or whether to synthesize
308 * ATSPI_KEY_PRESS, ATSPI_KEY_RELEASE, or both (ATSPI_KEY_PRESSRELEASE).
310 * Synthesizes a keyboard event (as if a hardware keyboard event occurred in the
311 * current UI context).
313 * Returns: #TRUE if successful, otherwise #FALSE.
316 atspi_generate_keyboard_event (glong keyval,
317 const gchar *keystring,
318 AtspiKeySynthType synth_type, GError **error)
320 dbus_uint32_t d_synth_type = synth_type;
321 dbus_int32_t d_keyval = keyval;
324 dbus_error_init (&d_error);
325 if (!keystring) keystring = "";
326 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry, atspi_path_dec, atspi_interface_dec, "GenerateKeyboardEvent", &d_error, "isu", d_keyval, keystring, d_synth_type);
332 * atspi_generate_mouse_event:
333 * @x: a #glong indicating the screen x coordinate of the mouse event.
334 * @y: a #glong indicating the screen y coordinate of the mouse event.
335 * @name: a string indicating which mouse event to be synthesized
336 * (e.g. "b1p", "b1c", "b2r", "rel", "abs").
338 * Synthesizes a mouse event at a specific screen coordinate.
339 * Most AT clients should use the #AccessibleAction interface when
340 * tempted to generate mouse events, rather than this method.
341 * Event names: b1p = button 1 press; b2r = button 2 release;
342 * b3c = button 3 click; b2d = button 2 double-click;
343 * abs = absolute motion; rel = relative motion.
345 * Returns: #TRUE if successful, otherwise #FALSE.
348 atspi_generate_mouse_event (glong x, glong y, const gchar *name, GError **error)
350 dbus_int32_t d_x = x, d_y = y;
353 dbus_error_init (&d_error);
354 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry,
355 atspi_path_dec, atspi_interface_dec,
356 "GenerateMouseEvent", &d_error, "iis",
362 atspi_key_definition_copy (AtspiKeyDefinition *src)
364 AtspiKeyDefinition *dst;
366 dst = g_new0 (AtspiKeyDefinition, 1);
367 dst->keycode = src->keycode;
368 dst->keysym = src->keysym;
370 dst->keystring = g_strdup (src->keystring);
371 dst->unused = src->unused;
376 atspi_key_definition_free (AtspiKeyDefinition *kd)
379 g_free (kd->keystring);
383 G_DEFINE_BOXED_TYPE (AtspiKeyDefinition, atspi_key_definition, atspi_key_definition_copy, atspi_key_definition_free)