aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rydberg <rydberg@euromail.se>2010-04-10 22:57:26 +0200
committerHenrik Rydberg <rydberg@euromail.se>2010-04-15 06:10:07 +0200
commit963d6f71bb64125603d59c8bb70eaeec38c6fd72 (patch)
tree87dc34640a4e47cee618ebbc8d665e100e21239f
parent9c24576540ba57449c31bafcb8f4aab41b8623b7 (diff)
downloadxorg-input-kobomultitouch-963d6f71bb64125603d59c8bb70eaeec38c6fd72.tar.gz
xorg-input-kobomultitouch-963d6f71bb64125603d59c8bb70eaeec38c6fd72.tar.bz2
xorg-input-kobomultitouch-963d6f71bb64125603d59c8bb70eaeec38c6fd72.zip
Introduce the MTState
The HWState keeps, for good reason, both touching fingers and fingers going away. However, this implies that additional logic is needed to keep track of the number of actual touching fingers. In particular the test for touching fingers is somewhat misplaced in hwstate.c. Moreover, HWState should only exist in one instance, since it contains data which does not need to be referred to during gesture extraction. This patch introduces the MTState structure, which keeps more digested data for gesture extraction. In particular, it only keeps the actual touches. Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
-rw-r--r--Makefile1
-rw-r--r--src/gestures.c23
-rw-r--r--src/hwstate.c69
-rw-r--r--src/hwstate.h4
-rw-r--r--src/mtouch.c8
-rw-r--r--src/mtouch.h4
-rw-r--r--src/mtstate.c93
-rw-r--r--src/mtstate.h43
8 files changed, 159 insertions, 86 deletions
diff --git a/Makefile b/Makefile
index 2e202b1..a00d246 100644
--- a/Makefile
+++ b/Makefile
@@ -12,6 +12,7 @@ o_src = capabilities \
iobuffer \
hwdata \
hwstate \
+ mtstate \
mtouch \
gestures \
multitouch
diff --git a/src/gestures.c b/src/gestures.c
index 5dd6861..ebf103f 100644
--- a/src/gestures.c
+++ b/src/gestures.c
@@ -25,16 +25,16 @@
void extract_gestures(struct Gestures *gs, struct MTouch* mt)
{
- const struct FingerState *b = mt->nhs.finger;
- const struct FingerState *e = b + mt->nhs.nfinger;
+ const struct FingerState *b = mt->state.finger;
+ const struct FingerState *e = b + mt->state.nfinger;
const struct FingerState *p, *fs;
- int nof = count_fingers(&mt->ohs);
- int nsf = count_fingers(&mt->nhs);
+ int nof = mt->prev_state.nfinger;
+ int nsf = mt->state.nfinger;
int dn = 0, i;
memset(gs, 0, sizeof(struct Gestures));
if (nof == nsf) {
for (p = b; p != e; p++) {
- fs = find_finger(&mt->ohs, p->id);
+ fs = find_finger(&mt->prev_state, p->id);
if (fs) {
gs->dx += p->hw.position_x - fs->hw.position_x;
gs->dy += p->hw.position_y - fs->hw.position_y;
@@ -52,14 +52,15 @@ void extract_gestures(struct Gestures *gs, struct MTouch* mt)
if (nsf == 3)
SETBIT(gs->type, GS_HSCROLL);
}
- if (mt->nhs.button == BITMASK(MT_BUTTON_LEFT)) {
+ if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) {
if (nsf == 2)
- mt->nhs.button = BITMASK(MT_BUTTON_RIGHT);
+ mt->state.button = BITMASK(MT_BUTTON_RIGHT);
if (nsf == 3)
- mt->nhs.button = BITMASK(MT_BUTTON_MIDDLE);
+ mt->state.button = BITMASK(MT_BUTTON_MIDDLE);
}
- gs->btmask = (mt->nhs.button ^ mt->ohs.button) & BITONES(DIM_BUTTON);
- gs->btdata = mt->nhs.button & BITONES(DIM_BUTTON);
- mt->ohs = mt->nhs;
+ gs->btmask = (mt->state.button ^ mt->prev_state.button) &
+ BITONES(DIM_BUTTON);
+ gs->btdata = mt->state.button & BITONES(DIM_BUTTON);
+ mt->prev_state = mt->state;
}
diff --git a/src/hwstate.c b/src/hwstate.c
index 7e40b50..50e34de 100644
--- a/src/hwstate.c
+++ b/src/hwstate.c
@@ -23,8 +23,6 @@
#include <stdlib.h>
#include <limits.h>
-const double FTW = 0.05;
-const double FTS = 0.05;
const int XMAX = 32767;
void init_hwstate(struct HWState *s)
@@ -63,17 +61,6 @@ static void set_finger(struct FingerState *fs,
fs->hw.width_minor = hw->width_major;
}
-static int touching_finger(const struct FingerData *hw,
- const struct Capabilities *caps)
-{
- if (caps->has_touch_major && caps->has_width_major)
- return hw->width_major > 0 &&
- hw->touch_major > FTW * hw->width_major;
- if (caps->has_touch_major)
- return hw->touch_major > FTS * caps->abs_touch_major.maximum;
- return 1;
-}
-
void modify_hwstate(struct HWState *s,
const struct HWData *hw,
const struct Capabilities *caps)
@@ -96,11 +83,8 @@ void modify_hwstate(struct HWState *s,
for (hwk = 0; hwk < hw->nfinger; hwk++) {
sk = hw2s[hwk];
id = sk >= 0 ? sid[sk] : 0;
- if (!touching_finger(&hw->finger[hwk], caps))
- id = 0;
- else
- while (!id)
- id = ++s->lastid;
+ while (!id)
+ id = ++s->lastid;
set_finger(&s->finger[hwk], &hw->finger[hwk], id, caps);
}
@@ -111,52 +95,3 @@ void modify_hwstate(struct HWState *s,
/* sort fingers in touching order */
qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp);
}
-
-const struct FingerState *find_finger(const struct HWState *s, int id)
-{
- int i;
-
- if (!id)
- return NULL;
- for (i = 0; i < s->nfinger; i++)
- if (s->finger[i].id == id)
- return s->finger + i;
-
- return NULL;
-}
-
-int count_fingers(const struct HWState *s)
-{
- int i, n = 0;
- for (i = 0; i < s->nfinger; i++)
- if (s->finger[i].id)
- n++;
- return n;
-}
-
-void output_hwstate(const struct HWState *s)
-{
- int i;
- xf86Msg(X_INFO, "buttons: %d%d%d\n",
- GETBIT(s->button, MT_BUTTON_LEFT),
- GETBIT(s->button, MT_BUTTON_MIDDLE),
- GETBIT(s->button, MT_BUTTON_RIGHT));
- xf86Msg(X_INFO, "fingers: %d\n",
- s->nfinger);
- xf86Msg(X_INFO, "evtime: %lld\n",
- s->evtime);
- for (i = 0; i < s->nfinger; i++) {
- xf86Msg(X_INFO,
- " %+02d %+05d:%+05d +%05d:%+05d "
- "%+06d %+06d %+05d:%+05d\n",
- s->finger[i].id,
- s->finger[i].hw.touch_major,
- s->finger[i].hw.touch_minor,
- s->finger[i].hw.width_major,
- s->finger[i].hw.width_minor,
- s->finger[i].hw.orientation,
- s->finger[i].hw.pressure,
- s->finger[i].hw.position_x,
- s->finger[i].hw.position_y);
- }
-}
diff --git a/src/hwstate.h b/src/hwstate.h
index fd53e71..b8c2ba0 100644
--- a/src/hwstate.h
+++ b/src/hwstate.h
@@ -43,9 +43,5 @@ void init_hwstate(struct HWState *s);
void modify_hwstate(struct HWState *s,
const struct HWData *hw,
const struct Capabilities *caps);
-void output_hwstate(const struct HWState *s);
-
-const struct FingerState *find_finger(const struct HWState *s, int id);
-int count_fingers(const struct HWState *s);
#endif
diff --git a/src/mtouch.c b/src/mtouch.c
index 5bf72ec..e47d69d 100644
--- a/src/mtouch.c
+++ b/src/mtouch.c
@@ -35,8 +35,9 @@ int open_mtouch(struct MTouch *mt, int fd)
int rc;
init_iobuf(&mt->buf);
init_hwdata(&mt->hw);
- init_hwstate(&mt->ohs);
- init_hwstate(&mt->nhs);
+ init_hwstate(&mt->hs);
+ init_mtstate(&mt->prev_state);
+ init_mtstate(&mt->state);
SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1));
return rc;
}
@@ -59,5 +60,6 @@ int read_synchronized_event(struct MTouch *mt, int fd)
void parse_event(struct MTouch *mt)
{
- modify_hwstate(&mt->nhs, &mt->hw, &mt->caps);
+ modify_hwstate(&mt->hs, &mt->hw, &mt->caps);
+ extract_mtstate(&mt->state, &mt->hs, &mt->caps);
}
diff --git a/src/mtouch.h b/src/mtouch.h
index e4a59fb..28a637b 100644
--- a/src/mtouch.h
+++ b/src/mtouch.h
@@ -26,12 +26,14 @@
#include "iobuffer.h"
#include "hwdata.h"
#include "hwstate.h"
+#include "mtstate.h"
struct MTouch {
struct Capabilities caps;
struct IOBuffer buf;
struct HWData hw;
- struct HWState ohs, nhs;
+ struct HWState hs;
+ struct MTState prev_state, state;
};
int configure_mtouch(struct MTouch *mt, int fd);
diff --git a/src/mtstate.c b/src/mtstate.c
new file mode 100644
index 0000000..a8541dc
--- /dev/null
+++ b/src/mtstate.c
@@ -0,0 +1,93 @@
+/***************************************************************************
+ *
+ * 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 "mtstate.h"
+
+#define TOUCH_WIDTH(hw) (0.05 * hw->width_major)
+#define TOUCH_SCALE(caps) (0.05 * caps->abs_touch_major.maximum)
+
+void init_mtstate(struct MTState *s)
+{
+ memset(s, 0, sizeof(struct MTState));
+}
+
+static int touching_finger(const struct FingerData *hw,
+ const struct Capabilities *caps)
+{
+ if (caps->has_touch_major && caps->has_width_major)
+ return hw->touch_major > TOUCH_WIDTH(hw);
+ if (caps->has_touch_major)
+ return hw->touch_major > TOUCH_SCALE(caps);
+ return 1;
+}
+
+void extract_mtstate(struct MTState *s,
+ const struct HWState *hs,
+ const struct Capabilities *caps)
+{
+ int i;
+
+ s->nfinger = 0;
+ for (i = 0; i < hs->nfinger; i++)
+ if (touching_finger(&hs->finger[i].hw, caps))
+ s->finger[s->nfinger++] = hs->finger[i];
+
+ s->button = hs->button;
+ s->evtime = hs->evtime;
+}
+
+const struct FingerState *find_finger(const struct MTState *s, int id)
+{
+ int i;
+
+ for (i = 0; i < s->nfinger; i++)
+ if (s->finger[i].id == id)
+ return s->finger + i;
+
+ return NULL;
+}
+
+void output_mtstate(const struct MTState *s)
+{
+ int i;
+ xf86Msg(X_INFO, "buttons: %d%d%d\n",
+ GETBIT(s->button, MT_BUTTON_LEFT),
+ GETBIT(s->button, MT_BUTTON_MIDDLE),
+ GETBIT(s->button, MT_BUTTON_RIGHT));
+ xf86Msg(X_INFO, "fingers: %d\n",
+ s->nfinger);
+ xf86Msg(X_INFO, "evtime: %lld\n",
+ s->evtime);
+ for (i = 0; i < s->nfinger; i++) {
+ xf86Msg(X_INFO,
+ " %+02d %+05d:%+05d +%05d:%+05d "
+ "%+06d %+06d %+05d:%+05d\n",
+ s->finger[i].id,
+ s->finger[i].hw.touch_major,
+ s->finger[i].hw.touch_minor,
+ s->finger[i].hw.width_major,
+ s->finger[i].hw.width_minor,
+ s->finger[i].hw.orientation,
+ s->finger[i].hw.pressure,
+ s->finger[i].hw.position_x,
+ s->finger[i].hw.position_y);
+ }
+}
diff --git a/src/mtstate.h b/src/mtstate.h
new file mode 100644
index 0000000..f8790dd
--- /dev/null
+++ b/src/mtstate.h
@@ -0,0 +1,43 @@
+/***************************************************************************
+ *
+ * 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 MTSTATE_H
+#define MTSTATE_H
+
+#include "hwstate.h"
+
+struct MTState {
+ struct FingerState finger[DIM_FINGER];
+ int nfinger;
+ unsigned button;
+ mstime_t evtime;
+};
+
+void init_mtstate(struct MTState *s);
+void extract_mtstate(struct MTState *s,
+ const struct HWState *hs,
+ const struct Capabilities *caps);
+void output_mtstate(const struct MTState *s);
+
+const struct FingerState *find_finger(const struct MTState *s, int id);
+
+#endif
+