From 73dd3b8de1f9b971b6e9e79647bb946740b2ab80 Mon Sep 17 00:00:00 2001 From: tokyo4j Date: Sat, 12 Apr 2025 01:48:11 +0900 Subject: [PATCH] rcxml: rewrite parser --- src/config/rcxml.c | 77 ++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 4d69545a..cddf8951 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -391,40 +391,51 @@ fill_window_switcher_field(char *nodename, char *content, struct parser_state *s } static void -fill_region(char *nodename, char *content, struct parser_state *state) +fill_region(xmlNode *node) { - string_truncate_at_pattern(nodename, ".region.regions"); + struct region *region = znew(*region); + wl_list_append(&rc.regions, ®ion->link); - if (!strcasecmp(nodename, "region.regions")) { - state->current_region = znew(*state->current_region); - wl_list_append(&rc.regions, &state->current_region->link); - } else if (!content) { - /* intentionally left empty */ - } else if (!state->current_region) { - wlr_log(WLR_ERROR, "Expecting current_region->name) { - state->current_region->name = xstrdup(content); + xmlNode *child; + char *key, *content; + LAB_XML_FOR_EACH(node, child, key, content) { + if (!strcasecmp(key, "name")) { + xstrdup_replace(region->name, content); + } else if (strstr("xywidtheight", key) + && !strchr(content, '%')) { + wlr_log(WLR_ERROR, "Removing invalid region " + "'%s': %s='%s' misses a trailing %%", + region->name, key, content); + wl_list_remove(®ion->link); + zfree(region->name); + zfree(region); + return; + } else if (!strcmp(key, "x")) { + region->percentage.x = atoi(content); + } else if (!strcmp(key, "y")) { + region->percentage.y = atoi(content); + } else if (!strcmp(key, "width")) { + region->percentage.width = atoi(content); + } else if (!strcmp(key, "height")) { + region->percentage.height = atoi(content); + } else { + wlr_log(WLR_ERROR, "Unexpected data in region " + "parser: %s=\"%s\"", key, content); + } + } +} + +static void +fill_regions(xmlNode *node) +{ + /* TODO: make sure is empty here */ + + xmlNode *child; + char *key, *content; + LAB_XML_FOR_EACH(node, child, key, content) { + if (!strcasecmp(key, "region")) { + fill_region(child); } - } else if (strstr("xywidtheight", nodename) && !strchr(content, '%')) { - wlr_log(WLR_ERROR, "Removing invalid region '%s': %s='%s' misses" - " a trailing %%", state->current_region->name, nodename, content); - wl_list_remove(&state->current_region->link); - zfree(state->current_region->name); - zfree(state->current_region); - } else if (!strcmp(nodename, "x")) { - state->current_region->percentage.x = atoi(content); - } else if (!strcmp(nodename, "y")) { - state->current_region->percentage.y = atoi(content); - } else if (!strcmp(nodename, "width")) { - state->current_region->percentage.width = atoi(content); - } else if (!strcmp(nodename, "height")) { - state->current_region->percentage.height = atoi(content); - } else { - wlr_log(WLR_ERROR, "Unexpected data in region parser: %s=\"%s\"", - nodename, content); } } @@ -1057,8 +1068,8 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state) fill_libinput_category(node); return; } - if (state->in_regions) { - fill_region(nodename, content, state); + if (!strcasecmp(nodename, "regions")) { + fill_regions(node); return; } if (state->in_window_switcher_field) {