CORBA_Environment *ev)
{
DEControllerKeyListener *key_listener = g_new0 (DEControllerKeyListener, 1);
- key_listener->listener.object = CORBA_Object_duplicate (l, ev);
+ key_listener->listener.object = bonobo_object_dup_ref (l, ev);
key_listener->listener.type = SPI_DEVICE_TYPE_KBD;
key_listener->keys = ORBit_copy_value (keys, TC_Accessibility_KeySet);
key_listener->mask = ORBit_copy_value (mask, TC_Accessibility_ControllerEventMask);
}
static void
+dec_key_listener_free (DEControllerKeyListener *key_listener, CORBA_Environment *ev)
+{
+ bonobo_object_release_unref (key_listener->listener.object, ev);
+ CORBA_free (key_listener->typeseq);
+ CORBA_free (key_listener->mask);
+ CORBA_free (key_listener->keys);
+ g_free (key_listener);
+}
+
+static void
controller_register_device_listener (SpiDeviceEventController *controller,
DEControllerListener *listener,
CORBA_Environment *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 *)
+ controller->key_listeners = g_list_prepend (controller->key_listeners, key_listener);
+ if (key_listener->is_system_global)
+ {
+ mask_ptr = (Accessibility_ControllerEventMask *)
g_list_find_custom (controller->keymask_list, (gpointer) key_listener->mask,
_eventmask_compare_value);
- if (mask_ptr)
+ if (mask_ptr)
++(mask_ptr->refcount);
- else
- {
+ else
+ {
if (key_listener->mask->refcount != (CORBA_unsigned_short) 1)
fprintf (stderr, "mask initial refcount is not 1!\n");
if (key_listener->mask->value > (CORBA_unsigned_long) 2048)
mask_ptr->refcount = (CORBA_unsigned_short) 1;
controller->keymask_list = g_list_append (controller->keymask_list,
(gpointer) mask_ptr);
- }
+ }
+ }
break;
case SPI_DEVICE_TYPE_MOUSE:
/* controller->mouse_listeners = g_list_append (controller->mouse_listeners,
{
Accessibility_ControllerEventMask *mask_ptr;
DEControllerKeyListener *key_listener;
+ DEControllerListener *dec_listener;
GList *list_ptr;
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);
+ /* first, deref matching event mask, if any */
list_ptr = (GList *)
g_list_find_custom (controller->keymask_list, (gpointer) key_listener->mask,
_eventmask_compare_value);
if (!mask_ptr->refcount)
{
controller->keymask_list =
- g_list_remove (controller->keymask_list, mask_ptr);
+ g_list_remove_link (controller->keymask_list, list_ptr);
; /* TODO: release any key grabs that are in place for this key mask */
}
}
+ /* now, remove this listener from the keylistener list */
+ list_ptr = g_list_find_custom (controller->key_listeners, listener, _compare_listeners);
+ if (list_ptr)
+ {
+ dec_listener = (DEControllerListener *) list_ptr->data;
+#ifdef SPI_DEBUG
+ g_print ("removing keylistener %p\n", dec_listener->object);
+#endif
+ controller->key_listeners = g_list_remove_link (controller->key_listeners,
+ list_ptr);
+ dec_key_listener_free (dec_listener, ev);
+ }
break;
case SPI_DEVICE_TYPE_MOUSE:
/* controller->mouse_listeners = g_list_append (controller->mouse_listeners,
for (i=0; i<len; ++i)
{
- g_print ("key_set[%d] = %d\n", i, (int) key_set->_buffer[i]);
- if (key_set->_buffer[i] == (CORBA_long) key_event->keyID) return TRUE;
+#ifdef SPI_KEYEVENT_DEBUG
+ g_print ("key_set[%d] = %d; key_event %d, code %d\n",
+ i,
+ (int) key_set->_buffer[i],
+ (int) key_event->keyID,
+ (int) key_event->keycode);
+#endif
+ if (key_set->_buffer[i] == (CORBA_long) key_event->keyID) return TRUE;
+ if (key_set->_buffer[i] == (CORBA_long) -key_event->keycode) return TRUE;
}
- return TRUE;
+ return FALSE;
}
static gboolean
for (i=0; i<len; ++i)
{
- g_print ("type_seq[%d] = %d\n", i, (int) type_seq->_buffer[i]);
+/* g_print ("type_seq[%d] = %d\n", i, (int) type_seq->_buffer[i]); */
if (type_seq->_buffer[i] == (CORBA_long) key_event->type) return TRUE;
}
is_consumed = Accessibility_KeystrokeListener_keyEvent (ls, key_event, ev);
}
}
- else g_print ("no match for listener %d\n", i);
+ else
+ {
+#ifdef SPI_KEYEVENT_DEBUG
+ g_print ("no match for listener %d\n", i);
+#endif
+ ;
+ }
}
return is_consumed;
}
#ifdef SPI_DEBUG
fprintf(stderr, "spi_device_event_controller_object_finalize called\n");
#endif
+ /* disconnect any special listeners, get rid of outstanding keygrabs */
+
spi_device_event_controller_parent_class->finalize (object);
}
type,
is_system_global,
ev);
-#ifdef SPI_DEBUG
+#ifdef SPI_DEREGISTER_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);
+ dec_key_listener_free (key_listener, ev);
}
/*