[PATCH libevdev 3/4] Blacklist SW_MAX so it doesn't shadow SW_PEN_INSERTED

Peter Hutterer peter.hutterer at who-t.net
Mon Feb 26 07:13:31 UTC 2018


They have the same value, so the _MAX code would shadow the real code, causing
issues in any client that needs to get all event names from libevdev.
Specifically, the loop of:
  for each code in 0 to max-for-type:
      print(name)
would not show up the code (but the _MAX) code instead. This causes issues
with clients that rely on name resolution that works. And the _MAX values are
special values anyway.

Blacklist it in the script here, causing it to resolve from name to code, but
not from code to name (like other duplicated codes).

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
---
 libevdev/make-event-names.py | 1 +
 test/test-event-codes.c      | 2 +-
 test/test-event-names.c      | 3 ++-
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/libevdev/make-event-names.py b/libevdev/make-event-names.py
index 8ec8858..44e1685 100755
--- a/libevdev/make-event-names.py
+++ b/libevdev/make-event-names.py
@@ -36,6 +36,7 @@ blacklist = [
 		"BTN_DIGI",
 		"BTN_WHEEL",
 		"BTN_TRIGGER_HAPPY",
+		"SW_MAX",
 		"REP_MAX",
 ]
 
diff --git a/test/test-event-codes.c b/test/test-event-codes.c
index b64940e..80f277b 100644
--- a/test/test-event-codes.c
+++ b/test/test-event-codes.c
@@ -72,7 +72,7 @@ START_TEST(test_key_codes)
 	ck_assert_int_eq(libevdev_event_code_from_name(EV_KEY, "KEY_0"), KEY_0);
 	ck_assert_int_eq(libevdev_event_code_from_name(EV_FF, "FF_GAIN"), FF_GAIN);
 	ck_assert_int_eq(libevdev_event_code_from_name(EV_FF_STATUS, "FF_STATUS_MAX"), FF_STATUS_MAX);
-	ck_assert_int_eq(libevdev_event_code_from_name(EV_SW, "SW_MAX"), SW_MAX);
+	ck_assert_int_eq(libevdev_event_code_from_name(EV_SW, "SW_PEN_INSERTED"), SW_PEN_INSERTED);
 
 	ck_assert_int_eq(libevdev_event_code_from_name_n(EV_ABS, "ABS_YXZ", 5), ABS_Y);
 }
diff --git a/test/test-event-names.c b/test/test-event-names.c
index b7d5567..4807dec 100644
--- a/test/test-event-names.c
+++ b/test/test-event-names.c
@@ -173,7 +173,8 @@ START_TEST(test_code_sw_name)
 	ck_assert_str_eq(libevdev_event_code_get_name(EV_SW, SW_LID), "SW_LID");
 	ck_assert_str_eq(libevdev_event_code_get_name(EV_SW, SW_RFKILL_ALL), "SW_RFKILL_ALL");
 	ck_assert_str_eq(libevdev_event_code_get_name(EV_SW, SW_LINEIN_INSERT), "SW_LINEIN_INSERT");
-	ck_assert_str_eq(libevdev_event_code_get_name(EV_SW, SW_MAX), "SW_MAX");
+	ck_assert_str_eq(libevdev_event_code_get_name(EV_SW, SW_PEN_INSERTED), "SW_PEN_INSERTED");
+	ck_assert_str_eq(libevdev_event_code_get_name(EV_SW, SW_MAX), "SW_PEN_INSERTED");
 }
 END_TEST
 
-- 
2.14.3



More information about the Input-tools mailing list