]> git.mdlowis.com Git - proto/labwc.git/commitdiff
rcxml: rewrite <windowSwitcher><fields> parser
authortokyo4j <hrak1529@gmail.com>
Fri, 11 Apr 2025 17:08:45 +0000 (02:08 +0900)
committerJohan Malm <johanmalm@users.noreply.github.com>
Wed, 30 Jul 2025 19:36:27 +0000 (20:36 +0100)
include/osd.h
src/config/rcxml.c
src/osd-field.c

index 806b88d4538f1fb6b69ab9a008116858db0b3438..971389d27589e5a6adbeb6f7a7093eafe6d69dbb 100644 (file)
@@ -56,7 +56,6 @@ void osd_field_get_content(struct window_switcher_field *field,
        struct buf *buf, struct view *view);
 
 /* Used by rcxml.c when parsing the config */
-struct window_switcher_field *osd_field_create(void);
 void osd_field_arg_from_xml_node(struct window_switcher_field *field,
        const char *nodename, const char *content);
 bool osd_field_is_valid(struct window_switcher_field *field);
index cddf895119d5a9501ced721b0ca0cc4f990465eb..92683cbe145a79fd31dcf33a6ac29d51ed38159f 100644 (file)
@@ -372,21 +372,29 @@ clear_window_switcher_fields(void)
 }
 
 static void
-fill_window_switcher_field(char *nodename, char *content, struct parser_state *state)
+fill_window_switcher_field(xmlNode *node)
 {
-       if (!strcasecmp(nodename, "field.fields.windowswitcher")) {
-               state->current_field = osd_field_create();
-               wl_list_append(&rc.window_switcher.fields, &state->current_field->link);
-               return;
+       struct window_switcher_field *field = znew(*field);
+       wl_list_append(&rc.window_switcher.fields, &field->link);
+
+       xmlNode *child;
+       char *key, *content;
+       LAB_XML_FOR_EACH(node, child, key, content) {
+               osd_field_arg_from_xml_node(field, key, content);
        }
+}
 
-       string_truncate_at_pattern(nodename, ".field.fields.windowswitcher");
-       if (!content) {
-               /* intentionally left empty */
-       } else if (!state->current_field) {
-               wlr_log(WLR_ERROR, "no <field>");
-       } else {
-               osd_field_arg_from_xml_node(state->current_field, nodename, content);
+static void
+fill_window_switcher_fields(xmlNode *node)
+{
+       clear_window_switcher_fields();
+
+       xmlNode *child;
+       char *key, *content;
+       LAB_XML_FOR_EACH(node, child, key, content) {
+               if (!strcasecmp(key, "field")) {
+                       fill_window_switcher_field(child);
+               }
        }
 }
 
@@ -1072,8 +1080,8 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
                fill_regions(node);
                return;
        }
-       if (state->in_window_switcher_field) {
-               fill_window_switcher_field(nodename, content, state);
+       if (!strcasecmp(nodename, "fields.windowSwitcher")) {
+               fill_window_switcher_fields(node);
                return;
        }
        if (state->in_window_rules) {
@@ -1428,7 +1436,6 @@ xml_tree_walk(xmlNode *node, struct parser_state *state)
                        continue;
                }
                if (!strcasecmp((char *)n->name, "fields")) {
-                       clear_window_switcher_fields();
                        state->in_window_switcher_field = true;
                        traverse(n, state);
                        state->in_window_switcher_field = false;
index 2885febe39e7c0cfaa0795b12a461a9408fe5172..0819e1e66f93594685689e07bb75b607afd54157 100644 (file)
@@ -297,13 +297,6 @@ reset_format:
        buf_reset(&field_result);
 }
 
-struct window_switcher_field *
-osd_field_create(void)
-{
-       struct window_switcher_field *field = znew(*field);
-       return field;
-}
-
 void
 osd_field_arg_from_xml_node(struct window_switcher_field *field,
                const char *nodename, const char *content)