config: support <desktops number="">

This commit is contained in:
Sachin Bhat 2023-06-19 08:46:56 +08:00 committed by Johan Malm
parent e82e557d56
commit 9bb4f44688
2 changed files with 17 additions and 4 deletions

View file

@ -69,6 +69,7 @@ struct rcxml {
struct { struct {
int popuptime; int popuptime;
int count;
struct wl_list workspaces; /* struct workspace.link */ struct wl_list workspaces; /* struct workspace.link */
} workspace_config; } workspace_config;

View file

@ -8,6 +8,7 @@
#include <libxml/tree.h> #include <libxml/tree.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <strings.h> #include <strings.h>
#include <unistd.h> #include <unistd.h>
@ -24,6 +25,7 @@
#include "config/libinput.h" #include "config/libinput.h"
#include "config/mousebind.h" #include "config/mousebind.h"
#include "config/rcxml.h" #include "config/rcxml.h"
#include "labwc.h"
#include "regions.h" #include "regions.h"
#include "window-rules.h" #include "window-rules.h"
#include "workspaces.h" #include "workspaces.h"
@ -613,6 +615,8 @@ entry(xmlNode *node, char *nodename, char *content)
wl_list_append(&rc.workspace_config.workspaces, &workspace->link); wl_list_append(&rc.workspace_config.workspaces, &workspace->link);
} else if (!strcasecmp(nodename, "popupTime.desktops")) { } else if (!strcasecmp(nodename, "popupTime.desktops")) {
rc.workspace_config.popuptime = atoi(content); 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.window_switcher.outlines = true;
rc.workspace_config.popuptime = INT_MIN; rc.workspace_config.popuptime = INT_MIN;
rc.workspace_config.count = 1;
} }
static struct { static struct {
@ -1042,10 +1047,17 @@ post_processing(void)
struct libinput_category *l = libinput_category_create(); struct libinput_category *l = libinput_category_create();
assert(l && libinput_category_get_default() == l); assert(l && libinput_category_get_default() == l);
} }
if (!wl_list_length(&rc.workspace_config.workspaces)) {
struct workspace *workspace = znew(*workspace); int workspaces_configured = wl_list_length(&rc.workspace_config.workspaces);
workspace->name = xstrdup("Default"); if (workspaces_configured < rc.workspace_config.count) {
wl_list_append(&rc.workspace_config.workspaces, &workspace->link); 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) { if (rc.workspace_config.popuptime == INT_MIN) {
rc.workspace_config.popuptime = 1000; rc.workspace_config.popuptime = 1000;