From 12b0a79f9e5bc483b5c16f702ae5b8836425827e Mon Sep 17 00:00:00 2001 From: Henrik Rydberg Date: Wed, 5 Nov 2008 00:02:22 +0100 Subject: Break out capabilities Signed-off-by: Henrik Rydberg --- src/multitouch.c | 125 +------------------------------------------------------ 1 file changed, 1 insertion(+), 124 deletions(-) (limited to 'src/multitouch.c') diff --git a/src/multitouch.c b/src/multitouch.c index 439155f..6818e7c 100644 --- a/src/multitouch.c +++ b/src/multitouch.c @@ -21,132 +21,9 @@ * **************************************************************************/ -#include "xorg-server.h" -#include -#include -#include -//#include -#include -#include +#include "capabilities.h" //////////////////////////////////////////////////////////////////////////// -//#define BTN_MT_REPORT_PACKET 0x210 /* report multitouch packet data */ -//#define BTN_MT_REPORT_FINGER 0x211 /* report multitouch finger data */ -#define BTN_TOOL_PRESS 0x148 /* The trackpad is a physical button */ -#define BTN_MT_REPORT_PACKET 0x14b /* multitouch device */ -#define BTN_MT_REPORT_FINGER 0x14c /* multitouch device */ -#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */ - -#define ABS_MT_TOUCH 0x30 -#define ABS_MT_TOUCH_MAJOR 0x30 -#define ABS_MT_TOUCH_MINOR 0x31 -#define ABS_MT_WIDTH 0x32 -#define ABS_MT_WIDTH_MAJOR 0x32 -#define ABS_MT_WIDTH_MINOR 0x33 -#define ABS_MT_ORIENTATION 0x34 -#define ABS_MT_POSITION_X 0x35 -#define ABS_MT_POSITION_Y 0x36 - -typedef int bool; - -//////////////////////////////////////////////////////////////////////////// - -#define SYSCALL(call) while (((call) == -1) && (errno == EINTR)) - -static const int bits_per_long = 8 * sizeof(long); - -static inline int nlongs(int nbit) -{ - return (nbit + bits_per_long - 1) / bits_per_long; -} - -static inline bool getbit(const unsigned long* map, int key) -{ - return (map[key / bits_per_long] >> (key % bits_per_long)) & 0x01; -} - -static bool getabs(struct input_absinfo *abs, int key, int fd) -{ - int rc; - SYSCALL(rc = ioctl(fd, EVIOCGABS(key), abs)); - return rc >= 0; -} - -#define SETABS(c, x, map, key, fd) \ - c->has_##x = getbit(map, key) && getabs(&c->abs_##x, key, fd) - -#define ADDCAP(s, c, x) strcat(s, c->has_##x ? " " #x : "") - -//////////////////////////////////////////////////////////////////////////// - -struct Capabilities { - bool has_left, has_middle; - bool has_right, has_mtdata; - bool has_touch_major, has_touch_minor; - bool has_width_major, has_width_minor; - bool has_orientation, has_dummy; - bool has_position_x, has_position_y; - struct input_absinfo abs_touch_major; - struct input_absinfo abs_touch_minor; - struct input_absinfo abs_width_major; - struct input_absinfo abs_width_minor; - struct input_absinfo abs_orientation; - struct input_absinfo abs_position_x; - struct input_absinfo abs_position_y; -}; - -//////////////////////////////////////////////////////////////////////////// - -static int read_capabilities(struct Capabilities *cap, int fd) -{ - unsigned long evbits[nlongs(EV_MAX)]; - unsigned long absbits[nlongs(ABS_MAX)]; - unsigned long keybits[nlongs(KEY_MAX)]; - int rc; - - memset(cap, 0, sizeof(struct Capabilities)); - - SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_SYN, sizeof(evbits)), evbits)); - if (rc < 0) - return rc; - SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits)); - if (rc < 0) - return rc; - SYSCALL(rc = ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits)); - if (rc < 0) - return rc; - - cap->has_left = getbit(keybits, BTN_LEFT); - cap->has_middle = getbit(keybits, BTN_MIDDLE); - cap->has_right = getbit(keybits, BTN_RIGHT); - cap->has_mtdata = getbit(keybits, BTN_MT_REPORT_PACKET); - - SETABS(cap, touch_major, absbits, ABS_MT_TOUCH_MAJOR, fd); - SETABS(cap, touch_minor, absbits, ABS_MT_TOUCH_MINOR, fd); - SETABS(cap, width_major, absbits, ABS_MT_WIDTH_MAJOR, fd); - SETABS(cap, width_minor, absbits, ABS_MT_WIDTH_MINOR, fd); - SETABS(cap, orientation, absbits, ABS_MT_ORIENTATION, fd); - SETABS(cap, position_x, absbits, ABS_MT_POSITION_X, fd); - SETABS(cap, position_y, absbits, ABS_MT_POSITION_Y, fd); -} - -static int output_capabilities(const struct Capabilities *cap) -{ - char line[1024]; - memset(line, 0, sizeof(line)); - ADDCAP(line, cap, left); - ADDCAP(line, cap, middle); - ADDCAP(line, cap, right); - ADDCAP(line, cap, mtdata); - ADDCAP(line, cap, touch_major); - ADDCAP(line, cap, touch_minor); - ADDCAP(line, cap, width_major); - ADDCAP(line, cap, width_minor); - ADDCAP(line, cap, orientation); - ADDCAP(line, cap, position_x); - ADDCAP(line, cap, position_y); - xf86Msg(X_INFO, "multitouch: caps:%s\n", line); -} static InputInfoPtr preinit(InputDriverPtr drv, IDevPtr dev, int flags) { -- cgit v1.2.3