From adc4fa1533227e856824c9dc5b80b3bdfd129d85 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 24 Sep 2010 13:39:14 +0200 Subject: [PATCH] libXi: Add handler to convert XI2 events to wire protocol. Signed-off-by: Carlos Garnacho --- src/XExtInt.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 80 insertions(+), 0 deletions(-) diff --git a/src/XExtInt.c b/src/XExtInt.c index bbd406d..8d5bbbd 100644 --- a/src/XExtInt.c +++ b/src/XExtInt.c @@ -127,6 +127,11 @@ static Bool XInputWireToCookie( XGenericEventCookie* /* re */, xEvent* /* event */ ); +static Bool XInputCookieToWire( + Display* /* display */, + XGenericEventCookie* /* re */, + xGenericEvent** /* event */ +); static Bool XInputCopyCookie( Display* /* display */, @@ -244,6 +249,7 @@ XExtDisplayInfo *XInput_find_display (Display *dpy) if (dpyinfo->codes) /* NULL if XI doesn't exist on the server */ { XESetWireToEventCookie(dpy, dpyinfo->codes->major_opcode, XInputWireToCookie); + XESetEventCookieToWire(dpy, dpyinfo->codes->major_opcode, XInputCookieToWire); XESetCopyEventCookie(dpy, dpyinfo->codes->major_opcode, XInputCopyCookie); } } @@ -992,6 +998,79 @@ XInputWireToCookie( return DONT_ENQUEUE; } +static Bool +XInputCookieToWire( + Display *dpy, + XGenericEventCookie *re, + xGenericEvent **event) +{ + XExtDisplayInfo *info = XInput_find_display(dpy); + XGenericEventCookie *xcookie = (XGenericEventCookie *) re; + + switch (((XGenericEvent*)re)->evtype) + { + case XI_KeyPress: + case XI_KeyRelease: { + register XIDeviceEvent *xev = (XIDeviceEvent *) xcookie->data; + register xXIDeviceEvent *wev = (xXIDeviceEvent *) event; + int buttons_len = (xev->buttons.mask_len + 3) >> 2; + unsigned char *mask; + + wev = (xXIDeviceEvent *) Xmalloc(sizeof(xXIDeviceEvent) + buttons_len); + + if (!wev) + return (_XUnknownEventCookie(dpy, re, event)); + + *event = (xGenericEvent *) wev; + + wev->type = GenericEvent; + wev->extension = info->codes->major_opcode; + wev->sequenceNumber = xev->serial & 0xFFFF; + wev->length = (sizeof (xXIDeviceEvent) + (buttons_len * 4) - sizeof (xEvent) + 3) >> 2; + wev->evtype = xev->evtype; + wev->deviceid = xev->deviceid; + wev->time = xev->time; + wev->detail = xev->detail; + wev->root = xev->root; + wev->event = xev->event; + wev->child = xev->child; + + if (xev->sourceid != 0) + wev->sourceid = xev->sourceid; + else + wev->sourceid = xev->deviceid; + + wev->flags = xev->flags; + + wev->buttons_len = (xev->buttons.mask_len + 3) << 2; + wev->valuators_len = 0; + + wev->root_x = 0; + wev->root_y = 0; + wev->event_x = 0; + wev->event_y = 0; + + wev->mods.base_mods = xev->mods.base; + wev->mods.latched_mods = xev->mods.latched; + wev->mods.locked_mods = xev->mods.locked; + wev->mods.effective_mods = xev->mods.effective; + + wev->group.base_group = xev->group.base; + wev->group.latched_group = xev->group.latched; + wev->group.locked_group = xev->group.locked; + wev->group.effective_group = xev->group.effective; + + /* Fill in trailing button mask */ + mask = (unsigned char *) &wev[1]; + memcpy (mask, xev->buttons.mask, xev->buttons.mask_len); + + return True; + } + } + + return False; +} + /** * Calculate length in bytes needed for the device event with the given * button mask length, valuator mask length + valuator mask. All parameters @@ -1711,3 +1790,4 @@ wireToPropertyEvent(xXIPropertyEvent *in, XGenericEventCookie *cookie) return 1; } + -- 1.7.0.4