diff options
Diffstat (limited to 'src/mtstate.c')
| -rw-r--r-- | src/mtstate.c | 93 |
1 files changed, 93 insertions, 0 deletions
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 | } | ||
