diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | src/capabilities.c | 87 | ||||
-rw-r--r-- | src/capabilities.h | 27 | ||||
-rw-r--r-- | src/common.h | 34 | ||||
-rw-r--r-- | src/multitouch.c | 125 |
5 files changed, 150 insertions, 125 deletions
@@ -2,7 +2,7 @@ LIBRARY = multitouch.so FDIS = 11-multitouch.fdi MODULES = src -o_src = multitouch +o_src = capabilities multitouch TARGETS = $(addsuffix /test,$(MODULES)) 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 @@ +#include "capabilities.h" +#include <errno.h> + +//////////////////////////////////////////////////////// + +#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 : "") + +//////////////////////////////////////////////////////// + +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; +} + +//////////////////////////////////////////////////////// + +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); +} + +//////////////////////////////////////////////////////// diff --git a/src/capabilities.h b/src/capabilities.h new file mode 100644 index 0000000..f09a34e --- /dev/null +++ b/src/capabilities.h @@ -0,0 +1,27 @@ +#ifndef CAPABILITIES_H +#define CAPABILITIES_H + +#include "common.h" +#include <linux/input.h> + +//////////////////////////////////////////////////////// + +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; +}; + +//////////////////////////////////////////////////////// + +#endif diff --git a/src/common.h b/src/common.h new file mode 100644 index 0000000..7aabd7e --- /dev/null +++ b/src/common.h @@ -0,0 +1,34 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "xorg-server.h" +#include <xf86.h> +#include <xf86_OSproc.h> +#include <xf86Xinput.h> +//#include <exevents.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)) + +//////////////////////////////////////////////////////// + +#endif 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 <xf86.h> -#include <xf86_OSproc.h> -#include <xf86Xinput.h> -//#include <exevents.h> -#include <linux/input.h> -#include <errno.h> +#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) { |