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 /* atspi_registry.c: Global functions wrapping the registry */
26 #include "atspi-private.h"
29 * atspi_get_desktop_count:
31 * Get the number of virtual desktops.
32 * NOTE: currently multiple virtual desktops are not implemented, this
33 * function always returns '1'.
35 * Returns: an integer indicating the number of active virtual desktops.
38 atspi_get_desktop_count ()
45 * @i: an integer indicating which of the accessible desktops is to be returned.
47 * Get the virtual desktop indicated by index @i.
48 * NOTE: currently multiple virtual desktops are not implemented.
50 * Returns: (transfer full): a pointer to the 'i-th' virtual desktop's
51 * #AtspiAccessible representation.
54 atspi_get_desktop (gint i)
56 if (i != 0) return NULL;
57 return _atspi_ref_accessible (atspi_bus_registry, atspi_path_root);
61 * atspi_get_desktop_list:
63 * Get the list of virtual desktops. On return, @list will point
64 * to a newly-created, NULL terminated array of virtual desktop
66 * It is the responsibility of the caller to free this array when
67 * it is no longer needed.
69 * Not Yet Implemented : this implementation always returns a single
70 * #Accessible desktop.
72 * Returns: (transfer full): a #GArray of desktops.
75 atspi_get_desktop_list ()
77 GArray *array = g_array_new (TRUE, TRUE, sizeof (AtspiAccessible *));
78 AtspiAccessible *desktop;
80 desktop = _atspi_ref_accessible (atspi_bus_registry, atspi_path_root);
82 g_array_index (array, AtspiAccessible *, 0) = desktop;
87 * atspi_register_keystroke_listener:
88 * @listener: a pointer to the #AtspiDeviceListener for which
89 * keystroke events are requested.
90 * @key_set: (element-type AtspiKeyDefinition) (allow-none): a pointer to the
91 * #AtspiKeyDefinition array indicating which keystroke events are
93 * to indicate that all keycodes and keyvals for the specified
94 * modifier set are to be included.
95 * @modmask: an #AtspiKeyMaskType mask indicating which
96 * key event modifiers must be set in combination with @keys,
97 * events will only be reported for key events for which all
98 * modifiers in @modmask are set. If you wish to listen for
99 * events with multiple modifier combinations you must call
100 * register_keystroke_listener() once for each
102 * @event_types: an #AtspiKeyMaskType mask indicating which
103 * types of key events are requested (#ATSPI_KEY_PRESSED, etc.).
104 * @sync_type: a #AtspiKeyListenerSyncType parameter indicating
105 * the behavior of the notification/listener transaction.
107 * Register a listener for keystroke events, either pre-emptively for
108 * all windows (ATSPI_KEYLISTENER_ALL_WINDOWS),
109 * non-preemptively (ATSPI_KEYLISTENER_NOSYNC), or
110 * pre-emptively at the toolkit level (ATSPI_KEYLISTENER_CANCONSUME).
111 * If ALL_WINDOWS or CANCONSUME are used, the event is consumed
112 * upon receipt if one of @listener's callbacks returns #TRUE.
113 * ( Other sync_type values may be available in the future )
115 * Returns: #TRUE if successful, otherwise #FALSE.
118 atspi_register_keystroke_listener (AtspiDeviceListener *listener,
120 AtspiKeyMaskType modmask,
121 AtspiKeyEventMask event_types,
122 AtspiKeyListenerSyncType sync_type,
126 gchar *path = _atspi_device_listener_get_path (listener);
128 dbus_uint32_t d_modmask = modmask;
129 dbus_uint32_t d_event_types = event_types;
130 AtspiEventListenerMode listener_mode;
131 gboolean retval = FALSE;
139 /* copy the keyval filter values from the C api into the DBind KeySet */
142 d_key_set = g_array_sized_new (FALSE, TRUE, sizeof (AtspiKeyDefinition), key_set->len);
143 d_key_set->len = key_set->len;
144 for (i = 0; i < key_set->len; ++i)
146 AtspiKeyDefinition *kd = ((AtspiKeyDefinition *) key_set->data) + i;
147 AtspiKeyDefinition *d_kd = ((AtspiKeyDefinition *) d_key_set->data) + i;
148 d_kd->keycode = kd->keycode;
149 d_kd->keysym = kd->keysym;
152 d_kd->keystring = kd->keystring;
156 d_kd->keystring = "";
162 d_key_set = g_array_sized_new (FALSE, TRUE, sizeof (AtspiKeyDefinition), 0);
165 listener_mode.synchronous =
166 (dbus_bool_t) ((sync_type & ATSPI_KEYLISTENER_SYNCHRONOUS)!=0);
167 listener_mode.preemptive =
168 (dbus_bool_t) ((sync_type & ATSPI_KEYLISTENER_CANCONSUME)!=0);
169 listener_mode.global =
170 (dbus_bool_t) ((sync_type & ATSPI_KEYLISTENER_ALL_WINDOWS)!=0);
172 dbus_error_init (&d_error);
173 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);
175 g_array_free (d_key_set, TRUE);
182 * atspi_deregister_keystroke_listener:
183 * @listener: a pointer to the #AtspiDeviceListener for which
184 * keystroke events are requested.
185 * @key_set: (element-type AtspiKeyDefinition) (allow-none): a pointer to the
186 * #AtspiKeyDefinition array indicating which keystroke events are
187 * requested, or %NULL
188 * to indicate that all keycodes and keyvals for the specified
189 * modifier set are to be included.
190 * @modmask: the key modifier mask for which this listener is to be
191 * 'deregistered' (of type #AtspiKeyMaskType).
192 * @event_types: an #AtspiKeyMaskType mask indicating which
193 * types of key events were requested (#ATSPI_KEY_PRESSED, etc.).
195 * Removes a keystroke event listener from the registry's listener queue,
196 * ceasing notification of events with modifiers matching @modmask.
198 * Returns: #TRUE if successful, otherwise #FALSE.
201 atspi_deregister_keystroke_listener (AtspiDeviceListener *listener,
203 AtspiKeyMaskType modmask,
204 AtspiKeyEventMask event_types,
207 gchar *path = _atspi_device_listener_get_path (listener);
208 dbus_uint32_t d_modmask = modmask;
209 dbus_uint32_t d_event_types = event_types;
212 dbus_error_init (&d_error);
218 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry,
219 atspi_path_dec, atspi_interface_dec,
220 "DeregisterKeystrokeListener", &d_error,
221 "oa(iisi)uu", path, &key_set, d_modmask,
228 * atspi_register_device_event_listener:
229 * @listener: a pointer to the #AtspiDeviceListener which requests
231 * @event_types: an #AtspiDeviceEventMask mask indicating which
232 * types of key events are requested (#ATSPI_KEY_PRESSED, etc.).
233 * @filter: Unused parameter.
235 * Register a listener for device events, for instance button events.
237 * Returns: #TRUE if successful, otherwise #FALSE.
240 atspi_register_device_event_listener (AtspiDeviceListener *listener,
241 AtspiDeviceEventMask event_types,
242 void *filter, GError **error)
244 gboolean retval = FALSE;
245 dbus_uint32_t d_event_types = event_types;
246 gchar *path = _atspi_device_listener_get_path (listener);
249 dbus_error_init (&d_error);
255 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);
261 * atspi_deregister_device_event_listener:
262 * @listener: a pointer to the #AtspiDeviceListener for which
263 * device events are requested.
264 * @filter: Unused parameter.
266 * Removes a device event listener from the registry's listener queue,
267 * ceasing notification of events of the specified type.
269 * Returns: #TRUE if successful, otherwise #FALSE.
272 atspi_deregister_device_event_listener (AtspiDeviceListener *listener,
273 void *filter, GError **error)
275 dbus_uint32_t event_types = 0;
276 gchar *path = _atspi_device_listener_get_path (listener);
279 dbus_error_init (&d_error);
286 event_types |= (1 << ATSPI_BUTTON_PRESSED_EVENT);
287 event_types |= (1 << ATSPI_BUTTON_RELEASED_EVENT);
289 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry, atspi_path_dec, atspi_interface_dec, "DeregisterDeviceEventListener", &d_error, "ou", path, event_types);
295 * atspi_generate_keyboard_event:
296 * @keyval: a long integer indicating the keycode or keysym of the key event
298 * @keystring: an (optional) UTF-8 string which, if @keyval is NULL,
299 * indicates a 'composed' keyboard input string which is
300 * being synthesized; this type of keyboard event synthesis does
301 * not emulate hardware keypresses but injects the string
302 * as though a composing input method (such as XIM) were used.
303 * @synth_type: a #AtspiKeySynthType flag indicating whether @keyval
304 * is to be interpreted as a keysym rather than a keycode
305 * (ATSPI_KEYSYM), or whether to synthesize
306 * ATSPI_KEY_PRESS, ATSPI_KEY_RELEASE, or both (ATSPI_KEY_PRESSRELEASE).
308 * Synthesize a keyboard event (as if a hardware keyboard event occurred in the
309 * current UI context).
311 * Returns: #TRUE if successful, otherwise #FALSE.
314 atspi_generate_keyboard_event (glong keyval,
315 const gchar *keystring,
316 AtspiKeySynthType synth_type, GError **error)
318 dbus_uint32_t d_synth_type = synth_type;
319 dbus_int32_t d_keyval = keyval;
322 dbus_error_init (&d_error);
323 if (!keystring) keystring = "";
324 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);
330 * atspi_generate_mouse_event:
331 * @x: a #long indicating the screen x coordinate of the mouse event.
332 * @y: a #long indicating the screen y coordinate of the mouse event.
333 * @name: a string indicating which mouse event to be synthesized
334 * (e.g. "b1p", "b1c", "b2r", "rel", "abs").
336 * Synthesize a mouse event at a specific screen coordinate.
337 * Most AT clients should use the #AccessibleAction interface when
338 * tempted to generate mouse events, rather than this method.
339 * Event names: b1p = button 1 press; b2r = button 2 release;
340 * b3c = button 3 click; b2d = button 2 double-click;
341 * abs = absolute motion; rel = relative motion.
343 * Returns: #TRUE if successful, otherwise #FALSE.
346 atspi_generate_mouse_event (glong x, glong y, const gchar *name, GError **error)
348 dbus_int32_t d_x = x, d_y = y;
351 dbus_error_init (&d_error);
352 dbind_method_call_reentrant (_atspi_bus(), atspi_bus_registry,
353 atspi_path_dec, atspi_interface_dec,
354 "GenerateMouseEvent", &d_error, "iis",
360 atspi_key_definition_copy (AtspiKeyDefinition *src)
362 AtspiKeyDefinition *dst;
364 dst = g_new0 (AtspiKeyDefinition, 1);
365 dst->keycode = src->keycode;
366 dst->keysym = src->keysym;
368 dst->keystring = g_strdup (src->keystring);
369 dst->unused = src->unused;
374 atspi_key_definition_free (AtspiKeyDefinition *kd)
377 g_free (kd->keystring);
381 G_DEFINE_BOXED_TYPE (AtspiKeyDefinition, atspi_key_definition, atspi_key_definition_copy, atspi_key_definition_free)