38#define BITS_PER_LONG (sizeof(unsigned long) * 8)
39#define NBITS(x) ((((x)-1)/BITS_PER_LONG)+1)
40#define OFF(x) ((x)%BITS_PER_LONG)
41#define LONG(x) ((x)/BITS_PER_LONG)
42#define test_bit(bit, array) ((array[LONG(bit)] >> OFF(bit)) & 1)
44 unsigned long bitmask_ev[
NBITS(EV_MAX)];
45 unsigned long bitmask_key[
NBITS(KEY_MAX)];
46 unsigned long bitmask_abs[
NBITS(ABS_MAX)];
47 unsigned long bitmask_rel[
NBITS(REL_MAX)];
49 if (ioctl(fd, EVIOCGBIT(0,
sizeof(bitmask_ev)), &bitmask_ev) == -1)
return false;
50 if (ioctl(fd, EVIOCGBIT(EV_KEY,
sizeof(bitmask_key)), &bitmask_key) == -1)
return false;
51 if (ioctl(fd, EVIOCGBIT(EV_ABS,
sizeof(bitmask_abs)), &bitmask_abs) == -1)
return false;
52 if (ioctl(fd, EVIOCGBIT(EV_REL,
sizeof(bitmask_rel)), &bitmask_rel) == -1)
return false;
54 bool is_keyboard = (bitmask_key[0] & 0xFFFFFFFE);
57 bool is_mouse = (is_abs || is_rel) &&
test_bit(BTN_MOUSE, bitmask_key);
58 bool is_touch = is_abs && (
test_bit(BTN_TOOL_FINGER, bitmask_key) ||
test_bit(BTN_TOUCH, bitmask_key));
60 return is_keyboard || is_mouse || is_touch;