diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-23 08:16:54 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2011-12-23 08:16:54 +1000 |
commit | 5fb48757477b2effd69c8fe8722ad95b21dbf7f5 (patch) | |
tree | 6795e62f0f41714c64965c4d588cd394af7a4ed1 | |
parent | 7909975b0b965fbf0935bf012987a5368ea0e67a (diff) | |
parent | e99ab2314f712df8dd705b16008755f8b3095707 (diff) | |
download | xorg-driver-xf86-input-evdev-5fb48757477b2effd69c8fe8722ad95b21dbf7f5.tar.gz |
Merge branch 'multitouch'
-rw-r--r-- | configure.ac | 15 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/emuMB.c | 3 | ||||
-rw-r--r-- | src/emuThird.c | 19 | ||||
-rw-r--r-- | src/evdev.c | 426 | ||||
-rw-r--r-- | src/evdev.h | 43 | ||||
-rw-r--r-- | src/udev.c | 69 |
7 files changed, 539 insertions, 37 deletions
diff --git a/configure.ac b/configure.ac index 1494a19..cfff2d4 100644 --- a/configure.ac +++ b/configure.ac @@ -46,6 +46,21 @@ XORG_DEFAULT_OPTIONS # Obtain compiler/linker options from server and required extensions PKG_CHECK_MODULES(XORG, [xorg-server >= 1.10] xproto inputproto) +PKG_CHECK_MODULES(UDEV, udev) + +# Whether to include support for experimental XI 2.2 multitouch +AC_ARG_ENABLE(multitouch, + AC_HELP_STRING([--enable-multitouch], + [Enable experimental XI 2.2 multitouch support [[default: disabled]]]), + [MULTITOUCH=$enableval], + [MULTITOUCH=no]) + +if test "x$MULTITOUCH" = xyes; then + AC_DEFINE(MULTITOUCH, 1, [Enable experimental multitouch code]) + + # Obtain compiler/linker options for mtdev + PKG_CHECK_MODULES(MTDEV, mtdev) +fi # Define a configure option for an alternate input module directory AC_ARG_WITH(xorg-module-dir, diff --git a/src/Makefile.am b/src/Makefile.am index b3a5671..cca1b0c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -30,6 +30,7 @@ AM_CPPFLAGS =-I$(top_srcdir)/include @DRIVER_NAME@_drv_la_LTLIBRARIES = @DRIVER_NAME@_drv.la @DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version +@DRIVER_NAME@_drv_la_LIBADD = $(MTDEV_LIBS) @DRIVER_NAME@_drv_ladir = @inputdir@ @DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c \ diff --git a/src/emuMB.c b/src/emuMB.c index b7a57b8..eb01495 100644 --- a/src/emuMB.c +++ b/src/emuMB.c @@ -191,7 +191,8 @@ EvdevMBEmuTimer(InputInfoPtr pInfo) pEvdev->emulateMB.pending = FALSE; if ((id = stateTab[pEvdev->emulateMB.state][4][0]) != 0) { - EvdevPostButtonEvent(pInfo, abs(id), (id >= 0)); + EvdevPostButtonEvent(pInfo, abs(id), + (id >= 0) ? BUTTON_PRESS : BUTTON_RELEASE); pEvdev->emulateMB.state = stateTab[pEvdev->emulateMB.state][4][2]; } else { diff --git a/src/emuThird.c b/src/emuThird.c index d89fd9e..7461767 100644 --- a/src/emuThird.c +++ b/src/emuThird.c @@ -58,7 +58,7 @@ enum EmulationState { }; static void -Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, int press) +Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act) { EvdevPtr pEvdev = pInfo->private; struct emulate3B *emu3B = &pEvdev->emulate3B; @@ -72,7 +72,8 @@ Evdev3BEmuPostButtonEvent(InputInfoPtr pInfo, int button, int press) if (emu3B->flags & EVDEV_ABSOLUTE_EVENTS) absolute = Absolute; - xf86PostButtonEventP(pInfo->dev, absolute, button, press, 0, + xf86PostButtonEventP(pInfo->dev, absolute, button, + (act == BUTTON_PRESS) ? 1 : 0, 0, (absolute ? 2 : 0), emu3B->startpos); } @@ -92,7 +93,7 @@ Evdev3BEmuTimer(OsTimerPtr timer, CARD32 time, pointer arg) sigstate = xf86BlockSIGIO (); emu3B->state = EM3B_EMULATING; - Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, 1); + Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_PRESS); xf86UnblockSIGIO (sigstate); return 0; } @@ -145,14 +146,14 @@ Evdev3BEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press) switch (emu3B->state) { case EM3B_PENDING: - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); break; case EM3B_EMULATING: /* We're emulating and now the user pressed a different * button. Just release the emulating one, tell the user to * not do that and get on with life */ - Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, 0); + Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_RELEASE); Evdev3BCancel(pInfo); break; default: @@ -171,11 +172,11 @@ Evdev3BEmuFilterEvent(InputInfoPtr pInfo, int button, BOOL press) switch(emu3B->state) { case EM3B_PENDING: - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); break; case EM3B_EMULATING: - Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, 0); + Evdev3BEmuPostButtonEvent(pInfo, emu3B->button, BUTTON_RELEASE); Evdev3BCancel(pInfo); ret = TRUE; break; @@ -237,7 +238,7 @@ Evdev3BEmuProcessAbsMotion(InputInfoPtr pInfo, ValuatorMask *vals) if (cancel) { - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); } } @@ -262,7 +263,7 @@ Evdev3BEmuProcessRelMotion(InputInfoPtr pInfo, int dx, int dy) if (abs(emu3B->delta[0]) > emu3B->threshold || abs(emu3B->delta[1]) > emu3B->threshold) { - Evdev3BEmuPostButtonEvent(pInfo, 1, 1); + Evdev3BEmuPostButtonEvent(pInfo, 1, BUTTON_PRESS); Evdev3BCancel(pInfo); } } diff --git a/src/evdev.c b/src/evdev.c index 562c7e7..9f3a22a 100644 --- a/src/evdev.c +++ b/src/evdev.c @@ -38,6 +38,7 @@ #include <linux/version.h> #include <sys/stat.h> +#include <libudev.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> @@ -56,6 +57,10 @@ #define XI_PROP_PRODUCT_ID "Device Product ID" #endif +#ifndef XI_PROP_VIRTUAL_DEVICE +#define XI_PROP_VIRTUAL_DEVICE "Virtual Device" +#endif + /* removed from server, purge when dropping support for server 1.10 */ #define XI86_SEND_DRAG_EVENTS 0x08 @@ -80,6 +85,14 @@ #define MODEFLAG 8 #define COMPOSEFLAG 16 +#ifndef ABS_MT_SLOT +#define ABS_MT_SLOT 0x2f +#endif + +#ifndef ABS_MT_TRACKING_ID +#define ABS_MT_TRACKING_ID 0x39 +#endif + static char *evdevDefaults[] = { "XkbRules", "evdev", "XkbModel", "evdev", @@ -119,6 +132,7 @@ static Atom prop_swap; static Atom prop_axis_label; static Atom prop_btn_label; static Atom prop_device; +static Atom prop_virtual; /* All devices the evdev driver has allocated and knows about. * MAXDEVICES is safe as null-terminated array, as two devices (VCP and VCK) @@ -277,6 +291,39 @@ SetXkbOption(InputInfoPtr pInfo, char *name, char **option) } } +static BOOL +EvdevDeviceIsVirtual(const char* devicenode) +{ + struct udev *udev = NULL; + struct udev_device *device = NULL; + struct stat st; + int rc = FALSE; + const char *devpath; + + udev = udev_new(); + if (!udev) + goto out; + + stat(devicenode, &st); + device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); + + if (!device) + goto out; + + + devpath = udev_device_get_devpath(device); + if (!devpath) + goto out; + + if (strstr(devpath, "LNXSYSTM")) + rc = TRUE; + +out: + udev_device_unref(device); + udev_unref(udev); + return rc; +} + #ifndef HAVE_SMOOTH_SCROLLING static int wheel_up_button = 4; static int wheel_down_button = 5; @@ -313,7 +360,7 @@ EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value) if ((pQueue = EvdevNextInQueue(pInfo))) { pQueue->type = EV_QUEUE_KEY; - pQueue->key = code; + pQueue->detail.key = code; pQueue->val = value; } } @@ -326,7 +373,7 @@ EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value) if ((pQueue = EvdevNextInQueue(pInfo))) { pQueue->type = EV_QUEUE_BTN; - pQueue->key = button; + pQueue->detail.key = button; pQueue->val = value; } } @@ -338,19 +385,36 @@ EvdevQueueProximityEvent(InputInfoPtr pInfo, int value) if ((pQueue = EvdevNextInQueue(pInfo))) { pQueue->type = EV_QUEUE_PROXIMITY; - pQueue->key = 0; + pQueue->detail.key = 0; pQueue->val = value; } } +#ifdef MULTITOUCH +void +EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch, ValuatorMask *mask, + uint16_t evtype) +{ + EventQueuePtr pQueue; + if ((pQueue = EvdevNextInQueue(pInfo))) + { + pQueue->type = EV_QUEUE_TOUCH; + pQueue->detail.touch = touch; + valuator_mask_copy(pQueue->touchMask, mask); + pQueue->val = evtype; + } +} +#endif + /** * Post button event right here, right now. * Interface for MB emulation since these need to post immediately. */ void -EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value) +EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act) { - xf86PostButtonEvent(pInfo->dev, Relative, button, value, 0, 0); + xf86PostButtonEvent(pInfo->dev, Relative, button, + (act == BUTTON_PRESS) ? 1 : 0, 0, 0); } void @@ -653,6 +717,64 @@ EvdevProcessRelativeMotionEvent(InputInfoPtr pInfo, struct input_event *ev) } } +#ifdef MULTITOUCH +static void +EvdevProcessTouch(InputInfoPtr pInfo) +{ + EvdevPtr pEvdev = pInfo->private; + int type; + + if (pEvdev->cur_slot < 0 || !pEvdev->mt_mask) + return; + + /* If the ABS_MT_SLOT is the first event we get after EV_SYN, skip this */ + if (pEvdev->slot_state == SLOTSTATE_EMPTY) + return; + + if (pEvdev->slot_state == SLOTSTATE_CLOSE) + type = XI_TouchEnd; + else if (pEvdev->slot_state == SLOTSTATE_OPEN) + type = XI_TouchBegin; + else + type = XI_TouchUpdate; + + + EvdevQueueTouchEvent(pInfo, pEvdev->cur_slot, pEvdev->mt_mask, type); + + pEvdev->slot_state = SLOTSTATE_EMPTY; + + valuator_mask_zero(pEvdev->mt_mask); +} + +static void +EvdevProcessTouchEvent(InputInfoPtr pInfo, struct input_event *ev) +{ + EvdevPtr pEvdev = pInfo->private; + int map; + + if (ev->code == ABS_MT_SLOT) { + EvdevProcessTouch(pInfo); + pEvdev->cur_slot = ev->value; + } else + { + if (pEvdev->slot_state == SLOTSTATE_EMPTY) + pEvdev->slot_state = SLOTSTATE_UPDATE; + if (ev->code == ABS_MT_TRACKING_ID) { + if (ev->value >= 0) + pEvdev->slot_state = SLOTSTATE_OPEN; + else + pEvdev->slot_state = SLOTSTATE_CLOSE; + } else { + map = pEvdev->axis_map[ev->code]; + valuator_mask_set(pEvdev->mt_mask, map, ev->value); + } + } +} +#else +#define EvdevProcessTouch(pInfo) +#define EvdevProcessTouchEvent(pInfo, ev) +#endif /* MULTITOUCH */ + /** * Take the absolute motion input event and process it accordingly. */ @@ -676,9 +798,14 @@ EvdevProcessAbsoluteMotionEvent(InputInfoPtr pInfo, struct input_event *ev) if (EvdevWheelEmuFilterMotion(pInfo, ev)) return; - map = pEvdev->axis_map[ev->code]; - valuator_mask_set(pEvdev->vals, map, value); - pEvdev->abs_queued = 1; + if (ev->code >= ABS_MT_SLOT) { + EvdevProcessTouchEvent(pInfo, ev); + pEvdev->abs_queued = 1; + } else if (!pEvdev->mt_mask) { + map = pEvdev->axis_map[ev->code]; + valuator_mask_set(pEvdev->vals, map, value); + pEvdev->abs_queued = 1; + } } /** @@ -713,7 +840,8 @@ EvdevProcessKeyEvent(InputInfoPtr pInfo, struct input_event *ev) * BTN_TOUCH as the proximity notifier */ if (!pEvdev->use_proximity) pEvdev->in_proximity = value ? ev->code : 0; - if (!(pEvdev->flags & (EVDEV_TOUCHSCREEN | EVDEV_TABLET))) + if (!(pEvdev->flags & (EVDEV_TOUCHSCREEN | EVDEV_TABLET)) || + pEvdev->mt_mask) break; /* Treat BTN_TOUCH from devices that only have BTN_TOUCH as * BTN_LEFT. */ @@ -774,6 +902,9 @@ EvdevPostProximityEvents(InputInfoPtr pInfo, int which, int num_v, int first_v, switch (pEvdev->queue[i].type) { case EV_QUEUE_KEY: case EV_QUEUE_BTN: +#ifdef MULTITOUCH + case EV_QUEUE_TOUCH: +#endif break; case EV_QUEUE_PROXIMITY: if (pEvdev->queue[i].val == which) @@ -796,26 +927,33 @@ static void EvdevPostQueuedEvents(InputInfoPtr pInfo, int num_v, int first_v, for (i = 0; i < pEvdev->num_queue; i++) { switch (pEvdev->queue[i].type) { case EV_QUEUE_KEY: - xf86PostKeyboardEvent(pInfo->dev, pEvdev->queue[i].key, + xf86PostKeyboardEvent(pInfo->dev, pEvdev->queue[i].detail.key, pEvdev->queue[i].val); break; case EV_QUEUE_BTN: if (Evdev3BEmuFilterEvent(pInfo, - pEvdev->queue[i].key, + pEvdev->queue[i].detail.key, pEvdev->queue[i].val)) break; if (pEvdev->abs_queued && pEvdev->in_proximity) { - xf86PostButtonEventP(pInfo->dev, Absolute, pEvdev->queue[i].key, + xf86PostButtonEventP(pInfo->dev, Absolute, pEvdev->queue[i].detail.key, pEvdev->queue[i].val, first_v, num_v, v + first_v); } else - xf86PostButtonEvent(pInfo->dev, Relative, pEvdev->queue[i].key, + xf86PostButtonEvent(pInfo->dev, Relative, pEvdev->queue[i].detail.key, pEvdev->queue[i].val, 0, 0); break; case EV_QUEUE_PROXIMITY: break; +#ifdef MULTITOUCH + case EV_QUEUE_TOUCH: + xf86PostTouchEvent(pInfo->dev, pEvdev->queue[i].detail.touch, + pEvdev->queue[i].val, 0, + pEvdev->queue[i].touchMask); + break; +#endif } } } @@ -827,6 +965,7 @@ static void EvdevPostQueuedEvents(InputInfoPtr pInfo, int num_v, int first_v, static void EvdevProcessSyncEvent(InputInfoPtr pInfo, struct input_event *ev) { + int i; int num_v = 0, first_v = 0; int v[MAX_VALUATORS] = {}; EvdevPtr pEvdev = pInfo->private; @@ -834,6 +973,7 @@ EvdevProcessSyncEvent(InputInfoPtr pInfo, struct input_event *ev) EvdevProcessProximityState(pInfo); EvdevProcessValuators(pInfo); + EvdevProcessTouch(pInfo); EvdevPostProximityEvents(pInfo, TRUE, num_v, first_v, v); EvdevPostRelativeMotionEvents(pInfo, num_v, first_v, v); @@ -842,7 +982,15 @@ EvdevProcessSyncEvent(InputInfoPtr pInfo, struct input_event *ev) EvdevPostProximityEvents(pInfo, FALSE, num_v, first_v, v); memset(pEvdev->delta, 0, sizeof(pEvdev->delta)); - memset(pEvdev->queue, 0, sizeof(pEvdev->queue)); + for (i = 0; i < ArrayLength(pEvdev->queue); i++) + { + EventQueuePtr queue = &pEvdev->queue[i]; + queue->detail.key = 0; + queue->type = 0; + queue->val = 0; + /* don't reset the touchMask */ + } + if (pEvdev->vals) valuator_mask_zero(pEvdev->vals); pEvdev->num_queue = 0; @@ -890,7 +1038,16 @@ EvdevReadInput(InputInfoPtr pInfo) while (len == sizeof(ev)) { - len = read(pInfo->fd, &ev, sizeof(ev)); +#ifdef MULTITOUCH + EvdevPtr pEvdev = pInfo->private; + + if (pEvdev->mtdev) + len = mtdev_get(pEvdev->mtdev, pInfo->fd, ev, NUM_EVENTS) * + sizeof(struct input_event); + else +#endif + len = read(pInfo->fd, &ev, sizeof(ev)); + if (len <= 0) { if (errno == ENODEV) /* May happen after resume */ @@ -986,12 +1143,50 @@ EvdevAddKeyClass(DeviceIntPtr device) return Success; } +/* MT axes are counted twice - once as ABS_X (which the kernel keeps for + * backwards compatibility), once as ABS_MT_POSITION_X. So we need to keep a + * mapping of those axes to make sure we only count them once + */ +struct mt_axis_mappings { + int mt_code; + int code; + Bool needs_mapping; /* TRUE if both code and mt_code are present */ + int mapping; /* Logical mapping of 'code' axis */ +}; + +static struct mt_axis_mappings mt_axis_mappings[] = { + {ABS_MT_POSITION_X, ABS_X}, + {ABS_MT_POSITION_Y, ABS_Y}, + {ABS_MT_PRESSURE, ABS_PRESSURE}, + {ABS_MT_DISTANCE, ABS_DISTANCE}, +}; + +/** + * return TRUE if the axis is not one we should count as true axis + */ +static int +is_blacklisted_axis(int axis) +{ + switch(axis) + { + case ABS_MT_SLOT: + case ABS_MT_TRACKING_ID: + return TRUE; + default: + return FALSE; + } +} + + static int EvdevAddAbsValuatorClass(DeviceIntPtr device) { InputInfoPtr pInfo; EvdevPtr pEvdev; int num_axes, axis, i = 0; + int num_mt_axes = 0, /* number of MT-only axes */ + num_mt_axes_total = 0; /* total number of MT axes, including + double-counted ones, excluding blacklisted */ Atom *atoms; pInfo = device->public.devicePrivate; @@ -1004,11 +1199,45 @@ EvdevAddAbsValuatorClass(DeviceIntPtr device) if (num_axes < 1) goto out; - if (num_axes > MAX_VALUATORS) { +#ifdef MULTITOUCH + for (axis = ABS_MT_SLOT; axis < ABS_MAX; axis++) + { + if (EvdevBitIsSet(pEvdev->abs_bitmask, axis)) + { + int j; + Bool skip = FALSE; + + for (j = 0; j < ArrayLength(mt_axis_mappings); j++) + { + if (mt_axis_mappings[j].mt_code == axis && + BitIsOn(pEvdev->abs_bitmask, mt_axis_mappings[j].code)) + { + mt_axis_mappings[j].needs_mapping = TRUE; + skip = TRUE; + } + } + + if (!is_blacklisted_axis(axis)) + { + num_mt_axes_total++; + if (!skip) + num_mt_axes++; + } + num_axes--; + } + } +#endif + if (num_axes + num_mt_axes > MAX_VALUATORS) { xf86IDrvMsg(pInfo, X_WARNING, "found %d axes, limiting to %d.\n", num_axes, MAX_VALUATORS); num_axes = MAX_VALUATORS; } + if (num_axes < 1 && num_mt_axes_total < 1) { + xf86Msg(X_WARNING, "%s: no absolute or touch axes found.\n", + device->name); + return !Success; + } + pEvdev->num_vals = num_axes; if (num_axes > 0) { pEvdev->vals = valuator_mask_new(num_axes); @@ -1018,25 +1247,81 @@ EvdevAddAbsValuatorClass(DeviceIntPtr device) goto out; } } - atoms = malloc(pEvdev->num_vals * sizeof(Atom)); +#ifdef MULTITOUCH + if (num_mt_axes_total > 0) { + pEvdev->mt_mask = valuator_mask_new(num_mt_axes_total); + if (!pEvdev->mt_mask) { + xf86Msg(X_ERROR, "%s: failed to allocate MT valuator mask.\n", + device->name); + goto out; + } + for (i = 0; i < EVDEV_MAXQUEUE; i++) { + pEvdev->queue[i].touchMask = + valuator_mask_new(num_mt_axes_total); + if (!pEvdev->queue[i].touchMask) { + xf86Msg(X_ERROR, "%s: failed to allocate MT valuator masks for " + "evdev event queue.\n", device->name); + goto out; + } + } + } +#endif + atoms = malloc((pEvdev->num_vals + num_mt_axes) * sizeof(Atom)); + + i = 0; for (axis = ABS_X; i < MAX_VALUATORS && axis <= ABS_MAX; axis++) { + int j; + int mapping; pEvdev->axis_map[axis] = -1; - if (!EvdevBitIsSet(pEvdev->abs_bitmask, axis)) + if (!EvdevBitIsSet(pEvdev->abs_bitmask, axis) || + is_blacklisted_axis(axis)) continue; - pEvdev->axis_map[axis] = i; - i++; + + mapping = i; + + for (j = 0; j < ArrayLength(mt_axis_mappings); j++) + { + if (mt_axis_mappings[j].code == axis) + mt_axis_mappings[j].mapping = mapping; + else if (mt_axis_mappings[j].mt_code == axis && + mt_axis_mappings[j].needs_mapping) + mapping = mt_axis_mappings[j].mapping; + } + + pEvdev->axis_map[axis] = mapping; + if (mapping == i) + i++; } - EvdevInitAxesLabels(pEvdev, pEvdev->num_vals, atoms); + EvdevInitAxesLabels(pEvdev, pEvdev->num_vals + num_mt_axes, atoms); - if (!InitValuatorClassDeviceStruct(device, num_axes, atoms, + if (!InitValuatorClassDeviceStruct(device, num_axes + num_mt_axes, atoms, GetMotionHistorySize(), Absolute)) { xf86IDrvMsg(pInfo, X_ERROR, "failed to initialize valuator class device.\n"); goto out; } - for (axis = ABS_X; axis <= ABS_MAX; axis++) { +#ifdef MULTITOUCH + if (num_mt_axes_total > 0) + { + int num_touches = 0; + int mode = pEvdev->flags & EVDEV_TOUCHPAD ? + XIDependentTouch : XIDirectTouch; + + if (pEvdev->mtdev->caps.slot.maximum > 0) + num_touches = pEvdev->mtdev->caps.slot.maximum; + + if (!InitTouchClassDeviceStruct(device, num_touches, mode, + num_mt_axes_total)) { + xf86Msg(X_ERROR, "%s: failed to initialize touch class device.\n", + device->name); + goto out; + } + } +#endif + + for (axis = ABS_X; axis < ABS_MT_SLOT; axis++) { int axnum = pEvdev->axis_map[axis]; int resolution = 10000; @@ -1057,6 +1342,40 @@ EvdevAddAbsValuatorClass(DeviceIntPtr device) xf86InitValuatorDefaults(device, axnum); } +#ifdef MULTITOUCH + for (axis = ABS_MT_TOUCH_MAJOR; axis <= ABS_MAX; axis++) { + int axnum = pEvdev->axis_map[axis]; + int resolution = 10000; + int j; + BOOL skip = FALSE; + + if (axnum < 0) + continue; + + for (j = 0; j < ArrayLength(mt_axis_mappings); j++) + if (mt_axis_mappings[j].mt_code == axis && + mt_axis_mappings[j].needs_mapping) + { + skip = TRUE; + break; + } + + /* MT axis is mapped, don't set up twice */ + if (skip) + continue; + + if (pEvdev->absinfo[axis].resolution) + resolution = pEvdev->absinfo[axis].resolution * 1000; + + xf86InitValuatorAxisStruct(device, axnum, + atoms[axnum], + pEvdev->absinfo[axis].minimum, + pEvdev->absinfo[axis].maximum, + resolution, 0, resolution, + Absolute); + } +#endif + free(atoms); for (i = 0; i < ArrayLength(proximity_bits); i++) @@ -1107,6 +1426,11 @@ out: valuator_mask_free(&pEvdev->vals); valuator_mask_free(&pEvdev->old_vals); valuator_mask_free(&pEvdev->prox); +#ifdef MULTITOUCH + valuator_mask_free(&pEvdev->mt_mask); + for (i = 0; i < EVDEV_MAXQUEUE; i++) + valuator_mask_free(&pEvdev->queue[i].touchMask); +#endif return !Success; } @@ -1440,6 +1764,9 @@ EvdevProc(DeviceIntPtr device, int what) { InputInfoPtr pInfo; EvdevPtr pEvdev; +#ifdef MULTITOUCH + int i; +#endif pInfo = device->public.devicePrivate; pEvdev = pInfo->private; @@ -1479,6 +1806,13 @@ EvdevProc(DeviceIntPtr device, int what) valuator_mask_free(&pEvdev->vals); valuator_mask_free(&pEvdev->old_vals); valuator_mask_free(&pEvdev->prox); +#ifdef MULTITOUCH + valuator_mask_free(&pEvdev->mt_mask); + for (i = 0; i < EVDEV_MAXQUEUE; i++) + valuator_mask_free(&pEvdev->queue[i].touchMask); + if (pEvdev->mtdev) + mtdev_close(pEvdev->mtdev); +#endif EvdevRemoveDevice(pInfo); pEvdev->min_maj = 0; break; @@ -1626,6 +1960,7 @@ EvdevProbe(InputInfoPtr pInfo) { int i, has_rel_axes, has_abs_axes, has_keys, num_buttons, has_scroll; int has_lmr; /* left middle right */ + int has_mt; /* multitouch */ int ignore_abs = 0, ignore_rel = 0; EvdevPtr pEvdev = pInfo->private; int rc = 1; @@ -1659,6 +1994,7 @@ EvdevProbe(InputInfoPtr pInfo) has_keys = FALSE; has_scroll = FALSE; has_lmr = FALSE; + has_mt = FALSE; num_buttons = 0; /* count all buttons */ @@ -1726,6 +2062,15 @@ EvdevProbe(InputInfoPtr pInfo) } } +#ifdef MULTITOUCH + for (i = ABS_MT_SLOT; i < ABS_MAX; i++) { + if (EvdevBitIsSet(pEvdev->abs_bitmask, i)) { + has_mt = TRUE; + break; + } + } +#endif + if (ignore_abs && has_abs_axes) { xf86IDrvMsg(pInfo, X_INFO, "Absolute axes present but ignored.\n"); @@ -1734,6 +2079,9 @@ EvdevProbe(InputInfoPtr pInfo) xf86IDrvMsg(pInfo, X_PROBED, "Found absolute axes\n"); pEvdev->flags |= EVDEV_ABSOLUTE_EVENTS; + if (has_mt) + xf86IDrvMsg(pInfo, X_PROBED, "Found absolute multitouch axes\n"); + if ((EvdevBitIsSet(pEvdev->abs_bitmask, ABS_X) && EvdevBitIsSet(pEvdev->abs_bitmask, ABS_Y))) { xf86IDrvMsg(pInfo, X_PROBED, "Found x and y absolute axes\n"); @@ -1891,12 +2239,26 @@ EvdevOpenDevice(InputInfoPtr pInfo) } } +#ifdef MULTITOUCH + pEvdev->mtdev = mtdev_new_open(pInfo->fd); + if (pEvdev->mtdev) + pEvdev->cur_slot = pEvdev->mtdev->caps.slot.value; + else { + xf86Msg(X_ERROR, "%s: Couldn't open mtdev device\n", pInfo->name); + return FALSE; + } +#endif + /* Check major/minor of device node to avoid adding duplicate devices. */ pEvdev->min_maj = EvdevGetMajorMinor(pInfo); if (EvdevIsDuplicate(pInfo)) { xf86IDrvMsg(pInfo, X_WARNING, "device file is duplicate. Ignoring.\n"); close(pInfo->fd); +#ifdef MULTITOUCH + mtdev_close_delete(pEvdev->mtdev); + pEvdev->mtdev = NULL; +#endif return BadMatch; } @@ -1937,6 +2299,10 @@ EvdevPreInit(InputDriverPtr drv, InputInfoPtr pInfo, int flags) if (rc != Success) goto error; +#ifdef MULTITOUCH + pEvdev->cur_slot = -1; +#endif + /* * We initialize pEvdev->in_proximity to 1 so that device that doesn't use * proximity will still report events. @@ -2334,6 +2700,17 @@ EvdevInitProperty(DeviceIntPtr dev) if (rc != Success) return; + if (EvdevDeviceIsVirtual(pEvdev->device)) + { + BOOL virtual = 1; + prop_virtual = MakeAtom(XI_PROP_VIRTUAL_DEVICE, + strlen(XI_PROP_VIRTUAL_DEVICE), TRUE); + rc = XIChangeDeviceProperty(dev, prop_virtual, XA_INTEGER, 8, + PropModeReplace, 1, &virtual, FALSE); + XISetDevicePropertyDeletable(dev, prop_virtual, FALSE); + } + + XISetDevicePropertyDeletable(dev, prop_device, FALSE); if (pEvdev->flags & (EVDEV_RELATIVE_EVENTS | EVDEV_ABSOLUTE_EVENTS)) @@ -2443,7 +2820,8 @@ EvdevSetProperty(DeviceIntPtr dev, Atom atom, XIPropertyValuePtr val, if (!checkonly) pEvdev->swap_axes = *((BOOL*)val->data); } else if (atom == prop_axis_label || atom == prop_btn_label || - atom == prop_product_id || atom == prop_device) + atom == prop_product_id || atom == prop_device || + atom == prop_virtual) return BadAccess; /* Read-only properties */ return Success; diff --git a/src/evdev.h b/src/evdev.h index b2e2f42..5fd99ff 100644 --- a/src/evdev.h +++ b/src/evdev.h @@ -39,6 +39,10 @@ #include <xf86_OSproc.h> #include <xkbstr.h> +#ifdef MULTITOUCH +#include <mtdev.h> +#endif + #ifndef EV_CNT /* linux 2.6.23 kernels and earlier lack _CNT defines */ #define EV_CNT (EV_MAX+1) #endif @@ -96,6 +100,18 @@ enum fkeymode { FKEYMODE_MMKEYS, /* function keys send multimedia keys */ }; +enum SlotState { + SLOTSTATE_OPEN = 8, + SLOTSTATE_CLOSE, + SLOTSTATE_UPDATE, + SLOTSTATE_EMPTY, +}; + +enum ButtonAction { + BUTTON_RELEASE = 0, + BUTTON_PRESS = 1 +}; + /* axis specific data for wheel emulation */ typedef struct { int up_button; @@ -109,9 +125,20 @@ typedef struct { EV_QUEUE_KEY, /* xf86PostKeyboardEvent() */ EV_QUEUE_BTN, /* xf86PostButtonEvent() */ EV_QUEUE_PROXIMITY, /* xf86PostProximityEvent() */ +#ifdef MULTITOUCH + EV_QUEUE_TOUCH, /*xf86PostTouchEvent() */ +#endif } type; - int key; /* May be either a key code or button number. */ - int val; /* State of the key/button; pressed or released. */ + union { + int key; /* May be either a key code or button number. */ +#ifdef MULTITOUCH + unsigned int touch; /* Touch ID */ +#endif + } detail; + int val; /* State of the key/button/touch; pressed or released. */ +#ifdef MULTITOUCH + ValuatorMask *touchMask; +#endif } EventQueueRec, *EventQueuePtr; typedef struct { @@ -126,6 +153,12 @@ typedef struct { ValuatorMask *vals; /* new values coming in */ ValuatorMask *old_vals; /* old values for calculating relative motion */ ValuatorMask *prox; /* last values set while not in proximity */ +#ifdef MULTITOUCH + ValuatorMask *mt_mask; + int cur_slot; + enum SlotState slot_state; + struct mtdev *mtdev; +#endif int flags; int in_proximity; /* device in proximity */ @@ -216,7 +249,11 @@ typedef struct { void EvdevQueueKbdEvent(InputInfoPtr pInfo, struct input_event *ev, int value); void EvdevQueueButtonEvent(InputInfoPtr pInfo, int button, int value); void EvdevQueueProximityEvent(InputInfoPtr pInfo, int value); -void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, int value); +#ifdef MULTITOUCH +void EvdevQueueTouchEvent(InputInfoPtr pInfo, unsigned int touch, + ValuatorMask *mask, uint16_t type); +#endif +void EvdevPostButtonEvent(InputInfoPtr pInfo, int button, enum ButtonAction act); void EvdevQueueButtonClicks(InputInfoPtr pInfo, int button, int count); void EvdevPostRelativeMotionEvents(InputInfoPtr pInfo, int num_v, int first_v, int v[MAX_VALUATORS]); diff --git a/src/udev.c b/src/udev.c new file mode 100644 index 0000000..9570d8f --- /dev/null +++ b/src/udev.c @@ -0,0 +1,69 @@ +/* + * Copyright © 2011 Red Hat, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of Red Hat + * not be used in advertising or publicity pertaining to distribution + * of the software without specific, written prior permission. Red + * Hat makes no representations about the suitability of this software + * for any purpose. It is provided "as is" without express or implied + * warranty. + * + * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Authors: + * Peter Hutterer (peter.hutterer@redhat.com) + */ + + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "evdev.h" + +#include <libudev.h> +#include <sys/types.h> +#include <sys/stat.h> + +Bool +udev_device_is_virtual(const char* devicenode) +{ + struct udev *udev = NULL; + struct udev_device *device = NULL; + struct stat st; + int rc = FALSE; + const char *devpath; + + udev = udev_new(); + if (!udev) + goto out; + + stat(devicenode, &st); + device = udev_device_new_from_devnum(udev, 'c', st.st_rdev); + + if (!device) + goto out; + + + devpath = udev_device_get_devpath(device); + if (!devpath) + goto out; + + if (strstr(devpath, "LNXSYSTM")) + rc = TRUE; + +out: + udev_device_unref(device); + udev_unref(udev); + return rc; +} |