[PATCH libinput] fallback: allow for multiple keyboards to toggle the lid switch

Peter Hutterer peter.hutterer at who-t.net
Wed Sep 20 04:53:01 UTC 2017


Previously we only listened for events on the first one to come up, based on
the assumption that there can only be one internal keyboard. The Razer Blade
laptop keyboards come with with multiple event nodes, all looking like a
normal keyboard. The one that comes up first is one for special keys, so
typing on the internal keyboard after a lid switch does not toggle the write
state.

Fix this by allowing for up to 3 keyboard listeners for a lid switch.

https://bugs.freedesktop.org/show_bug.cgi?id=102039

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 meson.build                                        |   2 +
 src/evdev.c                                        |  91 ++++--
 src/evdev.h                                        |  14 +-
 ...vice-keyboard-razer-blade-stealth-videoswitch.c | 228 ++++++++++++++
 test/litest-device-keyboard-razer-blade-stealth.c  | 347 +++++++++++++++++++++
 test/litest.c                                      |   4 +
 test/litest.h                                      |   2 +
 test/test-switch.c                                 |  57 ++++
 udev/90-libinput-model-quirks.hwdb                 |   9 +
 9 files changed, 728 insertions(+), 26 deletions(-)
 create mode 100644 test/litest-device-keyboard-razer-blade-stealth-videoswitch.c
 create mode 100644 test/litest-device-keyboard-razer-blade-stealth.c

diff --git a/meson.build b/meson.build
index 41381553..0e196f5a 100644
--- a/meson.build
+++ b/meson.build
@@ -544,6 +544,8 @@ if get_option('tests')
 		'test/litest-device-keyboard.c',
 		'test/litest-device-keyboard-all-codes.c',
 		'test/litest-device-keyboard-razer-blackwidow.c',
+		'test/litest-device-keyboard-razer-blade-stealth.c',
+		'test/litest-device-keyboard-razer-blade-stealth-videoswitch.c',
 		'test/litest-device-lid-switch.c',
 		'test/litest-device-lid-switch-surface3.c',
 		'test/litest-device-logitech-trackball.c',
diff --git a/src/evdev.c b/src/evdev.c
index 63cad8a9..ffe2f8d7 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -1155,22 +1155,38 @@ fallback_lid_keyboard_event(uint64_t time,
 
 static void
 fallback_lid_toggle_keyboard_listener(struct fallback_dispatch *dispatch,
+				      struct paired_keyboard *kbd,
 				      bool is_closed)
 {
-	if (!dispatch->lid.keyboard)
-		return;
+	assert(kbd->device);
 
 	if (is_closed) {
 		libinput_device_add_event_listener(
-					&dispatch->lid.keyboard->base,
-					&dispatch->lid.listener,
+					&kbd->device->base,
+					&kbd->listener,
 					fallback_lid_keyboard_event,
 					dispatch);
 	} else {
 		libinput_device_remove_event_listener(
-					&dispatch->lid.listener);
+					&kbd->listener);
 		libinput_device_init_event_listener(
-					&dispatch->lid.listener);
+					&kbd->listener);
+	}
+}
+
+static void
+fallback_lid_toggle_keyboard_listeners(struct fallback_dispatch *dispatch,
+				       bool is_closed)
+{
+	struct paired_keyboard *kbd;
+
+	ARRAY_FOR_EACH(dispatch->lid.paired_keyboard, kbd) {
+		if (!kbd->device)
+			continue;
+
+		fallback_lid_toggle_keyboard_listener(dispatch,
+						      kbd,
+						      is_closed);
 	}
 }
 
