[PATCH 1/8] evdev-touchpad: Replaced flags with boolean variabes

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


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

...and put them inside hw_abs, because they will need to be made
per-touch-point later.
---
 src/evdev-touchpad.c | 78 +++++++++++++++++++++-------------------------------
 1 file changed, 32 insertions(+), 46 deletions(-)

diff --git a/src/evdev-touchpad.c b/src/evdev-touchpad.c
index 53300ce..35be921 100644
--- a/src/evdev-touchpad.c
+++ b/src/evdev-touchpad.c
@@ -48,14 +48,6 @@ enum touchpad_model {
 	TOUCHPAD_MODEL_ELANTECH
 };
 
-enum touchpad_event {
-	TOUCHPAD_EVENT_NONE	    = 0,
-	TOUCHPAD_EVENT_ABSOLUTE_ANY = (1 << 0),
-	TOUCHPAD_EVENT_ABSOLUTE_X   = (1 << 1),
-	TOUCHPAD_EVENT_ABSOLUTE_Y   = (1 << 2),
-	TOUCHPAD_EVENT_REPORT	    = (1 << 3)
-};
-
 struct touchpad_model_spec {
 	short vendor;
 	short product;
@@ -70,12 +62,6 @@ static struct touchpad_model_spec touchpad_spec_table[] = {
 	{0x0000, 0x0000, TOUCHPAD_MODEL_UNKNOWN}
 };
 
-enum touchpad_state {
-	TOUCHPAD_STATE_NONE  = 0,
-	TOUCHPAD_STATE_TOUCH = (1 << 0),
-	TOUCHPAD_STATE_MOVE  = (1 << 1)
-};
-
 #define TOUCHPAD_HISTORY_LENGTH 4
 
 struct touchpad_motion {
@@ -109,7 +95,6 @@ struct touchpad_dispatch {
 	struct evdev_device *device;
 
 	enum touchpad_model model;
-	unsigned int state;
 	int finger_state;
 	int last_finger_state;
 
@@ -117,9 +102,6 @@ struct touchpad_dispatch {
 	double min_accel_factor;
 	double max_accel_factor;
 
-	unsigned int event_mask;
-	unsigned int event_mask_filter;
-
 	int reset;
 
 	struct {
@@ -133,6 +115,13 @@ struct touchpad_dispatch {
 	struct {
 		int32_t x;
 		int32_t y;
+
+		bool x_valid;
+		bool y_valid;
+
+		bool has_moved;
+		bool is_moving;
+		bool is_pressed;
 	} hw_abs;
 
 	int has_pressure;
@@ -432,9 +421,9 @@ touchpad_update_state(struct touchpad_dispatch *touchpad, uint32_t time)
 	    touchpad->last_finger_state != touchpad->finger_state) {
 		touchpad->reset = 0;
 		touchpad->motion_count = 0;
-		touchpad->event_mask = TOUCHPAD_EVENT_NONE;
-		touchpad->event_mask_filter =
-			TOUCHPAD_EVENT_ABSOLUTE_X | TOUCHPAD_EVENT_ABSOLUTE_Y;
+		touchpad->hw_abs.x_valid = touchpad->hw_abs.y_valid = false;
+		touchpad->hw_abs.is_moving = false;
+		/* XXX what about is_pressed? */
 
 		touchpad->last_finger_state = touchpad->finger_state;
 
@@ -444,18 +433,12 @@ touchpad_update_state(struct touchpad_dispatch *touchpad, uint32_t time)
 	}
 	touchpad->last_finger_state = touchpad->finger_state;
 
-	if (!(touchpad->event_mask & TOUCHPAD_EVENT_REPORT))
+	if (!touchpad->hw_abs.x_valid || !touchpad->hw_abs.y_valid)
 		return;
-	else
-		touchpad->event_mask &= ~TOUCHPAD_EVENT_REPORT;
 
-	if ((touchpad->event_mask & touchpad->event_mask_filter) !=
-	    touchpad->event_mask_filter)
+	if (!touchpad->hw_abs.is_moving)
 		return;
 
-	touchpad->event_mask_filter = TOUCHPAD_EVENT_ABSOLUTE_ANY;
-	touchpad->event_mask = 0;
-
 	/* Avoid noice by moving center only when delta reaches a threshold
 	 * distance from the old center. */
 	if (touchpad->motion_count > 0) {
@@ -506,9 +489,9 @@ touchpad_update_state(struct touchpad_dispatch *touchpad, uint32_t time)
 		}
 	}
 
-	if (!(touchpad->state & TOUCHPAD_STATE_MOVE) &&
+	if (!touchpad->hw_abs.has_moved &&
 	    ((int)dx || (int)dy)) {
-		touchpad->state |= TOUCHPAD_STATE_MOVE;
+		touchpad->hw_abs.has_moved = true;
 		push_fsm_event(touchpad, FSM_EVENT_MOTION);
 	}
 
@@ -518,7 +501,7 @@ touchpad_update_state(struct touchpad_dispatch *touchpad, uint32_t time)
 static void
 on_touch(struct touchpad_dispatch *touchpad)
 {
-	touchpad->state |= TOUCHPAD_STATE_TOUCH;
+	touchpad->hw_abs.is_pressed = true;
 
 	push_fsm_event(touchpad, FSM_EVENT_TOUCH);
 }
@@ -527,8 +510,8 @@ static void
 on_release(struct touchpad_dispatch *touchpad)
 {
 
+	touchpad->hw_abs.has_moved = touchpad->hw_abs.is_pressed = false;
 	touchpad->reset = 1;
-	touchpad->state &= ~(TOUCHPAD_STATE_MOVE | TOUCHPAD_STATE_TOUCH);
 
 	push_fsm_event(touchpad, FSM_EVENT_RELEASE);
 }
@@ -541,25 +524,25 @@ process_absolute(struct touchpad_dispatch *touchpad,
 	switch (e->code) {
 	case ABS_PRESSURE:
 		if (e->value > touchpad->pressure.touch_high &&
-		    !(touchpad->state & TOUCHPAD_STATE_TOUCH))
+		    !touchpad->hw_abs.is_pressed)
 			on_touch(touchpad);
 		else if (e->value < touchpad->pressure.touch_low &&
-			 touchpad->state & TOUCHPAD_STATE_TOUCH)
+			 touchpad->hw_abs.is_pressed)
 			on_release(touchpad);
 
 		break;
 	case ABS_X:
-		if (touchpad->state & TOUCHPAD_STATE_TOUCH) {
+		if (touchpad->hw_abs.is_pressed) {
 			touchpad->hw_abs.x = e->value;
-			touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_ANY;
-			touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_X;
+			touchpad->hw_abs.x_valid = true;
+			touchpad->hw_abs.is_moving = true;
 		}
 		break;
 	case ABS_Y:
-		if (touchpad->state & TOUCHPAD_STATE_TOUCH) {
+		if (touchpad->hw_abs.is_pressed) {
 			touchpad->hw_abs.y = e->value;
-			touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_ANY;
-			touchpad->event_mask |= TOUCHPAD_EVENT_ABSOLUTE_Y;
+			touchpad->hw_abs.y_valid = true;
+			touchpad->hw_abs.is_moving = true;
 		}
 		break;
 	}
@@ -576,7 +559,7 @@ process_key(struct touchpad_dispatch *touchpad,
 	switch (e->code) {
 	case BTN_TOUCH:
 		if (!touchpad->has_pressure) {
-			if (e->value && !(touchpad->state & TOUCHPAD_STATE_TOUCH))
+			if (e->value && !touchpad->hw_abs.is_pressed)
 				on_touch(touchpad);
 			else if (!e->value)
 				on_release(touchpad);
@@ -641,7 +624,7 @@ touchpad_process(struct evdev_dispatch *dispatch,
 	switch (e->type) {
 	case EV_SYN:
 		if (e->code == SYN_REPORT)
-			touchpad->event_mask |= TOUCHPAD_EVENT_REPORT;
+			touchpad_update_state(touchpad, time);
 		break;
 	case EV_ABS:
 		process_absolute(touchpad, device, e);
@@ -650,8 +633,6 @@ touchpad_process(struct evdev_dispatch *dispatch,
 		process_key(touchpad, device, e, time);
 		break;
 	}
-
-	touchpad_update_state(touchpad, time);
 }
 
 static void
@@ -736,7 +717,12 @@ touchpad_init(struct touchpad_dispatch *touchpad,
 	touchpad->motion_index = 0;
 	touchpad->motion_count = 0;
 
-	touchpad->state = TOUCHPAD_STATE_NONE;
+	touchpad->hw_abs.x_valid = false;
+	touchpad->hw_abs.y_valid = false;
+	touchpad->hw_abs.is_pressed = false;
+	touchpad->hw_abs.is_moving = false;
+	touchpad->hw_abs.has_moved = false;
+
 	touchpad->last_finger_state = 0;
 	touchpad->finger_state = 0;
 
-- 
1.8.3.2



More information about the wayland-devel mailing list