aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile15
-rw-r--r--driver/multitouch.c8
-rw-r--r--include/abs2mt.h39
-rw-r--r--include/capabilities.h (renamed from include/mtdev-caps.h)8
-rw-r--r--include/common.h49
-rw-r--r--include/hwstate.h6
-rw-r--r--include/match.h36
-rw-r--r--include/mtbit.h14
-rw-r--r--include/mtdev-evbuf.h57
-rw-r--r--include/mtdev-iobuf.h38
-rw-r--r--include/mtdev.h57
-rw-r--r--include/mtouch.h7
-rw-r--r--match/match.c385
-rw-r--r--match/test.c135
-rw-r--r--mtdev/core.c402
-rw-r--r--mtdev/iobuf.c63
-rw-r--r--mtdev/mapgen.c69
-rw-r--r--mtdev/test.c79
-rw-r--r--src/capabilities.c (renamed from mtdev/caps.c)22
-rw-r--r--src/hwstate.c24
-rw-r--r--src/memory.c4
-rw-r--r--src/mtouch.c32
-rw-r--r--src/mtstate.c14
-rw-r--r--src/test.c4
24 files changed, 58 insertions, 1509 deletions
diff --git a/Makefile b/Makefile
index b8697a2..81eec08 100644
--- a/Makefile
+++ b/Makefile
@@ -4,20 +4,13 @@ EXTRAVERSION = beta1
LIBRARY = multitouch.so
FDIS = 11-multitouch.fdi
-MODULES = match mtdev src
+MODULES = src
XMODULES = driver
-o_match = match
-
-o_mtdev = iobuf caps core
-
-o_src = hwstate mtstate memory mtouch gestures
+o_src = capabilities hwstate mtstate memory mtouch gestures
o_driver= multitouch
-TARGETS += match/test
-TARGETS += mtdev/mapgen
-TARGETS += mtdev/test
TARGETS += src/test
OBJECTS = $(addsuffix .o,\
@@ -33,7 +26,7 @@ TOBJ = $(addprefix obj/,$(addsuffix .o,$(TARGETS)))
TFDI = $(addprefix fdi/,$(FDIS))
OBJS = $(addprefix obj/,$(OBJECTS))
XOBJS = $(addprefix obj/,$(XOBJECTS))
-LIBS = -lm
+LIBS = -lmtdev -lm
DLIB = usr/lib/xorg/modules/input
DFDI = usr/share/hal/fdi/policy/20thirdparty
@@ -52,7 +45,7 @@ bin/%: obj/%.o $(OBJS)
$(TLIB): $(OBJS) $(XOBJS)
@rm -f $(TLIB)
- gcc -shared $(OBJS) $(XOBJS) -Wl,-soname -Wl,$(LIBRARY) -o $@
+ gcc -shared $(OBJS) $(XOBJS) $(LIBS) -Wl,-soname -Wl,$(LIBRARY) -o $@
obj/%.o: %.c
@mkdir -p $(@D)
diff --git a/driver/multitouch.c b/driver/multitouch.c
index eef86c5..3ccc1c6 100644
--- a/driver/multitouch.c
+++ b/driver/multitouch.c
@@ -132,16 +132,16 @@ static int device_init(DeviceIntPtr dev, LocalDevicePtr local)
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
axes_labels[0],
#endif
- mt->caps.abs[BIT_POSITION_X].minimum,
- mt->caps.abs[BIT_POSITION_X].maximum,
+ mt->caps.abs[MTDEV_POSITION_X].minimum,
+ mt->caps.abs[MTDEV_POSITION_X].maximum,
1, 0, 1);
xf86InitValuatorDefaults(dev, 0);
xf86InitValuatorAxisStruct(dev, 1,
#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
axes_labels[1],
#endif
- mt->caps.abs[BIT_POSITION_Y].minimum,
- mt->caps.abs[BIT_POSITION_Y].maximum,
+ mt->caps.abs[MTDEV_POSITION_Y].minimum,
+ mt->caps.abs[MTDEV_POSITION_Y].maximum,
1, 0, 1);
xf86InitValuatorDefaults(dev, 1);
diff --git a/include/abs2mt.h b/include/abs2mt.h
deleted file mode 100644
index 6021d8d..0000000
--- a/include/abs2mt.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/* generated by mapgen - do not edit */
-
-#ifndef ABS2MT_H
-#define ABS2MT_H
-
-#include "common.h"
-
-static const unsigned int map_abs2mt[ABS_CNT] = {
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
- 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007, 0x0008,
- 0x0009, 0x000a, 0x000b, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
-};
-
-static const unsigned int map_mt2abs[MT_ABS_SIZE] = {
- 0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
- 0x0038, 0x0039, 0x003a,
-};
-
-static inline int has_abs2mt(unsigned int code)
-{
- return map_abs2mt[code];
-}
-
-static inline unsigned int abs2mt(unsigned int code)
-{
- return map_abs2mt[code] - 1;
-}
-
-static inline unsigned int mt2abs(unsigned int mtcode)
-{
- return map_mt2abs[mtcode];
-}
-
-#endif
diff --git a/include/mtdev-caps.h b/include/capabilities.h
index 727cd11..0dfc73b 100644
--- a/include/mtdev-caps.h
+++ b/include/capabilities.h
@@ -19,20 +19,18 @@
*
**************************************************************************/
-#ifndef MTDEV_CAPS_H
-#define MTDEV_CAPS_H
+#ifndef CAPABILITIES_H
+#define CAPABILITIES_H
#include "common.h"
#include "button.h"
-#include "abs2mt.h"
-#include "mtbit.h"
struct Capabilities {
struct input_id devid;
char devname[32];
int has_left, has_middle, has_right;
int has_mtdata, has_ibt;
- int has_slot, nullid;
+ int has_slot;
int has_abs[MT_ABS_SIZE];
struct input_absinfo slot;
struct input_absinfo abs[MT_ABS_SIZE];
diff --git a/include/common.h b/include/common.h
index e13088f..6d00d6e 100644
--- a/include/common.h
+++ b/include/common.h
@@ -26,59 +26,12 @@
#include <xf86.h>
#include <xf86_OSproc.h>
#include <xf86Xinput.h>
-#include <linux/input.h>
#include <errno.h>
-
-/* includes available in 2.6.30-rc5 */
-
-#ifndef BTN_TOOL_QUADTAP
-#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
-#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
-#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
-#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
-#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
-#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
-#define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */
-#define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */
-#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
-#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
-#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
-#define SYN_MT_REPORT 2
-#define MT_TOOL_FINGER 0
-#define MT_TOOL_PEN 1
-#endif
-
-/* includes available in 2.6.33 */
-#ifndef ABS_MT_PRESSURE
-#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
-#endif
-
-/* includes available in 2.6.36 */
-#ifndef ABS_MT_SLOT
-#define ABS_MT_SLOT 0x2f /* MT slot being modified */
-#define MT_SLOT_ABS_EVENTS { \
- ABS_MT_TOUCH_MAJOR, \
- ABS_MT_TOUCH_MINOR, \
- ABS_MT_WIDTH_MAJOR, \
- ABS_MT_WIDTH_MINOR, \
- ABS_MT_ORIENTATION, \
- ABS_MT_POSITION_X, \
- ABS_MT_POSITION_Y, \
- ABS_MT_TOOL_TYPE, \
- ABS_MT_BLOB_ID, \
- ABS_MT_TRACKING_ID, \
- ABS_MT_PRESSURE, \
-}
-#endif
-
-#define MT_ABS_SIZE 11 /* Size of MT_SLOT_ABS_EVENTS */
+#include <mtdev-mapping.h>
#define DIM_FINGER 32
#define DIM2_FINGER (DIM_FINGER * DIM_FINGER)
-/* event buffer size (must be a power of two) */
-#define DIM_EVENTS 512
-
/* year-proof millisecond event time */
typedef __u64 mstime_t;
diff --git a/include/hwstate.h b/include/hwstate.h
index efd291f..4c59a1e 100644
--- a/include/hwstate.h
+++ b/include/hwstate.h
@@ -22,7 +22,7 @@
#ifndef HWSTATE_H
#define HWSTATE_H
-#include "mtdev.h"
+#include "capabilities.h"
struct FingerState {
int touch_major, touch_minor;
@@ -42,8 +42,8 @@ struct HWState {
void init_hwstate(struct HWState *s,
const struct Capabilities *caps);
-int hwstate_read(struct HWState *s, const struct Capabilities *caps,
- const struct input_event *ev);
+int modify_hwstate(struct HWState *s, struct mtdev *dev, int fd,
+ const struct Capabilities *caps);
void output_hwstate(const struct HWState *s);
static inline int finger_dist2(const struct FingerState *a,
diff --git a/include/match.h b/include/match.h
deleted file mode 100644
index 25842fc..0000000
--- a/include/match.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#ifndef MATCHER_H
-#define MATCHER_H
-
-/**
- * Special implementation of the hungarian algorithm.
- * The maximum number of fingers matches a uint32.
- * Bitmasks are used extensively.
- */
-
-#include "common.h"
-
-void match_fingers(int index[DIM_FINGER], int A[DIM2_FINGER],
- int nrow, int ncol);
-
-#endif
diff --git a/include/mtbit.h b/include/mtbit.h
deleted file mode 100644
index 2c4dacb..0000000
--- a/include/mtbit.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/* generated by mapgen - do not edit */
-
-#ifndef MTBIT_H
-#define MTBIT_H
-
-#define BIT_TRACKING_ID 9
-#define BIT_POSITION_X 5
-#define BIT_POSITION_Y 6
-#define BIT_TOUCH_MAJOR 0
-#define BIT_TOUCH_MINOR 1
-#define BIT_WIDTH_MAJOR 2
-#define BIT_WIDTH_MINOR 3
-
-#endif
diff --git a/include/mtdev-evbuf.h b/include/mtdev-evbuf.h
deleted file mode 100644
index 77fec41..0000000
--- a/include/mtdev-evbuf.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#ifndef MTDEV_EVBUF_H
-#define MTDEV_EVBUF_H
-
-#include "common.h"
-
-struct EventBuffer {
- int head;
- int tail;
- struct input_event buffer[DIM_EVENTS];
-};
-
-static inline void evbuf_init(struct EventBuffer *evbuf)
-{
- memset(evbuf, 0, sizeof(*evbuf));
-}
-
-static inline int evbuf_empty(const struct EventBuffer *evbuf)
-{
- return evbuf->head == evbuf->tail;
-}
-
-static inline void evbuf_put(struct EventBuffer *evbuf,
- const struct input_event *ev)
-{
- evbuf->buffer[evbuf->head++] = *ev;
- evbuf->head &= DIM_EVENTS - 1;
-}
-
-static inline void evbuf_get(struct EventBuffer *evbuf,
- struct input_event *ev)
-{
- *ev = evbuf->buffer[evbuf->tail++];
- evbuf->tail &= DIM_EVENTS - 1;
-}
-
-#endif
diff --git a/include/mtdev-iobuf.h b/include/mtdev-iobuf.h
deleted file mode 100644
index 7d4265c..0000000
--- a/include/mtdev-iobuf.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#ifndef MTDEV_IOBUF_H
-#define MTDEV_IOBUF_H
-
-#include "common.h"
-
-#define EVENT_SIZE sizeof(struct input_event)
-#define DIM_BUFFER (DIM_EVENTS * EVENT_SIZE)
-
-struct IOBuffer {
- char begin[DIM_BUFFER], *at, *top, *end;
-};
-
-void init_iobuf(struct IOBuffer *buf);
-const struct input_event *get_iobuf_event(struct IOBuffer *buf, int fd);
-int poll_iobuf(struct IOBuffer *buf, int fd, int ms);
-
-#endif
diff --git a/include/mtdev.h b/include/mtdev.h
deleted file mode 100644
index 936d597..0000000
--- a/include/mtdev.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#ifndef MTDEV_H
-#define MTDEV_H
-
-#include "mtdev-caps.h"
-#include "mtdev-evbuf.h"
-
-/**
- * struct MTDev - represents an input MT device
- * @inbuf: input event buffer
- * @outbuf: output event buffer
- * @priv: structure of private data
- */
-struct MTDev {
- struct EventBuffer inbuf;
- struct EventBuffer outbuf;
- struct MTDevState *priv;
-};
-
-int mtdev_init(struct MTDev *mtdev, const struct Capabilities *caps);
-
-static inline int mtdev_empty(struct MTDev *mtdev)
-{
- return evbuf_empty(&mtdev->outbuf);
-}
-
-void mtdev_put(struct MTDev *dev, const struct Capabilities *caps,
- const struct input_event *ev);
-
-static inline void mtdev_get(struct MTDev *mtdev, struct input_event* ev)
-{
- evbuf_get(&mtdev->outbuf, ev);
-}
-
-void mtdev_destroy(struct MTDev *mtdev);
-
-#endif
diff --git a/include/mtouch.h b/include/mtouch.h
index 482d010..aedb02c 100644
--- a/include/mtouch.h
+++ b/include/mtouch.h
@@ -23,12 +23,10 @@
#define MTOUCH_H
#include "memory.h"
-#include "mtdev-iobuf.h"
struct MTouch {
struct Capabilities caps;
- struct MTDev dev;
- struct IOBuffer buf;
+ struct mtdev dev;
struct HWState hs;
struct MTState prev_state, state;
struct Memory mem;
@@ -36,10 +34,9 @@ struct MTouch {
int configure_mtouch(struct MTouch *mt, int fd);
int open_mtouch(struct MTouch *mt, int fd);
-int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max);
int close_mtouch(struct MTouch *mt, int fd);
-int parse_event(struct MTouch *mt, const struct input_event *ev);
+int read_packet(struct MTouch *mt, int fd);
int has_delayed_gestures(struct MTouch *mt, int fd);
diff --git a/match/match.c b/match/match.c
deleted file mode 100644
index 4cb4495..0000000
--- a/match/match.c
+++ /dev/null
@@ -1,385 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include "match.h"
-#include <string.h>
-#include <stdio.h>
-
-/**
- * Bitmap implementation of the hungarian algorithm (GPL license)
- *
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * Based on code released by Markus Buehren (2004) (BSD license)
- *
- * Copyright (C) 2004, Markus Buehren. All rights reserved.
- * See CREDITS file for full license terms.
- *
- */
-
-typedef unsigned col_t[1];
-typedef unsigned mat_t[DIM_FINGER];
-
-#define GET1(m, x) ((m[0] >> (x)) & 1U)
-#define SET1(m, x) (m[0] |= (1U << (x)))
-#define CLEAR1(m, x) (m[0] &= ~(1U << (x)))
-
-#define GET2(m, row, col) ((m[col] >> (row)) & 1U)
-#define SET2(m, row, col) (m[col] |= (1U << (row)))
-#define CLEAR2(m, row, col) (m[col] &= ~(1U << (row)))
-
-/********************************************************/
-
-static void buildixvector(int *ix, mat_t mstar, int nrows, int ncols)
-{
- int row, col;
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (GET2(mstar, row, col)) {
- ix[row] = col;
- break;
- }
- }
- }
-}
-
-
-/********************************************************/
-
-static void step2a(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin);
-static void step2b(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin);
-static void step3(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin);
-static void step4(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin, int row, int col);
-static void step5(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin);
-
-static void ixoptimal(int *ix, int *mdist, int nrows, int ncols)
-{
- int *mdistTemp, *mdistEnd, *columnEnd, value, minValue;
- int dmin, row, col;
- col_t ccol, crow;
- mat_t mstar, mprime, nmstar;
-
- memset(ccol, 0, sizeof(col_t));
- memset(crow, 0, sizeof(col_t));
- memset(mstar, 0, sizeof(mat_t));
- memset(mprime, 0, sizeof(mat_t));
- memset(nmstar, 0, sizeof(mat_t));
-
- /* initialization */
- for (row = 0; row < nrows; row++)
- ix[row] = -1;
-
- mdistEnd = mdist + nrows * ncols;
-
- /* preliminary steps */
- if (nrows <= ncols) {
- dmin = nrows;
-
- for (row = 0; row < nrows; row++) {
- /* find the smallest element in the row */
- mdistTemp = mdist + row;
- minValue = *mdistTemp;
- mdistTemp += nrows;
- while (mdistTemp < mdistEnd) {
- value = *mdistTemp;
- if (value < minValue)
- minValue = value;
- mdistTemp += nrows;
- }
-
- /* subtract the smallest element from each element
- of the row */
- mdistTemp = mdist + row;
- while (mdistTemp < mdistEnd) {
- *mdistTemp -= minValue;
- mdistTemp += nrows;
- }
- }
-
- /* Steps 1 and 2a */
- for (row = 0; row < nrows; row++) {
- for (col = 0; col < ncols; col++) {
- if (mdist[row + nrows * col] != 0)
- continue;
- if (GET1(ccol, col))
- continue;
- SET2(mstar, row, col);
- SET1(ccol, col);
- break;
- }
- }
- } else {
- dmin = ncols;
-
- for (col = 0; col < ncols; col++) {
- /* find the smallest element in the column */
- mdistTemp = mdist + nrows*col;
- columnEnd = mdistTemp + nrows;
-
- minValue = *mdistTemp++;
- while (mdistTemp < columnEnd) {
- value = *mdistTemp++;
- if (value < minValue)
- minValue = value;
- }
-
- /* subtract the smallest element from each element
- of the column */
- mdistTemp = mdist + nrows*col;
- while (mdistTemp < columnEnd)
- *mdistTemp++ -= minValue;
- }
-
- /* Steps 1 and 2a */
- for (col = 0; col < ncols; col++) {
- for (row = 0; row < nrows; row++) {
- if (mdist[row + nrows * col] != 0)
- continue;
- if (GET1(crow, row))
- continue;
- SET2(mstar, row, col);
- SET1(ccol, col);
- SET1(crow, row);
- break;
- }
- }
- memset(crow, 0, sizeof(col_t));
- }
-
- /* move to step 2b */
- step2b(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin);
-}
-
-/********************************************************/
-static void step2a(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin)
-{
- int col, row;
-
- /* cover every column containing a starred zero */
- for (col = 0; col < ncols; col++) {
- for (row = 0; row < nrows; row++) {
- if (!GET2(mstar, row, col))
- continue;
- SET1(ccol, col);
- break;
- }
- }
-
- /* move to step 3 */
- step2b(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin);
-}
-
-/********************************************************/
-static void step2b(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin)
-{
- int col, ncc;
-
- /* count covered columns */
- ncc = 0;
- for (col = 0; col < ncols; col++)
- if (GET1(ccol, col))
- ncc++;
-
- if (ncc == dmin) {
- /* algorithm finished */
- buildixvector(ix, mstar, nrows, ncols);
- } else {
- /* move to step 3 */
- step3(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin);
- }
-
-}
-
-/********************************************************/
-static void step3(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin)
-{
- int zerosFound;
- int row, col, cstar;
-
- zerosFound = 1;
- while (zerosFound) {
- zerosFound = 0;
- for (col = 0; col < ncols; col++) {
- if (GET1(ccol, col))
- continue;
- for (row = 0; row < nrows; row++) {
- if (mdist[row + nrows * col] != 0)
- continue;
- if (GET1(crow, row))
- continue;
-
- /* prime zero */
- SET2(mprime, row, col);
-
- /* find starred zero in current row */
- for (cstar = 0; cstar < ncols; cstar++)
- if (GET2(mstar, row, cstar))
- break;
-
- if (cstar == ncols) { /* no starred zero */
- /* move to step 4 */
- step4(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin, row, col);
- return;
- } else {
- SET1(crow, row);
- CLEAR1(ccol, cstar);
- zerosFound = 1;
- break;
- }
- }
- }
- }
-
- /* move to step 5 */
- step5(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin);
-}
-
-/********************************************************/
-static void step4(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin, int row, int col)
-{
- int n, rstar, cstar, primeRow, primeCol;
-
- /* generate temporary copy of mstar */
- memcpy(nmstar, mstar, sizeof(mat_t));
-
- /* star current zero */
- SET2(nmstar, row, col);
-
- /* find starred zero in current column */
- cstar = col;
- for (rstar = 0; rstar < nrows; rstar++)
- if (GET2(mstar, rstar, cstar))
- break;
-
- while (rstar < nrows) {
- /* unstar the starred zero */
- CLEAR2(nmstar, rstar, cstar);
-
- /* find primed zero in current row */
- primeRow = rstar;
- for (primeCol = 0; primeCol < ncols; primeCol++)
- if (GET2(mprime, primeRow, primeCol))
- break;
-
- /* star the primed zero */
- SET2(nmstar, primeRow, primeCol);
-
- /* find starred zero in current column */
- cstar = primeCol;
- for (rstar = 0; rstar < nrows; rstar++)
- if (GET2(mstar, rstar, cstar))
- break;
- }
-
- /* use temporary copy as new mstar */
- /* delete all primes, uncover all rows */
- memcpy(mstar, nmstar, sizeof(mat_t));
- memset(mprime, 0, sizeof(mat_t));
- memset(crow, 0, sizeof(col_t));
-
- /* move to step 2a */
- step2a(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin);
-}
-
-/********************************************************/
-static void step5(int *ix, int *mdist, mat_t mstar, mat_t nmstar,
- mat_t mprime, col_t ccol, col_t crow, int nrows, int ncols,
- int dmin)
-{
- int h = 0, value;
- int row, col, found = 0;
-
- /* find smallest uncovered element h */
- for (row = 0; row < nrows; row++) {
- if (GET1(crow, row))
- continue;
- for (col = 0; col < ncols; col++) {
- if (GET1(ccol, col))
- continue;
- value = mdist[row + nrows * col];
- if (!found || value < h) {
- h = value;
- found = 1;
- }
- }
- }
-
- /* where to go if nothing uncovered? */
- if (!found)
- return;
-
- /* add h to each covered row */
- for (row = 0; row < nrows; row++) {
- if (!GET1(crow, row))
- continue;
- for (col = 0; col < ncols; col++)
- mdist[row + nrows * col] += h;
- }
-
- /* subtract h from each uncovered column */
- for (col = 0; col < ncols; col++) {
- if (GET1(ccol, col))
- continue;
- for (row = 0; row < nrows; row++)
- mdist[row + nrows * col] -= h;
- }
-
- /* move to step 3 */
- step3(ix, mdist, mstar, nmstar,
- mprime, ccol, crow, nrows, ncols,
- dmin);
-}
-
-void match_fingers(int ix[DIM_FINGER], int A[DIM2_FINGER], int nrow, int ncol)
-{
- ixoptimal(ix, A, nrow, ncol);
-}
-
diff --git a/match/test.c b/match/test.c
deleted file mode 100644
index dabc083..0000000
--- a/match/test.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include <match.h>
-#include <xbypass.h>
-#include <stdio.h>
-#include <time.h>
-
-#define ITS 1000000
-
-static void test1()
-{
- int A[] = {
- 1013,
- 3030660,
- 3559354,
- 12505925,
- 19008450,
- 6946421,
- 6118613,
- 698020,
- 3021800,
- 1017,
- 37573,
- 3242018,
- 8152794,
- 1266053,
- 942941,
- 462820,
- };
- int index[DIM_FINGER], i;
- match_fingers(index, A, 4, 4);
- for (i = 0; i < 4; i++)
- printf("match[%d] = %d\n", i, index[i]);
-}
-
-static void test2()
-{
- int A[] = {
- 0,
- 4534330,
- 22653552,
- 12252500,
- 685352,
- 4534330,
- 0,
- 9619317,
- 28409530,
- 6710170,
- 22653552,
- 9619317,
- 0,
- 47015292,
- 29788572,
- 2809040,
- 10428866,
- 38615920,
- 17732500,
- 719528,
- 12113945,
- 28196220,
- 46778656,
- 405,
- 14175493,
- };
- int index[DIM_FINGER], i;
- match_fingers(index, A, 5, 5);
- for (i = 0; i < 5; i++)
- printf("match[%d] = %d\n", i, index[i]);
-}
-
-static void speed1()
-{
- /* column-by-column matrix */
- int A[DIM2_FINGER];
- int x1[DIM_FINGER] = { 1, 5, 2, 3, 4, 5, 6, 7, 8 };
- int y1[DIM_FINGER] = { 1, 5, 2, 3, 4, 6, 6, 7, 8 };
- int x2[DIM_FINGER] = { 1.1, 3, 2, 4, 5, 6, 7, 8 };
- int y2[DIM_FINGER] = { 1, 3, 2, 4, 5, 6, 7, 8 };
- int index[DIM_FINGER];
- int n1 = 4;
- int n2 = 7;
-
- int i, j;
-
- for (i = 0; i < n1; i++) {
- for (j = 0; j < n2; j++) {
- A[i + n1 * j] =
- (x1[i] - x2[j]) * (x1[i] - x2[j]) +
- (y1[i] - y2[j]) * (y1[i] - y2[j]);
- }
- }
-
- clock_t t1 = clock();
- for (i = 0; i < ITS; i++)
- match_fingers(index, A, n1, n2);
- clock_t t2 = clock();
-
- printf("%lf matches per second\n",
- ITS * ((float)CLOCKS_PER_SEC / (t2 - t1)));
-
- for (i = 0; i < n1; i++)
- printf("match[%d] = %d\n", i, index[i]);
-
-}
-
-int main(int argc, char *argv[])
-{
- printf("test1\n");
- test1();
- printf("test2\n");
- test2();
- printf("speed1\n");
- speed1();
- printf("done\n");
- return 0;
-}
diff --git a/mtdev/core.c b/mtdev/core.c
deleted file mode 100644
index f13da13..0000000
--- a/mtdev/core.c
+++ /dev/null
@@ -1,402 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include "mtdev.h"
-#include "mtbit.h"
-
-/**
- * struct MTSlot - represents the state of an input MT slot
- * @abs: current values of ABS_MT axes for this slot
- */
-struct MTSlot {
- int abs[MT_ABS_SIZE];
-};
-
-/**
- * struct MTDevState - MT slot parsing
- * @data: array of scratch slot data
- * @used: bitmask of currently used slots
- * @slot: slot currently being modified
- * @lastid: last used tracking id
- */
-struct MTDevState {
- struct MTSlot data[DIM_FINGER];
- bitmask_t used;
- bitmask_t slot;
- bitmask_t lastid;
-};
-
-/**
- * mtdev_init - init MT device
- * @dev: device to initialize
- * @caps: device capabilities
- */
-int mtdev_init(struct MTDev *dev, const struct Capabilities *caps)
-{
- memset(dev, 0, sizeof(struct MTDev));
- if (!caps->has_mtdata)
- return -ENODEV;
- if (!caps->has_slot) {
- dev->priv = calloc(1, sizeof(struct MTDevState));
- if (!dev->priv)
- return -ENOMEM;
- }
- return 0;
-}
-
-static inline int istouch(const struct MTSlot *data,
- const struct Capabilities *caps)
-{
- return data->abs[BIT_TOUCH_MAJOR] || !caps->has_abs[BIT_TOUCH_MAJOR];
-}
-
-/* Dmitry Torokhov's code from kernel/driver/input/input.c */
-static int defuzz(int value, int old_val, int fuzz)
-{
- if (fuzz) {
- if (value > old_val - fuzz / 2 && value < old_val + fuzz / 2)
- return old_val;
-
- if (value > old_val - fuzz && value < old_val + fuzz)
- return (old_val * 3 + value) / 4;
-
- if (value > old_val - fuzz * 2 && value < old_val + fuzz * 2)
- return (old_val + value) / 2;
- }
-
- return value;
-}
-
-/*
- * solve - solve contact matching problem
- * @priv: parsing state
- * @caps: device capabilities
- * @sid: array of current tracking ids
- * @sx: array of current position x
- * @sy: array of current position y
- * @sn: number of current contacts
- * @nid: array of new or matched tracking ids, to be filled
- * @nx: array of new position x
- * @ny: array of new position y
- * @nn: number of new contacts
- * @touch: which of the new contacts to fill
- */
-static void solve(struct MTDevState *priv, const struct Capabilities *caps,
- const int *sid, const int *sx, const int *sy, int sn,
- int *nid, const int *nx, const int *ny, int nn,
- bitmask_t touch)
-{
- int A[DIM2_FINGER], *row;
- int n2s[DIM_FINGER];
- int id, i, j;
-
- /* setup distance matrix for contact matching */
- for (j = 0; j < sn; j++) {
- row = A + nn * j;
- for (i = 0; i < nn; i++)
- row[i] = dist2(nx[i] - sx[j], ny[i] - sy[j]);
- }
-
- match_fingers(n2s, A, nn, sn);
-
- /* update matched contacts and create new ones */
- foreach_bit(i, touch) {
- j = n2s[i];
- id = j >= 0 ? sid[j] : caps->nullid;
- while (id == caps->nullid)
- id = ++priv->lastid;
- nid[i] = id;
- }
-}
-
-/*
- * assign_tracking_id - assign tracking ids to all contacts
- * @priv: parsing state
- * @caps: device capabilities
- * @data: array of all present contacts, to be filled
- * @prop: array of all set contacts properties
- * @size: number of contacts in array
- * @touch: which of the contacts are actual touches
- */
-static void assign_tracking_id(struct MTDevState *priv,
- const struct Capabilities *caps,
- struct MTSlot *data, bitmask_t *prop,
- int size, bitmask_t touch)
-{
- int sid[DIM_FINGER], sx[DIM_FINGER], sy[DIM_FINGER], sn = 0;
- int nid[DIM_FINGER], nx[DIM_FINGER], ny[DIM_FINGER], i;
- foreach_bit(i, priv->used) {
- sid[sn] = priv->data[i].abs[BIT_TRACKING_ID];
- sx[sn] = priv->data[i].abs[BIT_POSITION_X];
- sy[sn] = priv->data[i].abs[BIT_POSITION_Y];
- sn++;
- }
- for (i = 0; i < size; i++) {
- nx[i] = data[i].abs[BIT_POSITION_X];
- ny[i] = data[i].abs[BIT_POSITION_Y];
- }
- solve(priv, caps, sid, sx, sy, sn, nid, nx, ny, size, touch);
- for (i = 0; i < size; i++) {
- data[i].abs[BIT_TRACKING_ID] =
- GETBIT(touch, i) ? nid[i] : caps->nullid;
- prop[i] |= BITMASK(BIT_TRACKING_ID);
- }
-}
-
-/*
- * process_typeA - consume MT events and update parsing state
- * @dev: MT device
- * @data: array of all present contacts, to be filled
- * @prop: array of all set contacts properties, to be filled
- *
- * This function is called when a SYN_REPORT is seen, right before
- * that event is pushed to the queue.
- *
- * Returns -1 if the packet is not MT related and should not affect
- * the current parsing state.
- */
-static int process_typeA(struct MTDev *dev,
- struct MTSlot *data, bitmask_t *prop)
-{
- struct input_event ev;
- int consumed, mtcode;
- int mtcnt = 0, size = 0;
- prop[size] = 0;
- while (!evbuf_empty(&dev->inbuf)) {
- evbuf_get(&dev->inbuf, &ev);
- consumed = 0;
- switch (ev.type) {
- case EV_SYN:
- switch (ev.code) {
- case SYN_MT_REPORT:
- if (size < DIM_FINGER &&
- GETBIT(prop[size], BIT_POSITION_X) &&
- GETBIT(prop[size], BIT_POSITION_Y))
- size++;
- if (size < DIM_FINGER)
- prop[size] = 0;
- mtcnt++;
- consumed = 1;
- break;
- }
- break;
- case EV_KEY:
- switch (ev.code) {
- case BTN_TOUCH:
- mtcnt++;
- break;
- }
- break;
- case EV_ABS:
- if (size < DIM_FINGER && has_abs2mt(ev.code)) {
- mtcode = abs2mt(ev.code);
- data[size].abs[mtcode] = ev.value;
- prop[size] |= BITMASK(mtcode);
- mtcnt++;
- consumed = 1;
- }
- break;
- }
- if (!consumed)
- evbuf_put(&dev->outbuf, &ev);
- }
- return mtcnt ? size : -1;
-}
-
-/*
- * process_typeB - propagate events without parsing
- * @dev: MT device
- *
- * This function is called when a SYN_REPORT is seen, right before
- * that event is pushed to the queue.
- */
-static void process_typeB(struct MTDev *dev)
-{
- struct input_event ev;
- while (!evbuf_empty(&dev->inbuf)) {
- evbuf_get(&dev->inbuf, &ev);
- evbuf_put(&dev->outbuf, &ev);
- }
-}
-
-/*
- * filter_data - apply input filtering on new incoming data
- * @priv: parsing state
- * @caps: device capabilities
- * @data: the incoming data to filter
- * @prop: the properties to filter
- * @slot: the slot the data refers to
- */
-static void filter_data(const struct MTDevState *priv,
- const struct Capabilities *caps,
- struct MTSlot *data, bitmask_t prop,
- int slot)
-{
- int i;
- foreach_bit(i, prop) {
- int fuzz = caps->abs[i].fuzz;
- int oldval = priv->data[slot].abs[i];
- data->abs[i] = defuzz(data->abs[i], oldval, fuzz);
- }
-}
-
-/*
- * push_slot_changes - propagate state changes
- * @dev: MT device
- * @data: the incoming data to propagate
- * @prop: the properties to propagate
- * @slot: the slot the data refers to
- * @syn: reference to the SYN_REPORT event
- */
-static void push_slot_changes(struct MTDev *dev,
- const struct MTSlot *data, bitmask_t prop,
- int slot, const struct input_event *syn)
-{
- struct MTDevState *priv = dev->priv;
- struct input_event ev;
- int i, count = 0;
- foreach_bit(i, prop)
- if (priv->data[slot].abs[i] != data->abs[i])
- count++;
- if (!count)
- return;
- ev.time = syn->time;
- ev.type = EV_ABS;
- ev.code = ABS_MT_SLOT;
- ev.value = slot;
- if (priv->slot != ev.value) {
- evbuf_put(&dev->outbuf, &ev);
- priv->slot = ev.value;
- }
- foreach_bit(i, prop) {
- ev.code = mt2abs(i);
- ev.value = data->abs[i];
- if (priv->data[slot].abs[i] != ev.value) {
- evbuf_put(&dev->outbuf, &ev);
- priv->data[slot].abs[i] = ev.value;
- }
- }
-}
-
-/*
- * apply_typeA_changes - parse and propagate state changes
- * @dev: MT device
- * @caps: device capabilities
- * @data: array of data to apply
- * @prop: array of properties to apply
- * @size: number of contacts in array
- * @syn: reference to the SYN_REPORT event
- */
-static void apply_typeA_changes(struct MTDev *dev,
- const struct Capabilities *caps,
- struct MTSlot *data, const bitmask_t *prop,
- int size, const struct input_event *syn)
-{
- struct MTDevState *priv = dev->priv;
- bitmask_t unused = ~priv->used;
- bitmask_t used = 0;
- int i, slot, id;
- for (i = 0; i < size; i++) {
- id = data[i].abs[BIT_TRACKING_ID];
- foreach_bit(slot, priv->used) {
- if (priv->data[slot].abs[BIT_TRACKING_ID] != id)
- continue;
- filter_data(priv, caps, &data[i], prop[i], slot);
- push_slot_changes(dev, &data[i], prop[i], slot, syn);
- SETBIT(used, slot);
- id = caps->nullid;
- break;
- }
- if (id != caps->nullid) {
- slot = firstbit(unused);
- push_slot_changes(dev, &data[i], prop[i], slot, syn);
- SETBIT(used, slot);
- CLEARBIT(unused, slot);
- }
- }
-
- /* clear unused slots and update slot usage */
- foreach_bit(slot, priv->used & ~used) {
- struct MTSlot tdata = priv->data[slot];
- bitmask_t tprop = BITMASK(BIT_TRACKING_ID);
- tdata.abs[BIT_TRACKING_ID] = caps->nullid;
- push_slot_changes(dev, &tdata, tprop, slot, syn);
- }
- priv->used = used;
-}
-
-/*
- * convert_A_to_B - propagate a type A packet as a type B packet
- * @dev: MT device
- * @caps: device capabilities
- * @syn: reference to the SYN_REPORT event
- */
-static void convert_A_to_B(struct MTDev *dev,
- const struct Capabilities *caps,
- const struct input_event *syn)
-{
- struct MTSlot data[DIM_FINGER];
- bitmask_t prop[DIM_FINGER];
- int size = process_typeA(dev, data, prop);
- if (size < 0)
- return;
- if (!caps->has_abs[BIT_TRACKING_ID]) {
- bitmask_t touch = 0;
- int i;
- for (i = 0; i < size; i++)
- MODBIT(touch, i, istouch(&data[i], caps));
- assign_tracking_id(dev->priv, caps, data, prop, size, touch);
- }
- apply_typeA_changes(dev, caps, data, prop, size, syn);
-}
-
-/**
- * mtdev_put - insert event into MT device
- * @dev: MT device
- * @caps: device capabilities
- * @syn: reference to the SYN_REPORT event
- */
-void mtdev_put(struct MTDev *dev,
- const struct Capabilities *caps,
- const struct input_event *ev)
-{
- if (ev->type == EV_SYN && ev->code == SYN_REPORT) {
- bitmask_t head = dev->outbuf.head;
- if (dev->priv)
- convert_A_to_B(dev, caps, ev);
- else
- process_typeB(dev);
- if (dev->outbuf.head != head)
- evbuf_put(&dev->outbuf, ev);
- } else {
- evbuf_put(&dev->inbuf, ev);
- }
-}
-
-/**
- * mtdev_destroy - destroy MT device
- * @dev: MT device
- */
-void mtdev_destroy(struct MTDev *dev)
-{
- free(dev->priv);
- memset(dev, 0, sizeof(struct MTDev));
-}
diff --git a/mtdev/iobuf.c b/mtdev/iobuf.c
deleted file mode 100644
index 65c33f6..0000000
--- a/mtdev/iobuf.c
+++ /dev/null
@@ -1,63 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include <mtdev-iobuf.h>
-#include <sys/poll.h>
-
-void init_iobuf(struct IOBuffer *buf)
-{
- memset(buf, 0, sizeof(struct IOBuffer));
- buf->at = buf->begin;
- buf->top = buf->at;
- buf->end = buf->begin + DIM_BUFFER;
-}
-
-const struct input_event *get_iobuf_event(struct IOBuffer *buf, int fd)
-{
- const struct input_event *ev;
- int n = buf->top - buf->at;
- if (n < EVENT_SIZE) {
- /* partial event is available: save it */
- if (buf->at != buf->begin && n > 0)
- memmove(buf->begin, buf->at, n);
- /* start from the beginning */
- buf->at = buf->begin;
- buf->top = buf->at + n;
- /* read more data */
- SYSCALL(n = read(fd, buf->top, buf->end - buf->top));
- if (n <= 0)
- return NULL;
- buf->top += n;
- }
- if (buf->top - buf->at < EVENT_SIZE)
- return NULL;
- ev = (const struct input_event *)buf->at;
- buf->at += EVENT_SIZE;
- return ev;
-}
-
-int poll_iobuf(struct IOBuffer *buf, int fd, int ms)
-{
- struct pollfd fds = { fd, POLLIN, 0 };
- if (buf->top != buf->at)
- return 1;
- return poll(&fds, 1, ms);
-}
diff --git a/mtdev/mapgen.c b/mtdev/mapgen.c
deleted file mode 100644
index efb3524..0000000
--- a/mtdev/mapgen.c
+++ /dev/null
@@ -1,69 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include <common.h>
-#include <fcntl.h>
-#include <xbypass.h>
-
-#define BIT_DEF(name) \
- printf("#define BIT_"#name" %d\n", \
- cabs2mt[ABS_MT_##name] - 1)
-
-static unsigned int cabs2mt[ABS_CNT];
-static unsigned int cmt2abs[MT_ABS_SIZE];
-
-void init_caps()
-{
- static const int init_abs_map[MT_ABS_SIZE] = MT_SLOT_ABS_EVENTS;
- int i;
- for (i = 0; i < MT_ABS_SIZE; i++) {
- cabs2mt[init_abs_map[i]] = i + 1;
- cmt2abs[i] = init_abs_map[i];
- }
-}
-
-static inline const char *newln(int i, int n)
-{
- return i == n - 1 || i % 8 == 7 ? "\n" : "";
-}
-
-int main(int argc, char *argv[])
-{
- int i;
- init_caps();
- printf("static const unsigned int map_abs2mt[ABS_CNT] = {\n");
- for (i = 0; i < ABS_CNT; i++)
- printf(" 0x%04x,%s", cabs2mt[i], newln(i, ABS_CNT));
- printf("};\n\n");
- printf("static const unsigned int map_mt2abs[MT_ABS_SIZE] = {\n");
- for (i = 0; i < MT_ABS_SIZE; i++)
- printf(" 0x%04x,%s", cmt2abs[i], newln(i, MT_ABS_SIZE));
- printf("};\n\n");
- BIT_DEF(TRACKING_ID);
- BIT_DEF(POSITION_X);
- BIT_DEF(POSITION_Y);
- BIT_DEF(TOUCH_MAJOR);
- BIT_DEF(TOUCH_MINOR);
- BIT_DEF(WIDTH_MAJOR);
- BIT_DEF(WIDTH_MINOR);
- printf("\n");
- return 0;
-}
diff --git a/mtdev/test.c b/mtdev/test.c
deleted file mode 100644
index 9f73fcd..0000000
--- a/mtdev/test.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/***************************************************************************
- *
- * Multitouch X driver
- * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- **************************************************************************/
-
-#include "mtdev-iobuf.h"
-#include "mtdev.h"
-#include <fcntl.h>
-#include <xbypass.h>
-
-static void print_event(const struct input_event *ev)
-{
- static const mstime_t ms = 1000;
- static int slot;
- mstime_t evtime = ev->time.tv_usec / ms + ev->time.tv_sec * ms;
- if (ev->type == EV_ABS && ev->code == ABS_MT_SLOT)
- slot = ev->value;
- fprintf(stderr, "%012llx: %04d: %04x %04x %d\n",
- evtime, slot, ev->type, ev->code, ev->value);
-}
-
-static void loop_device(int fd)
-{
- struct Capabilities caps;
- struct IOBuffer iobuf;
- struct MTDev mtdev;
- const struct input_event *ev;
- struct input_event event;
- if (read_capabilities(&caps, fd)) {
- fprintf(stderr, "error: could not read device capabilities\n");
- return;
- }
- output_capabilities(&caps);
- if (mtdev_init(&mtdev, &caps)) {
- fprintf(stderr, "error: could not initialize device\n");
- return;
- }
- init_iobuf(&iobuf);
- while (ev = get_iobuf_event(&iobuf, fd)) {
- mtdev_put(&mtdev, &caps, ev);
- while (!mtdev_empty(&mtdev)) {
- mtdev_get(&mtdev, &event);
- print_event(&event);
- }
- }
- mtdev_destroy(&mtdev);
-}
-
-int main(int argc, char *argv[])
-{
- if (argc < 2) {
- fprintf(stderr, "Usage: test <mtdev>\n");
- return -1;
- }
- int fd = open(argv[1], O_RDONLY);
- if (fd < 0) {
- fprintf(stderr, "error: could not open file\n");
- return -1;
- }
- loop_device(fd);
- close(fd);
- return 0;
-}
diff --git a/mtdev/caps.c b/src/capabilities.c
index 069816e..0d11669 100644
--- a/mtdev/caps.c
+++ b/src/capabilities.c
@@ -19,8 +19,7 @@
*
**************************************************************************/
-#include "mtdev-caps.h"
-#include "mtbit.h"
+#include "capabilities.h"
#define SETABS(c, x, map, key, fd) \
(c->has_##x = getbit(map, key) && getabs(&c->x, key, fd))
@@ -52,7 +51,7 @@ static int getabs(struct input_absinfo *abs, int key, int fd)
static int has_mt_data(const struct Capabilities *cap)
{
- return cap->has_abs[BIT_POSITION_X] && cap->has_abs[BIT_POSITION_Y];
+ return cap->has_abs[MTDEV_POSITION_X] && cap->has_abs[MTDEV_POSITION_Y];
}
static int has_integrated_button(const struct Capabilities *cap)
@@ -65,7 +64,7 @@ static int has_integrated_button(const struct Capabilities *cap)
static void default_fuzz(struct Capabilities *cap, unsigned int code, int sn)
{
- int bit = abs2mt(code);
+ int bit = mtdev_abs2mt(code);
if (cap->has_abs[bit] && cap->abs[bit].fuzz == 0)
cap->abs[bit].fuzz =
(cap->abs[bit].maximum - cap->abs[bit].minimum) / sn;
@@ -102,14 +101,11 @@ int read_capabilities(struct Capabilities *cap, int fd)
SETABS(cap, slot, absbits, ABS_MT_SLOT, fd);
for (i = 0; i < MT_ABS_SIZE; i++)
- SETABS(cap, abs[i], absbits, mt2abs(i), fd);
+ SETABS(cap, abs[i], absbits, mtdev_mt2abs(i), fd);
cap->has_mtdata = has_mt_data(cap);
cap->has_ibt = has_integrated_button(cap);
- if (cap->has_abs[BIT_TRACKING_ID])
- cap->nullid = cap->abs[BIT_TRACKING_ID].minimum - 1;
-
default_fuzz(cap, ABS_MT_POSITION_X, SN_COORD);
default_fuzz(cap, ABS_MT_POSITION_Y, SN_COORD);
default_fuzz(cap, ABS_MT_TOUCH_MAJOR, SN_WIDTH);
@@ -123,31 +119,31 @@ int read_capabilities(struct Capabilities *cap, int fd)
int get_cap_xsize(const struct Capabilities *cap)
{
- const struct input_absinfo *x = &cap->abs[BIT_POSITION_X];
+ const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X];
return x->maximum - x->minimum;
}
int get_cap_ysize(const struct Capabilities *cap)
{
- const struct input_absinfo *y = &cap->abs[BIT_POSITION_Y];
+ const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y];
return y->maximum - y->minimum;
}
int get_cap_wsize(const struct Capabilities *cap)
{
- const struct input_absinfo *w = &cap->abs[BIT_TOUCH_MAJOR];
+ const struct input_absinfo *w = &cap->abs[MTDEV_TOUCH_MAJOR];
return w->maximum - w->minimum;
}
int get_cap_xmid(const struct Capabilities *cap)
{
- const struct input_absinfo *x = &cap->abs[BIT_POSITION_X];
+ const struct input_absinfo *x = &cap->abs[MTDEV_POSITION_X];
return (x->maximum + x->minimum) >> 1;
}
int get_cap_ymid(const struct Capabilities *cap)
{
- const struct input_absinfo *y = &cap->abs[BIT_POSITION_Y];
+ const struct input_absinfo *y = &cap->abs[MTDEV_POSITION_Y];
return (y->maximum + y->minimum) >> 1;
}
diff --git a/src/hwstate.c b/src/hwstate.c
index 82a3a10..076efa1 100644
--- a/src/hwstate.c
+++ b/src/hwstate.c
@@ -26,7 +26,7 @@ void init_hwstate(struct HWState *s, const struct Capabilities *caps)
int i;
memset(s, 0, sizeof(struct HWState));
for (i = 0; i < DIM_FINGER; i++)
- s->data[i].tracking_id = caps->nullid;
+ s->data[i].tracking_id = MT_ID_NULL;
}
static void finish_packet(struct HWState *s, const struct Capabilities *caps,
@@ -35,16 +35,16 @@ static void finish_packet(struct HWState *s, const struct Capabilities *caps,
static const mstime_t ms = 1000;
int i;
foreach_bit(i, s->used) {
- if (!caps->has_abs[BIT_TOUCH_MINOR])
+ if (!caps->has_abs[MTDEV_TOUCH_MINOR])
s->data[i].touch_minor = s->data[i].touch_major;
- if (!caps->has_abs[BIT_WIDTH_MINOR])
+ if (!caps->has_abs[MTDEV_WIDTH_MINOR])
s->data[i].width_minor = s->data[i].width_major;
}
s->evtime = syn->time.tv_usec / ms + syn->time.tv_sec * ms;
}
-int hwstate_read(struct HWState *s, const struct Capabilities *caps,
- const struct input_event *ev)
+static int read_event(struct HWState *s, const struct Capabilities *caps,
+ const struct input_event *ev)
{
switch (ev->type) {
case EV_SYN:
@@ -99,11 +99,21 @@ int hwstate_read(struct HWState *s, const struct Capabilities *caps,
break;
case ABS_MT_TRACKING_ID:
s->data[s->slot].tracking_id = ev->value;
- MODBIT(s->used, s->slot,
- ev->value != caps->nullid);
+ MODBIT(s->used, s->slot, ev->value != MT_ID_NULL);
break;
}
break;
}
return 0;
}
+
+int modify_hwstate(struct HWState *s, struct mtdev *dev, int fd,
+ const struct Capabilities *caps)
+{
+ struct input_event ev;
+ int ret;
+ while ((ret = mtdev_get(dev, fd, &ev, 1)) > 0)
+ if (read_event(s, caps, &ev))
+ return 1;
+ return ret;
+}
diff --git a/src/memory.c b/src/memory.c
index 974a531..63134ca 100644
--- a/src/memory.c
+++ b/src/memory.c
@@ -119,13 +119,13 @@ static void update_pointers(struct Memory *m,
const struct Capabilities *caps)
{
const struct FingerState *f = state->finger;
- int yclick = caps->abs[BIT_POSITION_Y].maximum - CLICK_AREA(caps);
+ int yclick = caps->abs[MTDEV_POSITION_Y].maximum - CLICK_AREA(caps);
int i;
if (state->nfinger < 2) {
m->pointing = m->fingers;
- m->ybar = caps->abs[BIT_POSITION_Y].maximum;
+ m->ybar = caps->abs[MTDEV_POSITION_Y].maximum;
return;
}
diff --git a/src/mtouch.c b/src/mtouch.c
index f7a2710..e2d9572 100644
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -34,8 +34,7 @@ int configure_mtouch(struct MTouch *mt, int fd)
int open_mtouch(struct MTouch *mt, int fd)
{
- mtdev_init(&mt->dev, &mt->caps);
- init_iobuf(&mt->buf);
+ mtdev_open(&mt->dev, fd);
init_hwstate(&mt->hs, &mt->caps);
init_mtstate(&mt->prev_state);
init_mtstate(&mt->state);
@@ -48,40 +47,19 @@ int open_mtouch(struct MTouch *mt, int fd)
return 0;
}
-
-int get_mtouch(struct MTouch *mt, int fd, struct input_event* ev, int ev_max)
-{
- const struct input_event *kev;
- int count = 0;
- while (count < ev_max) {
- while (mtdev_empty(&mt->dev)) {
- kev = get_iobuf_event(&mt->buf, fd);
- if (!kev)
- return count;
- mtdev_put(&mt->dev, &mt->caps, kev);
- }
- mtdev_get(&mt->dev, &ev[count++]);
- }
- return count;
-}
-
int close_mtouch(struct MTouch *mt, int fd)
{
if (use_grab) {
int rc;
SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)0));
}
- mtdev_destroy(&mt->dev);
+ mtdev_close(&mt->dev);
return 0;
}
int read_packet(struct MTouch *mt, int fd)
{
- struct input_event ev;
- int ret;
- while ((ret = get_mtouch(mt, fd, &ev, 1)) > 0)
- if (hwstate_read(&mt->hs, &mt->caps, &ev))
- break;
+ int ret = modify_hwstate(&mt->hs, &mt->dev, fd, &mt->caps);
if (ret <= 0)
return ret;
extract_mtstate(&mt->state, &mt->hs, &mt->caps);
@@ -97,7 +75,5 @@ int read_packet(struct MTouch *mt, int fd)
int has_delayed_gestures(struct MTouch *mt, int fd)
{
- return mt->mem.wait &&
- mtdev_empty(&mt->dev) &&
- poll_iobuf(&mt->buf, fd, mt->mem.wait) == 0;
+ return mt->mem.wait && mtdev_idle(&mt->dev, fd, mt->mem.wait);
}
diff --git a/src/mtstate.c b/src/mtstate.c
index 7a8ef19..4c893a2 100644
--- a/src/mtstate.c
+++ b/src/mtstate.c
@@ -22,7 +22,7 @@
#include "mtstate.h"
#define TOUCH_WIDTH(hw) (0.05 * hw->width_major)
-#define TOUCH_SCALE(caps) (0.05 * caps->abs[BIT_TOUCH_MAJOR].maximum)
+#define TOUCH_SCALE(caps) (0.05 * caps->abs[MTDEV_TOUCH_MAJOR].maximum)
#define THUMB_TOUCH(hw) (1.2 * hw->touch_minor)
#define THUMB_WIDTH_TOUCH(hw) (3 * hw->touch_major)
@@ -37,9 +37,9 @@ void init_mtstate(struct MTState *s)
static int touching_finger(const struct FingerState *hw,
const struct Capabilities *caps)
{
- if (caps->has_abs[BIT_TOUCH_MAJOR] && caps->has_abs[BIT_WIDTH_MAJOR])
+ if (caps->has_abs[MTDEV_TOUCH_MAJOR] && caps->has_abs[MTDEV_WIDTH_MAJOR])
return hw->touch_major > TOUCH_WIDTH(hw);
- if (caps->has_abs[BIT_TOUCH_MAJOR])
+ if (caps->has_abs[MTDEV_TOUCH_MAJOR])
return hw->touch_major > TOUCH_SCALE(caps);
return 1;
}
@@ -55,10 +55,10 @@ static int touching_finger(const struct FingerState *hw,
static int is_thumb(const struct FingerState *hw,
const struct Capabilities *caps)
{
- if (!caps->has_abs[BIT_TOUCH_MAJOR] ||
- !caps->has_abs[BIT_TOUCH_MINOR] ||
- !caps->has_abs[BIT_WIDTH_MAJOR] ||
- !caps->has_abs[BIT_WIDTH_MINOR])
+ if (!caps->has_abs[MTDEV_TOUCH_MAJOR] ||
+ !caps->has_abs[MTDEV_TOUCH_MINOR] ||
+ !caps->has_abs[MTDEV_WIDTH_MAJOR] ||
+ !caps->has_abs[MTDEV_WIDTH_MINOR])
return 0;
return hw->touch_major > THUMB_TOUCH(hw) &&
hw->width_major > THUMB_WIDTH_TOUCH(hw) &&
diff --git a/src/test.c b/src/test.c
index e4247d2..3a23db3 100644
--- a/src/test.c
+++ b/src/test.c
@@ -35,8 +35,8 @@ static void loop_device(int fd)
fprintf(stderr, "error: could not open device\n");
return;
}
- while (poll_iobuf(&mt.buf, fd, 5000)) {
- while (read_packet(&mt, fd) > 0) {
+ while (mtdev_pull(&mt.dev, fd, 1) > 0) {
+ if (parse_event(&mt)) {
extract_gestures(&gs, &mt);
output_gesture(&gs);
}