diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-04 23:31:36 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-04 23:31:36 +0100 |
| commit | c3a677d567428f4d6d9f7fceb8034f2047e48d9d (patch) | |
| tree | 747f38112177eb309d7c4b60e0d4736b66b38eb4 | |
| parent | 3017e434f142be9aa8f7816a3410b40694c972b3 (diff) | |
almost working module code
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
| -rw-r--r-- | Makefile | 6 | ||||
| -rw-r--r-- | src/multitouch.c | 71 |
2 files changed, 50 insertions, 27 deletions
| @@ -4,7 +4,7 @@ MODULES = src | |||
| 4 | 4 | ||
| 5 | o_src = multitouch | 5 | o_src = multitouch |
| 6 | 6 | ||
| 7 | TARGETS = #$(addsuffix /test,$(MODULES)) | 7 | TARGETS = $(addsuffix /test,$(MODULES)) |
| 8 | 8 | ||
| 9 | OBJECTS = $(addsuffix .o,\ | 9 | OBJECTS = $(addsuffix .o,\ |
| 10 | $(foreach mod,$(MODULES),\ | 10 | $(foreach mod,$(MODULES),\ |
| @@ -26,7 +26,9 @@ OPTS = -O3 | |||
| 26 | .PHONY: all clean | 26 | .PHONY: all clean |
| 27 | .PRECIOUS: obj/%.o | 27 | .PRECIOUS: obj/%.o |
| 28 | 28 | ||
| 29 | all: $(OBJS) $(TLIB) $(TOBJ) $(TBIN) | 29 | all: $(OBJS) $(TLIB) $(TOBJ) |
| 30 | |||
| 31 | test: $(TBIN) | ||
| 30 | 32 | ||
| 31 | bin/%: obj/%.o | 33 | bin/%: obj/%.o |
| 32 | @mkdir -p $(@D) | 34 | @mkdir -p $(@D) |
diff --git a/src/multitouch.c b/src/multitouch.c index 2dfba79..21f0613 100644 --- a/src/multitouch.c +++ b/src/multitouch.c | |||
| @@ -30,21 +30,11 @@ | |||
| 30 | #include <errno.h> | 30 | #include <errno.h> |
| 31 | 31 | ||
| 32 | //////////////////////////////////////////////////////////////////////////// | 32 | //////////////////////////////////////////////////////////////////////////// |
| 33 | 33 | //#define BTN_MT_REPORT_PACKET 0x210 /* report multitouch packet data */ | |
| 34 | #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) | 34 | //#define BTN_MT_REPORT_FINGER 0x211 /* report multitouch finger data */ |
| 35 | |||
| 36 | #define LONG_BITS (sizeof(long) * 8) | ||
| 37 | #define NBITS(x) (((x) + LONG_BITS - 1) / LONG_BITS) | ||
| 38 | #define OFF(x) ((x) % LONG_BITS) | ||
| 39 | #define LONG(x) ((x) / LONG_BITS) | ||
| 40 | #define TEST_BIT(bit, array) (array[LONG(bit)] & (1 << OFF(bit))) | ||
| 41 | |||
| 42 | //////////////////////////////////////////////////////////////////////////// | ||
| 43 | |||
| 44 | //#define BTN_MT_RAW_DATA 0x210 /* multitouch device */ | ||
| 45 | #define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */ | 35 | #define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */ |
| 46 | #define BTN_MT_RAW_DATA 0x14b /* multitouch device */ | 36 | #define BTN_MT_REPORT_PACKET 0x14b /* multitouch device */ |
| 47 | #define BTN_MT_RAW_FINGER 0x14c /* multitouch device */ | 37 | #define BTN_MT_REPORT_FINGER 0x14c /* multitouch device */ |
| 48 | #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ | 38 | #define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ |
| 49 | 39 | ||
| 50 | #define ABS_MT_TOUCH 0x30 | 40 | #define ABS_MT_TOUCH 0x30 |
| @@ -59,6 +49,32 @@ | |||
| 59 | 49 | ||
| 60 | typedef int bool; | 50 | typedef int bool; |
| 61 | 51 | ||
| 52 | //////////////////////////////////////////////////////////////////////////// | ||
| 53 | |||
| 54 | #define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) | ||
| 55 | |||
| 56 | static const int bits_per_long = 8 * sizeof(long); | ||
| 57 | |||
| 58 | static inline int nlongs(int nbit) | ||
| 59 | { | ||
| 60 | return (nbit + bits_per_long - 1) / bits_per_long; | ||
| 61 | } | ||
| 62 | |||
| 63 | static inline bool getbit(const unsigned long* map, int key) | ||
| 64 | { | ||
| 65 | return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; | ||
| 66 | } | ||
| 67 | |||
| 68 | static bool getabs(struct input_absinfo *abs, int key, int fd) | ||
| 69 | { | ||
| 70 | int rc; | ||
| 71 | SYSCALL(rc = ioctl(fd, EVIOCGABS(key), &abs)); | ||
| 72 | return rc >= 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | #define SETABS(c, x, map, key, fd) \ | ||
| 76 | c->has_##x = getbit(map, key) && getabs(&c->abs_##x, key, fd) | ||
| 77 | |||
| 62 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") | 78 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") |
| 63 | 79 | ||
| 64 | //////////////////////////////////////////////////////////////////////////// | 80 | //////////////////////////////////////////////////////////////////////////// |
| @@ -83,9 +99,9 @@ struct Capabilities { | |||
| 83 | 99 | ||
| 84 | static int read_capabilities(struct Capabilities *cap, int fd) | 100 | static int read_capabilities(struct Capabilities *cap, int fd) |
| 85 | { | 101 | { |
| 86 | unsigned long evbits[NBITS(EV_MAX)]; | 102 | unsigned long evbits[nlongs(EV_MAX)]; |
| 87 | unsigned long absbits[NBITS(ABS_MAX)]; | 103 | unsigned long absbits[nlongs(ABS_MAX)]; |
| 88 | unsigned long keybits[NBITS(KEY_MAX)]; | 104 | unsigned long keybits[nlongs(KEY_MAX)]; |
| 89 | int rc; | 105 | int rc; |
| 90 | 106 | ||
| 91 | memset(cap, 0, sizeof(struct Capabilities)); | 107 | memset(cap, 0, sizeof(struct Capabilities)); |
| @@ -100,19 +116,24 @@ static int read_capabilities(struct Capabilities *cap, int fd) | |||
| 100 | if (rc < 0) | 116 | if (rc < 0) |
| 101 | return rc; | 117 | return rc; |
| 102 | 118 | ||
| 103 | cap->has_left = TEST_BIT(BTN_LEFT, keybits); | 119 | cap->has_left = getbit(keybits, BTN_LEFT); |
| 104 | cap->has_middle = TEST_BIT(BTN_MIDDLE, keybits); | 120 | cap->has_middle = getbit(keybits, BTN_MIDDLE); |
| 105 | cap->has_right = TEST_BIT(BTN_RIGHT, keybits); | 121 | cap->has_right = getbit(keybits, BTN_RIGHT); |
| 106 | cap->has_mtdata = TEST_BIT(BTN_MT_RAW_DATA, keybits); | 122 | cap->has_mtdata = getbit(keybits, BTN_MT_REPORT_PACKET); |
| 107 | 123 | ||
| 108 | SYSCALL(rc = ioctl(fd, EVIOCGABS(ABS_MT_TOUCH_MAJOR), | 124 | SETABS(cap, touch_major, absbits, ABS_MT_TOUCH_MAJOR, fd); |
| 109 | &cap->abs_touch_major)); | 125 | SETABS(cap, touch_minor, absbits, ABS_MT_TOUCH_MINOR, fd); |
| 110 | cap->has_touch_major = rc >= 0; | 126 | SETABS(cap, width_major, absbits, ABS_MT_WIDTH_MAJOR, fd); |
| 127 | SETABS(cap, width_minor, absbits, ABS_MT_WIDTH_MINOR, fd); | ||
| 128 | SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); | ||
| 129 | SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); | ||
| 130 | SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); | ||
| 111 | } | 131 | } |
| 112 | 132 | ||
| 113 | static int output_capabilities(const struct Capabilities *cap) | 133 | static int output_capabilities(const struct Capabilities *cap) |
| 114 | { | 134 | { |
| 115 | char line[1024]; | 135 | char line[1024]; |
| 136 | memset(line, 0, sizeof(line)); | ||
| 116 | ADDCAP(line, cap, left); | 137 | ADDCAP(line, cap, left); |
| 117 | ADDCAP(line, cap, middle); | 138 | ADDCAP(line, cap, middle); |
| 118 | ADDCAP(line, cap, right); | 139 | ADDCAP(line, cap, right); |
