[PATCH libinput 03/14] Pair touchpad and lid_switch for disable

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


From: James Ye <jye836 at gmail.com>

Add listener for lid switch events, disable touchpad on switch event.

Signed-off-by: James Ye <jye836 at gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer at who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 src/evdev-mt-touchpad.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/evdev-mt-touchpad.h |  5 +++++
 2 files changed, 54 insertions(+)

diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 56822df..6e2818c 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -1176,6 +1176,10 @@ tp_remove_sendevents(struct tp_dispatch *tp)
 	if (tp->dwt.keyboard)
 		libinput_device_remove_event_listener(
 					&tp->dwt.keyboard_listener);
+
+	if (tp->lid_switch.lid_switch)
+		libinput_device_remove_event_listener(
+					&tp->lid_switch.lid_switch_listener);
 }
 
 static void
@@ -1553,6 +1557,50 @@ tp_pair_trackpoint(struct evdev_device *touchpad,
 }
 
 static void
+tp_lid_switch_event(uint64_t time, struct libinput_event *event, void *data)
+{
+	struct tp_dispatch *tp = data;
+	struct libinput_event_switch *swev;
+
+	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;
+		}
+	}
+}
+
+static void
+tp_pair_lid_switch(struct evdev_device *touchpad,
+		   struct evdev_device *lid_switch)
+{
+	struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
+
+	if ((lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0)
+		return;
+
+	if (tp->lid_switch.lid_switch == NULL) {
+		log_debug(tp_libinput_context(tp),
+			  "lid_switch: activated for %s<->%s\n",
+			  touchpad->devname,
+			  lid_switch->devname);
+
+		libinput_device_add_event_listener(&lid_switch->base,
+					&tp->lid_switch.lid_switch_listener,
+					tp_lid_switch_event, tp);
+		tp->lid_switch.lid_switch = lid_switch;
+	}
+}
+
+static void
 tp_interface_device_added(struct evdev_device *device,
 			  struct evdev_device *added_device)
 {
@@ -1560,6 +1608,7 @@ tp_interface_device_added(struct evdev_device *device,
 
 	tp_pair_trackpoint(device, added_device);
 	tp_dwt_pair_keyboard(device, added_device);
+	tp_pair_lid_switch(device, added_device);
 
 	if (tp->sendevents.current_mode !=
 	    LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE)
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index fb15956..8ae1bf9 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -376,6 +376,11 @@ struct tp_dispatch {
 		 */
 		unsigned int nonmotion_event_count;
 	} quirks;
+
+	struct {
+		struct libinput_event_listener lid_switch_listener;
+		struct evdev_device *lid_switch;
+	} lid_switch;
 };
 
 #define tp_for_each_touch(_tp, _t) \
-- 
2.9.3



More information about the wayland-devel mailing list