diff options
| author | Henrik Rydberg <rydberg@euromail.se> | 2008-11-05 00:02:22 +0100 |
|---|---|---|
| committer | Henrik Rydberg <rydberg@euromail.se> | 2008-11-05 00:02:22 +0100 |
| commit | 12b0a79f9e5bc483b5c16f702ae5b8836425827e (patch) | |
| tree | e0f1ef6f040d8122b418214d7cbf09db889edc2e /src/capabilities.c | |
| parent | 85e6b86f23bea2e5265f6aaac2b5673409a9b7b5 (diff) | |
Break out capabilities
Signed-off-by: Henrik Rydberg <rydberg@euromail.se>
Diffstat (limited to 'src/capabilities.c')
| -rw-r--r-- | src/capabilities.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/capabilities.c b/src/capabilities.c new file mode 100644 index 0000000..3149131 --- /dev/null +++ b/src/capabilities.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | #include "capabilities.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | //////////////////////////////////////////////////////// | ||
| 5 | |||
| 6 | #define SETABS(c, x, map, key, fd) \ | ||
| 7 | c->has_##x = getbit(map, key) && getabs(&c->abs_##x, key, fd) | ||
| 8 | |||
| 9 | #define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////// | ||
| 12 | |||
| 13 | static const int bits_per_long = 8 * sizeof(long); | ||
| 14 | |||
| 15 | static inline int nlongs(int nbit) | ||
| 16 | { | ||
| 17 | return (nbit + bits_per_long - 1) / bits_per_long; | ||
| 18 | } | ||
| 19 | |||
| 20 | static inline bool getbit(const unsigned long* map, int key) | ||
| 21 | { | ||
| 22 | return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; | ||
| 23 | } | ||
| 24 | |||
| 25 | static bool getabs(struct input_absinfo *abs, int key, int fd) | ||
| 26 | { | ||
| 27 | int rc; | ||
| 28 | SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs)); | ||
| 29 | return rc >= 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | //////////////////////////////////////////////////////// | ||
| 33 | |||
| 34 | static int read_capabilities(struct Capabilities *cap, int fd) | ||
| 35 | { | ||
| 36 | unsigned long evbits[nlongs(EV_MAX)]; | ||
| 37 | unsigned long absbits[nlongs(ABS_MAX)]; | ||
| 38 | unsigned long keybits[nlongs(KEY_MAX)]; | ||
| 39 | int rc; | ||
| 40 | |||
| 41 | memset(cap, 0, sizeof(struct Capabilities)); | ||
| 42 | |||
| 43 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits)); | ||
| 44 | if (rc < 0) | ||
| 45 | return rc; | ||
| 46 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits)); | ||
| 47 | if (rc < 0) | ||
| 48 | return rc; | ||
| 49 | SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); | ||
| 50 | if (rc < 0) | ||
| 51 | return rc; | ||
| 52 | |||
| 53 | cap->has_left = getbit(keybits, BTN_LEFT); | ||
| 54 | cap->has_middle = getbit(keybits, BTN_MIDDLE); | ||
| 55 | cap->has_right = getbit(keybits, BTN_RIGHT); | ||
| 56 | cap->has_mtdata = getbit(keybits, BTN_MT_REPORT_PACKET); | ||
| 57 | |||
| 58 | SETABS(cap, touch_major, absbits, ABS_MT_TOUCH_MAJOR, fd); | ||
| 59 | SETABS(cap, touch_minor, absbits, ABS_MT_TOUCH_MINOR, fd); | ||
| 60 | SETABS(cap, width_major, absbits, ABS_MT_WIDTH_MAJOR, fd); | ||
| 61 | SETABS(cap, width_minor, absbits, ABS_MT_WIDTH_MINOR, fd); | ||
| 62 | SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); | ||
| 63 | SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); | ||
| 64 | SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); | ||
| 65 | } | ||
| 66 | |||
| 67 | //////////////////////////////////////////////////////// | ||
| 68 | |||
| 69 | static int output_capabilities(const struct Capabilities *cap) | ||
| 70 | { | ||
| 71 | char line[1024]; | ||
| 72 | memset(line, 0, sizeof(line)); | ||
| 73 | ADDCAP(line, cap, left); | ||
| 74 | ADDCAP(line, cap, middle); | ||
| 75 | ADDCAP(line, cap, right); | ||
| 76 | ADDCAP(line, cap, mtdata); | ||
| 77 | ADDCAP(line, cap, touch_major); | ||
| 78 | ADDCAP(line, cap, touch_minor); | ||
| 79 | ADDCAP(line, cap, width_major); | ||
| 80 | ADDCAP(line, cap, width_minor); | ||
| 81 | ADDCAP(line, cap, orientation); | ||
| 82 | ADDCAP(line, cap, position_x); | ||
| 83 | ADDCAP(line, cap, position_y); | ||
| 84 | xf86Msg(X_INFO, "multitouch: caps:%s\n", line); | ||
| 85 | } | ||
| 86 | |||
| 87 | //////////////////////////////////////////////////////// | ||
