int evdev_device_dispatch(struct evdev_device *device) { int fd = device->fd; struct input_event ev[32]; int len; /* If the compositor is repainting, this function is called only once * per frame and we have to process all the events available on the * fd, otherwise there will be input lag. */ do { if (device->mtdev) len = mtdev_get(device->mtdev, fd, ev, ARRAY_LENGTH(ev)) * sizeof (struct input_event); else len = read(fd, &ev, sizeof ev); if (len < 0 || len % sizeof ev[0] != 0) { if (len < 0 && errno != EAGAIN && errno != EINTR) { device->base.device_interface->device_lost( device->base.device_interface_data); } return 1; } evdev_process_events(device, ev, len / sizeof ev[0]); } while (len > 0); return 1; }
static int evdev_device_data(int fd, uint32_t mask, void *data) { struct weston_compositor *ec; struct evdev_device *device = data; struct input_event ev[32]; int len; ec = device->seat->compositor; if (!ec->focus) return 1; /* If the compositor is repainting, this function is called only once * per frame and we have to process all the events available on the * fd, otherwise there will be input lag. */ do { if (device->mtdev) len = mtdev_get(device->mtdev, fd, ev, ARRAY_LENGTH(ev)) * sizeof (struct input_event); else len = read(fd, &ev, sizeof ev); if (len < 0 || len % sizeof ev[0] != 0) { /* FIXME: call evdev_device_destroy when errno is ENODEV. */ return 1; } evdev_process_events(device, ev, len / sizeof ev[0]); } while (len > 0); return 1; }
int main(int argc, char *argv[]) { struct input_event ev; m_dpy = XOpenDisplay(NULL); if (!m_dpy) printf("fail top open x display\n"); m_fd = open(argv[1] ? argv[1] : DEVICE, O_RDONLY); if (m_fd == -1) { printf("fail to open device\n"); return -1; } if (m_dev = mtdev_new_open(m_fd)) { unlink(SAMPLE_FILE); m_sample_file.open(SAMPLE_FILE); CHECK(m_dev, ABS_MT_SLOT); CHECK(m_dev, ABS_MT_TOUCH_MAJOR); CHECK(m_dev, ABS_MT_TOUCH_MINOR); CHECK(m_dev, ABS_MT_WIDTH_MAJOR); CHECK(m_dev, ABS_MT_WIDTH_MINOR); CHECK(m_dev, ABS_MT_ORIENTATION); CHECK(m_dev, ABS_MT_POSITION_X); CHECK(m_dev, ABS_MT_POSITION_Y); CHECK(m_dev, ABS_MT_TOOL_TYPE); CHECK(m_dev, ABS_MT_BLOB_ID); CHECK(m_dev, ABS_MT_TRACKING_ID); CHECK(m_dev, ABS_MT_PRESSURE); CHECK(m_dev, ABS_MT_DISTANCE); CHECK(m_dev, ABS_MT_TOOL_X); CHECK(m_dev, ABS_MT_TOOL_Y); printf("ctrl+c to quit\n"); signal(SIGINT, m_signal_callback_handler); while (mtdev_get(m_dev, m_fd, &ev, 1) * sizeof(struct input_event)) m_process_event(&ev); } return 0; }
static void loop_device(int fd) { struct mtdev dev; struct input_event ev; int ret = mtdev_open(&dev, fd); if (ret) { fprintf(stderr, "error: could not open device: %d\n", ret); return; } show_props(&dev); /* while the device has not been inactive for five seconds */ while (!mtdev_idle(&dev, fd, 5000)) { /* extract all available processed events */ while (mtdev_get(&dev, fd, &ev, 1) > 0) { if (use_event(&ev)) print_event(&ev); } } mtdev_close(&dev); }