[PATCH libinput 1/4] evdev: allow for multiple LIBINPUT_MODEL_* flags per device

Peter Hutterer peter.hutterer at who-t.net
Mon Jul 20 22:51:01 PDT 2015


On some devices we need to set more than one flag, i.e. make it into actual
flags.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad-buttons.c        | 17 +++++++----------
 src/evdev-mt-touchpad.c                | 12 ++++--------
 src/evdev.c                            | 11 ++++++-----
 src/evdev.h                            | 22 +++++++++++-----------
 udev/90-libinput-model-quirks.rules.in | 10 ++--------
 5 files changed, 30 insertions(+), 42 deletions(-)

diff --git a/src/evdev-mt-touchpad-buttons.c b/src/evdev-mt-touchpad-buttons.c
index 6aa74c3..84bf6ab 100644
--- a/src/evdev-mt-touchpad-buttons.c
+++ b/src/evdev-mt-touchpad-buttons.c
@@ -641,22 +641,19 @@ static enum libinput_config_click_method
 tp_click_get_default_method(struct tp_dispatch *tp)
 {
 	struct evdev_device *device = tp->device;
+	uint32_t clickfinger_models = EVDEV_MODEL_CHROMEBOOK |
+				      EVDEV_MODEL_SYSTEM76_BONOBO |
+				      EVDEV_MODEL_SYSTEM76_GALAGO |
+				      EVDEV_MODEL_SYSTEM76_KUDU |
+				      EVDEV_MODEL_CLEVO_W740SU;
 
 	if (!tp->buttons.is_clickpad)
 		return LIBINPUT_CONFIG_CLICK_METHOD_NONE;
 	else if (libevdev_get_id_vendor(tp->device->evdev) == VENDOR_ID_APPLE)
 		return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
 
-	switch (device->model) {
-	case EVDEV_MODEL_CHROMEBOOK:
-	case EVDEV_MODEL_SYSTEM76_BONOBO:
-	case EVDEV_MODEL_SYSTEM76_GALAGO:
-	case EVDEV_MODEL_SYSTEM76_KUDU:
-	case EVDEV_MODEL_CLEVO_W740SU:
+	if (device->model_flags & clickfinger_models)
 		return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
-	default:
-		break;
-	}
 
 	return LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
 }
