evdev_read_model_flags(struct evdev_device *device)
{
	const struct model_map {
		enum quirk quirk;
		enum evdev_device_model model;
	} model_map[] = {
#define MODEL(name) { QUIRK_MODEL_##name, EVDEV_MODEL_##name }
		MODEL(WACOM_TOUCHPAD),
		MODEL(SYNAPTICS_SERIAL_TOUCHPAD),
		MODEL(ALPS_SERIAL_TOUCHPAD),
		MODEL(LENOVO_T450_TOUCHPAD),
		MODEL(TRACKBALL),
		MODEL(APPLE_TOUCHPAD_ONEBUTTON),
		MODEL(LENOVO_SCROLLPOINT),
#undef MODEL
		{ 0, 0 },
	};
	const struct model_map *m = model_map;
	uint32_t model_flags = 0;
	uint32_t all_model_flags = 0;
	struct quirks_context *quirks;
	struct quirks *q;

	quirks = evdev_libinput_context(device)->quirks;
	q = quirks_fetch_for_device(quirks, device->udev_device);

	while (q && m->quirk) {
		bool is_set;

		/* Check for flag re-use */
		assert((all_model_flags & m->model) == 0);
		all_model_flags |= m->model;

		if (quirks_get_bool(q, m->quirk, &is_set)) {
			if (is_set) {
				evdev_log_debug(device,
						"tagged as %s\n",
						quirk_get_name(m->quirk));
				model_flags |= m->model;
			} else {
				evdev_log_debug(device,
						"untagged as %s\n",
						quirk_get_name(m->quirk));
				model_flags &= ~m->model;
			}
		}

		m++;
	}

	quirks_unref(q);

	if (parse_udev_flag(device,
			    device->udev_device,
			    "ID_INPUT_TRACKBALL")) {
		evdev_log_debug(device, "tagged as trackball\n");
		model_flags |= EVDEV_MODEL_TRACKBALL;
	}

	/**
	 * Device is 6 years old at the time of writing this and this was
	 * one of the few udev properties that wasn't reserved for private
	 * usage, so we need to keep this for backwards compat.
	 */
	if (parse_udev_flag(device,
			    device->udev_device,
			    "LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81")) {
		evdev_log_debug(device, "tagged as trackball\n");
		model_flags |= EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81;
	}

	if (parse_udev_flag(device, device->udev_device,
			    "LIBINPUT_TEST_DEVICE")) {
		evdev_log_debug(device, "is a test device\n");
		model_flags |= EVDEV_MODEL_TEST_DEVICE;
	}

	return model_flags;
}
evdev_read_model_flags(struct evdev_device *device)
{
	const struct model_map {
		enum quirk quirk;
		enum evdev_device_model model;
	} model_map[] = {
#define MODEL(name) { QUIRK_MODEL_##name, EVDEV_MODEL_##name }
		MODEL(WACOM_TOUCHPAD),
		MODEL(SYNAPTICS_SERIAL_TOUCHPAD),
		MODEL(ALPS_SERIAL_TOUCHPAD),
		MODEL(LENOVO_T450_TOUCHPAD),
		MODEL(TRACKBALL),
		MODEL(APPLE_TOUCHPAD_ONEBUTTON),
		MODEL(LENOVO_SCROLLPOINT),
#undef MODEL
		{ 0, 0 },
	};
	const struct model_map *m = model_map;
	uint32_t model_flags = 0;
	uint32_t all_model_flags = 0;
	struct quirks_context *quirks;
	struct quirks *q;

	quirks = evdev_libinput_context(device)->quirks;
	q = quirks_fetch_for_device(quirks, device->udev_device);

	while (q && m->quirk) {
		bool is_set;

		 
		assert((all_model_flags & m->model) == 0);
		all_model_flags |= m->model;

		if (quirks_get_bool(q, m->quirk, &is_set)) {
			if (is_set) {
				evdev_log_debug(device,
						"tagged as %s\n",
						quirk_get_name(m->quirk));
				model_flags |= m->model;
			} else {
				evdev_log_debug(device,
						"untagged as %s\n",
						quirk_get_name(m->quirk));
				model_flags &= ~m->model;
			}
		}

		m++;
	}

	quirks_unref(q);

	if (parse_udev_flag(device,
			    device->udev_device,
			    "ID_INPUT_TRACKBALL")) {
		evdev_log_debug(device, "tagged as trackball\n");
		model_flags |= EVDEV_MODEL_TRACKBALL;
	}

	 
	if (parse_udev_flag(device,
			    device->udev_device,
			    "LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81")) {
		evdev_log_debug(device, "tagged as trackball\n");
		model_flags |= EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81;
	}

	if (parse_udev_flag(device, device->udev_device,
			    "LIBINPUT_TEST_DEVICE")) {
		evdev_log_debug(device, "is a test device\n");
		model_flags |= EVDEV_MODEL_TEST_DEVICE;
	}

	return model_flags;
}