From 9bb4f44688ec33a20c0ea0b48a5085b7b6c5c310 Mon Sep 17 00:00:00 2001 From: Sachin Bhat Date: Mon, 19 Jun 2023 08:46:56 +0800 Subject: [PATCH] config: support --- include/config/rcxml.h | 1 + src/config/rcxml.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/include/config/rcxml.h b/include/config/rcxml.h index 8e7f3c5f..29468a42 100644 --- a/include/config/rcxml.h +++ b/include/config/rcxml.h @@ -69,6 +69,7 @@ struct rcxml { struct { int popuptime; + int count; struct wl_list workspaces; /* struct workspace.link */ } workspace_config; diff --git a/src/config/rcxml.c b/src/config/rcxml.c index 116cedde..1b275761 100644 --- a/src/config/rcxml.c +++ b/src/config/rcxml.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -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;