@@ -688,7 +685,7 @@ tp_init_middlebutton_emulation(struct tp_dispatch *tp,
 	if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE)) {
 		enable_by_default = true;
 		want_config_option = false;
-	} else if (device->model == EVDEV_MODEL_ALPS_TOUCHPAD) {
+	} else if (device->model_flags & EVDEV_MODEL_ALPS_TOUCHPAD) {
 		enable_by_default = true;
 		want_config_option = true;
 	} else
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 35d0d85..b78618b 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1224,7 +1224,7 @@ evdev_tag_touchpad(struct evdev_device *device,
 	 */
 	bustype = libevdev_get_id_bustype(device->evdev);
 	if (bustype == BUS_USB) {
-		if (device->model == EVDEV_MODEL_APPLE_TOUCHPAD)
+		if (device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD)
 			 device->tags |= EVDEV_TAG_INTERNAL_TOUCHPAD;
 	} else if (bustype != BUS_BLUETOOTH)
 		device->tags |= EVDEV_TAG_INTERNAL_TOUCHPAD;
@@ -1350,14 +1350,10 @@ tp_init_accel(struct tp_dispatch *tp, double diagonal)
 	tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x;
 	tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
 
-	switch (tp->device->model) {
-	case EVDEV_MODEL_LENOVO_X230:
+	if (tp->device->model_flags & EVDEV_MODEL_LENOVO_X230)
 		profile = touchpad_lenovo_x230_accel_profile;
-		break;
-	default:
+	else
 		profile = touchpad_accel_profile_linear;
-		break;
-	}
 
 	if (evdev_device_init_pointer_acceleration(tp->device, profile) == -1)
 		return -1;
@@ -1460,7 +1456,7 @@ tp_init_palmdetect(struct tp_dispatch *tp,
 
 	/* Wacom doesn't have internal touchpads,
 	 * Apple touchpads are always big enough to warrant palm detection */
-	if (device->model == EVDEV_MODEL_WACOM_TOUCHPAD)
+	if (device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD)
 		return 0;
 
 	/* Enable palm detection on touchpads >= 70 mm. Anything smaller
diff --git a/src/evdev.c b/src/evdev.c
index 07934de..1d328b4 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1525,8 +1525,8 @@ evdev_read_dpi_prop(struct evdev_device *device)
 	return dpi;
 }
 
-static inline enum evdev_device_model
-evdev_read_model(struct evdev_device *device)
+static inline uint32_t
+evdev_read_model_flags(struct evdev_device *device)
 {
 	const struct model_map {
 		const char *property;
@@ -1544,15 +1544,16 @@ evdev_read_model(struct evdev_device *device)
 		{ NULL, EVDEV_MODEL_DEFAULT },
 	};
 	const struct model_map *m = model_map;
+	uint32_t model_flags = 0;
 
 	while (m->property) {
 		if (!!udev_device_get_property_value(device->udev_device,
 						     m->property))
-			break;
+			model_flags |= m->model;
 		m++;
 	}
 
-	return m->model;
+	return model_flags;
 }
 
 static inline int
@@ -2146,7 +2147,7 @@ evdev_device_create(struct libinput_seat *seat,
 	device->scroll.direction = 0;
 	device->scroll.wheel_click_angle =
 		evdev_read_wheel_click_prop(device);
-	device->model = evdev_read_model(device);
+	device->model_flags = evdev_read_model_flags(device);
 	device->dpi = DEFAULT_MOUSE_DPI;
 
 	/* at most 5 SYN_DROPPED log-messages per 30s */
diff --git a/src/evdev.h b/src/evdev.h
index 77db1b4..363f93b 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -95,16 +95,16 @@ enum evdev_middlebutton_event {
 };
 
 enum evdev_device_model {
-	EVDEV_MODEL_DEFAULT,
-	EVDEV_MODEL_LENOVO_X230,
-	EVDEV_MODEL_CHROMEBOOK,
-	EVDEV_MODEL_SYSTEM76_BONOBO,
-	EVDEV_MODEL_SYSTEM76_GALAGO,
-	EVDEV_MODEL_SYSTEM76_KUDU,
-	EVDEV_MODEL_CLEVO_W740SU,
-	EVDEV_MODEL_APPLE_TOUCHPAD,
-	EVDEV_MODEL_WACOM_TOUCHPAD,
-	EVDEV_MODEL_ALPS_TOUCHPAD,
+	EVDEV_MODEL_DEFAULT = 0,
+	EVDEV_MODEL_LENOVO_X230 = (1 << 0),
+	EVDEV_MODEL_CHROMEBOOK = (1 << 1),
+	EVDEV_MODEL_SYSTEM76_BONOBO = (1 << 2),
+	EVDEV_MODEL_SYSTEM76_GALAGO = (1 << 3),
+	EVDEV_MODEL_SYSTEM76_KUDU = (1 << 4),
+	EVDEV_MODEL_CLEVO_W740SU = (1 << 5),
+	EVDEV_MODEL_APPLE_TOUCHPAD = (1 << 6),
+	EVDEV_MODEL_WACOM_TOUCHPAD = (1 << 7),
+	EVDEV_MODEL_ALPS_TOUCHPAD = (1 << 8),
 };
 
 struct mt_slot {
@@ -221,7 +221,7 @@ struct evdev_device {
 	int dpi; /* HW resolution */
 	struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */
 
-	enum evdev_device_model model;
+	uint32_t model_flags;
 };
 
 #define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
diff --git a/udev/90-libinput-model-quirks.rules.in b/udev/90-libinput-model-quirks.rules.in
index d834155..5b07726 100644
--- a/udev/90-libinput-model-quirks.rules.in
+++ b/udev/90-libinput-model-quirks.rules.in
@@ -25,18 +25,12 @@ KERNELS=="*input*", \
   IMPORT{builtin}="hwdb 'libinput:name:$attr{name}:fwversion:$env{LIBINPUT_MODEL_FIRMWARE_VERSION}'"
 # End of touchpad firmware detection
 
-# Matches below are exclusive, if one matches we skip the rest
-# hwdb matches:
-# 
 # libinput:touchpad:<modalias>
 ENV{ID_INPUT_TOUCHPAD}=="1", \
-  IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=libinput:touchpad:", \
-  GOTO="libinput_model_quirks_end"
+  IMPORT{builtin}="hwdb --subsystem=input --lookup-prefix=libinput:touchpad:"
 
 # libinput:name:<name>:dmi:<dmi string>
 KERNELS=="input*", \
-  IMPORT{builtin}="hwdb 'libinput:name:$attr{name}:$attr{[dmi/id]modalias}'", \
-  GOTO="libinput_model_quirks_end"
-
+  IMPORT{builtin}="hwdb 'libinput:name:$attr{name}:$attr{[dmi/id]modalias}'"
 
 LABEL="libinput_model_quirks_end"
-- 
2.4.3



More information about the wayland-devel mailing list