[PATCH libinput 06/14] touchpad: check for a switch type before handling the event

Peter Hutterer peter.hutterer at who-t.net
Wed Jan 25 23:44:16 UTC 2017


Don't call get_switch_event immediately, doing so for non-switch events is
documented as a bug. Check the event type instead, if that one is correct then
we can assume the rest works.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 6e2818c..5b16645 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1562,19 +1562,19 @@ tp_lid_switch_event(uint64_t time, struct libinput_event *event, void *data)
 	struct tp_dispatch *tp = data;
 	struct libinput_event_switch *swev;
 
+	if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE)
+		return;
+
 	swev = libinput_event_get_switch_event(event);
-
-	if (swev) {
-		switch (libinput_event_switch_get_switch_state(swev)) {
-		case LIBINPUT_SWITCH_STATE_OFF:
-			tp_resume(tp, tp->device);
-			log_debug(tp_libinput_context(tp), "lid: resume touchpad\n");
-			break;
-		case LIBINPUT_SWITCH_STATE_ON:
-			tp_suspend(tp, tp->device);
-			log_debug(tp_libinput_context(tp), "lid: suspend touchpad\n");
-			break;
-		}
+	switch (libinput_event_switch_get_switch_state(swev)) {
+	case LIBINPUT_SWITCH_STATE_OFF:
+		tp_resume(tp, tp->device);
+		log_debug(tp_libinput_context(tp), "lid: resume touchpad\n");
+		break;
+	case LIBINPUT_SWITCH_STATE_ON:
+		tp_suspend(tp, tp->device);
+		log_debug(tp_libinput_context(tp), "lid: suspend touchpad\n");
+		break;
 	}
 }
 
-- 
2.9.3



More information about the wayland-devel mailing list