#include <stdio.h>
#include <unistd.h>
#include <linux/input.h>
#include <linux/uinput.h>
#include "fakedev.h"
int absrel_setup(struct uinput_user_dev* dev, int fd)
{
if (ioctl(fd, UI_SET_EVBIT, EV_REL) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_ABS) == -1) goto error;
if (ioctl(fd, UI_SET_EVBIT, EV_SYN) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_LEFT) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_MIDDLE) == -1) goto error;
if (ioctl(fd, UI_SET_KEYBIT, BTN_RIGHT) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_X) == -1) goto error;
if (ioctl(fd, UI_SET_RELBIT, REL_Y) == -1) goto error;
if (ioctl(fd, UI_SET_ABSBIT, ABS_X) == -1) goto error;
if (ioctl(fd, UI_SET_ABSBIT, ABS_Y) == -1) goto error;
dev->absmin[ABS_X] = 0;
dev->absmax[ABS_X] = 1000;
dev->absmin[ABS_Y] = 0;
dev->absmax[ABS_Y] = 1000;
return 0;
error:
perror("ioctl failed.");
return -1;
}
int absrel_run(int fd)
{
absmove(fd, 100, 100);
sleep(1);
absmove(fd, 120, 120);
sleep(1);
move(fd, 10, 10);
return 0;
}
struct test_device absrel_dev = {
.name = "Abs/Rel test device",
.setup = absrel_setup,
.run = absrel_run,
};
struct test_device* get_device()
{
return &absrel_dev;
}