diff options
Diffstat (limited to 'include/common.h')
| -rw-r--r-- | include/common.h | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/include/common.h b/include/common.h new file mode 100644 index 0000000..09582ce --- /dev/null +++ b/include/common.h | |||
| @@ -0,0 +1,128 @@ | |||
| 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 COMMON_H | ||
| 23 | #define COMMON_H | ||
| 24 | |||
| 25 | #include "xorg-server.h" | ||
| 26 | #include <xf86.h> | ||
| 27 | #include <xf86_OSproc.h> | ||
| 28 | #include <xf86Xinput.h> | ||
| 29 | #include <linux/input.h> | ||
| 30 | #include <errno.h> | ||
| 31 | |||
| 32 | /* includes available in 2.6.30-rc5 */ | ||
| 33 | |||
| 34 | #ifndef BTN_TOOL_QUADTAP | ||
| 35 | #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ | ||
| 36 | #define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */ | ||
| 37 | #define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */ | ||
| 38 | #define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */ | ||
| 39 | #define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */ | ||
| 40 | #define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */ | ||
| 41 | #define ABS_MT_POSITION_X 0x35 /* Center X ellipse position */ | ||
| 42 | #define ABS_MT_POSITION_Y 0x36 /* Center Y ellipse position */ | ||
| 43 | #define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */ | ||
| 44 | #define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */ | ||
| 45 | #define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */ | ||
| 46 | #define SYN_MT_REPORT 2 | ||
| 47 | #define MT_TOOL_FINGER 0 | ||
| 48 | #define MT_TOOL_PEN 1 | ||
| 49 | #endif | ||
| 50 | |||
| 51 | /* includes available in 2.6.33 */ | ||
| 52 | #ifndef ABS_MT_PRESSURE | ||
| 53 | #define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */ | ||
| 54 | #endif | ||
| 55 | |||
| 56 | /* includes available in 2.6.36 */ | ||
| 57 | #ifndef ABS_MT_SLOT | ||
| 58 | #define ABS_MT_SLOT 0x2f /* MT slot being modified */ | ||
| 59 | #define MT_ABS_SIZE 11 /* Size of MT_SLOT_ABS_EVENTS */ | ||
| 60 | #define MT_SLOT_ABS_EVENTS { \ | ||
| 61 | ABS_MT_TOUCH_MAJOR, \ | ||
| 62 | ABS_MT_TOUCH_MINOR, \ | ||
| 63 | ABS_MT_WIDTH_MAJOR, \ | ||
| 64 | ABS_MT_WIDTH_MINOR, \ | ||
| 65 | ABS_MT_ORIENTATION, \ | ||
| 66 | ABS_MT_POSITION_X, \ | ||
| 67 | ABS_MT_POSITION_Y, \ | ||
| 68 | ABS_MT_TOOL_TYPE, \ | ||
| 69 | ABS_MT_BLOB_ID, \ | ||
| 70 | ABS_MT_TRACKING_ID, \ | ||
| 71 | ABS_MT_PRESSURE, \ | ||
| 72 | } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #define DIM_FINGER 32 | ||
| 76 | #define DIM2_FINGER (DIM_FINGER * DIM_FINGER) | ||
| 77 | |||
| 78 | /* event buffer size (must be a power of two) */ | ||
| 79 | #define DIM_EVENTS 64 | ||
| 80 | |||
| 81 | /* year-proof millisecond event time */ | ||
| 82 | typedef __u64 mstime_t; | ||
| 83 | |||
| 84 | /* all bit masks have this type */ | ||
| 85 | typedef unsigned int bitmask_t; | ||
| 86 | |||
| 87 | #define BITMASK(x) (1U << (x)) | ||
| 88 | #define BITONES(x) (BITMASK(x) - 1U) | ||
| 89 | #define GETBIT(m, x) (((m) >> (x)) & 1U) | ||
| 90 | #define SETBIT(m, x) (m |= BITMASK(x)) | ||
| 91 | #define CLEARBIT(m, x) (m &= ~BITMASK(x)) | ||
| 92 | #define MODBIT(m, x, b) ((b) ? SETBIT(m, x) : CLEARBIT(m, x)) | ||
| 93 | |||
| 94 | static inline int maxval(int x, int y) { return x > y ? x : y; } | ||
| 95 | static inline int minval(int x, int y) { return x < y ? x : y; } | ||
| 96 | |||
| 97 | static inline int clamp15(int x) | ||
| 98 | { | ||
| 99 | return x < -32767 ? -32767 : x > 32767 ? 32767 : x; | ||
| 100 | } | ||
| 101 | |||
| 102 | /* absolute scale is assumed to fit in 15 bits */ | ||
| 103 | static inline int dist2(int dx, int dy) | ||
| 104 | { | ||
| 105 | dx = clamp15(dx); | ||
| 106 | dy = clamp15(dy); | ||
| 107 | return dx * dx + dy * dy; | ||
| 108 | } | ||
| 109 | |||
| 110 | /* Count number of bits (Sean Eron Andersson's Bit Hacks) */ | ||
| 111 | static inline int bitcount(unsigned v) | ||
| 112 | { | ||
| 113 | v -= ((v>>1) & 0x55555555); | ||
| 114 | v = (v&0x33333333) + ((v>>2) & 0x33333333); | ||
| 115 | return (((v + (v>>4)) & 0xF0F0F0F) * 0x1010101) >> 24; | ||
| 116 | } | ||
| 117 | |||
| 118 | /* Return index of first bit [0-31], -1 on zero */ | ||
| 119 | #define firstbit(v) (__builtin_ffs(v) - 1) | ||
| 120 | |||
| 121 | /* boost-style foreach bit */ | ||
| 122 | #define foreach_bit(i, m) \ | ||
| 123 | for (i = firstbit(m); i >= 0; i = firstbit((m) & (~0U << i + 1))) | ||
| 124 | |||
| 125 | /* robust system ioctl calls */ | ||
| 126 | #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) | ||
| 127 | |||
| 128 | #endif | ||
