summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Stone <daniel@fooishbar.org>2010-09-20 15:03:08 +1000
committerChase Douglas <chase.douglas@ubuntu.com>2010-10-08 22:25:33 +0200
commite080d09ea9f4908b5802510f48b8453efb608b8d (patch)
treeb48311e8f7bbf7f2c82b7f5b94b6b947f17236a3 /src
parentccbebb111fb2084716fce67cb44b5bd8b86adbbc (diff)
Add multitouch support from Xi 2.1HEADxi2.1
Add support to libXi for all the Xi 2.1 additions to the spec: TouchClass, TouchBegin, TouchEnd and TouchMotion, as well as touch grabs. Signed-off-by: Daniel Stone <daniel@fooishbar.org>
Diffstat (limited to 'src')
-rw-r--r--src/XExtInt.c136
-rw-r--r--src/XIAllowEvents.c29
-rw-r--r--src/XIPassiveGrab.c21
3 files changed, 185 insertions, 1 deletions
diff --git a/src/XExtInt.c b/src/XExtInt.c
index eed6637..8dff669 100644
--- a/src/XExtInt.c
+++ b/src/XExtInt.c
@@ -146,6 +146,10 @@ static int
wireToEnterLeave(xXIEnterEvent *in, XGenericEventCookie *cookie);
static int
wireToPropertyEvent(xXIPropertyEvent *in, XGenericEventCookie *cookie);
+static int
+wireToTouchStateEvent(xXITouchStateEvent *in, XGenericEventCookie *cookie);
+static int
+wireToTouchMotionEvent(xXITouchMotionEvent*in, XGenericEventCookie *cookie);
static /* const */ XEvent emptyevent;
@@ -268,7 +272,8 @@ static XExtensionVersion versions[] = { {XI_Absent, 0, 0},
XI_Add_DevicePresenceNotify_Minor},
{XI_Present, XI_Add_DeviceProperties_Major,
XI_Add_DeviceProperties_Minor},
-{XI_Present, XI_2_Major, XI_2_Minor}
+{XI_Present, XI_2_Major, XI_2_Minor},
+{XI_Present, XI_2_Major, XI_2_1_Minor}
};
/***********************************************************************
@@ -985,6 +990,25 @@ XInputWireToCookie(
break;
}
return ENQUEUE_EVENT;
+ case XI_TouchBegin:
+ case XI_TouchEnd:
+ *cookie = *(XGenericEventCookie*)save;
+ if (!wireToTouchStateEvent((xXITouchStateEvent*)event, cookie))
+ {
+ printf("XInputWireToCookie: CONVERSION FAILURE! evtype=%d\n",
+ ge->evtype);
+ break;
+ }
+ return ENQUEUE_EVENT;
+ case XI_TouchMotion:
+ *cookie = *(XGenericEventCookie*)save;
+ if (!wireToTouchMotionEvent((xXITouchMotionEvent*)event, cookie))
+ {
+ printf("XInputWireToCookie: CONVERSION FAILURE! evtype=%d\n",
+ ge->evtype);
+ break;
+ }
+ return ENQUEUE_EVENT;
default:
printf("XInputWireToCookie: Unknown generic event. type %d\n", ge->evtype);
@@ -1037,6 +1061,10 @@ sizeDeviceClassType(int type, int num_elements)
case XIValuatorClass:
l = sizeof(XIValuatorClassInfo);
break;
+ case XITouchClass:
+ l = sizeof(XITouchClassInfo);
+ l += num_elements * sizeof(XITouchInfo);
+ break;
default:
printf("sizeDeviceClassType: unknown type %d\n", type);
break;
@@ -1426,6 +1454,9 @@ size_classes(xXIAnyInfo* from, int nclasses)
case XIValuatorClass:
l = sizeDeviceClassType(XIValuatorClass, 0);
break;
+ case XITouchClass:
+ l = sizeDeviceClassType(XITouchClass,
+ ((xXITouchClassInfo*)any_wire)->num_touches);
}
len += l;
@@ -1526,6 +1557,51 @@ copy_classes(XIDeviceInfo* to, xXIAnyInfo* from, int nclasses)
}
break;
+ case XITouchClass:
+ {
+ XITouchClassInfo *cls_lib;
+ xXITouchClassInfo *cls_wire;
+ XITouchInfo *tp_lib;
+ xXITouchInfo *tp_wire;
+ int j;
+
+ cls_wire = (xXITouchClassInfo*)any_wire;
+ cls_lib = next_block(&ptr_lib,
+ sizeof(XITouchClassInfo) +
+ (cls_wire->num_touches *
+ sizeof(XITouchInfo)));
+
+ cls_lib->mode = cls_wire->mode;
+ /* FIXME: fractional parts */
+ cls_lib->min_x = cls_wire->min_x.integral;
+ cls_lib->max_x = cls_wire->max_x.integral;
+ cls_lib->min_y = cls_wire->min_y.integral;
+ cls_lib->max_y = cls_wire->max_y.integral;
+ cls_lib->min_touch_width =
+ cls_wire->min_touch_width.integral;
+ cls_lib->max_touch_width =
+ cls_wire->max_touch_width.integral;
+ cls_lib->max_touches = cls_wire->max_touches;
+ cls_lib->num_touches = cls_wire->num_touches;
+ cls_lib->touches = (XITouchInfo *) &cls_lib[1];
+
+ tp_lib = cls_lib->touches;
+ tp_wire = (xXITouchInfo *) &cls_wire[1];
+ for (j = 0; j < cls_wire->num_touches; j++) {
+ tp_lib->touchid = tp_wire->touchid;
+ tp_lib->tool = tp_wire->tool;
+ tp_lib->x = tp_wire->x.integral;
+ tp_lib->y = tp_wire->y.integral;
+ tp_lib->touch_major = tp_wire->touch_major.integral;
+ tp_lib->touch_minor = tp_wire->touch_minor.integral;
+ tp_lib->tool_major = tp_wire->tool_major.integral;
+ tp_lib->tool_minor = tp_wire->tool_minor.integral;
+ tp_lib->orientation = tp_wire->orientation;
+ tp_lib++;
+ tp_wire++;
+ }
+ }
+ break;
}
len += any_wire->length * 4;
ptr_wire += any_wire->length * 4;
@@ -1711,3 +1787,61 @@ wireToPropertyEvent(xXIPropertyEvent *in, XGenericEventCookie *cookie)
return 1;
}
+
+static int
+wireToTouchStateEvent(xXITouchStateEvent *in, XGenericEventCookie *cookie)
+{
+ XITouchStateEvent *out = malloc(sizeof(XITouchStateEvent));
+
+ cookie->data = out;
+
+ out->type = in->type;
+ out->extension = in->extension;
+ out->evtype = in->evtype;
+ out->send_event = ((in->type & 0x80) != 0);
+ out->time = in->time;
+ out->deviceid = in->deviceid;
+ out->sourceid = in->sourceid;
+ out->root = in->root;
+ out->event = in->event;
+ out->child = in->child;
+ out->touchid = in->touchid;
+ out->tool = in->tool;
+
+ return 1;
+}
+
+static int
+wireToTouchMotionEvent(xXITouchMotionEvent *in, XGenericEventCookie *cookie)
+{
+ XITouchMotionEvent *out = malloc(sizeof(XITouchMotionEvent));
+
+ cookie->data = out;
+
+ out->type = in->type;
+ out->extension = in->extension;
+ out->evtype = in->evtype;
+ out->send_event = ((in->type & 0x80) != 0);
+ out->time = in->time;
+ out->deviceid = in->deviceid;
+ out->sourceid = in->sourceid;
+ out->mask = in->mask;
+ out->root = in->root;
+ out->event = in->event;
+ out->child = in->child;
+ out->touchid = in->touchid;
+ out->root_x = FP1616toDBL(in->root_x);
+ out->root_y = FP1616toDBL(in->root_y);
+ out->event_x = FP1616toDBL(in->event_x);
+ out->event_y = FP1616toDBL(in->event_y);
+ /* FIXME: fractional values */
+ out->x = in->x.integral;
+ out->y = in->y.integral;
+ out->touch_width_major = in->touch_width_major.integral;
+ out->touch_width_minor = in->touch_width_minor.integral;
+ out->tool_width_major = in->tool_width_major.integral;
+ out->tool_width_minor = in->tool_width_minor.integral;
+ out->orientation = in->orientation;
+
+ return 1;
+}
diff --git a/src/XIAllowEvents.c b/src/XIAllowEvents.c
index 75980a0..00229c9 100644
--- a/src/XIAllowEvents.c
+++ b/src/XIAllowEvents.c
@@ -51,3 +51,32 @@ XIAllowEvents(Display *dpy, int deviceid, int event_mode, Time time)
SyncHandle();
return Success;
}
+
+Status
+XIAllowTouchEvents(Display *dpy, int deviceid, int event_mode, Time time,
+ uint32_t touchid)
+{
+ xXIAllowEventsDetailReq *req;
+
+ XExtDisplayInfo *extinfo = XInput_find_display(dpy);
+
+ LockDisplay(dpy);
+ if (_XiCheckExtInit(dpy, XInput_2_1, extinfo) == -1)
+ return (NoSuchExtension);
+
+ /* Xlib really wants the struct and req names to be the same. */
+#define X_XIAllowEventsDetail X_XIAllowEvents
+ GetReq(XIAllowEventsDetail, req);
+#undef X_XIAllowEventsDetail
+
+ req->reqType = extinfo->codes->major_opcode;
+ req->ReqType = X_XIAllowEvents;
+ req->deviceid = deviceid;
+ req->mode = event_mode;
+ req->time = time;
+ req->detail = touchid;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return Success;
+}
diff --git a/src/XIPassiveGrab.c b/src/XIPassiveGrab.c
index 8953013..6bfea82 100644
--- a/src/XIPassiveGrab.c
+++ b/src/XIPassiveGrab.c
@@ -145,6 +145,18 @@ XIGrabFocusIn(Display *dpy, int deviceid, Window grab_window, int grab_mode,
modifiers_inout);
}
+int
+XIGrabTouchBegin(Display *dpy, int deviceid, Window grab_window, int grab_mode,
+ Bool owner_events, XIEventMask *mask, int num_modifiers,
+ XIGrabModifiers *modifiers_inout)
+{
+ /* FIXME: Don't send to Xi 2.0 servers. */
+ return _XIPassiveGrabDevice(dpy, deviceid, XIGrabtypeTouchBegin, 0,
+ grab_window, None, grab_mode, 0,
+ owner_events, mask, num_modifiers,
+ modifiers_inout);
+}
+
static int
_XIPassiveUngrabDevice(Display* dpy, int deviceid, int grabtype, int detail,
Window grab_window, int num_modifiers, XIGrabModifiers *modifiers)
@@ -208,3 +220,12 @@ XIUngrabFocusIn(Display* display, int deviceid, Window grab_window,
return _XIPassiveUngrabDevice(display, deviceid, XIGrabtypeFocusIn, 0,
grab_window, num_modifiers, modifiers);
}
+
+int
+XIUngrabTouchBegin(Display* display, int deviceid, Window grab_window,
+ int num_modifiers, XIGrabModifiers *modifiers)
+{
+ /* FIXME: Don't send to Xi 2.0 servers. */
+ return _XIPassiveUngrabDevice(display, deviceid, XIGrabtypeTouchBegin, 0,
+ grab_window, num_modifiers, modifiers);
+}