@@ -1189,7 +1205,8 @@ fallback_process_switch(struct fallback_dispatch *dispatch,
 
 		if (dispatch->lid.is_closed == is_closed)
 			return;
-		fallback_lid_toggle_keyboard_listener(dispatch, is_closed);
+
+		fallback_lid_toggle_keyboard_listeners(dispatch, is_closed);
 
 		dispatch->lid.is_closed = is_closed;
 		fallback_lid_notify_toggle(dispatch, device, time);
@@ -1560,11 +1577,14 @@ static void
 fallback_remove(struct evdev_dispatch *evdev_dispatch)
 {
 	struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
+	struct paired_keyboard *kbd;
 
-	if (!dispatch->lid.keyboard)
-		return;
+	ARRAY_FOR_EACH(dispatch->lid.paired_keyboard, kbd) {
+		if (!kbd->device)
+			continue;
 
-	libinput_device_remove_event_listener(&dispatch->lid.listener);
+		libinput_device_remove_event_listener(&kbd->listener);
+	}
 }
 
 static void
@@ -1678,27 +1698,41 @@ fallback_lid_pair_keyboard(struct evdev_device *lid_switch,
 {
 	struct fallback_dispatch *dispatch =
 		fallback_dispatch(lid_switch->dispatch);
+	struct paired_keyboard *kbd;
+	bool paired = false;
+
 
 	if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0 ||
 	    (lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0)
 		return;
 
-	if (dispatch->lid.keyboard)
+	if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0)
 		return;
 
-	if (keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) {
-		dispatch->lid.keyboard = keyboard;
+	ARRAY_FOR_EACH(dispatch->lid.paired_keyboard, kbd) {
+		if (kbd->device)
+			continue;
+
+		kbd->device = keyboard;
 		evdev_log_debug(lid_switch,
 				"lid: keyboard paired with %s<->%s\n",
 				lid_switch->devname,
 				keyboard->devname);
 
-		/* We need to init the event listener now only if the reported state
-		 * is closed. */
+		/* We need to init the event listener now only if the
+		 * reported state is closed. */
 		if (dispatch->lid.is_closed)
-			fallback_lid_toggle_keyboard_listener(dispatch,
-						    dispatch->lid.is_closed);
+			fallback_lid_toggle_keyboard_listener(
+					      dispatch,
+					      kbd,
+					      dispatch->lid.is_closed);
+		paired = true;
+		break;
 	}
+
+	if (!paired)
+		evdev_log_bug_libinput(lid_switch,
+				       "lid: too many internal keyboards\n");
 }
 
 static void
@@ -1714,13 +1748,18 @@ fallback_interface_device_removed(struct evdev_device *device,
 {
 	struct fallback_dispatch *dispatch =
 			fallback_dispatch(device->dispatch);
+	struct paired_keyboard *kbd;
 
-	if (removed_device == dispatch->lid.keyboard) {
-		libinput_device_remove_event_listener(
-					&dispatch->lid.listener);
-		libinput_device_init_event_listener(
-					&dispatch->lid.listener);
-		dispatch->lid.keyboard = NULL;
+	ARRAY_FOR_EACH(dispatch->lid.paired_keyboard, kbd) {
+		if (!kbd->device)
+			continue;
+
+		if (kbd->device != removed_device)
+			continue;
+
+		libinput_device_remove_event_listener(&kbd->listener);
+		libinput_device_init_event_listener(&kbd->listener);
+		kbd->device = NULL;
 	}
 }
 
@@ -2233,7 +2272,11 @@ fallback_dispatch_init_switch(struct fallback_dispatch *dispatch,
 	int val;
 
 	if (device->tags & EVDEV_TAG_LID_SWITCH) {
-		libinput_device_init_event_listener(&dispatch->lid.listener);
+		struct paired_keyboard *kbd;
+
+		ARRAY_FOR_EACH(dispatch->lid.paired_keyboard, kbd)
+			libinput_device_init_event_listener(&kbd->listener);
+
 		dispatch->lid.reliability = evdev_read_switch_reliability_prop(device);
 		dispatch->lid.is_closed = false;
 	}
diff --git a/src/evdev.h b/src/evdev.h
index 5192927c..04a827fb 100644
--- a/src/evdev.h
+++ b/src/evdev.h
@@ -403,8 +403,18 @@ struct fallback_dispatch {
 
 		bool is_closed;
 		bool is_closed_client_state;
-		struct evdev_device *keyboard;
-		struct libinput_event_listener listener;
+
+		/* We allow up to 3 paired keyboards for the lid switch
+		 * listener. Only one keyboard should exist, but that can
+		 * have more than one event node.
+		 *
+		 * Note: this is a sparse list, any element may have a
+		 * non-NULL device.
+		 */
+		struct paired_keyboard {
+			struct evdev_device *device;
+			struct libinput_event_listener listener;
+		} paired_keyboard[3];
 	} lid;
 };
 
diff --git a/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c b/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c
new file mode 100644
index 00000000..77483f98
--- /dev/null
+++ b/test/litest-device-keyboard-razer-blade-stealth-videoswitch.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "litest.h"
+#include "litest-int.h"
+
+/* Recording from https://bugs.freedesktop.org/show_bug.cgi?id=102039
+ * This is the 'video switch' of 2 devices exported by this keyboard.
+ */
+static void litest_blade_stealth_setup(void)
+{
+	struct litest_device *d;
+
+	d = litest_create_device(LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH);
+	litest_set_current_device(d);
+}
+
+static struct input_id input_id = {
+	.bustype = 0x3,
+	.vendor = 0x1532,
+	.product = 0x220,
+};
+
+static int events[] = {
+	EV_KEY, KEY_ESC,
+	EV_KEY, KEY_1,
+	EV_KEY, KEY_2,
+	EV_KEY, KEY_3,
+	EV_KEY, KEY_4,
+	EV_KEY, KEY_5,
+	EV_KEY, KEY_6,
+	EV_KEY, KEY_7,
+	EV_KEY, KEY_8,
+	EV_KEY, KEY_9,
+	EV_KEY, KEY_0,
+	EV_KEY, KEY_MINUS,
+	EV_KEY, KEY_EQUAL,
+	EV_KEY, KEY_BACKSPACE,
+	EV_KEY, KEY_TAB,
+	EV_KEY, KEY_Q,
+	EV_KEY, KEY_W,
+	EV_KEY, KEY_E,
+	EV_KEY, KEY_R,
+	EV_KEY, KEY_T,
+	EV_KEY, KEY_Y,
+	EV_KEY, KEY_U,
+	EV_KEY, KEY_I,
+	EV_KEY, KEY_O,
+	EV_KEY, KEY_P,
+	EV_KEY, KEY_LEFTBRACE,
+	EV_KEY, KEY_RIGHTBRACE,
+	EV_KEY, KEY_ENTER,
+	EV_KEY, KEY_LEFTCTRL,
+	EV_KEY, KEY_A,
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KEY, KEY_COFFEE,
+	EV_KEY, KEY_BACK,
+	EV_KEY, KEY_FORWARD,
+	EV_KEY, KEY_EJECTCD,
+	EV_KEY, KEY_NEXTSONG,
+	EV_KEY, KEY_PLAYPAUSE,
+	EV_KEY, KEY_PREVIOUSSONG,
+	EV_KEY, KEY_STOPCD,
+	EV_KEY, KEY_REFRESH,
+	EV_KEY, KEY_EDIT,
+	EV_KEY, KEY_SCROLLUP,
+	EV_KEY, KEY_SCROLLDOWN,
+	EV_KEY, KEY_KPLEFTPAREN,
+	EV_KEY, KEY_KPRIGHTPAREN,
+	EV_KEY, KEY_F13,
+	EV_KEY, KEY_F14,
+	EV_KEY, KEY_F15,
+	EV_KEY, KEY_F16,
+	EV_KEY, KEY_F17,
+	EV_KEY, KEY_F18,
+	EV_KEY, KEY_F19,
+	EV_KEY, KEY_F20,
+	EV_KEY, KEY_F21,
+	EV_KEY, KEY_F22,
+	EV_KEY, KEY_F23,
+	EV_KEY, KEY_F24,
+	EV_KEY, KEY_UNKNOWN,
+	EV_LED, LED_NUML,
+	EV_LED, LED_CAPSL,
+	EV_LED, LED_SCROLLL,
+	EV_MSC, MSC_SCAN,
+	-1 , -1,
+};
+
+struct litest_test_device litest_keyboard_blade_stealth_device_video = {
+	.type = LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH,
+	.features = LITEST_KEYS,
+	.shortname = "blade-stealth-video-switch",
+	.setup = litest_blade_stealth_setup,
+	.interface = NULL,
+
+	.name = "Razer Razer Blade Stealth",
+	.id = &input_id,
+	.events = events,
+};
+
diff --git a/test/litest-device-keyboard-razer-blade-stealth.c b/test/litest-device-keyboard-razer-blade-stealth.c
new file mode 100644
index 00000000..9565f116
--- /dev/null
+++ b/test/litest-device-keyboard-razer-blade-stealth.c
@@ -0,0 +1,347 @@
+/*
+ * Copyright © 2017 Red Hat, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+
+#include "config.h"
+
+#include "litest.h"
+#include "litest-int.h"
+
+/* Recording from https://bugs.freedesktop.org/show_bug.cgi?id=102039
+ * This is the 'normal keyboard' of 2 devices exported by this keyboard.
+ */
+static void litest_blade_stealth_setup(void)
+{
+	struct litest_device *d = litest_create_device(LITEST_KEYBOARD_BLADE_STEALTH);
+	litest_set_current_device(d);
+}
+
+static struct input_id input_id = {
+	.bustype = 0x3,
+	.vendor = 0x1532,
+	.product = 0x220,
+};
+
+static int events[] = {
+	EV_REL, REL_HWHEEL,
+	EV_KEY, BTN_0,
+	EV_KEY, KEY_ESC,
+	EV_KEY, KEY_1,
+	EV_KEY, KEY_2,
+	EV_KEY, KEY_3,
+	EV_KEY, KEY_4,
+	EV_KEY, KEY_5,
+	EV_KEY, KEY_6,
+	EV_KEY, KEY_7,
+	EV_KEY, KEY_8,
+	EV_KEY, KEY_9,
+	EV_KEY, KEY_0,
+	EV_KEY, KEY_MINUS,
+	EV_KEY, KEY_EQUAL,
+	EV_KEY, KEY_BACKSPACE,
+	EV_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EY_SHUFFLE,
+	EV_KEY, KEY_PREVIOUS,
+	EV_KEY, KEY_VIDEOPHONE,
+	EV_KEY, KEY_GAMES,
+	EV_KEY, KEY_ZOOMIN,
+	EV_KEY, KEY_ZOOMOUT,
+	EV_KEY, KEY_ZOOMRESET,
+	EV_KEY, KEY_WORDPROCESSOR,
+	EV_KEY, KEY_EDITOR,
+	EV_KEY, KEY_SPREADSHEET,
+	EV_KEY, KEY_GRAPHICSEDITOR,
+	EV_KEY, KEY_PRESENTATION,
+	EV_KEY, KEY_DATABASE,
+	EV_KEY, KEY_NEWS,
+	EV_KEY, KEY_VOICEMAIL,
+	EV_KEY, KEY_ADDRESSBOOK,
+	EV_KEY, KEY_MESSENGER,
+	EV_KEY, KEY_DISPLAYTOGGLE,
+	EV_KEY, KEY_SPELLCHECK,
+	EV_KEY, KEY_LOGOFF,
+	EV_KEY, KEY_MEDIA_REPEAT,
+	EV_KEY, KEY_IMAGES,
+	EV_KEY, KEY_BUTTONCONFIG,
+	EV_KEY, KEY_TASKMANAGER,
+	EV_KEY, KEY_JOURNAL,
+	EV_KEY, KEY_CONTROLPANEL,
+	EV_KEY, KEY_APPSELECT,
+	EV_KEY, KEY_SCREENSAVER,
+	EV_KEY, KEY_VOICECOMMAND,
+	EV_KEY, KEY_BRIGHTNESS_MIN,
+	EV_KEY, KEY_BRIGHTNESS_MAX,
+	EV_MSC, MSC_SCAN,
+	-1 , -1,
+};
+
+static struct input_absinfo absinfo[] = {
+	{ ABS_VOLUME, 0, 572, 0, 0, 0 },
+	{ ABS_MISC, 0, 255, 0, 0, 0 },
+	{ 0x29, 0, 255, 0, 0, 0 },
+	{ 0x2a, 0, 255, 0, 0, 0 },
+	{ 0x2b, 0, 255, 0, 0, 0 },
+	{ 0x2c, 0, 255, 0, 0, 0 },
+	{ 0x2d, 0, 255, 0, 0, 0 },
+	{ 0x2e, 0, 255, 0, 0, 0 },
+	{ 0x2f, 0, 255, 0, 0, 0 },
+	{ 0x30, 0, 255, 0, 0, 0 },
+	{ 0x31, 0, 255, 0, 0, 0 },
+	{ 0x32, 0, 255, 0, 0, 0 },
+	{ 0x33, 0, 255, 0, 0, 0 },
+	{ 0x34, 0, 255, 0, 0, 0 },
+	{ 0x35, 0, 255, 0, 0, 0 },
+	{ 0x36, 0, 255, 0, 0, 0 },
+	{ 0x37, 0, 255, 0, 0, 0 },
+	{ 0x38, 0, 255, 0, 0, 0 },
+	{ 0x39, 0, 255, 0, 0, 0 },
+	{ 0x3a, 0, 255, 0, 0, 0 },
+	{ 0x3b, 0, 255, 0, 0, 0 },
+	{ 0x3c, 0, 255, 0, 0, 0 },
+	{ 0x3d, 0, 255, 0, 0, 0 },
+	{ 0x3e, 0, 255, 0, 0, 0 },
+	{ 0x3f, 0, 255, 0, 0, 0 },
+	{ .value = -1 },
+};
+
+struct litest_test_device litest_keyboard_blade_stealth_device = {
+	.type = LITEST_KEYBOARD_BLADE_STEALTH,
+	.features = LITEST_KEYS | LITEST_WHEEL,
+	.shortname = "blade_stealth",
+	.setup = litest_blade_stealth_setup,
+	.interface = NULL,
+
+	.name = "Razer Razer Blade Stealth",
+	.id = &input_id,
+	.absinfo = absinfo,
+	.events = events,
+};
+
diff --git a/test/litest.c b/test/litest.c
index 1f238431..f28e0166 100644
--- a/test/litest.c
+++ b/test/litest.c
@@ -418,6 +418,8 @@ extern struct litest_test_device litest_gpio_keys_device;
 extern struct litest_test_device litest_ignored_mouse_device;
 extern struct litest_test_device litest_wacom_mobilestudio_13hdt_pad_device;
 extern struct litest_test_device litest_thinkpad_extrabuttons_device;
+extern struct litest_test_device litest_keyboard_blade_stealth_device;
+extern struct litest_test_device litest_keyboard_blade_stealth_device_video;
 
 struct litest_test_device* devices[] = {
 	&litest_synaptics_clickpad_device,
@@ -487,6 +489,8 @@ struct litest_test_device* devices[] = {
 	&litest_ignored_mouse_device,
 	&litest_wacom_mobilestudio_13hdt_pad_device,
 	&litest_thinkpad_extrabuttons_device,
+	&litest_keyboard_blade_stealth_device,
+	&litest_keyboard_blade_stealth_device_video,
 	NULL,
 };
 
diff --git a/test/litest.h b/test/litest.h
index 679406dc..e05c238c 100644
--- a/test/litest.h
+++ b/test/litest.h
@@ -238,6 +238,8 @@ enum litest_device_type {
 	LITEST_IGNORED_MOUSE,
 	LITEST_WACOM_MOBILESTUDIO_PRO_16_PAD,
 	LITEST_THINKPAD_EXTRABUTTONS,
+	LITEST_KEYBOARD_BLADE_STEALTH,
+	LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH,
 };
 
 enum litest_device_feature {
diff --git a/test/test-switch.c b/test/test-switch.c
index 7cdcf440..c306305b 100644
--- a/test/test-switch.c
+++ b/test/test-switch.c
@@ -754,6 +754,62 @@ START_TEST(lid_update_hw_on_key_closed_on_init)
 }
 END_TEST
 
+START_TEST(lid_update_hw_on_key_multiple_keyboards)
+{
+	struct litest_device *sw = litest_current_device();
+	struct libinput *li = sw->libinput;
+	struct libinput *li2;
+	struct litest_device *keyboard1, *keyboard2;
+	struct libinput_event *event;
+
+	if (!switch_has_lid(sw))
+		return;
+
+	keyboard1 = litest_add_device(li,
+				LITEST_KEYBOARD_BLADE_STEALTH_VIDEOSWITCH);
+	libinput_dispatch(li);
+
+	keyboard2 = litest_add_device(li, LITEST_KEYBOARD_BLADE_STEALTH);
+	libinput_dispatch(li);
+
+	/* separate context to listen to the fake hw event */
+	li2 = litest_create_context();
+	libinput_path_add_device(li2,
+				 libevdev_uinput_get_devnode(sw->uinput));
+	litest_drain_events(li2);
+
+	litest_switch_action(sw,
+			     LIBINPUT_SWITCH_LID,
+			     LIBINPUT_SWITCH_STATE_ON);
+	litest_drain_events(li);
+
+	libinput_dispatch(li2);
+	event = libinput_get_event(li2);
+	litest_is_switch_event(event,
+			       LIBINPUT_SWITCH_LID,
+			       LIBINPUT_SWITCH_STATE_ON);
+	libinput_event_destroy(event);
+
+	litest_event(keyboard2, EV_KEY, KEY_A, 1);
+	litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
+	litest_event(keyboard2, EV_KEY, KEY_A, 0);
+	litest_event(keyboard2, EV_SYN, SYN_REPORT, 0);
+	litest_drain_events(li);
+
+	libinput_dispatch(li2);
+	event = libinput_get_event(li2);
+	litest_is_switch_event(event,
+			       LIBINPUT_SWITCH_LID,
+			       LIBINPUT_SWITCH_STATE_OFF);
+	libinput_event_destroy(event);
+	litest_assert_empty_queue(li2);
+
+	libinput_unref(li2);
+	litest_delete_device(keyboard1);
+	litest_delete_device(keyboard2);
+}
+END_TEST
+
 START_TEST(lid_key_press)
 {
 	struct litest_device *sw = litest_current_device();
@@ -836,6 +892,7 @@ litest_setup_tests_lid(void)
 	litest_add("lid:keyboard", lid_open_on_key_touchpad_enabled, LITEST_SWITCH, LITEST_ANY);
 	litest_add_for_device("lid:buggy", lid_update_hw_on_key, LITEST_LID_SWITCH_SURFACE3);
 	litest_add_for_device("lid:buggy", lid_update_hw_on_key_closed_on_init, LITEST_LID_SWITCH_SURFACE3);
+	litest_add_for_device("lid:buggy", lid_update_hw_on_key_multiple_keyboards, LITEST_LID_SWITCH_SURFACE3);
 	litest_add_for_device("lid:keypress", lid_key_press, LITEST_GPIO_KEYS);
 
 	litest_add("tablet-mode:touchpad", tablet_mode_disable_touchpad_on_init, LITEST_SWITCH, LITEST_ANY);
diff --git a/udev/90-libinput-model-quirks.hwdb b/udev/90-libinput-model-quirks.hwdb
index 72fcdca1..46c28085 100644
--- a/udev/90-libinput-model-quirks.hwdb
+++ b/udev/90-libinput-model-quirks.hwdb
@@ -212,6 +212,15 @@ libinput:name:*Microsoft Surface Type Cover Keyboard*:dmi:*svnMicrosoftCorporati
  LIBINPUT_ATTR_KEYBOARD_INTEGRATION=internal
 
 ##########################################
+# Razer
+##########################################
+libinput:keyboard:input:b0003v1532p0220*
+ LIBINPUT_ATTR_KEYBOARD_INTEGRATION=internal
+
+libinput:name:*Lid Switch*:dmi:*svnRazer:pnBlade*
+ LIBINPUT_ATTR_LID_SWITCH_RELIABILITY=write_open
+
+##########################################
 # Synaptics
 ##########################################
 libinput:touchpad:input:b0011v0002p0007*
-- 
2.13.5



More information about the wayland-devel mailing list