]> git.mdlowis.com Git - proto/labwc.git/commitdiff
config: honor no content <desktops><prefix> node
authorJohan Malm <jgm323@gmail.com>
Fri, 28 Feb 2025 16:01:07 +0000 (16:01 +0000)
committerHiroaki Yamamoto <hrak1529@gmail.com>
Sun, 9 Mar 2025 03:06:16 +0000 (12:06 +0900)
...because users need a way to override the default "Workspace".

Fixes: #2601
src/config/rcxml.c

index f8e6dc9bebd762e48ce1991259a694afd9c2ac32..b9dc92aa5a600946d7b23cc57e51a0ee568eed5a 100644 (file)
@@ -1025,7 +1025,24 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
                return;
        }
 
-       /* handle the rest */
+       if (!strcasecmp(nodename, "prefix.desktops")) {
+               xstrdup_replace(rc.workspace_config.prefix, content ? content : "");
+               return;
+       }
+
+       /*
+        * Nodenames where we want to honour !content have to be parsed above
+        * this point. An example of this is:
+        *
+        *     <desktops>
+        *       <prefix></prefix>
+        *     </desktops>
+        *
+        * In the case of the <prefix> element having content, the node will be
+        * processed twice; first for the element itself (with no content) and
+        * then the content itself. In this situation xstrdup_replace() is
+        * called twice, but the end result is the right one.
+        */
        if (!content) {
                return;
        }
@@ -1209,8 +1226,6 @@ entry(xmlNode *node, char *nodename, char *content, struct parser_state *state)
                rc.workspace_config.popuptime = atoi(content);
        } else if (!strcasecmp(nodename, "number.desktops")) {
                rc.workspace_config.min_nr_workspaces = MAX(1, atoi(content));
-       } else if (!strcasecmp(nodename, "prefix.desktops")) {
-               xstrdup_replace(rc.workspace_config.prefix, content);
        } else if (!strcasecmp(nodename, "popupShow.resize")) {
                if (!strcasecmp(content, "Always")) {
                        rc.resize_indicator = LAB_RESIZE_INDICATOR_ALWAYS;
@@ -1760,13 +1775,20 @@ post_processing(void)
                if (!rc.workspace_config.prefix) {
                        rc.workspace_config.prefix = xstrdup(_("Workspace"));
                }
+
+               struct buf b = BUF_INIT;
                struct workspace *workspace;
                for (int i = nr_workspaces; i < rc.workspace_config.min_nr_workspaces; i++) {
                        workspace = znew(*workspace);
-                       workspace->name = strdup_printf("%s %d",
-                               rc.workspace_config.prefix, i + 1);
+                       if (!string_null_or_empty(rc.workspace_config.prefix)) {
+                               buf_add_fmt(&b, "%s ", rc.workspace_config.prefix);
+                       }
+                       buf_add_fmt(&b, "%d", i + 1);
+                       workspace->name = xstrdup(b.data);
                        wl_list_append(&rc.workspace_config.workspaces, &workspace->link);
+                       buf_clear(&b);
                }
+               buf_reset(&b);
        }
        if (rc.workspace_config.popuptime == INT_MIN) {
                rc.workspace_config.popuptime = 1000;