Exemple #1
0
struct evdev_device *
evdev_device_create(struct weston_seat *seat, const char *path, int device_fd)
{
	struct evdev_device *device;
	struct weston_compositor *ec;
	char devname[256] = "unknown";

	device = zalloc(sizeof *device);
	if (device == NULL)
		return NULL;

	ec = seat->compositor;
	device->output =
		container_of(ec->output_list.next, struct weston_output, link);

	device->seat = seat;
	device->is_mt = 0;
	device->mtdev = NULL;
	device->devnode = strdup(path);
	device->mt.slot = -1;
	device->rel.dx = 0;
	device->rel.dy = 0;
	device->dispatch = NULL;
	device->fd = device_fd;

	ioctl(device->fd, EVIOCGNAME(sizeof(devname)), devname);
	devname[sizeof(devname) - 1] = '\0';
	device->devname = strdup(devname);

	if (!evdev_handle_device(device)) {
		evdev_device_destroy(device);
		return EVDEV_UNHANDLED_DEVICE;
	}

	if (evdev_configure_device(device) == -1)
		goto err;

	/* If the dispatch was not set up use the fallback. */
	if (device->dispatch == NULL)
		device->dispatch = fallback_dispatch_create();
	if (device->dispatch == NULL)
		goto err;

	device->source = wl_event_loop_add_fd(ec->input_loop, device->fd,
					      WL_EVENT_READABLE,
					      evdev_device_data, device);
	if (device->source == NULL)
		goto err;

	return device;

err:
	evdev_device_destroy(device);
	return NULL;
}
Exemple #2
0
LIBINPUT_EXPORT struct libinput_device *
libinput_device_create_evdev(
	const char *devnode,
	int fd,
	const struct libinput_device_interface *device_interface,
	void *user_data)
{
	struct evdev_device *device;
	char devname[256] = "unknown";

	device = zalloc(sizeof *device);
	if (device == NULL)
		return NULL;

	device->base.device_interface = device_interface;
	device->base.device_interface_data = user_data;

	device->seat_caps = 0;
	device->is_mt = 0;
	device->mtdev = NULL;
	device->devnode = strdup(devnode);
	device->mt.slot = -1;
	device->rel.dx = 0;
	device->rel.dy = 0;
	device->dispatch = NULL;
	device->fd = fd;
	device->pending_event = EVDEV_NONE;

	ioctl(device->fd, EVIOCGNAME(sizeof(devname)), devname);
	devname[sizeof(devname) - 1] = '\0';
	device->devname = strdup(devname);

	if (!evdev_handle_device(device)) {
		evdev_device_destroy(device);
		return NULL;
	}

	if (evdev_configure_device(device) == -1)
		goto err;

	/* If the dispatch was not set up use the fallback. */
	if (device->dispatch == NULL)
		device->dispatch = fallback_dispatch_create();
	if (device->dispatch == NULL)
		goto err;

	return &device->base;

err:
	evdev_device_destroy(device);
	return NULL;
}
Exemple #3
0
LIBINPUT_EXPORT void
libinput_device_destroy(struct libinput_device *device)
{
	evdev_device_destroy((struct evdev_device *) device);
}