]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rcxml: rewrite <tablet><map> parser
authortokyo4j <hrak1529@gmail.com>
Fri, 11 Apr 2025 18:21:13 +0000 (03:21 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 30 Jul 2025 19:36:27 +0000 (20:36 +0100)
src/config/rcxml.c

index bfd9155dd127139c7d18bdb1c3c9068394f91d23..7881e7625c883f4a234b438b13cd72b99d71a9d8 100644 (file)
@@ -678,6 +678,30 @@ fill_touch(xmlNode *node)
        }
 }
 
+static void
+fill_tablet_button_map(xmlNode *node)
+{
+       uint32_t map_from;
+       uint32_t map_to;
+       char buf[256];
+
+       if (lab_xml_get_string(node, "button", buf, sizeof(buf))) {
+               map_from = tablet_button_from_str(buf);
+       } else {
+               wlr_log(WLR_ERROR, "Invalid 'button' argument for tablet button mapping");
+               return;
+       }
+
+       if (lab_xml_get_string(node, "to", buf, sizeof(buf))) {
+               map_to = mousebind_button_from_str(buf, NULL);
+       } else {
+               wlr_log(WLR_ERROR, "Invalid 'to' argument for tablet button mapping");
+               return;
+       }
+
+       tablet_button_mapping_add(map_from, map_to);
+}
+
 static int
 get_accel_profile(const char *s)
 {
@@ -1044,8 +1068,6 @@ set_tearing_mode(const char *str, enum tearing_mode *variable)
 static void
 entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
 {
-       static uint32_t button_map_from;
-
        if (!nodename) {
                return;
        }
@@ -1092,6 +1114,10 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
                fill_font(node);
                return;
        }
+       if (!strcasecmp(nodename, "map.tablet")) {
+               fill_tablet_button_map(node);
+               return;
+       }
 
        /* handle nodes without content, e.g. <keyboard><default /> */
        if (!strcmp(nodename, "default.keyboard")) {
@@ -1104,11 +1130,6 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
                return;
        }
 
-       if (!strcasecmp(nodename, "map.tablet")) {
-               button_map_from = UINT32_MAX;
-               return;
-       }
-
        if (!strcasecmp(nodename, "prefix.desktops")) {
                xstrdup_replace(rc.workspace_config.prefix, content ? content : "");
                return;
@@ -1318,17 +1339,6 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
                rc.tablet.box.width = tablet_get_dbl_if_positive(content, "width");
        } else if (!strcasecmp(nodename, "height.area.tablet")) {
                rc.tablet.box.height = tablet_get_dbl_if_positive(content, "height");
-       } else if (!strcasecmp(nodename, "button.map.tablet")) {
-               button_map_from = tablet_button_from_str(content);
-       } else if (!strcasecmp(nodename, "to.map.tablet")) {
-               if (button_map_from != UINT32_MAX) {
-                       uint32_t button_map_to = mousebind_button_from_str(content, NULL);
-                       if (button_map_to != UINT32_MAX) {
-                               tablet_button_mapping_add(button_map_from, button_map_to);
-                       }
-               } else {
-                       wlr_log(WLR_ERROR, "Missing 'button' argument for tablet button mapping");
-               }
        } else if (!strcasecmp(nodename, "motion.tabletTool")) {
                rc.tablet_tool.motion = tablet_parse_motion(content);
        } else if (!strcasecmp(nodename, "relativeMotionSensitivity.tabletTool")) {