[PATCH 5/8] evdev-touchpad: Introduced the notion of interaction model

Alexander E. Patrakov patrakov at gmail.com
Mon Aug 5 03:34:34 PDT 2013


From: "Alexander E. Patrakov" <patrakov at gmail.com>

Different hardware can be interacted with differently. So far, there is
some code for simple trackpads and for buttonpads. For buttonpads,
currently the FSM is disabled and the right click is emulated through
two-finger click. This is OK for Apple hardware, but not for Sony. A
Sony-specific interaction model will be introduced later.
---
 src/evdev-touchpad.c | 47 ++++++++++++++++++++++++++++++++++-------------
 1 file changed, 34 insertions(+), 13 deletions(-)

diff --git a/src/evdev-touchpad.c b/src/evdev-touchpad.c
index a9b21b8..1ed2dbb 100644
--- a/src/evdev-touchpad.c
+++ b/src/evdev-touchpad.c
@@ -45,7 +45,12 @@ enum touchpad_model {
 	TOUCHPAD_MODEL_SYNAPTICS,
 	TOUCHPAD_MODEL_ALPS,
 	TOUCHPAD_MODEL_APPLETOUCH,
-	TOUCHPAD_MODEL_ELANTECH
+	TOUCHPAD_MODEL_ELANTECH,
+};
+
+enum interaction_model {
+	INTERACTION_MODEL_SIMPLE = 0,
+	INTERACTION_MODEL_APPLE,
 };
 
 struct touchpad_model_spec {
@@ -95,6 +100,7 @@ struct touchpad_dispatch {
 	struct evdev_device *device;
 
 	enum touchpad_model model;
+	enum interaction_model interaction_model;
 	int finger_state;
 	int last_finger_state;
 
@@ -103,8 +109,6 @@ struct touchpad_dispatch {
 	double max_accel_factor;
 
 	struct {
-		bool enable;
-
 		struct wl_array events;
 		enum fsm_state state;
 		struct wl_event_source *timer_source;
@@ -163,6 +167,28 @@ get_touchpad_model(struct evdev_device *device)
 }
 
 static void
+configure_interaction_model(struct touchpad_dispatch *touchpad)
+{
+	unsigned long prop_bits[INPUT_PROP_MAX];
+
+	touchpad->interaction_model = INTERACTION_MODEL_SIMPLE;
+
+	ioctl(touchpad->device->fd, EVIOCGPROP(sizeof(prop_bits)), prop_bits);
+	if (!TEST_BIT(prop_bits, INPUT_PROP_BUTTONPAD))
+		return;
+
+	switch (touchpad->model) {
+	case TOUCHPAD_MODEL_APPLETOUCH:
+		touchpad->interaction_model = INTERACTION_MODEL_APPLE;
+		break;
+	default:
+		weston_log("Found a buttonpad of unknown type, assuming Apple-style\n");
+		touchpad->interaction_model = INTERACTION_MODEL_APPLE;
+		break;
+	}
+}
+
+static void
 configure_touchpad_pressure(struct touchpad_dispatch *touchpad,
 			    int32_t pressure_min, int32_t pressure_max)
 {
@@ -293,7 +319,7 @@ process_fsm_events(struct touchpad_dispatch *touchpad, uint32_t time)
 	enum fsm_event *pevent;
 	enum fsm_event event;
 
-	if (!touchpad->fsm.enable)
+	if (touchpad->interaction_model == INTERACTION_MODEL_APPLE)
 		return;
 
 	if (touchpad->fsm.events.size == 0)
@@ -387,7 +413,7 @@ push_fsm_event(struct touchpad_dispatch *touchpad,
 {
 	enum fsm_event *pevent;
 
-	if (!touchpad->fsm.enable)
+	if (touchpad->interaction_model == INTERACTION_MODEL_APPLE)
 		return;
 
 	pevent = wl_array_add(&touchpad->fsm.events, sizeof event);
@@ -578,7 +604,8 @@ process_key(struct touchpad_dispatch *touchpad,
 	case BTN_FORWARD:
 	case BTN_BACK:
 	case BTN_TASK:
-		if (!touchpad->fsm.enable && e->code == BTN_LEFT &&
+		if (touchpad->interaction_model == INTERACTION_MODEL_APPLE &&
+		    e->code == BTN_LEFT &&
 		    touchpad->finger_state == TOUCHPAD_FINGERS_TWO)
 			code = BTN_RIGHT;
 		else
@@ -667,12 +694,9 @@ touchpad_init(struct touchpad_dispatch *touchpad,
 	struct weston_motion_filter *accel;
 	struct wl_event_loop *loop;
 
-	unsigned long prop_bits[INPUT_PROP_MAX];
 	struct input_absinfo absinfo;
 	unsigned long abs_bits[NBITS(ABS_MAX)];
 
-	bool has_buttonpad;
-
 	double width;
 	double height;
 	double diagonal;
@@ -682,9 +706,7 @@ touchpad_init(struct touchpad_dispatch *touchpad,
 
 	/* Detect model */
 	touchpad->model = get_touchpad_model(device);
-
-	ioctl(device->fd, EVIOCGPROP(sizeof(prop_bits)), prop_bits);
-	has_buttonpad = TEST_BIT(prop_bits, INPUT_PROP_BUTTONPAD);
+	configure_interaction_model(touchpad);
 
 	/* Configure pressure */
 	ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), abs_bits);
@@ -746,7 +768,6 @@ touchpad_init(struct touchpad_dispatch *touchpad,
 	}
 
 	/* Configure */
-	touchpad->fsm.enable = !has_buttonpad;
 
 	return 0;
 }
-- 
1.8.3.2



More information about the wayland-devel mailing list