Added docs and C bindings for AccessibleStateSet and AccessibleRelationSet.
[platform/core/uifw/at-spi2-atk.git] / libspi / deviceeventcontroller.c
index 76b5666..9d2e6e1 100644 (file)
@@ -29,7 +29,9 @@
 #include <stdio.h>
 #endif
 
+#include <stdlib.h> /* for getenv() */
 #include <X11/Xlib.h>
+#include <X11/extensions/XTest.h>
 #include <config.h>
 #include <gdk/gdkx.h> /* TODO: hide dependency (wrap in single porting file) */
 #include <gdk/gdkwindow.h>
 /*
  * A pointer to our parent object class
  */
-static GObjectClass *device_event_controller_parent_class;
+static GObjectClass *spi_device_event_controller_parent_class;
 
 static gboolean kbd_registered = FALSE;
 
+static Display *display;
+
+static Window root_window;
+
 typedef enum {
-  DEVICE_TYPE_KBD,
-  DEVICE_TYPE_MOUSE,
-  DEVICE_TYPE_LAST_DEFINED
-} DeviceTypeCategory;
+  SPI_DEVICE_TYPE_KBD,
+  SPI_DEVICE_TYPE_MOUSE,
+  SPI_DEVICE_TYPE_LAST_DEFINED
+} SpiDeviceTypeCategory;
+
+struct _DEControllerListener {
+  CORBA_Object object;
+  SpiDeviceTypeCategory type;
+};
+
+typedef struct _DEControllerListener DEControllerListener;
+
+struct _DEControllerKeyListener {
+  DEControllerListener listener;
+  Accessibility_KeySet *keys;
+  Accessibility_ControllerEventMask *mask;
+  Accessibility_KeyEventTypeSeq *typeseq;
+  gboolean is_system_global;   
+};
+
+typedef struct _DEControllerKeyListener DEControllerKeyListener;
 
-static gboolean _controller_register_with_devices (DeviceEventController *controller);
-static gboolean _controller_grab_keyboard (DeviceEventController *controller);
+static gboolean _controller_register_with_devices (SpiDeviceEventController *controller);
+static gboolean _controller_grab_keyboard (SpiDeviceEventController *controller);
 
-static void _controller_register_device_listener (DeviceEventController *controller,
-                                                 const CORBA_Object l,
-                                                 const Accessibility_ControllerEventMask *mask,
-                                                 DeviceTypeCategory type,
-                                                 CORBA_Environment *ev);
+static void controller_register_device_listener (SpiDeviceEventController *controller,
+                                                DEControllerListener *l,
+                                                CORBA_Environment *ev);
 
 /*
  * Private methods
  */
 
 static gint
