diff options
| -rw-r--r-- | Makefile | 1 | ||||
| -rw-r--r-- | src/gestures.c | 23 | ||||
| -rw-r--r-- | src/hwstate.c | 69 | ||||
| -rw-r--r-- | src/hwstate.h | 4 | ||||
| -rw-r--r-- | src/mtouch.c | 8 | ||||
| -rw-r--r-- | src/mtouch.h | 4 | ||||
| -rw-r--r-- | src/mtstate.c | 93 | ||||
| -rw-r--r-- | src/mtstate.h | 43 |
8 files changed, 159 insertions, 86 deletions
| @@ -12,6 +12,7 @@ o_src = capabilities \ | |||
| 12 | iobuffer \ | 12 | iobuffer \ |
| 13 | hwdata \ | 13 | hwdata \ |
| 14 | hwstate \ | 14 | hwstate \ |
| 15 | mtstate \ | ||
| 15 | mtouch \ | 16 | mtouch \ |
| 16 | gestures \ | 17 | gestures \ |
| 17 | multitouch | 18 | 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 @@ | |||
| 25 | 25 | ||
| 26 | void extract_gestures(struct Gestures *gs, struct MTouch* mt) | 26 | void extract_gestures(struct Gestures *gs, struct MTouch* mt) |
| 27 | { | 27 | { |
| 28 | const struct FingerState *b = mt->nhs.finger; | 28 | const struct FingerState *b = mt->state.finger; |
| 29 | const struct FingerState *e = b + mt->nhs.nfinger; | 29 | const struct FingerState *e = b + mt->state.nfinger; |
| 30 | const struct FingerState *p, *fs; | 30 | const struct FingerState *p, *fs; |
| 31 | int nof = count_fingers(&mt->ohs); | 31 | int nof = mt->prev_state.nfinger; |
| 32 | int nsf = count_fingers(&mt->nhs); | 32 | int nsf = mt->state.nfinger; |
| 33 | int dn = 0, i; | 33 | int dn = 0, i; |
| 34 | memset(gs, 0, sizeof(struct Gestures)); | 34 | memset(gs, 0, sizeof(struct Gestures)); |
| 35 | if (nof == nsf) { | 35 | if (nof == nsf) { |
| 36 | for (p = b; p != e; p++) { | 36 | for (p = b; p != e; p++) { |
| 37 | fs = find_finger(&mt->ohs, p->id); | 37 | fs = find_finger(&mt->prev_state, p->id); |
| 38 | if (fs) { | 38 | if (fs) { |
| 39 | gs->dx += p->hw.position_x - fs->hw.position_x; | 39 | gs->dx += p->hw.position_x - fs->hw.position_x; |
| 40 | gs->dy += p->hw.position_y - fs->hw.position_y; | 40 | gs->dy += p->hw.position_y - fs->hw.position_y; |
| @@ -52,14 +52,15 @@ void extract_gestures(struct Gestures *gs, struct MTouch* mt) | |||
| 52 | if (nsf == 3) | 52 | if (nsf == 3) |
| 53 | SETBIT(gs->type, GS_HSCROLL); | 53 | SETBIT(gs->type, GS_HSCROLL); |
| 54 | } | 54 | } |
| 55 | if (mt->nhs.button == BITMASK(MT_BUTTON_LEFT)) { | 55 | if (mt->state.button == BITMASK(MT_BUTTON_LEFT)) { |
| 56 | if (nsf == 2) | 56 | if (nsf == 2) |
| 57 | mt->nhs.button = BITMASK(MT_BUTTON_RIGHT); | 57 | mt->state.button = BITMASK(MT_BUTTON_RIGHT); |
| 58 | if (nsf == 3) | 58 | if (nsf == 3) |
| 59 | mt->nhs.button = BITMASK(MT_BUTTON_MIDDLE); | 59 | mt->state.button = BITMASK(MT_BUTTON_MIDDLE); |
| 60 | } | 60 | } |
| 61 | gs->btmask = (mt->nhs.button ^ mt->ohs.button) & BITONES(DIM_BUTTON); | 61 | gs->btmask = (mt->state.button ^ mt->prev_state.button) & |
| 62 | gs->btdata = mt->nhs.button & BITONES(DIM_BUTTON); | 62 | BITONES(DIM_BUTTON); |
| 63 | mt->ohs = mt->nhs; | 63 | gs->btdata = mt->state.button & BITONES(DIM_BUTTON); |
| 64 | mt->prev_state = mt->state; | ||
| 64 | } | 65 | } |
| 65 | 66 | ||
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 @@ | |||
| 23 | #include <stdlib.h> | 23 | #include <stdlib.h> |
| 24 | #include <limits.h> | 24 | #include <limits.h> |
| 25 | 25 | ||
| 26 | const double FTW = 0.05; | ||
| 27 | const double FTS = 0.05; | ||
| 28 | const int XMAX = 32767; | 26 | const int XMAX = 32767; |
| 29 | 27 | ||
| 30 | void init_hwstate(struct HWState *s) | 28 | void init_hwstate(struct HWState *s) |
| @@ -63,17 +61,6 @@ static void set_finger(struct FingerState *fs, | |||
| 63 | fs->hw.width_minor = hw->width_major; | 61 | fs->hw.width_minor = hw->width_major; |
| 64 | } | 62 | } |
| 65 | 63 | ||
| 66 | static int touching_finger(const struct FingerData *hw, | ||
| 67 | const struct Capabilities *caps) | ||
| 68 | { | ||
| 69 | if (caps->has_touch_major && caps->has_width_major) | ||
| 70 | return hw->width_major > 0 && | ||
| 71 | hw->touch_major > FTW * hw->width_major; | ||
| 72 | if (caps->has_touch_major) | ||
| 73 | return hw->touch_major > FTS * caps->abs_touch_major.maximum; | ||
| 74 | return 1; | ||
| 75 | } | ||
| 76 | |||
| 77 | void modify_hwstate(struct HWState *s, | 64 | void modify_hwstate(struct HWState *s, |
| 78 | const struct HWData *hw, | 65 | const struct HWData *hw, |
| 79 | const struct Capabilities *caps) | 66 | const struct Capabilities *caps) |
| @@ -96,11 +83,8 @@ void modify_hwstate(struct HWState *s, | |||
| 96 | for (hwk = 0; hwk < hw->nfinger; hwk++) { | 83 | for (hwk = 0; hwk < hw->nfinger; hwk++) { |
| 97 | sk = hw2s[hwk]; | 84 | sk = hw2s[hwk]; |
| 98 | id = sk >= 0 ? sid[sk] : 0; | 85 | id = sk >= 0 ? sid[sk] : 0; |
| 99 | if (!touching_finger(&hw->finger[hwk], caps)) | 86 | while (!id) |
| 100 | id = 0; | 87 | id = ++s->lastid; |
| 101 | else | ||
| 102 | while (!id) | ||
| 103 | id = ++s->lastid; | ||
| 104 | set_finger(&s->finger[hwk], &hw->finger[hwk], id, caps); | 88 | set_finger(&s->finger[hwk], &hw->finger[hwk], id, caps); |
| 105 | } | 89 | } |
| 106 | 90 | ||
| @@ -111,52 +95,3 @@ void modify_hwstate(struct HWState *s, | |||
| 111 | /* sort fingers in touching order */ | 95 | /* sort fingers in touching order */ |
| 112 | qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); | 96 | qsort(s->finger, s->nfinger, sizeof(struct FingerState), fincmp); |
| 113 | } | 97 | } |
| 114 | |||
| 115 | const struct FingerState *find_finger(const struct HWState *s, int id) | ||
| 116 | { | ||
| 117 | int i; | ||
| 118 | |||
| 119 | if (!id) | ||
| 120 | return NULL; | ||
| 121 | for (i = 0; i < s->nfinger; i++) | ||
| 122 | if (s->finger[i].id == id) | ||
| 123 | return s->finger + i; | ||
| 124 | |||
| 125 | return NULL; | ||
| 126 | } | ||
| 127 | |||
| 128 | int count_fingers(const struct HWState *s) | ||
| 129 | { | ||
| 130 | int i, n = 0; | ||
| 131 | for (i = 0; i < s->nfinger; i++) | ||
| 132 | if (s->finger[i].id) | ||
| 133 | n++; | ||
| 134 | return n; | ||
| 135 | } | ||
| 136 | |||
| 137 | void output_hwstate(const struct HWState *s) | ||
| 138 | { | ||
| 139 | int i; | ||
| 140 | xf86Msg(X_INFO, "buttons: %d%d%d\n", | ||
| 141 | GETBIT(s->button, MT_BUTTON_LEFT), | ||
| 142 | GETBIT(s->button, MT_BUTTON_MIDDLE), | ||
| 143 | GETBIT(s->button, MT_BUTTON_RIGHT)); | ||
| 144 | xf86Msg(X_INFO, "fingers: %d\n", | ||
| 145 | s->nfinger); | ||
| 146 | xf86Msg(X_INFO, "evtime: %lld\n", | ||
| 147 | s->evtime); | ||
| 148 | for (i = 0; i < s->nfinger; i++) { | ||
| 149 | xf86Msg(X_INFO, | ||
| 150 | " %+02d %+05d:%+05d +%05d:%+05d " | ||
| 151 | "%+06d %+06d %+05d:%+05d\n", | ||
| 152 | s->finger[i].id, | ||
| 153 | s->finger[i].hw.touch_major, | ||
| 154 | s->finger[i].hw.touch_minor, | ||
| 155 | s->finger[i].hw.width_major, | ||
| 156 | s->finger[i].hw.width_minor, | ||
| 157 | s->finger[i].hw.orientation, | ||
| 158 | s->finger[i].hw.pressure, | ||
| 159 | s->finger[i].hw.position_x, | ||
| 160 | s->finger[i].hw.position_y); | ||
| 161 | } | ||
| 162 | } | ||
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); | |||
| 43 | void modify_hwstate(struct HWState *s, | 43 | void modify_hwstate(struct HWState *s, |
| 44 | const struct HWData *hw, | 44 | const struct HWData *hw, |
| 45 | const struct Capabilities *caps); | 45 | const struct Capabilities *caps); |
| 46 | void output_hwstate(const struct HWState *s); | ||
| 47 | |||
| 48 | const struct FingerState *find_finger(const struct HWState *s, int id); | ||
| 49 | int count_fingers(const struct HWState *s); | ||
| 50 | 46 | ||
| 51 | #endif | 47 | #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) | |||
| 35 | int rc; | 35 | int rc; |
| 36 | init_iobuf(&mt->buf); | 36 | init_iobuf(&mt->buf); |
| 37 | init_hwdata(&mt->hw); | 37 | init_hwdata(&mt->hw); |
| 38 | init_hwstate(&mt->ohs); | 38 | init_hwstate(&mt->hs); |
| 39 | init_hwstate(&mt->nhs); | 39 | init_mtstate(&mt->prev_state); |
| 40 | init_mtstate(&mt->state); | ||
| 40 | SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1)); | 41 | SYSCALL(rc = ioctl(fd, EVIOCGRAB, (pointer)1)); |
| 41 | return rc; | 42 | return rc; |
| 42 | } | 43 | } |
| @@ -59,5 +60,6 @@ int read_synchronized_event(struct MTouch *mt, int fd) | |||
| 59 | 60 | ||
| 60 | void parse_event(struct MTouch *mt) | 61 | void parse_event(struct MTouch *mt) |
| 61 | { | 62 | { |
| 62 | modify_hwstate(&mt->nhs, &mt->hw, &mt->caps); | 63 | modify_hwstate(&mt->hs, &mt->hw, &mt->caps); |
| 64 | extract_mtstate(&mt->state, &mt->hs, &mt->caps); | ||
| 63 | } | 65 | } |
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 @@ | |||
| 26 | #include "iobuffer.h" | 26 | #include "iobuffer.h" |
| 27 | #include "hwdata.h" | 27 | #include "hwdata.h" |
| 28 | #include "hwstate.h" | 28 | #include "hwstate.h" |
| 29 | #include "mtstate.h" | ||
| 29 | 30 | ||
| 30 | struct MTouch { | 31 | struct MTouch { |
| 31 | struct Capabilities caps; | 32 | struct Capabilities caps; |
| 32 | struct IOBuffer buf; | 33 | struct IOBuffer buf; |
| 33 | struct HWData hw; | 34 | struct HWData hw; |
| 34 | struct HWState ohs, nhs; | 35 | struct HWState hs; |
| 36 | struct MTState prev_state, state; | ||
| 35 | }; | 37 | }; |
| 36 | 38 | ||
| 37 | int configure_mtouch(struct MTouch *mt, int fd); | 39 | 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 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * Multitouch X driver | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | * | ||
| 20 | **************************************************************************/ | ||
| 21 | |||
| 22 | #include "mtstate.h" | ||
| 23 | |||
| 24 | #define TOUCH_WIDTH(hw) (0.05 * hw->width_major) | ||
| 25 | #define TOUCH_SCALE(caps) (0.05 * caps->abs_touch_major.maximum) | ||
| 26 | |||
| 27 | void init_mtstate(struct MTState *s) | ||
| 28 | { | ||
| 29 | memset(s, 0, sizeof(struct MTState)); | ||
| 30 | } | ||
| 31 | |||
| 32 | static int touching_finger(const struct FingerData *hw, | ||
| 33 | const struct Capabilities *caps) | ||
| 34 | { | ||
| 35 | if (caps->has_touch_major && caps->has_width_major) | ||
| 36 | return hw->touch_major > TOUCH_WIDTH(hw); | ||
| 37 | if (caps->has_touch_major) | ||
| 38 | return hw->touch_major > TOUCH_SCALE(caps); | ||
| 39 | return 1; | ||
| 40 | } | ||
| 41 | |||
| 42 | void extract_mtstate(struct MTState *s, | ||
| 43 | const struct HWState *hs, | ||
| 44 | const struct Capabilities *caps) | ||
| 45 | { | ||
| 46 | int i; | ||
| 47 | |||
| 48 | s->nfinger = 0; | ||
| 49 | for (i = 0; i < hs->nfinger; i++) | ||
| 50 | if (touching_finger(&hs->finger[i].hw, caps)) | ||
| 51 | s->finger[s->nfinger++] = hs->finger[i]; | ||
| 52 | |||
| 53 | s->button = hs->button; | ||
| 54 | s->evtime = hs->evtime; | ||
| 55 | } | ||
| 56 | |||
| 57 | const struct FingerState *find_finger(const struct MTState *s, int id) | ||
| 58 | { | ||
| 59 | int i; | ||
| 60 | |||
| 61 | for (i = 0; i < s->nfinger; i++) | ||
| 62 | if (s->finger[i].id == id) | ||
| 63 | return s->finger + i; | ||
| 64 | |||
| 65 | return NULL; | ||
| 66 | } | ||
| 67 | |||
| 68 | void output_mtstate(const struct MTState *s) | ||
| 69 | { | ||
| 70 | int i; | ||
| 71 | xf86Msg(X_INFO, "buttons: %d%d%d\n", | ||
| 72 | GETBIT(s->button, MT_BUTTON_LEFT), | ||
| 73 | GETBIT(s->button, MT_BUTTON_MIDDLE), | ||
| 74 | GETBIT(s->button, MT_BUTTON_RIGHT)); | ||
| 75 | xf86Msg(X_INFO, "fingers: %d\n", | ||
| 76 | s->nfinger); | ||
| 77 | xf86Msg(X_INFO, "evtime: %lld\n", | ||
| 78 | s->evtime); | ||
| 79 | for (i = 0; i < s->nfinger; i++) { | ||
| 80 | xf86Msg(X_INFO, | ||
| 81 | " %+02d %+05d:%+05d +%05d:%+05d " | ||
| 82 | "%+06d %+06d %+05d:%+05d\n", | ||
| 83 | s->finger[i].id, | ||
| 84 | s->finger[i].hw.touch_major, | ||
| 85 | s->finger[i].hw.touch_minor, | ||
| 86 | s->finger[i].hw.width_major, | ||
| 87 | s->finger[i].hw.width_minor, | ||
| 88 | s->finger[i].hw.orientation, | ||
| 89 | s->finger[i].hw.pressure, | ||
| 90 | s->finger[i].hw.position_x, | ||
| 91 | s->finger[i].hw.position_y); | ||
| 92 | } | ||
| 93 | } | ||
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 @@ | |||
| 1 | /*************************************************************************** | ||
| 2 | * | ||
| 3 | * Multitouch X driver | ||
| 4 | * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se> | ||
| 5 | * | ||
| 6 | * This program is free software; you can redistribute it and/or modify | ||
| 7 | * it under the terms of the GNU General Public License as published by | ||
| 8 | * the Free Software Foundation; either version 2 of the License, or | ||
| 9 | * (at your option) any later version. | ||
| 10 | * | ||
| 11 | * This program is distributed in the hope that it will be useful, | ||
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 14 | * GNU General Public License for more details. | ||
| 15 | * | ||
| 16 | * You should have received a copy of the GNU General Public License | ||
| 17 | * along with this program; if not, write to the Free Software | ||
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 19 | * | ||
| 20 | **************************************************************************/ | ||
| 21 | |||
| 22 | #ifndef MTSTATE_H | ||
| 23 | #define MTSTATE_H | ||
| 24 | |||
| 25 | #include "hwstate.h" | ||
| 26 | |||
| 27 | struct MTState { | ||
| 28 | struct FingerState finger[DIM_FINGER]; | ||
| 29 | int nfinger; | ||
| 30 | unsigned button; | ||
| 31 | mstime_t evtime; | ||
| 32 | }; | ||
| 33 | |||
| 34 | void init_mtstate(struct MTState *s); | ||
| 35 | void extract_mtstate(struct MTState *s, | ||
| 36 | const struct HWState *hs, | ||
| 37 | const struct Capabilities *caps); | ||
| 38 | void output_mtstate(const struct MTState *s); | ||
| 39 | |||
| 40 | const struct FingerState *find_finger(const struct MTState *s, int id); | ||
| 41 | |||
| 42 | #endif | ||
| 43 | |||
