]> git.mdlowis.com Git - proto/labwc.git/commitdiff
config: support <desktops number="">
authorSachin Bhat <sachubhat17@gmail.com>
Mon, 19 Jun 2023 00:46:56 +0000 (08:46 +0800)
committerJohan Malm <johanmalm@users.noreply.github.com>
Sun, 25 Jun 2023 09:31:13 +0000 (10:31 +0100)
include/config/rcxml.h
src/config/rcxml.c

index 8e7f3c5fd7a291dbd38afb36292533854b6a7eab..29468a4258334f7a634aea2387cbfb49c7ea69d7 100644 (file)
@@ -69,6 +69,7 @@ struct rcxml {
 
        struct {
                int popuptime;
+               int count;
                struct wl_list workspaces;  /* struct workspace.link */
        } workspace_config;
 
index 116ceddedda11f5c730e99a202a84f1a6b11042b..1b275761cb60f74af4ad73ddabec765ba194a649 100644 (file)
@@ -8,6 +8,7 @@
 #include <libxml/tree.h>
 #include <stdbool.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <strings.h>
 #include <unistd.h>
@@ -24,6 +25,7 @@
 #include "config/libinput.h"
 #include "config/mousebind.h"
 #include "config/rcxml.h"
+#include "labwc.h"
 #include "regions.h"
 #include "window-rules.h"
 #include "workspaces.h"
@@ -613,6 +615,8 @@ entry(xmlNode *node, char *nodename, char *content)
                wl_list_append(&rc.workspace_config.workspaces, &workspace->link);
        } else if (!strcasecmp(nodename, "popupTime.desktops")) {
                rc.workspace_config.popuptime = atoi(content);
+       } else if (!strcasecmp(nodename, "number.desktops")) {
+               rc.workspace_config.count = MAX(1, atoi(content));
        }
 }
 
@@ -755,6 +759,7 @@ rcxml_init(void)
        rc.window_switcher.outlines = true;
 
        rc.workspace_config.popuptime = INT_MIN;
+       rc.workspace_config.count = 1;
 }
 
 static struct {
@@ -1042,10 +1047,17 @@ post_processing(void)
                struct libinput_category *l = libinput_category_create();
                assert(l && libinput_category_get_default() == l);
        }
-       if (!wl_list_length(&rc.workspace_config.workspaces)) {
-               struct workspace *workspace = znew(*workspace);
-               workspace->name = xstrdup("Default");
-               wl_list_append(&rc.workspace_config.workspaces, &workspace->link);
+
+       int workspaces_configured = wl_list_length(&rc.workspace_config.workspaces);
+       if (workspaces_configured < rc.workspace_config.count) {
+               struct workspace *workspace;
+               char workspace_name[32]; // Maximum length of workspace name "Workspace X"
+               for (int i = workspaces_configured; i < rc.workspace_config.count; i++) {
+                       workspace = znew(*workspace);
+                       snprintf(workspace_name, sizeof(workspace_name), "Workspace %d", i + 1);
+                       workspace->name = xstrdup(workspace_name);
+                       wl_list_append(&rc.workspace_config.workspaces, &workspace->link);
+               }
        }
        if (rc.workspace_config.popuptime == INT_MIN) {
                rc.workspace_config.popuptime = 1000;