#include <sys/time.h>
#include <X11/Xlib.h>
+#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
#include <X11/XKBlib.h>
#define XK_MISCELLANY
#endif /* HAVE_XEVIE */
#include <glib.h>
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h> /* TODO: hide dependency (wrap in single porting file) */
-#include <gdk/gdkkeysyms.h>
-#include <gdk/gdkwindow.h>
-#include <atk-adaptor/spi-private.h>
-#include <atk-adaptor/keymasks.h>
-#include <droute/droute.h>
-#include <spi-common/spi-dbus.h>
-#include <spi-common/spi-types.h>
+#include <dbus/dbus.h>
+
+#include "paths.h"
+#include "keymasks.h"
+#include "de-types.h"
+#include "de-marshaller.h"
+#include "display.h"
+#include "event-source.h"
#include "deviceeventcontroller.h"
#include "reentrant-list.h"
+#include "introspection.h"
+
KeySym ucs2keysym (long ucs);
long keysym2ucs(KeySym keysym);
/* A pointer to our parent object class */
static int spi_error_code = 0;
-static GdkPoint last_mouse_pos_static = {0, 0};
-static GdkPoint *last_mouse_pos = &last_mouse_pos_static;
+struct _SpiPoint {
+ gint x;
+ gint y;
+};
+typedef struct _SpiPoint SpiPoint;
+static SpiPoint last_mouse_pos_static = {0, 0};
+static SpiPoint *last_mouse_pos = &last_mouse_pos_static;
static unsigned int mouse_mask_state = 0;
static unsigned int mouse_button_mask =
Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask;
static GQuark spi_dec_private_quark = 0;
static XModifierKeymap* xmkeymap = NULL;
+static gboolean have_mouse_listener = FALSE;
+static gboolean have_mouse_event_listener = FALSE;
+
static int (*x_default_error_handler) (Display *display, XErrorEvent *error_event);
typedef enum {
} DEControllerGrabMask;
typedef struct {
- char *app_path;
+ char *bus_name;
char *path;
SpiDeviceTypeCategory type;
gulong types;
static gboolean spi_dec_poll_mouse_moving (gpointer data);
static gboolean spi_dec_poll_mouse_idle (gpointer data);
-#define spi_get_display() GDK_DISPLAY()
-
G_DEFINE_TYPE(SpiDEController, spi_device_event_controller, G_TYPE_OBJECT)
+DBusMessage *
+invalid_arguments_error (DBusMessage *message)
+{
+ DBusMessage *reply;
+ gchar *errmsg;
+
+ errmsg= g_strdup_printf (
+ "Method \"%s\" with signature \"%s\" on interface \"%s\" was supplied with invalid arguments\n",
+ dbus_message_get_member (message),
+ dbus_message_get_signature (message),
+ dbus_message_get_interface (message));
+ reply = dbus_message_new_error (message,
+ DBUS_ERROR_INVALID_ARGS,
+ errmsg);
+ g_free (errmsg);
+ return reply;
+}
+
/* Private methods */
+static dbus_bool_t
+spi_dbus_add_disconnect_match (DBusConnection *bus, const char *name)
+{
+ char *match = g_strdup_printf ("interface=%s,member=NameOwnerChanged,arg0=%s", DBUS_INTERFACE_DBUS, name);
+ if (match)
+ {
+ DBusError error;
+ dbus_error_init (&error);
+ dbus_bus_add_match (bus, match, &error);
+ g_free (match);
+ if (dbus_error_is_set (&error))
+ {
+ dbus_error_free (&error);
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+ else return FALSE;
+}
+
+static dbus_bool_t
+spi_dbus_remove_disconnect_match (DBusConnection *bus, const char *name)
+{
+ char *match = g_strdup_printf ("interface=%s,member=NameOwnerChanged,arg0=%s", DBUS_INTERFACE_DBUS, name);
+ if (match)
+ {
+ DBusError error;
+ dbus_error_init (&error);
+ dbus_bus_remove_match (bus, match, &error);
+ g_free (match);
+ if (dbus_error_is_set (&error))
+ {
+ dbus_error_free (&error);
+ return FALSE;
+ }
+ else
+ {
+ return TRUE;
+ }
+ }
+ else return FALSE;
+}
static unsigned int
keysym_mod_mask (KeySym keysym, KeyCode keycode)
{
DEControllerPrivateData *priv =
g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
- priv->xkb_latch_mask = 0;
+ priv->xkb_latch_mask = 0;
}
-
-static void emit(SpiDEController *controller, const char *name, int first_type, ...)
+
+static void emit(SpiDEController *controller, const char *interface, const char *name, const char *minor, int a1, int a2)
{
- va_list arg;
+ DBusMessage *signal = NULL;
+ DBusMessageIter iter, iter_struct, iter_variant;
+ int nil = 0;
+ const char *path = SPI_DBUS_PATH_ROOT;
+ const char *bus_name = dbus_bus_get_unique_name (controller->bus);
+
+ signal = dbus_message_new_signal (path, interface, name);
- va_start(arg, first_type);
- spi_dbus_emit_valist(controller->registry->droute.bus, SPI_DBUS_PATH_DEC, SPI_DBUS_INTERFACE_DEC, name, first_type, arg);
- va_end(arg);
+ dbus_message_iter_init_append (signal, &iter);
+
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &minor);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &a1);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_INT32, &a2);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "i", &iter_variant);
+ dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, &nil);
+ dbus_message_iter_close_container (&iter, &iter_variant);
+
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
+ &iter_struct);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &bus_name);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
+ dbus_message_iter_close_container (&iter, &iter_struct);
+
+ dbus_connection_send (controller->bus, signal, NULL);
+ dbus_message_unref (signal);
}
static gboolean
-spi_dec_button_update_and_emit (SpiDEController *controller,
+spi_dec_button_update_and_emit (SpiDEController *controller,
guint mask_return)
{
Accessibility_DeviceEvent mouse_e;
- gchar event_name[24];
+ gchar event_detail[3];
gboolean is_consumed = FALSE;
if ((mask_return & mouse_button_mask) !=
fprintf (stderr, "Button %d %s\n",
button_number, (is_down) ? "Pressed" : "Released");
#endif
- snprintf (event_name, 22, "mouse:button:%d%c", button_number,
+ snprintf (event_detail, 3, "%d%c", button_number,
(is_down) ? 'p' : 'r');
/* TODO: FIXME distinguish between physical and
* logical buttons
if (!is_consumed)
{
dbus_uint32_t x = last_mouse_pos->x, y = last_mouse_pos->y;
- emit(controller, event_name, DBUS_TYPE_UINT32, &x, DBUS_TYPE_UINT32, &y, DBUS_TYPE_INVALID);
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, x, y);
}
else
spi_dec_set_unlatch_pending (controller, mask_return);
{
// TODO: combine these two signals?
dbus_uint32_t ix = *x, iy = *y;
- emit(controller, "mouse_abs", DBUS_TYPE_UINT32, &ix, DBUS_TYPE_UINT32, &iy, DBUS_TYPE_INVALID);
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Abs", "", ix, iy);
ix -= last_mouse_pos->x;
iy -= last_mouse_pos->y;
- emit(controller, "mouse_rel", DBUS_TYPE_UINT32, &ix, DBUS_TYPE_UINT32, &iy, DBUS_TYPE_INVALID);
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Rel", "", ix, iy);
last_mouse_pos->x = *x;
last_mouse_pos->y = *y;
*moved = True;
d1 = prev_mask & key_modifier_mask;
d2 = current_mask & key_modifier_mask;
- emit(controller, "keyboard_modifiers", DBUS_TYPE_UINT32, &d1, DBUS_TYPE_UINT32, &d2, DBUS_TYPE_INVALID);
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_KEYBOARD, "Modifiers", "", d1, d2);
}
static gboolean
spi_dec_poll_mouse_moved (gpointer data)
{
- SpiRegistry *registry = SPI_REGISTRY (data);
- SpiDEController *controller = registry->de_controller;
- int x, y;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(data);
+ int x, y;
gboolean moved;
guint mask_return;
mask_return = spi_dec_mouse_check (controller, &x, &y, &moved);
-
+
if ((mask_return & key_modifier_mask) !=
(mouse_mask_state & key_modifier_mask))
{
static gboolean
spi_dec_poll_mouse_idle (gpointer data)
{
- if (! spi_dec_poll_mouse_moved (data))
+ if (!have_mouse_event_listener && !have_mouse_listener)
+ return FALSE;
+ else if (!spi_dec_poll_mouse_moved (data))
return TRUE;
else
{
static gboolean
spi_dec_poll_mouse_moving (gpointer data)
{
- if (spi_dec_poll_mouse_moved (data))
+ if (!have_mouse_event_listener && !have_mouse_listener)
+ return FALSE;
+ else if (spi_dec_poll_mouse_moved (data))
return TRUE;
else
{
#endif
static void
-spi_dec_init_mouse_listener (SpiRegistry *registry)
+spi_dec_init_mouse_listener (SpiDEController *dec)
{
#ifdef GRAB_BUTTON
Display *display = spi_get_display ();
-#endif
- g_timeout_add (100, spi_dec_poll_mouse_idle, registry);
-#ifdef GRAB_BUTTON
if (display)
{
if (XGrabButton (display, AnyButton, AnyModifier,
- gdk_x11_get_default_root_xwindow (),
+ spi_get_root_window (),
True, ButtonPressMask | ButtonReleaseMask,
GrabModeSync, GrabModeAsync, None, None) != Success) {
#ifdef SPI_DEBUG
}
static DEControllerKeyListener *
-spi_dec_key_listener_new (const char *app_path,
+spi_dec_key_listener_new (const char *bus_name,
const char *path,
GSList *keys,
const Accessibility_ControllerEventMask mask,
const Accessibility_EventListenerMode *mode)
{
DEControllerKeyListener *key_listener = g_new0 (DEControllerKeyListener, 1);
- key_listener->listener.app_path = g_strdup(app_path);
+ key_listener->listener.bus_name = g_strdup(bus_name);
key_listener->listener.path = g_strdup(path);
key_listener->listener.type = SPI_DEVICE_TYPE_KBD;
key_listener->keys = keys;
}
static DEControllerListener *
-spi_dec_listener_new (const char *app_path,
+spi_dec_listener_new (const char *bus_name,
const char *path,
dbus_uint32_t types)
{
DEControllerListener *listener = g_new0 (DEControllerListener, 1);
- listener->app_path = g_strdup(app_path);
+ listener->bus_name = g_strdup(bus_name);
listener->path = g_strdup(path);
listener->type = SPI_DEVICE_TYPE_MOUSE;
listener->types = types;
spi_listener_clone (DEControllerListener *listener)
{
DEControllerListener *clone = g_new0 (DEControllerListener, 1);
- clone->app_path = g_strdup (listener->app_path);
+ clone->bus_name = g_strdup (listener->bus_name);
clone->path = g_strdup (listener->path);
clone->type = listener->type;
clone->types = listener->types;
spi_key_listener_clone (DEControllerKeyListener *key_listener)
{
DEControllerKeyListener *clone = g_new0 (DEControllerKeyListener, 1);
- clone->listener.app_path = g_strdup (key_listener->listener.app_path);
+ clone->listener.bus_name = g_strdup (key_listener->listener.bus_name);
clone->listener.path = g_strdup (key_listener->listener.path);
clone->listener.type = SPI_DEVICE_TYPE_KBD;
clone->keys = keylist_clone (key_listener->keys);
{
keylist_free(key_listener->keys);
if (key_listener->mode) g_free(key_listener->mode);
+ g_free (key_listener->listener.bus_name);
+ g_free (key_listener->listener.path);
g_free (key_listener);
}
spi_listener_clone_free (DEControllerListener *clone)
{
g_free (clone->path);
- g_free (clone->app_path);
+ g_free (clone->bus_name);
g_free (clone);
}
static void
spi_dec_listener_free (DEControllerListener *listener)
{
- g_free (listener->app_path);
- g_free (listener->path);
if (listener->type == SPI_DEVICE_TYPE_KBD)
spi_key_listener_data_free ((DEControllerKeyListener *) listener);
+ else
+ {
+ g_free (listener->bus_name);
+ g_free (listener->path);
+ }
}
static void
cur_mask->pending_remove = TRUE;
}
}
- else
- {
- DBG (1, g_warning ("De-registering non-existant grab"));
- }
}
static void
spi_controller_update_key_grabs (controller, NULL);
}
+static void
+append_keystroke_listener (DBusMessageIter *iter, DEControllerKeyListener *listener)
+{
+ dbus_uint32_t d_uint;
+ DBusMessageIter iter_struct, iter_subarray, iter_substruct;
+ GList *l;
+ GSList *kl;
+
+ if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL,
+ &iter_struct))
+ return;
+
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING,
+ &listener->listener.bus_name);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH,
+ &listener->listener.path);
+ d_uint = listener->listener.type;
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &d_uint);
+ d_uint = listener->listener.types;
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &d_uint);
+ if (!dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_ARRAY,
+ "(iisi)", &iter_subarray))
+ {
+ dbus_message_iter_close_container (iter, &iter_struct);
+ return;
+ }
+ for (kl = listener->keys; kl; kl = kl->next)
+ {
+ Accessibility_KeyDefinition *kd = kl->data;
+ if (!dbus_message_iter_open_container (&iter_subarray, DBUS_TYPE_STRUCT,
+ NULL, &iter_substruct))
+ break;
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_INT32, &kd->keycode);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_INT32, &kd->keysym);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_STRING, &kd->keystring);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_INT32, &kd->unused);
+ dbus_message_iter_close_container (&iter_subarray, &iter_substruct);
+ }
+ dbus_message_iter_close_container (&iter_struct, &iter_subarray);
+ d_uint = listener->mask;
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &d_uint);
+ if (dbus_message_iter_open_container (&iter_struct, DBUS_TYPE_STRUCT,
+ NULL, &iter_substruct))
+ {
+ if (listener->mode)
+ {
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_BOOLEAN,
+ &listener->mode->synchronous);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_BOOLEAN,
+ &listener->mode->preemptive);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_BOOLEAN,
+ &listener->mode->global);
+ }
+ else
+ {
+ dbus_bool_t dummy_val = FALSE;
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_BOOLEAN,
+ &dummy_val);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_BOOLEAN,
+ &dummy_val);
+ dbus_message_iter_append_basic (&iter_substruct, DBUS_TYPE_BOOLEAN,
+ &dummy_val);
+ }
+ dbus_message_iter_close_container (&iter_struct, &iter_substruct);
+ }
+ dbus_message_iter_close_container (iter, &iter_struct);
+}
+
+static void
+notify_keystroke_listener (SpiDEController *controller,
+ DEControllerKeyListener *listener,
+ gboolean enable)
+{
+ const char *path = SPI_DBUS_PATH_DEC;
+ const char *interface = SPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER;
+ const char *name = (enable
+ ? "KeystrokeListenerRegistered"
+ : "KeystrokeListenerDeregistered");
+ DBusMessage *signal;
+ DBusMessageIter iter;
+
+ signal = dbus_message_new_signal (path, interface, name);
+ if (!signal)
+ return;
+ dbus_message_iter_init_append (signal, &iter);
+ append_keystroke_listener (&iter, listener);
+ dbus_connection_send (controller->bus, signal, NULL);
+ dbus_message_unref (signal);
+}
+
+static void
+append_mouse_listener (DBusMessageIter *iter, DEControllerListener *listener)
+{
+ DBusMessageIter iter_struct;
+ dbus_uint32_t d_uint;
+
+ if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL,
+ &iter_struct))
+ return;
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING,
+ &listener->bus_name);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH,
+ &listener->path);
+ d_uint = listener->types;
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_UINT32, &d_uint);
+ dbus_message_iter_close_container (iter, &iter_struct);
+}
+
+static void
+notify_mouse_listener (SpiDEController *controller,
+ DEControllerListener *listener,
+ gboolean enable)
+{
+ const char *path = SPI_DBUS_PATH_DEC;
+ const char *interface = SPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER;
+ const char *name = (enable
+ ? "DeviceListenerRegistered"
+ : "DeviceListenerDeregistered");
+ DBusMessage *signal;
+ DBusMessageIter iter;
+
+ signal = dbus_message_new_signal (path, interface, name);
+ if (!signal)
+ return;
+ dbus_message_iter_init_append (signal, &iter);
+ append_mouse_listener (&iter, listener);
+ dbus_connection_send (controller->bus, signal, NULL);
+ dbus_message_unref (signal);
+}
+
static gboolean
spi_controller_register_device_listener (SpiDEController *controller,
DEControllerListener *listener)
{
DEControllerKeyListener *key_listener;
+ gboolean retval;
switch (listener->type) {
case SPI_DEVICE_TYPE_KBD:
controller->key_listeners = g_list_prepend (controller->key_listeners,
key_listener);
+ spi_dbus_add_disconnect_match (controller->bus, key_listener->listener.bus_name);
if (key_listener->mode->global)
{
- return spi_controller_register_global_keygrabs (controller, key_listener);
+ retval = spi_controller_register_global_keygrabs (controller, key_listener);
}
else
- return TRUE;
+ retval = TRUE;
+ if (retval)
+ notify_keystroke_listener (controller, key_listener, TRUE);
break;
case SPI_DEVICE_TYPE_MOUSE:
controller->mouse_listeners = g_list_prepend (controller->mouse_listeners, listener);
+ if (!have_mouse_listener)
+ {
+ have_mouse_listener = TRUE;
+ if (!have_mouse_event_listener)
+ g_timeout_add (100, spi_dec_poll_mouse_idle, controller);
+ }
+ spi_dbus_add_disconnect_match (controller->bus, listener->bus_name);
+ notify_mouse_listener (controller, listener, TRUE);
break;
default:
- DBG (1, g_warning ("listener registration for unknown device type.\n"));
break;
}
- return FALSE;
+ return FALSE;
+}
+
+static void
+set_reply (DBusPendingCall *pending, void *user_data)
+{
+ void **replyptr = (void **)user_data;
+
+ *replyptr = dbus_pending_call_steal_reply (pending);
}
-static gboolean Accessibility_DeviceEventListener_notifyEvent(SpiRegistry *registry, DEControllerListener *listener, const Accessibility_DeviceEvent *key_event)
+static GSList *hung_processes = NULL;
+
+static void
+reset_hung_process (DBusPendingCall *pending, void *data)
{
- DBusMessage *message = dbus_message_new_method_call(listener->app_path, listener->path, "org.freedesktop.atspi.Registry", "notifyEvent");
- DBusError error;
+ DBusMessage *message = data;
+ const char *dest = dbus_message_get_destination (message);
+ GSList *l;
+
+ /* At this point we don't care about the result */
+ dbus_pending_call_unref (pending);
+
+ for (l = hung_processes; l; l = l->next)
+ {
+ if (!strcmp (l->data, dest))
+ {
+ g_free (l->data);
+ hung_processes = g_slist_remove (hung_processes, l->data);
+ break;
+ }
+ }
+}
+
+static gint
+time_elapsed (struct timeval *origin)
+{
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ return (tv.tv_sec - origin->tv_sec) * 1000 + (tv.tv_usec - origin->tv_usec) / 1000;
+}
+
+static void
+reset_hung_process_from_ping (DBusPendingCall *pending, void *data)
+{
+ gchar *bus_name = data;
+ GSList *l;
+
+ for (l = hung_processes; l; l = l->next)
+ {
+ if (!strcmp (l->data, data))
+ {
+ g_free (l->data);
+ hung_processes = g_slist_remove (hung_processes, l->data);
+ break;
+ }
+ }
+ g_free (data);
+ dbus_pending_call_unref (pending);
+}
+
+static DBusMessage *
+send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, int timeout, DBusError *error)
+{
+ DBusPendingCall *pending;
+ DBusMessage *reply = NULL;
+ struct timeval tv;
+
+ if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
+ {
+ return NULL;
+ }
+ dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
+ gettimeofday (&tv, NULL);
+ while (!reply)
+ {
+ if (!dbus_connection_read_write_dispatch (bus, timeout) ||
+ time_elapsed (&tv) > timeout)
+ {
+ const char *dest = dbus_message_get_destination (message);
+ GSList *l;
+ gchar *bus_name_dup;
+ dbus_message_ref (message);
+ dbus_pending_call_set_notify (pending, reset_hung_process, message,
+ (DBusFreeFunction) dbus_message_unref);
+ message = dbus_message_new_method_call (dest, "/",
+ "org.freedesktop.DBus.Peer",
+ "Ping");
+ if (!message)
+ return NULL;
+ dbus_connection_send_with_reply (bus, message, &pending, -1);
+ dbus_message_unref (message);
+ if (!pending)
+ return NULL;
+ bus_name_dup = g_strdup (dest);
+ dbus_pending_call_set_notify (pending, reset_hung_process_from_ping,
+ bus_name_dup, NULL);
+ for (l = hung_processes; l; l = l->next)
+ if (!strcmp (l->data, dest))
+ return NULL;
+ hung_processes = g_slist_prepend (hung_processes, g_strdup (dest));
+ return NULL;
+ }
+ }
+ dbus_pending_call_unref (pending);
+ return reply;
+}
+static gboolean
+Accessibility_DeviceEventListener_NotifyEvent(SpiDEController *controller,
+ SpiRegistry *registry,
+ DEControllerListener *listener,
+ const Accessibility_DeviceEvent *key_event)
+{
+ DBusMessage *message = dbus_message_new_method_call(listener->bus_name,
+ listener->path,
+ SPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER,
+ "NotifyEvent");
dbus_bool_t consumed = FALSE;
+ GSList *l;
+ gboolean hung = FALSE;
+
+ for (l = hung_processes; l; l = l->next)
+ {
+ if (!strcmp (l->data, listener->bus_name))
+ {
+ dbus_message_set_no_reply (message, TRUE);
+ hung = TRUE;
+ break;
+ }
+ }
- dbus_error_init(&error);
- if (spi_dbus_marshall_deviceEvent(message, key_event))
+ if (spi_dbus_marshal_deviceEvent(message, key_event))
{
- // TODO: Evaluate performance: perhaps rework this whole architecture
- // to avoid blocking calls
- DBusMessage *reply = dbus_connection_send_with_reply_and_block(registry->droute.bus, message, 1000, &error);
+ DBusMessage *reply;
+
+ if (hung)
+ {
+ dbus_connection_send (controller->bus, message, NULL);
+ dbus_message_unref (message);
+ return FALSE;
+ }
+
+ reply = send_and_allow_reentry (controller->bus, message, 3000, NULL);
if (reply)
{
- DBusError error;
- dbus_error_init(&error);
- dbus_message_get_args(reply, &error, DBUS_TYPE_BOOLEAN, &consumed, DBUS_TYPE_INVALID);
+ dbus_message_get_args(reply, NULL, DBUS_TYPE_BOOLEAN, &consumed, DBUS_TYPE_INVALID);
dbus_message_unref(reply);
}
}
is_consumed = FALSE;
for (l2 = notify; l2 && !is_consumed; l2 = l2->next)
{
- DEControllerListener *listener = l2->data;
+ DEControllerListener *listener = l2->data;
+
+ is_consumed = Accessibility_DeviceEventListener_NotifyEvent (controller, controller->registry, listener, event);
- is_consumed = Accessibility_DeviceEventListener_notifyEvent (controller->registry, listener, event);
-
spi_listener_clone_free ((DEControllerListener *) l2->data);
}
for (; l2; l2 = l2->next)
{
- DEControllerListener *listener = l2->data;
+ DEControllerListener *listener = l2->data;
spi_listener_clone_free (listener);
/* clone doesn't have its own ref, so don't use spi_device_listener_free */
}
XEvent *xevent)
{
Accessibility_DeviceEvent mouse_e;
- gchar event_name[24];
+ gchar event_detail[3];
gboolean is_consumed = FALSE;
gboolean xkb_mod_unlatch_occurred;
XButtonEvent *xbutton_event = (XButtonEvent *) xevent;
(xevent->type == ButtonPress) ? "Press" : "Release",
mouse_button_state);
#endif
- snprintf (event_name, 22, "mouse:button_%d%c", button,
+ snprintf (event_detail, 3, "%d%c", button,
(xevent->type == ButtonPress) ? 'p' : 'r');
/* TODO: FIXME distinguish between physical and logical buttons */
spi_controller_notify_mouselisteners (controller, &mouse_e);
ix = last_mouse_pos->x;
iy = last_mouse_pos->y;
- emit(controller, event_name, DBUS_TYPE_UINT32, &ix, DBUS_TYPE_UINT32, &iy, DBUS_TYPE_INVALID);
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, ix, iy);
}
xkb_mod_unlatch_occurred = (xevent->type == ButtonPress ||
CurrentTime);
}
-static GdkFilterReturn
-global_filter_fn (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
+static void
+global_filter_fn (XEvent *xevent, void *data)
{
- XEvent *xevent = gdk_xevent;
SpiDEController *controller;
DEControllerPrivateData *priv;
Display *display = spi_get_display ();
}
}
- return GDK_FILTER_CONTINUE;
+ return;
}
if (xevent->type == ButtonPress || xevent->type == ButtonRelease)
{
priv->xkb_latch_mask = xkb_snev->latched_mods;
}
}
- else
- DBG (2, g_warning ("XKB event %d\n", xkb_ev->xkb_type));
XSynchronize (display, FALSE);
}
- return GDK_FILTER_CONTINUE;
+ return;
}
static int
static void
spi_controller_register_with_devices (SpiDEController *controller)
{
- DEControllerPrivateData *priv = (DEControllerPrivateData *)
- g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
- /* FIXME: should check for extension first! */
- XTestGrabControl (spi_get_display (), True);
+ DEControllerPrivateData *priv;
+ int event_base, error_base, major_version, minor_version;
+
+ priv = (DEControllerPrivateData *) g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
+ if (XTestQueryExtension (spi_get_display(), &event_base, &error_base, &major_version, &minor_version))
+ {
+ XTestGrabControl (spi_get_display (), True);
+ }
/* calls to device-specific implementations and routines go here */
/* register with: keyboard hardware code handler */
if (XKeycodeToKeysym (spi_get_display (), i, 0) != 0)
{
/* don't use this one if there's a grab client! */
- gdk_error_trap_push ();
+
+ /* Runtime errors are generated from these functions,
+ * that are then quashed. Equivalent to:
+ * try
+ * {Blah}
+ * except
+ * {;}
+ */
+
+ spi_x_error_trap ();
XGrabKey (spi_get_display (), i, 0,
- gdk_x11_get_default_root_xwindow (),
+ spi_get_root_window (),
TRUE,
GrabModeSync, GrabModeSync);
XSync (spi_get_display (), TRUE);
XUngrabKey (spi_get_display (), i, 0,
- gdk_x11_get_default_root_xwindow ());
- if (!gdk_error_trap_pop ())
+ spi_get_root_window ());
+ if (!spi_x_error_release ())
{
reserved = i;
break;
#endif
}
- gdk_window_add_filter (NULL, global_filter_fn, controller);
-
- gdk_window_set_events (gdk_get_default_root_window (),
- GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
+ spi_set_filter (global_filter_fn, controller);
+ spi_set_events (KeyPressMask | KeyReleaseMask);
x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler);
}
if (!key_set)
{
- g_print ("null key set!");
+#ifdef SPI_DEBUG
+ g_print ("null key set!\n");
+#endif
return TRUE;
}
{
DEControllerKeyListener *key_listener = l2->data;
- is_consumed = Accessibility_DeviceEventListener_notifyEvent (controller->registry, &key_listener->listener, key_event) &&
+ is_consumed = Accessibility_DeviceEventListener_NotifyEvent (controller, controller->registry, &key_listener->listener, key_event) &&
key_listener->mode->preemptive;
spi_key_listener_clone_free (key_listener);
XUngrabKey (spi_get_display (),
grab_mask->key_val,
grab_mask->mod_mask,
- gdk_x11_get_default_root_xwindow ());
+ spi_get_root_window ());
do_remove = TRUE;
}
XGrabKey (spi_get_display (),
grab_mask->key_val,
grab_mask->mod_mask,
- gdk_x11_get_default_root_xwindow (),
+ spi_get_root_window (),
True,
GrabModeSync,
GrabModeSync);
}
/*
- * DBus Accessibility::DEController::registerKeystrokeListener
+ * DBus Accessibility::DEController::RegisterKeystrokeListener
* method implementation
*/
static DBusMessage *
DBusMessage *message,
void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
DEControllerKeyListener *dec_listener;
DBusMessageIter iter, iter_array;
const char *path;
GSList *keys = NULL;
dbus_int32_t mask, type;
Accessibility_EventListenerMode *mode;
- dbus_bool_t ret;
- DBusMessage *reply;
+ dbus_bool_t ret;
+ DBusMessage *reply = NULL;
char *keystring;
+ if (strcmp (dbus_message_get_signature (message), "oa(iisi)uu(bbb)") != 0)
+ return invalid_arguments_error (message);
+
dbus_message_iter_init(message, &iter);
- // TODO: verify type signature
dbus_message_iter_get_basic(&iter, &path);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &iter_array);
dbus_message_get_sender(message), path, (unsigned long) mask);
#endif
dec_listener = spi_dec_key_listener_new (dbus_message_get_sender(message), path, keys, mask, type, mode);
+ g_free (mode);
ret = spi_controller_register_device_listener (
controller, (DEControllerListener *) dec_listener);
reply = dbus_message_new_method_return (message);
}
/*
- * DBus Accessibility::DEController::registerDeviceEventListener
+ * DBus Accessibility::DEController::RegisterDeviceEventListener
* method implementation
*/
static DBusMessage *
-impl_register_device_listener (DBusConnection *bus,
+impl_register_device_event_listener (DBusConnection *bus,
DBusMessage *message,
void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
DEControllerListener *dec_listener;
- DBusError error;
const char *path;
dbus_int32_t event_types;
dbus_bool_t ret;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
- dbus_error_init(&error);
- if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
{
- return spi_dbus_general_error (message);
+ return invalid_arguments_error (message);
}
dec_listener = spi_dec_listener_new (dbus_message_get_sender(message), path, event_types);
ret = spi_controller_register_device_listener (
DEControllerListener *listener = (*list)->data;
RemoveListenerClosure *ctx = user_data;
- if (!strcmp(ctx->listener->app_path, listener->app_path) &&
+ if (!strcmp(ctx->listener->bus_name, listener->bus_name) &&
!strcmp(ctx->listener->path, listener->path))
{
spi_re_entrant_list_delete_link (list);
+ spi_dbus_remove_disconnect_match (ctx->bus, listener->bus_name);
spi_dec_listener_free (listener);
}
DEControllerKeyListener *key_listener = (*list)->data;
RemoveListenerClosure *ctx = user_data;
- if (!strcmp(ctx->listener->app_path, key_listener->listener.app_path) &&
+ if (!strcmp(ctx->listener->bus_name, key_listener->listener.bus_name) &&
!strcmp(ctx->listener->path, key_listener->listener.path))
{
/* TODO: FIXME aggregate keys in case the listener is registered twice */
{
RemoveListenerClosure ctx;
- ctx.bus = controller->registry->droute.bus;
+ ctx.bus = controller->bus;
ctx.listener = listener;
+ notify_mouse_listener (controller, listener, FALSE);
+
spi_re_entrant_list_foreach (&controller->mouse_listeners,
remove_listener_cb, &ctx);
+ if (!controller->mouse_listeners)
+ have_mouse_listener = FALSE;
}
static void
{
RemoveListenerClosure ctx;
- ctx.bus = controller->registry->droute.bus;
- ctx.listener = (DEControllerListener *) key_listener;
+ ctx.bus = controller->bus;
+ ctx.listener = (DEControllerListener *) spi_key_listener_clone (key_listener);
+
+ notify_keystroke_listener (controller, key_listener, FALSE);
/* special case, copy keyset from existing controller list entry */
if (g_slist_length(key_listener->keys) == 0)
spi_re_entrant_list_foreach (&controller->key_listeners,
copy_key_listener_cb, &ctx);
}
-
+
spi_controller_deregister_global_keygrabs (controller, key_listener);
spi_re_entrant_list_foreach (&controller->key_listeners,
remove_listener_cb, &ctx);
+ spi_key_listener_clone_free ((DEControllerKeyListener *) ctx.listener);
+}
+
+void
+spi_remove_device_listeners (SpiDEController *controller, const char *bus_name)
+{
+ GList *l, *tmp;
+
+ for (l = controller->mouse_listeners; l; l = tmp)
+ {
+ DEControllerListener *listener = l->data;
+ tmp = l->next;
+ if (!strcmp (listener->bus_name, bus_name))
+ {
+ spi_controller_deregister_device_listener (controller, listener);
+ tmp = controller->mouse_listeners;
+ }
+ }
+ for (l = controller->key_listeners; l; l = tmp)
+ {
+ DEControllerKeyListener *key_listener = l->data;
+ tmp = l->next;
+ if (!strcmp (key_listener->listener.bus_name, bus_name))
+ {
+ /* TODO: untangle the below line(s) */
+ spi_deregister_controller_key_listener (controller, key_listener);
+ tmp = controller->key_listeners;
+ }
+ }
}
/*
- * DBus Accessibility::DEController::deregisterKeystrokeListener
+ * DBus Accessibility::DEController::DeregisterKeystrokeListener
* method implementation
*/
static DBusMessage *
DBusMessage *message,
void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
DEControllerKeyListener *key_listener;
DBusMessageIter iter, iter_array;
const char *path;
GSList *keys = NULL;
dbus_int32_t mask, type;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
dbus_message_iter_init(message, &iter);
- // TODO: verify type signature
+ if (strcmp (dbus_message_get_signature (message), "oa(iisi)uu") != 0)
+ {
+ g_warning ("Received DeregisterKeystrokeListener with strange signature '%s'", dbus_message_get_signature (message));
+ return invalid_arguments_error (message);
+ }
+
dbus_message_iter_get_basic(&iter, &path);
dbus_message_iter_next(&iter);
dbus_message_iter_recurse(&iter, &iter_array);
}
/*
- * DBus Accessibility::DEController::deregisterDeviceEventListener
+ * DBus Accessibility::DEController::DeregisterDeviceEventListener
* method implementation
*/
static DBusMessage *
-impl_deregister_device_listener (DBusConnection *bus,
+impl_deregister_device_event_listener (DBusConnection *bus,
DBusMessage *message,
void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
DEControllerListener *listener;
- DBusError error;
const char *path;
dbus_int32_t event_types;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
- dbus_error_init(&error);
- if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
{
- return spi_dbus_general_error (message);
+ return invalid_arguments_error (message);
}
listener = spi_dec_listener_new (dbus_message_get_sender(message), path, event_types);
spi_controller_deregister_device_listener (
return reply;
}
+static DBusMessage *
+impl_get_keystroke_listeners (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ DEControllerKeyListener *dec_listener;
+ DBusMessageIter iter, iter_array;
+ DBusMessage *reply = dbus_message_new_method_return (message);
+ GList *l;
+
+ if (!reply)
+ return NULL;
+
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ "(souua(iisi)u(bbb))", &iter_array);
+ for (l = controller->key_listeners; l; l = l->next)
+ {
+ append_keystroke_listener (&iter_array, l->data);
+ }
+ dbus_message_iter_close_container (&iter, &iter_array);
+ return reply;
+}
+
+static DBusMessage *
+impl_get_device_event_listeners (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ DEControllerKeyListener *dec_listener;
+ DBusMessageIter iter, iter_array;
+ GList *l;
+ DBusMessage *reply = dbus_message_new_method_return (message);
+
+ if (!reply)
+ return NULL;
+
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ "(sou)", &iter_array);
+ for (l = controller->key_listeners; l; l = l->next)
+ {
+ append_mouse_listener (&iter_array, l->data);
+ }
+ dbus_message_iter_close_container (&iter, &iter_array);
+ return reply;
+}
+
static unsigned int dec_xkb_get_slowkeys_delay (SpiDEController *controller)
{
unsigned int retval = 0;
gboolean retval = TRUE;
const gchar *c;
- maxlen = strlen (keystring);
+ maxlen = strlen (keystring) + 1;
keysyms = g_new0 (KeySym, maxlen);
if (!(keystring && *keystring && g_utf8_validate (keystring, -1, &c))) {
retval = FALSE;
/*
- * DBus Accessibility::DEController::registerKeystrokeListener
+ * DBus Accessibility::DEController::RegisterKeystrokeListener
* method implementation
*/
static DBusMessage * impl_generate_keyboard_event (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
- DBusError error;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
dbus_int32_t keycode;
char *keystring;
dbus_uint32_t synth_type;
gint err;
KeySym keysym;
DEControllerPrivateData *priv;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
- dbus_error_init(&error);
- if (!dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &keycode, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_UINT32, &synth_type, DBUS_TYPE_INVALID))
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &keycode, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_UINT32, &synth_type, DBUS_TYPE_INVALID))
{
- return spi_dbus_general_error (message);
+ return invalid_arguments_error (message);
}
#ifdef SPI_DEBUG
* and fall back to XSendEvent() if XTest is not available.
*/
- gdk_error_trap_push ();
+ spi_x_error_trap ();
priv = (DEControllerPrivateData *)
g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
keystring);
break;
}
- if ((err = gdk_error_trap_pop ()))
- {
- DBG (-1, g_warning ("Error [%d] emitting keystroke", err));
- }
if (synth_type == Accessibility_KEY_SYM) {
keysym = keycode;
}
return reply;
}
-/* Accessibility::DEController::generateMouseEvent */
+/* Accessibility::DEController::GenerateMouseEvent */
static DBusMessage * impl_generate_mouse_event (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- DBusError error;
dbus_int32_t x;
dbus_int32_t y;
char *eventName;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
int button = 0;
gboolean err = FALSE;
Display *display = spi_get_display ();
- if (!dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_STRING, &eventName, DBUS_TYPE_INVALID))
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_STRING, &eventName, DBUS_TYPE_INVALID))
{
- return spi_dbus_general_error (message);
+ return invalid_arguments_error (message);
}
#ifdef SPI_DEBUG
return reply;
}
-/* Accessibility::DEController::notifyListenersSync */
+/* Accessibility::DEController::NotifyListenersSync */
static DBusMessage *
impl_notify_listeners_sync (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
Accessibility_DeviceEvent event;
dbus_bool_t ret;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
- if (!spi_dbus_demarshall_deviceEvent(message, &event))
+ if (!spi_dbus_demarshal_deviceEvent(message, &event))
{
- return spi_dbus_general_error (message);
+ return invalid_arguments_error (message);
}
#ifdef SPI_DEBUG
g_print ("notifylistening listeners synchronously: controller %p, event id %d\n",
static DBusMessage *
impl_notify_listeners_async (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiDEController *controller = SPI_REGISTRY(user_data)->de_controller;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
Accessibility_DeviceEvent event;
- DBusMessage *reply;
+ DBusMessage *reply = NULL;
- if (!spi_dbus_demarshall_deviceEvent(message, &event))
+ if (!spi_dbus_demarshal_deviceEvent(message, &event))
{
- return spi_dbus_general_error (message);
+ return invalid_arguments_error (message);
}
#ifdef SPI_DEBUG
g_print ("notifylistening listeners asynchronously: controller %p, event id %d\n",
GObjectClass * object_class = (GObjectClass *) klass;
spi_device_event_controller_parent_class = g_type_class_peek_parent (klass);
-
+
object_class->finalize = spi_device_event_controller_object_finalize;
if (!spi_dec_private_quark)
static void
spi_device_event_controller_init (SpiDEController *device_event_controller)
{
+ spi_events_init (spi_get_display());
#ifdef HAVE_XEVIE
GIOChannel *ioc;
int fd;
spi_dec_private_quark,
private);
spi_controller_register_with_devices (device_event_controller);
+ device_event_controller->message_queue = g_queue_new ();
+ saved_controller = device_event_controller;
}
static gboolean
return ret;
}
-SpiDEController *
-spi_device_event_controller_new (SpiRegistry *registry)
-{
- SpiDEController *retval = g_object_new (
- SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL);
-
- retval->registry = g_object_ref (registry);
-
- spi_dec_init_mouse_listener (registry);
- /* TODO: kill mouse listener on finalize */
- return retval;
-}
static gboolean
is_key_released (KeyCode code)
SpiDEController *controller)
{
pressed_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
- saved_controller = controller;
check_release_handler = g_timeout_add (CHECK_RELEASE_DELAY, check_release, &pressed_event);
}
-static DRouteMethod methods[] =
+/*---------------------------------------------------------------------------*/
+
+static const char *introspection_header =
+"<?xml version=\"1.0\"?>\n";
+
+static const char *introspection_node_element =
+"<node name=\"%s\">\n";
+
+static const char *introspection_footer =
+"</node>";
+
+static DBusMessage *
+impl_Introspect (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
{
- { impl_register_keystroke_listener, "registerKeystrokeListener" },
- { impl_register_device_listener, "registerDeviceListener" },
- { impl_deregister_keystroke_listener, "deregisterKeystrokeListener" },
- { impl_deregister_device_listener, "deregisterDeviceListener" },
- { impl_generate_keyboard_event, "generateKeyboardEvent" },
- { impl_generate_mouse_event, "generateMouseEvent" },
- { impl_notify_listeners_sync, "notifyListenersSync" },
- { impl_notify_listeners_async, "notifyListenersAsync" },
- { NULL, NULL }
+ GString *output;
+ gchar *final;
+ gint i;
+
+ const gchar *pathstr = SPI_DBUS_PATH_DEC;
+
+ DBusMessage *reply;
+
+ output = g_string_new(introspection_header);
+
+ g_string_append_printf(output, introspection_node_element, pathstr);
+
+ g_string_append (output, spi_org_a11y_atspi_DeviceEventController);
+
+ g_string_append(output, introspection_footer);
+ final = g_string_free(output, FALSE);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
+
+ g_free(final);
+ return reply;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void
+handle_dec_method_from_idle (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ DBusMessage *reply = NULL;
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_DEC))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "RegisterKeystrokeListener"))
+ reply = impl_register_keystroke_listener (bus, message, user_data);
+ else if (!strcmp (member, "RegisterDeviceEventListener"))
+ reply = impl_register_device_event_listener (bus, message, user_data);
+ else if (!strcmp (member, "DeregisterKeystrokeListener"))
+ reply = impl_deregister_keystroke_listener (bus, message, user_data);
+ else if (!strcmp (member, "DeregisterDeviceEventListener"))
+ reply = impl_deregister_device_event_listener (bus, message, user_data);
+ else if (!strcmp (member, "GetKeystrokeListeners"))
+ reply = impl_get_keystroke_listeners (bus, message, user_data);
+ else if (!strcmp (member, "GetDeviceEventListeners"))
+ reply = impl_get_device_event_listeners (bus, message, user_data);
+ else if (!strcmp (member, "GenerateKeyboardEvent"))
+ reply = impl_generate_keyboard_event (bus, message, user_data);
+ else if (!strcmp (member, "GenerateMouseEvent"))
+ reply = impl_generate_mouse_event (bus, message, user_data);
+ else if (!strcmp (member, "NotifyListenersSync"))
+ reply = impl_notify_listeners_sync (bus, message, user_data);
+ else if (!strcmp (member, "NotifyListenersAsync"))
+ reply = impl_notify_listeners_async (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "Introspect"))
+ reply = impl_Introspect (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (result == DBUS_HANDLER_RESULT_HANDLED)
+ {
+ if (!reply)
+ {
+ reply = dbus_message_new_method_return (message);
+ }
+
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ }
+}
+
+static gboolean
+message_queue_dispatch (gpointer data)
+{
+ saved_controller->message_queue_idle = 0;
+ while (!g_queue_is_empty (saved_controller->message_queue))
+ {
+ DBusMessage *message = g_queue_pop_head (saved_controller->message_queue);
+ data = g_queue_pop_head (saved_controller->message_queue);
+ handle_dec_method_from_idle (saved_controller->bus, message, data);
+ dbus_message_unref (message);
+ }
+ return FALSE;
+}
+
+static DBusHandlerResult
+handle_dec_method (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+
+ /* Check for basic reasons not to handle */
+ if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
+ member == NULL ||
+ iface == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_ref (message);
+ g_queue_push_tail (saved_controller->message_queue, message);
+ g_queue_push_tail (saved_controller->message_queue, user_data);
+ if (!saved_controller->message_queue_idle)
+ saved_controller->message_queue_idle = g_idle_add (message_queue_dispatch, NULL);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusObjectPathVTable dec_vtable =
+{
+ NULL,
+ &handle_dec_method,
+ NULL, NULL, NULL, NULL
};
+SpiDEController *
+spi_registry_dec_new (SpiRegistry *reg, DBusConnection *bus)
+{
+ SpiDEController *dec = g_object_new (SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL);
+
+ dec->registry = g_object_ref (reg);
+ reg->dec = g_object_ref (dec);
+ dec->bus = bus;
+
+ dbus_connection_register_object_path (bus, SPI_DBUS_PATH_DEC, &dec_vtable, dec);
+
+ spi_dec_init_mouse_listener (dec);
+
+ return dec;
+}
+
void
-spi_registry_initialize_dec_interface (DRouteData * data)
+spi_device_event_controller_start_poll_mouse (SpiRegistry *registry)
{
- droute_add_interface (data, "org.freedesktop.atspi.DeviceEventController", methods,
- NULL, NULL, NULL);
-};
+ if (!have_mouse_event_listener)
+ {
+ have_mouse_event_listener = TRUE;
+ if (!have_mouse_listener)
+ g_timeout_add (100, spi_dec_poll_mouse_idle, registry->dec);
+ }
+}
+
+void
+spi_device_event_controller_stop_poll_mouse (void)
+{
+ have_mouse_event_listener = FALSE;
+}