2 * AT-SPI - Assistive Technology Service Provider Interface
3 * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
5 * Copyright 2001 Sun Microsystems Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 /* deviceeventcontroler.c: implement the DeviceEventController interface */
32 #include <bonobo/bonobo-exception.h>
35 #include <X11/extensions/XTest.h>
37 #include <X11/keysymdef.h>
39 #include <gdk/gdkx.h> /* TODO: hide dependency (wrap in single porting file) */
40 #include <gdk/gdkkeysyms.h>
41 #include <gdk/gdkwindow.h>
43 #include "../libspi/spi-private.h"
44 #include "deviceeventcontroller.h"
46 /* Our parent Gtk object type */
47 #define PARENT_TYPE BONOBO_TYPE_OBJECT
49 /* A pointer to our parent object class */
50 static GObjectClass *spi_device_event_controller_parent_class;
52 int (*x_default_error_handler) (Display *display, XErrorEvent *error_event);
56 SPI_DEVICE_TYPE_MOUSE,
57 SPI_DEVICE_TYPE_LAST_DEFINED
58 } SpiDeviceTypeCategory;
62 guint pending_add : 1;
63 guint pending_remove : 1;
65 Accessibility_ControllerEventMask mod_mask;
66 CORBA_unsigned_long key_val; /* KeyCode */
67 } DEControllerGrabMask;
71 SpiDeviceTypeCategory type;
72 } DEControllerListener;
75 DEControllerListener listener;
77 Accessibility_KeySet *keys;
78 Accessibility_ControllerEventMask mask;
79 Accessibility_KeyEventTypeSeq *typeseq;
80 Accessibility_EventListenerMode *mode;
81 } DEControllerKeyListener;
83 static void spi_controller_register_with_devices (SpiDEController *controller);
84 static gboolean spi_controller_update_key_grabs (SpiDEController *controller,
85 Accessibility_DeviceEvent *recv);
86 static void spi_controller_register_device_listener (SpiDEController *controller,
87 DEControllerListener *l,
88 CORBA_Environment *ev);
89 static void spi_device_event_controller_forward_key_event (SpiDEController *controller,
92 #define spi_get_display() GDK_DISPLAY()
97 keycode_for_keysym (long keysym)
99 return XKeysymToKeycode (spi_get_display (), (KeySym) keysym);
102 static DEControllerGrabMask *
103 spi_grab_mask_clone (DEControllerGrabMask *grab_mask)
105 DEControllerGrabMask *clone = g_new (DEControllerGrabMask, 1);
107 memcpy (clone, grab_mask, sizeof (DEControllerGrabMask));
109 clone->ref_count = 1;
110 clone->pending_add = TRUE;
111 clone->pending_remove = FALSE;
117 spi_grab_mask_free (DEControllerGrabMask *grab_mask)
123 spi_grab_mask_compare_values (gconstpointer p1, gconstpointer p2)
125 DEControllerGrabMask *l1 = (DEControllerGrabMask *) p1;
126 DEControllerGrabMask *l2 = (DEControllerGrabMask *) p2;
134 return ((l1->mod_mask != l2->mod_mask) || (l1->key_val != l2->key_val));
138 static DEControllerKeyListener *
139 spi_dec_key_listener_new (CORBA_Object l,
140 const Accessibility_KeySet *keys,
141 const Accessibility_ControllerEventMask mask,
142 const Accessibility_KeyEventTypeSeq *typeseq,
143 const Accessibility_EventListenerMode *mode,
144 CORBA_Environment *ev)
146 DEControllerKeyListener *key_listener = g_new0 (DEControllerKeyListener, 1);
147 key_listener->listener.object = bonobo_object_dup_ref (l, ev);
148 key_listener->listener.type = SPI_DEVICE_TYPE_KBD;
149 key_listener->keys = ORBit_copy_value (keys, TC_Accessibility_KeySet);
150 key_listener->mask = mask;
151 key_listener->typeseq = ORBit_copy_value (typeseq, TC_Accessibility_KeyEventTypeSeq);
153 key_listener->mode = ORBit_copy_value (mode, TC_Accessibility_EventListenerMode);
155 key_listener->mode = NULL;
158 g_print ("new listener, with mask %x, is_global %d, keys %p (%d)\n",
159 (unsigned int) key_listener->mask,
160 (int) (mode ? mode->global : 0),
161 (void *) key_listener->keys,
162 (int) (key_listener->keys ? key_listener->keys->_length : 0));
169 spi_dec_key_listener_free (DEControllerKeyListener *key_listener,
170 CORBA_Environment *ev)
172 bonobo_object_release_unref (key_listener->listener.object, ev);
173 CORBA_free (key_listener->typeseq);
174 CORBA_free (key_listener->keys);
175 g_free (key_listener);
179 _register_keygrab (SpiDEController *controller,
180 DEControllerGrabMask *grab_mask)
184 l = g_list_find_custom (controller->keygrabs_list, grab_mask,
185 spi_grab_mask_compare_values);
188 DEControllerGrabMask *cur_mask = l->data;
190 cur_mask->ref_count++;
191 if (cur_mask->pending_remove)
193 cur_mask->pending_remove = FALSE;
198 controller->keygrabs_list =
199 g_list_prepend (controller->keygrabs_list,
200 spi_grab_mask_clone (grab_mask));
205 _deregister_keygrab (SpiDEController *controller,
206 DEControllerGrabMask *grab_mask)
210 l = g_list_find_custom (controller->keygrabs_list, grab_mask,
211 spi_grab_mask_compare_values);
215 DEControllerGrabMask *cur_mask = l->data;
217 cur_mask->ref_count--;
218 if (cur_mask->ref_count <= 0)
220 cur_mask->pending_remove = TRUE;
225 g_warning ("De-registering non-existant grab");
230 handle_keygrab (SpiDEController *controller,
231 DEControllerKeyListener *key_listener,
232 void (*process_cb) (SpiDEController *controller,
233 DEControllerGrabMask *grab_mask))
235 DEControllerGrabMask grab_mask = { 0 };
237 grab_mask.mod_mask = key_listener->mask;
238 if (key_listener->keys->_length == 0) /* special case means AnyKey/AllKeys */
240 grab_mask.key_val = AnyKey;
241 process_cb (controller, &grab_mask);
247 for (i = 0; i < key_listener->keys->_length; ++i)
249 long int key_val = key_listener->keys->_buffer[i];
250 /* X Grabs require keycodes, not keysyms */
253 key_val = XKeysymToKeycode (spi_get_display (), (KeySym) key_val);
255 grab_mask.key_val = key_val;
257 process_cb (controller, &grab_mask);
263 spi_controller_register_global_keygrabs (SpiDEController *controller,
264 DEControllerKeyListener *key_listener)
266 handle_keygrab (controller, key_listener, _register_keygrab);
267 spi_controller_update_key_grabs (controller, NULL);
271 spi_controller_deregister_global_keygrabs (SpiDEController *controller,
272 DEControllerKeyListener *key_listener)
274 handle_keygrab (controller, key_listener, _deregister_keygrab);
275 spi_controller_update_key_grabs (controller, NULL);
279 spi_controller_register_device_listener (SpiDEController *controller,
280 DEControllerListener *listener,
281 CORBA_Environment *ev)
283 DEControllerKeyListener *key_listener;
285 switch (listener->type) {
286 case SPI_DEVICE_TYPE_KBD:
287 key_listener = (DEControllerKeyListener *) listener;
289 controller->key_listeners = g_list_prepend (controller->key_listeners,
291 if (key_listener->mode->global)
293 spi_controller_register_global_keygrabs (controller, key_listener);
301 static GdkFilterReturn
302 global_filter_fn (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
304 XEvent *xevent = gdk_xevent;
305 SpiDEController *controller;
307 if (xevent->type != KeyPress && xevent->type != KeyRelease)
309 return GDK_FILTER_CONTINUE;
312 controller = SPI_DEVICE_EVENT_CONTROLLER (data);
314 spi_device_event_controller_forward_key_event (controller, xevent);
316 /* FIXME: is this right ? */
317 return GDK_FILTER_CONTINUE;
321 _spi_controller_device_error_handler (Display *display, XErrorEvent *error)
323 if (error->error_code == BadAccess)
325 g_message ("Could not complete key grab: grab already in use.\n");
330 return (*x_default_error_handler) (display, error);
335 spi_controller_register_with_devices (SpiDEController *controller)
337 /* calls to device-specific implementations and routines go here */
338 /* register with: keyboard hardware code handler */
339 /* register with: (translated) keystroke handler */
341 gdk_window_add_filter (NULL, global_filter_fn, controller);
343 gdk_window_set_events (gdk_get_default_root_window (),
344 GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
346 x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler);
350 spi_key_set_contains_key (Accessibility_KeySet *key_set,
351 const Accessibility_DeviceEvent *key_event)
358 g_print ("null key set!");
362 len = key_set->_length;
364 if (len == 0) /* special case, means "all keys/any key" */
366 g_print ("anykey\n");
370 for (i = 0; i < len; ++i)
372 #ifdef SPI_KEYEVENT_DEBUG
373 g_print ("key_set[%d] = %d; key_event %d, code %d\n",
374 i, (int) key_set->_buffer[i],
375 (int) key_event->id, (int) key_event->hw_code);
377 if (key_set->_buffer[i] == (CORBA_long) key_event->id)
381 if (key_set->_buffer[i] == (CORBA_long) -key_event->hw_code)
391 spi_key_eventtype_seq_contains_event (Accessibility_KeyEventTypeSeq *type_seq,
392 const Accessibility_DeviceEvent *key_event)
400 g_print ("null type seq!");
404 len = type_seq->_length;
406 if (len == 0) /* special case, means "all events/any event" */
411 for (i = 0; i < len; ++i)
414 g_print ("type_seq[%d] = %d; key event type = %d\n", i,
415 (int) type_seq->_buffer[i], (int) key_event->type);
417 if (type_seq->_buffer[i] == (CORBA_long) key_event->type)
427 spi_key_event_matches_listener (const Accessibility_DeviceEvent *key_event,
428 DEControllerKeyListener *listener,
429 CORBA_boolean is_system_global)
431 if ((key_event->modifiers == (CORBA_unsigned_short) (listener->mask & 0xFFFF)) &&
432 spi_key_set_contains_key (listener->keys, key_event) &&
433 spi_key_eventtype_seq_contains_event (listener->typeseq, key_event) &&
434 (is_system_global == listener->mode->global))
445 spi_notify_keylisteners (GList **key_listeners,
446 const Accessibility_DeviceEvent *key_event,
447 CORBA_boolean is_system_global,
448 CORBA_Environment *ev)
451 GSList *notify = NULL, *l2;
452 gboolean is_consumed;
459 for (l = *key_listeners; l; l = l->next)
461 DEControllerKeyListener *key_listener = l->data;
463 if (spi_key_event_matches_listener (key_event, key_listener, is_system_global))
465 Accessibility_DeviceEventListener ls = key_listener->listener.object;
467 if (ls != CORBA_OBJECT_NIL)
469 notify = g_slist_prepend (notify, CORBA_Object_duplicate (ls, ev));
474 #ifdef SPI_KEYEVENT_DEBUG
477 g_print ("no match for listener %d\n", i);
482 for (l2 = notify; l2 && !is_consumed; l2 = l2->next)
484 Accessibility_DeviceEventListener ls = l2->data;
486 is_consumed = Accessibility_DeviceEventListener_notifyEvent (ls, key_event, ev);
491 CORBA_exception_free (ev);
494 CORBA_Object_release (ls, ev);
497 for (; l2; l2 = l2->next)
499 CORBA_Object_release (l2->data, ev);
502 g_slist_free (notify);
507 static Accessibility_DeviceEvent
508 spi_keystroke_from_x_key_event (XKeyEvent *x_key_event)
510 Accessibility_DeviceEvent key_event;
512 const int cbuf_bytes = 20;
513 char cbuf [cbuf_bytes];
515 keysym = XLookupKeysym (x_key_event, 0);
516 key_event.id = (CORBA_long)(keysym);
517 key_event.hw_code = (CORBA_short) x_key_event->keycode;
518 if (((XEvent *) x_key_event)->type == KeyPress)
520 key_event.type = Accessibility_KEY_PRESSED;
524 key_event.type = Accessibility_KEY_RELEASED;
526 key_event.modifiers = (CORBA_unsigned_short)(x_key_event->state);
527 key_event.is_text = CORBA_FALSE;
531 key_event.event_string = CORBA_string_dup ("space");
534 key_event.event_string = CORBA_string_dup ("Tab");
537 key_event.event_string = CORBA_string_dup ("Backspace");
540 key_event.event_string = CORBA_string_dup ("Return");
543 if (XLookupString (x_key_event, cbuf, cbuf_bytes, &keysym, NULL) > 0)
545 key_event.event_string = CORBA_string_dup (cbuf);
546 if (isgraph (keysym))
548 key_event.is_text = CORBA_TRUE; /* FIXME: incorrect for some composed chars? */
553 key_event.event_string = CORBA_string_dup ("");
557 key_event.timestamp = (CORBA_unsigned_long) x_key_event->time;
558 #ifdef SPI_KEYEVENT_DEBUG
560 "Key %lu pressed (%c), modifiers %d\n",
561 (unsigned long) keysym,
562 keysym ? (int) keysym : '*',
563 (int) x_key_event->state);
566 fprintf (stderr, "%s%c",
567 (x_key_event->state & Mod1Mask)?"Alt-":"",
568 ((x_key_event->state & ShiftMask)^(x_key_event->state & LockMask))?
569 g_ascii_toupper (keysym) : g_ascii_tolower (keysym));
570 #endif /* SPI_DEBUG */
575 spi_controller_update_key_grabs (SpiDEController *controller,
576 Accessibility_DeviceEvent *recv)
580 g_return_val_if_fail (controller != NULL, FALSE);
583 * masks known to work with default RH 7.1+:
584 * 0 (no mods), LockMask, Mod1Mask, Mod2Mask, ShiftMask,
585 * ShiftMask|LockMask, Mod1Mask|LockMask, Mod2Mask|LockMask,
586 * ShiftMask|Mod1Mask, ShiftMask|Mod2Mask, Mod1Mask|Mod2Mask,
587 * ShiftMask|LockMask|Mod1Mask, ShiftMask|LockMask|Mod2Mask,
589 * ControlMask grabs are broken, must be in use already
591 for (l = controller->keygrabs_list; l; l = next)
594 gboolean re_issue_grab;
595 DEControllerGrabMask *grab_mask = l->data;
599 re_issue_grab = recv &&
600 /* (recv->type == Accessibility_KEY_RELEASED) && - (?) */
601 (recv->modifiers & grab_mask->mod_mask) &&
602 (grab_mask->key_val == keycode_for_keysym (recv->id));
605 fprintf (stderr, "mask=%lx %lx (%c%c) %s\n",
606 (long int) grab_mask->key_val,
607 (long int) grab_mask->mod_mask,
608 grab_mask->pending_add ? '+' : '.',
609 grab_mask->pending_remove ? '-' : '.',
610 re_issue_grab ? "re-issue": "");
615 if (grab_mask->pending_add && grab_mask->pending_remove)
619 else if (grab_mask->pending_remove)
622 fprintf (stderr, "ungrabbing, mask=%x\n", grab_mask->mod_mask);
624 XUngrabKey (spi_get_display (),
627 gdk_x11_get_default_root_xwindow ());
631 else if (grab_mask->pending_add || re_issue_grab)
635 fprintf (stderr, "grab with mask %x\n", grab_mask->mod_mask);
637 XGrabKey (spi_get_display (),
640 gdk_x11_get_default_root_xwindow (),
646 grab_mask->pending_add = FALSE;
647 grab_mask->pending_remove = FALSE;
651 g_assert (grab_mask->ref_count <= 0);
653 controller->keygrabs_list = g_list_delete_link (
654 controller->keygrabs_list, l);
656 spi_grab_mask_free (grab_mask);
659 /* TODO: check calls for errors and return FALSE if error occurs */
666 * Implemented GObject::finalize
669 spi_device_event_controller_object_finalize (GObject *object)
671 SpiDEController *controller;
673 controller = SPI_DEVICE_EVENT_CONTROLLER (object);
676 fprintf(stderr, "spi_device_event_controller_object_finalize called\n");
678 /* disconnect any special listeners, get rid of outstanding keygrabs */
679 XUngrabKey (spi_get_display (), AnyKey, AnyModifier, DefaultRootWindow (spi_get_display ()));
681 spi_device_event_controller_parent_class->finalize (object);
685 * CORBA Accessibility::DEController::registerKeystrokeListener
686 * method implementation
689 impl_register_keystroke_listener (PortableServer_Servant servant,
690 const Accessibility_DeviceEventListener l,
691 const Accessibility_KeySet *keys,
692 const Accessibility_ControllerEventMask mask,
693 const Accessibility_KeyEventTypeSeq *type,
694 const Accessibility_EventListenerMode *mode,
695 CORBA_Environment *ev)
697 SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
698 bonobo_object_from_servant (servant));
699 DEControllerKeyListener *dec_listener;
701 fprintf (stderr, "registering keystroke listener %p with maskVal %lu\n",
702 (void *) l, (unsigned long) mask);
704 dec_listener = spi_dec_key_listener_new (l, keys, mask, type, mode, ev);
705 spi_controller_register_device_listener (
706 controller, (DEControllerListener *) dec_listener, ev);
711 CORBA_Environment *ev;
712 DEControllerKeyListener *key_listener;
713 } RemoveKeyListenerClosure;
715 static SpiReEntrantContinue
716 remove_key_listener_cb (GList * const *list,
719 DEControllerKeyListener *key_listener = (*list)->data;
720 RemoveKeyListenerClosure *ctx = user_data;
722 if (CORBA_Object_is_equivalent (ctx->key_listener->listener.object,
723 key_listener->listener.object, ctx->ev))
725 spi_re_entrant_list_delete_link (list);
726 spi_dec_key_listener_free (key_listener, ctx->ev);
729 return SPI_RE_ENTRANT_CONTINUE;
732 static SpiReEntrantContinue
733 copy_key_listener_cb (GList * const *list,
736 DEControllerKeyListener *key_listener = (*list)->data;
737 RemoveKeyListenerClosure *ctx = user_data;
739 if (CORBA_Object_is_equivalent (ctx->key_listener->listener.object,
740 key_listener->listener.object, ctx->ev))
742 /* TODO: FIXME aggregate keys in case the listener is registered twice */
743 CORBA_free (ctx->key_listener->keys);
744 ctx->key_listener->keys = ORBit_copy_value (key_listener->keys, TC_Accessibility_KeySet);
747 return SPI_RE_ENTRANT_CONTINUE;
751 * CORBA Accessibility::DEController::deregisterKeystrokeListener
752 * method implementation
755 impl_deregister_keystroke_listener (PortableServer_Servant servant,
756 const Accessibility_DeviceEventListener l,
757 const Accessibility_KeySet *keys,
758 const Accessibility_ControllerEventMask mask,
759 const Accessibility_KeyEventTypeSeq *type,
760 CORBA_Environment *ev)
762 DEControllerKeyListener *key_listener;
763 RemoveKeyListenerClosure ctx;
764 SpiDEController *controller;
766 controller = SPI_DEVICE_EVENT_CONTROLLER (bonobo_object (servant));
768 key_listener = spi_dec_key_listener_new (l, keys, mask, type, NULL, ev);
770 #ifdef SPI_DEREGISTER_DEBUG
771 fprintf (stderr, "deregistering keystroke listener %p with maskVal %lu\n",
772 (void *) l, (unsigned long) mask->value);
776 ctx.key_listener = key_listener;
778 /* special case, copy keyset from existing controller list entry */
779 if (keys->_length == 0)
781 spi_re_entrant_list_foreach (&controller->key_listeners,
782 copy_key_listener_cb, &ctx);
785 spi_controller_deregister_global_keygrabs (controller, key_listener);
787 spi_re_entrant_list_foreach (&controller->key_listeners,
788 remove_key_listener_cb, &ctx);
790 spi_dec_key_listener_free (key_listener, ev);
794 * CORBA Accessibility::DEController::registerKeystrokeListener
795 * method implementation
798 impl_generate_keyboard_event (PortableServer_Servant servant,
799 const CORBA_long keycode,
800 const CORBA_char *keystring,
801 const Accessibility_KeySynthType synth_type,
802 CORBA_Environment *ev)
807 fprintf (stderr, "synthesizing keystroke %ld, type %d\n",
808 (long) keycode, (int) synth_type);
810 /* TODO: hide/wrap/remove X dependency */
812 /* TODO: be accessX-savvy so that keyrelease occurs after sufficient timeout */
815 * TODO: when initializing, query for XTest extension before using,
816 * and fall back to XSendEvent() if XTest is not available.
819 /* TODO: implement keystring mode also */
820 gdk_error_trap_push ();
824 case Accessibility_KEY_PRESS:
825 XTestFakeKeyEvent (spi_get_display (), (unsigned int) keycode, True, CurrentTime);
827 case Accessibility_KEY_PRESSRELEASE:
828 XTestFakeKeyEvent (spi_get_display (), (unsigned int) keycode, True, CurrentTime);
829 case Accessibility_KEY_RELEASE:
830 XTestFakeKeyEvent (spi_get_display (), (unsigned int) keycode, False, CurrentTime);
832 case Accessibility_KEY_SYM:
833 key_synth_code = keycode_for_keysym (keycode);
834 XTestFakeKeyEvent (spi_get_display (), (unsigned int) key_synth_code, True, CurrentTime);
835 XTestFakeKeyEvent (spi_get_display (), (unsigned int) key_synth_code, False, CurrentTime);
837 case Accessibility_KEY_STRING:
838 fprintf (stderr, "Not yet implemented\n");
841 if (gdk_error_trap_pop ())
843 g_warning ("Error emitting keystroke");
847 /* Accessibility::DEController::generateMouseEvent */
849 impl_generate_mouse_event (PortableServer_Servant servant,
852 const CORBA_char *eventName,
853 CORBA_Environment *ev)
856 gboolean error = FALSE;
857 Display *display = spi_get_display ();
859 fprintf (stderr, "generating mouse %s event at %ld, %ld\n",
860 eventName, (long int) x, (long int) y);
862 g_message ("mouse event synthesis\n");
863 switch (eventName[0])
866 switch (eventName[1])
868 /* TODO: check number of buttons before parsing */
883 if (x != -1 && y != -1)
885 XTestFakeMotionEvent (display, DefaultScreen (display),
888 XTestFakeButtonEvent (display, button, !(eventName[2] == 'r'), 0);
889 if (eventName[2] == 'c')
890 XTestFakeButtonEvent (display, button, FALSE, 1);
891 else if (eventName[2] == 'd')
893 XTestFakeButtonEvent (display, button, FALSE, 1);
894 XTestFakeButtonEvent (display, button, TRUE, 2);
895 XTestFakeButtonEvent (display, button, FALSE, 3);
899 case 'r': /* relative motion */
900 XTestFakeRelativeMotionEvent (display, x, y, 0);
902 case 'a': /* absolute motion */
903 XTestFakeMotionEvent (display, DefaultScreen (display),
909 /* Accessibility::DEController::notifyListenersSync */
911 impl_notify_listeners_sync (PortableServer_Servant servant,
912 const Accessibility_DeviceEvent *event,
913 CORBA_Environment *ev)
915 SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
916 bonobo_object_from_servant (servant));
918 g_print ("notifylistening listeners synchronously: controller %p, event id %d\n",
919 controller, (int) event->id);
921 return spi_notify_keylisteners (&controller->key_listeners, event, CORBA_FALSE, ev) ?
922 CORBA_TRUE : CORBA_FALSE;
925 /* Accessibility::DEController::notifyListenersAsync */
927 impl_notify_listeners_async (PortableServer_Servant servant,
928 const Accessibility_DeviceEvent *event,
929 CORBA_Environment *ev)
931 SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
932 bonobo_object_from_servant (servant));
934 fprintf (stderr, "notifying listeners asynchronously\n");
936 spi_notify_keylisteners (&controller->key_listeners, event, CORBA_FALSE, ev);
940 spi_device_event_controller_class_init (SpiDEControllerClass *klass)
942 GObjectClass * object_class = (GObjectClass *) klass;
943 POA_Accessibility_DeviceEventController__epv *epv = &klass->epv;
945 spi_device_event_controller_parent_class = g_type_class_peek_parent (klass);
947 object_class->finalize = spi_device_event_controller_object_finalize;
949 epv->registerKeystrokeListener = impl_register_keystroke_listener;
950 epv->deregisterKeystrokeListener = impl_deregister_keystroke_listener;
951 epv->generateKeyboardEvent = impl_generate_keyboard_event;
952 epv->generateMouseEvent = impl_generate_mouse_event;
953 epv->notifyListenersSync = impl_notify_listeners_sync;
954 epv->notifyListenersAsync = impl_notify_listeners_async;
958 spi_device_event_controller_init (SpiDEController *device_event_controller)
960 device_event_controller->key_listeners = NULL;
961 device_event_controller->mouse_listeners = NULL;
962 device_event_controller->keygrabs_list = NULL;
965 * TODO: fixme, this module makes the foolish assumptions that
966 * registryd uses the same display as the apps, and that the
967 * DISPLAY environment variable is set.
969 gdk_init (NULL, NULL);
971 spi_controller_register_with_devices (device_event_controller);
975 spi_device_event_controller_forward_key_event (SpiDEController *controller,
978 gboolean is_consumed = FALSE;
979 CORBA_Environment ev;
980 Accessibility_DeviceEvent key_event;
982 g_assert (event->type == KeyPress || event->type == KeyRelease);
984 CORBA_exception_init (&ev);
986 key_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
988 spi_controller_update_key_grabs (controller, &key_event);
990 /* relay to listeners, and decide whether to consume it or not */
991 is_consumed = spi_notify_keylisteners (
992 &controller->key_listeners, &key_event, CORBA_TRUE, &ev);
994 CORBA_exception_free (&ev);
998 XAllowEvents (spi_get_display (), AsyncKeyboard, CurrentTime);
1002 XAllowEvents (spi_get_display (), ReplayKeyboard, CurrentTime);
1007 spi_device_event_controller_new (SpiRegistry *registry)
1009 SpiDEController *retval = g_object_new (
1010 SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL);
1012 retval->registry = SPI_REGISTRY (bonobo_object_ref (
1013 BONOBO_OBJECT (registry)));
1018 BONOBO_TYPE_FUNC_FULL (SpiDEController,
1019 Accessibility_DeviceEventController,
1021 spi_device_event_controller);