#include <ctype.h>
#include <stdio.h>
#include <sys/time.h>
-#include <bonobo/bonobo-exception.h>
#include <X11/Xlib.h>
#include <X11/extensions/XTest.h>
#include <X11/extensions/Xevie.h>
#endif /* HAVE_XEVIE */
-#include <gdk/gdk.h>
-#include <gdk/gdkx.h> /* TODO: hide dependency (wrap in single porting file) */
-#include <gdk/gdkkeysyms.h>
-#include <gdk/gdkwindow.h>
+#include <glib.h>
+
+#include <dbus/dbus.h>
+
+#include "paths.h"
+#include "keymasks.h"
+#include "de-types.h"
+#include "de-marshaller.h"
+#include "display.h"
-#include "../libspi/spi-private.h"
#include "deviceeventcontroller.h"
+#include "reentrant-list.h"
+
+#include "introspection.h"
KeySym ucs2keysym (long ucs);
long keysym2ucs(KeySym keysym);
static void wait_for_release_event (XEvent *event, SpiDEController *controller);
/* Our parent Gtk object type */
-#define PARENT_TYPE BONOBO_TYPE_OBJECT
+#define PARENT_TYPE G_TYPE_OBJECT
/* A pointer to our parent object class */
-static GObjectClass *spi_device_event_controller_parent_class;
static int spi_error_code = 0;
-static GdkPoint last_mouse_pos_static = {0, 0};
-static GdkPoint *last_mouse_pos = &last_mouse_pos_static;
+struct _SpiPoint {
+ gint x;
+ gint y;
+};
+typedef struct _SpiPoint SpiPoint;
+static SpiPoint last_mouse_pos_static = {0, 0};
+static SpiPoint *last_mouse_pos = &last_mouse_pos_static;
static unsigned int mouse_mask_state = 0;
static unsigned int mouse_button_mask =
Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask;
static unsigned int _numlock_physical_mask = Mod2Mask; /* a guess, will be reset */
static GQuark spi_dec_private_quark = 0;
+static XModifierKeymap* xmkeymap = NULL;
-int (*x_default_error_handler) (Display *display, XErrorEvent *error_event);
+static gboolean have_mouse_listener = FALSE;
+static gboolean have_mouse_event_listener = FALSE;
+
+static int (*x_default_error_handler) (Display *display, XErrorEvent *error_event);
typedef enum {
SPI_DEVICE_TYPE_KBD,
guint pending_remove : 1;
Accessibility_ControllerEventMask mod_mask;
- CORBA_unsigned_long key_val; /* KeyCode */
+ dbus_uint32_t key_val; /* KeyCode */
} DEControllerGrabMask;
typedef struct {
- CORBA_Object object;
+ char *bus_name;
+ char *path;
SpiDeviceTypeCategory type;
- Accessibility_EventTypeSeq *typeseq;
+ gulong types;
} DEControllerListener;
typedef struct {
DEControllerListener listener;
- Accessibility_KeySet *keys;
+ GSList *keys;
Accessibility_ControllerEventMask mask;
Accessibility_EventListenerMode *mode;
} DEControllerKeyListener;
static gboolean spi_controller_update_key_grabs (SpiDEController *controller,
Accessibility_DeviceEvent *recv);
static gboolean spi_controller_register_device_listener (SpiDEController *controller,
- DEControllerListener *l,
- CORBA_Environment *ev);
+ DEControllerListener *l);
static gboolean spi_device_event_controller_forward_key_event (SpiDEController *controller,
const XEvent *event);
-static void spi_deregister_controller_device_listener (SpiDEController *controller,
- DEControllerListener *listener,
- CORBA_Environment *ev);
+static void spi_controller_deregister_device_listener (SpiDEController *controller,
+ DEControllerListener *listener);
static void spi_deregister_controller_key_listener (SpiDEController *controller,
- DEControllerKeyListener *key_listener,
- CORBA_Environment *ev);
+ DEControllerKeyListener *key_listener);
static gboolean spi_controller_notify_mouselisteners (SpiDEController *controller,
- const Accessibility_DeviceEvent *event,
- CORBA_Environment *ev);
+ const Accessibility_DeviceEvent *event);
-static gboolean spi_eventtype_seq_contains_event (Accessibility_EventTypeSeq *type_seq,
+static gboolean spi_eventtype_seq_contains_event (dbus_uint32_t types,
const Accessibility_DeviceEvent *event);
static gboolean spi_clear_error_state (void);
static gboolean spi_dec_poll_mouse_moved (gpointer data);
static gboolean spi_dec_poll_mouse_moving (gpointer data);
static gboolean spi_dec_poll_mouse_idle (gpointer data);
-#define spi_get_display() GDK_DISPLAY()
+G_DEFINE_TYPE(SpiDEController, spi_device_event_controller, G_TYPE_OBJECT)
+
+DBusMessage *
+invalid_arguments_error (DBusMessage *message)
+{
+ DBusMessage *reply;
+ gchar *errmsg;
+
+ errmsg= g_strdup_printf (
+ "Method \"%s\" with signature \"%s\" on interface \"%s\" was supplied with invalid arguments\n",
+ dbus_message_get_member (message),
+ dbus_message_get_signature (message),
+ dbus_message_get_interface (message));
+ reply = dbus_message_new_error (message,
+ DBUS_ERROR_INVALID_ARGS,
+ errmsg);
+ g_free (errmsg);
+ return reply;
+}
/* Private methods */
+static dbus_bool_t
+spi_dbus_add_disconnect_match (DBusConnection *bus, const char *name)
+{
+ char *match = g_strdup_printf ("interface=%s,member=NameOwnerChanged,arg0=%s", DBUS_INTERFACE_DBUS, name);
+ if (match)
+ {
+ DBusError error;
+ dbus_error_init (&error);
+ dbus_bus_add_match (bus, match, &error);
+ g_free (match);
+ return !dbus_error_is_set (&error);
+ }
+ 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);
+ return !dbus_error_is_set (&error);
+ }
+ else return FALSE;
+}
static unsigned int
keysym_mod_mask (KeySym keysym, KeyCode keycode)
if (desc && desc->map)
{
gint offset = desc->map->key_sym_map[keycode].offset;
- long old_sym = desc->map->syms[offset];
desc->map->syms[offset] = keysym;
}
else
{
DEControllerPrivateData *priv =
g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
- priv->xkb_latch_mask = 0;
+ priv->xkb_latch_mask = 0;
}
-
+
+static void emit(SpiDEController *controller, const char *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_button_update_and_emit (SpiDEController *controller,
+spi_dec_button_update_and_emit (SpiDEController *controller,
guint mask_return)
{
- CORBA_Environment ev;
- Accessibility_Event e;
Accessibility_DeviceEvent mouse_e;
- gchar event_name[24];
+ gchar event_detail[3];
gboolean is_consumed = FALSE;
if ((mask_return & mouse_button_mask) !=
fprintf (stderr, "Button %d %s\n",
button_number, (is_down) ? "Pressed" : "Released");
#endif
- snprintf (event_name, 22, "mouse:button:%d%c", button_number,
+ snprintf (event_detail, 3, "%d%c", button_number,
(is_down) ? 'p' : 'r');
/* TODO: FIXME distinguish between physical and
* logical buttons
Accessibility_BUTTON_RELEASED_EVENT;
mouse_e.id = button_number;
mouse_e.hw_code = button_number;
- mouse_e.modifiers = (CORBA_unsigned_short) mouse_mask_state;
+ mouse_e.modifiers = (dbus_uint16_t) mouse_mask_state;
mouse_e.timestamp = 0;
mouse_e.event_string = "";
- mouse_e.is_text = CORBA_FALSE;
+ mouse_e.is_text = FALSE;
is_consumed =
spi_controller_notify_mouselisteners (controller,
- &mouse_e,
- &ev);
- e.type = event_name;
- e.source = BONOBO_OBJREF (controller->registry->desktop);
- e.detail1 = last_mouse_pos->x;
- e.detail2 = last_mouse_pos->y;
- spi_init_any_nil (&e.any_data);
- CORBA_exception_init (&ev);
+ &mouse_e);
if (!is_consumed)
{
- Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
- &e,
- &ev);
+ dbus_uint32_t x = last_mouse_pos->x, y = last_mouse_pos->y;
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, x, y);
}
else
spi_dec_set_unlatch_pending (controller, mask_return);
spi_dec_mouse_check (SpiDEController *controller,
int *x, int *y, gboolean *moved)
{
- Accessibility_Event e;
- CORBA_Environment ev;
int win_x_return,win_y_return;
unsigned int mask_return;
Window root_return, child_return;
if (*x != last_mouse_pos->x || *y != last_mouse_pos->y)
{
- e.type = "mouse:abs";
- e.source = BONOBO_OBJREF (controller->registry->desktop);
- e.detail1 = *x;
- e.detail2 = *y;
- spi_init_any_nil (&e.any_data);
- CORBA_exception_init (&ev);
- Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
- &e,
- &ev);
- e.type = "mouse:rel";
- e.source = BONOBO_OBJREF (controller->registry->desktop);
- e.detail1 = *x - last_mouse_pos->x;
- e.detail2 = *y - last_mouse_pos->y;
- spi_init_any_nil (&e.any_data);
- CORBA_exception_init (&ev);
+ // TODO: combine these two signals?
+ dbus_uint32_t ix = *x, iy = *y;
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Abs", "", ix, iy);
+ ix -= last_mouse_pos->x;
+ iy -= last_mouse_pos->y;
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Rel", "", ix, iy);
last_mouse_pos->x = *x;
last_mouse_pos->y = *y;
- Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
- &e,
- &ev);
*moved = True;
}
else
spi_dec_emit_modifier_event (SpiDEController *controller, guint prev_mask,
guint current_mask)
{
- Accessibility_Event e;
- CORBA_Environment ev;
+ dbus_uint32_t d1, d2;
#ifdef SPI_XKB_DEBUG
fprintf (stderr, "MODIFIER CHANGE EVENT! %x to %x\n",
if (current_mask & _numlock_physical_mask)
current_mask |= SPI_KEYMASK_NUMLOCK;
- e.type = "keyboard:modifiers";
- e.source = BONOBO_OBJREF (controller->registry->desktop);
- e.detail1 = prev_mask & key_modifier_mask;
- e.detail2 = current_mask & key_modifier_mask;
- spi_init_any_nil (&e.any_data);
- CORBA_exception_init (&ev);
- Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
- &e,
- &ev);
+ d1 = prev_mask & key_modifier_mask;
+ d2 = current_mask & key_modifier_mask;
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_KEYBOARD, "Modifiers", "", d1, d2);
}
static gboolean
spi_dec_poll_mouse_moved (gpointer data)
{
- SpiRegistry *registry = SPI_REGISTRY (data);
- SpiDEController *controller = registry->de_controller;
- int x, y;
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(data);
+ int x, y;
gboolean moved;
guint mask_return;
mask_return = spi_dec_mouse_check (controller, &x, &y, &moved);
-
+
if ((mask_return & key_modifier_mask) !=
(mouse_mask_state & key_modifier_mask))
{
static gboolean
spi_dec_poll_mouse_idle (gpointer data)
{
- if (! spi_dec_poll_mouse_moved (data))
+ if (!have_mouse_event_listener && !have_mouse_listener)
+ return FALSE;
+ else if (!spi_dec_poll_mouse_moved (data))
return TRUE;
else
{
static gboolean
spi_dec_poll_mouse_moving (gpointer data)
{
- if (spi_dec_poll_mouse_moved (data))
+ if (!have_mouse_event_listener && !have_mouse_listener)
+ return FALSE;
+ else if (spi_dec_poll_mouse_moved (data))
return TRUE;
else
{
#endif
static void
-spi_dec_init_mouse_listener (SpiRegistry *registry)
+spi_dec_init_mouse_listener (SpiDEController *dec)
{
+#ifdef GRAB_BUTTON
Display *display = spi_get_display ();
- g_timeout_add (100, spi_dec_poll_mouse_idle, registry);
-#ifdef GRAB_BUTTON
if (display)
{
if (XGrabButton (display, AnyButton, AnyModifier,
- gdk_x11_get_default_root_xwindow (),
+ spi_get_root_window (),
True, ButtonPressMask | ButtonReleaseMask,
GrabModeSync, GrabModeAsync, None, None) != Success) {
#ifdef SPI_DEBUG
}
static DEControllerKeyListener *
-spi_dec_key_listener_new (CORBA_Object l,
- const Accessibility_KeySet *keys,
+spi_dec_key_listener_new (const char *bus_name,
+ const char *path,
+ GSList *keys,
const Accessibility_ControllerEventMask mask,
- const Accessibility_EventTypeSeq *typeseq,
- const Accessibility_EventListenerMode *mode,
- CORBA_Environment *ev)
+ const dbus_uint32_t types,
+ const Accessibility_EventListenerMode *mode)
{
DEControllerKeyListener *key_listener = g_new0 (DEControllerKeyListener, 1);
- key_listener->listener.object = bonobo_object_dup_ref (l, ev);
+ 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 = ORBit_copy_value (keys, TC_Accessibility_KeySet);
+ key_listener->keys = keys;
key_listener->mask = spi_dec_translate_mask (mask);
- key_listener->listener.typeseq = ORBit_copy_value (typeseq, TC_Accessibility_EventTypeSeq);
+ key_listener->listener.types = types;
if (mode)
- key_listener->mode = ORBit_copy_value (mode, TC_Accessibility_EventListenerMode);
+ {
+ key_listener->mode = (Accessibility_EventListenerMode *) g_malloc(sizeof(Accessibility_EventListenerMode));
+ memcpy(key_listener->mode, mode, sizeof(*mode));
+ }
else
key_listener->mode = NULL;
(unsigned int) key_listener->mask,
(int) (mode ? mode->global : 0),
(void *) key_listener->keys,
- (int) (key_listener->keys ? key_listener->keys->_length : 0));
+ (int) (key_listener->keys ? g_slist_length(key_listener->keys) : 0));
#endif
return key_listener;
}
static DEControllerListener *
-spi_dec_listener_new (CORBA_Object l,
- const Accessibility_EventTypeSeq *typeseq,
- CORBA_Environment *ev)
+spi_dec_listener_new (const char *bus_name,
+ const char *path,
+ dbus_uint32_t types)
{
DEControllerListener *listener = g_new0 (DEControllerListener, 1);
- listener->object = bonobo_object_dup_ref (l, ev);
+ listener->bus_name = g_strdup(bus_name);
+ listener->path = g_strdup(path);
listener->type = SPI_DEVICE_TYPE_MOUSE;
- listener->typeseq = ORBit_copy_value (typeseq, TC_Accessibility_EventTypeSeq);
+ listener->types = types;
return listener;
}
static DEControllerListener *
-spi_listener_clone (DEControllerListener *listener, CORBA_Environment *ev)
+spi_listener_clone (DEControllerListener *listener)
{
DEControllerListener *clone = g_new0 (DEControllerListener, 1);
- clone->object =
- CORBA_Object_duplicate (listener->object, ev);
+ clone->bus_name = g_strdup (listener->bus_name);
+ clone->path = g_strdup (listener->path);
clone->type = listener->type;
- clone->typeseq = ORBit_copy_value (listener->typeseq, TC_Accessibility_EventTypeSeq);
+ 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, CORBA_Environment *ev)
+spi_key_listener_clone (DEControllerKeyListener *key_listener)
{
DEControllerKeyListener *clone = g_new0 (DEControllerKeyListener, 1);
- clone->listener.object =
- CORBA_Object_duplicate (key_listener->listener.object, ev);
+ 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 = ORBit_copy_value (key_listener->keys, TC_Accessibility_KeySet);
+ clone->keys = keylist_clone (key_listener->keys);
clone->mask = key_listener->mask;
- clone->listener.typeseq = ORBit_copy_value (key_listener->listener.typeseq, TC_Accessibility_EventTypeSeq);
+ clone->listener.types = key_listener->listener.types;
if (key_listener->mode)
- clone->mode = ORBit_copy_value (key_listener->mode, TC_Accessibility_EventListenerMode);
+ {
+ 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, CORBA_Environment *ev)
+spi_key_listener_data_free (DEControllerKeyListener *key_listener)
{
- CORBA_free (key_listener->listener.typeseq);
- CORBA_free (key_listener->keys);
+ keylist_free(key_listener->keys);
+ if (key_listener->mode) g_free(key_listener->mode);
+ g_free (key_listener->listener.bus_name);
+ g_free (key_listener->listener.path);
g_free (key_listener);
}
static void
-spi_key_listener_clone_free (DEControllerKeyListener *clone, CORBA_Environment *ev)
+spi_key_listener_clone_free (DEControllerKeyListener *clone)
{
- CORBA_Object_release (clone->listener.object, ev);
- spi_key_listener_data_free (clone, ev);
+ spi_key_listener_data_free (clone);
}
static void
-spi_listener_clone_free (DEControllerListener *clone, CORBA_Environment *ev)
+spi_listener_clone_free (DEControllerListener *clone)
{
- CORBA_Object_release (clone->object, ev);
- CORBA_free (clone->typeseq);
+ g_free (clone->path);
+ g_free (clone->bus_name);
g_free (clone);
}
static void
-spi_dec_listener_free (DEControllerListener *listener,
- CORBA_Environment *ev)
+spi_dec_listener_free (DEControllerListener *listener)
{
- bonobo_object_release_unref (listener->object, ev);
+ g_free (listener->bus_name);
+ g_free (listener->path);
if (listener->type == SPI_DEVICE_TYPE_KBD)
- spi_key_listener_data_free ((DEControllerKeyListener *) listener, ev);
+ spi_key_listener_data_free ((DEControllerKeyListener *) listener);
}
static void
cur_mask->pending_remove = TRUE;
}
}
- else
- {
- DBG (1, g_warning ("De-registering non-existant grab"));
- }
}
static void
DEControllerGrabMask grab_mask = { 0 };
grab_mask.mod_mask = key_listener->mask;
- if (key_listener->keys->_length == 0) /* special case means AnyKey/AllKeys */
+ if (g_slist_length (key_listener->keys) == 0) /* special case means AnyKey/AllKeys */
{
grab_mask.key_val = AnyKey;
#ifdef SPI_DEBUG
}
else
{
- int i;
+ GSList *l;
- for (i = 0; i < key_listener->keys->_length; ++i)
+ for (l = key_listener->keys; l; l = g_slist_next(l))
{
- Accessibility_KeyDefinition keydef = key_listener->keys->_buffer[i];
- long int key_val = keydef.keysym;
+ Accessibility_KeyDefinition *keydef = l->data;
+ long int key_val = keydef->keysym;
/* X Grabs require keycodes, not keysyms */
- if (keydef.keystring && keydef.keystring[0])
+ if (keydef->keystring && keydef->keystring[0])
{
- key_val = XStringToKeysym(keydef.keystring);
+ key_val = XStringToKeysym(keydef->keystring);
}
if (key_val > 0)
{
}
else
{
- key_val = keydef.keycode;
+ key_val = keydef->keycode;
}
grab_mask.key_val = key_val;
process_cb (controller, &grab_mask);
static gboolean
spi_controller_register_device_listener (SpiDEController *controller,
- DEControllerListener *listener,
- CORBA_Environment *ev)
+ DEControllerListener *listener)
{
DEControllerKeyListener *key_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)
{
return spi_controller_register_global_keygrabs (controller, key_listener);
break;
case SPI_DEVICE_TYPE_MOUSE:
controller->mouse_listeners = g_list_prepend (controller->mouse_listeners, listener);
+ if (!have_mouse_listener)
+ {
+ have_mouse_listener = TRUE;
+ if (!have_mouse_event_listener)
+ g_timeout_add (100, spi_dec_poll_mouse_idle, controller);
+ }
+ spi_dbus_add_disconnect_match (controller->bus, listener->bus_name);
break;
default:
- DBG (1, g_warning ("listener registration for unknown device type.\n"));
break;
}
- return FALSE;
+ return FALSE;
+}
+
+static void
+set_reply (DBusPendingCall *pending, void *user_data)
+{
+ void **replyptr = (void **)user_data;
+
+ *replyptr = dbus_pending_call_steal_reply (pending);
+}
+
+static DBusMessage *
+send_and_allow_reentry (DBusConnection *bus, DBusMessage *message, int timeout, DBusError *error)
+{
+ DBusPendingCall *pending;
+ DBusMessage *reply = NULL;
+
+ if (!dbus_connection_send_with_reply (bus, message, &pending, -1))
+ {
+ return NULL;
+ }
+ dbus_pending_call_set_notify (pending, set_reply, (void *)&reply, NULL);
+ while (!reply)
+ {
+ if (!dbus_connection_read_write_dispatch (bus, timeout))
+ 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");
+ DBusError error;
+ dbus_bool_t consumed = FALSE;
+
+ dbus_error_init(&error);
+ if (spi_dbus_marshal_deviceEvent(message, key_event))
+ {
+ DBusMessage *reply = send_and_allow_reentry (controller->bus, message, 1000, &error);
+ if (reply)
+ {
+ DBusError error;
+ dbus_error_init(&error);
+ dbus_message_get_args(reply, &error, DBUS_TYPE_BOOLEAN, &consumed, DBUS_TYPE_INVALID);
+ dbus_message_unref(reply);
+ }
+ }
+ dbus_message_unref(message);
+ return consumed;
}
static gboolean
spi_controller_notify_mouselisteners (SpiDEController *controller,
- const Accessibility_DeviceEvent *event,
- CORBA_Environment *ev)
+ 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;
{
DEControllerListener *listener = l->data;
- if (spi_eventtype_seq_contains_event (listener->typeseq, event))
+ if (spi_eventtype_seq_contains_event (listener->types, event))
{
- Accessibility_DeviceEventListener ls = listener->object;
-
- if (ls != CORBA_OBJECT_NIL)
- {
- /* we clone (don't dup) the listener, to avoid refcount inc. */
- notify = g_slist_prepend (notify,
- spi_listener_clone (listener, ev));
- found = TRUE;
- }
+ /* 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
}
}
is_consumed = FALSE;
for (l2 = notify; l2 && !is_consumed; l2 = l2->next)
{
- DEControllerListener *listener = l2->data;
- Accessibility_DeviceEventListener ls = listener->object;
+ DEControllerListener *listener = l2->data;
- CORBA_exception_init (ev);
- is_consumed = Accessibility_DeviceEventListener_notifyEvent (ls, event, ev);
- if (BONOBO_EX (ev))
- {
- is_consumed = FALSE;
- DBG (2, g_warning ("error notifying listener, removing it\n"));
- spi_deregister_controller_device_listener (controller, listener,
- ev);
- CORBA_exception_free (ev);
- }
-
- spi_listener_clone_free ((DEControllerListener *) l2->data, ev);
+ 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, ev);
+ DEControllerListener *listener = l2->data;
+ spi_listener_clone_free (listener);
/* clone doesn't have its own ref, so don't use spi_device_listener_free */
}
spi_device_event_controller_forward_mouse_event (SpiDEController *controller,
XEvent *xevent)
{
- Accessibility_Event e;
Accessibility_DeviceEvent mouse_e;
- CORBA_Environment ev;
- gchar event_name[24];
+ 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;
(xevent->type == ButtonPress) ? "Press" : "Release",
mouse_button_state);
#endif
- snprintf (event_name, 22, "mouse:button:%d%c", button,
+ snprintf (event_detail, 3, "%d%c", button,
(xevent->type == ButtonPress) ? 'p' : 'r');
/* TODO: FIXME distinguish between physical and logical buttons */
Accessibility_BUTTON_RELEASED_EVENT;
mouse_e.id = button;
mouse_e.hw_code = button;
- mouse_e.modifiers = (CORBA_unsigned_short) xbutton_event->state;
- mouse_e.timestamp = (CORBA_unsigned_long) xbutton_event->time;
+ 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 = CORBA_FALSE;
+ mouse_e.is_text = FALSE;
if ((mouse_button_state & mouse_button_mask) !=
(mouse_mask_state & mouse_button_mask))
{
mouse_mask_state, mouse_button_state);
mouse_mask_state = mouse_button_state;
is_consumed =
- spi_controller_notify_mouselisteners (controller, &mouse_e, &ev);
- e.type = CORBA_string_dup (event_name);
- e.source = BONOBO_OBJREF (controller->registry->desktop);
- e.detail1 = last_mouse_pos->x;
- e.detail2 = last_mouse_pos->y;
- spi_init_any_nil (&e.any_data);
- CORBA_exception_init (&ev);
-
- Accessibility_Registry_notifyEvent (BONOBO_OBJREF (controller->registry),
- &e,
- &ev);
+ spi_controller_notify_mouselisteners (controller, &mouse_e);
+ ix = last_mouse_pos->x;
+ iy = last_mouse_pos->y;
+ emit(controller, SPI_DBUS_INTERFACE_EVENT_MOUSE, "Button", event_detail, ix, iy);
}
xkb_mod_unlatch_occurred = (xevent->type == ButtonPress ||
CurrentTime);
}
-static GdkFilterReturn
-global_filter_fn (GdkXEvent *gdk_xevent, GdkEvent *event, gpointer data)
+static void
+global_filter_fn (XEvent *xevent, void *data)
{
- XEvent *xevent = gdk_xevent;
SpiDEController *controller;
DEControllerPrivateData *priv;
Display *display = spi_get_display ();
priv = (DEControllerPrivateData *)
g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
+ if (xevent->type == MappingNotify)
+ xmkeymap = NULL;
+
if (xevent->type == KeyPress || xevent->type == KeyRelease)
{
if (controller->xevie_display == NULL)
}
}
- return GDK_FILTER_CONTINUE;
+ return;
}
if (xevent->type == ButtonPress || xevent->type == ButtonRelease)
{
priv->xkb_latch_mask = xkb_snev->latched_mods;
}
}
- else
- DBG (2, g_warning ("XKB event %d\n", xkb_ev->xkb_type));
XSynchronize (display, FALSE);
}
- return GDK_FILTER_CONTINUE;
+ return;
}
-int
+static int
_spi_controller_device_error_handler (Display *display, XErrorEvent *error)
{
if (error->error_code == BadAccess)
static void
spi_controller_register_with_devices (SpiDEController *controller)
{
- DEControllerPrivateData *priv = (DEControllerPrivateData *)
- g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
- /* FIXME: should check for extension first! */
- XTestGrabControl (spi_get_display (), True);
+ DEControllerPrivateData *priv;
+ int event_base, error_base, major_version, minor_version;
+
+ priv = (DEControllerPrivateData *) g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
+ if (XTestQueryExtension (spi_get_display(), &event_base, &error_base, &major_version, &minor_version))
+ {
+ XTestGrabControl (spi_get_display (), True);
+ }
/* calls to device-specific implementations and routines go here */
/* register with: keyboard hardware code handler */
if (XKeycodeToKeysym (spi_get_display (), i, 0) != 0)
{
/* don't use this one if there's a grab client! */
- gdk_error_trap_push ();
+
+ /* Runtime errors are generated from these functions,
+ * that are then quashed. Equivalent to:
+ * try
+ * {Blah}
+ * except
+ * {;}
+ */
+
+ spi_x_error_trap ();
XGrabKey (spi_get_display (), i, 0,
- gdk_x11_get_default_root_xwindow (),
+ spi_get_root_window (),
TRUE,
GrabModeSync, GrabModeSync);
XSync (spi_get_display (), TRUE);
XUngrabKey (spi_get_display (), i, 0,
- gdk_x11_get_default_root_xwindow ());
- if (!gdk_error_trap_pop ())
+ spi_get_root_window ());
+ if (!spi_x_error_release ())
{
reserved = i;
break;
#endif
}
- gdk_window_add_filter (NULL, global_filter_fn, controller);
-
- gdk_window_set_events (gdk_get_default_root_window (),
- GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK);
+ spi_set_filter (global_filter_fn, controller);
+ spi_set_events (KeyPressMask | KeyReleaseMask);
x_default_error_handler = XSetErrorHandler (_spi_controller_device_error_handler);
}
static gboolean
-spi_key_set_contains_key (Accessibility_KeySet *key_set,
+spi_key_set_contains_key (GSList *key_set,
const Accessibility_DeviceEvent *key_event)
{
gint i;
gint len;
+ GSList *l;
if (!key_set)
{
- g_print ("null key set!");
+#ifdef SPI_DEBUG
+ g_print ("null key set!\n");
+#endif
return TRUE;
}
- len = key_set->_length;
+ 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 (i = 0; i < len; ++i)
+ 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)key_set->_buffer[i].keysym,
- (int) key_set->_buffer[i].keycode,
+ (int) kd->keysym,
+ (int) kd->keycode,
(int) key_event->id,
(int) key_event->hw_code,
key_event->event_string);
#endif
- if (key_set->_buffer[i].keysym == (CORBA_long) key_event->id)
+ if (kd->keysym == (dbus_uint32_t) key_event->id)
{
return TRUE;
}
- if (key_set->_buffer[i].keycode == (CORBA_long) key_event->hw_code)
+ if (kd->keycode == (dbus_uint32_t) key_event->hw_code)
{
return TRUE;
}
if (key_event->event_string && key_event->event_string[0] &&
- !strcmp (key_set->_buffer[i].keystring, key_event->event_string))
+ !strcmp (kd->keystring, key_event->event_string))
{
return TRUE;
}
}
static gboolean
-spi_eventtype_seq_contains_event (Accessibility_EventTypeSeq *type_seq,
+spi_eventtype_seq_contains_event (dbus_uint32_t types,
const Accessibility_DeviceEvent *event)
{
- gint i;
- gint len;
-
-
- if (!type_seq)
- {
- g_print ("null type seq!");
- return TRUE;
- }
-
- len = type_seq->_length;
-
- if (len == 0) /* special case, means "all events/any event" */
+ if (types == 0) /* special case, means "all events/any event" */
{
return TRUE;
}
- for (i = 0; i < len; ++i)
- {
-#ifdef SPI_DEBUG
- g_print ("type_seq[%d] = %d; event type = %d\n", i,
- (int) type_seq->_buffer[i], (int) event->type);
-#endif
- if (type_seq->_buffer[i] == (CORBA_long) event->type)
- {
- return TRUE;
- }
- }
-
- return FALSE;
+ return (types & (1 << event->type));
}
static gboolean
spi_key_event_matches_listener (const Accessibility_DeviceEvent *key_event,
DEControllerKeyListener *listener,
- CORBA_boolean is_system_global)
+ dbus_bool_t is_system_global)
{
- if ((key_event->modifiers == (CORBA_unsigned_short) (listener->mask & 0xFF)) &&
+ if (((key_event->modifiers & 0xFF) == (dbus_uint16_t) (listener->mask & 0xFF)) &&
spi_key_set_contains_key (listener->keys, key_event) &&
- spi_eventtype_seq_contains_event (listener->listener.typeseq, key_event) &&
+ spi_eventtype_seq_contains_event (listener->listener.types, key_event) &&
(is_system_global == listener->mode->global))
{
return TRUE;
static gboolean
spi_controller_notify_keylisteners (SpiDEController *controller,
- const Accessibility_DeviceEvent *key_event,
- CORBA_boolean is_system_global,
- CORBA_Environment *ev)
+ Accessibility_DeviceEvent *key_event,
+ dbus_bool_t is_system_global)
{
GList *l;
GSList *notify = NULL, *l2;
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))
{
- Accessibility_DeviceEventListener ls = key_listener->listener.object;
-
- if (ls != CORBA_OBJECT_NIL)
- {
- /* we clone (don't dup) the listener, to avoid refcount inc. */
- notify = g_slist_prepend (notify,
- spi_key_listener_clone (key_listener, ev));
- }
+ /* we clone (don't dup) the listener, to avoid refcount inc. */
+ notify = g_slist_prepend (notify,
+ spi_key_listener_clone (key_listener));
}
}
for (l2 = notify; l2 && !is_consumed; l2 = l2->next)
{
DEControllerKeyListener *key_listener = l2->data;
- Accessibility_DeviceEventListener ls = key_listener->listener.object;
-
- is_consumed = Accessibility_DeviceEventListener_notifyEvent (ls, key_event, ev);
- if (BONOBO_EX (ev))
- {
- is_consumed = FALSE;
- spi_deregister_controller_key_listener (controller, key_listener,
- ev);
- CORBA_exception_free (ev);
- }
+ is_consumed = Accessibility_DeviceEventListener_NotifyEvent (controller, controller->registry, &key_listener->listener, key_event) &&
+ key_listener->mode->preemptive;
- spi_key_listener_clone_free (key_listener, ev);
+ spi_key_listener_clone_free (key_listener);
}
for (; l2; l2 = l2->next)
{
DEControllerKeyListener *key_listener = l2->data;
- spi_key_listener_clone_free (key_listener, ev);
+ spi_key_listener_clone_free (key_listener);
/* clone doesn't have its own ref, so don't use spi_dec_listener_free */
}
}
static gboolean
-spi_clear_error_state ()
+spi_clear_error_state (void)
{
gboolean retval = spi_error_code != 0;
spi_error_code = 0;
int nbytes;
nbytes = XLookupString (x_key_event, cbuf, cbuf_bytes, &keysym, NULL);
- key_event.id = (CORBA_long)(keysym);
- key_event.hw_code = (CORBA_short) x_key_event->keycode;
+ 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;
{
key_event.type = Accessibility_KEY_RELEASED_EVENT;
}
- key_event.modifiers = (CORBA_unsigned_short)(x_key_event->state);
- key_event.is_text = CORBA_FALSE;
+ key_event.modifiers = (dbus_uint16_t)(x_key_event->state);
+ key_event.is_text = FALSE;
switch (keysym)
{
case ' ':
- key_event.event_string = CORBA_string_dup ("space");
+ key_event.event_string = g_strdup ("space");
break;
case XK_Tab:
- key_event.event_string = CORBA_string_dup ("Tab");
+ key_event.event_string = g_strdup ("Tab");
break;
case XK_BackSpace:
- key_event.event_string = CORBA_string_dup ("Backspace");
+ key_event.event_string = g_strdup ("Backspace");
break;
case XK_Return:
- key_event.event_string = CORBA_string_dup ("Return");
+ key_event.event_string = g_strdup ("Return");
break;
case XK_Home:
- key_event.event_string = CORBA_string_dup ("Home");
+ key_event.event_string = g_strdup ("Home");
break;
case XK_Page_Down:
- key_event.event_string = CORBA_string_dup ("Page_Down");
+ key_event.event_string = g_strdup ("Page_Down");
break;
case XK_Page_Up:
- key_event.event_string = CORBA_string_dup ("Page_Up");
+ key_event.event_string = g_strdup ("Page_Up");
break;
case XK_F1:
- key_event.event_string = CORBA_string_dup ("F1");
+ key_event.event_string = g_strdup ("F1");
break;
case XK_F2:
- key_event.event_string = CORBA_string_dup ("F2");
+ key_event.event_string = g_strdup ("F2");
break;
case XK_F3:
- key_event.event_string = CORBA_string_dup ("F3");
+ key_event.event_string = g_strdup ("F3");
break;
case XK_F4:
- key_event.event_string = CORBA_string_dup ("F4");
+ key_event.event_string = g_strdup ("F4");
break;
case XK_F5:
- key_event.event_string = CORBA_string_dup ("F5");
+ key_event.event_string = g_strdup ("F5");
break;
case XK_F6:
- key_event.event_string = CORBA_string_dup ("F6");
+ key_event.event_string = g_strdup ("F6");
break;
case XK_F7:
- key_event.event_string = CORBA_string_dup ("F7");
+ key_event.event_string = g_strdup ("F7");
break;
case XK_F8:
- key_event.event_string = CORBA_string_dup ("F8");
+ key_event.event_string = g_strdup ("F8");
break;
case XK_F9:
- key_event.event_string = CORBA_string_dup ("F9");
+ key_event.event_string = g_strdup ("F9");
break;
case XK_F10:
- key_event.event_string = CORBA_string_dup ("F10");
+ key_event.event_string = g_strdup ("F10");
break;
case XK_F11:
- key_event.event_string = CORBA_string_dup ("F11");
+ key_event.event_string = g_strdup ("F11");
break;
case XK_F12:
- key_event.event_string = CORBA_string_dup ("F12");
+ key_event.event_string = g_strdup ("F12");
break;
case XK_End:
- key_event.event_string = CORBA_string_dup ("End");
+ key_event.event_string = g_strdup ("End");
break;
case XK_Escape:
- key_event.event_string = CORBA_string_dup ("Escape");
+ key_event.event_string = g_strdup ("Escape");
break;
case XK_Up:
- key_event.event_string = CORBA_string_dup ("Up");
+ key_event.event_string = g_strdup ("Up");
break;
case XK_Down:
- key_event.event_string = CORBA_string_dup ("Down");
+ key_event.event_string = g_strdup ("Down");
break;
case XK_Left:
- key_event.event_string = CORBA_string_dup ("Left");
+ key_event.event_string = g_strdup ("Left");
break;
case XK_Right:
- key_event.event_string = CORBA_string_dup ("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 = CORBA_string_dup (cbuf);
+ key_event.event_string = g_strdup (cbuf);
c = keysym2ucs (keysym);
if (c > 0 && !g_unichar_iscntrl (c))
{
- key_event.is_text = CORBA_TRUE;
+ key_event.is_text = TRUE;
/* incorrect for some composed chars? */
}
}
else
{
- key_event.event_string = CORBA_string_dup ("");
+ key_event.event_string = g_strdup ("");
}
}
- key_event.timestamp = (CORBA_unsigned_long) x_key_event->time;
+ key_event.timestamp = (dbus_uint32_t) x_key_event->time;
#ifdef SPI_KEYEVENT_DEBUG
{
char *pressed_str = "pressed";
(int) x_key_event->state,
key_event.event_string,
key_event.event_string[0],
- (key_event.is_text == CORBA_TRUE) ? "(text)" : "(not text)");
+ (key_event.is_text == TRUE) ? "(text)" : "(not text)");
}
#endif
#ifdef SPI_DEBUG
{
GList *l, *next;
gboolean update_failed = FALSE;
- KeyCode keycode;
+ KeyCode keycode = 0;
g_return_val_if_fail (controller != NULL, FALSE);
XUngrabKey (spi_get_display (),
grab_mask->key_val,
grab_mask->mod_mask,
- gdk_x11_get_default_root_xwindow ());
+ spi_get_root_window ());
do_remove = TRUE;
}
XGrabKey (spi_get_display (),
grab_mask->key_val,
grab_mask->mod_mask,
- gdk_x11_get_default_root_xwindow (),
+ spi_get_root_window (),
True,
GrabModeSync,
GrabModeSync);
SpiDEController *controller;
DEControllerPrivateData *private;
controller = SPI_DEVICE_EVENT_CONTROLLER (object);
-
+ GObjectClass *parent_class = G_OBJECT_CLASS(spi_device_event_controller_parent_class);
#ifdef SPI_DEBUG
fprintf(stderr, "spi_device_event_controller_object_finalize called\n");
#endif
if (private->xkb_desc)
XkbFreeKeyboard (private->xkb_desc, 0, True);
g_free (private);
- spi_device_event_controller_parent_class->finalize (object);
+ parent_class->finalize (object);
}
/*
- * CORBA Accessibility::DEController::registerKeystrokeListener
+ * DBus Accessibility::DEController::RegisterKeystrokeListener
* method implementation
*/
-static CORBA_boolean
-impl_register_keystroke_listener (PortableServer_Servant servant,
- const Accessibility_DeviceEventListener l,
- const Accessibility_KeySet *keys,
- const Accessibility_ControllerEventMask mask,
- const Accessibility_EventTypeSeq *type,
- const Accessibility_EventListenerMode *mode,
- CORBA_Environment *ev)
-{
- SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
- bonobo_object_from_servant (servant));
+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;
+ char *sig;
+
+ dbus_message_iter_init(message, &iter);
+ // TODO: verify type signature
+ dbus_message_iter_get_basic(&iter, &path);
+ dbus_message_iter_next(&iter);
+ dbus_message_iter_recurse(&iter, &iter_array);
+ 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);
+ sig = dbus_message_iter_get_signature (&iter);
+ if (sig && !strcmp (sig, "u"))
+ dbus_message_iter_get_basic(&iter, &type);
+ else
+ {
+ dbus_message_iter_recurse(&iter, &iter_array);
+ while (dbus_message_iter_get_arg_type(&iter_array) != DBUS_TYPE_INVALID)
+ {
+ dbus_uint32_t t;
+ dbus_message_iter_get_basic (&iter_array, &t);
+ type |= (1 << t);
+ dbus_message_iter_next (&iter_array);
+ }
+ dbus_message_iter_next (&iter_array);
+ }
+ dbus_free (sig);
+ 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 %p with maskVal %lu\n",
- (void *) l, (unsigned long) mask);
+ 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 (l, keys, mask, type, mode, ev);
- return spi_controller_register_device_listener (
- controller, (DEControllerListener *) dec_listener, ev);
+ 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;
}
-
/*
- * CORBA Accessibility::DEController::registerDeviceEventListener
+ * DBus Accessibility::DEController::RegisterDeviceEventListener
* method implementation
*/
-static CORBA_boolean
-impl_register_device_listener (PortableServer_Servant servant,
- const Accessibility_DeviceEventListener l,
- const Accessibility_EventTypeSeq *event_types,
- CORBA_Environment *ev)
-{
- SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
- bonobo_object_from_servant (servant));
+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;
-
- dec_listener = spi_dec_listener_new (l, event_types, ev);
- return spi_controller_register_device_listener (
- controller, (DEControllerListener *) dec_listener, ev);
+ DBusError error;
+ const char *path;
+ dbus_int32_t event_types;
+ dbus_bool_t ret;
+ DBusMessage *reply = NULL;
+
+ dbus_error_init(&error);
+ if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
+ {
+ 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 {
- CORBA_Environment *ev;
+ DBusConnection *bus;
DEControllerListener *listener;
} RemoveListenerClosure;
DEControllerListener *listener = (*list)->data;
RemoveListenerClosure *ctx = user_data;
- if (CORBA_Object_is_equivalent (ctx->listener->object,
- listener->object, ctx->ev))
+ if (!strcmp(ctx->listener->bus_name, listener->bus_name) &&
+ !strcmp(ctx->listener->path, listener->path))
{
spi_re_entrant_list_delete_link (list);
- spi_dec_listener_free (listener, ctx->ev);
+ spi_dbus_remove_disconnect_match (ctx->bus, listener->bus_name);
+ spi_dec_listener_free (listener);
}
return SPI_RE_ENTRANT_CONTINUE;
DEControllerKeyListener *key_listener = (*list)->data;
RemoveListenerClosure *ctx = user_data;
- if (CORBA_Object_is_equivalent (ctx->listener->object,
- key_listener->listener.object, ctx->ev))
+ 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;
- CORBA_free (ctx_key_listener->keys);
- ctx_key_listener->keys = ORBit_copy_value (key_listener->keys, TC_Accessibility_KeySet);
+ keylist_free (ctx_key_listener->keys);
+ ctx_key_listener->keys = keylist_clone(key_listener->keys);
}
return SPI_RE_ENTRANT_CONTINUE;
}
static void
-spi_deregister_controller_device_listener (SpiDEController *controller,
- DEControllerListener *listener,
- CORBA_Environment *ev)
+spi_controller_deregister_device_listener (SpiDEController *controller,
+ DEControllerListener *listener)
{
RemoveListenerClosure ctx;
- ctx.ev = ev;
+ ctx.bus = controller->bus;
ctx.listener = listener;
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,
- CORBA_Environment *ev)
+ DEControllerKeyListener *key_listener)
{
RemoveListenerClosure ctx;
- ctx.ev = ev;
+ ctx.bus = controller->bus;
ctx.listener = (DEControllerListener *) key_listener;
/* special case, copy keyset from existing controller list entry */
- if (key_listener->keys->_length == 0)
+ 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,
}
+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);
+ }
+ }
+ 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))
+ {
+ spi_deregister_controller_key_listener (controller, key_listener);
+ }
+ }
+}
+
/*
- * CORBA Accessibility::DEController::deregisterKeystrokeListener
+ * DBus Accessibility::DEController::DeregisterKeystrokeListener
* method implementation
*/
-static void
-impl_deregister_keystroke_listener (PortableServer_Servant servant,
- const Accessibility_DeviceEventListener l,
- const Accessibility_KeySet *keys,
- const Accessibility_ControllerEventMask mask,
- const Accessibility_EventTypeSeq *type,
- CORBA_Environment *ev)
-{
- DEControllerKeyListener *key_listener;
- SpiDEController *controller;
-
- controller = SPI_DEVICE_EVENT_CONTROLLER (bonobo_object (servant));
-
- key_listener = spi_dec_key_listener_new (l, keys, mask, type, NULL, ev);
+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);
+ // TODO: verify type signature
+ 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, ev);
+ spi_deregister_controller_key_listener (controller, key_listener);
- spi_dec_listener_free ((DEControllerListener *) key_listener, ev);
+ spi_dec_listener_free ((DEControllerListener *) key_listener);
+ reply = dbus_message_new_method_return (message);
+ return reply;
}
/*
- * CORBA Accessibility::DEController::deregisterDeviceEventListener
+ * DBus Accessibility::DEController::DeregisterDeviceEventListener
* method implementation
*/
-static void
-impl_deregister_device_listener (PortableServer_Servant servant,
- const Accessibility_DeviceEventListener l,
- const Accessibility_EventTypeSeq *event_types,
- CORBA_Environment *ev)
-{
- SpiDEController *controller;
- DEControllerListener *listener =
- spi_dec_listener_new (l, event_types, ev);
-
- controller = SPI_DEVICE_EVENT_CONTROLLER (bonobo_object (servant));
-
- spi_deregister_controller_device_listener (controller, listener, ev);
-
- spi_dec_listener_free (listener, ev);
+static DBusMessage *
+impl_deregister_device_event_listener (DBusConnection *bus,
+ DBusMessage *message,
+ void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ DEControllerListener *listener;
+ DBusError error;
+ const char *path;
+ dbus_int32_t event_types;
+ DBusMessage *reply = NULL;
+
+ dbus_error_init(&error);
+ if (!dbus_message_get_args(message, &error, DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_UINT32, &event_types, DBUS_TYPE_INVALID))
+ {
+ 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 unsigned int dec_xkb_get_slowkeys_delay (SpiDEController *controller)
static gboolean
dec_lock_modifiers (SpiDEController *controller, unsigned modifiers)
{
- return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
- modifiers, modifiers);
+ DEControllerPrivateData *priv = (DEControllerPrivateData *)
+ g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
+
+ if (priv->have_xkb) {
+ return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
+ modifiers, modifiers);
+ } else {
+ int mod_index;
+ for (mod_index=0;mod_index<8;mod_index++)
+ if (modifiers & (1<<mod_index))
+ dec_synth_keycode_press(controller, xmkeymap->modifiermap[mod_index]);
+ return TRUE;
+ }
}
static gboolean
dec_unlock_modifiers (SpiDEController *controller, unsigned modifiers)
{
- return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
- modifiers, 0);
+ DEControllerPrivateData *priv = (DEControllerPrivateData *)
+ g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
+
+ if (priv->have_xkb) {
+ return XkbLockModifiers (spi_get_display (), XkbUseCoreKbd,
+ modifiers, 0);
+ } else {
+ int mod_index;
+ for (mod_index=0;mod_index<8;mod_index++)
+ if (modifiers & (1<<mod_index))
+ dec_synth_keycode_release(controller, xmkeymap->modifiermap[mod_index]);
+ return TRUE;
+ }
}
static KeySym
static gboolean
-dec_synth_keystring (SpiDEController *controller, const CORBA_char *keystring)
+dec_synth_keystring (SpiDEController *controller, const char *keystring)
{
/* probably we need to create and inject an XIM handler eventually. */
/* for now, try to match the string to existing
gboolean retval = TRUE;
const gchar *c;
- maxlen = strlen (keystring);
+ maxlen = strlen (keystring) + 1;
keysyms = g_new0 (KeySym, maxlen);
if (!(keystring && *keystring && g_utf8_validate (keystring, -1, &c))) {
retval = FALSE;
/*
- * CORBA Accessibility::DEController::registerKeystrokeListener
+ * DBus Accessibility::DEController::RegisterKeystrokeListener
* method implementation
*/
-static void
-impl_generate_keyboard_event (PortableServer_Servant servant,
- const CORBA_long keycode,
- const CORBA_char *keystring,
- const Accessibility_KeySynthType synth_type,
- CORBA_Environment *ev)
-{
- SpiDEController *controller =
- SPI_DEVICE_EVENT_CONTROLLER (bonobo_object (servant));
- long key_synth_code;
+static DBusMessage * impl_generate_keyboard_event (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER(user_data);
+ DBusError error;
+ dbus_int32_t keycode;
+ char *keystring;
+ dbus_uint32_t synth_type;
gint err;
KeySym keysym;
+ DEControllerPrivateData *priv;
+ DBusMessage *reply = NULL;
+
+ dbus_error_init(&error);
+ if (!dbus_message_get_args(message, &error, DBUS_TYPE_INT32, &keycode, DBUS_TYPE_STRING, &keystring, DBUS_TYPE_UINT32, &synth_type, DBUS_TYPE_INVALID))
+ {
+ return invalid_arguments_error (message);
+ }
#ifdef SPI_DEBUG
fprintf (stderr, "synthesizing keystroke %ld, type %d\n",
* and fall back to XSendEvent() if XTest is not available.
*/
- gdk_error_trap_push ();
- key_synth_code = keycode;
+ spi_x_error_trap ();
+
+ priv = (DEControllerPrivateData *)
+ g_object_get_qdata (G_OBJECT (controller), spi_dec_private_quark);
+
+ if (!priv->have_xkb && xmkeymap==NULL) {
+ xmkeymap = XGetModifierMapping(spi_get_display ());
+ }
switch (synth_type)
{
keystring);
break;
}
- if (err = gdk_error_trap_pop ())
- {
- DBG (-1, g_warning ("Error [%d] emitting keystroke", err));
- }
if (synth_type == Accessibility_KEY_SYM) {
keysym = keycode;
}
{
spi_dec_clear_unlatch_pending (controller);
}
+ reply = dbus_message_new_method_return (message);
+ return reply;
}
-/* Accessibility::DEController::generateMouseEvent */
-static void
-impl_generate_mouse_event (PortableServer_Servant servant,
- const CORBA_long x,
- const CORBA_long y,
- const CORBA_char *eventName,
- CORBA_Environment *ev)
+/* Accessibility::DEController::GenerateMouseEvent */
+static DBusMessage * impl_generate_mouse_event (DBusConnection *bus, DBusMessage *message, void *user_data)
{
+ DBusError error;
+ dbus_int32_t x;
+ dbus_int32_t y;
+ char *eventName;
+ DBusMessage *reply = NULL;
int button = 0;
- gboolean error = FALSE;
+ gboolean err = FALSE;
Display *display = spi_get_display ();
+
+ dbus_error_init (&error);
+ if (!dbus_message_get_args(message, &error, 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);
button = 5;
break;
default:
- error = TRUE;
+ err = TRUE;
}
- if (!error)
+ if (!err)
{
if (x != -1 && y != -1)
{
x, y, 0);
break;
}
+ reply = dbus_message_new_method_return (message);
+ return reply;
}
-/* Accessibility::DEController::notifyListenersSync */
-static CORBA_boolean
-impl_notify_listeners_sync (PortableServer_Servant servant,
- const Accessibility_DeviceEvent *event,
- CORBA_Environment *ev)
+/* Accessibility::DEController::NotifyListenersSync */
+static DBusMessage *
+impl_notify_listeners_sync (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
- bonobo_object_from_servant (servant));
+ 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);
+ controller, (int) event.id);
#endif
- return spi_controller_notify_keylisteners (controller, event, CORBA_FALSE, ev) ?
- CORBA_TRUE : CORBA_FALSE;
+ 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;
}
-/* Accessibility::DEController::notifyListenersAsync */
-static void
-impl_notify_listeners_async (PortableServer_Servant servant,
- const Accessibility_DeviceEvent *event,
- CORBA_Environment *ev)
+static DBusMessage *
+impl_notify_listeners_async (DBusConnection *bus, DBusMessage *message, void *user_data)
{
- SpiDEController *controller = SPI_DEVICE_EVENT_CONTROLLER (
- bonobo_object_from_servant (servant));
+ 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
- fprintf (stderr, "notifying listeners asynchronously\n");
+ g_print ("notifylistening listeners asynchronously: controller %p, event id %d\n",
+ controller, (int) event.id);
#endif
- spi_controller_notify_keylisteners (controller, event, CORBA_FALSE, ev);
+ 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;
- POA_Accessibility_DeviceEventController__epv *epv = &klass->epv;
spi_device_event_controller_parent_class = g_type_class_peek_parent (klass);
-
+
object_class->finalize = spi_device_event_controller_object_finalize;
-
- epv->registerKeystrokeListener = impl_register_keystroke_listener;
- epv->deregisterKeystrokeListener = impl_deregister_keystroke_listener;
- epv->registerDeviceEventListener = impl_register_device_listener;
- epv->deregisterDeviceEventListener = impl_deregister_device_listener;
- epv->generateKeyboardEvent = impl_generate_keyboard_event;
- epv->generateMouseEvent = impl_generate_mouse_event;
- epv->notifyListenersSync = impl_notify_listeners_sync;
- epv->notifyListenersAsync = impl_notify_listeners_async;
if (!spi_dec_private_quark)
spi_dec_private_quark = g_quark_from_static_string ("spi-dec-private");
}
#ifdef HAVE_XEVIE
-Bool isEvent(dpy,event,arg)
- Display *dpy;
- XEvent *event;
- char *arg;
+static Bool isEvent(Display *dpy, XEvent *event, char *arg)
{
return TRUE;
}
-gboolean
+static gboolean
handle_io (GIOChannel *source,
GIOCondition condition,
gpointer data)
static void
spi_device_event_controller_init (SpiDEController *device_event_controller)
{
+ spi_events_init (spi_get_display());
#ifdef HAVE_XEVIE
GIOChannel *ioc;
int fd;
spi_dec_private_quark,
private);
spi_controller_register_with_devices (device_event_controller);
+ device_event_controller->message_queue = g_queue_new ();
+ saved_controller = device_event_controller;
}
static gboolean
spi_device_event_controller_forward_key_event (SpiDEController *controller,
const XEvent *event)
{
- CORBA_Environment ev;
Accessibility_DeviceEvent key_event;
+ gboolean ret;
g_assert (event->type == KeyPress || event->type == KeyRelease);
- CORBA_exception_init (&ev);
-
key_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
if (controller->xevie_display == NULL)
spi_controller_update_key_grabs (controller, &key_event);
/* relay to listeners, and decide whether to consume it or not */
- return spi_controller_notify_keylisteners (controller, &key_event, CORBA_TRUE, &ev);
+ ret = spi_controller_notify_keylisteners (controller, &key_event, TRUE);
+ g_free(key_event.event_string);
+ return ret;
}
-SpiDEController *
-spi_device_event_controller_new (SpiRegistry *registry)
-{
- SpiDEController *retval = g_object_new (
- SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL);
-
- retval->registry = SPI_REGISTRY (bonobo_object_ref (
- BONOBO_OBJECT (registry)));
-
- spi_dec_init_mouse_listener (registry);
- /* TODO: kill mouse listener on finalize */
- return retval;
-}
static gboolean
is_key_released (KeyCode code)
{
char keys[32];
int down;
- int i;
XQueryKeymap (spi_get_display (), keys);
down = BIT (keys, code);
gboolean released;
Accessibility_DeviceEvent *event = (Accessibility_DeviceEvent *)data;
KeyCode code = event->hw_code;
- CORBA_Environment ev;
released = is_key_released (code);
{
check_release_handler = 0;
event->type = Accessibility_KEY_RELEASED_EVENT;
- ev._major = CORBA_NO_EXCEPTION;
- spi_controller_notify_keylisteners (saved_controller, event, CORBA_TRUE, &ev);
+ spi_controller_notify_keylisteners (saved_controller, event, TRUE);
}
return (released == 0);
}
SpiDEController *controller)
{
pressed_event = spi_keystroke_from_x_key_event ((XKeyEvent *) event);
- saved_controller = controller;
check_release_handler = g_timeout_add (CHECK_RELEASE_DELAY, check_release, &pressed_event);
}
-BONOBO_TYPE_FUNC_FULL (SpiDEController,
- Accessibility_DeviceEventController,
- PARENT_TYPE,
- spi_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;
+ gint i;
+
+ const gchar *pathstr = SPI_DBUS_PATH_DEC;
+
+ DBusMessage *reply;
+
+ output = g_string_new(introspection_header);
+
+ g_string_append_printf(output, introspection_node_element, pathstr);
+
+ g_string_append (output, spi_org_a11y_atspi_DeviceEventController);
+
+ g_string_append(output, introspection_footer);
+ final = g_string_free(output, FALSE);
+
+ reply = dbus_message_new_method_return (message);
+ dbus_message_append_args(reply, DBUS_TYPE_STRING, &final, DBUS_TYPE_INVALID);
+
+ g_free(final);
+ return reply;
+}
+
+/*---------------------------------------------------------------------------*/
+
+static void
+handle_dec_method_from_idle (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+ DBusHandlerResult result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ DBusMessage *reply = NULL;
+
+ if (!strcmp (iface, SPI_DBUS_INTERFACE_DEC))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "RegisterKeystrokeListener"))
+ reply = impl_register_keystroke_listener (bus, message, user_data);
+ else if (!strcmp (member, "RegisterDeviceEventListener"))
+ reply = impl_register_device_event_listener (bus, message, user_data);
+ else if (!strcmp (member, "DeregisterKeystrokeListener"))
+ reply = impl_deregister_keystroke_listener (bus, message, user_data);
+ else if (!strcmp (member, "DeregisterDeviceEventListener"))
+ reply = impl_deregister_device_event_listener (bus, message, user_data);
+ else if (!strcmp (member, "GenerateKeyboardEvent"))
+ reply = impl_generate_keyboard_event (bus, message, user_data);
+ else if (!strcmp (member, "GenerateMouseEvent"))
+ reply = impl_generate_mouse_event (bus, message, user_data);
+ else if (!strcmp (member, "NotifyListenersSync"))
+ reply = impl_notify_listeners_sync (bus, message, user_data);
+ else if (!strcmp (member, "NotifyListenersAsync"))
+ reply = impl_notify_listeners_async (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (!strcmp (iface, "org.freedesktop.DBus.Introspectable"))
+ {
+ result = DBUS_HANDLER_RESULT_HANDLED;
+ if (!strcmp (member, "Introspect"))
+ reply = impl_Introspect (bus, message, user_data);
+ else
+ result = DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (result == DBUS_HANDLER_RESULT_HANDLED)
+ {
+ if (!reply)
+ {
+ reply = dbus_message_new_method_return (message);
+ }
+
+ dbus_connection_send (bus, reply, NULL);
+ dbus_message_unref (reply);
+ }
+}
+
+static gboolean
+message_queue_dispatch (gpointer data)
+{
+ saved_controller->message_queue_idle = 0;
+ while (!g_queue_is_empty (saved_controller->message_queue))
+ {
+ DBusMessage *message = g_queue_pop_head (saved_controller->message_queue);
+ data = g_queue_pop_head (saved_controller->message_queue);
+ handle_dec_method_from_idle (saved_controller->bus, message, data);
+ dbus_message_unref (message);
+ }
+ return FALSE;
+}
+
+static DBusHandlerResult
+handle_dec_method (DBusConnection *bus, DBusMessage *message, void *user_data)
+{
+ const gchar *iface = dbus_message_get_interface (message);
+ const gchar *member = dbus_message_get_member (message);
+ const gint type = dbus_message_get_type (message);
+
+ /* Check for basic reasons not to handle */
+ if (type != DBUS_MESSAGE_TYPE_METHOD_CALL ||
+ member == NULL ||
+ iface == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
+ dbus_message_ref (message);
+ g_queue_push_tail (saved_controller->message_queue, message);
+ g_queue_push_tail (saved_controller->message_queue, user_data);
+ if (!saved_controller->message_queue_idle)
+ saved_controller->message_queue_idle = g_idle_add (message_queue_dispatch, NULL);
+ return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static DBusObjectPathVTable dec_vtable =
+{
+ NULL,
+ &handle_dec_method,
+ NULL, NULL, NULL, NULL
+};
+
+SpiDEController *
+spi_registry_dec_new (SpiRegistry *reg, DBusConnection *bus)
+{
+ SpiDEController *dec = g_object_new (SPI_DEVICE_EVENT_CONTROLLER_TYPE, NULL);
+
+ dec->registry = g_object_ref (reg);
+ reg->dec = g_object_ref (dec);
+ dec->bus = bus;
+
+ dbus_connection_register_object_path (bus, SPI_DBUS_PATH_DEC, &dec_vtable, dec);
+
+ spi_dec_init_mouse_listener (dec);
+
+ return dec;
+}
+
+void
+spi_device_event_controller_start_poll_mouse (SpiRegistry *registry)
+{
+ if (!have_mouse_event_listener)
+ {
+ have_mouse_event_listener = TRUE;
+ if (!have_mouse_listener)
+ g_timeout_add (100, spi_dec_poll_mouse_idle, registry->dec);
+ }
+}
+
+void
+spi_device_event_controller_stop_poll_mouse (void)
+{
+ have_mouse_event_listener = FALSE;
+}