From 5337eda2429702af5f8330de2e326228469e68b8 Mon Sep 17 00:00:00 2001 From: Johan Malm Date: Fri, 29 Dec 2023 19:50:37 +0000 Subject: [PATCH] config: remove duplication in libinput-category parsing Related-to: #1382 --- include/config/libinput.h | 3 +++ src/config/libinput.c | 7 +++++-- src/config/rcxml.c | 19 +++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/config/libinput.h b/include/config/libinput.h index 83d512e4..d05b8489 100644 --- a/include/config/libinput.h +++ b/include/config/libinput.h @@ -7,6 +7,9 @@ #include enum device_type { + LAB_LIBINPUT_DEVICE_NONE = 0, + + // FIXME: Rename the entries below with a LAB_LIBINPUT_ prefix DEFAULT_DEVICE, TOUCH_DEVICE, TOUCHPAD_DEVICE, diff --git a/src/config/libinput.c b/src/config/libinput.c index 8a447582..e55e990b 100644 --- a/src/config/libinput.c +++ b/src/config/libinput.c @@ -26,7 +26,10 @@ libinput_category_init(struct libinput_category *l) enum device_type get_device_type(const char *s) { - if (!s) { + if (!s || !*s) { + return LAB_LIBINPUT_DEVICE_NONE; + } + if (!strcasecmp(s, "default")) { return DEFAULT_DEVICE; } if (!strcasecmp(s, "touch")) { @@ -38,7 +41,7 @@ get_device_type(const char *s) if (!strcasecmp(s, "non-touch")) { return NON_TOUCH_DEVICE; } - return DEFAULT_DEVICE; + return LAB_LIBINPUT_DEVICE_NONE; } struct libinput_category * diff --git a/src/config/rcxml.c b/src/config/rcxml.c index f1a9c110..c57352a4 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -460,12 +460,19 @@ fill_libinput_category(char *nodename, char *content) string_truncate_at_pattern(nodename, ".device.libinput"); if (!strcmp(nodename, "category")) { - if (!strcmp(content, "touch") - || !strcmp(content, "touchpad") - || !strcmp(content, "non-touch") - || !strcmp(content, "default")) { - current_libinput_category->type = get_device_type(content); - } else { + /* + * First we try to get a type based on a number of pre-defined + * terms, for example: 'default', 'touch', 'touchpad' and + * 'non-touch' + */ + current_libinput_category->type = get_device_type(content); + + /* + * If we couldn't match against any of those terms, we use the + * provided value to define the device name that the settings + * should be applicable to. + */ + if (current_libinput_category->type == LAB_LIBINPUT_DEVICE_NONE) { current_libinput_category->name = xstrdup(content); } } else if (!strcasecmp(nodename, "naturalScroll")) {