]> git.mdlowis.com Git - proto/labwc.git/commitdiff
config: remove duplication in libinput-category parsing
authorJohan Malm <jgm323@gmail.com>
Fri, 29 Dec 2023 19:50:37 +0000 (19:50 +0000)
committerJohan Malm <johanmalm@users.noreply.github.com>
Mon, 1 Jan 2024 22:04:21 +0000 (22:04 +0000)
Related-to: #1382
include/config/libinput.h
src/config/libinput.c
src/config/rcxml.c

index 83d512e4ab0e8c9ee67c2a357a0a41c84b0d90af..d05b84890dfb3431f582a092e0b144a3521d0e33 100644 (file)
@@ -7,6 +7,9 @@
 #include <wayland-server-core.h>
 
 enum device_type {
+       LAB_LIBINPUT_DEVICE_NONE = 0,
+
+       // FIXME: Rename the entries below with a LAB_LIBINPUT_ prefix
        DEFAULT_DEVICE,
        TOUCH_DEVICE,
        TOUCHPAD_DEVICE,
index 8a447582ab75456304fcba822d3f66bf7231e158..e55e990b3e3ad8421707712b50b574f6cee4a7f4 100644 (file)
@@ -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 *
index f1a9c1100a854d2ba6ad2c94a044ed86357d6478..c57352a483416f7ec3c271e3f5ea19e90adc7747 100644 (file)
@@ -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")) {