Exemple #1
0
static int
device_added(struct udev_device *udev_device, struct udev_input *input)
{
	struct weston_compositor *c;
	struct evdev_device *device;
	struct weston_output *output;
	const char *devnode;
	const char *device_seat, *seat_name, *output_name;
	const char *calibration_values;
	int fd;
	struct udev_seat *seat;

	device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
	if (!device_seat)
		device_seat = default_seat;

	if (strcmp(device_seat, input->seat_id))
		return 0;

	c = input->compositor;
	devnode = udev_device_get_devnode(udev_device);

	/* Search for matching logical seat */
	seat_name = udev_device_get_property_value(udev_device, "WL_SEAT");
	if (!seat_name)
		seat_name = default_seat_name;

	seat = udev_seat_get_named(c, seat_name);

	if (seat == NULL)
		return -1;

	/* Use non-blocking mode so that we can loop on read on
	 * evdev_device_data() until all events on the fd are
	 * read.  mtdev_get() also expects this. */
	fd = weston_launcher_open(c->launcher, devnode, O_RDWR | O_NONBLOCK);
	if (fd < 0) {
		weston_log("opening input device '%s' failed.\n", devnode);
		return 0;
	}

	device = evdev_device_create(&seat->base, devnode, fd);
	if (device == EVDEV_UNHANDLED_DEVICE) {
		weston_launcher_close(c->launcher, fd);
		weston_log("not using input device '%s'.\n", devnode);
		return 0;
	} else if (device == NULL) {
		weston_launcher_close(c->launcher, fd);
		weston_log("failed to create input device '%s'.\n", devnode);
		return 0;
	}

	calibration_values =
		udev_device_get_property_value(udev_device,
					       "WL_CALIBRATION");

	if (calibration_values && sscanf(calibration_values,
					 "%f %f %f %f %f %f",
					 &device->abs.calibration[0],
					 &device->abs.calibration[1],
					 &device->abs.calibration[2],
					 &device->abs.calibration[3],
					 &device->abs.calibration[4],
					 &device->abs.calibration[5]) == 6) {
		device->abs.apply_calibration = 1;
		weston_log ("Applying calibration: %f %f %f %f %f %f\n",
			    device->abs.calibration[0],
			    device->abs.calibration[1],
			    device->abs.calibration[2],
			    device->abs.calibration[3],
			    device->abs.calibration[4],
			    device->abs.calibration[5]);
	}

	wl_list_insert(seat->devices_list.prev, &device->link);

	if (seat->base.output && seat->base.pointer)
		weston_pointer_clamp(seat->base.pointer,
				     &seat->base.pointer->x,
				     &seat->base.pointer->y);

	output_name = udev_device_get_property_value(udev_device, "WL_OUTPUT");
	if (output_name) {
		device->output_name = strdup(output_name);
		wl_list_for_each(output, &c->output_list, link)
			if (strcmp(output->name, device->output_name) == 0)
				evdev_device_set_output(device, output);
	} else if (device->output == NULL) {
Exemple #2
0
static int
device_added(struct udev_device *udev_device, struct udev_seat *master)
{
	struct weston_compositor *c;
	struct evdev_device *device;
	const char *devnode;
	const char *device_seat;
	const char *calibration_values;
	int fd;

	device_seat = udev_device_get_property_value(udev_device, "ID_SEAT");
	if (!device_seat)
		device_seat = default_seat;

	if (strcmp(device_seat, master->seat_id))
		return 0;

	c = master->base.compositor;
	devnode = udev_device_get_devnode(udev_device);

	/* Use non-blocking mode so that we can loop on read on
	 * evdev_device_data() until all events on the fd are
	 * read.  mtdev_get() also expects this. */
	fd = weston_launcher_open(c, devnode, O_RDWR | O_NONBLOCK);
	if (fd < 0) {
		weston_log("opening input device '%s' failed.\n", devnode);
		return -1;
	}

	device = evdev_device_create(&master->base, devnode, fd);
	if (device == EVDEV_UNHANDLED_DEVICE) {
		close(fd);
		weston_log("not using input device '%s'.\n", devnode);
		return 0;
	} else if (device == NULL) {
		close(fd);
		weston_log("failed to create input device '%s'.\n", devnode);
		return -1;
	}

	calibration_values =
		udev_device_get_property_value(udev_device,
					       "WL_CALIBRATION");

	if (calibration_values && sscanf(calibration_values,
					 "%f %f %f %f %f %f",
					 &device->abs.calibration[0],
					 &device->abs.calibration[1],
					 &device->abs.calibration[2],
					 &device->abs.calibration[3],
					 &device->abs.calibration[4],
					 &device->abs.calibration[5]) == 6) {
		device->abs.apply_calibration = 1;
		weston_log ("Applying calibration: %f %f %f %f %f %f\n",
			    device->abs.calibration[0],
			    device->abs.calibration[1],
			    device->abs.calibration[2],
			    device->abs.calibration[3],
			    device->abs.calibration[4],
			    device->abs.calibration[5]);
	}

	wl_list_insert(master->devices_list.prev, &device->link);

	return 0;
}