+_compare_listeners (gconstpointer p1, gconstpointer p2)
+{
+  DEControllerListener *l1 = (DEControllerListener *) p1;      
+  DEControllerListener *l2 = (DEControllerListener *) p2;      
+  return _compare_corba_objects (l1->object, l2->object);
+}
+
+static gint
 _compare_corba_objects (gconstpointer p1, gconstpointer p2)
 {
   CORBA_Environment ev;
@@ -90,50 +119,69 @@ _compare_corba_objects (gconstpointer p1, gconstpointer p2)
 static gint
 _eventmask_compare_value (gconstpointer p1, gconstpointer p2)
 {
+    long d;
     if (!p1 || !p2)
        return (gint) (p1?1:(p2?-1:0));
     else
-       return ((long)((Accessibility_ControllerEventMask*)p2)->value) -
+       d = ((long)((Accessibility_ControllerEventMask*)p2)->value) -
                ((long)((Accessibility_ControllerEventMask*)p1)->value);
+    return (gint) d;
+}
+
+static DEControllerKeyListener *
+dec_key_listener_new (CORBA_Object l,
+                     const Accessibility_KeySet *keys,
+                     const Accessibility_ControllerEventMask *mask,
+                     const Accessibility_KeyEventTypeSeq *typeseq,
+                     const CORBA_boolean is_system_global,
+                     CORBA_Environment *ev)
+{
+  DEControllerKeyListener *key_listener = g_new0 (DEControllerKeyListener, 1);
+  key_listener->listener.object = CORBA_Object_duplicate (l, ev);
+  key_listener->listener.type = SPI_DEVICE_TYPE_KBD;
+  key_listener->keys = keys;
+  key_listener->mask = mask;
+  key_listener->is_system_global = is_system_global;
+
+  return key_listener; 
 }
 
 static void
-_controller_register_device_listener (DeviceEventController *controller,
-                                     const CORBA_Object l,
-                                     const Accessibility_ControllerEventMask *mask,
-                                     DeviceTypeCategory type,
-                                     CORBA_Environment *ev)
+controller_register_device_listener (SpiDeviceEventController *controller,
+                                    DEControllerListener *listener,
+                                    CORBA_Environment *ev)
 {
-  Accessibility_ControllerEventMask *mask_ptr;
+  Accessibility_ControllerEventMask *mask_ptr = NULL;
+  DEControllerKeyListener *key_listener;
   
-  switch (type) {
-  case DEVICE_TYPE_KBD:
-      controller->key_listeners = g_list_append (controller->key_listeners,
-                                                CORBA_Object_duplicate (l, ev));
+  switch (listener->type) {
+  case SPI_DEVICE_TYPE_KBD:
+      key_listener = (DEControllerKeyListener *) listener;       
+      controller->key_listeners = g_list_append (controller->key_listeners, key_listener);
       
       mask_ptr = (Accessibility_ControllerEventMask *)
-             g_list_find_custom (controller->keymask_list, (gpointer) mask,
+             g_list_find_custom (controller->keymask_list, (gpointer) key_listener->mask,
                                  _eventmask_compare_value);
       if (mask_ptr)
              ++(mask_ptr->refcount);
       else
       {
-             if (mask->refcount != (CORBA_unsigned_short) 1)
+             if (key_listener->mask->refcount != (CORBA_unsigned_short) 1)
                      fprintf (stderr, "mask initial refcount is not 1!\n");
-             if (mask->value > (CORBA_unsigned_long) 2048)
+             if (key_listener->mask->value > (CORBA_unsigned_long) 2048)
                      fprintf (stderr, "mask value looks invalid (%lu)\n",
-                              (unsigned long) mask->value);
+                              (unsigned long) key_listener->mask->value);
              else
                      fprintf (stderr, "appending mask with val=%lu\n",
-                              (unsigned long) mask->value);
+                              (unsigned long) key_listener->mask->value);
              mask_ptr = Accessibility_ControllerEventMask__alloc();
-             mask_ptr->value = mask->value;
+             mask_ptr->value = key_listener->mask->value;
              mask_ptr->refcount = (CORBA_unsigned_short) 1;
              controller->keymask_list = g_list_append (controller->keymask_list,
                                                        (gpointer) mask_ptr);
       }
       break;
-  case DEVICE_TYPE_MOUSE:
+  case SPI_DEVICE_TYPE_MOUSE:
 /*    controller->mouse_listeners = g_list_append (controller->mouse_listeners,
                                                    CORBA_Object_duplicate (l, ev));*/
 
@@ -143,32 +191,37 @@ _controller_register_device_listener (DeviceEventController *controller,
 }
 
 static void
-_controller_deregister_device_listener (DeviceEventController *controller,
-                                       const CORBA_Object l,
-                                       const Accessibility_ControllerEventMask *mask,
-                                       DeviceTypeCategory type,
-                                       CORBA_Environment *ev)
+controller_deregister_device_listener (SpiDeviceEventController *controller,
+                                      DEControllerListener *listener,
+                                      CORBA_Environment *ev)
 {
   Accessibility_ControllerEventMask *mask_ptr;
+  DEControllerKeyListener *key_listener;
   GList *list_ptr;
-  switch (type) {
-  case DEVICE_TYPE_KBD:
-      list_ptr = g_list_find_custom (controller->key_listeners, l, _compare_corba_objects);
+  switch (listener->type) {
+  case SPI_DEVICE_TYPE_KBD:
+      key_listener = (DEControllerKeyListener *) listener;
+      list_ptr = g_list_find_custom (controller->key_listeners, listener, _compare_listeners);
+      /* TODO: need a different custom compare func */
       if (list_ptr)
          controller->key_listeners = g_list_remove (controller->key_listeners, list_ptr);
-      
-      mask_ptr = (Accessibility_ControllerEventMask *)
-                 g_list_find_custom (controller->keymask_list, (gpointer) mask,
+      list_ptr = (GList *)
+                 g_list_find_custom (controller->keymask_list, (gpointer) key_listener->mask,
                                     _eventmask_compare_value);
-      if (mask_ptr)
+      if (list_ptr)
+        {
+         mask_ptr = (Accessibility_ControllerEventMask *) list_ptr->data;
+          if (mask_ptr)
              --mask_ptr->refcount;
-      if (!mask_ptr->refcount)
-      {
-          controller->keymask_list = g_list_remove (controller->keymask_list, mask_ptr);
-          ;  /* release any key grabs that are in place for this key mask */
-      }
+          if (!mask_ptr->refcount)
+            {
+             controller->keymask_list =
+                     g_list_remove (controller->keymask_list, mask_ptr);
+             ;  /* TODO: release any key grabs that are in place for this key mask */
+           }
+       }
       break;
-  case DEVICE_TYPE_MOUSE:
+  case SPI_DEVICE_TYPE_MOUSE:
 /*    controller->mouse_listeners = g_list_append (controller->mouse_listeners,
                                                    CORBA_Object_duplicate (l, ev));*/
 
@@ -178,38 +231,51 @@ _controller_deregister_device_listener (DeviceEventController *controller,
 }
 
 static gboolean
-_controller_register_with_devices (DeviceEventController *controller)
+_controller_register_with_devices (SpiDeviceEventController *controller)
 {
   gboolean retval = FALSE;
-  Display *default_display;
-  Window root_window;
 
-  default_display = GDK_DISPLAY();
-  root_window = GDK_ROOT_WINDOW();  
   /* calls to device-specific implementations and routines go here */
   /* register with: keyboard hardware code handler */
   /* register with: (translated) keystroke handler */
 #ifdef SPI_DEBUG
-  fprintf (stderr, "About to request events on window %ld of display %p\n",
-          (unsigned long) root_window, default_display);
+  fprintf (stderr, "About to request events on window %ld of display %x\n",
+          (unsigned long) GDK_ROOT_WINDOW(), GDK_DISPLAY());
 #endif
-  XSelectInput (default_display,
-               root_window,
-               KeyPressMask);
-  XSelectInput (default_display,
+  /* We must open a new connection to the server to avoid clashing with the GDK event loop */
+  display = XOpenDisplay (getenv ("DISPLAY"));
+  root_window = DefaultRootWindow (display);           
+  XSelectInput (display,
                root_window,
-               KeyReleaseMask);
+               KeyPressMask | KeyReleaseMask);
   /* register with: mouse hardware device handler? */
   /* register with: mouse event handler */
   return retval;
 }
 
-static gboolean _check_key_event (DeviceEventController *controller)
+
+static gboolean
+notify_keylisteners (GList *key_listeners, Accessibility_KeyStroke *key_event, CORBA_Environment *ev)
+{
+  int i, n_listeners = g_list_length (key_listeners);
+  gboolean is_consumed = FALSE;
+  for (i=0; i<n_listeners && !is_consumed; ++i)
+    {
+      Accessibility_KeystrokeListener ls;
+      ls = (Accessibility_KeystrokeListener)
+           g_list_nth_data (key_listeners, i);
+      if (!CORBA_Object_is_nil(ls, ev))
+        {
+           is_consumed = Accessibility_KeystrokeListener_keyEvent (ls, key_event, ev);
+        }              
+    }
+  return is_consumed;
+}
+
+
+static gboolean
+_check_key_event (SpiDeviceEventController *controller)
 {
-#ifdef SPI_DEBUG
-       static Accessibility_ControllerEventMask shiftlock_mask =
-               {(CORBA_unsigned_long) LockMask, (CORBA_unsigned_short) 1};
-#endif
        static gboolean initialized = FALSE;
        static gboolean is_active = FALSE;
        XEvent *x_event = g_new0 (XEvent, 1);
@@ -218,92 +284,70 @@ static gboolean _check_key_event (DeviceEventController *controller)
        gboolean is_consumed = FALSE;
        char key_name[16];
        int i;
-       int n_listeners = g_list_length (controller->key_listeners);
        Accessibility_KeyStroke key_event;
        static CORBA_Environment ev;
-       
+
        if (!initialized)
        {
-               initialized = TRUE;
-               CORBA_exception_init (&ev);
+         initialized = TRUE;
+         CORBA_exception_init (&ev);
        }
 
-/*        if (!XPending(GDK_DISPLAY())) return TRUE; */
-
-       /*
-        * the call to XPending seemed like a good idea, why did it
-        * wreak such havoc?
-        */
-
-       XPeekEvent (GDK_DISPLAY(), x_event);
-       if (x_event->type == KeyPress)
-       {
-           x_key_event = (XKeyEvent *)x_event;
-           keysym = XLookupKeysym (x_key_event, 0);
-           key_event.keyID = (CORBA_long)(keysym);
-           key_event.type = Accessibility_KEY_PRESSED;
-           key_event.modifiers = (CORBA_unsigned_short)(x_key_event->state);
-#if defined SPI_KEYEVENT_DEBUG
+       while (XPending(display))
+         {
+           XNextEvent (display, x_event);
+           if (XFilterEvent (x_event, None)) continue;   
+           if (x_event->type == KeyPress)
+             {
+               x_key_event = (XKeyEvent *)x_event;
+               keysym = XLookupKeysym (x_key_event, 0);
+               key_event.keyID = (CORBA_long)(keysym);
+               key_event.keycode = (CORBA_short) x_key_event->keycode;
+               key_event.type = Accessibility_KEY_PRESSED;
+               key_event.modifiers = (CORBA_unsigned_short)(x_key_event->state);
+#ifdef SPI_KEYEVENT_DEBUG
            fprintf (stderr,
                     "Key %lu pressed (%c), modifiers %d\n",
                     (unsigned long) keysym,
-                    (char) keysym,
+                    keysym ? (int) keysym : '*',
                     (int) x_key_event->state);
-#elif defined SPI_DEBUG
+#endif
+#ifdef SPI_DEBUG
            fprintf(stderr, "%s%c",
                    (x_key_event->state & Mod1Mask)?"Alt-":"",
                    ((x_key_event->state & ShiftMask)^(x_key_event->state & LockMask))?
                    (char) toupper((int) keysym) : (char) tolower((int)keysym));
 #endif /* SPI_DEBUG */
-       }
-       else
-       {
+             }
+           else
+           {
 #ifdef SPI_KEYEVENT_DEBUG
-               fprintf (stderr, "other event, type %d\n", (int) x_event->type);
-#endif
-       }
-       /* relay to listeners, and decide whether to consume it or not */
-       for (i=0; i<n_listeners && !is_consumed; ++i)
-       {
-         Accessibility_KeystrokeListener ls;
-         ls = (Accessibility_KeystrokeListener)
-                       g_list_nth_data (controller->key_listeners, i);
-         if (!CORBA_Object_is_nil(ls, &ev))
-         {
-           is_consumed = Accessibility_KeystrokeListener_keyEvent (ls, &key_event, &ev);
-         }             
-       }
-       if (is_consumed) XNextEvent (GDK_DISPLAY(), x_event);
-       XAllowEvents (GDK_DISPLAY(), ReplayKeyboard, CurrentTime);
-/*
- *  I haven't figure out how to make this work correctly yet :-(
- *
- *     XGrabKeyboard (GDK_DISPLAY(), GDK_ROOT_WINDOW(), True,
- *                    GrabModeAsync, GrabModeSync, CurrentTime);
- *      XAllowEvents (GDK_DISPLAY(), SyncKeyboard, CurrentTime);
- *
- *
- * ControlMask grabs are broken, must be in use already.
- *
- */
-       
-/* Always grab ShiftLock in DEBUG mode */
-#ifdef SPI_DEBUG
-       if (!controller->keymask_list)
-           controller->keymask_list =
-               g_list_append (controller->keymask_list, &shiftlock_mask);
+                   fprintf (stderr, "other event, type %d\n", (int) x_event->type);
 #endif
+           }
+           /* relay to listeners, and decide whether to consume it or not */
+           is_consumed = notify_keylisteners (controller->key_listeners, &key_event, &ev);
+
+           if (is_consumed)
+           {
+             XAllowEvents (display, SyncKeyboard, CurrentTime);
+           }
+           else
+           {
+             XAllowEvents (display, ReplayKeyboard, CurrentTime);
+           }
+         }
+       XUngrabKey (display, AnyKey, AnyModifier, root_window);
        return _controller_grab_keyboard (controller);
 }
 
 static gboolean
-_controller_grab_keyboard (DeviceEventController *controller)
+_controller_grab_keyboard (SpiDeviceEventController *controller)
 {
-       Display *display = GDK_DISPLAY();
-       Window root_window = GDK_ROOT_WINDOW();
        GList *maskList = controller->keymask_list;
        int i;
-       int last_mask = g_list_length (maskList);
+       int last_mask;
+       last_mask = g_list_length (maskList);
 
 /*
  * masks known to work with default RH 7.1: 
@@ -326,9 +370,6 @@ _controller_grab_keyboard (DeviceEventController *controller)
 #endif
                if (!(maskVal & ControlMask))
                {
-#ifdef SPI_KEYEVENT_DEBUG
-                       fprintf (stderr, "grabbing for mod %lu\n", (unsigned long) maskVal);
-#endif
                        XGrabKey (display,
                                  AnyKey,
                                  maskVal,
@@ -348,13 +389,13 @@ _controller_grab_keyboard (DeviceEventController *controller)
  * Implemented GObject::finalize
  */
 static void
-device_event_controller_object_finalize (GObject *object)
+spi_device_event_controller_object_finalize (GObject *object)
 {
 
 #ifdef SPI_DEBUG
-        fprintf(stderr, "device_event_controller_object_finalize called\n");
+        fprintf(stderr, "spi_device_event_controller_object_finalize called\n");
 #endif
-        device_event_controller_parent_class->finalize (object);
+        spi_device_event_controller_parent_class->finalize (object);
 }
 
 /*
@@ -364,16 +405,51 @@ device_event_controller_object_finalize (GObject *object)
 static void
 impl_register_keystroke_listener (PortableServer_Servant     servant,
                                  const Accessibility_KeystrokeListener l,
+                                 const Accessibility_KeySet *keys,
                                  const Accessibility_ControllerEventMask *mask,
+                                 const Accessibility_KeyEventTypeSeq *type,
+                                 const CORBA_boolean is_system_global,
                                  CORBA_Environment         *ev)
 {
-       DeviceEventController *controller = DEVICE_EVENT_CONTROLLER (
+       SpiDeviceEventController *controller = SPI_DEVICE_EVENT_CONTROLLER (
                bonobo_object_from_servant (servant));
+       DEControllerKeyListener *dec_listener;
 #ifdef SPI_DEBUG
        fprintf (stderr, "registering keystroke listener %p with maskVal %lu\n",
                 (void *) l, (unsigned long) mask->value);
 #endif
-       _controller_register_device_listener(controller, l, mask, DEVICE_TYPE_KBD, ev);
+       dec_listener = dec_key_listener_new (l, keys, mask, type, is_system_global, ev);
+       controller_register_device_listener (controller, (DEControllerListener *) dec_listener, ev);
+}
+
+/*
+ * CORBA Accessibility::DeviceEventController::deregisterKeystrokeListener
+ *     method implementation
+ */
+static void
+impl_deregister_keystroke_listener (PortableServer_Servant     servant,
+                                   const Accessibility_KeystrokeListener l,
+                                   const Accessibility_KeySet *keys,
+                                   const Accessibility_ControllerEventMask *mask,
+                                   const Accessibility_KeyEventTypeSeq *type,
+                                   const CORBA_boolean is_system_global,
+                                   CORBA_Environment         *ev)
+{
+       SpiDeviceEventController *controller = SPI_DEVICE_EVENT_CONTROLLER (
+               bonobo_object_from_servant (servant));
+       DEControllerKeyListener *key_listener = dec_key_listener_new (l,
+                                                                     keys,
+                                                                     mask,
+                                                                     type,
+                                                                     is_system_global,
+                                                                     ev);
+#ifdef SPI_DEBUG
+       fprintf (stderr, "deregistering keystroke listener %p with maskVal %lu\n",
+                (void *) l, (unsigned long) mask->value);
+#endif
+       controller_deregister_device_listener(controller,
+                                             (DEControllerListener *) key_listener,
+                                             ev);
 }
 
 /*
@@ -386,27 +462,60 @@ impl_register_mouse_listener (PortableServer_Servant     servant,
                              const Accessibility_MouseListener *l,
                              CORBA_Environment         *ev)
 {
-       DeviceEventController *controller = DEVICE_EVENT_CONTROLLER (
+       SpiDeviceEventController *controller = SPI_DEVICE_EVENT_CONTROLLER (
                bonobo_object_from_servant (servant));
 #ifdef SPI_DEBUG
        fprintf (stderr, "registering mouse listener %p\n", l);
 #endif
-       _controller_register_device_listener(controller, l, mask, DEVICE_TYPE_MOUSE, ev);
+       controller_register_device_listener(controller, DEVICE_TYPE_MOUSE, l, keys, mask, ev);
 }
 */
 
+static KeyCode
+keycode_for_keysym (long keysym)
+{
+  return XKeysymToKeycode (display, (KeySym) keysym);
+}
+
 /*
  * CORBA Accessibility::DeviceEventController::registerKeystrokeListener
  *     method implementation
  */
 static void
 impl_generate_key_event (PortableServer_Servant     servant,
-                        const CORBA_long           keyEventID,
-                        CORBA_Environment         *ev)
+                        const CORBA_long           keycode,
+                        const Accessibility_KeySynthType synth_type,
+                        CORBA_Environment          *ev)
 {
+       long key_synth_code;
 #ifdef SPI_DEBUG
-       fprintf (stderr, "synthesizing keystroke %ld\n", (long) keyEventID);
+       fprintf (stderr, "synthesizing keystroke %ld\n", (long) keycode);
 #endif
+       /* TODO: hide/wrap/remove X dependency */
+
+       /* TODO: be accessX-savvy so that keyrelease occurs after sufficient timeout */
+       
+       /*
+        * TODO: when initializing, query for XTest extension before using,
+        * and fall back to XSendEvent() if XTest is not available.
+        */
+       
+       switch (synth_type)
+       {
+       case Accessibility_KEY_PRESS:
+               XTestFakeKeyEvent (GDK_DISPLAY(), (unsigned int) keycode, True, CurrentTime);
+               break;
+       case Accessibility_KEY_PRESSRELEASE:
+               XTestFakeKeyEvent (GDK_DISPLAY(), (unsigned int) keycode, True, CurrentTime);
+       case Accessibility_KEY_RELEASE:
+               XTestFakeKeyEvent (GDK_DISPLAY(), (unsigned int) keycode, False, CurrentTime);
+               break;
+       case Accessibility_KEY_SYM:
+               key_synth_code = keycode_for_keysym (keycode);
+               XTestFakeKeyEvent (GDK_DISPLAY(), (unsigned int) key_synth_code, True, CurrentTime);
+               XTestFakeKeyEvent (GDK_DISPLAY(), (unsigned int) key_synth_code, False, CurrentTime);
+               break;
+       }
 }
 
 /*
@@ -426,15 +535,16 @@ impl_generate_mouse_event (PortableServer_Servant     servant,
 }
 
 static void
-device_event_controller_class_init (DeviceEventControllerClass *klass)
+spi_device_event_controller_class_init (SpiDeviceEventControllerClass *klass)
 {
         GObjectClass * object_class = (GObjectClass *) klass;
         POA_Accessibility_DeviceEventController__epv *epv = &klass->epv;
-        device_event_controller_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE);
+        spi_device_event_controller_parent_class = g_type_class_ref (BONOBO_OBJECT_TYPE);
 
-        object_class->finalize = device_event_controller_object_finalize;
+        object_class->finalize = spi_device_event_controller_object_finalize;
 
         epv->registerKeystrokeListener = impl_register_keystroke_listener;
+        epv->deregisterKeystrokeListener = impl_deregister_keystroke_listener;
 /*        epv->registerMouseListener = impl_register_mouse_listener; */
         epv->generateKeyEvent = impl_generate_key_event;
         epv->generateMouseEvent = impl_generate_mouse_event;
@@ -442,37 +552,48 @@ device_event_controller_class_init (DeviceEventControllerClass *klass)
 }
 
 static void
-device_event_controller_init (DeviceEventController *device_event_controller)
+spi_device_event_controller_init (SpiDeviceEventController *device_event_controller)
 {
   device_event_controller->key_listeners = NULL;
-  device_event_controller->key_listeners = NULL;
+  device_event_controller->mouse_listeners = NULL;
   device_event_controller->keymask_list = NULL;
   kbd_registered = _controller_register_with_devices (device_event_controller);
 }
 
-gboolean device_event_controller_check_key_event (DeviceEventController *controller)
+gboolean spi_device_event_controller_check_key_event (SpiDeviceEventController *controller)
 {
-       DeviceEventControllerClass *klass = DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+       SpiDeviceEventControllerClass *klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
        if (klass->check_key_event)
                return (klass->check_key_event) (controller);
 }
 
+SpiDeviceEventController *
+spi_device_event_controller_new (void *registryp)
+{
+  SpiRegistry *registry = SPI_REGISTRY (registryp);    
+  SpiDeviceEventController *retval = 
+         SPI_DEVICE_EVENT_CONTROLLER (g_object_new (SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL));
+  retval->registry = registry;
+  bonobo_object_ref (registry);
+  return retval;
+}
+
 GType
-device_event_controller_get_type (void)
+spi_device_event_controller_get_type (void)
 {
         static GType type = 0;
 
         if (!type) {
                 static const GTypeInfo tinfo = {
-                        sizeof (DeviceEventControllerClass),
+                        sizeof (SpiDeviceEventControllerClass),
                         (GBaseInitFunc) NULL,
                         (GBaseFinalizeFunc) NULL,
-                        (GClassInitFunc) device_event_controller_class_init,
+                        (GClassInitFunc) spi_device_event_controller_class_init,
                         (GClassFinalizeFunc) NULL,
                         NULL, /* class data */
-                        sizeof (DeviceEventController),
+                        sizeof (SpiDeviceEventController),
                         0, /* n preallocs */
-                        (GInstanceInitFunc) device_event_controller_init,
+                        (GInstanceInitFunc) spi_device_event_controller_init,
                         NULL /* value table */
                 };
                 /*
@@ -485,9 +606,9 @@ device_event_controller_get_type (void)
                         PARENT_TYPE,
                         POA_Accessibility_DeviceEventController__init,
                         NULL,
-                        G_STRUCT_OFFSET (DeviceEventControllerClass, epv),
+                        G_STRUCT_OFFSET (SpiDeviceEventControllerClass, epv),
                         &tinfo,
-                        "DeviceEventController");
+                        "SpiDeviceEventController");
         }
 
         return type;