summaryrefslogtreecommitdiff
path: root/registryd
diff options
context:
space:
mode:
Diffstat (limited to 'registryd')
-rw-r--r--registryd/Makefile.am71
-rw-r--r--registryd/de-marshaller.c102
-rw-r--r--registryd/de-marshaller.h37
-rw-r--r--registryd/de-types.h81
-rw-r--r--registryd/deviceeventcontroller-x11.c1485
-rw-r--r--registryd/deviceeventcontroller.c2044
-rw-r--r--registryd/deviceeventcontroller.h179
-rw-r--r--registryd/display.c90
-rw-r--r--registryd/display.h36
-rw-r--r--registryd/event-source.c175
-rw-r--r--registryd/event-source.h33
-rw-r--r--registryd/introspection.c871
-rw-r--r--registryd/introspection.h53
-rw-r--r--registryd/keymasks.h53
-rw-r--r--registryd/org.a11y.atspi.Registry.service.in3
-rw-r--r--registryd/paths.h53
-rw-r--r--registryd/reentrant-list.c105
-rw-r--r--registryd/reentrant-list.h46
-rw-r--r--registryd/registry-main.c268
-rw-r--r--registryd/registry.c1470
-rw-r--r--registryd/registry.h64
-rwxr-xr-xregistryd/testregistry.py59
-rw-r--r--registryd/ucs2keysym.c855
23 files changed, 8233 insertions, 0 deletions
diff --git a/registryd/Makefile.am b/registryd/Makefile.am
new file mode 100644
index 0000000..1e2e953
--- /dev/null
+++ b/registryd/Makefile.am
@@ -0,0 +1,71 @@
+libexec_PROGRAMS = at-spi2-registryd
+
+at_spi2_registryd_LDFLAGS = -pie
+at_spi2_registryd_CFLAGS = \
+ -fPIE \
+ $(GLIB_CFLAGS) \
+ $(GIO_CFLAGS) \
+ $(DBUS_CFLAGS) \
+ $(GOBJ_CFLAGS) \
+ $(ATK_CFLAGS) \
+ -I$(top_srcdir) \
+ -I$(top_builddir) \
+ -I$(top_builddir)/atspi \
+ -DATSPI_INTROSPECTION_PATH=\"$(pkgdatadir)/$(DEFAULT_ATSPI_INTROSPECTION_PATH)\"
+
+at_spi2_registryd_LDADD = \
+ ../atspi/libatspi.la \
+ $(GLIB_LIBS) \
+ $(GIO_LIBS) \
+ $(DBUS_LIBS) \
+ $(GOBJ_CFLAGS) \
+ $(ATK_LIBS) \
+ $(X_LIBS) \
+ $(SM_LIBS) \
+ $(XTST_LIBS) \
+ $(XEVIE_LIBS) \
+ $(DL_LIBS)
+
+at_spi2_registryd_SOURCES = \
+ de-marshaller.h \
+ de-marshaller.c \
+ de-types.h \
+ keymasks.h \
+ paths.h \
+ registry-main.c \
+ registry.c \
+ registry.h \
+ introspection.h \
+ introspection.c \
+ deviceeventcontroller.c \
+ deviceeventcontroller.h \
+ reentrant-list.c \
+ reentrant-list.h \
+ ucs2keysym.c
+
+X11_SOURCES = \
+ deviceeventcontroller-x11.c \
+ display.h \
+ display.c \
+ event-source.c \
+ event-source.h
+
+if USE_X11
+at_spi2_registryd_SOURCES += $(X11_SOURCES)
+EXTRA_DIST =
+else
+EXTRA_DIST = $(X11_SOURCES)
+endif
+
+servicedir=$(datadir)/dbus-1/accessibility-services
+service_in_files = org.a11y.atspi.Registry.service.in
+service_DATA = $(service_in_files:.service.in=.service)
+
+$(service_DATA): $(service_in_files) Makefile
+ sed -e "s|[@]LIBEXECDIR[@]|$(libexecdir)|" $(srcdir)/$@.in > $@
+
+
+DISTCLEANFILES = org.a11y.atspi.Registry.service
+EXTRA_DIST += org.a11y.atspi.Registry.service.in
+
+-include $(top_srcdir)/git.mk
diff --git a/registryd/de-marshaller.c b/registryd/de-marshaller.c
new file mode 100644
index 0000000..fef8e48
--- /dev/null
+++ b/registryd/de-marshaller.c
@@ -0,0 +1,102 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008 Novell, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <glib.h>
+#include <glib-object.h>
+#include <dbus/dbus.h>
+
+#include "de-types.h"
+
+dbus_bool_t spi_dbus_message_iter_get_struct(DBusMessageIter *iter, ...)
+{
+ va_list args;
+ DBusMessageIter iter_struct;
+ int type;
+ void *ptr;
+
+ dbus_message_iter_recurse(iter, &iter_struct);
+ va_start(args, iter);
+ for (;;)
+ {
+ type = va_arg(args, int);
+ if (type == DBUS_TYPE_INVALID) break;
+ if (type != dbus_message_iter_get_arg_type(&iter_struct))
+ {
+ va_end(args);
+ return FALSE;
+ }
+ ptr = va_arg(args, void *);
+ dbus_message_iter_get_basic(&iter_struct, ptr);
+ dbus_message_iter_next(&iter_struct);
+ }
+ dbus_message_iter_next(iter);
+ va_end(args);
+ return TRUE;
+}
+
+dbus_bool_t spi_dbus_message_iter_append_struct(DBusMessageIter *iter, ...)
+{
+ va_list args;
+ DBusMessageIter iter_struct;
+ int type;
+ void *ptr;
+
+ if (!dbus_message_iter_open_container(iter, DBUS_TYPE_STRUCT, NULL, &iter_struct)) return FALSE;
+ va_start(args, iter);
+ for (;;)
+ {
+ type = va_arg(args, int);
+ if (type == DBUS_TYPE_INVALID) break;
+ ptr = va_arg(args, void *);
+ dbus_message_iter_append_basic(&iter_struct, type, ptr);
+ }
+ if (!dbus_message_iter_close_container(iter, &iter_struct)) return FALSE;
+ va_end(args);
+ return TRUE;
+}
+
+dbus_bool_t spi_dbus_marshal_deviceEvent(DBusMessage *message, const Accessibility_DeviceEvent *e)
+{
+ DBusMessageIter iter;
+
+ if (!message) return FALSE;
+ dbus_message_iter_init_append(message, &iter);
+ return spi_dbus_message_iter_append_struct(&iter, DBUS_TYPE_UINT32, &e->type, DBUS_TYPE_INT32, &e->id, DBUS_TYPE_UINT32, &e->hw_code, DBUS_TYPE_UINT32, &e->modifiers, DBUS_TYPE_INT32, &e->timestamp, DBUS_TYPE_STRING, &e->event_string, DBUS_TYPE_BOOLEAN, &e->is_text, DBUS_TYPE_INVALID);
+}
+
+dbus_bool_t spi_dbus_demarshal_deviceEvent(DBusMessage *message, Accessibility_DeviceEvent *e)
+{
+ DBusMessageIter iter;
+ dbus_uint16_t hw_code;
+ dbus_uint16_t modifiers;
+
+ dbus_message_iter_init(message, &iter);
+ if (spi_dbus_message_iter_get_struct(&iter, DBUS_TYPE_UINT32, &e->type, DBUS_TYPE_INT32, &e->id, DBUS_TYPE_INT32, &e->hw_code, DBUS_TYPE_INT32, &e->modifiers, DBUS_TYPE_INT32, &e->timestamp, DBUS_TYPE_STRING, &e->event_string, DBUS_TYPE_BOOLEAN, &e->is_text, DBUS_TYPE_INVALID))
+ return TRUE;
+ /* TODO: Perhaps remove the below code for 2.1 */
+ if (!spi_dbus_message_iter_get_struct(&iter, DBUS_TYPE_UINT32, &e->type, DBUS_TYPE_INT32, &e->id, DBUS_TYPE_INT16, &hw_code, DBUS_TYPE_INT16, &modifiers, DBUS_TYPE_INT32, &e->timestamp, DBUS_TYPE_STRING, &e->event_string, DBUS_TYPE_BOOLEAN, &e->is_text, DBUS_TYPE_INVALID))
+ return FALSE;
+ e->hw_code = hw_code;
+ e->modifiers = modifiers;
+ return TRUE;
+}
diff --git a/registryd/de-marshaller.h b/registryd/de-marshaller.h
new file mode 100644
index 0000000..9d55a9d
--- /dev/null
+++ b/registryd/de-marshaller.h
@@ -0,0 +1,37 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Codethink Ltd
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_DE_MARSHALLER_H_
+#define SPI_DE_MARSHALLER_H_
+
+#include <dbus/dbus.h>
+
+#include "de-types.h"
+
+dbus_bool_t spi_dbus_message_iter_get_struct(DBusMessageIter *iter, ...);
+dbus_bool_t spi_dbus_message_iter_append_struct(DBusMessageIter *iter, ...);
+dbus_bool_t spi_dbus_marshal_deviceEvent(DBusMessage *message, const Accessibility_DeviceEvent *e);
+dbus_bool_t spi_dbus_demarshal_deviceEvent(DBusMessage *message, Accessibility_DeviceEvent *e);
+
+#endif /* SPI_DE_MARSHALLER_H_ */
diff --git a/registryd/de-types.h b/registryd/de-types.h
new file mode 100644
index 0000000..a338e38
--- /dev/null
+++ b/registryd/de-types.h
@@ -0,0 +1,81 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Codethink Ltd
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_DE_TYPES_H_
+#define SPI_DE_TYPES_H_
+
+#include <dbus/dbus.h>
+
+typedef unsigned long Accessibility_ControllerEventMask;
+
+typedef enum {
+ Accessibility_KEY_PRESSED_EVENT,
+ Accessibility_KEY_RELEASED_EVENT,
+ Accessibility_BUTTON_PRESSED_EVENT,
+ Accessibility_BUTTON_RELEASED_EVENT,
+} Accessibility_EventType;
+
+typedef enum {
+ Accessibility_KEY_PRESSED,
+ Accessibility_KEY_RELEASED,
+} Accessibility_KeyEventType;
+
+typedef enum {
+ Accessibility_KEY_PRESS,
+ Accessibility_KEY_RELEASE,
+ Accessibility_KEY_PRESSRELEASE,
+ Accessibility_KEY_SYM,
+ Accessibility_KEY_STRING,
+} Accessibility_KeySynthType;
+
+typedef struct _Accessibility_DeviceEvent Accessibility_DeviceEvent;
+struct _Accessibility_DeviceEvent
+{
+ Accessibility_EventType type;
+ dbus_uint32_t id;
+ dbus_uint32_t hw_code;
+ dbus_uint32_t modifiers;
+ dbus_uint32_t timestamp;
+ char * event_string;
+ dbus_bool_t is_text;
+};
+
+typedef struct _Accessibility_EventListenerMode Accessibility_EventListenerMode;
+struct _Accessibility_EventListenerMode
+{
+ dbus_bool_t synchronous;
+ dbus_bool_t preemptive;
+ dbus_bool_t global;
+};
+
+typedef struct _Accessibility_KeyDefinition Accessibility_KeyDefinition;
+struct _Accessibility_KeyDefinition
+{
+ dbus_int32_t keycode;
+ dbus_int32_t keysym;
+ char *keystring;
+ dbus_int32_t unused;
+};
+
+#endif /* SPI_DE_TYPES_H_ */
diff --git a/registryd/deviceeventcontroller-x11.c b/registryd/deviceeventcontroller-x11.c
new file mode 100644
index 0000000..5c2cf89
--- /dev/null
+++ b/registryd/deviceeventcontroller-x11.c
@@ -0,0 +1,1485 @@
+/* AT-SPI - Assistive Technology Service Provider Interface
+ *
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2003 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* deviceeventcontroller-x11.c: X-specific DeviceEventController support */
+
+#include <config.h>
+
+#undef SPI_XKB_DEBUG
+#undef SPI_DEBUG
+#undef SPI_KEYEVENT_DEBUG
+
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/extensions/XTest.h>
+#include <X11/XKBlib.h>
+
+#define XK_MISCELLANY
+#define XK_LATIN1
+#include <X11/keysymdef.h>
+
+#ifdef HAVE_XEVIE
+#include <X11/Xproto.h>
+#include <X11/X.h>
+#include <X11/extensions/Xevie.h>
+#endif /* HAVE_XEVIE */
+
+#include <glib.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"
+
+static void spi_dec_x11_emit_modifier_event (SpiDEController *controller,
+ guint prev_mask,
+ guint current_mask);
+
+#define CHECK_RELEASE_DELAY 20
+#define BIT(c, x) (c[x/8]&(1<<(x%8)))
+static guint check_release_handler = 0;
+static Accessibility_DeviceEvent pressed_event;
+static void wait_for_release_event (XEvent *event, SpiDEController *controller);
+
+static int spi_error_code = 0;
+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 unsigned int key_modifier_mask =
+ Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask | ShiftMask | LockMask | ControlMask | SPI_KEYMASK_NUMLOCK;
+static unsigned int _numlock_physical_mask = Mod2Mask; /* a guess, will be reset */
+
+static XModifierKeymap* xmkeymap = NULL;
+
+
+static int (*x_default_error_handler) (Display *display, XErrorEvent *error_event);
+
+typedef struct {
+ Display *xevie_display;
+ unsigned int last_press_keycode;
+ unsigned int last_release_keycode;
+ struct timeval last_press_time;
+ struct timeval last_release_time;
+ int have_xkb;
+ int xkb_major_extension_opcode;
+ int xkb_base_event_code;
+ int xkb_base_error_code;
+ unsigned int xkb_latch_mask;
+ unsigned int pending_xkb_mod_relatch_mask;
+ XkbDescPtr xkb_desc;
+ KeyCode reserved_keycode;
+ KeySym reserved_keysym;
+ guint reserved_reset_timeout;
+} DEControllerPrivateData;
+
+static void spi_controller_register_with_devices (SpiDEController *controller);
+static gboolean spi_device_event_controller_forward_key_event (SpiDEController *controller,
+ const XEvent *event);
+
+
+static SpiDEController *saved_controller;
+
+static unsigned int
+keysym_mod_mask (KeySym keysym, KeyCode keycode)
+{
+ /* we really should use XKB and look directly at the keymap */
+ /* this is very inelegant */
+ Display *display = spi_get_display ();
+ unsigned int mods_rtn = 0;
+ unsigned int retval = 0;
+ KeySym sym_rtn;
+
+ if (XkbLookupKeySym (display, keycode, 0, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = 0;
+ }
+ else if (XkbLookupKeySym (display, keycode, ShiftMask, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = ShiftMask;
+ }
+ else if (XkbLookupKeySym (display, keycode, Mod2Mask, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = Mod2Mask;
+ }
+ else if (XkbLookupKeySym (display, keycode, Mod3Mask, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = Mod3Mask;
+ }
+ else if (XkbLookupKeySym (display, keycode,
+ ShiftMask | Mod2Mask, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = (Mod2Mask | ShiftMask);
+ }
+ else if (XkbLookupKeySym (display, keycode,
+ ShiftMask | Mod3Mask, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = (Mod3Mask | ShiftMask);
+ }
+ else if (XkbLookupKeySym (display, keycode,
+ ShiftMask | Mod4Mask, &mods_rtn, &sym_rtn) &&
+ (sym_rtn == keysym)) {
+ retval = (Mod4Mask | ShiftMask);
+ }
+ else
+ retval = 0xFFFF;
+ return retval;
+}
+
+static gboolean
+replace_map_keysym (DEControllerPrivateData *priv, KeyCode keycode, KeySym keysym)
+{
+#ifdef HAVE_XKB
+ Display *dpy = spi_get_display ();
+ XkbDescPtr desc;
+ if (!(desc = XkbGetMap (dpy, XkbAllMapComponentsMask, XkbUseCoreKbd)))
+ {
+ fprintf (stderr, "ERROR getting map\n");
+ }
+ XFlush (dpy);
+ XSync (dpy, False);
+ if (desc && desc->map)
+ {
+ gint offset = desc->map->key_sym_map[keycode].offset;
+ desc->map->syms[offset] = keysym;
+ }
+ else
+ {
+ fprintf (stderr, "Error changing key map: empty server structure\n");
+ }
+ XkbSetMap (dpy, XkbAllMapComponentsMask, desc);
+ /**
+ * FIXME: the use of XkbChangeMap, and the reuse of the priv->xkb_desc structure,
+ * would be far preferable.
+ * HOWEVER it does not seem to work using XFree 4.3.
+ **/
+ /* XkbChangeMap (dpy, priv->xkb_desc, priv->changes); */
+ XFlush (dpy);
+ XSync (dpy, False);
+ XkbFreeKeyboard (desc, 0, TRUE);
+
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
+static gboolean
+spi_dec_reset_reserved (gpointer data)
+{
+ DEControllerPrivateData *priv = data;
+ replace_map_keysym (priv, priv->reserved_keycode, priv->reserved_keysym);
+ priv->reserved_reset_timeout = 0;
+ return FALSE;
+}
+
+static gint
+spi_dec_x11_get_keycode (SpiDEController *controller,
+ gint keysym,
+ gchar *key_str,
+ gboolean fix,
+ guint *modmask)
+{
+ KeyCode keycode = 0;
+ if (key_str && key_str[0])
+ keysym = XStringToKeysym(key_str);
+ keycode = XKeysymToKeycode (spi_get_display (), (KeySym) keysym);
+ if (!keycode && fix)
+ {
+ DEControllerPrivateData *priv = controller->priv;
+ /* if there's no keycode available, fix it */
+ if (replace_map_keysym (priv, priv->reserved_keycode, keysym))
+ {
+ keycode = priv->reserved_keycode;
+ /*
+ * queue a timer to restore the old keycode. Ugly, but required
+ * due to races / asynchronous X delivery.
+ * Long-term fix is to extend the X keymap here instead of replace entries.
+ */
+ priv->reserved_reset_timeout = g_timeout_add (500, spi_dec_reset_reserved, priv);
+ g_source_set_name_by_id (priv->reserved_reset_timeout, "[at-spi2-core] spi_dec_reset_reserved");
+ }
+ if (modmask)
+ *modmask = 0;
+ return keycode;
+ }
+ if (modmask)
+ *modmask = keysym_mod_mask (keysym, keycode);
+ return keycode;
+}
+
+static void
+spi_dec_set_unlatch_pending (SpiDEController *controller, unsigned mask)
+{
+ DEControllerPrivateData *priv = controller->priv;
+#ifdef SPI_XKB_DEBUG
+ if (priv->xkb_latch_mask) fprintf (stderr, "unlatch pending! %x\n",
+ priv->xkb_latch_mask);
+#endif
+ priv->pending_xkb_mod_relatch_mask |= priv->xkb_latch_mask;
+}
+
+static gboolean
+spi_dec_button_update_and_emit (SpiDEController *controller,
+ guint mask_return)
+{
+ Accessibility_DeviceEvent mouse_e;
+ gchar event_detail[3];
+ gboolean is_consumed = FALSE;
+
+ if ((mask_return & mouse_button_mask) !=
+ (mouse_mask_state & mouse_button_mask))
+ {
+ int button_number = 0;
+ gboolean is_down = False;
+
+ if (!(mask_return & Button1Mask) &&
+ (mouse_mask_state & Button1Mask))
+ {
+ mouse_mask_state &= ~Button1Mask;
+ button_number = 1;
+ }
+ else if ((mask_return & Button1Mask) &&
+ !(mouse_mask_state & Button1Mask))
+ {
+ mouse_mask_state |= Button1Mask;
+ button_number = 1;
+ is_down = True;
+ }
+ else if (!(mask_return & Button2Mask) &&
+ (mouse_mask_state & Button2Mask))
+ {
+ mouse_mask_state &= ~Button2Mask;
+ button_number = 2;
+ }
+ else if ((mask_return & Button2Mask) &&
+ !(mouse_mask_state & Button2Mask))
+ {
+ mouse_mask_state |= Button2Mask;
+ button_number = 2;
+ is_down = True;
+ }
+ else if (!(mask_return & Button3Mask) &&
+ (mouse_mask_state & Button3Mask))
+ {
+ mouse_mask_state &= ~Button3Mask;
+ button_number = 3;
+ }
+ else if ((mask_return & Button3Mask) &&
+ !(mouse_mask_state & Button3Mask))
+ {
+ mouse_mask_state |= Button3Mask;
+ button_number = 3;
+ is_down = True;
+ }
+ else if (!(mask_return & Button4Mask) &&
+ (mouse_mask_state & Button4Mask))
+ {
+ mouse_mask_state &= ~Button4Mask;
+ button_number = 4;
+ }
+ else if ((mask_return & Button4Mask) &&
+ !(mouse_mask_state & Button4Mask))
+ {
+ mouse_mask_state |= Button4Mask;
+ button_number = 4;
+ is_down = True;
+ }
+ else if (!(mask_return & Button5Mask) &&
+ (mouse_mask_state & Button5Mask))
+ {
+ mouse_mask_state &= ~Button5Mask;
+ button_number = 5;
+ }
+ else if ((mask_return & Button5Mask) &&
+ !(mouse_mask_state & Button5Mask))
+ {
+ mouse_mask_state |= Button5Mask;
+ button_number = 5;
+ is_down = True;
+ }
+ if (button_number) {
+#ifdef SPI_DEBUG
+ fprintf (stderr, "Button %d %s\n",
+ button_number, (is_down) ? "Pressed" : "Released");
+#endif
+ snprintf (event_detail, 3, "%d%c", button_number,
+ (is_down) ? 'p' : 'r');
+ /* TODO: FIXME distinguish between physical and
+ * logical buttons
+ */
+ mouse_e.type = (is_down) ?
+ Accessibility_BUTTON_PRESSED_EVENT :
+ Accessibility_BUTTON_RELEASED_EVENT;
+ mouse_e.id = button_number;
+ mouse_e.hw_code = button_number;
+ mouse_e.modifiers = (dbus_uint16_t) mouse_mask_state;
+ mouse_e.timestamp = 0;
+ mouse_e.event_string = "";
+ mouse_e.is_text = FALSE;
+ is_consumed =
+ spi_controller_notify_mouselisteners (controller,
+ &mouse_e);
+ if (!is_consumed)
+ {
+ dbus_uint32_t x = last_mouse_pos->x, y = last_mouse_pos->y;
+ spi_dec_dbus_emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, x, y);
+ }
+ else
+ spi_dec_set_unlatch_pending (controller, mask_return);
+ }
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+static guint
+spi_dec_x11_mouse_check (SpiDEController *controller,
+ int *x, int *y, gboolean *moved)
+{
+ int win_x_return,win_y_return;
+ unsigned int mask_return;
+ Window root_return, child_return;
+ Display *display = spi_get_display ();
+
+ if (display != NULL)
+ XQueryPointer(display, DefaultRootWindow (display),
+ &root_return, &child_return,
+ x, y,
+ &win_x_return, &win_y_return, &mask_return);
+ /*
+ * Since many clients grab the pointer, and X goes an automatic
+ * pointer grab on mouse-down, we often must detect mouse button events
+ * by polling rather than via a button grab.
+ * The while loop (rather than if) is used since it's possible that
+ * multiple buttons have changed state since we last checked.
+ */
+ if (mask_return != mouse_mask_state)
+ {
+ while (spi_dec_button_update_and_emit (controller, mask_return));
+ }
+
+ if (*x != last_mouse_pos->x || *y != last_mouse_pos->y)
+ {
+ // TODO: combine these two signals?
+ dbus_uint32_t ix = *x, iy = *y;
+ spi_dec_dbus_emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Abs", "", ix, iy);
+ ix -= last_mouse_pos->x;
+ iy -= last_mouse_pos->y;
+ spi_dec_dbus_emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Rel", "", ix, iy);
+ last_mouse_pos->x = *x;
+ last_mouse_pos->y = *y;
+ *moved = True;
+ }
+ else
+ {
+ *moved = False;
+ }
+
+ return mask_return;
+}
+
+#ifdef WE_NEED_UGRAB_MOUSE
+static int
+spi_dec_ungrab_mouse (gpointer data)
+{
+ Display *display = spi_get_display ();
+ if (display)
+ {
+ XUngrabButton (spi_get_display (), AnyButton, AnyModifier,
+ XDefaultRootWindow (spi_get_display ()));
+ }
+ return FALSE;
+}
+#endif
+
+static void
+spi_dec_init_mouse_listener (SpiDEController *dec)
+{
+#ifdef GRAB_BUTTON
+ Display *display = spi_get_display ();
+
+ if (display)
+ {
+ if (XGrabButton (display, AnyButton, AnyModifier,
+ spi_get_root_window (),
+ True, ButtonPressMask | ButtonReleaseMask,
+ GrabModeSync, GrabModeAsync, None, None) != Success) {
+#ifdef SPI_DEBUG
+ fprintf (stderr, "WARNING: could not grab mouse buttons!\n");
+#endif
+ ;
+ }
+ XSync (display, False);
+#ifdef SPI_DEBUG
+ fprintf (stderr, "mouse buttons grabbed\n");
+#endif
+ }
+#endif
+}
+
+static void
+spi_dec_clear_unlatch_pending (SpiDEController *controller)
+{
+ DEControllerPrivateData *priv = controller->priv;
+ priv->xkb_latch_mask = 0;
+}
+
+static void
+spi_device_event_controller_forward_mouse_event (SpiDEController *controller,
+ XEvent *xevent)
+{
+ Accessibility_DeviceEvent mouse_e;
+ gchar event_detail[3];
+ gboolean is_consumed = FALSE;
+ gboolean xkb_mod_unlatch_occurred;
+ XButtonEvent *xbutton_event = (XButtonEvent *) xevent;
+ dbus_uint32_t ix, iy;
+
+ int button = xbutton_event->button;
+
+ unsigned int mouse_button_state = xbutton_event->state;
+
+ switch (button)
+ {
+ case 1:
+ mouse_button_state |= Button1Mask;
+ break;
+ case 2:
+ mouse_button_state |= Button2Mask;
+ break;
+ case 3:
+ mouse_button_state |= Button3Mask;
+ break;
+ case 4:
+ mouse_button_state |= Button4Mask;
+ break;
+ case 5:
+ mouse_button_state |= Button5Mask;
+ break;
+ }
+
+ last_mouse_pos->x = ((XButtonEvent *) xevent)->x_root;
+ last_mouse_pos->y = ((XButtonEvent *) xevent)->y_root;
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "mouse button %d %s (%x)\n",
+ xbutton_event->button,
+ (xevent->type == ButtonPress) ? "Press" : "Release",
+ mouse_button_state);
+#endif
+ snprintf (event_detail, 3, "%d%c", button,
+ (xevent->type == ButtonPress) ? 'p' : 'r');
+
+ /* TODO: FIXME distinguish between physical and logical buttons */
+ mouse_e.type = (xevent->type == ButtonPress) ?
+ Accessibility_BUTTON_PRESSED_EVENT :
+ Accessibility_BUTTON_RELEASED_EVENT;
+ mouse_e.id = button;
+ mouse_e.hw_code = button;
+ mouse_e.modifiers = (dbus_uint16_t) xbutton_event->state;
+ mouse_e.timestamp = (dbus_uint32_t) xbutton_event->time;
+ mouse_e.event_string = "";
+ mouse_e.is_text = FALSE;
+ if ((mouse_button_state & mouse_button_mask) !=
+ (mouse_mask_state & mouse_button_mask))
+ {
+ if ((mouse_mask_state & key_modifier_mask) !=
+ (mouse_button_state & key_modifier_mask))
+ spi_dec_x11_emit_modifier_event (controller,
+ mouse_mask_state, mouse_button_state);
+ mouse_mask_state = mouse_button_state;
+ is_consumed =
+ spi_controller_notify_mouselisteners (controller, &mouse_e);
+ ix = last_mouse_pos->x;
+ iy = last_mouse_pos->y;
+ spi_dec_dbus_emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, ix, iy);
+ }
+
+ xkb_mod_unlatch_occurred = (xevent->type == ButtonPress ||
+ xevent->type == ButtonRelease);
+
+ /* if client wants to consume this event, and XKB latch state was
+ * unset by this button event, we reset it
+ */
+ if (is_consumed && xkb_mod_unlatch_occurred)
+ spi_dec_set_unlatch_pending (controller, mouse_mask_state);
+
+ XAllowEvents (spi_get_display (),
+ (is_consumed) ? SyncPointer : ReplayPointer,
+ CurrentTime);
+}
+
+static void
+global_filter_fn (XEvent *xevent, void *data)
+{
+ SpiDEController *controller;
+ DEControllerPrivateData *priv;
+ Display *display = spi_get_display ();
+ controller = SPI_DEVICE_EVENT_CONTROLLER (data);
+ priv = controller->priv;
+
+ if (xevent->type == MappingNotify)
+ xmkeymap = NULL;
+
+ if (xevent->type == KeyPress || xevent->type == KeyRelease)
+ {
+ if (priv->xevie_display == NULL)
+ {
+ gboolean is_consumed;
+
+ is_consumed =
+ spi_device_event_controller_forward_key_event (controller, xevent);
+
+ if (is_consumed)
+ {
+ int n_events;
+ int i;
+ XEvent next_event;
+ n_events = XPending (display);
+
+#ifdef SPI_KEYEVENT_DEBUG
+ g_print ("Number of events pending: %d\n", n_events);
+#endif
+ for (i = 0; i < n_events; i++)
+ {
+ XNextEvent (display, &next_event);
+ if (next_event.type != KeyPress &&
+ next_event.type != KeyRelease)
+ g_warning ("Unexpected event type %d in queue", next_event.type);
+ }
+
+ XAllowEvents (display, AsyncKeyboard, CurrentTime);
+ if (n_events)
+ XUngrabKeyboard (display, CurrentTime);
+ }
+ else
+ {
+ if (xevent->type == KeyPress)
+ wait_for_release_event (xevent, controller);
+ XAllowEvents (display, ReplayKeyboard, CurrentTime);
+ }
+ }
+
+ return;
+ }
+ if (xevent->type == ButtonPress || xevent->type == ButtonRelease)
+ {
+ spi_device_event_controller_forward_mouse_event (controller, xevent);
+ }
+ if (xevent->type == priv->xkb_base_event_code)
+ {
+ XkbAnyEvent * xkb_ev = (XkbAnyEvent *) xevent;
+ /* ugly but probably necessary...*/
+ XSynchronize (display, TRUE);
+
+ if (xkb_ev->xkb_type == XkbStateNotify)
+ {
+ XkbStateNotifyEvent *xkb_snev =
+ (XkbStateNotifyEvent *) xkb_ev;
+ /* check the mouse, to catch mouse events grabbed by
+ * another client; in case we should revert this XKB delatch
+ */
+ if (!priv->pending_xkb_mod_relatch_mask)
+ {
+ int x, y;
+ gboolean moved;
+ spi_dec_x11_mouse_check (controller, &x, &y, &moved);
+ }
+ /* we check again, since the previous call may have
+ changed this flag */
+ if (priv->pending_xkb_mod_relatch_mask)
+ {
+ unsigned int feedback_mask;
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "relatching %x\n",
+ priv->pending_xkb_mod_relatch_mask);
+#endif
+ /* temporarily turn off the latch bell, if it's on */
+ XkbGetControls (display,
+ XkbAccessXFeedbackMask,
+ priv->xkb_desc);
+ feedback_mask = priv->xkb_desc->ctrls->ax_options;
+ if (feedback_mask & XkbAX_StickyKeysFBMask)
+ {
+ XkbControlsChangesRec changes = {XkbAccessXFeedbackMask,
+ 0, False};
+ priv->xkb_desc->ctrls->ax_options
+ &= ~(XkbAX_StickyKeysFBMask);
+ XkbChangeControls (display, priv->xkb_desc, &changes);
+ }
+ /* TODO: account for lock as well as latch */
+ XkbLatchModifiers (display,
+ XkbUseCoreKbd,
+ priv->pending_xkb_mod_relatch_mask,
+ priv->pending_xkb_mod_relatch_mask);
+ if (feedback_mask & XkbAX_StickyKeysFBMask)
+ {
+ XkbControlsChangesRec changes = {XkbAccessXFeedbackMask,
+ 0, False};
+ priv->xkb_desc->ctrls->ax_options = feedback_mask;
+ XkbChangeControls (display, priv->xkb_desc, &changes);
+ }
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "relatched %x\n",
+ priv->pending_xkb_mod_relatch_mask);
+#endif
+ priv->pending_xkb_mod_relatch_mask = 0;
+ }
+ else
+ {
+ priv->xkb_latch_mask = xkb_snev->latched_mods;
+ }
+ }
+ XSynchronize (display, FALSE);
+ }
+
+ return;
+}
+
+static int
+_spi_controller_device_error_handler (Display *display, XErrorEvent *error)
+{
+ if (error->error_code == BadAccess)
+ {
+ g_message ("Could not complete key grab: grab already in use.\n");
+ spi_error_code = BadAccess;
+ return 0;
+ }
+ else
+ {
+ return (*x_default_error_handler) (display, error);
+ }
+}
+
+static void
+spi_controller_register_with_devices (SpiDEController *controller)
+{
+ DEControllerPrivateData *priv;
+ int event_base, error_base, major_version, minor_version;
+
+ priv = controller->priv;
+ 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 */
+ /* register with: (translated) keystroke handler */
+
+ priv->have_xkb = XkbQueryExtension (spi_get_display (),
+ &priv->xkb_major_extension_opcode,
+ &priv->xkb_base_event_code,
+ &priv->xkb_base_error_code, NULL, NULL);
+ if (priv->have_xkb)
+ {
+ gint i;
+ guint64 reserved = 0;
+ priv->xkb_desc = XkbGetMap (spi_get_display (), XkbKeySymsMask, XkbUseCoreKbd);
+ XkbSelectEvents (spi_get_display (),
+ XkbUseCoreKbd,
+ XkbStateNotifyMask, XkbStateNotifyMask);
+ _numlock_physical_mask = XkbKeysymToModifiers (spi_get_display (),
+ XK_Num_Lock);
+ for (i = priv->xkb_desc->max_key_code; i >= priv->xkb_desc->min_key_code; --i)
+ {
+ if (priv->xkb_desc->map->key_sym_map[i].kt_index[0] == XkbOneLevelIndex)
+ {
+ if (XkbKeycodeToKeysym (spi_get_display (), i, 0, 0) != 0)
+ {
+ /* don't use this one if there's a grab client! */
+
+ /* 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,
+ spi_get_root_window (),
+ TRUE,
+ GrabModeSync, GrabModeSync);
+ XSync (spi_get_display (), TRUE);
+ XUngrabKey (spi_get_display (), i, 0,
+ spi_get_root_window ());
+ if (!spi_x_error_release ())
+ {
+ reserved = i;
+ break;
+ }
+ }
+ }
+ }
+ if (reserved)
+ {
+ priv->reserved_keycode = reserved;
+ priv->reserved_keysym = XkbKeycodeToKeysym (spi_get_display (), reserved, 0, 0);
+ }
+ else
+ {
+ priv->reserved_keycode = XKeysymToKeycode (spi_get_display (), XK_numbersign);
+ priv->reserved_keysym = XK_numbersign;
+ }
+#ifdef SPI_RESERVED_DEBUG
+ unsigned sym = 0;
+ sym = XKeycodeToKeysym (spi_get_display (), reserved, 0);
+ fprintf (stderr, "%x\n", sym);
+ fprintf (stderr, "setting the reserved keycode to %d (%s)\n",
+ reserved,
+ XKeysymToString (XKeycodeToKeysym (spi_get_display (),
+ reserved, 0)));
+#endif
+ }
+
+ spi_set_filter (global_filter_fn, controller);
+ spi_set_events (KeyPressMask | KeyReleaseMask);
+
+ x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler);
+}
+
+static Accessibility_DeviceEvent
+spi_keystroke_from_x_key_event (XKeyEvent *x_key_event)
+{
+ Accessibility_DeviceEvent key_event;
+ KeySym keysym;
+ const int cbuf_bytes = 20;
+ char cbuf [21];
+ int nbytes;
+
+ nbytes = XLookupString (x_key_event, cbuf, cbuf_bytes, &keysym, NULL);
+ key_event.id = (dbus_int32_t)(keysym);
+ key_event.hw_code = (dbus_int16_t) x_key_event->keycode;
+ if (((XEvent *) x_key_event)->type == KeyPress)
+ {
+ key_event.type = Accessibility_KEY_PRESSED_EVENT;
+ }
+ else
+ {
+ key_event.type = Accessibility_KEY_RELEASED_EVENT;
+ }
+ key_event.modifiers = (dbus_uint16_t)(x_key_event->state);
+ key_event.is_text = FALSE;
+ switch (keysym)
+ {
+ case ' ':
+ key_event.event_string = g_strdup ("space");
+ break;
+ case XK_Tab:
+ key_event.event_string = g_strdup ("Tab");
+ break;
+ case XK_BackSpace:
+ key_event.event_string = g_strdup ("Backspace");
+ break;
+ case XK_Return:
+ key_event.event_string = g_strdup ("Return");
+ break;
+ case XK_Home:
+ key_event.event_string = g_strdup ("Home");
+ break;
+ case XK_Page_Down:
+ key_event.event_string = g_strdup ("Page_Down");
+ break;
+ case XK_Page_Up:
+ key_event.event_string = g_strdup ("Page_Up");
+ break;
+ case XK_F1:
+ key_event.event_string = g_strdup ("F1");
+ break;
+ case XK_F2:
+ key_event.event_string = g_strdup ("F2");
+ break;
+ case XK_F3:
+ key_event.event_string = g_strdup ("F3");
+ break;
+ case XK_F4:
+ key_event.event_string = g_strdup ("F4");
+ break;
+ case XK_F5:
+ key_event.event_string = g_strdup ("F5");
+ break;
+ case XK_F6:
+ key_event.event_string = g_strdup ("F6");
+ break;
+ case XK_F7:
+ key_event.event_string = g_strdup ("F7");
+ break;
+ case XK_F8:
+ key_event.event_string = g_strdup ("F8");
+ break;
+ case XK_F9:
+ key_event.event_string = g_strdup ("F9");
+ break;
+ case XK_F10:
+ key_event.event_string = g_strdup ("F10");
+ break;
+ case XK_F11:
+ key_event.event_string = g_strdup ("F11");
+ break;
+ case XK_F12:
+ key_event.event_string = g_strdup ("F12");
+ break;
+ case XK_End:
+ key_event.event_string = g_strdup ("End");
+ break;
+ case XK_Escape:
+ key_event.event_string = g_strdup ("Escape");
+ break;
+ case XK_Up:
+ key_event.event_string = g_strdup ("Up");
+ break;
+ case XK_Down:
+ key_event.event_string = g_strdup ("Down");
+ break;
+ case XK_Left:
+ key_event.event_string = g_strdup ("Left");
+ break;
+ case XK_Right:
+ key_event.event_string = g_strdup ("Right");
+ break;
+ default:
+ if (nbytes > 0)
+ {
+ gunichar c;
+ cbuf[nbytes] = '\0'; /* OK since length is cbuf_bytes+1 */
+ key_event.event_string = g_strdup (cbuf);
+ c = keysym2ucs (keysym);
+ if (c > 0 && !g_unichar_iscntrl (c))
+ {
+ key_event.is_text = TRUE;
+ /* incorrect for some composed chars? */
+ }
+ }
+ else
+ {
+ key_event.event_string = g_strdup ("");
+ }
+ }
+
+ key_event.timestamp = (dbus_uint32_t) x_key_event->time;
+#ifdef SPI_KEYEVENT_DEBUG
+ {
+ char *pressed_str = "pressed";
+ char *released_str = "released";
+ char *state_ptr;
+
+ if (key_event.type == Accessibility_KEY_PRESSED_EVENT)
+ state_ptr = pressed_str;
+ else
+ state_ptr = released_str;
+
+ fprintf (stderr,
+ "Key %lu %s (%c), modifiers %d; string=%s [%x] %s\n",
+ (unsigned long) keysym,
+ state_ptr,
+ keysym ? (int) keysym : '*',
+ (int) x_key_event->state,
+ key_event.event_string,
+ key_event.event_string[0],
+ (key_event.is_text == TRUE) ? "(text)" : "(not text)");
+ }
+#endif
+#ifdef SPI_DEBUG
+ fprintf (stderr, "%s%c\n",
+ (x_key_event->state & Mod1Mask)?"Alt-":"",
+ ((x_key_event->state & ShiftMask)^(x_key_event->state & LockMask))?
+ g_ascii_toupper (keysym) : g_ascii_tolower (keysym));
+ fprintf (stderr, "serial: %x Time: %x\n", x_key_event->serial, x_key_event->time);
+#endif /* SPI_DEBUG */
+ return key_event;
+}
+
+static gboolean
+spi_dec_x11_grab_key (SpiDEController *controller,
+ guint key_val,
+ Accessibility_ControllerEventMask mod_mask)
+{
+ XGrabKey (spi_get_display (),
+ key_val,
+ mod_mask,
+ spi_get_root_window (),
+ True,
+ GrabModeSync,
+ GrabModeSync);
+ XSync (spi_get_display (), False);
+ return spi_clear_error_state ();
+}
+
+static void
+spi_dec_x11_ungrab_key (SpiDEController *controller,
+ guint key_val,
+ Accessibility_ControllerEventMask mod_mask)
+{
+ XUngrabKey (spi_get_display (),
+ key_val,
+ mod_mask,
+ spi_get_root_window ());
+}
+
+static unsigned int
+xkb_get_slowkeys_delay (SpiDEController *controller)
+{
+ unsigned int retval = 0;
+ DEControllerPrivateData *priv = controller->priv;
+#ifdef HAVE_XKB
+#ifdef XKB_HAS_GET_SLOW_KEYS_DELAY
+ retval = XkbGetSlowKeysDelay (spi_get_display (),
+ XkbUseCoreKbd, &bounce_delay);
+#else
+ if (!(priv->xkb_desc == (XkbDescPtr) BadAlloc || priv->xkb_desc == NULL))
+ {
+ Status s = XkbGetControls (spi_get_display (),
+ XkbAllControlsMask, priv->xkb_desc);
+ if (s == Success)
+ {
+ if (priv->xkb_desc->ctrls->enabled_ctrls & XkbSlowKeysMask)
+ retval = priv->xkb_desc->ctrls->slow_keys_delay;
+ }
+ }
+#endif
+#endif
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "SlowKeys delay: %d\n", (int) retval);
+#endif
+ return retval;
+}
+
+static unsigned int
+xkb_get_bouncekeys_delay (SpiDEController *controller)
+{
+ unsigned int retval = 0;
+ DEControllerPrivateData *priv = controller->priv;
+#ifdef HAVE_XKB
+#ifdef XKB_HAS_GET_BOUNCE_KEYS_DELAY
+ retval = XkbGetBounceKeysDelay (spi_get_display (),
+ XkbUseCoreKbd, &bounce_delay);
+#else
+ if (!(priv->xkb_desc == (XkbDescPtr) BadAlloc || priv->xkb_desc == NULL))
+ {
+ Status s = XkbGetControls (spi_get_display (),
+ XkbAllControlsMask, priv->xkb_desc);
+ if (s == Success)
+ {
+ if (priv->xkb_desc->ctrls->enabled_ctrls & XkbBounceKeysMask)
+ retval = priv->xkb_desc->ctrls->debounce_delay;
+ }
+ }
+#endif
+#endif
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "BounceKeys delay: %d\n", (int) retval);
+#endif
+ return retval;
+}
+
+static gboolean
+spi_dec_x11_synth_keycode_press (SpiDEController *controller,
+ unsigned int keycode)
+{
+ unsigned int time = CurrentTime;
+ unsigned int bounce_delay;
+ unsigned int elapsed_msec;
+ struct timeval tv;
+ DEControllerPrivateData *priv = controller->priv;
+
+ spi_x_error_trap ();
+ if (keycode == priv->last_release_keycode)
+ {
+ bounce_delay = xkb_get_bouncekeys_delay (controller);
+ if (bounce_delay)
+ {
+ gettimeofday (&tv, NULL);
+ elapsed_msec =
+ (tv.tv_sec - priv->last_release_time.tv_sec) * 1000
+ + (tv.tv_usec - priv->last_release_time.tv_usec) / 1000;
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "%d ms elapsed (%ld usec)\n", elapsed_msec,
+ (long) (tv.tv_usec - priv->last_release_time.tv_usec));
+#endif
+#ifdef THIS_IS_BROKEN
+ if (elapsed_msec < bounce_delay)
+ time = bounce_delay - elapsed_msec + 1;
+#else
+ time = bounce_delay + 10;
+ /* fudge for broken XTest */
+#endif
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "waiting %d ms\n", time);
+#endif
+ }
+ }
+ XTestFakeKeyEvent (spi_get_display (), keycode, True, time);
+ priv->last_press_keycode = keycode;
+ XFlush (spi_get_display ());
+ XSync (spi_get_display (), False);
+ gettimeofday (&priv->last_press_time, NULL);
+ return TRUE;
+}
+
+static gboolean
+spi_dec_x11_synth_keycode_release (SpiDEController *controller,
+ unsigned int keycode)
+{
+ unsigned int time = CurrentTime;
+ unsigned int slow_delay;
+ unsigned int elapsed_msec;
+ struct timeval tv;
+ DEControllerPrivateData *priv = controller->priv;
+
+ spi_x_error_trap ();
+ if (keycode == priv->last_press_keycode)
+ {
+ slow_delay = xkb_get_slowkeys_delay (controller);
+ if (slow_delay)
+ {
+ gettimeofday (&tv, NULL);
+ elapsed_msec =
+ (tv.tv_sec - priv->last_press_time.tv_sec) * 1000
+ + (tv.tv_usec - priv->last_press_time.tv_usec) / 1000;
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "%d ms elapsed (%ld usec)\n", elapsed_msec,
+ (long) (tv.tv_usec - priv->last_press_time.tv_usec));
+#endif
+#ifdef THIS_IS_BROKEN_DUNNO_WHY
+ if (elapsed_msec < slow_delay)
+ time = slow_delay - elapsed_msec + 1;
+#else
+ time = slow_delay + 10;
+ /* our XTest seems broken, we have to add slop as above */
+#endif
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "waiting %d ms\n", time);
+#endif
+ }
+ }
+ XTestFakeKeyEvent (spi_get_display (), keycode, False, time);
+ priv->last_release_keycode = keycode;
+ XSync (spi_get_display (), False);
+ gettimeofday (&priv->last_release_time, NULL);
+ return TRUE;
+}
+
+static gboolean
+spi_dec_x11_lock_modifiers (SpiDEController *controller, unsigned modifiers)
+{
+ DEControllerPrivateData *priv = controller->priv;
+
+ if (priv->have_xkb) {
+ return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
+ modifiers, modifiers);
+ } else {
+ int mod_index;
+ if (xmkeymap==NULL)
+ xmkeymap = XGetModifierMapping(spi_get_display ());
+ for (mod_index=0;mod_index<8;mod_index++)
+ if (modifiers & (1<<mod_index))
+ spi_dec_x11_synth_keycode_press(controller, xmkeymap->modifiermap[mod_index]);
+ return TRUE;
+ }
+}
+
+static gboolean
+spi_dec_x11_unlock_modifiers (SpiDEController *controller, unsigned modifiers)
+{
+ DEControllerPrivateData *priv = controller->priv;
+
+ if (priv->have_xkb) {
+ return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
+ modifiers, 0);
+ } else {
+ int mod_index;
+ if (xmkeymap==NULL)
+ xmkeymap = XGetModifierMapping(spi_get_display ());
+
+ for (mod_index=0;mod_index<8;mod_index++)
+ if (modifiers & (1<<mod_index))
+ spi_dec_x11_synth_keycode_release(controller, xmkeymap->modifiermap[mod_index]);
+ return TRUE;
+ }
+}
+
+static KeySym
+keysym_for_unichar (SpiDEController *controller, gunichar unichar)
+{
+ return (KeySym) ucs2keysym ((long) unichar);
+}
+
+static gboolean
+spi_dec_x11_synth_keystring (SpiDEController *controller, guint synth_type, gint keycode, const char *keystring)
+{
+ /* probably we need to create and inject an XIM handler eventually. */
+ /* for now, try to match the string to existing
+ * keycode+modifier states.
+ */
+ KeySym *keysyms;
+ gint maxlen = 0;
+ gunichar unichar = 0;
+ gint i = 0;
+ gboolean retval = TRUE;
+ const gchar *c;
+ KeySym keysym;
+
+ maxlen = strlen (keystring) + 1;
+ keysyms = g_new0 (KeySym, maxlen);
+ if (!(keystring && *keystring && g_utf8_validate (keystring, -1, &c))) {
+ retval = FALSE;
+ }
+ else {
+#ifdef SPI_DEBUG
+ fprintf (stderr, "[keystring synthesis attempted on %s]\n", keystring);
+#endif
+ while (keystring && (unichar = g_utf8_get_char (keystring))) {
+ char bytes[6];
+ gint mbytes;
+
+ mbytes = g_unichar_to_utf8 (unichar, bytes);
+ bytes[mbytes] = '\0';
+#ifdef SPI_DEBUG
+ fprintf (stderr, "[unichar %s]", bytes);
+#endif
+ keysym = keysym_for_unichar (controller, unichar);
+ if (keysym == NoSymbol) {
+#ifdef SPI_DEBUG
+ fprintf (stderr, "no keysym for %s", bytes);
+#endif
+ retval = FALSE;
+ break;
+ }
+ keysyms[i++] = keysym;
+ keystring = g_utf8_next_char (keystring);
+ }
+ keysyms[i++] = 0;
+ XSynchronize (spi_get_display (), TRUE);
+ for (i = 0; keysyms[i]; ++i) {
+ if (!spi_dec_synth_keysym (controller, keysyms[i])) {
+#ifdef SPI_DEBUG
+ fprintf (stderr, "could not synthesize %c\n",
+ (int) keysyms[i]);
+#endif
+ retval = FALSE;
+ break;
+ }
+ }
+ XSynchronize (spi_get_display (), FALSE);
+ }
+ g_free (keysyms);
+
+ if (synth_type == Accessibility_KEY_SYM) {
+ keysym = keycode;
+ }
+ else {
+ keysym = XkbKeycodeToKeysym (spi_get_display (), keycode, 0, 0);
+ }
+ if (XkbKeysymToModifiers (spi_get_display (), keysym) == 0) {
+ spi_dec_clear_unlatch_pending (controller);
+ }
+ return retval;
+}
+
+#ifdef HAVE_XEVIE
+static Bool
+isEvent(Display *dpy, XEvent *event, char *arg)
+{
+ return TRUE;
+}
+
+static gboolean
+handle_io (GIOChannel *source,
+ GIOCondition condition,
+ gpointer data)
+{
+ SpiDEController *controller = (SpiDEController *) data;
+ DEControllerPrivateData *priv = controller->priv;
+ gboolean is_consumed = FALSE;
+ XEvent ev;
+
+ while (XCheckIfEvent(priv->xevie_display, &ev, isEvent, NULL))
+ {
+ if (ev.type == KeyPress || ev.type == KeyRelease)
+ is_consumed = spi_device_event_controller_forward_key_event (controller, &ev);
+
+ if (! is_consumed)
+ XevieSendEvent(priv->xevie_display, &ev, XEVIE_UNMODIFIED);
+ }
+
+ return TRUE;
+}
+#endif /* HAVE_XEVIE */
+
+static void
+spi_dec_x11_init (SpiDEController *controller)
+{
+ DEControllerPrivateData *priv = controller->priv;
+ spi_events_init (spi_get_display());
+#ifdef HAVE_XEVIE
+ GIOChannel *ioc;
+ int fd;
+#endif /* HAVE_XEVIE */
+
+ spi_events_init (spi_get_display ());
+#ifdef HAVE_XEVIE
+ priv->xevie_display = XOpenDisplay(NULL);
+
+ if (XevieStart(priv->xevie_display) == TRUE)
+ {
+#ifdef SPI_KEYEVENT_DEBUG
+ fprintf (stderr, "XevieStart() success \n");
+#endif
+ XevieSelectInput(priv->xevie_display, KeyPressMask | KeyReleaseMask);
+
+ fd = ConnectionNumber(priv->xevie_display);
+ ioc = g_io_channel_unix_new (fd);
+ g_io_add_watch (ioc, G_IO_IN | G_IO_HUP, handle_io, controller);
+ g_io_channel_unref (ioc);
+ }
+ else
+ {
+#ifdef SPI_KEYEVENT_DEBUG
+ fprintf (stderr, "XevieStart() failed, only one client is allowed to do event int exception\n");
+#endif
+ }
+#endif /* HAVE_XEVIE */
+
+ gettimeofday (&priv->last_press_time, NULL);
+ gettimeofday (&priv->last_release_time, NULL);
+ spi_controller_register_with_devices (controller);
+
+ spi_dec_init_mouse_listener (controller);
+
+ saved_controller = controller;
+}
+
+static void
+spi_dec_x11_finalize (SpiDEController *controller)
+{
+ DEControllerPrivateData *priv = controller->priv;
+ /* disconnect any special listeners, get rid of outstanding keygrabs */
+ XUngrabKey (spi_get_display (), AnyKey, AnyModifier, DefaultRootWindow (spi_get_display ()));
+
+#ifdef HAVE_XEVIE
+ if (priv->xevie_display != NULL)
+ {
+ XevieEnd(priv->xevie_display);
+#ifdef SPI_KEYEVENT_DEBUG
+ printf("XevieEnd(dpy) finished \n");
+#endif
+ }
+#endif
+
+ if (priv->xkb_desc)
+ XkbFreeKeyboard (priv->xkb_desc, 0, True);
+ /* TODO: Should free the keymap */
+}
+
+static gboolean
+spi_device_event_controller_forward_key_event (SpiDEController *controller,
+ const XEvent *event)
+{
+ DEControllerPrivateData *priv = controller->priv;
+ Accessibility_DeviceEvent key_event;
+ gboolean ret;
+
+ g_assert (event->type == KeyPress || event->type == KeyRelease);
+
+ key_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
+
+ if (priv->xevie_display == NULL)
+ spi_controller_update_key_grabs (controller, &key_event);
+
+ /* relay to listeners, and decide whether to consume it or not */
+ ret = spi_controller_notify_keylisteners (controller, &key_event, TRUE);
+ g_free(key_event.event_string);
+ return ret;
+}
+
+
+static gboolean
+is_key_released (long code)
+{
+ char keys[32];
+ int down;
+
+ XQueryKeymap (spi_get_display (), keys);
+ down = BIT (keys, code);
+ return (down == 0);
+}
+
+static gboolean
+check_release (gpointer data)
+{
+ gboolean released;
+ Accessibility_DeviceEvent *event = (Accessibility_DeviceEvent *)data;
+ KeyCode code = event->hw_code;
+
+ released = is_key_released (code);
+
+ if (released)
+ {
+ check_release_handler = 0;
+ event->type = Accessibility_KEY_RELEASED_EVENT;
+ spi_controller_notify_keylisteners (saved_controller, event, TRUE);
+ }
+ return (released == 0);
+}
+
+static void
+wait_for_release_event (XEvent *event,
+ SpiDEController *controller)
+{
+ pressed_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
+ check_release_handler = g_timeout_add (CHECK_RELEASE_DELAY, check_release, &pressed_event);
+ g_source_set_name_by_id (check_release_handler, "[at-spi2-core] check_release");
+}
+
+static void
+spi_dec_x11_emit_modifier_event (SpiDEController *controller, guint prev_mask,
+ guint current_mask)
+{
+ dbus_uint32_t d1, d2;
+
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "MODIFIER CHANGE EVENT! %x to %x\n",
+ prev_mask, current_mask);
+#endif
+
+ /* set bits for the virtual modifiers like NUMLOCK */
+ if (prev_mask & _numlock_physical_mask)
+ prev_mask |= SPI_KEYMASK_NUMLOCK;
+ if (current_mask & _numlock_physical_mask)
+ current_mask |= SPI_KEYMASK_NUMLOCK;
+
+ d1 = prev_mask & key_modifier_mask;
+ d2 = current_mask & key_modifier_mask;
+ spi_dec_dbus_emit(controller, SPI_DBUS_INTERFACE_EVENT_KEYBOARD, "Modifiers", "", d1, d2);
+}
+
+static void
+spi_dec_x11_generate_mouse_event (SpiDEController *controller,
+ gint x,
+ gint y,
+ const char *eventName)
+{
+ int button = 0;
+ gboolean err = FALSE;
+ Display *display = spi_get_display ();
+
+ switch (eventName[0])
+ {
+ case 'b':
+ switch (eventName[1])
+ {
+ /* TODO: check number of buttons before parsing */
+ case '1':
+ button = 1;
+ break;
+ case '2':
+ button = 2;
+ break;
+ case '3':
+ button = 3;
+ break;
+ case '4':
+ button = 4;
+ break;
+ case '5':
+ button = 5;
+ break;
+ default:
+ err = TRUE;
+ }
+ if (!err)
+ {
+ if (x != -1 && y != -1)
+ {
+ XTestFakeMotionEvent (display, DefaultScreen (display),
+ x, y, 0);
+ }
+ XTestFakeButtonEvent (display, button, !(eventName[2] == 'r'), 0);
+ if (eventName[2] == 'c')
+ XTestFakeButtonEvent (display, button, FALSE, 1);
+ else if (eventName[2] == 'd')
+ {
+ XTestFakeButtonEvent (display, button, FALSE, 1);
+ XTestFakeButtonEvent (display, button, TRUE, 2);
+ XTestFakeButtonEvent (display, button, FALSE, 3);
+ }
+ }
+ break;
+ case 'r': /* relative motion */
+ XTestFakeRelativeMotionEvent (display, x, y, 0);
+ break;
+ case 'a': /* absolute motion */
+ XTestFakeMotionEvent (display, DefaultScreen (display),
+ x, y, 0);
+ break;
+ }
+}
+
+void
+spi_dec_setup_x11 (SpiDEControllerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+ klass->plat.get_keycode = spi_dec_x11_get_keycode;
+ klass->plat.mouse_check = spi_dec_x11_mouse_check;
+ klass->plat.synth_keycode_press = spi_dec_x11_synth_keycode_press;
+ klass->plat.synth_keycode_release = spi_dec_x11_synth_keycode_release;
+ klass->plat.lock_modifiers = spi_dec_x11_lock_modifiers;
+ klass->plat.unlock_modifiers = spi_dec_x11_unlock_modifiers;
+ klass->plat.synth_keystring = spi_dec_x11_synth_keystring;
+ klass->plat.grab_key = spi_dec_x11_grab_key;
+ klass->plat.ungrab_key = spi_dec_x11_ungrab_key;
+ klass->plat.emit_modifier_event = spi_dec_x11_emit_modifier_event;
+ klass->plat.generate_mouse_event = spi_dec_x11_generate_mouse_event;
+
+ klass->plat.init = spi_dec_x11_init;
+ klass->plat.finalize = spi_dec_x11_finalize;
+
+ g_type_class_add_private (object_class, sizeof (DEControllerPrivateData));
+}
diff --git a/registryd/deviceeventcontroller.c b/registryd/deviceeventcontroller.c
new file mode 100644
index 0000000..8279a1d
--- /dev/null
+++ b/registryd/deviceeventcontroller.c
@@ -0,0 +1,2044 @@
+/* AT-SPI - Assistive Technology Service Provider Interface
+ *
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2003 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/* deviceeventcontroller.c: implement the DeviceEventController interface */
+
+#include <config.h>
+
+#undef SPI_XKB_DEBUG
+#undef SPI_DEBUG
+#undef SPI_KEYEVENT_DEBUG
+
+#include <string.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <sys/time.h>
+
+#include <glib.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"
+
+#define CHECK_RELEASE_DELAY 20
+#define BIT(c, x) (c[x/8]&(1<<(x%8)))
+static SpiDEController *saved_controller;
+
+/* Our parent Gtk object type */
+#define PARENT_TYPE G_TYPE_OBJECT
+
+/* A pointer to our parent object class */
+static int spi_error_code = 0;
+struct _SpiPoint {
+ gint x;
+ gint y;
+};
+typedef struct _SpiPoint SpiPoint;
+static unsigned int mouse_mask_state = 0;
+static unsigned int key_modifier_mask =
+ Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask | ShiftMask | LockMask | ControlMask | SPI_KEYMASK_NUMLOCK;
+static unsigned int _numlock_physical_mask = Mod2Mask; /* a guess, will be reset */
+
+static gboolean have_mouse_listener = FALSE;
+static gboolean have_mouse_event_listener = FALSE;
+
+
+typedef struct {
+ guint ref_count : 30;
+ guint pending_add : 1;
+ guint pending_remove : 1;
+
+ Accessibility_ControllerEventMask mod_mask;
+ dbus_uint32_t key_val; /* KeyCode */
+} DEControllerGrabMask;
+
+
+gboolean spi_controller_update_key_grabs (SpiDEController *controller,
+ Accessibility_DeviceEvent *recv);
+
+static gboolean eventtype_seq_contains_event (dbus_uint32_t types,
+ const Accessibility_DeviceEvent *event);
+static gboolean spi_dec_poll_mouse_moving (gpointer data);
+static gboolean spi_dec_poll_mouse_idle (gpointer data);
+
+G_DEFINE_TYPE(SpiDEController, spi_device_event_controller, G_TYPE_OBJECT)
+
+static gint
+spi_dec_plat_get_keycode (SpiDEController *controller,
+ gint keysym,
+ gchar *key_str,
+ gboolean fix,
+ guint *modmask)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.get_keycode)
+ return klass->plat.get_keycode (controller, keysym, key_str, fix, modmask);
+ else
+ return keysym;
+}
+
+static guint
+spi_dec_plat_mouse_check (SpiDEController *controller,
+ int *x, int *y, gboolean *moved)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.mouse_check)
+ return klass->plat.mouse_check (controller, x, y, moved);
+ else
+ return 0;
+}
+
+static gboolean
+spi_dec_plat_grab_key (SpiDEController *controller, guint key_val, Accessibility_ControllerEventMask mod_mask)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.grab_key)
+ return klass->plat.grab_key (controller, key_val, mod_mask);
+ else
+ return FALSE;
+}
+
+static void
+spi_dec_plat_ungrab_key (SpiDEController *controller, guint key_val, Accessibility_ControllerEventMask mod_mask)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.ungrab_key)
+ klass->plat.ungrab_key (controller, key_val, mod_mask);
+}
+
+static gboolean
+spi_dec_plat_synth_keycode_press (SpiDEController *controller,
+ unsigned int keycode)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.synth_keycode_press)
+ return klass->plat.synth_keycode_press (controller, keycode);
+ else
+ return FALSE;
+}
+
+static gboolean
+spi_dec_plat_synth_keycode_release (SpiDEController *controller,
+ unsigned int keycode)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.synth_keycode_release)
+ return klass->plat.synth_keycode_release (controller, keycode);
+ else
+ return FALSE;
+}
+
+static gboolean
+spi_dec_plat_lock_modifiers (SpiDEController *controller, unsigned modifiers)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.lock_modifiers)
+ return klass->plat.lock_modifiers (controller, modifiers);
+ else
+ return FALSE;
+}
+
+static gboolean
+spi_dec_plat_unlock_modifiers (SpiDEController *controller, unsigned modifiers)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.unlock_modifiers)
+ return klass->plat.unlock_modifiers (controller, modifiers);
+ else
+ return FALSE;
+}
+
+static gboolean
+spi_dec_plat_synth_keystring (SpiDEController *controller, guint synth_type, gint keycode, const char *keystring)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.synth_keystring)
+ return klass->plat.synth_keystring (controller, synth_type, keycode, keystring);
+ else
+ return FALSE;
+}
+
+static void
+spi_dec_plat_emit_modifier_event (SpiDEController *controller, guint prev_mask,
+ guint current_mask)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.emit_modifier_event)
+ return klass->plat.emit_modifier_event (controller, prev_mask, current_mask);
+}
+
+static void
+spi_dec_plat_generate_mouse_event (SpiDEController *controller,
+ gint x,
+ gint y,
+ const char *eventName)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+ if (klass->plat.generate_mouse_event)
+ return klass->plat.generate_mouse_event (controller, x, y, eventName);
+}
+
+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 DEControllerGrabMask *
+spi_grab_mask_clone (DEControllerGrabMask *grab_mask)
+{
+ DEControllerGrabMask *clone = g_new (DEControllerGrabMask, 1);
+
+ memcpy (clone, grab_mask, sizeof (DEControllerGrabMask));
+
+ clone->ref_count = 1;
+ clone->pending_add = TRUE;
+ clone->pending_remove = FALSE;
+
+ return clone;
+}
+
+static void
+spi_grab_mask_free (DEControllerGrabMask *grab_mask)
+{
+ g_free (grab_mask);
+}
+
+static gint
+spi_grab_mask_compare_values (gconstpointer p1, gconstpointer p2)
+{
+ DEControllerGrabMask *l1 = (DEControllerGrabMask *) p1;
+ DEControllerGrabMask *l2 = (DEControllerGrabMask *) p2;
+
+ if (p1 == p2)
+ {
+ return 0;
+ }
+ else
+ {
+ return ((l1->mod_mask != l2->mod_mask) || (l1->key_val != l2->key_val));
+ }
+}
+
+void
+spi_dec_dbus_emit (SpiDEController *controller, const char *interface,
+ const char *name, const char *minor, int a1, int a2)
+{
+ 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);
+
+ 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_poll_mouse_moved (gpointer data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(data);
+ int x, y;
+ gboolean moved;
+ guint mask_return;
+
+ mask_return = spi_dec_plat_mouse_check (controller, &x, &y, &moved);
+
+ if ((mask_return & key_modifier_mask) !=
+ (mouse_mask_state & key_modifier_mask))
+ {
+ spi_dec_plat_emit_modifier_event (controller, mouse_mask_state, mask_return);
+ mouse_mask_state = mask_return;
+ }
+
+ return moved;
+}
+
+static gboolean
+spi_dec_poll_mouse_idle (gpointer data)
+{
+ if (!have_mouse_event_listener && !have_mouse_listener)
+ return FALSE;
+ else if (!spi_dec_poll_mouse_moved (data))
+ return TRUE;
+ else
+ {
+ guint id;
+ id = g_timeout_add (20, spi_dec_poll_mouse_moving, data);
+ g_source_set_name_by_id (id, "[at-spi2-core] spi_dec_poll_mouse_moving");
+ return FALSE;
+ }
+}
+
+static gboolean
+spi_dec_poll_mouse_moving (gpointer data)
+{
+ if (!have_mouse_event_listener && !have_mouse_listener)
+ return FALSE;
+ else if (spi_dec_poll_mouse_moved (data))
+ return TRUE;
+ else
+ {
+ guint id;
+ id = g_timeout_add (100, spi_dec_poll_mouse_idle, data);
+ g_source_set_name_by_id (id, "[at-spi2-core] check_release");
+ return FALSE;
+ }
+}
+
+/**
+ * Eventually we can use this to make the marshalling of mask types
+ * more sane, but for now we just use this to detect
+ * the use of 'virtual' masks such as numlock and convert them to
+ * system-specific mask values (i.e. ModMask).
+ *
+ **/
+static Accessibility_ControllerEventMask
+spi_dec_translate_mask (Accessibility_ControllerEventMask mask)
+{
+ Accessibility_ControllerEventMask tmp_mask;
+ gboolean has_numlock;
+
+ has_numlock = (mask & SPI_KEYMASK_NUMLOCK);
+ tmp_mask = mask;
+ if (has_numlock)
+ {
+ tmp_mask = mask ^ SPI_KEYMASK_NUMLOCK;
+ tmp_mask |= _numlock_physical_mask;
+ }
+
+ return tmp_mask;
+}
+
+static DEControllerKeyListener *
+spi_dec_key_listener_new (const char *bus_name,
+ const char *path,
+ GSList *keys,
+ const Accessibility_ControllerEventMask mask,
+ const dbus_uint32_t types,
+ const Accessibility_EventListenerMode *mode)
+{
+ DEControllerKeyListener *key_listener = g_new0 (DEControllerKeyListener, 1);
+ 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;
+ key_listener->mask = spi_dec_translate_mask (mask);
+ key_listener->listener.types = types;
+ if (mode)
+ {
+ key_listener->mode = (Accessibility_EventListenerMode *) g_malloc(sizeof(Accessibility_EventListenerMode));
+ memcpy(key_listener->mode, mode, sizeof(*mode));
+ }
+ else
+ key_listener->mode = NULL;
+
+#ifdef SPI_DEBUG
+ g_print ("new listener, with mask %x, is_global %d, keys %p (%d)\n",
+ (unsigned int) key_listener->mask,
+ (int) (mode ? mode->global : 0),
+ (void *) key_listener->keys,
+ (int) (key_listener->keys ? g_slist_length(key_listener->keys) : 0));
+#endif
+
+ return key_listener;
+}
+
+static DEControllerListener *
+spi_dec_listener_new (const char *bus_name,
+ const char *path,
+ dbus_uint32_t types)
+{
+ DEControllerListener *listener = g_new0 (DEControllerListener, 1);
+ listener->bus_name = g_strdup(bus_name);
+ listener->path = g_strdup(path);
+ listener->type = SPI_DEVICE_TYPE_MOUSE;
+ listener->types = types;
+ return listener;
+}
+
+static DEControllerListener *
+spi_listener_clone (DEControllerListener *listener)
+{
+ DEControllerListener *clone = g_new0 (DEControllerListener, 1);
+ clone->bus_name = g_strdup (listener->bus_name);
+ clone->path = g_strdup (listener->path);
+ clone->type = listener->type;
+ clone->types = listener->types;
+ return clone;
+}
+
+static GSList *keylist_clone (GSList *s)
+{
+ GSList *d = NULL;
+ GSList *l;
+
+ for (l = s; l; l = g_slist_next(l))
+ {
+ Accessibility_KeyDefinition *kd = (Accessibility_KeyDefinition *)g_malloc(sizeof(Accessibility_KeyDefinition));
+ if (kd)
+ {
+ Accessibility_KeyDefinition *kds = (Accessibility_KeyDefinition *)l->data;
+ kd->keycode = kds->keycode;
+ kd->keysym = kds->keysym;
+ kd->keystring = g_strdup(kds->keystring);
+ d = g_slist_append(d, kd);
+ }
+ }
+ return d;
+}
+
+static DEControllerKeyListener *
+spi_key_listener_clone (DEControllerKeyListener *key_listener)
+{
+ DEControllerKeyListener *clone = g_new0 (DEControllerKeyListener, 1);
+ 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);
+ clone->mask = key_listener->mask;
+ clone->listener.types = key_listener->listener.types;
+ if (key_listener->mode)
+ {
+ clone->mode = (Accessibility_EventListenerMode *)g_malloc(sizeof(Accessibility_EventListenerMode));
+ if (clone->mode) memcpy(clone->mode, key_listener->mode, sizeof(Accessibility_EventListenerMode));
+ }
+ else
+ clone->mode = NULL;
+ return clone;
+}
+
+static void keylist_free(GSList *keys)
+{
+ GSList *l;
+
+ for (l = keys; l; l = g_slist_next(l))
+ {
+ Accessibility_KeyDefinition *kd = (Accessibility_KeyDefinition *)l->data;
+ g_free(kd->keystring);
+ g_free(kd);
+ }
+ g_slist_free (keys);
+}
+
+static void
+spi_key_listener_data_free (DEControllerKeyListener *key_listener)
+{
+ 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);
+}
+
+static void
+spi_key_listener_clone_free (DEControllerKeyListener *clone)
+{
+ spi_key_listener_data_free (clone);
+}
+
+static void
+spi_listener_clone_free (DEControllerListener *clone)
+{
+ g_free (clone->path);
+ g_free (clone->bus_name);
+ g_free (clone);
+}
+
+static void
+spi_dec_listener_free (DEControllerListener *listener)
+{
+ 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
+_register_keygrab (SpiDEController *controller,
+ DEControllerGrabMask *grab_mask)
+{
+ GList *l;
+
+ l = g_list_find_custom (controller->keygrabs_list, grab_mask,
+ spi_grab_mask_compare_values);
+ if (l)
+ {
+ DEControllerGrabMask *cur_mask = l->data;
+
+ cur_mask->ref_count++;
+ if (cur_mask->pending_remove)
+ {
+ cur_mask->pending_remove = FALSE;
+ }
+ }
+ else
+ {
+ controller->keygrabs_list =
+ g_list_prepend (controller->keygrabs_list,
+ spi_grab_mask_clone (grab_mask));
+ }
+}
+
+static void
+_deregister_keygrab (SpiDEController *controller,
+ DEControllerGrabMask *grab_mask)
+{
+ GList *l;
+
+ l = g_list_find_custom (controller->keygrabs_list, grab_mask,
+ spi_grab_mask_compare_values);
+
+ if (l)
+ {
+ DEControllerGrabMask *cur_mask = l->data;
+
+ cur_mask->ref_count--;
+ if (cur_mask->ref_count <= 0)
+ {
+ cur_mask->pending_remove = TRUE;
+ }
+ }
+}
+
+static void
+handle_keygrab (SpiDEController *controller,
+ DEControllerKeyListener *key_listener,
+ void (*process_cb) (SpiDEController *controller,
+ DEControllerGrabMask *grab_mask))
+{
+ DEControllerGrabMask grab_mask = { 0 };
+
+ grab_mask.mod_mask = key_listener->mask;
+ if (g_slist_length (key_listener->keys) == 0) /* special case means AnyKey/AllKeys */
+ {
+ grab_mask.key_val = AnyKey;
+#ifdef SPI_DEBUG
+ fprintf (stderr, "AnyKey grab!");
+#endif
+ process_cb (controller, &grab_mask);
+ }
+ else
+ {
+ GSList *l;
+
+ for (l = key_listener->keys; l; l = g_slist_next(l))
+ {
+ Accessibility_KeyDefinition *keydef = l->data;
+ long key_val;
+ key_val = spi_dec_plat_get_keycode (controller, keydef->keysym, keydef->keystring, FALSE, NULL);
+ if (!key_val)
+ key_val = keydef->keycode;
+ grab_mask.key_val = key_val;
+ process_cb (controller, &grab_mask);
+ }
+ }
+}
+
+static gboolean
+spi_controller_register_global_keygrabs (SpiDEController *controller,
+ DEControllerKeyListener *key_listener)
+{
+ handle_keygrab (controller, key_listener, _register_keygrab);
+ return spi_controller_update_key_grabs (controller, NULL);
+}
+
+static void
+spi_controller_deregister_global_keygrabs (SpiDEController *controller,
+ DEControllerKeyListener *key_listener)
+{
+ handle_keygrab (controller, key_listener, _deregister_keygrab);
+ 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;
+ 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:
+ key_listener = (DEControllerKeyListener *) listener;
+
+ 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)
+ {
+ retval = spi_controller_register_global_keygrabs (controller, key_listener);
+ }
+ else
+ 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) {
+ guint id;
+ id = g_timeout_add (100, spi_dec_poll_mouse_idle, controller);
+ g_source_set_name_by_id (id, "[at-spi2-core] spi_dec_poll_mouse_idle");
+ }
+ }
+ spi_dbus_add_disconnect_match (controller->bus, listener->bus_name);
+ notify_mouse_listener (controller, listener, TRUE);
+ break;
+ default:
+ break;
+ }
+ return FALSE;
+}
+
+static void
+set_reply (DBusPendingCall *pending, void *user_data)
+{
+ void **replyptr = (void **)user_data;
+
+ *replyptr = dbus_pending_call_steal_reply (pending);
+}
+
+static GSList *hung_processes = NULL;
+
+static void
+reset_hung_process (DBusPendingCall *pending, void *data)
+{
+ 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)
+{
+ 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;
+ }
+ }
+
+ if (spi_dbus_marshal_deviceEvent(message, key_event))
+ {
+ 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)
+ {
+ dbus_message_get_args(reply, NULL, DBUS_TYPE_BOOLEAN, &consumed, DBUS_TYPE_INVALID);
+ dbus_message_unref(reply);
+ }
+ }
+ dbus_message_unref(message);
+ return consumed;
+}
+
+gboolean
+spi_controller_notify_mouselisteners (SpiDEController *controller,
+ const Accessibility_DeviceEvent *event)
+{
+ GList *l;
+ GSList *notify = NULL, *l2;
+ GList **listeners = &controller->mouse_listeners;
+ gboolean is_consumed;
+#ifdef SPI_KEYEVENT_DEBUG
+ gboolean found = FALSE;
+#endif
+ if (!listeners)
+ {
+ return FALSE;
+ }
+
+ for (l = *listeners; l; l = l->next)
+ {
+ DEControllerListener *listener = l->data;
+
+ if (eventtype_seq_contains_event (listener->types, event))
+ {
+ /* we clone (don't dup) the listener, to avoid refcount inc. */
+ notify = g_slist_prepend (notify,
+ spi_listener_clone (listener));
+#ifdef SPI_KEYEVENT_DEBUG
+ found = TRUE;
+#endif
+ }
+ }
+
+#ifdef SPI_KEYEVENT_DEBUG
+ if (!found)
+ {
+ g_print ("no match for event\n");
+ }
+#endif
+
+ is_consumed = FALSE;
+ for (l2 = notify; l2 && !is_consumed; l2 = l2->next)
+ {
+ DEControllerListener *listener = l2->data;
+
+ is_consumed = Accessibility_DeviceEventListener_NotifyEvent (controller, controller->registry, listener, event);
+
+ spi_listener_clone_free ((DEControllerListener *) l2->data);
+ }
+
+ for (; l2; l2 = l2->next)
+ {
+ DEControllerListener *listener = l2->data;
+ spi_listener_clone_free (listener);
+ /* clone doesn't have its own ref, so don't use spi_device_listener_free */
+ }
+
+ g_slist_free (notify);
+
+#ifdef SPI_DEBUG
+ if (is_consumed) g_message ("consumed\n");
+#endif
+ return is_consumed;
+}
+
+static gboolean
+key_set_contains_key (GSList *key_set,
+ const Accessibility_DeviceEvent *key_event)
+{
+ gint i;
+ gint len;
+ GSList *l;
+
+ if (!key_set)
+ {
+#ifdef SPI_DEBUG
+ g_print ("null key set!\n");
+#endif
+ return TRUE;
+ }
+
+ len = g_slist_length (key_set);
+
+ if (len == 0) /* special case, means "all keys/any key" */
+ {
+#ifdef SPI_DEBUG
+ g_print ("anykey\n");
+#endif
+ return TRUE;
+ }
+
+ for (l = key_set,i = 0; l; l = g_slist_next(l),i++)
+ {
+ Accessibility_KeyDefinition *kd = l->data;
+#ifdef SPI_KEYEVENT_DEBUG
+ g_print ("key_set[%d] event = %d, code = %d; key_event %d, code %d, string %s\n",
+ i,
+ (int) kd->keysym,
+ (int) kd->keycode,
+ (int) key_event->id,
+ (int) key_event->hw_code,
+ key_event->event_string);
+#endif
+ if (kd->keysym == (dbus_uint32_t) key_event->id)
+ {
+ return TRUE;
+ }
+ if (kd->keycode == (dbus_uint32_t) key_event->hw_code)
+ {
+ return TRUE;
+ }
+ if (key_event->event_string && key_event->event_string[0] &&
+ !strcmp (kd->keystring, key_event->event_string))
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+static gboolean
+eventtype_seq_contains_event (dbus_uint32_t types,
+ const Accessibility_DeviceEvent *event)
+{
+ if (types == 0) /* special case, means "all events/any event" */
+ {
+ return TRUE;
+ }
+
+ return (types & (1 << event->type));
+}
+
+static gboolean
+spi_key_event_matches_listener (const Accessibility_DeviceEvent *key_event,
+ DEControllerKeyListener *listener,
+ dbus_bool_t is_system_global)
+{
+ if (((key_event->modifiers & 0xFF) == (dbus_uint16_t) (listener->mask & 0xFF)) &&
+ key_set_contains_key (listener->keys, key_event) &&
+ eventtype_seq_contains_event (listener->listener.types, key_event) &&
+ (is_system_global == listener->mode->global))
+ {
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
+}
+
+gboolean
+spi_controller_notify_keylisteners (SpiDEController *controller,
+ Accessibility_DeviceEvent *key_event,
+ dbus_bool_t is_system_global)
+{
+ GList *l;
+ GSList *notify = NULL, *l2;
+ GList **key_listeners = &controller->key_listeners;
+ gboolean is_consumed;
+
+ if (!key_listeners)
+ {
+ return FALSE;
+ }
+
+ /* set the NUMLOCK event mask bit if appropriate: see bug #143702 */
+ if (key_event->modifiers & _numlock_physical_mask)
+ key_event->modifiers |= SPI_KEYMASK_NUMLOCK;
+
+ for (l = *key_listeners; l; l = l->next)
+ {
+ DEControllerKeyListener *key_listener = l->data;
+
+ if (spi_key_event_matches_listener (key_event, key_listener, is_system_global))
+ {
+ /* we clone (don't dup) the listener, to avoid refcount inc. */
+ notify = g_slist_prepend (notify,
+ spi_key_listener_clone (key_listener));
+ }
+ }
+
+#ifdef SPI_KEYEVENT_DEBUG
+ if (!notify)
+ {
+ g_print ("no match for event\n");
+ }
+#endif
+
+ is_consumed = FALSE;
+ for (l2 = notify; l2 && !is_consumed; l2 = l2->next)
+ {
+ DEControllerKeyListener *key_listener = l2->data;
+
+ is_consumed = Accessibility_DeviceEventListener_NotifyEvent (controller, controller->registry, &key_listener->listener, key_event) &&
+ key_listener->mode->preemptive;
+
+ spi_key_listener_clone_free (key_listener);
+ }
+
+ for (; l2; l2 = l2->next)
+ {
+ DEControllerKeyListener *key_listener = l2->data;
+ spi_key_listener_clone_free (key_listener);
+ /* clone doesn't have its own ref, so don't use spi_dec_listener_free */
+ }
+
+ g_slist_free (notify);
+
+#ifdef SPI_DEBUG
+ if (is_consumed) g_message ("consumed\n");
+#endif
+ return is_consumed;
+}
+
+gboolean
+spi_clear_error_state (void)
+{
+ gboolean retval = spi_error_code != 0;
+ spi_error_code = 0;
+ return retval;
+}
+
+gboolean
+spi_controller_update_key_grabs (SpiDEController *controller,
+ Accessibility_DeviceEvent *recv)
+{
+ GList *l, *next;
+ gboolean update_failed = FALSE;
+ long keycode = 0;
+
+ g_return_val_if_fail (controller != NULL, FALSE);
+
+ /*
+ * masks known to work with default RH 7.1+:
+ * 0 (no mods), LockMask, Mod1Mask, Mod2Mask, ShiftMask,
+ * ShiftMask|LockMask, Mod1Mask|LockMask, Mod2Mask|LockMask,
+ * ShiftMask|Mod1Mask, ShiftMask|Mod2Mask, Mod1Mask|Mod2Mask,
+ * ShiftMask|LockMask|Mod1Mask, ShiftMask|LockMask|Mod2Mask,
+ *
+ * ControlMask grabs are broken, must be in use already
+ */
+ if (recv)
+ keycode = spi_dec_plat_get_keycode (controller, recv->id, NULL, TRUE, NULL);
+ for (l = controller->keygrabs_list; l; l = next)
+ {
+ gboolean do_remove;
+ gboolean re_issue_grab;
+ DEControllerGrabMask *grab_mask = l->data;
+
+ next = l->next;
+
+ re_issue_grab = recv &&
+ (recv->modifiers & grab_mask->mod_mask) &&
+ (grab_mask->key_val == keycode);
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "mask=%lx %lx (%c%c) %s\n",
+ (long int) grab_mask->key_val,
+ (long int) grab_mask->mod_mask,
+ grab_mask->pending_add ? '+' : '.',
+ grab_mask->pending_remove ? '-' : '.',
+ re_issue_grab ? "re-issue": "");
+#endif
+
+ do_remove = FALSE;
+
+ if (grab_mask->pending_add && grab_mask->pending_remove)
+ {
+ do_remove = TRUE;
+ }
+ else if (grab_mask->pending_remove)
+ {
+#ifdef SPI_DEBUG
+ fprintf (stderr, "ungrabbing, mask=%x\n", grab_mask->mod_mask);
+#endif
+ spi_dec_plat_ungrab_key (controller,
+ grab_mask->key_val,
+ grab_mask->mod_mask);
+
+ do_remove = TRUE;
+ }
+ else if (grab_mask->pending_add || re_issue_grab)
+ {
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "grab %d with mask %x\n", grab_mask->key_val, grab_mask->mod_mask);
+#endif
+ update_failed = spi_dec_plat_grab_key (controller,
+ grab_mask->key_val,
+ grab_mask->mod_mask);
+ if (update_failed) {
+ while (grab_mask->ref_count > 0) --grab_mask->ref_count;
+ do_remove = TRUE;
+ }
+ }
+
+ grab_mask->pending_add = FALSE;
+ grab_mask->pending_remove = FALSE;
+
+ if (do_remove)
+ {
+ g_assert (grab_mask->ref_count <= 0);
+
+ controller->keygrabs_list = g_list_delete_link (
+ controller->keygrabs_list, l);
+
+ spi_grab_mask_free (grab_mask);
+ }
+
+ }
+
+ return ! update_failed;
+}
+
+/*
+ * Implemented GObject::finalize
+ */
+static void
+spi_device_event_controller_object_finalize (GObject *object)
+{
+ SpiDEController *controller;
+ GObjectClass *parent_class = G_OBJECT_CLASS(spi_device_event_controller_parent_class);
+ SpiDEControllerClass *klass;
+
+ controller = SPI_DEVICE_EVENT_CONTROLLER (object);
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (controller);
+#ifdef SPI_DEBUG
+ fprintf(stderr, "spi_device_event_controller_object_finalize called\n");
+#endif
+ if (klass->plat.finalize)
+ klass->plat.finalize (controller);
+
+ parent_class->finalize (object);
+}
+
+/*
+ * DBus Accessibility::DEController::RegisterKeystrokeListener
+ * method implementation
+ */
+static DBusMessage *
+impl_register_keystroke_listener (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ 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 = 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);
+ dbus_message_iter_get_basic(&iter, &path);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &iter_array);
+ while (dbus_message_iter_get_arg_type(&iter_array) != DBUS_TYPE_INVALID)
+ {
+ Accessibility_KeyDefinition *kd = (Accessibility_KeyDefinition *)g_malloc(sizeof(Accessibility_KeyDefinition));
+ if (!spi_dbus_message_iter_get_struct(&iter_array, DBUS_TYPE_INT32, &kd->keycode, DBUS_TYPE_INT32, &kd->keysym, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_INVALID))
+ {
+ break;
+ }
+ kd->keystring = g_strdup (keystring);
+ keys = g_slist_append(keys, kd);
+ }
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &mask);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &type);
+ dbus_message_iter_next(&iter);
+ mode = (Accessibility_EventListenerMode *)g_malloc(sizeof(Accessibility_EventListenerMode));
+ if (mode)
+ {
+ spi_dbus_message_iter_get_struct(&iter, DBUS_TYPE_BOOLEAN, &mode->synchronous, DBUS_TYPE_BOOLEAN, &mode->preemptive, DBUS_TYPE_BOOLEAN, &mode->global, DBUS_TYPE_INVALID);
+ }
+#ifdef SPI_DEBUG
+ fprintf (stderr, "registering keystroke listener %s:%s with maskVal %lu\n",
+ 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);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret, DBUS_TYPE_INVALID);
+ }
+ return reply;
+}
+
+/*
+ * DBus Accessibility::DEController::RegisterDeviceEventListener
+ * method implementation
+ */
+static DBusMessage *
+impl_register_device_event_listener (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ DEControllerListener *dec_listener;
+ const char *path;
+ dbus_int32_t event_types;
+ dbus_bool_t ret;
+ DBusMessage *reply = NULL;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
+ {
+ 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 (
+ controller, (DEControllerListener *) dec_listener);
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret, DBUS_TYPE_INVALID);
+ }
+ return reply;
+}
+
+typedef struct {
+ DBusConnection *bus;
+ DEControllerListener *listener;
+} RemoveListenerClosure;
+
+static SpiReEntrantContinue
+remove_listener_cb (GList * const *list,
+ gpointer user_data)
+{
+ DEControllerListener *listener = (*list)->data;
+ RemoveListenerClosure *ctx = user_data;
+
+ 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);
+ }
+
+ return SPI_RE_ENTRANT_CONTINUE;
+}
+
+static SpiReEntrantContinue
+copy_key_listener_cb (GList * const *list,
+ gpointer user_data)
+{
+ DEControllerKeyListener *key_listener = (*list)->data;
+ RemoveListenerClosure *ctx = user_data;
+
+ 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 */
+ DEControllerKeyListener *ctx_key_listener =
+ (DEControllerKeyListener *) ctx->listener;
+ keylist_free (ctx_key_listener->keys);
+ ctx_key_listener->keys = keylist_clone(key_listener->keys);
+ }
+
+ return SPI_RE_ENTRANT_CONTINUE;
+}
+
+static void
+spi_controller_deregister_device_listener (SpiDEController *controller,
+ DEControllerListener *listener)
+{
+ RemoveListenerClosure ctx;
+
+ 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
+spi_deregister_controller_key_listener (SpiDEController *controller,
+ DEControllerKeyListener *key_listener)
+{
+ RemoveListenerClosure ctx;
+
+ 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
+ * method implementation
+ */
+static DBusMessage *
+impl_deregister_keystroke_listener (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ 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 = NULL;
+
+ dbus_message_iter_init(message, &iter);
+ 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);
+ while (dbus_message_iter_get_arg_type(&iter_array) != DBUS_TYPE_INVALID)
+ {
+ Accessibility_KeyDefinition *kd = (Accessibility_KeyDefinition *)g_malloc(sizeof(Accessibility_KeyDefinition));
+ char *keystring;
+
+ if (!spi_dbus_message_iter_get_struct(&iter_array, DBUS_TYPE_INT32, &kd->keycode, DBUS_TYPE_INT32, &kd->keysym, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_INVALID))
+ {
+ break;
+ }
+ kd->keystring = g_strdup (keystring);
+ keys = g_slist_append(keys, kd);
+ }
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &mask);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_get_basic(&iter, &type);
+ dbus_message_iter_next(&iter);
+ key_listener = spi_dec_key_listener_new (dbus_message_get_sender(message), path, keys, mask, type, NULL);
+#ifdef SPI_DEREGISTER_DEBUG
+ fprintf (stderr, "deregistering keystroke listener %p with maskVal %lu\n",
+ (void *) l, (unsigned long) mask->value);
+#endif
+
+ spi_deregister_controller_key_listener (controller, key_listener);
+
+ spi_dec_listener_free ((DEControllerListener *) key_listener);
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+/*
+ * DBus Accessibility::DEController::DeregisterDeviceEventListener
+ * method implementation
+ */
+static DBusMessage *
+impl_deregister_device_event_listener (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ DEControllerListener *listener;
+ const char *path;
+ dbus_int32_t event_types;
+ DBusMessage *reply = NULL;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
+ {
+ return invalid_arguments_error (message);
+ }
+ listener = spi_dec_listener_new (dbus_message_get_sender(message), path, event_types);
+ spi_controller_deregister_device_listener (
+ controller, listener);
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+static DBusMessage *
+impl_get_keystroke_listeners (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ 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);
+ 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
+get_modifier_state (SpiDEController *controller)
+{
+ return mouse_mask_state;
+}
+
+gboolean
+spi_dec_synth_keysym (SpiDEController *controller, long keysym)
+{
+ long key_synth_code;
+ unsigned int modifiers, synth_mods, lock_mods;
+
+ key_synth_code = spi_dec_plat_get_keycode (controller, keysym, NULL, TRUE, &synth_mods);
+
+ if ((key_synth_code == 0) || (synth_mods == 0xFF)) return FALSE;
+
+ /* TODO: set the modifiers accordingly! */
+ modifiers = get_modifier_state (controller);
+ /* side-effect; we may unset mousebutton modifiers here! */
+
+ lock_mods = 0;
+ if (synth_mods != modifiers) {
+ lock_mods = synth_mods & ~modifiers;
+ spi_dec_plat_lock_modifiers (controller, lock_mods);
+ }
+ spi_dec_plat_synth_keycode_press (controller, key_synth_code);
+ spi_dec_plat_synth_keycode_release (controller, key_synth_code);
+
+ if (synth_mods != modifiers)
+ spi_dec_plat_unlock_modifiers (controller, lock_mods);
+ return TRUE;
+}
+
+
+
+/*
+ * DBus Accessibility::DEController::RegisterKeystrokeListener
+ * method implementation
+ */
+static DBusMessage *
+impl_generate_keyboard_event (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ dbus_int32_t keycode;
+ char *keystring;
+ dbus_uint32_t synth_type;
+ DBusMessage *reply = NULL;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &keycode, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_UINT32, &synth_type, DBUS_TYPE_INVALID))
+ {
+ return invalid_arguments_error (message);
+ }
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "synthesizing keystroke %ld, type %d\n",
+ (long) keycode, (int) synth_type);
+#endif
+ /* TODO: hide/wrap/remove X dependency */
+
+ /*
+ * 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:
+ spi_dec_plat_synth_keycode_press (controller, keycode);
+ break;
+ case Accessibility_KEY_PRESSRELEASE:
+ spi_dec_plat_synth_keycode_press (controller, keycode);
+ case Accessibility_KEY_RELEASE:
+ spi_dec_plat_synth_keycode_release (controller, keycode);
+ break;
+ case Accessibility_KEY_SYM:
+#ifdef SPI_XKB_DEBUG
+ fprintf (stderr, "KeySym synthesis\n");
+#endif
+ /*
+ * note: we are using long for 'keycode'
+ * in our arg list; it can contain either
+ * a keycode or a keysym.
+ */
+ spi_dec_synth_keysym (controller, (KeySym) keycode);
+ break;
+ case Accessibility_KEY_STRING:
+ if (!spi_dec_plat_synth_keystring (controller, synth_type, keycode, keystring))
+ fprintf (stderr, "Keystring synthesis failure, string=%s\n",
+ keystring);
+ break;
+ }
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+/* Accessibility::DEController::GenerateMouseEvent */
+static DBusMessage *
+impl_generate_mouse_event (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ dbus_int32_t x;
+ dbus_int32_t y;
+ char *eventName;
+ DBusMessage *reply = NULL;
+
+ if (!dbus_message_get_args(message, NULL, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32, &y, DBUS_TYPE_STRING, &eventName, DBUS_TYPE_INVALID))
+ {
+ return invalid_arguments_error (message);
+ }
+
+#ifdef SPI_DEBUG
+ fprintf (stderr, "generating mouse %s event at %ld, %ld\n",
+ eventName, (long int) x, (long int) y);
+#endif
+ spi_dec_plat_generate_mouse_event (saved_controller, x, y, eventName);
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+/* Accessibility::DEController::NotifyListenersSync */
+static DBusMessage *
+impl_notify_listeners_sync (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ Accessibility_DeviceEvent event;
+ dbus_bool_t ret;
+ DBusMessage *reply = NULL;
+
+ if (!spi_dbus_demarshal_deviceEvent(message, &event))
+ {
+ return invalid_arguments_error (message);
+ }
+#ifdef SPI_DEBUG
+ g_print ("notifylistening listeners synchronously: controller %p, event id %d\n",
+ controller, (int) event.id);
+#endif
+ ret = spi_controller_notify_keylisteners (controller,
+ (Accessibility_DeviceEvent *)
+ &event, FALSE) ?
+ TRUE : FALSE;
+ reply = dbus_message_new_method_return (message);
+ if (reply)
+ {
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &ret, DBUS_TYPE_INVALID);
+ }
+ return reply;
+}
+
+static DBusMessage *
+impl_notify_listeners_async (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ Accessibility_DeviceEvent event;
+ DBusMessage *reply = NULL;
+
+ if (!spi_dbus_demarshal_deviceEvent(message, &event))
+ {
+ return invalid_arguments_error (message);
+ }
+#ifdef SPI_DEBUG
+ g_print ("notifylistening listeners asynchronously: controller %p, event id %d\n",
+ controller, (int) event.id);
+#endif
+ spi_controller_notify_keylisteners (controller, (Accessibility_DeviceEvent *)
+ &event, FALSE);
+ reply = dbus_message_new_method_return (message);
+ return reply;
+}
+
+static void
+spi_device_event_controller_class_init (SpiDEControllerClass *klass)
+{
+ 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;
+
+#ifdef HAVE_X11
+ if (g_getenv ("DISPLAY"))
+ spi_dec_setup_x11 (klass);
+ else
+#endif
+ g_type_class_add_private (object_class, sizeof (long)); /* dummy */
+}
+
+static void
+spi_device_event_controller_init (SpiDEController *device_event_controller)
+{
+ SpiDEControllerClass *klass;
+ klass = SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS (device_event_controller);
+
+ /* TODO: shouldn't be gpointer below */
+ device_event_controller->priv = G_TYPE_INSTANCE_GET_PRIVATE (device_event_controller,
+ SPI_DEVICE_EVENT_CONTROLLER_TYPE,
+ gpointer);
+ device_event_controller->message_queue = g_queue_new ();
+ saved_controller = device_event_controller;
+
+ if (klass->plat.init)
+ klass->plat.init (device_event_controller);
+}
+
+
+/*---------------------------------------------------------------------------*/
+
+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)
+{
+ GString *output;
+ gchar *final;
+
+ 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);
+ 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);
+ g_source_set_name_by_id (saved_controller->message_queue_idle, "[at-spi2-core] message_queue_dispatch");
+ }
+ 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);
+
+ return dec;
+}
+
+void
+spi_device_event_controller_start_poll_mouse (SpiRegistry *registry)
+{
+ if (!have_mouse_event_listener)
+ {
+ have_mouse_event_listener = TRUE;
+ if (!have_mouse_listener) {
+ guint id;
+ id = g_timeout_add (100, spi_dec_poll_mouse_idle, registry->dec);
+ g_source_set_name_by_id (id, "[at-spi2-core] spi_dec_poll_mouse_idle");
+ }
+ }
+}
+
+void
+spi_device_event_controller_stop_poll_mouse (void)
+{
+ have_mouse_event_listener = FALSE;
+}
diff --git a/registryd/deviceeventcontroller.h b/registryd/deviceeventcontroller.h
new file mode 100644
index 0000000..0c6eee4
--- /dev/null
+++ b/registryd/deviceeventcontroller.h
@@ -0,0 +1,179 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_DEVICE_EVENT_CONTROLLER_H_
+#define SPI_DEVICE_EVENT_CONTROLLER_H_
+
+#ifdef HAVE_X11
+#include <X11/Xlib.h>
+#endif
+#include <dbus/dbus.h>
+
+typedef struct _SpiDEController SpiDEController;
+
+#include "registry.h"
+#include "de-types.h"
+
+G_BEGIN_DECLS
+
+#define SPI_DEVICE_EVENT_CONTROLLER_TYPE (spi_device_event_controller_get_type ())
+#define SPI_DEVICE_EVENT_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SPI_DEVICE_EVENT_CONTROLLER_TYPE, SpiDEController))
+#define SPI_DEVICE_EVENT_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SPI_DEVICE_EVENT_CONTROLLER_TYPE, SpiDEControllerClass))
+#define SPI_IS_DEVICE_EVENT_CONTROLLER(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), SPI_DEVICE_EVENT_CONTROLLER_TYPE))
+#define SPI_IS_DEVICE_EVENT_CONTROLLER_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SPI_DEVICE_EVENT_CONTROLLER_TYPE))
+#define SPI_DEVICE_EVENT_CONTROLLER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SPI_DEVICE_EVENT_CONTROLLER_TYPE, SpiDEControllerClass))
+
+struct _SpiDEController {
+ GObject parent;
+ DBusConnection *bus;
+ SpiRegistry *registry;
+ GList *key_listeners;
+ GList *mouse_listeners;
+ GList *keygrabs_list;
+ GQueue *message_queue;
+ guint message_queue_idle;
+ gpointer priv;
+};
+
+typedef enum {
+ SPI_DEVICE_TYPE_KBD,
+ SPI_DEVICE_TYPE_MOUSE,
+ SPI_DEVICE_TYPE_LAST_DEFINED
+} SpiDeviceTypeCategory;
+
+typedef struct {
+ char *bus_name;
+ char *path;
+ SpiDeviceTypeCategory type;
+ gulong types;
+} DEControllerListener;
+
+typedef struct {
+ DEControllerListener listener;
+
+ GSList *keys;
+ Accessibility_ControllerEventMask mask;
+ Accessibility_EventListenerMode *mode;
+} DEControllerKeyListener;
+
+typedef struct
+{
+ gint (*get_keycode) (SpiDEController *controller,
+ gint keysym,
+ gchar *key_str,
+ gboolean fix,
+ guint *modmask);
+
+ guint (*mouse_check) (SpiDEController *controller,
+ gint *x,
+ gint *y,
+ gboolean *moved);
+
+ gboolean (*register_global_keygrabs) (SpiDEController *controller,
+ DEControllerKeyListener *key_listener);
+
+ void (*deregister_global_keygrabs) (SpiDEController *controller,
+ DEControllerKeyListener *key_listener);
+
+ gboolean (*synth_keycode_press) (SpiDEController *controller,
+ guint keycode);
+
+ gboolean (*synth_keycode_release) (SpiDEController *controller,
+ guint keycode);
+
+ gboolean (*lock_modifiers) (SpiDEController *controller,
+ unsigned modifiers);
+
+ gboolean (*unlock_modifiers) (SpiDEController *controller,
+ unsigned modifiers);
+
+ gboolean (*synth_keystring) (SpiDEController *controller,
+ guint synth_type,
+ gint keycode,
+ const char *keystring);
+
+ gboolean (*grab_key) (SpiDEController *controller,
+ guint key_val,
+ Accessibility_ControllerEventMask mod_mask);
+
+ void (*ungrab_key) (SpiDEController *controller,
+ guint key_val,
+ Accessibility_ControllerEventMask mod_mask);
+
+ void (*emit_modifier_event) (SpiDEController *controller,
+ guint prev_mask,
+ guint current_mask);
+
+ void (*generate_mouse_event) (SpiDEController *controller,
+ gint x,
+ gint y,
+ const char *eventName);
+
+ void (*init) (SpiDEController *controller);
+ void (*finalize) (SpiDEController *controller);
+} SpiDEControllerPlat;
+
+typedef struct {
+ GObjectClass parent_class;
+ SpiDEControllerPlat plat;
+} SpiDEControllerClass;
+
+GType spi_device_event_controller_get_type (void);
+SpiDEController *spi_device_event_controller_new (SpiRegistry *registry,
+ DBusConnection *bus);
+
+gboolean spi_clear_error_state (void);
+
+void spi_device_event_controller_start_poll_mouse (SpiRegistry *registry);
+void spi_device_event_controller_stop_poll_mouse (void);
+
+void spi_remove_device_listeners (SpiDEController *controller, const char *bus_name);
+
+SpiDEController *spi_registry_dec_new (SpiRegistry *reg, DBusConnection *bus);
+
+gboolean
+spi_controller_notify_mouselisteners (SpiDEController *controller,
+ const Accessibility_DeviceEvent *event);
+
+gboolean
+spi_controller_notify_keylisteners (SpiDEController *controller,
+ Accessibility_DeviceEvent *key_event,
+ dbus_bool_t is_system_global);
+
+gboolean spi_controller_update_key_grabs (SpiDEController *controller,
+ Accessibility_DeviceEvent *recv);
+
+gboolean spi_dec_synth_keysym (SpiDEController *controller, long keysym);
+
+void spi_dec_dbus_emit(SpiDEController *controller, const char *interface, const char *name, const char *minor, int a1, int a2);
+
+#ifdef HAVE_X11
+void spi_dec_setup_x11 (SpiDEControllerClass *klass);
+#endif
+
+long ucs2keysym (long ucs);
+long keysym2ucs(long keysym);
+
+G_END_DECLS
+
+#endif /* DEVICEEVENTCONTROLLER_H_ */
diff --git a/registryd/display.c b/registryd/display.c
new file mode 100644
index 0000000..2ba781c
--- /dev/null
+++ b/registryd/display.c
@@ -0,0 +1,90 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+#include <X11/Xlib.h>
+#include <X11/Xutil.h>
+#include <X11/Xos.h>
+#include <X11/Xatom.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "display.h"
+
+static Display *default_display = NULL;
+
+Display *spi_set_display (const char *display_name)
+{
+ /*
+ * TODO - Should we ever do anything different might need to
+ * close previous display.
+ */
+ default_display = XOpenDisplay (display_name);
+ if (!default_display)
+ {
+ g_warning ("AT-SPI: Cannot open default display");
+ exit (1);
+ }
+ return default_display;
+}
+
+Display *spi_get_display ()
+{
+ if (!default_display)
+ spi_set_display (NULL);
+
+ return default_display;
+}
+
+Window spi_get_root_window ()
+{
+ if (!default_display)
+ spi_set_display (NULL);
+
+ return DefaultRootWindow (default_display);
+}
+
+static int (*old_x_error_handler) (Display *, XErrorEvent *);
+static int x_error_code;
+
+static int spi_x_error_handler (Display *display, XErrorEvent *error)
+{
+ if (error->error_code)
+ x_error_code = error->error_code;
+ else
+ x_error_code = 0;
+
+ return 0;
+}
+
+void spi_x_error_trap (void)
+{
+ old_x_error_handler = XSetErrorHandler (spi_x_error_handler);
+}
+
+int spi_x_error_release (void)
+{
+ XSetErrorHandler (old_x_error_handler);
+ return x_error_code;
+}
diff --git a/registryd/display.h b/registryd/display.h
new file mode 100644
index 0000000..2238a55
--- /dev/null
+++ b/registryd/display.h
@@ -0,0 +1,36 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_DISPLAY_H_
+#define SPI_DISPLAY_H_
+
+#include <X11/Xlib.h>
+
+Display *spi_set_display (const char *display_name);
+Display *spi_get_display ();
+
+Window spi_get_root_window ();
+
+void spi_x_error_trap (void);
+int spi_x_error_release (void);
+
+#endif /* SPI_DISPLAY_H_ */
diff --git a/registryd/event-source.c b/registryd/event-source.c
new file mode 100644
index 0000000..9ad3ec5
--- /dev/null
+++ b/registryd/event-source.c
@@ -0,0 +1,175 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+
+#include "event-source.h"
+
+typedef struct _DisplaySource
+{
+ GSource source;
+
+ Display *display;
+ GPollFD event_poll_fd;
+} DisplaySource;
+
+/*---------------------------------------------------------------------------*/
+
+static void (*_spi_default_filter) (XEvent*, void*) = NULL;
+static void* _spi_default_filter_data = NULL;
+
+/*---------------------------------------------------------------------------*/
+
+static gboolean
+event_prepare (GSource *source, gint *timeout)
+{
+ Display *display = ((DisplaySource *)source)->display;
+ gboolean retval;
+
+ *timeout = -1;
+ retval = XPending (display);
+
+ return retval;
+}
+
+static gboolean
+event_check (GSource *source)
+{
+ DisplaySource *display_source = (DisplaySource*)source;
+ gboolean retval;
+
+ if (display_source->event_poll_fd.revents & G_IO_IN)
+ retval = XPending (display_source->display);
+ else
+ retval = FALSE;
+
+ return retval;
+}
+
+static gboolean
+event_dispatch (GSource *source, GSourceFunc callback, gpointer user_data)
+{
+ Display *display = ((DisplaySource*)source)->display;
+ XEvent xevent;
+
+ /* TODO - Should this be "if (XPending (display))"?
+ * The effect of this might be to run other main loop functions
+ * before dispatching the next XEvent.
+ */
+ while (XPending (display))
+ {
+ XNextEvent (display, &xevent);
+
+ switch (xevent.type)
+ {
+ case KeyPress:
+ case KeyRelease:
+ break;
+ default:
+ if (XFilterEvent (&xevent, None))
+ continue;
+ }
+
+ if (_spi_default_filter)
+ {
+ _spi_default_filter (&xevent, _spi_default_filter_data);
+ }
+ }
+
+ return TRUE;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static GSourceFuncs event_funcs = {
+ event_prepare,
+ event_check,
+ event_dispatch,
+ NULL
+};
+
+static GSource *
+display_source_new (Display *display)
+{
+ GSource *source = g_source_new (&event_funcs, sizeof (DisplaySource));
+ DisplaySource *display_source = (DisplaySource *) source;
+ g_source_set_name (source, "[at-spi2-core] display_source_funcs");
+
+ display_source->display = display;
+
+ return source;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static DisplaySource *spi_display_source = NULL;
+
+void
+spi_events_init (Display *display)
+{
+ GSource *source;
+
+ int connection_number = ConnectionNumber (display);
+
+ source = display_source_new (display);
+ spi_display_source = (DisplaySource*) source;
+
+ g_source_set_priority (source, G_PRIORITY_DEFAULT);
+
+ spi_display_source->event_poll_fd.fd = connection_number;
+ spi_display_source->event_poll_fd.events = G_IO_IN;
+
+ g_source_add_poll (source, &spi_display_source->event_poll_fd);
+ g_source_set_can_recurse (source, TRUE);
+ g_source_attach (source, NULL);
+}
+
+void
+spi_events_uninit ()
+{
+ if (spi_display_source)
+ {
+ g_source_destroy ((GSource *) spi_display_source);
+ g_source_unref ((GSource *) spi_display_source);
+ spi_display_source = NULL;
+ }
+}
+
+void
+spi_set_events (long event_mask)
+{
+ long xevent_mask = StructureNotifyMask | PropertyChangeMask;
+ xevent_mask |= event_mask;
+
+ XSelectInput (spi_display_source->display,
+ DefaultRootWindow (spi_display_source->display),
+ xevent_mask);
+}
+
+void
+spi_set_filter (void (*filter) (XEvent*, void*), void* data)
+{
+ _spi_default_filter = filter;
+ _spi_default_filter_data = data;
+}
+
+/*END------------------------------------------------------------------------*/
diff --git a/registryd/event-source.h b/registryd/event-source.h
new file mode 100644
index 0000000..55ab663
--- /dev/null
+++ b/registryd/event-source.h
@@ -0,0 +1,33 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2009 Nokia.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_EVENT_SOURCE_H_
+#define SPI_EVENT_SOURCE_H_
+
+#include <X11/Xlib.h>
+
+void spi_events_init (Display *display);
+void spi_events_uninit ();
+void spi_set_events (long event_mask);
+void spi_set_filter (void (*filter) (XEvent*, void*), void* data);
+
+#endif /* SPI_EVENT_SOURCE_H_ */
diff --git a/registryd/introspection.c b/registryd/introspection.c
new file mode 100644
index 0000000..84ce759
--- /dev/null
+++ b/registryd/introspection.c
@@ -0,0 +1,871 @@
+
+/*
+ * This file has been auto-generated from the introspection data available
+ * in the at-spi2-core repository. The D-Bus procol is defined in this
+ * repository, which can be found at:
+ *
+ * http://download.gnome.org/sources/at-spi2-core/0.1/
+ *
+ * DO NOT EDIT.
+ */
+
+
+const char *spi_org_a11y_atspi_Accessible =
+"<interface name=\"org.a11y.atspi.Accessible\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"name\" type=\"s\" />"
+""
+" <property access=\"read\" name=\"description\" type=\"s\" />"
+""
+" <property access=\"read\" name=\"parent\" type=\"(so)\">"
+" "
+" </property>"
+""
+" <property access=\"read\" name=\"childCount\" type=\"i\" />"
+""
+" <method name=\"GetChildAtIndex\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetChildren\">"
+" <arg direction=\"out\" type=\"a(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetIndexInParent\">"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetRelationSet\">"
+" <arg direction=\"out\" type=\"a(ua(so))\" />"
+" "
+" </method>"
+""
+" <method name=\"GetRole\">"
+" <arg direction=\"out\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GetRoleName\">"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetLocalizedRoleName\">"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetState\">"
+" <arg direction=\"out\" type=\"au\" />"
+" "
+" </method>"
+""
+" <method name=\"GetAttributes\">"
+" <arg direction=\"out\" type=\"a{ss}\" />"
+" "
+" </method>"
+""
+" <method name=\"GetApplication\">"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Action =
+"<interface name=\"org.a11y.atspi.Action\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"nActions\" type=\"i\" />"
+""
+" <method name=\"GetDescription\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetName\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetKeyBinding\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetActions\">"
+" <arg direction=\"out\" name=\"index\" type=\"a(sss)\" />"
+" "
+" </method>"
+""
+" <method name=\"DoAction\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Application =
+"<interface name=\"org.a11y.atspi.Application\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"toolkitName\" type=\"s\" />"
+""
+" <property access=\"read\" name=\"version\" type=\"s\" />"
+""
+" <property access=\"read\" name=\"id\" type=\"i\" />"
+""
+" <method name=\"GetLocale\">"
+" <arg direction=\"in\" name=\"lctype\" type=\"u\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"RegisterEventListener\">"
+" <arg direction=\"in\" name=\"event\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"DeregisterEventListener\">"
+" <arg direction=\"in\" name=\"event\" type=\"s\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Collection =
+"<interface name=\"org.a11y.atspi.Collection\" version=\"0.1.7\">"
+""
+" <method name=\"GetMatches\">"
+" <arg direction=\"in\" name=\"rule\" type=\"(auuasuauusub)\" />"
+" "
+" <arg direction=\"in\" name=\"sortby\" type=\"u\" />"
+" <arg direction=\"in\" name=\"count\" type=\"i\" />"
+" <arg direction=\"in\" name=\"traverse\" type=\"b\" />"
+" <arg direction=\"out\" type=\"a(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetMatchesTo\">"
+" <arg direction=\"in\" name=\"current_object\" type=\"o\" />"
+" "
+" <arg direction=\"in\" name=\"rule\" type=\"(auuasuauusub)\" />"
+" "
+" <arg direction=\"in\" name=\"sortby\" type=\"u\" />"
+" <arg direction=\"in\" name=\"tree\" type=\"u\" />"
+" <arg direction=\"in\" name=\"recurse\" type=\"b\" />"
+" <arg direction=\"in\" name=\"count\" type=\"i\" />"
+" <arg direction=\"in\" name=\"traverse\" type=\"b\" />"
+" <arg direction=\"out\" type=\"a(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetMatchesFrom\">"
+" <arg direction=\"in\" name=\"current_object\" type=\"o\" />"
+" "
+" <arg direction=\"in\" name=\"rule\" type=\"(auuasuauusub)\" />"
+" "
+" <arg direction=\"in\" name=\"sortby\" type=\"u\" />"
+" <arg direction=\"in\" name=\"tree\" type=\"u\" />"
+" <arg direction=\"in\" name=\"count\" type=\"i\" />"
+" <arg direction=\"in\" name=\"traverse\" type=\"b\" />"
+" <arg direction=\"out\" type=\"a(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetActiveDescendant\">"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Component =
+"<interface name=\"org.a11y.atspi.Component\" version=\"0.1.7\">"
+""
+" <method name=\"Contains\">"
+" <arg direction=\"in\" name=\"x\" type=\"i\" />"
+" <arg direction=\"in\" name=\"y\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coord_type\" type=\"u\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GetAccessibleAtPoint\">"
+" <arg direction=\"in\" name=\"x\" type=\"i\" />"
+" <arg direction=\"in\" name=\"y\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coord_type\" type=\"u\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetExtents\">"
+" <arg direction=\"in\" name=\"coord_type\" type=\"u\" />"
+" <arg direction=\"out\" type=\"(iiii)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetPosition\">"
+" <arg direction=\"in\" name=\"coord_type\" type=\"u\" />"
+" <arg direction=\"out\" name=\"x\" type=\"i\" />"
+" <arg direction=\"out\" name=\"y\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetSize\">"
+" <arg direction=\"out\" name=\"width\" type=\"i\" />"
+" <arg direction=\"out\" name=\"height\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetLayer\">"
+" <arg direction=\"out\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GetMDIZOrder\">"
+" <arg direction=\"out\" type=\"n\" />"
+" </method>"
+""
+" <method name=\"GrabFocus\">"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"ClearHighlight\">"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GrabHighlight\">"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GetAlpha\">"
+" <arg direction=\"out\" type=\"d\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Document =
+"<interface name=\"org.a11y.atspi.Document\" version=\"0.1.7\">"
+""
+" <method name=\"GetLocale\">"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetAttributeValue\">"
+" <arg direction=\"in\" name=\"attributename\" type=\"s\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetAttributes\">"
+" <arg direction=\"out\" type=\"{ss}\" />"
+" "
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Hypertext =
+"<interface name=\"org.a11y.atspi.Hypertext\" version=\"0.1.7\">"
+""
+" <method name=\"GetNLinks\">"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetLink\">"
+" <arg direction=\"in\" name=\"linkIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetLinkIndex\">"
+" <arg direction=\"in\" name=\"characterIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Hyperlink =
+"<interface name=\"org.a11y.atspi.Hyperlink\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"nAnchors\" type=\"n\" />"
+""
+" <property access=\"read\" name=\"startIndex\" type=\"i\" />"
+""
+" <property access=\"read\" name=\"endIndex\" type=\"i\" />"
+""
+" <method name=\"GetObject\">"
+" <arg direction=\"in\" name=\"i\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetURI\">"
+" <arg direction=\"in\" name=\"i\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"IsValid\">"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Image =
+"<interface name=\"org.a11y.atspi.Image\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"imageDescription\" type=\"s\" />"
+""
+" <property access=\"read\" name=\"imageLocale\" type=\"s\" />"
+""
+" <method name=\"GetImageExtents\">"
+" <arg direction=\"in\" name=\"coordType\" type=\"u\" />"
+" <arg direction=\"out\" type=\"(iiii)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetImagePosition\">"
+" <arg direction=\"out\" name=\"x\" type=\"i\" />"
+" <arg direction=\"out\" name=\"y\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coordType\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GetImageSize\">"
+" <arg direction=\"out\" name=\"width\" type=\"i\" />"
+" <arg direction=\"out\" name=\"height\" type=\"i\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Selection =
+"<interface name=\"org.a11y.atspi.Selection\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"nSelectedChildren\" type=\"i\" />"
+""
+" <method name=\"GetSelectedChild\">"
+" <arg direction=\"in\" name=\"selectedChildIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"SelectChild\">"
+" <arg direction=\"in\" name=\"childIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"DeselectSelectedChild\">"
+" <arg direction=\"in\" name=\"selectedChildIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"IsChildSelected\">"
+" <arg direction=\"in\" name=\"childIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"SelectAll\">"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"ClearSelection\">"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"deSelectChild\">"
+" <arg direction=\"in\" name=\"childIndex\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Table =
+"<interface name=\"org.a11y.atspi.Table\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"nRows\" type=\"i\" />"
+""
+" <property access=\"read\" name=\"nColumns\" type=\"i\" />"
+""
+" <property access=\"read\" name=\"caption\" type=\"(so)\">"
+" "
+" </property>"
+""
+" <property access=\"read\" name=\"summary\" type=\"(so)\">"
+" "
+" </property>"
+""
+" <property access=\"read\" name=\"nSelectedRows\" type=\"i\" />"
+""
+" <property access=\"read\" name=\"nSelectedColumns\" type=\"i\" />"
+""
+" <method name=\"GetAccessibleAt\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetIndexAt\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetRowAtIndex\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetColumnAtIndex\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetRowDescription\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetColumnDescription\">"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"GetRowExtentAt\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetColumnExtentAt\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetRowHeader\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetColumnHeader\">"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"(so)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetSelectedRows\">"
+" <arg direction=\"out\" type=\"ai\" />"
+" "
+" </method>"
+""
+" <method name=\"GetSelectedColumns\">"
+" <arg direction=\"out\" type=\"ai\" />"
+" "
+" </method>"
+""
+" <method name=\"IsRowSelected\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"IsColumnSelected\">"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"IsSelected\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"AddRowSelection\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"AddColumnSelection\">"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"RemoveRowSelection\">"
+" <arg direction=\"in\" name=\"row\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"RemoveColumnSelection\">"
+" <arg direction=\"in\" name=\"column\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GetRowColumnExtentsAtIndex\">"
+" <arg direction=\"in\" name=\"index\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" <arg direction=\"out\" name=\"row\" type=\"i\" />"
+" <arg direction=\"out\" name=\"col\" type=\"i\" />"
+" <arg direction=\"out\" name=\"row_extents\" type=\"i\" />"
+" <arg direction=\"out\" name=\"col_extents\" type=\"i\" />"
+" <arg direction=\"out\" name=\"is_selected\" type=\"b\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Text =
+"<interface name=\"org.a11y.atspi.Text\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"characterCount\" type=\"i\" />"
+""
+" <property access=\"read\" name=\"caretOffset\" type=\"i\" />"
+""
+" <method name=\"GetText\">"
+" <arg direction=\"in\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endOffset\" type=\"i\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"SetCaretOffset\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GetTextBeforeOffset\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"type\" type=\"u\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetTextAtOffset\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"type\" type=\"u\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetTextAfterOffset\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"type\" type=\"u\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetCharacterAtOffset\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetAttributeValue\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"attributeName\" type=\"s\" />"
+" <arg direction=\"out\" type=\"s\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"defined\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GetAttributes\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"out\" type=\"a{ss}\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" "
+" </method>"
+""
+" <method name=\"GetDefaultAttributes\">"
+" <arg direction=\"out\" type=\"a{ss}\" />"
+" "
+" </method>"
+""
+" <method name=\"GetCharacterExtents\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"x\" type=\"i\" />"
+" <arg direction=\"out\" name=\"y\" type=\"i\" />"
+" <arg direction=\"out\" name=\"width\" type=\"i\" />"
+" <arg direction=\"out\" name=\"height\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coordType\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GetOffsetAtPoint\">"
+" <arg direction=\"in\" name=\"x\" type=\"i\" />"
+" <arg direction=\"in\" name=\"y\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coordType\" type=\"u\" />"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetNSelections\">"
+" <arg direction=\"out\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"GetSelection\">"
+" <arg direction=\"in\" name=\"selectionNum\" type=\"i\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"AddSelection\">"
+" <arg direction=\"in\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endOffset\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"RemoveSelection\">"
+" <arg direction=\"in\" name=\"selectionNum\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"SetSelection\">"
+" <arg direction=\"in\" name=\"selectionNum\" type=\"i\" />"
+" <arg direction=\"in\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endOffset\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"GetRangeExtents\">"
+" <arg direction=\"in\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"x\" type=\"i\" />"
+" <arg direction=\"out\" name=\"y\" type=\"i\" />"
+" <arg direction=\"out\" name=\"width\" type=\"i\" />"
+" <arg direction=\"out\" name=\"height\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coordType\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GetBoundedRanges\">"
+" <arg direction=\"in\" name=\"x\" type=\"i\" />"
+" <arg direction=\"in\" name=\"y\" type=\"i\" />"
+" <arg direction=\"in\" name=\"width\" type=\"i\" />"
+" <arg direction=\"in\" name=\"height\" type=\"i\" />"
+" <arg direction=\"in\" name=\"coordType\" type=\"u\" />"
+" <arg direction=\"in\" name=\"xClipType\" type=\"u\" />"
+" <arg direction=\"in\" name=\"yClipType\" type=\"u\" />"
+" <arg direction=\"out\" type=\"a(iisv)\" />"
+" "
+" </method>"
+""
+" <method name=\"GetAttributeRun\">"
+" <arg direction=\"in\" name=\"offset\" type=\"i\" />"
+" <arg direction=\"in\" name=\"includeDefaults\" type=\"b\" />"
+" <arg direction=\"out\" type=\"a{ss}\" />"
+" <arg direction=\"out\" name=\"startOffset\" type=\"i\" />"
+" <arg direction=\"out\" name=\"endOffset\" type=\"i\" />"
+" "
+" </method>"
+""
+" <method name=\"GetDefaultAttributeSet\">"
+" <arg direction=\"out\" type=\"as\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_EditableText =
+"<interface name=\"org.a11y.atspi.EditableText\" version=\"0.1.7\">"
+""
+" <method name=\"SetTextContents\">"
+" <arg direction=\"in\" name=\"newContents\" type=\"s\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"InsertText\">"
+" <arg direction=\"in\" name=\"position\" type=\"i\" />"
+" <arg direction=\"in\" name=\"text\" type=\"s\" />"
+" <arg direction=\"in\" name=\"length\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"CopyText\">"
+" <arg direction=\"in\" name=\"startPos\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endPos\" type=\"i\" />"
+" </method>"
+""
+" <method name=\"CutText\">"
+" <arg direction=\"in\" name=\"startPos\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endPos\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"DeleteText\">"
+" <arg direction=\"in\" name=\"startPos\" type=\"i\" />"
+" <arg direction=\"in\" name=\"endPos\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"PasteText\">"
+" <arg direction=\"in\" name=\"position\" type=\"i\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Cache =
+"<interface name=\"org.a11y.atspi.Cache\" version=\"0.1.7\">"
+""
+" <method name=\"GetItems\">"
+" <arg direction=\"out\" name=\"nodes\" type=\"a((so)(so)a(so)assusau)\" />"
+" "
+" </method>"
+""
+" <signal name=\"AddAccessible\">"
+" <arg name=\"nodeAdded\" type=\"((so)(so)a(so)assusau)\" />"
+" "
+" </signal>"
+""
+" <signal name=\"RemoveAccessible\">"
+" <arg name=\"nodeRemoved\" type=\"(so)\" />"
+" "
+" </signal>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Value =
+"<interface name=\"org.a11y.atspi.Value\" version=\"0.1.7\">"
+""
+" <property access=\"read\" name=\"minimumValue\" type=\"d\" />"
+""
+" <property access=\"read\" name=\"maximumValue\" type=\"d\" />"
+""
+" <property access=\"read\" name=\"minimumIncrement\" type=\"d\" />"
+""
+" <property access=\"readwrite\" name=\"currentValue\" type=\"d\" />"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_Registry =
+"<interface name=\"org.a11y.atspi.Registry\" version=\"0.1.7\">"
+""
+" <method name=\"RegisterEvent\">"
+" <arg direction=\"in\" name=\"event\" type=\"s\">"
+" </arg>"
+" </method>"
+""
+" <method name=\"DeregisterEvent\">"
+" <arg direction=\"in\" name=\"event\" type=\"s\">"
+" </arg>"
+" </method>"
+""
+" <method name=\"GetRegisteredEvents\">"
+" <arg direction=\"out\" name=\"events\" type=\"a(ss)\">"
+" </arg>"
+" </method>"
+""
+" <signal name=\"EventListenerRegistered\">"
+" <arg direction=\"out\" name=\"bus\" type=\"s\" />"
+" <arg direction=\"out\" name=\"path\" type=\"s\" />"
+" </signal>"
+""
+" <signal name=\"EventListenerDeregistered\">"
+" <arg direction=\"out\" name=\"bus\" type=\"s\" />"
+" <arg direction=\"out\" name=\"path\" type=\"s\" />"
+" </signal>"
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_DeviceEventController =
+"<interface name=\"org.a11y.atspi.DeviceEventController\" version=\"0.1.7\">"
+""
+" <method name=\"RegisterKeystrokeListener\">"
+" <arg direction=\"in\" name=\"listener\" type=\"o\" />"
+" <arg direction=\"in\" name=\"keys\" type=\"a(iisi)\">"
+" "
+" </arg>"
+" <arg direction=\"in\" name=\"mask\" type=\"u\" />"
+" <arg direction=\"in\" name=\"type\" type=\"au\">"
+" "
+" </arg>"
+" <arg direction=\"in\" name=\"mode\" type=\"(bbb)\">"
+" "
+" </arg>"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"DeregisterKeystrokeListener\">"
+" <arg direction=\"in\" name=\"listener\" type=\"o\" />"
+" <arg direction=\"in\" name=\"keys\" type=\"a(iisi)\">"
+" "
+" </arg>"
+" <arg direction=\"in\" name=\"mask\" type=\"u\" />"
+" <arg direction=\"in\" name=\"type\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"RegisterDeviceEventListener\">"
+" <arg direction=\"in\" name=\"listener\" type=\"o\" />"
+" <arg direction=\"in\" name=\"types\" type=\"u\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <method name=\"DeregisterDeviceEventListener\">"
+" <arg direction=\"in\" name=\"listener\" type=\"o\" />"
+" <arg direction=\"in\" name=\"types\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GetKeystrokeListeners\">"
+" <arg direction=\"out\" type=\"a(souua(iisi)u(bbb))\" />"
+" </method>"
+""
+" <method name=\"GetDeviceEventListeners\">"
+" <arg direction=\"out\" type=\"a(sou)\" />"
+" </method>"
+""
+" <method name=\"GenerateKeyboardEvent\">"
+" <arg direction=\"in\" name=\"keycode\" type=\"i\" />"
+" <arg direction=\"in\" name=\"keystring\" type=\"s\" />"
+" <arg direction=\"in\" name=\"type\" type=\"u\" />"
+" </method>"
+""
+" <method name=\"GenerateMouseEvent\">"
+" <arg direction=\"in\" name=\"x\" type=\"i\" />"
+" <arg direction=\"in\" name=\"y\" type=\"i\" />"
+" <arg direction=\"in\" name=\"eventName\" type=\"s\" />"
+" </method>"
+""
+" <method name=\"NotifyListenersSync\">"
+" <arg direction=\"in\" name=\"event\" type=\"(uiuuisb)\" />"
+" <arg direction=\"out\" type=\"b\" />"
+" "
+" </method>"
+""
+" <method name=\"NotifyListenersAsync\">"
+" <arg direction=\"in\" name=\"event\" type=\"(uiuuisb)\" />"
+" "
+" </method>"
+""
+"</interface>"
+"";
+
+const char *spi_org_a11y_atspi_DeviceEventListener =
+"<interface name=\"org.a11y.atspi.DeviceEventListener\" version=\"0.1.7\">"
+""
+" <method name=\"NotifyEvent\">"
+" <arg direction=\"in\" name=\"event\" type=\"(uiuuisb)\" />"
+" "
+" <arg direction=\"out\" type=\"b\" />"
+" </method>"
+""
+" <signal name=\"KeystrokeListenerRegistered\">"
+" <arg name=\"listener\" type=\"(souua(iisi)u(bbb))\" />"
+" </signal>"
+""
+" <signal name=\"KeystrokeListenerDeregistered\">"
+" <arg name=\"listener\" type=\"(souua(iisi)u(bbb))\" />"
+" </signal>"
+""
+" <signal name=\"DeviceListenerRegistered\">"
+" <arg name=\"listener\" type=\"(sou)\" />"
+" </signal>"
+""
+" <signal name=\"DeviceListenerDeregistered\">"
+" <arg name=\"listener\" type=\"(sou)\" />"
+" </signal>"
+""
+"</interface>"
+"";
+
diff --git a/registryd/introspection.h b/registryd/introspection.h
new file mode 100644
index 0000000..5c28333
--- /dev/null
+++ b/registryd/introspection.h
@@ -0,0 +1,53 @@
+
+/*
+ * This file has been auto-generated from the introspection data available
+ * in the at-spi2-core repository. The D-Bus procol is defined in this
+ * repository, which can be found at:
+ *
+ * http://download.gnome.org/sources/at-spi2-core/0.1/
+ *
+ * DO NOT EDIT.
+ */
+
+#ifndef SPI_INTROSPECTION_DATA_H_
+#define SPI_INTROSPECTION_DATA_H_
+
+
+extern const char *spi_org_a11y_atspi_Accessible;
+
+extern const char *spi_org_a11y_atspi_Action;
+
+extern const char *spi_org_a11y_atspi_Application;
+
+extern const char *spi_org_a11y_atspi_Collection;
+
+extern const char *spi_org_a11y_atspi_Component;
+
+extern const char *spi_org_a11y_atspi_Document;
+
+extern const char *spi_org_a11y_atspi_Hypertext;
+
+extern const char *spi_org_a11y_atspi_Hyperlink;
+
+extern const char *spi_org_a11y_atspi_Image;
+
+extern const char *spi_org_a11y_atspi_Selection;
+
+extern const char *spi_org_a11y_atspi_Table;
+
+extern const char *spi_org_a11y_atspi_Text;
+
+extern const char *spi_org_a11y_atspi_EditableText;
+
+extern const char *spi_org_a11y_atspi_Cache;
+
+extern const char *spi_org_a11y_atspi_Value;
+
+extern const char *spi_org_a11y_atspi_Registry;
+
+extern const char *spi_org_a11y_atspi_DeviceEventController;
+
+extern const char *spi_org_a11y_atspi_DeviceEventListener;
+
+
+#endif /* SPI_INTROSPECTION_DATA_H_ */
diff --git a/registryd/keymasks.h b/registryd/keymasks.h
new file mode 100644
index 0000000..6dc95ad
--- /dev/null
+++ b/registryd/keymasks.h
@@ -0,0 +1,53 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_KEYMASKS_H_
+#define SPI_KEYMASKS_H_
+
+#include <X11/Xlib.h>
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef unsigned long SpiKeyMaskType;
+
+#define SPI_KEYMASK_ALT Mod1Mask
+#define SPI_KEYMASK_MOD1 Mod1Mask
+#define SPI_KEYMASK_MOD2 Mod2Mask
+#define SPI_KEYMASK_MOD3 Mod3Mask
+#define SPI_KEYMASK_MOD4 Mod4Mask
+#define SPI_KEYMASK_MOD5 Mod5Mask
+#define SPI_KEYMASK_BUTTON1 Button1Mask
+#define SPI_KEYMASK_BUTTON2 Button2Mask
+#define SPI_KEYMASK_BUTTON3 Button3Mask
+#define SPI_KEYMASK_BUTTON4 Button4Mask
+#define SPI_KEYMASK_BUTTON5 Button5Mask
+#define SPI_KEYMASK_CONTROL ControlMask
+#define SPI_KEYMASK_SHIFT ShiftMask
+#define SPI_KEYMASK_SHIFTLOCK LockMask
+#define SPI_KEYMASK_NUMLOCK (1<<14)
+#define SPI_KEYMASK_UNMODIFIED 0
+
+G_END_DECLS
+
+#endif /* SPI_KEYMASKS_H_ */
diff --git a/registryd/org.a11y.atspi.Registry.service.in b/registryd/org.a11y.atspi.Registry.service.in
new file mode 100644
index 0000000..204ca27
--- /dev/null
+++ b/registryd/org.a11y.atspi.Registry.service.in
@@ -0,0 +1,3 @@
+[D-BUS Service]
+Name=org.a11y.atspi.Registry
+Exec=@LIBEXECDIR@/at-spi2-registryd
diff --git a/registryd/paths.h b/registryd/paths.h
new file mode 100644
index 0000000..918df67
--- /dev/null
+++ b/registryd/paths.h
@@ -0,0 +1,53 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_PATHS_H_
+#define SPI_PATHS_H_
+
+#define SPI_DBUS_NAME_PREFIX "org.a11y.atspi."
+#define SPI_DBUS_PATH_PREFIX "/org/a11y/atspi/"
+#define SPI_DBUS_INTERFACE_PREFIX "org.a11y.atspi."
+
+#define SPI_DBUS_PATH_NULL SPI_DBUS_PATH_PREFIX "null"
+#define SPI_DBUS_PATH_ROOT SPI_DBUS_PATH_PREFIX "accessible/root"
+
+#define SPI_DBUS_NAME_REGISTRY SPI_DBUS_NAME_PREFIX "Registry"
+#define SPI_DBUS_INTERFACE_REGISTRY SPI_DBUS_INTERFACE_PREFIX "Registry"
+#define SPI_DBUS_PATH_REGISTRY SPI_DBUS_PATH_PREFIX "registry"
+
+#define SPI_DBUS_PATH_DEC SPI_DBUS_PATH_PREFIX "registry/deviceeventcontroller"
+#define SPI_DBUS_INTERFACE_DEC SPI_DBUS_INTERFACE_PREFIX "DeviceEventController"
+#define SPI_DBUS_INTERFACE_DEVICE_EVENT_LISTENER SPI_DBUS_INTERFACE_PREFIX "DeviceEventListener"
+
+#define SPI_DBUS_PATH_CACHE SPI_DBUS_PATH_PREFIX "cache"
+#define SPI_DBUS_INTERFACE_CACHE SPI_DBUS_INTERFACE_PREFIX "Cache"
+
+#define SPI_DBUS_INTERFACE_ACCESSIBLE SPI_DBUS_INTERFACE_PREFIX "Accessible"
+#define SPI_DBUS_INTERFACE_APPLICATION SPI_DBUS_INTERFACE_PREFIX "Application"
+#define SPI_DBUS_INTERFACE_COMPONENT SPI_DBUS_INTERFACE_PREFIX "Component"
+#define SPI_DBUS_INTERFACE_EVENT_KEYBOARD SPI_DBUS_INTERFACE_PREFIX "Keyboard"
+#define SPI_DBUS_INTERFACE_EVENT_MOUSE SPI_DBUS_INTERFACE_PREFIX "Event.Mouse"
+#define SPI_DBUS_INTERFACE_EVENT_OBJECT SPI_DBUS_INTERFACE_PREFIX "Event.Object"
+#define SPI_DBUS_INTERFACE_SOCKET SPI_DBUS_INTERFACE_PREFIX "Socket"
+
+#endif /* SPI_PATHS_H_ */
diff --git a/registryd/reentrant-list.c b/registryd/reentrant-list.c
new file mode 100644
index 0000000..29bdfca
--- /dev/null
+++ b/registryd/reentrant-list.c
@@ -0,0 +1,105 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <glib.h>
+
+#include "reentrant-list.h"
+
+typedef struct {
+ GList **list;
+ GList *iterator;
+} Iteration;
+
+static GSList *working_list = NULL; /* of Iteration */
+
+/*
+ * deletes an element from the list - in a re-entrant
+ * safe fashion; advances the element pointer to the next
+ * element.
+ */
+void
+spi_re_entrant_list_delete_link (GList * const *element_ptr)
+{
+ GSList *l;
+ GList *next;
+ GList *element;
+ gboolean first_item;
+ GList *dummy; /* suppress warning */
+
+ g_return_if_fail (element_ptr != NULL);
+
+ element = *element_ptr;
+ g_return_if_fail (element != NULL);
+
+ next = element->next;
+ first_item = (element->prev == NULL);
+
+ dummy = g_list_remove_link (NULL, element);
+
+ for (l = working_list; l; l = l->next)
+ {
+ Iteration *i = l->data;
+
+ if (i->iterator == element)
+ {
+ i->iterator = next;
+ }
+
+ if (first_item && *(i->list) == element)
+ {
+ *(i->list) = next;
+ }
+ }
+
+ g_list_free_1 (element);
+}
+
+void
+spi_re_entrant_list_foreach (GList **list,
+ SpiReEntrantFn func,
+ gpointer user_data)
+{
+ Iteration i;
+
+ if (!list || !*list)
+ {
+ return;
+ }
+
+ i.list = list;
+ i.iterator = *list;
+
+ working_list = g_slist_prepend (working_list, &i);
+
+ while (i.iterator) {
+ GList *l = i.iterator;
+
+ func (&i.iterator, user_data);
+
+ if (i.iterator == l)
+ i.iterator = i.iterator->next;
+ }
+
+ working_list = g_slist_remove (working_list, &i);
+}
diff --git a/registryd/reentrant-list.h b/registryd/reentrant-list.h
new file mode 100644
index 0000000..901561b
--- /dev/null
+++ b/registryd/reentrant-list.h
@@ -0,0 +1,46 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef REENTRANT_LIST_H_
+#define REENTRANT_LIST_H_
+
+#include <glib.h>
+
+G_BEGIN_DECLS
+
+typedef enum {
+ SPI_RE_ENTRANT_CONTINUE = 0,
+ SPI_RE_ENTRANT_TERMINATE
+} SpiReEntrantContinue;
+
+typedef SpiReEntrantContinue (*SpiReEntrantFn) (GList * const *list,
+ gpointer user_data);
+
+void spi_re_entrant_list_delete_link (GList * const *element_ptr);
+void spi_re_entrant_list_foreach (GList **list,
+ SpiReEntrantFn func,
+ gpointer user_data);
+
+G_END_DECLS
+
+#endif /* REENTRANT_LIST_H_ */
diff --git a/registryd/registry-main.c b/registryd/registry-main.c
new file mode 100644
index 0000000..d8b5dc5
--- /dev/null
+++ b/registryd/registry-main.c
@@ -0,0 +1,268 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <stdlib.h>
+#include <config.h>
+#include <string.h>
+#include <glib.h>
+#include <gio/gio.h>
+#include <stdio.h>
+#include <dlfcn.h>
+
+#include <dbus/dbus.h>
+
+#include "paths.h"
+#include "registry.h"
+#include "deviceeventcontroller.h"
+#include "atspi/atspi.h"
+
+static GMainLoop *mainloop;
+static gchar *dbus_name = NULL;
+static gboolean use_gnome_session = FALSE;
+
+static GOptionEntry optentries[] =
+{
+ {"dbus-name", 0, 0, G_OPTION_ARG_STRING, &dbus_name, "Well-known name to register with D-Bus", NULL},
+ {"use-gnome-session", 0, 0, G_OPTION_ARG_NONE, &use_gnome_session, "Should register with gnome session manager", NULL},
+ {NULL}
+};
+
+static GDBusProxy *sm_proxy = NULL;
+static char *client_id = NULL;
+static GDBusProxy *client_proxy = NULL;
+
+#define SM_DBUS_NAME "org.gnome.SessionManager"
+#define SM_DBUS_PATH "/org/gnome/SessionManager"
+#define SM_DBUS_INTERFACE "org.gnome.SessionManager"
+
+#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
+
+static gboolean register_client (void);
+
+static void
+on_session_signal (GDBusProxy *proxy,
+ gchar *sender_name,
+ gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ if (g_strcmp0 (signal_name, "SessionOver") == 0) {
+ g_main_loop_quit (mainloop);
+ } else if (g_strcmp0 (signal_name, "SessionRunning") == 0) {
+ if (!register_client ())
+ g_warning ("Unable to register client with session manager");
+ }
+}
+
+static gboolean
+session_manager_connect (void)
+{
+ GVariant *res;
+ gboolean is_running;
+
+ sm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, 0, NULL,
+ SM_DBUS_NAME,
+ SM_DBUS_PATH,
+ SM_DBUS_INTERFACE, NULL, NULL);
+
+ res = g_dbus_proxy_call_sync (sm_proxy,
+ "IsSessionRunning", NULL,
+ 0, 1000, NULL, NULL);
+
+ if (res) {
+ g_variant_get (res, "(b)", &is_running);
+ g_variant_unref (res);
+ if (is_running) {
+ if (!register_client ())
+ g_warning ("Unable to register client with session manager");
+ }
+ }
+
+ g_signal_connect (G_OBJECT (sm_proxy), "g-signal",
+ G_CALLBACK (on_session_signal), NULL);
+
+ return (sm_proxy != NULL);
+}
+
+static gboolean
+end_session_response (gboolean is_okay, const gchar *reason)
+{
+ GVariant *ret;
+ GError *error = NULL;
+
+ if (!reason)
+ reason = "";
+
+ ret = g_dbus_proxy_call_sync (client_proxy, "EndSessionResponse",
+ g_variant_new ("(bs)", is_okay, reason),
+ 0, 1000, NULL, &error);
+
+ if (!ret) {
+ g_warning ("Failed to send session response %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+ else
+ g_variant_unref (ret);
+
+ return TRUE;
+}
+
+static void
+client_proxy_signal_cb (GDBusProxy *proxy,
+ gchar *sender_name,
+ gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ if (g_strcmp0 (signal_name, "QueryEndSession") == 0) {
+ g_debug ("Got QueryEndSession signal");
+ end_session_response (TRUE, NULL);
+ } else if (g_strcmp0 (signal_name, "EndSession") == 0) {
+ g_debug ("Got EndSession signal");
+ end_session_response (TRUE, NULL);
+ g_main_loop_quit (mainloop);
+ } else if (g_strcmp0 (signal_name, "Stop") == 0) {
+ g_debug ("Got Stop signal");
+ g_main_loop_quit (mainloop);
+ }
+}
+
+static gboolean
+register_client (void)
+{
+ GError *error;
+ GVariant *res;
+ const char *startup_id;
+ const char *app_id;
+
+ if (client_proxy)
+ return TRUE;
+
+ startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+ if (!startup_id)
+ startup_id = "";
+ app_id = "at-spi-registryd.desktop";
+
+ error = NULL;
+ res = g_dbus_proxy_call_sync (sm_proxy,
+ "RegisterClient",
+ g_variant_new ("(ss)", app_id,
+ startup_id),
+ 0, 1000, NULL, &error);
+ if (! res) {
+ const char *message = (error && error->message ? error->message
+ : "no error");
+ g_warning ("Failed to register client: %s", message);
+ if (error)
+ g_error_free (error);
+ return FALSE;
+ }
+ g_variant_get (res, "(o)", &client_id);
+ g_variant_unref (res);
+
+ client_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION, 0, NULL,
+ SM_DBUS_NAME,
+ client_id,
+ SM_CLIENT_DBUS_INTERFACE,
+ NULL, NULL);
+
+ g_signal_connect (client_proxy, "g-signal",
+ G_CALLBACK (client_proxy_signal_cb), NULL);
+
+ g_unsetenv ("DESKTOP_AUTOSTART_ID");
+
+ return TRUE;
+}
+
+/*---------------------------------------------------------------------------*/
+
+
+/*---------------------------------------------------------------------------*/
+
+typedef GObject *(*gconf_client_get_default_t) ();
+typedef gboolean (*gconf_client_get_bool_t)(GObject *, const char *, void *);
+
+int
+main (int argc, char **argv)
+{
+ SpiRegistry *registry;
+ SpiDEController *dec;
+
+ DBusConnection *bus = NULL;
+
+ GOptionContext *opt;
+
+ GError *err = NULL;
+ int ret;
+
+ /*Parse command options*/
+ opt = g_option_context_new(NULL);
+ g_option_context_add_main_entries(opt, optentries, NULL);
+
+ if (!g_option_context_parse(opt, &argc, &argv, &err))
+ {
+ g_error("Option parsing failed: %s\n", err->message);
+ g_clear_error (&err);
+ }
+
+ if (dbus_name == NULL)
+ dbus_name = SPI_DBUS_NAME_REGISTRY;
+
+ bus = atspi_get_a11y_bus ();
+ if (!bus)
+ {
+ return 0;
+ }
+
+ mainloop = g_main_loop_new (NULL, FALSE);
+ atspi_dbus_connection_setup_with_g_main(bus, NULL);
+
+ ret = dbus_bus_request_name(bus, dbus_name, DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL);
+ if (ret == DBUS_REQUEST_NAME_REPLY_EXISTS)
+ {
+ exit (0); /* most likely already running */
+ }
+ else
+ {
+ g_print ("SpiRegistry daemon is running with well-known name - %s\n", dbus_name);
+ }
+
+ registry = spi_registry_new (bus);
+ dec = spi_registry_dec_new (registry, bus);
+
+ if (use_gnome_session)
+ {
+ if (!session_manager_connect ())
+ g_warning ("Unable to connect to session manager");
+ }
+
+ g_main_loop_run (mainloop);
+
+ dbus_connection_close (bus);
+ dbus_connection_unref (bus);
+ g_object_unref (dec);
+ g_object_unref (registry);
+
+ return 0;
+}
diff --git a/registryd/registry.c b/registryd/registry.c
new file mode 100644
index 0000000..81cf045
--- /dev/null
+++ b/registryd/registry.c
@@ -0,0 +1,1470 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2008, 2010 Codethink Ltd.
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "paths.h"
+#include "registry.h"
+#include "introspection.h"
+
+typedef struct event_data event_data;
+struct event_data
+{
+ gchar *bus_name;
+ gchar **data;
+ GSList *properties;
+};
+
+static void
+children_added_listener (DBusConnection * bus,
+ gint index,
+ const gchar * name,
+ const gchar * path);
+
+static void
+children_removed_listener (DBusConnection * bus,
+ gint index,
+ const gchar * name,
+ const gchar * path);
+
+/*---------------------------------------------------------------------------*/
+
+typedef struct _SpiReference
+{
+ gchar *name;
+ gchar *path;
+} SpiReference;
+
+static SpiReference *
+spi_reference_new (const gchar *name, const gchar *path)
+{
+ SpiReference *ref;
+
+ ref = g_new0 (SpiReference, 1);
+ ref->name = g_strdup (name);
+ ref->path = g_strdup (path);
+
+ return ref;
+}
+
+static void
+spi_reference_free (SpiReference *ref)
+{
+ g_free (ref->name);
+ g_free (ref->path);
+ g_free (ref);
+}
+
+/*---------------------------------------------------------------------------*/
+
+G_DEFINE_TYPE(SpiRegistry, spi_registry, G_TYPE_OBJECT)
+
+static void
+spi_registry_class_init (SpiRegistryClass *klass)
+{
+ spi_registry_parent_class = g_type_class_ref (G_TYPE_OBJECT);
+}
+
+static void
+spi_registry_init (SpiRegistry *registry)
+{
+ registry->apps = g_ptr_array_new_with_free_func ((GDestroyNotify) spi_reference_free);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static dbus_bool_t
+return_v_string (DBusMessageIter * iter, const gchar * str)
+{
+ DBusMessageIter variant;
+
+ if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "s",
+ &variant))
+ return FALSE;
+ dbus_message_iter_append_basic (&variant, DBUS_TYPE_STRING, &str);
+ dbus_message_iter_close_container (iter, &variant);
+ return TRUE;
+}
+
+static dbus_bool_t
+append_reference (DBusMessageIter * iter, const char * name, const char * path)
+{
+ DBusMessageIter iter_struct;
+
+ if (!dbus_message_iter_open_container (iter, DBUS_TYPE_STRUCT, NULL,
+ &iter_struct))
+ return FALSE;
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &name);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_OBJECT_PATH, &path);
+ dbus_message_iter_close_container (iter, &iter_struct);
+ return TRUE;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static gboolean
+compare_reference (SpiReference *one, SpiReference *two)
+{
+ if (g_strcmp0 (one->name, two->name) == 0 &&
+ g_strcmp0 (one->path, two->path) == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+static gboolean
+find_index_of_reference (GPtrArray *arr, const gchar *name, const gchar * path, guint *index)
+{
+ SpiReference *ref;
+ gboolean found = FALSE;
+ guint i = 0;
+
+ ref = spi_reference_new (name, path);
+
+ for (i = 0; i < arr->len && found == FALSE; i++)
+ {
+ if (compare_reference (ref, g_ptr_array_index (arr, i)));
+ {
+ found = TRUE;
+ }
+ }
+
+ spi_reference_free (ref);
+
+ *index = i;
+ return found;
+}
+
+static void
+add_application (SpiRegistry *reg, DBusConnection *bus, const gchar *name, const gchar *path)
+{
+ g_ptr_array_add (reg->apps, spi_reference_new (name, path));
+ children_added_listener (bus, reg->apps->len - 1, name, path);
+}
+
+static void
+set_id (SpiRegistry *reg, DBusConnection *bus, const gchar *name, const gchar *path)
+{
+ DBusMessage *message;
+ DBusMessageIter iter, iter_variant;
+ const char *iface_application = "org.a11y.atspi.Application";
+ const char *id = "Id";
+
+ message = dbus_message_new_method_call (name, path,
+ DBUS_INTERFACE_PROPERTIES, "Set");
+ if (!message)
+ return;
+ dbus_message_iter_init_append (message, &iter);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &iface_application);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &id);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "i", &iter_variant);
+ dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, &reg->id);
+ /* TODO: This will cause problems if we cycle through 2^31 ids */
+ reg->id++;
+ dbus_message_iter_close_container (&iter, &iter_variant);
+ dbus_connection_send (bus, message, NULL);
+ dbus_message_unref (message);
+}
+
+static void
+remove_application (SpiRegistry *reg, DBusConnection *bus, guint index)
+{
+ SpiReference *ref = g_ptr_array_index (reg->apps, index);
+
+ spi_remove_device_listeners (reg->dec, ref->name);
+ children_removed_listener (bus, index, ref->name, ref->path);
+ g_ptr_array_remove_index (reg->apps, index);
+}
+
+static gboolean
+event_is_subtype (gchar **needle, gchar **haystack)
+{
+ while (*haystack && **haystack)
+ {
+ if (g_strcmp0 (*needle, *haystack))
+ return FALSE;
+ needle++;
+ haystack++;
+ }
+ return TRUE;
+}
+
+static gboolean
+needs_mouse_poll (char **event)
+{
+ if (g_strcmp0 (event [0], "Mouse") != 0)
+ return FALSE;
+ if (!event [1] || !event [1][0])
+ return TRUE;
+ return (g_strcmp0 (event [1], "Abs") == 0);
+}
+
+static void
+remove_events (SpiRegistry *registry, const char *bus_name, const char *event)
+{
+ gchar **remove_data;
+ GList *list;
+ gboolean mouse_found = FALSE;
+ DBusMessage *signal;
+
+ remove_data = g_strsplit (event, ":", 3);
+ if (!remove_data)
+ {
+ return;
+ }
+
+ for (list = registry->events; list;)
+ {
+ event_data *evdata = list->data;
+ list = list->next;
+ if (!g_strcmp0 (evdata->bus_name, bus_name) &&
+ event_is_subtype (evdata->data, remove_data))
+ {
+ g_strfreev (evdata->data);
+ g_free (evdata->bus_name);
+ g_slist_free_full (evdata->properties, g_free);
+ g_free (evdata);
+ registry->events = g_list_remove (registry->events, evdata);
+ }
+ else
+ {
+ if (needs_mouse_poll (evdata->data))
+ mouse_found = TRUE;
+ }
+ }
+
+ if (!mouse_found)
+ spi_device_event_controller_stop_poll_mouse ();
+
+ g_strfreev (remove_data);
+
+ signal = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY,
+ SPI_DBUS_INTERFACE_REGISTRY,
+ "EventListenerDeregistered");
+ dbus_message_append_args (signal, DBUS_TYPE_STRING, &bus_name,
+ DBUS_TYPE_STRING, &event, DBUS_TYPE_INVALID);
+ dbus_connection_send (registry->bus, signal, NULL);
+ dbus_message_unref (signal);
+}
+
+static void
+handle_disconnection (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ char *name, *old, *new;
+ SpiRegistry *reg = SPI_REGISTRY (user_data);
+
+ if (dbus_message_get_args (message, NULL,
+ DBUS_TYPE_STRING, &name,
+ DBUS_TYPE_STRING, &old,
+ DBUS_TYPE_STRING, &new,
+ DBUS_TYPE_INVALID))
+ {
+ if (*old != '\0' && *new == '\0')
+ {
+ /* Remove all children with the application name the same as the disconnected application. */
+ guint i;
+ for (i = 0; i < reg->apps->len; i++)
+ {
+ SpiReference *ref = g_ptr_array_index (reg->apps, i);
+ if (!g_strcmp0 (old, ref->name))
+ {
+ remove_application (reg, bus, i);
+ i--;
+ }
+ }
+
+ remove_events (reg, old, "");
+ }
+ }
+}
+
+/*
+ * Converts names of the form "active-descendant-changed" to
+ *" ActiveDescendantChanged"
+ */
+static gchar *
+ensure_proper_format (const char *name)
+{
+ gchar *ret = (gchar *) g_malloc (strlen (name) * 2 + 2);
+ gchar *p = ret;
+ gboolean need_upper = TRUE;
+
+ if (!ret)
+ return NULL;
+ while (*name)
+ {
+ if (need_upper)
+ {
+ *p++ = toupper (*name);
+ need_upper = FALSE;
+ }
+ else if (*name == '-')
+ need_upper = TRUE;
+ else if (*name == ':')
+ {
+ need_upper = TRUE;
+ *p++ = *name;
+ }
+ else
+ *p++ = *name;
+ name++;
+ }
+ *p = '\0';
+ return ret;
+}
+
+static DBusHandlerResult
+signal_filter (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ guint res = DBUS_HANDLER_RESULT_HANDLED;
+ const gint type = dbus_message_get_type (message);
+ const char *iface = dbus_message_get_interface (message);
+ const char *member = dbus_message_get_member (message);
+
+ if (type != DBUS_MESSAGE_TYPE_SIGNAL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ if (!g_strcmp0(iface, DBUS_INTERFACE_DBUS) &&
+ !g_strcmp0(member, "NameOwnerChanged"))
+ handle_disconnection (bus, message, user_data);
+ else
+ res = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ return res;
+}
+
+/* org.at_spi.Socket interface */
+/*---------------------------------------------------------------------------*/
+
+static DBusMessage*
+impl_Embed (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiRegistry *reg = SPI_REGISTRY (user_data);
+ DBusMessageIter iter, iter_struct;
+ const gchar *app_name, *obj_path;
+
+ DBusMessage *reply = NULL;
+ DBusMessageIter reply_iter;
+
+ dbus_message_iter_init (message, &iter);
+ dbus_message_iter_recurse (&iter, &iter_struct);
+ if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
+ goto error;
+ dbus_message_iter_get_basic (&iter_struct, &app_name);
+ if (!app_name)
+ app_name = dbus_message_get_sender (message);
+ if (!dbus_message_iter_next (&iter_struct))
+ goto error;
+ if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
+ goto error;
+ dbus_message_iter_get_basic (&iter_struct, &obj_path);
+
+ add_application(reg, bus, app_name, obj_path);
+
+ set_id (reg, bus, app_name, obj_path);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &reply_iter);
+ append_reference (&reply_iter,
+ dbus_bus_get_unique_name (bus),
+ SPI_DBUS_PATH_ROOT);
+
+ return reply;
+error:
+ return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
+}
+
+static DBusMessage*
+impl_Unembed (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiRegistry *reg = SPI_REGISTRY (user_data);
+ DBusMessageIter iter, iter_struct;
+ gchar *app_name, *obj_path;
+ guint index;
+
+ dbus_message_iter_init (message, &iter);
+ dbus_message_iter_recurse (&iter, &iter_struct);
+ if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_STRING))
+ goto error;
+ dbus_message_iter_get_basic (&iter_struct, &app_name);
+ if (!dbus_message_iter_next (&iter_struct))
+ goto error;
+ if (!(dbus_message_iter_get_arg_type (&iter_struct) == DBUS_TYPE_OBJECT_PATH))
+ goto error;
+ dbus_message_iter_get_basic (&iter_struct, &obj_path);
+
+ if (find_index_of_reference (reg->apps, app_name, obj_path, &index))
+ remove_application(reg, bus, index);
+
+ return NULL;
+error:
+ return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
+}
+
+/* org.at_spi.Component interface */
+/*---------------------------------------------------------------------------*/
+
+static DBusMessage *
+impl_Contains (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ dbus_bool_t retval = FALSE;
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetAccessibleAtPoint (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+ append_reference (&iter,
+ dbus_bus_get_unique_name (bus),
+ SPI_DBUS_PATH_NULL);
+
+ return reply;
+}
+
+static DBusMessage *
+impl_GetExtents (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ dbus_int32_t x = 0, y = 0, width = 1024, height = 768;
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_struct;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_STRUCT, NULL,
+ &iter_struct);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &x);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &y);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &width);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_INT32, &height);
+ dbus_message_iter_close_container (&iter, &iter_struct);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetPosition (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
+{
+ DBusMessage *reply;
+ dbus_int32_t x = 0, y = 0;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_INT32, &x, DBUS_TYPE_INT32,
+ &y, DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetSize (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ /* TODO - Get the screen size */
+ DBusMessage *reply;
+ dbus_int32_t width = 1024, height = 768;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_INT32, &width,
+ DBUS_TYPE_INT32, &height, DBUS_TYPE_INVALID);
+ return reply;
+}
+
+#define LAYER_WIDGET 3;
+
+static DBusMessage *
+impl_GetLayer (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ dbus_uint32_t rv = LAYER_WIDGET;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetMDIZOrder (DBusConnection * bus, DBusMessage * message,
+ void *user_data)
+{
+ DBusMessage *reply;
+ dbus_int16_t rv = 0;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_INT16, &rv,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GrabFocus (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ dbus_bool_t retval = FALSE;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_ClearHighlight (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ dbus_bool_t retval = FALSE;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GrabHighlight (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ dbus_bool_t retval = FALSE;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_BOOLEAN, &retval,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetAlpha (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ double rv = 1.0;
+ DBusMessage *reply;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_DOUBLE, &rv,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+/* org.at_spi.Accessible interface */
+/*---------------------------------------------------------------------------*/
+
+static dbus_bool_t
+impl_get_Name (DBusMessageIter * iter, void *user_data)
+{
+ const gchar *name = "main";
+ return return_v_string (iter, name);
+}
+
+static dbus_bool_t
+impl_get_Description (DBusMessageIter * iter, void *user_data)
+{
+ const gchar *description = "";
+ return return_v_string (iter, description);
+}
+
+static dbus_bool_t
+impl_get_Parent (DBusMessageIter * iter, void *user_data)
+{
+ const gchar *name = "";
+ DBusMessageIter iter_variant;
+
+ dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "(so)",
+ &iter_variant);
+ append_reference (&iter_variant,
+ name,
+ SPI_DBUS_PATH_NULL);
+ dbus_message_iter_close_container (iter, &iter_variant);
+ return TRUE;
+}
+
+static dbus_bool_t
+impl_get_ChildCount (DBusMessageIter * iter, void *user_data)
+{
+ SpiRegistry *reg = SPI_REGISTRY (user_data);
+ dbus_int32_t rv = reg->apps->len;
+ dbus_bool_t result;
+ DBusMessageIter iter_variant;
+
+ if (!dbus_message_iter_open_container (iter, DBUS_TYPE_VARIANT, "i",
+ &iter_variant))
+ return FALSE;
+ result = dbus_message_iter_append_basic (&iter_variant, DBUS_TYPE_INT32, &rv);
+ dbus_message_iter_close_container (iter, &iter_variant);
+ return result;
+}
+
+static dbus_bool_t
+impl_get_ToolkitName (DBusMessageIter * iter, void *user_data)
+{
+ return return_v_string (iter, "at-spi-registry");
+}
+
+static dbus_bool_t
+impl_get_ToolkitVersion (DBusMessageIter * iter, void *user_data)
+{
+ return return_v_string (iter, "2.0");
+}
+
+static DBusMessage *
+impl_GetChildAtIndex (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ SpiRegistry *reg = SPI_REGISTRY (user_data);
+ DBusMessage *reply;
+ DBusMessageIter iter;
+ DBusError error;
+ SpiReference *ref;
+ dbus_int32_t i;
+
+ dbus_error_init (&error);
+ if (!dbus_message_get_args
+ (message, &error, DBUS_TYPE_INT32, &i, DBUS_TYPE_INVALID))
+ {
+ return dbus_message_new_error (message, DBUS_ERROR_FAILED, "Invalid arguments");
+ }
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+
+ if (i < 0 || i >= reg->apps->len)
+ append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_NULL);
+ else
+ {
+ ref = g_ptr_array_index (reg->apps, i);
+ append_reference (&iter, ref->name, ref->path);
+ }
+
+ return reply;
+}
+
+static DBusMessage *
+impl_GetChildren (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, iter_array;
+ SpiRegistry *reg = SPI_REGISTRY (user_data);
+ int i;
+
+ reply = dbus_message_new_method_return (message);
+
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "(so)", &iter_array);
+ for (i=0; i < reg->apps->len; i++)
+ {
+ SpiReference *current = g_ptr_array_index (reg->apps, i);
+ append_reference (&iter_array, current->name, current->path);
+ }
+ dbus_message_iter_close_container(&iter, &iter_array);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetIndexInParent (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ dbus_uint32_t rv = 0;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_INT32, &rv, DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetRelationSet (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_array;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "(ua(so))", &iter_array);
+ dbus_message_iter_close_container (&iter, &iter_array);
+
+ return reply;
+}
+
+static DBusMessage *
+impl_GetRole (DBusConnection * bus, DBusMessage * message, void * user_data)
+{
+ DBusMessage *reply;
+ dbus_uint32_t rv = 14; /* TODO: Get DESKTOP_FRAME from somewhere */
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_UINT32, &rv, DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetRoleName (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ const char *role_name = "desktop frame";
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetLocalizedRoleName (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ /* TODO - Localize this */
+ DBusMessage *reply;
+ const char *role_name = "desktop frame";
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args (reply, DBUS_TYPE_STRING, &role_name,
+ DBUS_TYPE_INVALID);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetState (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, iter_array;
+
+ dbus_uint32_t states[2] = {0, 0};
+ guint count;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "u", &iter_array);
+ for (count = 0; count < 2; count++)
+ {
+ dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_UINT32,
+ &states[count]);
+ }
+ dbus_message_iter_close_container (&iter, &iter_array);
+ return reply;
+}
+
+static DBusMessage *
+impl_GetAttributes (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter, array;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "{ss}", &array);
+ dbus_message_iter_close_container (&iter, &array);
+
+ return reply;
+}
+
+static DBusMessage *
+impl_GetApplication (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply = NULL;
+ DBusMessageIter iter;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+ append_reference (&iter,
+ dbus_bus_get_unique_name (bus),
+ SPI_DBUS_PATH_NULL);
+
+ return reply;
+}
+
+static DBusMessage *
+impl_GetInterfaces (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_array;
+
+ const char *acc = SPI_DBUS_INTERFACE_ACCESSIBLE;
+ const char *com = SPI_DBUS_INTERFACE_COMPONENT;
+
+ reply = dbus_message_new_method_return (message);
+
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s",
+ &iter_array);
+ dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &acc);
+ dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &com);
+ dbus_message_iter_close_container (&iter, &iter_array);
+
+ return reply;
+}
+
+static DBusMessage *
+impl_GetItems (DBusConnection * bus, DBusMessage * message, void *user_data)
+{
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_array;
+
+ reply = dbus_message_new_method_return (message);
+
+ dbus_message_iter_init_append (reply, &iter);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY,
+ "((so)(so)(so)a(so)assusau)", &iter_array);
+ dbus_message_iter_close_container (&iter, &iter_array);
+ return reply;
+}
+
+/* I would rather these two be signals, but I'm not sure that dbus-python
+ * supports emitting signals except for a service, so implementing as both
+ * a method call and signal for now.
+ */
+static DBusMessage *
+impl_register_event (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiRegistry *registry = SPI_REGISTRY (user_data);
+ const char *orig_name;
+ gchar *name;
+ event_data *evdata;
+ gchar **data;
+ DBusMessage *signal;
+ const char *sender = dbus_message_get_sender (message);
+ DBusMessageIter iter, iter_array;
+ const char *signature = dbus_message_get_signature (message);
+
+ if (strcmp (signature, "sas") != 0 &&
+ strcmp (signature, "s") != 0)
+ {
+ g_warning ("got RegisterEvent with invalid signature '%s'", signature);
+ return NULL;
+ }
+
+ dbus_message_iter_init (message, &iter);
+ dbus_message_iter_get_basic (&iter, &orig_name);
+ dbus_message_iter_next (&iter);
+ name = ensure_proper_format (orig_name);
+
+ evdata = g_new0 (event_data, 1);
+ data = g_strsplit (name, ":", 3);
+ evdata->bus_name = g_strdup (sender);
+ evdata->data = data;
+
+ if (dbus_message_iter_get_arg_type (&iter) == DBUS_TYPE_ARRAY)
+ {
+ dbus_message_iter_recurse (&iter, &iter_array);
+ while (dbus_message_iter_get_arg_type (&iter_array) != DBUS_TYPE_INVALID)
+ {
+ const char *property;
+ dbus_message_iter_get_basic (&iter_array, &property);
+ evdata->properties = g_slist_append (evdata->properties,
+ g_strdup (property));
+ dbus_message_iter_next (&iter_array);
+ }
+ }
+ registry->events = g_list_append (registry->events, evdata);
+
+ if (needs_mouse_poll (evdata->data))
+ {
+ spi_device_event_controller_start_poll_mouse (registry);
+ }
+
+ signal = dbus_message_new_signal (SPI_DBUS_PATH_REGISTRY,
+ SPI_DBUS_INTERFACE_REGISTRY,
+ "EventListenerRegistered");
+ if (signal)
+ {
+ GSList *ls = evdata->properties;
+ dbus_message_iter_init_append (signal, &iter);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &sender);
+ dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &name);
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_ARRAY, "s", &iter_array);
+ while (ls)
+ {
+ dbus_message_iter_append_basic (&iter_array, DBUS_TYPE_STRING, &ls->data);
+ ls = g_slist_next (ls);
+ }
+ dbus_message_iter_close_container (&iter, &iter_array);
+ dbus_connection_send (bus, signal, NULL);
+ dbus_message_unref (signal);
+ }
+
+ g_free (name);
+ return dbus_message_new_method_return (message);
+}
+
+static DBusMessage *
+impl_deregister_event (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiRegistry *registry = SPI_REGISTRY (user_data);
+ const char *orig_name;
+ gchar *name;
+ const char *sender = dbus_message_get_sender (message);
+
+ if (!dbus_message_get_args (message, NULL, DBUS_TYPE_STRING, &orig_name,
+ DBUS_TYPE_INVALID))
+ return NULL;
+ name = ensure_proper_format (orig_name);
+
+ remove_events (registry, sender, name);
+
+ g_free (name);
+ return dbus_message_new_method_return (message);
+}
+
+static DBusMessage *
+impl_get_registered_events (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiRegistry *registry = SPI_REGISTRY (user_data);
+ event_data *evdata;
+ DBusMessage *reply;
+ DBusMessageIter iter, iter_struct, iter_array;
+ GList *list;
+
+ 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, "(ss)", &iter_array);
+ for (list = registry->events; list; list = list->next)
+ {
+ gchar *str;
+ evdata = list->data;
+ str = g_strconcat (evdata->data [0],
+ ":", (evdata->data [1]? evdata->data [1]: ""),
+ ":", (evdata->data [1] && evdata->data [2]? evdata->data [2]: ""), NULL);
+ dbus_message_iter_open_container (&iter_array, DBUS_TYPE_STRUCT, NULL, &iter_struct);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &evdata->bus_name);
+ dbus_message_iter_append_basic (&iter_struct, DBUS_TYPE_STRING, &str);
+ dbus_message_iter_close_container (&iter_array, &iter_struct);
+ g_free (str);
+ }
+ dbus_message_iter_close_container (&iter, &iter_array);
+ return reply;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void
+emit_Available (DBusConnection * bus)
+{
+ DBusMessage *sig;
+ DBusMessageIter iter;
+
+ sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, SPI_DBUS_INTERFACE_SOCKET, "Available");
+
+ dbus_message_iter_init_append(sig, &iter);
+ append_reference (&iter, SPI_DBUS_NAME_REGISTRY, SPI_DBUS_PATH_ROOT);
+
+ dbus_connection_send(bus, sig, NULL);
+ dbus_message_unref(sig);
+}
+
+/*---------------------------------------------------------------------------*/
+
+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_root (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ GString *output;
+ gchar *final;
+
+ const gchar *pathstr = SPI_DBUS_PATH_ROOT;
+
+ 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_Accessible);
+ g_string_append (output, spi_org_a11y_atspi_Component);
+
+ 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 DBusMessage *
+impl_Introspect_registry (DBusConnection * bus,
+ DBusMessage * message, void *user_data)
+{
+ GString *output;
+ gchar *final;
+
+ const gchar *pathstr = SPI_DBUS_PATH_REGISTRY;
+
+ 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_Registry);
+
+ 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;
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*
+ * Emits an AT-SPI event.
+ * AT-SPI events names are split into three parts:
+ * class:major:minor
+ * This is mapped onto D-Bus events as:
+ * D-Bus Interface:Signal Name:Detail argument
+ *
+ * Marshals a basic type into the 'any_data' attribute of
+ * the AT-SPI event.
+ */
+static void
+emit_event (DBusConnection *bus,
+ const char *klass,
+ const char *major,
+ const char *minor,
+ dbus_int32_t detail1,
+ dbus_int32_t detail2,
+ const char *name,
+ const char *path)
+{
+ DBusMessage *sig;
+ DBusMessageIter iter, iter_variant;
+
+ sig = dbus_message_new_signal(SPI_DBUS_PATH_ROOT, klass, major);
+
+ dbus_message_iter_init_append(sig, &iter);
+
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &minor);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail1);
+ dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &detail2);
+
+ dbus_message_iter_open_container (&iter, DBUS_TYPE_VARIANT, "(so)",
+ &iter_variant);
+ append_reference (&iter_variant, name, path);
+ dbus_message_iter_close_container (&iter, &iter_variant);
+
+ append_reference (&iter,
+ dbus_bus_get_unique_name (bus),
+ SPI_DBUS_PATH_ROOT);
+
+ dbus_connection_send(bus, sig, NULL);
+ dbus_message_unref(sig);
+}
+
+/*---------------------------------------------------------------------------*/
+
+/*
+ * Children changed signal converter and forwarder.
+ *
+ * Klass (Interface) org.a11y.atspi.Event.Object
+ * Major is the signal name.
+ * Minor is 'add' or 'remove'
+ * detail1 is the index.
+ * detail2 is 0.
+ * any_data is the child reference.
+ */
+
+static void
+children_added_listener (DBusConnection * bus,
+ gint index,
+ const gchar * name,
+ const gchar * path)
+{
+ emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "add", index, 0,
+ name, path);
+}
+
+static void
+children_removed_listener (DBusConnection * bus,
+ gint index,
+ const gchar * name,
+ const gchar * path)
+{
+ emit_event (bus, SPI_DBUS_INTERFACE_EVENT_OBJECT, "ChildrenChanged", "remove", index, 0,
+ name, path);
+}
+
+/*---------------------------------------------------------------------------*/
+
+static DBusHandlerResult
+handle_method_root (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+
+ DBusMessage *reply = NULL;
+
+ /* 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;
+
+ if (!strcmp (iface, "org.freedesktop.DBus.Properties"))
+ {
+ if (!strcmp (member, "Get"))
+ {
+ const gchar *prop_iface;
+ const gchar *prop_member;
+ DBusError error;
+
+ dbus_error_init (&error);
+ if (dbus_message_get_args (message,
+ &error,
+ DBUS_TYPE_STRING,
+ &prop_iface,
+ DBUS_TYPE_STRING,
+ &prop_member,
+ DBUS_TYPE_INVALID))
+ {
+ DBusMessageIter iter;
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_iter_init_append (reply, &iter);
+
+
+ if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
+ {
+ if (!strcmp (prop_member, "Name"))
+ impl_get_Name (&iter, user_data);
+ else if (!strcmp (prop_member, "Description"))
+ impl_get_Description (&iter, user_data);
+ else if (!strcmp (prop_member, "Parent"))
+ impl_get_Parent (&iter, user_data);
+ else if (!strcmp (prop_member, "ChildCount"))
+ impl_get_ChildCount (&iter, user_data);
+ else
+ {
+ dbus_message_unref (reply);
+ reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
+ }
+ }
+ else if (!strcmp (prop_iface, SPI_DBUS_INTERFACE_APPLICATION))
+ {
+ if (!strcmp (prop_member, "ToolkitName"))
+ impl_get_ToolkitName (&iter, user_data);
+ else if (!strcmp (prop_member, "ToolkitVersion"))
+ impl_get_ToolkitVersion (&iter, user_data);
+ else
+ {
+ dbus_message_unref (reply);
+ reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
+ }
+ }
+ else
+ {
+ dbus_message_unref (reply);
+ reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, "Property unavailable");
+ }
+ }
+ else
+ {
+ reply = dbus_message_new_error (message, DBUS_ERROR_FAILED, error.message);
+ }
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ else if (!strcmp (member, "GetAll"))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ }
+ }
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_ACCESSIBLE))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "GetChildAtIndex"))
+ reply = impl_GetChildAtIndex (bus, message, user_data);
+ else if (!strcmp (member, "GetChildren"))
+ reply = impl_GetChildren (bus, message, user_data);
+ else if (!strcmp (member, "GetIndexInParent"))
+ reply = impl_GetIndexInParent (bus, message, user_data);
+ else if (!strcmp (member, "GetRelationSet"))
+ reply = impl_GetRelationSet (bus, message, user_data);
+ else if (!strcmp (member, "GetRole"))
+ reply = impl_GetRole (bus, message, user_data);
+ else if (!strcmp (member, "GetRoleName"))
+ reply = impl_GetRoleName (bus, message, user_data);
+ else if (!strcmp (member, "GetLocalizedRoleName"))
+ reply = impl_GetLocalizedRoleName (bus, message, user_data);
+ else if (!strcmp (member, "GetState"))
+ reply = impl_GetState (bus, message, user_data);
+ else if (!strcmp (member, "GetAttributes"))
+ reply = impl_GetAttributes (bus, message, user_data);
+ else if (!strcmp (member, "GetApplication"))
+ reply = impl_GetApplication (bus, message, user_data);
+ else if (!strcmp (member, "GetInterfaces"))
+ reply = impl_GetInterfaces (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_COMPONENT))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "Contains"))
+ reply = impl_Contains (bus, message, user_data);
+ else if (!strcmp (member, "GetAccessibleAtPoint"))
+ reply = impl_GetAccessibleAtPoint (bus, message, user_data);
+ else if (!strcmp (member, "GetExtents"))
+ reply = impl_GetExtents (bus, message, user_data);
+ else if (!strcmp (member, "GetPosition"))
+ reply = impl_GetPosition (bus, message, user_data);
+ else if (!strcmp (member, "GetSize"))
+ reply = impl_GetSize (bus, message, user_data);
+ else if (!strcmp (member, "GetLayer"))
+ reply = impl_GetLayer (bus, message, user_data);
+ else if (!strcmp (member, "GetMDIZOrder"))
+ reply = impl_GetMDIZOrder (bus, message, user_data);
+ else if (!strcmp (member, "GrabFocus"))
+ reply = impl_GrabFocus (bus, message, user_data);
+ else if (!strcmp (member, "GrabHighlight"))
+ reply = impl_GrabHighlight (bus, message, user_data);
+ else if (!strcmp (member, "ClearHighlight"))
+ reply = impl_ClearHighlight (bus, message, user_data);
+ else if (!strcmp (member, "GetAlpha"))
+ reply = impl_GetAlpha (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_SOCKET))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "Embed"))
+ reply = impl_Embed (bus, message, user_data);
+ else if (!strcmp (member, "Unembed"))
+ reply = impl_Unembed (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_root (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);
+ }
+#if 0
+ else
+ {
+ g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
+ }
+#endif
+
+ return result;
+}
+
+static DBusHandlerResult
+handle_method_cache (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+
+ DBusMessage *reply = NULL;
+
+ /* 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;
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_CACHE))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "GetItems"))
+ reply = impl_GetItems (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);
+ }
+ return result;
+}
+
+static DBusHandlerResult
+handle_method_registry (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+
+ DBusMessage *reply = NULL;
+
+ /* 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;
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_REGISTRY))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp(member, "RegisterEvent"))
+ reply = impl_register_event (bus, message, user_data);
+ else if (!strcmp(member, "DeregisterEvent"))
+ reply = impl_deregister_event (bus, message, user_data);
+ else if (!strcmp(member, "GetRegisteredEvents"))
+ reply = impl_get_registered_events (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_registry (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);
+ }
+#if 0
+ else
+ {
+ g_print ("Registry | Unhandled message : %s|%s\n", iface, member);
+ }
+#endif
+
+ return result;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static DBusObjectPathVTable root_vtable =
+{
+ NULL,
+ &handle_method_root,
+ NULL, NULL, NULL, NULL
+};
+
+static DBusObjectPathVTable registry_vtable =
+{
+ NULL,
+ &handle_method_registry,
+ NULL, NULL, NULL, NULL
+};
+
+static DBusObjectPathVTable cache_vtable =
+{
+ NULL,
+ &handle_method_cache,
+ NULL, NULL, NULL, NULL
+};
+
+static gchar *app_sig_match_name_owner =
+ "type='signal', interface='org.freedesktop.DBus', member='NameOwnerChanged'";
+
+SpiRegistry *
+spi_registry_new (DBusConnection *bus)
+{
+ SpiRegistry *reg = g_object_new (SPI_REGISTRY_TYPE, NULL);
+
+ reg->bus = bus;
+
+ dbus_bus_add_match (bus, app_sig_match_name_owner, NULL);
+ dbus_connection_add_filter (bus, signal_filter, reg, NULL);
+
+ dbus_connection_register_object_path (bus, SPI_DBUS_PATH_ROOT, &root_vtable, reg);
+
+ dbus_connection_register_object_path (bus, SPI_DBUS_PATH_CACHE, &cache_vtable, reg);
+
+ dbus_connection_register_object_path (bus, SPI_DBUS_PATH_REGISTRY, &registry_vtable, reg);
+
+ emit_Available (bus);
+
+ reg->events = NULL;
+
+ return reg;
+}
+
+/*END------------------------------------------------------------------------*/
diff --git a/registryd/registry.h b/registryd/registry.h
new file mode 100644
index 0000000..16dd0d9
--- /dev/null
+++ b/registryd/registry.h
@@ -0,0 +1,64 @@
+/*
+ * AT-SPI - Assistive Technology Service Provider Interface
+ * (Gnome Accessibility Project; http://developer.gnome.org/projects/gap)
+ *
+ * Copyright 2001, 2002 Sun Microsystems Inc.,
+ * Copyright 2001, 2002 Ximian, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef SPI_REGISTRY_H_
+#define SPI_REGISTRY_H_
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include <dbus/dbus.h>
+
+typedef struct _SpiRegistry SpiRegistry;
+typedef struct _SpiRegistryClass SpiRegistryClass;
+
+#include "deviceeventcontroller.h"
+
+G_BEGIN_DECLS
+
+#define SPI_REGISTRY_TYPE (spi_registry_get_type ())
+#define SPI_REGISTRY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), SPI_REGISTRY_TYPE, SpiRegistry))
+#define SPI_REGISTRY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), SPI_REGISTRY_TYPE, SpiRegistryClass))
+#define SPI_IS_REGISTRY(o) (G_TYPE_CHECK__INSTANCE_TYPE ((o), SPI_REGISTRY_TYPE))
+#define SPI_IS_REGISTRY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), SPI_REGISTRY_TYPE))
+
+struct _SpiRegistry {
+ GObject parent;
+ SpiDEController *dec;
+ GPtrArray *apps;
+ dbus_int32_t id;
+
+ DBusConnection *bus;
+ GList *events;
+};
+
+struct _SpiRegistryClass {
+ GObjectClass parent_class;
+};
+
+GType spi_registry_get_type (void);
+SpiRegistry *spi_registry_new (DBusConnection *bus);
+
+G_END_DECLS
+
+#endif /* SPI_REGISTRY_H_ */
diff --git a/registryd/testregistry.py b/registryd/testregistry.py
new file mode 100755
index 0000000..db85e74
--- /dev/null
+++ b/registryd/testregistry.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python
+
+import sys
+import dbus
+import dbus.service
+import gobject
+
+from dbus.mainloop.glib import DBusGMainLoop
+
+DBusGMainLoop(set_as_default=True)
+
+class IdleStateM (object):
+ def __init__(self, bus, loop):
+ self._bus = bus
+ self._loop = loop
+ self._func = self.setup
+
+ def idle_handler(self):
+ self._func = self._func()
+ if self._func == None:
+ self._func = self.teardown
+ return True
+
+ def setup(self):
+ self.obj = self._bus.get_object("org.a11y.atspi.Registry",
+ "/org/a11y/atspi/accessible/root",
+ introspect=False)
+ self.itf = dbus.Interface(self.obj, dbus_interface="org.a11y.atspi.Accessible")
+ return self.register_apps
+
+ def register_apps(self):
+ #self.itf.registerApplication(":R456", ignore_reply=True)
+ #self.itf.registerApplication(":R123", ignore_reply=True)
+ return self.print_applications
+
+ def print_applications(self):
+ apps = self.itf.GetChildren()
+ print apps
+ return self.teardown
+
+ def teardown(self):
+ self._loop.quit()
+
+def main(argv):
+ bus = dbus.SessionBus()
+ obj = bus.get_object("org.a11y.Bus",
+ "/org/a11y/bus",
+ introspect=False)
+ itf = dbus.Interface(obj, dbus_interface="org.a11y.Bus")
+ address = itf.GetAddress()
+
+ bus = dbus.bus.BusConnection(str(address))
+ loop = gobject.MainLoop()
+ stateM = IdleStateM(bus, loop)
+ gobject.idle_add(stateM.idle_handler)
+ loop.run()
+
+if __name__=="__main__":
+ sys.exit(main(sys.argv))
diff --git a/registryd/ucs2keysym.c b/registryd/ucs2keysym.c
new file mode 100644
index 0000000..b4967be
--- /dev/null
+++ b/registryd/ucs2keysym.c
@@ -0,0 +1,855 @@
+/* Modified from the public domain program keysym2ucs.c,
+ * as documented below.
+ *
+ * This module converts ISO 10646
+ * (UCS, Unicode) values into X Keysym values.
+ *
+ * The array keysymtab[] contains pairs of X11 keysym values for graphical
+ * characters and the corresponding Unicode value. The function
+ * keysym2ucs() maps a Unicode value onto a keysym using a binary search,
+ * therefore keysymtab[] must remain SORTED by ucs2 value.
+ *
+ * We allow to represent any UCS character in the range U-00000000 to
+ * U-00FFFFFF by a keysym value in the range 0x01000000 to 0x01ffffff.
+ * This admittedly does not cover the entire 31-bit space of UCS, but
+ * it does cover all of the characters up to U-10FFFF, which can be
+ * represented by UTF-16, and more, and it is very unlikely that higher
+ * UCS codes will ever be assigned by ISO. So to get Unicode character
+ * U+ABCD you can directly use keysym 0x0100abcd.
+ *
+ * NOTE: The comments in the table below contain the actual character
+ * encoded in UTF-8, so for viewing and editing best use an editor in
+ * UTF-8 mode.
+ *
+ * Author: Markus G. Kuhn <http://www.cl.cam.ac.uk/~mgk25/>,
+ * University of Cambridge, April 2001
+ *
+ * Special thanks to Richard Verhoeven <river@win.tue.nl> for preparing
+ * an initial draft of the mapping table.
+ *
+ * This software is in the public domain. Share and enjoy!
+ *
+ */
+
+#include <X11/X.h>
+#include "deviceeventcontroller.h" /* for prototype */
+
+struct codepair {
+ unsigned short keysym;
+ unsigned short ucs;
+} keysymtab[] = {
+ { 0x0ba3, 0x003c }, /* leftcaret < LESS-THAN SIGN */
+ { 0x0ba6, 0x003e }, /* rightcaret > GREATER-THAN SIGN */
+ { 0x0bc6, 0x005f }, /* underbar _ LOW LINE */
+ { 0x0bc0, 0x00af }, /* overbar ¯ MACRON */
+
+ { 0x01a1, 0x0104 }, /* Aogonek Ą LATIN CAPITAL LETTER A WITH OGONEK */
+ { 0x01b1, 0x0105 }, /* aogonek ą LATIN SMALL LETTER A WITH OGONEK */
+ { 0x01a5, 0x013d }, /* Lcaron Ľ LATIN CAPITAL LETTER L WITH CARON */
+ { 0x01a3, 0x0141 }, /* Lstroke Ł LATIN CAPITAL LETTER L WITH STROKE */
+ { 0x01a6, 0x015a }, /* Sacute Ś LATIN CAPITAL LETTER S WITH ACUTE */
+ { 0x01aa, 0x015e }, /* Scedilla Ş LATIN CAPITAL LETTER S WITH CEDILLA */
+ { 0x01a9, 0x0160 }, /* Scaron Š LATIN CAPITAL LETTER S WITH CARON */
+ { 0x01ab, 0x0164 }, /* Tcaron Ť LATIN CAPITAL LETTER T WITH CARON */
+ { 0x01ac, 0x0179 }, /* Zacute Ź LATIN CAPITAL LETTER Z WITH ACUTE */
+ { 0x01af, 0x017b }, /* Zabovedot Ż LATIN CAPITAL LETTER Z WITH DOT ABOVE */
+ { 0x01ae, 0x017d }, /* Zcaron Ž LATIN CAPITAL LETTER Z WITH CARON */
+ { 0x01b3, 0x0142 }, /* lstroke ł LATIN SMALL LETTER L WITH STROKE */
+ { 0x01b5, 0x013e }, /* lcaron ľ LATIN SMALL LETTER L WITH CARON */
+ { 0x01b6, 0x015b }, /* sacute ś LATIN SMALL LETTER S WITH ACUTE */
+ { 0x01b9, 0x0161 }, /* scaron š LATIN SMALL LETTER S WITH CARON */
+ { 0x01ba, 0x015f }, /* scedilla ş LATIN SMALL LETTER S WITH CEDILLA */
+ { 0x01bb, 0x0165 }, /* tcaron ť LATIN SMALL LETTER T WITH CARON */
+ { 0x01bc, 0x017a }, /* zacute ź LATIN SMALL LETTER Z WITH ACUTE */
+ { 0x01be, 0x017e }, /* zcaron ž LATIN SMALL LETTER Z WITH CARON */
+ { 0x01bf, 0x017c }, /* zabovedot ż LATIN SMALL LETTER Z WITH DOT ABOVE */
+ { 0x01c0, 0x0154 }, /* Racute Ŕ LATIN CAPITAL LETTER R WITH ACUTE */
+ { 0x01c3, 0x0102 }, /* Abreve Ă LATIN CAPITAL LETTER A WITH BREVE */
+ { 0x01c5, 0x0139 }, /* Lacute Ĺ LATIN CAPITAL LETTER L WITH ACUTE */
+ { 0x01c6, 0x0106 }, /* Cacute Ć LATIN CAPITAL LETTER C WITH ACUTE */
+ { 0x01c8, 0x010c }, /* Ccaron Č LATIN CAPITAL LETTER C WITH CARON */
+ { 0x01ca, 0x0118 }, /* Eogonek Ę LATIN CAPITAL LETTER E WITH OGONEK */
+ { 0x01cc, 0x011a }, /* Ecaron Ě LATIN CAPITAL LETTER E WITH CARON */
+ { 0x01cf, 0x010e }, /* Dcaron Ď LATIN CAPITAL LETTER D WITH CARON */
+ { 0x01d0, 0x0110 }, /* Dstroke Đ LATIN CAPITAL LETTER D WITH STROKE */
+ { 0x01d1, 0x0143 }, /* Nacute Ń LATIN CAPITAL LETTER N WITH ACUTE */
+ { 0x01d2, 0x0147 }, /* Ncaron Ň LATIN CAPITAL LETTER N WITH CARON */
+ { 0x01d5, 0x0150 }, /* Odoubleacute Ő LATIN CAPITAL LETTER O WITH DOUBLE ACUTE */
+ { 0x01d8, 0x0158 }, /* Rcaron Ř LATIN CAPITAL LETTER R WITH CARON */
+ { 0x01d9, 0x016e }, /* Uring Ů LATIN CAPITAL LETTER U WITH RING ABOVE */
+ { 0x01db, 0x0170 }, /* Udoubleacute Ű LATIN CAPITAL LETTER U WITH DOUBLE ACUTE */
+ { 0x01de, 0x0162 }, /* Tcedilla Ţ LATIN CAPITAL LETTER T WITH CEDILLA */
+ { 0x01e0, 0x0155 }, /* racute ŕ LATIN SMALL LETTER R WITH ACUTE */
+ { 0x01e3, 0x0103 }, /* abreve ă LATIN SMALL LETTER A WITH BREVE */
+ { 0x01e5, 0x013a }, /* lacute ĺ LATIN SMALL LETTER L WITH ACUTE */
+ { 0x01e6, 0x0107 }, /* cacute ć LATIN SMALL LETTER C WITH ACUTE */
+ { 0x01e8, 0x010d }, /* ccaron č LATIN SMALL LETTER C WITH CARON */
+ { 0x01ea, 0x0119 }, /* eogonek ę LATIN SMALL LETTER E WITH OGONEK */
+ { 0x01ec, 0x011b }, /* ecaron ě LATIN SMALL LETTER E WITH CARON */
+ { 0x01ef, 0x010f }, /* dcaron ď LATIN SMALL LETTER D WITH CARON */
+ { 0x01f0, 0x0111 }, /* dstroke đ LATIN SMALL LETTER D WITH STROKE */
+ { 0x01f1, 0x0144 }, /* nacute ń LATIN SMALL LETTER N WITH ACUTE */
+ { 0x01f2, 0x0148 }, /* ncaron ň LATIN SMALL LETTER N WITH CARON */
+ { 0x01f5, 0x0151 }, /* odoubleacute ő LATIN SMALL LETTER O WITH DOUBLE ACUTE */
+ { 0x01f8, 0x0159 }, /* rcaron ř LATIN SMALL LETTER R WITH CARON */
+ { 0x01f9, 0x016f }, /* uring ů LATIN SMALL LETTER U WITH RING ABOVE */
+ { 0x01fb, 0x0171 }, /* udoubleacute ű LATIN SMALL LETTER U WITH DOUBLE ACUTE */
+ { 0x01fe, 0x0163 }, /* tcedilla ţ LATIN SMALL LETTER T WITH CEDILLA */
+ { 0x02a1, 0x0126 }, /* Hstroke Ħ LATIN CAPITAL LETTER H WITH STROKE */
+ { 0x02a6, 0x0124 }, /* Hcircumflex Ĥ LATIN CAPITAL LETTER H WITH CIRCUMFLEX */
+ { 0x02a9, 0x0130 }, /* Iabovedot İ LATIN CAPITAL LETTER I WITH DOT ABOVE */
+ { 0x02ab, 0x011e }, /* Gbreve Ğ LATIN CAPITAL LETTER G WITH BREVE */
+ { 0x02ac, 0x0134 }, /* Jcircumflex Ĵ LATIN CAPITAL LETTER J WITH CIRCUMFLEX */
+ { 0x02b1, 0x0127 }, /* hstroke ħ LATIN SMALL LETTER H WITH STROKE */
+ { 0x02b6, 0x0125 }, /* hcircumflex ĥ LATIN SMALL LETTER H WITH CIRCUMFLEX */
+ { 0x02b9, 0x0131 }, /* idotless ı LATIN SMALL LETTER DOTLESS I */
+ { 0x02bb, 0x011f }, /* gbreve ğ LATIN SMALL LETTER G WITH BREVE */
+ { 0x02bc, 0x0135 }, /* jcircumflex ĵ LATIN SMALL LETTER J WITH CIRCUMFLEX */
+ { 0x02c5, 0x010a }, /* Cabovedot Ċ LATIN CAPITAL LETTER C WITH DOT ABOVE */
+ { 0x02c6, 0x0108 }, /* Ccircumflex Ĉ LATIN CAPITAL LETTER C WITH CIRCUMFLEX */
+ { 0x02d5, 0x0120 }, /* Gabovedot Ġ LATIN CAPITAL LETTER G WITH DOT ABOVE */
+ { 0x02d8, 0x011c }, /* Gcircumflex Ĝ LATIN CAPITAL LETTER G WITH CIRCUMFLEX */
+ { 0x02dd, 0x016c }, /* Ubreve Ŭ LATIN CAPITAL LETTER U WITH BREVE */
+ { 0x02de, 0x015c }, /* Scircumflex Ŝ LATIN CAPITAL LETTER S WITH CIRCUMFLEX */
+ { 0x02e5, 0x010b }, /* cabovedot ċ LATIN SMALL LETTER C WITH DOT ABOVE */
+ { 0x02e6, 0x0109 }, /* ccircumflex ĉ LATIN SMALL LETTER C WITH CIRCUMFLEX */
+ { 0x02f5, 0x0121 }, /* gabovedot ġ LATIN SMALL LETTER G WITH DOT ABOVE */
+ { 0x02f8, 0x011d }, /* gcircumflex ĝ LATIN SMALL LETTER G WITH CIRCUMFLEX */
+ { 0x02fd, 0x016d }, /* ubreve ŭ LATIN SMALL LETTER U WITH BREVE */
+ { 0x02fe, 0x015d }, /* scircumflex ŝ LATIN SMALL LETTER S WITH CIRCUMFLEX */
+ { 0x03a2, 0x0138 }, /* kra ĸ LATIN SMALL LETTER KRA */
+ { 0x03a3, 0x0156 }, /* Rcedilla Ŗ LATIN CAPITAL LETTER R WITH CEDILLA */
+ { 0x03a5, 0x0128 }, /* Itilde Ĩ LATIN CAPITAL LETTER I WITH TILDE */
+ { 0x03a6, 0x013b }, /* Lcedilla Ļ LATIN CAPITAL LETTER L WITH CEDILLA */
+ { 0x03aa, 0x0112 }, /* Emacron Ē LATIN CAPITAL LETTER E WITH MACRON */
+ { 0x03ab, 0x0122 }, /* Gcedilla Ģ LATIN CAPITAL LETTER G WITH CEDILLA */
+ { 0x03ac, 0x0166 }, /* Tslash Ŧ LATIN CAPITAL LETTER T WITH STROKE */
+ { 0x03b3, 0x0157 }, /* rcedilla ŗ LATIN SMALL LETTER R WITH CEDILLA */
+ { 0x03b5, 0x0129 }, /* itilde ĩ LATIN SMALL LETTER I WITH TILDE */
+ { 0x03b6, 0x013c }, /* lcedilla ļ LATIN SMALL LETTER L WITH CEDILLA */
+ { 0x03ba, 0x0113 }, /* emacron ē LATIN SMALL LETTER E WITH MACRON */
+ { 0x03bb, 0x0123 }, /* gcedilla ģ LATIN SMALL LETTER G WITH CEDILLA */
+ { 0x03bc, 0x0167 }, /* tslash ŧ LATIN SMALL LETTER T WITH STROKE */
+ { 0x03bd, 0x014a }, /* ENG Ŋ LATIN CAPITAL LETTER ENG */
+ { 0x03bf, 0x014b }, /* eng ŋ LATIN SMALL LETTER ENG */
+ { 0x03c0, 0x0100 }, /* Amacron Ā LATIN CAPITAL LETTER A WITH MACRON */
+ { 0x03c7, 0x012e }, /* Iogonek Į LATIN CAPITAL LETTER I WITH OGONEK */
+ { 0x03cc, 0x0116 }, /* Eabovedot Ė LATIN CAPITAL LETTER E WITH DOT ABOVE */
+ { 0x03cf, 0x012a }, /* Imacron Ī LATIN CAPITAL LETTER I WITH MACRON */
+ { 0x03d1, 0x0145 }, /* Ncedilla Ņ LATIN CAPITAL LETTER N WITH CEDILLA */
+ { 0x03d2, 0x014c }, /* Omacron Ō LATIN CAPITAL LETTER O WITH MACRON */
+ { 0x03d3, 0x0136 }, /* Kcedilla Ķ LATIN CAPITAL LETTER K WITH CEDILLA */
+ { 0x03d9, 0x0172 }, /* Uogonek Ų LATIN CAPITAL LETTER U WITH OGONEK */
+ { 0x03dd, 0x0168 }, /* Utilde Ũ LATIN CAPITAL LETTER U WITH TILDE */
+ { 0x03de, 0x016a }, /* Umacron Ū LATIN CAPITAL LETTER U WITH MACRON */
+ { 0x03e0, 0x0101 }, /* amacron ā LATIN SMALL LETTER A WITH MACRON */
+ { 0x03e7, 0x012f }, /* iogonek į LATIN SMALL LETTER I WITH OGONEK */
+ { 0x03ec, 0x0117 }, /* eabovedot ė LATIN SMALL LETTER E WITH DOT ABOVE */
+ { 0x03ef, 0x012b }, /* imacron ī LATIN SMALL LETTER I WITH MACRON */
+ { 0x03f1, 0x0146 }, /* ncedilla ņ LATIN SMALL LETTER N WITH CEDILLA */
+ { 0x03f2, 0x014d }, /* omacron ō LATIN SMALL LETTER O WITH MACRON */
+ { 0x03f3, 0x0137 }, /* kcedilla ķ LATIN SMALL LETTER K WITH CEDILLA */
+ { 0x03f9, 0x0173 }, /* uogonek ų LATIN SMALL LETTER U WITH OGONEK */
+ { 0x03fd, 0x0169 }, /* utilde ũ LATIN SMALL LETTER U WITH TILDE */
+ { 0x03fe, 0x016b }, /* umacron ū LATIN SMALL LETTER U WITH MACRON */
+ { 0x08f6, 0x0192 }, /* function ƒ LATIN SMALL LETTER F WITH HOOK */
+ { 0x13bc, 0x0152 }, /* OE Œ LATIN CAPITAL LIGATURE OE */
+ { 0x13bd, 0x0153 }, /* oe œ LATIN SMALL LIGATURE OE */
+ { 0x13be, 0x0178 }, /* Ydiaeresis Ÿ LATIN CAPITAL LETTER Y WITH DIAERESIS */
+
+ { 0x01b7, 0x02c7 }, /* caron ˇ CARON */
+ { 0x01a2, 0x02d8 }, /* breve ˘ BREVE */
+ { 0x01ff, 0x02d9 }, /* abovedot ˙ DOT ABOVE */
+ { 0x01b2, 0x02db }, /* ogonek ˛ OGONEK */
+ { 0x01bd, 0x02dd }, /* doubleacute ˝ DOUBLE ACUTE ACCENT */
+
+ { 0x07ae, 0x0385 }, /* Greek_accentdieresis ΅ GREEK DIALYTIKA TONOS */
+ { 0x07a1, 0x0386 }, /* Greek_ALPHAaccent Ά GREEK CAPITAL LETTER ALPHA WITH TONOS */
+ { 0x07a2, 0x0388 }, /* Greek_EPSILONaccent Έ GREEK CAPITAL LETTER EPSILON WITH TONOS */
+ { 0x07a3, 0x0389 }, /* Greek_ETAaccent Ή GREEK CAPITAL LETTER ETA WITH TONOS */
+ { 0x07a4, 0x038a }, /* Greek_IOTAaccent Ί GREEK CAPITAL LETTER IOTA WITH TONOS */
+ { 0x07a7, 0x038c }, /* Greek_OMICRONaccent Ό GREEK CAPITAL LETTER OMICRON WITH TONOS */
+ { 0x07a8, 0x038e }, /* Greek_UPSILONaccent Ύ GREEK CAPITAL LETTER UPSILON WITH TONOS */
+ { 0x07ab, 0x038f }, /* Greek_OMEGAaccent Ώ GREEK CAPITAL LETTER OMEGA WITH TONOS */
+ { 0x07b6, 0x0390 }, /* Greek_iotaaccentdieresis ΐ GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS */
+ { 0x07c1, 0x0391 }, /* Greek_ALPHA Α GREEK CAPITAL LETTER ALPHA */
+ { 0x07c2, 0x0392 }, /* Greek_BETA Β GREEK CAPITAL LETTER BETA */
+ { 0x07c3, 0x0393 }, /* Greek_GAMMA Γ GREEK CAPITAL LETTER GAMMA */
+ { 0x07c4, 0x0394 }, /* Greek_DELTA Δ GREEK CAPITAL LETTER DELTA */
+ { 0x07c5, 0x0395 }, /* Greek_EPSILON Ε GREEK CAPITAL LETTER EPSILON */
+ { 0x07c6, 0x0396 }, /* Greek_ZETA Ζ GREEK CAPITAL LETTER ZETA */
+ { 0x07c7, 0x0397 }, /* Greek_ETA Η GREEK CAPITAL LETTER ETA */
+ { 0x07c8, 0x0398 }, /* Greek_THETA Θ GREEK CAPITAL LETTER THETA */
+ { 0x07c9, 0x0399 }, /* Greek_IOTA Ι GREEK CAPITAL LETTER IOTA */
+ { 0x07ca, 0x039a }, /* Greek_KAPPA Κ GREEK CAPITAL LETTER KAPPA */
+ { 0x07cb, 0x039b }, /* Greek_LAMBDA Λ GREEK CAPITAL LETTER LAMDA */
+ { 0x07cc, 0x039c }, /* Greek_MU Μ GREEK CAPITAL LETTER MU */
+ { 0x07cd, 0x039d }, /* Greek_NU Ν GREEK CAPITAL LETTER NU */
+ { 0x07ce, 0x039e }, /* Greek_XI Ξ GREEK CAPITAL LETTER XI */
+ { 0x07cf, 0x039f }, /* Greek_OMICRON Ο GREEK CAPITAL LETTER OMICRON */
+ { 0x07d0, 0x03a0 }, /* Greek_PI Π GREEK CAPITAL LETTER PI */
+ { 0x07d1, 0x03a1 }, /* Greek_RHO Ρ GREEK CAPITAL LETTER RHO */
+ { 0x07d2, 0x03a3 }, /* Greek_SIGMA Σ GREEK CAPITAL LETTER SIGMA */
+ { 0x07d4, 0x03a4 }, /* Greek_TAU Τ GREEK CAPITAL LETTER TAU */
+ { 0x07d5, 0x03a5 }, /* Greek_UPSILON Υ GREEK CAPITAL LETTER UPSILON */
+ { 0x07d6, 0x03a6 }, /* Greek_PHI Φ GREEK CAPITAL LETTER PHI */
+ { 0x07d7, 0x03a7 }, /* Greek_CHI Χ GREEK CAPITAL LETTER CHI */
+ { 0x07d8, 0x03a8 }, /* Greek_PSI Ψ GREEK CAPITAL LETTER PSI */
+ { 0x07d9, 0x03a9 }, /* Greek_OMEGA Ω GREEK CAPITAL LETTER OMEGA */
+ { 0x07a5, 0x03aa }, /* Greek_IOTAdiaeresis Ϊ GREEK CAPITAL LETTER IOTA WITH DIALYTIKA */
+ { 0x07a9, 0x03ab }, /* Greek_UPSILONdieresis Ϋ GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA */
+ { 0x07b1, 0x03ac }, /* Greek_alphaaccent ά GREEK SMALL LETTER ALPHA WITH TONOS */
+ { 0x07b2, 0x03ad }, /* Greek_epsilonaccent έ GREEK SMALL LETTER EPSILON WITH TONOS */
+ { 0x07b3, 0x03ae }, /* Greek_etaaccent ή GREEK SMALL LETTER ETA WITH TONOS */
+ { 0x07b4, 0x03af }, /* Greek_iotaaccent ί GREEK SMALL LETTER IOTA WITH TONOS */
+ { 0x07ba, 0x03b0 }, /* Greek_upsilonaccentdieresis ΰ GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS */
+ { 0x07e1, 0x03b1 }, /* Greek_alpha α GREEK SMALL LETTER ALPHA */
+ { 0x07e2, 0x03b2 }, /* Greek_beta β GREEK SMALL LETTER BETA */
+ { 0x07e3, 0x03b3 }, /* Greek_gamma γ GREEK SMALL LETTER GAMMA */
+ { 0x07e4, 0x03b4 }, /* Greek_delta δ GREEK SMALL LETTER DELTA */
+ { 0x07e5, 0x03b5 }, /* Greek_epsilon ε GREEK SMALL LETTER EPSILON */
+ { 0x07e6, 0x03b6 }, /* Greek_zeta ζ GREEK SMALL LETTER ZETA */
+ { 0x07e7, 0x03b7 }, /* Greek_eta η GREEK SMALL LETTER ETA */
+ { 0x07e8, 0x03b8 }, /* Greek_theta θ GREEK SMALL LETTER THETA */
+ { 0x07e9, 0x03b9 }, /* Greek_iota ι GREEK SMALL LETTER IOTA */
+ { 0x07ea, 0x03ba }, /* Greek_kappa κ GREEK SMALL LETTER KAPPA */
+ { 0x07eb, 0x03bb }, /* Greek_lambda λ GREEK SMALL LETTER LAMDA */
+ { 0x07ec, 0x03bc }, /* Greek_mu μ GREEK SMALL LETTER MU */
+ { 0x07ed, 0x03bd }, /* Greek_nu ν GREEK SMALL LETTER NU */
+ { 0x07ee, 0x03be }, /* Greek_xi ξ GREEK SMALL LETTER XI */
+ { 0x07ef, 0x03bf }, /* Greek_omicron ο GREEK SMALL LETTER OMICRON */
+ { 0x07f0, 0x03c0 }, /* Greek_pi π GREEK SMALL LETTER PI */
+ { 0x07f1, 0x03c1 }, /* Greek_rho ρ GREEK SMALL LETTER RHO */
+ { 0x07f3, 0x03c2 }, /* Greek_finalsmallsigma ς GREEK SMALL LETTER FINAL SIGMA */
+ { 0x07f2, 0x03c3 }, /* Greek_sigma σ GREEK SMALL LETTER SIGMA */
+ { 0x07f4, 0x03c4 }, /* Greek_tau τ GREEK SMALL LETTER TAU */
+ { 0x07f5, 0x03c5 }, /* Greek_upsilon υ GREEK SMALL LETTER UPSILON */
+ { 0x07f6, 0x03c6 }, /* Greek_phi φ GREEK SMALL LETTER PHI */
+ { 0x07f7, 0x03c7 }, /* Greek_chi χ GREEK SMALL LETTER CHI */
+ { 0x07f8, 0x03c8 }, /* Greek_psi ψ GREEK SMALL LETTER PSI */
+ { 0x07f9, 0x03c9 }, /* Greek_omega ω GREEK SMALL LETTER OMEGA */
+ { 0x07b5, 0x03ca }, /* Greek_iotadieresis ϊ GREEK SMALL LETTER IOTA WITH DIALYTIKA */
+ { 0x07b9, 0x03cb }, /* Greek_upsilondieresis ϋ GREEK SMALL LETTER UPSILON WITH DIALYTIKA */
+ { 0x07b7, 0x03cc }, /* Greek_omicronaccent ό GREEK SMALL LETTER OMICRON WITH TONOS */
+ { 0x07b8, 0x03cd }, /* Greek_upsilonaccent ύ GREEK SMALL LETTER UPSILON WITH TONOS */
+ { 0x07bb, 0x03ce }, /* Greek_omegaaccent ώ GREEK SMALL LETTER OMEGA WITH TONOS */
+
+ { 0x06b3, 0x0401 }, /* Cyrillic_IO Ё CYRILLIC CAPITAL LETTER IO */
+ { 0x06b1, 0x0402 }, /* Serbian_DJE Ђ CYRILLIC CAPITAL LETTER DJE */
+ { 0x06b2, 0x0403 }, /* Macedonia_GJE Ѓ CYRILLIC CAPITAL LETTER GJE */
+ { 0x06b4, 0x0404 }, /* Ukrainian_IE Є CYRILLIC CAPITAL LETTER UKRAINIAN IE */
+ { 0x06b5, 0x0405 }, /* Macedonia_DSE Ѕ CYRILLIC CAPITAL LETTER DZE */
+ { 0x06b6, 0x0406 }, /* Ukrainian_I І CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I */
+ { 0x06b7, 0x0407 }, /* Ukrainian_YI Ї CYRILLIC CAPITAL LETTER YI */
+ { 0x06b8, 0x0408 }, /* Cyrillic_JE Ј CYRILLIC CAPITAL LETTER JE */
+ { 0x06b9, 0x0409 }, /* Cyrillic_LJE Љ CYRILLIC CAPITAL LETTER LJE */
+ { 0x06ba, 0x040a }, /* Cyrillic_NJE Њ CYRILLIC CAPITAL LETTER NJE */
+ { 0x06bb, 0x040b }, /* Serbian_TSHE Ћ CYRILLIC CAPITAL LETTER TSHE */
+ { 0x06bc, 0x040c }, /* Macedonia_KJE Ќ CYRILLIC CAPITAL LETTER KJE */
+ { 0x06be, 0x040e }, /* Byelorussian_SHORTU Ў CYRILLIC CAPITAL LETTER SHORT U */
+ { 0x06bf, 0x040f }, /* Cyrillic_DZHE Џ CYRILLIC CAPITAL LETTER DZHE */
+ { 0x06e1, 0x0410 }, /* Cyrillic_A А CYRILLIC CAPITAL LETTER A */
+ { 0x06e2, 0x0411 }, /* Cyrillic_BE Б CYRILLIC CAPITAL LETTER BE */
+ { 0x06f7, 0x0412 }, /* Cyrillic_VE В CYRILLIC CAPITAL LETTER VE */
+ { 0x06e7, 0x0413 }, /* Cyrillic_GHE Г CYRILLIC CAPITAL LETTER GHE */
+ { 0x06e4, 0x0414 }, /* Cyrillic_DE Д CYRILLIC CAPITAL LETTER DE */
+ { 0x06e5, 0x0415 }, /* Cyrillic_IE Е CYRILLIC CAPITAL LETTER IE */
+ { 0x06f6, 0x0416 }, /* Cyrillic_ZHE Ж CYRILLIC CAPITAL LETTER ZHE */
+ { 0x06fa, 0x0417 }, /* Cyrillic_ZE З CYRILLIC CAPITAL LETTER ZE */
+ { 0x06e9, 0x0418 }, /* Cyrillic_I И CYRILLIC CAPITAL LETTER I */
+ { 0x06ea, 0x0419 }, /* Cyrillic_SHORTI Й CYRILLIC CAPITAL LETTER SHORT I */
+ { 0x06eb, 0x041a }, /* Cyrillic_KA К CYRILLIC CAPITAL LETTER KA */
+ { 0x06ec, 0x041b }, /* Cyrillic_EL Л CYRILLIC CAPITAL LETTER EL */
+ { 0x06ed, 0x041c }, /* Cyrillic_EM М CYRILLIC CAPITAL LETTER EM */
+ { 0x06ee, 0x041d }, /* Cyrillic_EN Н CYRILLIC CAPITAL LETTER EN */
+ { 0x06ef, 0x041e }, /* Cyrillic_O О CYRILLIC CAPITAL LETTER O */
+ { 0x06f0, 0x041f }, /* Cyrillic_PE П CYRILLIC CAPITAL LETTER PE */
+ { 0x06f2, 0x0420 }, /* Cyrillic_ER Р CYRILLIC CAPITAL LETTER ER */
+ { 0x06f3, 0x0421 }, /* Cyrillic_ES С CYRILLIC CAPITAL LETTER ES */
+ { 0x06f4, 0x0422 }, /* Cyrillic_TE Т CYRILLIC CAPITAL LETTER TE */
+ { 0x06f5, 0x0423 }, /* Cyrillic_U У CYRILLIC CAPITAL LETTER U */
+ { 0x06e6, 0x0424 }, /* Cyrillic_EF Ф CYRILLIC CAPITAL LETTER EF */
+ { 0x06e8, 0x0425 }, /* Cyrillic_HA Х CYRILLIC CAPITAL LETTER HA */
+ { 0x06e3, 0x0426 }, /* Cyrillic_TSE Ц CYRILLIC CAPITAL LETTER TSE */
+ { 0x06fe, 0x0427 }, /* Cyrillic_CHE Ч CYRILLIC CAPITAL LETTER CHE */
+ { 0x06fb, 0x0428 }, /* Cyrillic_SHA Ш CYRILLIC CAPITAL LETTER SHA */
+ { 0x06fd, 0x0429 }, /* Cyrillic_SHCHA Щ CYRILLIC CAPITAL LETTER SHCHA */
+ { 0x06ff, 0x042a }, /* Cyrillic_HARDSIGN Ъ CYRILLIC CAPITAL LETTER HARD SIGN */
+ { 0x06f9, 0x042b }, /* Cyrillic_YERU Ы CYRILLIC CAPITAL LETTER YERU */
+ { 0x06f8, 0x042c }, /* Cyrillic_SOFTSIGN Ь CYRILLIC CAPITAL LETTER SOFT SIGN */
+ { 0x06fc, 0x042d }, /* Cyrillic_E Э CYRILLIC CAPITAL LETTER E */
+ { 0x06e0, 0x042e }, /* Cyrillic_YU Ю CYRILLIC CAPITAL LETTER YU */
+ { 0x06f1, 0x042f }, /* Cyrillic_YA Я CYRILLIC CAPITAL LETTER YA */
+ { 0x06c1, 0x0430 }, /* Cyrillic_a а CYRILLIC SMALL LETTER A */
+ { 0x06c2, 0x0431 }, /* Cyrillic_be б CYRILLIC SMALL LETTER BE */
+ { 0x06d7, 0x0432 }, /* Cyrillic_ve в CYRILLIC SMALL LETTER VE */
+ { 0x06c7, 0x0433 }, /* Cyrillic_ghe г CYRILLIC SMALL LETTER GHE */
+ { 0x06c4, 0x0434 }, /* Cyrillic_de д CYRILLIC SMALL LETTER DE */
+ { 0x06c5, 0x0435 }, /* Cyrillic_ie е CYRILLIC SMALL LETTER IE */
+ { 0x06d6, 0x0436 }, /* Cyrillic_zhe ж CYRILLIC SMALL LETTER ZHE */
+ { 0x06da, 0x0437 }, /* Cyrillic_ze з CYRILLIC SMALL LETTER ZE */
+ { 0x06c9, 0x0438 }, /* Cyrillic_i и CYRILLIC SMALL LETTER I */
+ { 0x06ca, 0x0439 }, /* Cyrillic_shorti й CYRILLIC SMALL LETTER SHORT I */
+ { 0x06cb, 0x043a }, /* Cyrillic_ka к CYRILLIC SMALL LETTER KA */
+ { 0x06cc, 0x043b }, /* Cyrillic_el л CYRILLIC SMALL LETTER EL */
+ { 0x06cd, 0x043c }, /* Cyrillic_em м CYRILLIC SMALL LETTER EM */
+ { 0x06ce, 0x043d }, /* Cyrillic_en н CYRILLIC SMALL LETTER EN */
+ { 0x06cf, 0x043e }, /* Cyrillic_o о CYRILLIC SMALL LETTER O */
+ { 0x06d0, 0x043f }, /* Cyrillic_pe п CYRILLIC SMALL LETTER PE */
+ { 0x06d2, 0x0440 }, /* Cyrillic_er р CYRILLIC SMALL LETTER ER */
+ { 0x06d3, 0x0441 }, /* Cyrillic_es с CYRILLIC SMALL LETTER ES */
+ { 0x06d4, 0x0442 }, /* Cyrillic_te т CYRILLIC SMALL LETTER TE */
+ { 0x06d5, 0x0443 }, /* Cyrillic_u у CYRILLIC SMALL LETTER U */
+ { 0x06c6, 0x0444 }, /* Cyrillic_ef ф CYRILLIC SMALL LETTER EF */
+ { 0x06c8, 0x0445 }, /* Cyrillic_ha х CYRILLIC SMALL LETTER HA */
+ { 0x06c3, 0x0446 }, /* Cyrillic_tse ц CYRILLIC SMALL LETTER TSE */
+ { 0x06de, 0x0447 }, /* Cyrillic_che ч CYRILLIC SMALL LETTER CHE */
+ { 0x06db, 0x0448 }, /* Cyrillic_sha ш CYRILLIC SMALL LETTER SHA */
+ { 0x06dd, 0x0449 }, /* Cyrillic_shcha щ CYRILLIC SMALL LETTER SHCHA */
+ { 0x06df, 0x044a }, /* Cyrillic_hardsign ъ CYRILLIC SMALL LETTER HARD SIGN */
+ { 0x06d9, 0x044b }, /* Cyrillic_yeru ы CYRILLIC SMALL LETTER YERU */
+ { 0x06d8, 0x044c }, /* Cyrillic_softsign ь CYRILLIC SMALL LETTER SOFT SIGN */
+ { 0x06dc, 0x044d }, /* Cyrillic_e э CYRILLIC SMALL LETTER E */
+ { 0x06c0, 0x044e }, /* Cyrillic_yu ю CYRILLIC SMALL LETTER YU */
+ { 0x06d1, 0x044f }, /* Cyrillic_ya я CYRILLIC SMALL LETTER YA */
+ { 0x06a3, 0x0451 }, /* Cyrillic_io ё CYRILLIC SMALL LETTER IO */
+ { 0x06a1, 0x0452 }, /* Serbian_dje ђ CYRILLIC SMALL LETTER DJE */
+ { 0x06a2, 0x0453 }, /* Macedonia_gje ѓ CYRILLIC SMALL LETTER GJE */
+ { 0x06a4, 0x0454 }, /* Ukrainian_ie є CYRILLIC SMALL LETTER UKRAINIAN IE */
+ { 0x06a5, 0x0455 }, /* Macedonia_dse ѕ CYRILLIC SMALL LETTER DZE */
+ { 0x06a6, 0x0456 }, /* Ukrainian_i і CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I */
+ { 0x06a7, 0x0457 }, /* Ukrainian_yi ї CYRILLIC SMALL LETTER YI */
+ { 0x06a8, 0x0458 }, /* Cyrillic_je ј CYRILLIC SMALL LETTER JE */
+ { 0x06a9, 0x0459 }, /* Cyrillic_lje љ CYRILLIC SMALL LETTER LJE */
+ { 0x06aa, 0x045a }, /* Cyrillic_nje њ CYRILLIC SMALL LETTER NJE */
+ { 0x06ab, 0x045b }, /* Serbian_tshe ћ CYRILLIC SMALL LETTER TSHE */
+ { 0x06ac, 0x045c }, /* Macedonia_kje ќ CYRILLIC SMALL LETTER KJE */
+ { 0x06ae, 0x045e }, /* Byelorussian_shortu ў CYRILLIC SMALL LETTER SHORT U */
+ { 0x06af, 0x045f }, /* Cyrillic_dzhe џ CYRILLIC SMALL LETTER DZHE */
+
+ { 0x0ce0, 0x05d0 }, /* hebrew_aleph א HEBREW LETTER ALEF */
+ { 0x0ce1, 0x05d1 }, /* hebrew_bet ב HEBREW LETTER BET */
+ { 0x0ce2, 0x05d2 }, /* hebrew_gimel ג HEBREW LETTER GIMEL */
+ { 0x0ce3, 0x05d3 }, /* hebrew_dalet ד HEBREW LETTER DALET */
+ { 0x0ce4, 0x05d4 }, /* hebrew_he ה HEBREW LETTER HE */
+ { 0x0ce5, 0x05d5 }, /* hebrew_waw ו HEBREW LETTER VAV */
+ { 0x0ce6, 0x05d6 }, /* hebrew_zain ז HEBREW LETTER ZAYIN */
+ { 0x0ce7, 0x05d7 }, /* hebrew_chet ח HEBREW LETTER HET */
+ { 0x0ce8, 0x05d8 }, /* hebrew_tet ט HEBREW LETTER TET */
+ { 0x0ce9, 0x05d9 }, /* hebrew_yod י HEBREW LETTER YOD */
+ { 0x0cea, 0x05da }, /* hebrew_finalkaph ך HEBREW LETTER FINAL KAF */
+ { 0x0ceb, 0x05db }, /* hebrew_kaph כ HEBREW LETTER KAF */
+ { 0x0cec, 0x05dc }, /* hebrew_lamed ל HEBREW LETTER LAMED */
+ { 0x0ced, 0x05dd }, /* hebrew_finalmem ם HEBREW LETTER FINAL MEM */
+ { 0x0cee, 0x05de }, /* hebrew_mem מ HEBREW LETTER MEM */
+ { 0x0cef, 0x05df }, /* hebrew_finalnun ן HEBREW LETTER FINAL NUN */
+ { 0x0cf0, 0x05e0 }, /* hebrew_nun נ HEBREW LETTER NUN */
+ { 0x0cf1, 0x05e1 }, /* hebrew_samech ס HEBREW LETTER SAMEKH */
+ { 0x0cf2, 0x05e2 }, /* hebrew_ayin ע HEBREW LETTER AYIN */
+ { 0x0cf3, 0x05e3 }, /* hebrew_finalpe ף HEBREW LETTER FINAL PE */
+ { 0x0cf4, 0x05e4 }, /* hebrew_pe פ HEBREW LETTER PE */
+ { 0x0cf5, 0x05e5 }, /* hebrew_finalzade ץ HEBREW LETTER FINAL TSADI */
+ { 0x0cf6, 0x05e6 }, /* hebrew_zade צ HEBREW LETTER TSADI */
+ { 0x0cf7, 0x05e7 }, /* hebrew_qoph ק HEBREW LETTER QOF */
+ { 0x0cf8, 0x05e8 }, /* hebrew_resh ר HEBREW LETTER RESH */
+ { 0x0cf9, 0x05e9 }, /* hebrew_shin ש HEBREW LETTER SHIN */
+ { 0x0cfa, 0x05ea }, /* hebrew_taw ת HEBREW LETTER TAV */
+
+ { 0x05ac, 0x060c }, /* Arabic_comma ، ARABIC COMMA */
+ { 0x05bb, 0x061b }, /* Arabic_semicolon ؛ ARABIC SEMICOLON */
+ { 0x05bf, 0x061f }, /* Arabic_question_mark ؟ ARABIC QUESTION MARK */
+ { 0x05c1, 0x0621 }, /* Arabic_hamza ء ARABIC LETTER HAMZA */
+ { 0x05c2, 0x0622 }, /* Arabic_maddaonalef آ ARABIC LETTER ALEF WITH MADDA ABOVE */
+ { 0x05c3, 0x0623 }, /* Arabic_hamzaonalef أ ARABIC LETTER ALEF WITH HAMZA ABOVE */
+ { 0x05c4, 0x0624 }, /* Arabic_hamzaonwaw ؤ ARABIC LETTER WAW WITH HAMZA ABOVE */
+ { 0x05c5, 0x0625 }, /* Arabic_hamzaunderalef إ ARABIC LETTER ALEF WITH HAMZA BELOW */
+ { 0x05c6, 0x0626 }, /* Arabic_hamzaonyeh ئ ARABIC LETTER YEH WITH HAMZA ABOVE */
+ { 0x05c7, 0x0627 }, /* Arabic_alef ا ARABIC LETTER ALEF */
+ { 0x05c8, 0x0628 }, /* Arabic_beh ب ARABIC LETTER BEH */
+ { 0x05c9, 0x0629 }, /* Arabic_tehmarbuta ة ARABIC LETTER TEH MARBUTA */
+ { 0x05ca, 0x062a }, /* Arabic_teh ت ARABIC LETTER TEH */
+ { 0x05cb, 0x062b }, /* Arabic_theh ث ARABIC LETTER THEH */
+ { 0x05cc, 0x062c }, /* Arabic_jeem ج ARABIC LETTER JEEM */
+ { 0x05cd, 0x062d }, /* Arabic_hah ح ARABIC LETTER HAH */
+ { 0x05ce, 0x062e }, /* Arabic_khah خ ARABIC LETTER KHAH */
+ { 0x05cf, 0x062f }, /* Arabic_dal د ARABIC LETTER DAL */
+ { 0x05d0, 0x0630 }, /* Arabic_thal ذ ARABIC LETTER THAL */
+ { 0x05d1, 0x0631 }, /* Arabic_ra ر ARABIC LETTER REH */
+ { 0x05d2, 0x0632 }, /* Arabic_zain ز ARABIC LETTER ZAIN */
+ { 0x05d3, 0x0633 }, /* Arabic_seen س ARABIC LETTER SEEN */
+ { 0x05d4, 0x0634 }, /* Arabic_sheen ش ARABIC LETTER SHEEN */
+ { 0x05d5, 0x0635 }, /* Arabic_sad ص ARABIC LETTER SAD */
+ { 0x05d6, 0x0636 }, /* Arabic_dad ض ARABIC LETTER DAD */
+ { 0x05d7, 0x0637 }, /* Arabic_tah ط ARABIC LETTER TAH */
+ { 0x05d8, 0x0638 }, /* Arabic_zah ظ ARABIC LETTER ZAH */
+ { 0x05d9, 0x0639 }, /* Arabic_ain ع ARABIC LETTER AIN */
+ { 0x05da, 0x063a }, /* Arabic_ghain غ ARABIC LETTER GHAIN */
+ { 0x05e0, 0x0640 }, /* Arabic_tatweel ـ ARABIC TATWEEL */
+ { 0x05e1, 0x0641 }, /* Arabic_feh ف ARABIC LETTER FEH */
+ { 0x05e2, 0x0642 }, /* Arabic_qaf ق ARABIC LETTER QAF */
+ { 0x05e3, 0x0643 }, /* Arabic_kaf ك ARABIC LETTER KAF */
+ { 0x05e4, 0x0644 }, /* Arabic_lam ل ARABIC LETTER LAM */
+ { 0x05e5, 0x0645 }, /* Arabic_meem م ARABIC LETTER MEEM */
+ { 0x05e6, 0x0646 }, /* Arabic_noon ن ARABIC LETTER NOON */
+ { 0x05e7, 0x0647 }, /* Arabic_ha ه ARABIC LETTER HEH */
+ { 0x05e8, 0x0648 }, /* Arabic_waw و ARABIC LETTER WAW */
+ { 0x05e9, 0x0649 }, /* Arabic_alefmaksura ى ARABIC LETTER ALEF MAKSURA */
+ { 0x05ea, 0x064a }, /* Arabic_yeh ي ARABIC LETTER YEH */
+ { 0x05eb, 0x064b }, /* Arabic_fathatan ً ARABIC FATHATAN */
+ { 0x05ec, 0x064c }, /* Arabic_dammatan ٌ ARABIC DAMMATAN */
+ { 0x05ed, 0x064d }, /* Arabic_kasratan ٍ ARABIC KASRATAN */
+ { 0x05ee, 0x064e }, /* Arabic_fatha َ ARABIC FATHA */
+ { 0x05ef, 0x064f }, /* Arabic_damma ُ ARABIC DAMMA */
+ { 0x05f0, 0x0650 }, /* Arabic_kasra ِ ARABIC KASRA */
+ { 0x05f1, 0x0651 }, /* Arabic_shadda ّ ARABIC SHADDA */
+ { 0x05f2, 0x0652 }, /* Arabic_sukun ْ ARABIC SUKUN */
+
+ { 0x0da1, 0x0e01 }, /* Thai_kokai ก THAI CHARACTER KO KAI */
+ { 0x0da2, 0x0e02 }, /* Thai_khokhai ข THAI CHARACTER KHO KHAI */
+ { 0x0da3, 0x0e03 }, /* Thai_khokhuat ฃ THAI CHARACTER KHO KHUAT */
+ { 0x0da4, 0x0e04 }, /* Thai_khokhwai ค THAI CHARACTER KHO KHWAI */
+ { 0x0da5, 0x0e05 }, /* Thai_khokhon ฅ THAI CHARACTER KHO KHON */
+ { 0x0da6, 0x0e06 }, /* Thai_khorakhang ฆ THAI CHARACTER KHO RAKHANG */
+ { 0x0da7, 0x0e07 }, /* Thai_ngongu ง THAI CHARACTER NGO NGU */
+ { 0x0da8, 0x0e08 }, /* Thai_chochan จ THAI CHARACTER CHO CHAN */
+ { 0x0da9, 0x0e09 }, /* Thai_choching ฉ THAI CHARACTER CHO CHING */
+ { 0x0daa, 0x0e0a }, /* Thai_chochang ช THAI CHARACTER CHO CHANG */
+ { 0x0dab, 0x0e0b }, /* Thai_soso ซ THAI CHARACTER SO SO */
+ { 0x0dac, 0x0e0c }, /* Thai_chochoe ฌ THAI CHARACTER CHO CHOE */
+ { 0x0dad, 0x0e0d }, /* Thai_yoying ญ THAI CHARACTER YO YING */
+ { 0x0dae, 0x0e0e }, /* Thai_dochada ฎ THAI CHARACTER DO CHADA */
+ { 0x0daf, 0x0e0f }, /* Thai_topatak ฏ THAI CHARACTER TO PATAK */
+ { 0x0db0, 0x0e10 }, /* Thai_thothan ฐ THAI CHARACTER THO THAN */
+ { 0x0db1, 0x0e11 }, /* Thai_thonangmontho ฑ THAI CHARACTER THO NANGMONTHO */
+ { 0x0db2, 0x0e12 }, /* Thai_thophuthao ฒ THAI CHARACTER THO PHUTHAO */
+ { 0x0db3, 0x0e13 }, /* Thai_nonen ณ THAI CHARACTER NO NEN */
+ { 0x0db4, 0x0e14 }, /* Thai_dodek ด THAI CHARACTER DO DEK */
+ { 0x0db5, 0x0e15 }, /* Thai_totao ต THAI CHARACTER TO TAO */
+ { 0x0db6, 0x0e16 }, /* Thai_thothung ถ THAI CHARACTER THO THUNG */
+ { 0x0db7, 0x0e17 }, /* Thai_thothahan ท THAI CHARACTER THO THAHAN */
+ { 0x0db8, 0x0e18 }, /* Thai_thothong ธ THAI CHARACTER THO THONG */
+ { 0x0db9, 0x0e19 }, /* Thai_nonu น THAI CHARACTER NO NU */
+ { 0x0dba, 0x0e1a }, /* Thai_bobaimai บ THAI CHARACTER BO BAIMAI */
+ { 0x0dbb, 0x0e1b }, /* Thai_popla ป THAI CHARACTER PO PLA */
+ { 0x0dbc, 0x0e1c }, /* Thai_phophung ผ THAI CHARACTER PHO PHUNG */
+ { 0x0dbd, 0x0e1d }, /* Thai_fofa ฝ THAI CHARACTER FO FA */
+ { 0x0dbe, 0x0e1e }, /* Thai_phophan พ THAI CHARACTER PHO PHAN */
+ { 0x0dbf, 0x0e1f }, /* Thai_fofan ฟ THAI CHARACTER FO FAN */
+ { 0x0dc0, 0x0e20 }, /* Thai_phosamphao ภ THAI CHARACTER PHO SAMPHAO */
+ { 0x0dc1, 0x0e21 }, /* Thai_moma ม THAI CHARACTER MO MA */
+ { 0x0dc2, 0x0e22 }, /* Thai_yoyak ย THAI CHARACTER YO YAK */
+ { 0x0dc3, 0x0e23 }, /* Thai_rorua ร THAI CHARACTER RO RUA */
+ { 0x0dc4, 0x0e24 }, /* Thai_ru ฤ THAI CHARACTER RU */
+ { 0x0dc5, 0x0e25 }, /* Thai_loling ล THAI CHARACTER LO LING */
+ { 0x0dc6, 0x0e26 }, /* Thai_lu ฦ THAI CHARACTER LU */
+ { 0x0dc7, 0x0e27 }, /* Thai_wowaen ว THAI CHARACTER WO WAEN */
+ { 0x0dc8, 0x0e28 }, /* Thai_sosala ศ THAI CHARACTER SO SALA */
+ { 0x0dc9, 0x0e29 }, /* Thai_sorusi ษ THAI CHARACTER SO RUSI */
+ { 0x0dca, 0x0e2a }, /* Thai_sosua ส THAI CHARACTER SO SUA */
+ { 0x0dcb, 0x0e2b }, /* Thai_hohip ห THAI CHARACTER HO HIP */
+ { 0x0dcc, 0x0e2c }, /* Thai_lochula ฬ THAI CHARACTER LO CHULA */
+ { 0x0dcd, 0x0e2d }, /* Thai_oang อ THAI CHARACTER O ANG */
+ { 0x0dce, 0x0e2e }, /* Thai_honokhuk ฮ THAI CHARACTER HO NOKHUK */
+ { 0x0dcf, 0x0e2f }, /* Thai_paiyannoi ฯ THAI CHARACTER PAIYANNOI */
+ { 0x0dd0, 0x0e30 }, /* Thai_saraa ะ THAI CHARACTER SARA A */
+ { 0x0dd1, 0x0e31 }, /* Thai_maihanakat ั THAI CHARACTER MAI HAN-AKAT */
+ { 0x0dd2, 0x0e32 }, /* Thai_saraaa า THAI CHARACTER SARA AA */
+ { 0x0dd3, 0x0e33 }, /* Thai_saraam ำ THAI CHARACTER SARA AM */
+ { 0x0dd4, 0x0e34 }, /* Thai_sarai ิ THAI CHARACTER SARA I */
+ { 0x0dd5, 0x0e35 }, /* Thai_saraii ี THAI CHARACTER SARA II */
+ { 0x0dd6, 0x0e36 }, /* Thai_saraue ึ THAI CHARACTER SARA UE */
+ { 0x0dd7, 0x0e37 }, /* Thai_sarauee ื THAI CHARACTER SARA UEE */
+ { 0x0dd8, 0x0e38 }, /* Thai_sarau ุ THAI CHARACTER SARA U */
+ { 0x0dd9, 0x0e39 }, /* Thai_sarauu ู THAI CHARACTER SARA UU */
+ { 0x0dda, 0x0e3a }, /* Thai_phinthu ฺ THAI CHARACTER PHINTHU */
+ { 0x0ddf, 0x0e3f }, /* Thai_baht ฿ THAI CURRENCY SYMBOL BAHT */
+ { 0x0de0, 0x0e40 }, /* Thai_sarae เ THAI CHARACTER SARA E */
+ { 0x0de1, 0x0e41 }, /* Thai_saraae แ THAI CHARACTER SARA AE */
+ { 0x0de2, 0x0e42 }, /* Thai_sarao โ THAI CHARACTER SARA O */
+ { 0x0de3, 0x0e43 }, /* Thai_saraaimaimuan ใ THAI CHARACTER SARA AI MAIMUAN */
+ { 0x0de4, 0x0e44 }, /* Thai_saraaimaimalai ไ THAI CHARACTER SARA AI MAIMALAI */
+ { 0x0de5, 0x0e45 }, /* Thai_lakkhangyao ๅ THAI CHARACTER LAKKHANGYAO */
+ { 0x0de6, 0x0e46 }, /* Thai_maiyamok ๆ THAI CHARACTER MAIYAMOK */
+ { 0x0de7, 0x0e47 }, /* Thai_maitaikhu ็ THAI CHARACTER MAITAIKHU */
+ { 0x0de8, 0x0e48 }, /* Thai_maiek ่ THAI CHARACTER MAI EK */
+ { 0x0de9, 0x0e49 }, /* Thai_maitho ้ THAI CHARACTER MAI THO */
+ { 0x0dea, 0x0e4a }, /* Thai_maitri ๊ THAI CHARACTER MAI TRI */
+ { 0x0deb, 0x0e4b }, /* Thai_maichattawa ๋ THAI CHARACTER MAI CHATTAWA */
+ { 0x0dec, 0x0e4c }, /* Thai_thanthakhat ์ THAI CHARACTER THANTHAKHAT */
+ { 0x0ded, 0x0e4d }, /* Thai_nikhahit ํ THAI CHARACTER NIKHAHIT */
+ { 0x0df0, 0x0e50 }, /* Thai_leksun ๐ THAI DIGIT ZERO */
+ { 0x0df1, 0x0e51 }, /* Thai_leknung ๑ THAI DIGIT ONE */
+ { 0x0df2, 0x0e52 }, /* Thai_leksong ๒ THAI DIGIT TWO */
+ { 0x0df3, 0x0e53 }, /* Thai_leksam ๓ THAI DIGIT THREE */
+ { 0x0df4, 0x0e54 }, /* Thai_leksi ๔ THAI DIGIT FOUR */
+ { 0x0df5, 0x0e55 }, /* Thai_lekha ๕ THAI DIGIT FIVE */
+ { 0x0df6, 0x0e56 }, /* Thai_lekhok ๖ THAI DIGIT SIX */
+ { 0x0df7, 0x0e57 }, /* Thai_lekchet ๗ THAI DIGIT SEVEN */
+ { 0x0df8, 0x0e58 }, /* Thai_lekpaet ๘ THAI DIGIT EIGHT */
+ { 0x0df9, 0x0e59 }, /* Thai_lekkao ๙ THAI DIGIT NINE */
+
+ { 0x0ed4, 0x11a8 }, /* Hangul_J_Kiyeog ᆨ HANGUL JONGSEONG KIYEOK */
+ { 0x0ed5, 0x11a9 }, /* Hangul_J_SsangKiyeog ᆩ HANGUL JONGSEONG SSANGKIYEOK */
+ { 0x0ed6, 0x11aa }, /* Hangul_J_KiyeogSios ᆪ HANGUL JONGSEONG KIYEOK-SIOS */
+ { 0x0ed7, 0x11ab }, /* Hangul_J_Nieun ᆫ HANGUL JONGSEONG NIEUN */
+ { 0x0ed8, 0x11ac }, /* Hangul_J_NieunJieuj ᆬ HANGUL JONGSEONG NIEUN-CIEUC */
+ { 0x0ed9, 0x11ad }, /* Hangul_J_NieunHieuh ᆭ HANGUL JONGSEONG NIEUN-HIEUH */
+ { 0x0eda, 0x11ae }, /* Hangul_J_Dikeud ᆮ HANGUL JONGSEONG TIKEUT */
+ { 0x0edb, 0x11af }, /* Hangul_J_Rieul ᆯ HANGUL JONGSEONG RIEUL */
+ { 0x0edc, 0x11b0 }, /* Hangul_J_RieulKiyeog ᆰ HANGUL JONGSEONG RIEUL-KIYEOK */
+ { 0x0edd, 0x11b1 }, /* Hangul_J_RieulMieum ᆱ HANGUL JONGSEONG RIEUL-MIEUM */
+ { 0x0ede, 0x11b2 }, /* Hangul_J_RieulPieub ᆲ HANGUL JONGSEONG RIEUL-PIEUP */
+ { 0x0edf, 0x11b3 }, /* Hangul_J_RieulSios ᆳ HANGUL JONGSEONG RIEUL-SIOS */
+ { 0x0ee0, 0x11b4 }, /* Hangul_J_RieulTieut ᆴ HANGUL JONGSEONG RIEUL-THIEUTH */
+ { 0x0ee1, 0x11b5 }, /* Hangul_J_RieulPhieuf ᆵ HANGUL JONGSEONG RIEUL-PHIEUPH */
+ { 0x0ee2, 0x11b6 }, /* Hangul_J_RieulHieuh ᆶ HANGUL JONGSEONG RIEUL-HIEUH */
+ { 0x0ee3, 0x11b7 }, /* Hangul_J_Mieum ᆷ HANGUL JONGSEONG MIEUM */
+ { 0x0ee4, 0x11b8 }, /* Hangul_J_Pieub ᆸ HANGUL JONGSEONG PIEUP */
+ { 0x0ee5, 0x11b9 }, /* Hangul_J_PieubSios ᆹ HANGUL JONGSEONG PIEUP-SIOS */
+ { 0x0ee6, 0x11ba }, /* Hangul_J_Sios ᆺ HANGUL JONGSEONG SIOS */
+ { 0x0ee7, 0x11bb }, /* Hangul_J_SsangSios ᆻ HANGUL JONGSEONG SSANGSIOS */
+ { 0x0ee8, 0x11bc }, /* Hangul_J_Ieung ᆼ HANGUL JONGSEONG IEUNG */
+ { 0x0ee9, 0x11bd }, /* Hangul_J_Jieuj ᆽ HANGUL JONGSEONG CIEUC */
+ { 0x0eea, 0x11be }, /* Hangul_J_Cieuc ᆾ HANGUL JONGSEONG CHIEUCH */
+ { 0x0eeb, 0x11bf }, /* Hangul_J_Khieuq ᆿ HANGUL JONGSEONG KHIEUKH */
+ { 0x0eec, 0x11c0 }, /* Hangul_J_Tieut ᇀ HANGUL JONGSEONG THIEUTH */
+ { 0x0eed, 0x11c1 }, /* Hangul_J_Phieuf ᇁ HANGUL JONGSEONG PHIEUPH */
+ { 0x0eee, 0x11c2 }, /* Hangul_J_Hieuh ᇂ HANGUL JONGSEONG HIEUH */
+ { 0x0ef8, 0x11eb }, /* Hangul_J_PanSios ᇫ HANGUL JONGSEONG PANSIOS */
+ { 0x0ef9, 0x11f0 }, /* Hangul_J_KkogjiDalrinIeung ᇰ HANGUL JONGSEONG YESIEUNG */
+ { 0x0efa, 0x11f9 }, /* Hangul_J_YeorinHieuh ᇹ HANGUL JONGSEONG YEORINHIEUH */
+
+
+ { 0x0aa2, 0x2002 }, /* enspace   EN SPACE */
+ { 0x0aa1, 0x2003 }, /* emspace   EM SPACE */
+ { 0x0aa3, 0x2004 }, /* em3space   THREE-PER-EM SPACE */
+ { 0x0aa4, 0x2005 }, /* em4space   FOUR-PER-EM SPACE */
+ { 0x0aa5, 0x2007 }, /* digitspace   FIGURE SPACE */
+ { 0x0aa6, 0x2008 }, /* punctspace   PUNCTUATION SPACE */
+ { 0x0aa7, 0x2009 }, /* thinspace   THIN SPACE */
+ { 0x0aa8, 0x200a }, /* hairspace   HAIR SPACE */
+ { 0x0abb, 0x2012 }, /* figdash ‒ FIGURE DASH */
+ { 0x0aaa, 0x2013 }, /* endash – EN DASH */
+ { 0x0aa9, 0x2014 }, /* emdash — EM DASH */
+ { 0x07af, 0x2015 }, /* Greek_horizbar ― HORIZONTAL BAR */
+ { 0x0cdf, 0x2017 }, /* hebrew_doublelowline ‗ DOUBLE LOW LINE */
+ { 0x0ad0, 0x2018 }, /* leftsinglequotemark ‘ LEFT SINGLE QUOTATION MARK */
+ { 0x0ad1, 0x2019 }, /* rightsinglequotemark ’ RIGHT SINGLE QUOTATION MARK */
+ { 0x0afd, 0x201a }, /* singlelowquotemark ‚ SINGLE LOW-9 QUOTATION MARK */
+ { 0x0ad2, 0x201c }, /* leftdoublequotemark “ LEFT DOUBLE QUOTATION MARK */
+ { 0x0ad3, 0x201d }, /* rightdoublequotemark ” RIGHT DOUBLE QUOTATION MARK */
+ { 0x0afe, 0x201e }, /* doublelowquotemark „ DOUBLE LOW-9 QUOTATION MARK */
+ { 0x0af1, 0x2020 }, /* dagger † DAGGER */
+ { 0x0af2, 0x2021 }, /* doubledagger ‡ DOUBLE DAGGER */
+ { 0x0ae6, 0x2022 }, /* enfilledcircbullet • BULLET */
+ { 0x0aaf, 0x2025 }, /* doubbaselinedot ‥ TWO DOT LEADER */
+ { 0x0aae, 0x2026 }, /* ellipsis … HORIZONTAL ELLIPSIS */
+ { 0x0ad6, 0x2032 }, /* minutes ′ PRIME */
+ { 0x0ad7, 0x2033 }, /* seconds ″ DOUBLE PRIME */
+ { 0x0afc, 0x2038 }, /* caret ‸ CARET */
+ { 0x047e, 0x203e }, /* overline ‾ OVERLINE */
+ { 0x0eff, 0x20a9 }, /* Korean_Won ₩ WON SIGN */
+ { 0x13a4, 0x20ac }, /* Euro € EURO SIGN */
+
+ { 0x0ab8, 0x2105 }, /* careof ℅ CARE OF */
+ { 0x06b0, 0x2116 }, /* numerosign № NUMERO SIGN */
+ { 0x0afb, 0x2117 }, /* phonographcopyright ℗ SOUND RECORDING COPYRIGHT */
+ { 0x0ad4, 0x211e }, /* prescription ℞ PRESCRIPTION TAKE */
+ { 0x0ac9, 0x2122 }, /* trademark ™ TRADE MARK SIGN */
+ { 0x0ab0, 0x2153 }, /* onethird ⅓ VULGAR FRACTION ONE THIRD */
+ { 0x0ab1, 0x2154 }, /* twothirds ⅔ VULGAR FRACTION TWO THIRDS */
+ { 0x0ab2, 0x2155 }, /* onefifth ⅕ VULGAR FRACTION ONE FIFTH */
+ { 0x0ab3, 0x2156 }, /* twofifths ⅖ VULGAR FRACTION TWO FIFTHS */
+ { 0x0ab4, 0x2157 }, /* threefifths ⅗ VULGAR FRACTION THREE FIFTHS */
+ { 0x0ab5, 0x2158 }, /* fourfifths ⅘ VULGAR FRACTION FOUR FIFTHS */
+ { 0x0ab6, 0x2159 }, /* onesixth ⅙ VULGAR FRACTION ONE SIXTH */
+ { 0x0ab7, 0x215a }, /* fivesixths ⅚ VULGAR FRACTION FIVE SIXTHS */
+ { 0x0ac3, 0x215b }, /* oneeighth ⅛ VULGAR FRACTION ONE EIGHTH */
+ { 0x0ac4, 0x215c }, /* threeeighths ⅜ VULGAR FRACTION THREE EIGHTHS */
+ { 0x0ac5, 0x215d }, /* fiveeighths ⅝ VULGAR FRACTION FIVE EIGHTHS */
+ { 0x0ac6, 0x215e }, /* seveneighths ⅞ VULGAR FRACTION SEVEN EIGHTHS */
+ { 0x08fb, 0x2190 }, /* leftarrow ← LEFTWARDS ARROW */
+ { 0x08fc, 0x2191 }, /* uparrow ↑ UPWARDS ARROW */
+ { 0x08fd, 0x2192 }, /* rightarrow → RIGHTWARDS ARROW */
+ { 0x08fe, 0x2193 }, /* downarrow ↓ DOWNWARDS ARROW */
+ { 0x08ce, 0x21d2 }, /* implies ⇒ RIGHTWARDS DOUBLE ARROW */
+ { 0x08cd, 0x21d4 }, /* ifonlyif ⇔ LEFT RIGHT DOUBLE ARROW */
+ { 0x08ef, 0x2202 }, /* partialderivative ∂ PARTIAL DIFFERENTIAL */
+ { 0x08c5, 0x2207 }, /* nabla ∇ NABLA */
+ { 0x0bca, 0x2218 }, /* jot ∘ RING OPERATOR */
+ { 0x08d6, 0x221a }, /* radical √ SQUARE ROOT */
+ { 0x08c1, 0x221d }, /* variation ∝ PROPORTIONAL TO */
+ { 0x08c2, 0x221e }, /* infinity ∞ INFINITY */
+ { 0x08de, 0x2227 }, /* logicaland ∧ LOGICAL AND */
+ { 0x08df, 0x2228 }, /* logicalor ∨ LOGICAL OR */
+ { 0x08dc, 0x2229 }, /* intersection ∩ INTERSECTION */
+ { 0x08dd, 0x222a }, /* union ∪ UNION */
+ { 0x08bf, 0x222b }, /* integral ∫ INTEGRAL */
+ { 0x08c0, 0x2234 }, /* therefore ∴ THEREFORE */
+ { 0x08c8, 0x223c }, /* approximate ∼ TILDE OPERATOR */
+ { 0x08c9, 0x2243 }, /* similarequal ≃ ASYMPTOTICALLY EQUAL TO */
+ { 0x08bd, 0x2260 }, /* notequal ≠ NOT EQUAL TO */
+ { 0x08cf, 0x2261 }, /* identical ≡ IDENTICAL TO */
+ { 0x08bc, 0x2264 }, /* lessthanequal ≤ LESS-THAN OR EQUAL TO */
+ { 0x08be, 0x2265 }, /* greaterthanequal ≥ GREATER-THAN OR EQUAL TO */
+ { 0x08da, 0x2282 }, /* includedin ⊂ SUBSET OF */
+ { 0x08db, 0x2283 }, /* includes ⊃ SUPERSET OF */
+ { 0x0bdc, 0x22a2 }, /* lefttack ⊢ RIGHT TACK */
+ { 0x0bfc, 0x22a3 }, /* righttack ⊣ LEFT TACK */
+ { 0x0bce, 0x22a4 }, /* uptack ⊤ DOWN TACK */
+ { 0x0bc2, 0x22a5 }, /* downtack ⊥ UP TACK */
+ { 0x0bd3, 0x2308 }, /* upstile ⌈ LEFT CEILING */
+ { 0x0bc4, 0x230a }, /* downstile ⌊ LEFT FLOOR */
+ { 0x0afa, 0x2315 }, /* telephonerecorder ⌕ TELEPHONE RECORDER */
+ { 0x08a4, 0x2320 }, /* topintegral ⌠ TOP HALF INTEGRAL */
+ { 0x08a5, 0x2321 }, /* botintegral ⌡ BOTTOM HALF INTEGRAL */
+ { 0x0abc, 0x2329 }, /* leftanglebracket 〈 LEFT-POINTING ANGLE BRACKET */
+ { 0x0abe, 0x232a }, /* rightanglebracket 〉 RIGHT-POINTING ANGLE BRACKET */
+ { 0x0bcc, 0x2395 }, /* quad ⎕ APL FUNCTIONAL SYMBOL QUAD */
+ { 0x08ab, 0x239b }, /* topleftparens ⎛ ??? */
+ { 0x08ac, 0x239d }, /* botleftparens ⎝ ??? */
+ { 0x08ad, 0x239e }, /* toprightparens ⎞ ??? */
+ { 0x08ae, 0x23a0 }, /* botrightparens ⎠ ??? */
+ { 0x08a7, 0x23a1 }, /* topleftsqbracket ⎡ ??? */
+ { 0x08a8, 0x23a3 }, /* botleftsqbracket ⎣ ??? */
+ { 0x08a9, 0x23a4 }, /* toprightsqbracket ⎤ ??? */
+ { 0x08aa, 0x23a6 }, /* botrightsqbracket ⎦ ??? */
+ { 0x08af, 0x23a8 }, /* leftmiddlecurlybrace ⎨ ??? */
+ { 0x08b0, 0x23ac }, /* rightmiddlecurlybrace ⎬ ??? */
+ { 0x08a1, 0x23b7 }, /* leftradical ⎷ ??? */
+ { 0x09ef, 0x23ba }, /* horizlinescan1 ⎺ HORIZONTAL SCAN LINE-1 (Unicode 3.2 draft) */
+ { 0x09f0, 0x23bb }, /* horizlinescan3 ⎻ HORIZONTAL SCAN LINE-3 (Unicode 3.2 draft) */
+ { 0x09f2, 0x23bc }, /* horizlinescan7 ⎼ HORIZONTAL SCAN LINE-7 (Unicode 3.2 draft) */
+ { 0x09f3, 0x23bd }, /* horizlinescan9 ⎽ HORIZONTAL SCAN LINE-9 (Unicode 3.2 draft) */
+ { 0x09e2, 0x2409 }, /* ht ␉ SYMBOL FOR HORIZONTAL TABULATION */
+ { 0x09e3, 0x240c }, /* ff ␌ SYMBOL FOR FORM FEED */
+ { 0x09e4, 0x240d }, /* cr ␍ SYMBOL FOR CARRIAGE RETURN */
+ { 0x09e5, 0x240a }, /* lf ␊ SYMBOL FOR LINE FEED */
+ { 0x09e8, 0x2424 }, /* nl ␤ SYMBOL FOR NEWLINE */
+ { 0x09e9, 0x240b }, /* vt ␋ SYMBOL FOR VERTICAL TABULATION */
+
+ { 0x08a3, 0x2500 }, /* horizconnector ─ BOX DRAWINGS LIGHT HORIZONTAL */
+ { 0x08a6, 0x2502 }, /* vertconnector │ BOX DRAWINGS LIGHT VERTICAL */
+ { 0x08a2, 0x250c }, /* topleftradical ┌ BOX DRAWINGS LIGHT DOWN AND RIGHT */
+ { 0x09ec, 0x250c }, /* upleftcorner ┌ BOX DRAWINGS LIGHT DOWN AND RIGHT */
+ { 0x09eb, 0x2510 }, /* uprightcorner ┐ BOX DRAWINGS LIGHT DOWN AND LEFT */
+ { 0x09ed, 0x2514 }, /* lowleftcorner └ BOX DRAWINGS LIGHT UP AND RIGHT */
+ { 0x09ea, 0x2518 }, /* lowrightcorner ┘ BOX DRAWINGS LIGHT UP AND LEFT */
+ { 0x09f4, 0x251c }, /* leftt ├ BOX DRAWINGS LIGHT VERTICAL AND RIGHT */
+ { 0x09f5, 0x2524 }, /* rightt ┤ BOX DRAWINGS LIGHT VERTICAL AND LEFT */
+ { 0x09f7, 0x252c }, /* topt ┬ BOX DRAWINGS LIGHT DOWN AND HORIZONTAL */
+ { 0x09ee, 0x253c }, /* crossinglines ┼ BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL */
+ { 0x09f6, 0x2534 }, /* bott ┴ BOX DRAWINGS LIGHT UP AND HORIZONTAL */
+ { 0x09e1, 0x2592 }, /* checkerboard ▒ MEDIUM SHADE */
+ { 0x0ae7, 0x25aa }, /* enfilledsqbullet ▪ BLACK SMALL SQUARE */
+ { 0x0ae1, 0x25ab }, /* enopensquarebullet ▫ WHITE SMALL SQUARE */
+ { 0x0adb, 0x25ac }, /* filledrectbullet ▬ BLACK RECTANGLE */
+ { 0x0ae2, 0x25ad }, /* openrectbullet ▭ WHITE RECTANGLE */
+ { 0x0adf, 0x25ae }, /* emfilledrect ▮ BLACK VERTICAL RECTANGLE */
+ { 0x0acf, 0x25af }, /* emopenrectangle ▯ WHITE VERTICAL RECTANGLE */
+ { 0x0ae8, 0x25b2 }, /* filledtribulletup ▲ BLACK UP-POINTING TRIANGLE */
+ { 0x0ae3, 0x25b3 }, /* opentribulletup △ WHITE UP-POINTING TRIANGLE */
+ { 0x0add, 0x25b6 }, /* filledrighttribullet ▶ BLACK RIGHT-POINTING TRIANGLE */
+ { 0x0acd, 0x25b7 }, /* rightopentriangle ▷ WHITE RIGHT-POINTING TRIANGLE */
+ { 0x0ae9, 0x25bc }, /* filledtribulletdown ▼ BLACK DOWN-POINTING TRIANGLE */
+ { 0x0ae4, 0x25bd }, /* opentribulletdown ▽ WHITE DOWN-POINTING TRIANGLE */
+ { 0x0adc, 0x25c0 }, /* filledlefttribullet ◀ BLACK LEFT-POINTING TRIANGLE */
+ { 0x0acc, 0x25c1 }, /* leftopentriangle ◁ WHITE LEFT-POINTING TRIANGLE */
+ { 0x09e0, 0x25c6 }, /* soliddiamond ◆ BLACK DIAMOND */
+ { 0x0ace, 0x25cb }, /* emopencircle ○ WHITE CIRCLE */
+ { 0x0ade, 0x25cf }, /* emfilledcircle ● BLACK CIRCLE */
+ { 0x0ae0, 0x25e6 }, /* enopencircbullet ◦ WHITE BULLET */
+ { 0x0aee, 0x2665 }, /* heart ♥ BLACK HEART SUIT */
+ { 0x0aed, 0x2666 }, /* diamond ♦ BLACK DIAMOND SUIT */
+ { 0x0af5, 0x266f }, /* musicalsharp ♯ MUSIC SHARP SIGN */
+ { 0x0af6, 0x266d }, /* musicalflat ♭ MUSIC FLAT SIGN */
+ { 0x0af3, 0x2713 }, /* checkmark ✓ CHECK MARK */
+ { 0x0af4, 0x2717 }, /* ballotcross ✗ BALLOT X */
+ { 0x0ad9, 0x271d }, /* latincross ✝ LATIN CROSS */
+ { 0x0af0, 0x2720 }, /* maltesecross ✠ MALTESE CROSS */
+
+ { 0x04a4, 0x3001 }, /* kana_comma 、 IDEOGRAPHIC COMMA */
+ { 0x04a1, 0x3002 }, /* kana_fullstop 。 IDEOGRAPHIC FULL STOP */
+ { 0x04a2, 0x300c }, /* kana_openingbracket 「 LEFT CORNER BRACKET */
+ { 0x04a3, 0x300d }, /* kana_closingbracket 」 RIGHT CORNER BRACKET */
+ { 0x04de, 0x309b }, /* voicedsound ゛ KATAKANA-HIRAGANA VOICED SOUND MARK */
+ { 0x04df, 0x309c }, /* semivoicedsound ゜ KATAKANA-HIRAGANA SEMI-VOICED SOUND MARK */
+ { 0x04a7, 0x30a1 }, /* kana_a ァ KATAKANA LETTER SMALL A */
+ { 0x04b1, 0x30a2 }, /* kana_A ア KATAKANA LETTER A */
+ { 0x04a8, 0x30a3 }, /* kana_i ィ KATAKANA LETTER SMALL I */
+ { 0x04b2, 0x30a4 }, /* kana_I イ KATAKANA LETTER I */
+ { 0x04a9, 0x30a5 }, /* kana_u ゥ KATAKANA LETTER SMALL U */
+ { 0x04b3, 0x30a6 }, /* kana_U ウ KATAKANA LETTER U */
+ { 0x04aa, 0x30a7 }, /* kana_e ェ KATAKANA LETTER SMALL E */
+ { 0x04b4, 0x30a8 }, /* kana_E エ KATAKANA LETTER E */
+ { 0x04ab, 0x30a9 }, /* kana_o ォ KATAKANA LETTER SMALL O */
+ { 0x04b5, 0x30aa }, /* kana_O オ KATAKANA LETTER O */
+ { 0x04b6, 0x30ab }, /* kana_KA カ KATAKANA LETTER KA */
+ { 0x04b7, 0x30ad }, /* kana_KI キ KATAKANA LETTER KI */
+ { 0x04b8, 0x30af }, /* kana_KU ク KATAKANA LETTER KU */
+ { 0x04b9, 0x30b1 }, /* kana_KE ケ KATAKANA LETTER KE */
+ { 0x04ba, 0x30b3 }, /* kana_KO コ KATAKANA LETTER KO */
+ { 0x04bb, 0x30b5 }, /* kana_SA サ KATAKANA LETTER SA */
+ { 0x04bc, 0x30b7 }, /* kana_SHI シ KATAKANA LETTER SI */
+ { 0x04bd, 0x30b9 }, /* kana_SU ス KATAKANA LETTER SU */
+ { 0x04be, 0x30bb }, /* kana_SE セ KATAKANA LETTER SE */
+ { 0x04bf, 0x30bd }, /* kana_SO ソ KATAKANA LETTER SO */
+ { 0x04c0, 0x30bf }, /* kana_TA タ KATAKANA LETTER TA */
+ { 0x04c1, 0x30c1 }, /* kana_CHI チ KATAKANA LETTER TI */
+ { 0x04af, 0x30c3 }, /* kana_tsu ッ KATAKANA LETTER SMALL TU */
+ { 0x04c2, 0x30c4 }, /* kana_TSU ツ KATAKANA LETTER TU */
+ { 0x04c3, 0x30c6 }, /* kana_TE テ KATAKANA LETTER TE */
+ { 0x04c4, 0x30c8 }, /* kana_TO ト KATAKANA LETTER TO */
+ { 0x04c5, 0x30ca }, /* kana_NA ナ KATAKANA LETTER NA */
+ { 0x04c6, 0x30cb }, /* kana_NI ニ KATAKANA LETTER NI */
+ { 0x04c7, 0x30cc }, /* kana_NU ヌ KATAKANA LETTER NU */
+ { 0x04c8, 0x30cd }, /* kana_NE ネ KATAKANA LETTER NE */
+ { 0x04c9, 0x30ce }, /* kana_NO ノ KATAKANA LETTER NO */
+ { 0x04ca, 0x30cf }, /* kana_HA ハ KATAKANA LETTER HA */
+ { 0x04cb, 0x30d2 }, /* kana_HI ヒ KATAKANA LETTER HI */
+ { 0x04cc, 0x30d5 }, /* kana_FU フ KATAKANA LETTER HU */
+ { 0x04cd, 0x30d8 }, /* kana_HE ヘ KATAKANA LETTER HE */
+ { 0x04ce, 0x30db }, /* kana_HO ホ KATAKANA LETTER HO */
+ { 0x04cf, 0x30de }, /* kana_MA マ KATAKANA LETTER MA */
+ { 0x04d0, 0x30df }, /* kana_MI ミ KATAKANA LETTER MI */
+ { 0x04d1, 0x30e0 }, /* kana_MU ム KATAKANA LETTER MU */
+ { 0x04d2, 0x30e1 }, /* kana_ME メ KATAKANA LETTER ME */
+ { 0x04d3, 0x30e2 }, /* kana_MO モ KATAKANA LETTER MO */
+ { 0x04ac, 0x30e3 }, /* kana_ya ャ KATAKANA LETTER SMALL YA */
+ { 0x04d4, 0x30e4 }, /* kana_YA ヤ KATAKANA LETTER YA */
+ { 0x04ad, 0x30e5 }, /* kana_yu ュ KATAKANA LETTER SMALL YU */
+ { 0x04d5, 0x30e6 }, /* kana_YU ユ KATAKANA LETTER YU */
+ { 0x04ae, 0x30e7 }, /* kana_yo ョ KATAKANA LETTER SMALL YO */
+ { 0x04d6, 0x30e8 }, /* kana_YO ヨ KATAKANA LETTER YO */
+ { 0x04d7, 0x30e9 }, /* kana_RA ラ KATAKANA LETTER RA */
+ { 0x04d8, 0x30ea }, /* kana_RI リ KATAKANA LETTER RI */
+ { 0x04d9, 0x30eb }, /* kana_RU ル KATAKANA LETTER RU */
+ { 0x04da, 0x30ec }, /* kana_RE レ KATAKANA LETTER RE */
+ { 0x04db, 0x30ed }, /* kana_RO ロ KATAKANA LETTER RO */
+ { 0x04dc, 0x30ef }, /* kana_WA ワ KATAKANA LETTER WA */
+ { 0x04a6, 0x30f2 }, /* kana_WO ヲ KATAKANA LETTER WO */
+ { 0x04dd, 0x30f3 }, /* kana_N ン KATAKANA LETTER N */
+ { 0x04a5, 0x30fb }, /* kana_conjunctive ・ KATAKANA MIDDLE DOT */
+ { 0x04b0, 0x30fc }, /* prolongedsound ー KATAKANA-HIRAGANA PROLONGED SOUND MARK */
+
+ { 0x0ea1, 0x3131 }, /* Hangul_Kiyeog ㄱ HANGUL LETTER KIYEOK */
+ { 0x0ea2, 0x3132 }, /* Hangul_SsangKiyeog ㄲ HANGUL LETTER SSANGKIYEOK */
+ { 0x0ea3, 0x3133 }, /* Hangul_KiyeogSios ㄳ HANGUL LETTER KIYEOK-SIOS */
+ { 0x0ea4, 0x3134 }, /* Hangul_Nieun ㄴ HANGUL LETTER NIEUN */
+ { 0x0ea5, 0x3135 }, /* Hangul_NieunJieuj ㄵ HANGUL LETTER NIEUN-CIEUC */
+ { 0x0ea6, 0x3136 }, /* Hangul_NieunHieuh ㄶ HANGUL LETTER NIEUN-HIEUH */
+ { 0x0ea7, 0x3137 }, /* Hangul_Dikeud ㄷ HANGUL LETTER TIKEUT */
+ { 0x0ea8, 0x3138 }, /* Hangul_SsangDikeud ㄸ HANGUL LETTER SSANGTIKEUT */
+ { 0x0ea9, 0x3139 }, /* Hangul_Rieul ㄹ HANGUL LETTER RIEUL */
+ { 0x0eaa, 0x313a }, /* Hangul_RieulKiyeog ㄺ HANGUL LETTER RIEUL-KIYEOK */
+ { 0x0eab, 0x313b }, /* Hangul_RieulMieum ㄻ HANGUL LETTER RIEUL-MIEUM */
+ { 0x0eac, 0x313c }, /* Hangul_RieulPieub ㄼ HANGUL LETTER RIEUL-PIEUP */
+ { 0x0ead, 0x313d }, /* Hangul_RieulSios ㄽ HANGUL LETTER RIEUL-SIOS */
+ { 0x0eae, 0x313e }, /* Hangul_RieulTieut ㄾ HANGUL LETTER RIEUL-THIEUTH */
+ { 0x0eaf, 0x313f }, /* Hangul_RieulPhieuf ㄿ HANGUL LETTER RIEUL-PHIEUPH */
+ { 0x0eb0, 0x3140 }, /* Hangul_RieulHieuh ㅀ HANGUL LETTER RIEUL-HIEUH */
+ { 0x0eb1, 0x3141 }, /* Hangul_Mieum ㅁ HANGUL LETTER MIEUM */
+ { 0x0eb2, 0x3142 }, /* Hangul_Pieub ㅂ HANGUL LETTER PIEUP */
+ { 0x0eb3, 0x3143 }, /* Hangul_SsangPieub ㅃ HANGUL LETTER SSANGPIEUP */
+ { 0x0eb4, 0x3144 }, /* Hangul_PieubSios ㅄ HANGUL LETTER PIEUP-SIOS */
+ { 0x0eb5, 0x3145 }, /* Hangul_Sios ㅅ HANGUL LETTER SIOS */
+ { 0x0eb6, 0x3146 }, /* Hangul_SsangSios ㅆ HANGUL LETTER SSANGSIOS */
+ { 0x0eb7, 0x3147 }, /* Hangul_Ieung ㅇ HANGUL LETTER IEUNG */
+ { 0x0eb8, 0x3148 }, /* Hangul_Jieuj ㅈ HANGUL LETTER CIEUC */
+ { 0x0eb9, 0x3149 }, /* Hangul_SsangJieuj ㅉ HANGUL LETTER SSANGCIEUC */
+ { 0x0eba, 0x314a }, /* Hangul_Cieuc ㅊ HANGUL LETTER CHIEUCH */
+ { 0x0ebb, 0x314b }, /* Hangul_Khieuq ㅋ HANGUL LETTER KHIEUKH */
+ { 0x0ebc, 0x314c }, /* Hangul_Tieut ㅌ HANGUL LETTER THIEUTH */
+ { 0x0ebd, 0x314d }, /* Hangul_Phieuf ㅍ HANGUL LETTER PHIEUPH */
+ { 0x0ebe, 0x314e }, /* Hangul_Hieuh ㅎ HANGUL LETTER HIEUH */
+ { 0x0ebf, 0x314f }, /* Hangul_A ㅏ HANGUL LETTER A */
+ { 0x0ec0, 0x3150 }, /* Hangul_AE ㅐ HANGUL LETTER AE */
+ { 0x0ec1, 0x3151 }, /* Hangul_YA ㅑ HANGUL LETTER YA */
+ { 0x0ec2, 0x3152 }, /* Hangul_YAE ㅒ HANGUL LETTER YAE */
+ { 0x0ec3, 0x3153 }, /* Hangul_EO ㅓ HANGUL LETTER EO */
+ { 0x0ec4, 0x3154 }, /* Hangul_E ㅔ HANGUL LETTER E */
+ { 0x0ec5, 0x3155 }, /* Hangul_YEO ㅕ HANGUL LETTER YEO */
+ { 0x0ec6, 0x3156 }, /* Hangul_YE ㅖ HANGUL LETTER YE */
+ { 0x0ec7, 0x3157 }, /* Hangul_O ㅗ HANGUL LETTER O */
+ { 0x0ec8, 0x3158 }, /* Hangul_WA ㅘ HANGUL LETTER WA */
+ { 0x0ec9, 0x3159 }, /* Hangul_WAE ㅙ HANGUL LETTER WAE */
+ { 0x0eca, 0x315a }, /* Hangul_OE ㅚ HANGUL LETTER OE */
+ { 0x0ecb, 0x315b }, /* Hangul_YO ㅛ HANGUL LETTER YO */
+ { 0x0ecc, 0x315c }, /* Hangul_U ㅜ HANGUL LETTER U */
+ { 0x0ecd, 0x315d }, /* Hangul_WEO ㅝ HANGUL LETTER WEO */
+ { 0x0ece, 0x315e }, /* Hangul_WE ㅞ HANGUL LETTER WE */
+ { 0x0ecf, 0x315f }, /* Hangul_WI ㅟ HANGUL LETTER WI */
+ { 0x0ed0, 0x3160 }, /* Hangul_YU ㅠ HANGUL LETTER YU */
+ { 0x0ed1, 0x3161 }, /* Hangul_EU ㅡ HANGUL LETTER EU */
+ { 0x0ed2, 0x3162 }, /* Hangul_YI ㅢ HANGUL LETTER YI */
+ { 0x0ed3, 0x3163 }, /* Hangul_I ㅣ HANGUL LETTER I */
+ { 0x0eef, 0x316d }, /* Hangul_RieulYeorinHieuh ㅭ HANGUL LETTER RIEUL-YEORINHIEUH */
+ { 0x0ef0, 0x3171 }, /* Hangul_SunkyeongeumMieum ㅱ HANGUL LETTER KAPYEOUNMIEUM */
+ { 0x0ef1, 0x3178 }, /* Hangul_SunkyeongeumPieub ㅸ HANGUL LETTER KAPYEOUNPIEUP */
+ { 0x0ef2, 0x317f }, /* Hangul_PanSios ㅿ HANGUL LETTER PANSIOS */
+ { 0x0ef3, 0x3181 }, /* Hangul_KkogjiDalrinIeung ㆁ HANGUL LETTER YESIEUNG */
+ { 0x0ef4, 0x3184 }, /* Hangul_SunkyeongeumPhieuf ㆄ HANGUL LETTER KAPYEOUNPHIEUPH */
+ { 0x0ef5, 0x3186 }, /* Hangul_YeorinHieuh ㆆ HANGUL LETTER YEORINHIEUH */
+ { 0x0ef6, 0x318d }, /* Hangul_AraeA ㆍ HANGUL LETTER ARAEA */
+ { 0x0ef7, 0x318e }, /* Hangul_AraeAE ㆎ HANGUL LETTER ARAEAE */
+ };
+
+long ucs2keysym (long ucs)
+{
+ int min = 0;
+ int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
+ int mid;
+
+ /* first check for Latin-1 characters (1:1 mapping) */
+ if ((ucs >= 0x0020 && ucs <= 0x007e) ||
+ (ucs >= 0x00a0 && ucs <= 0x00ff))
+ return ucs;
+
+ /* binary search in table */
+ while (max >= min) {
+ mid = (min + max) / 2;
+ if (keysymtab[mid].ucs < ucs)
+ min = mid + 1;
+ else if (keysymtab[mid].ucs > ucs)
+ max = mid - 1;
+ else {
+ /* found it */
+ return keysymtab[mid].keysym;
+ }
+ }
+
+ /* no matching keysym value found, return UCS2 with bit set */
+ return ucs | 0x01000000;
+}
+
+long keysym2ucs(long keysym)
+{
+ int min = 0;
+ int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
+ int mid;
+
+ /* first check for Latin-1 characters (1:1 mapping) */
+ if ((keysym >= 0x0020 && keysym <= 0x007e) ||
+ (keysym >= 0x00a0 && keysym <= 0x00ff))
+ return (long) keysym;
+
+ /* also check for directly encoded 24-bit UCS characters */
+ if ((keysym & 0xff000000) == 0x01000000)
+ return keysym & 0x00ffffff;
+
+ /* binary search in table */
+ while (max >= min) {
+ mid = (min + max) / 2;
+ if (keysymtab[mid].keysym < keysym)
+ min = mid + 1;
+ else if (keysymtab[mid].keysym > keysym)
+ max = mid - 1;
+ else {
+ /* found it */
+ return keysymtab[mid].ucs;
+ }
+ }
+
+ /* no matching Unicode value found */
+ return -1;
+}