Avoid double use of struct workspace

`struct workspace` was used both for representing an actual workspace
and for an entry of workspace configuration. Avoid it for clarity.
This commit is contained in:
tokyo4j 2026-01-31 01:24:01 +09:00 committed by Consolatis
parent 4819f47f98
commit 37618a1456
4 changed files with 39 additions and 41 deletions

View file

@ -57,6 +57,11 @@ struct usable_area_override {
struct wl_list link; /* struct rcxml.usable_area_overrides */ struct wl_list link; /* struct rcxml.usable_area_overrides */
}; };
struct workspace_config {
struct wl_list link; /* struct rcxml.workspace_config.workspaces */
char *name;
};
struct rcxml { struct rcxml {
/* from command line */ /* from command line */
char *config_dir; char *config_dir;
@ -170,7 +175,7 @@ struct rcxml {
int min_nr_workspaces; int min_nr_workspaces;
char *initial_workspace_name; char *initial_workspace_name;
char *prefix; char *prefix;
struct wl_list workspaces; /* struct workspace.link */ struct wl_list workspaces; /* struct workspace_config.link */
} workspace_config; } workspace_config;
/* Regions */ /* Regions */

View file

@ -10,12 +10,8 @@ struct seat;
struct server; struct server;
struct wlr_scene_tree; struct wlr_scene_tree;
/* Double use: as config in config/rcxml.c and as instance in workspaces.c */
struct workspace { struct workspace {
struct wl_list link; /* struct wl_list link; /* struct server.workspaces */
* struct server.workspaces
* struct rcxml.workspace_config.workspaces
*/
struct server *server; struct server *server;
char *name; char *name;

View file

@ -1309,9 +1309,9 @@ entry(xmlNode *node, char *nodename, char *content)
" Use <windowSwitcher outlines=\"\" />"); " Use <windowSwitcher outlines=\"\" />");
} else if (!strcasecmp(nodename, "name.names.desktops")) { } else if (!strcasecmp(nodename, "name.names.desktops")) {
struct workspace *workspace = znew(*workspace); struct workspace_config *conf = znew(*conf);
workspace->name = xstrdup(content); conf->name = xstrdup(content);
wl_list_append(&rc.workspace_config.workspaces, &workspace->link); wl_list_append(&rc.workspace_config.workspaces, &conf->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, "initial.desktops")) { } else if (!strcasecmp(nodename, "initial.desktops")) {
@ -1784,15 +1784,14 @@ post_processing(void)
} }
struct buf b = BUF_INIT; struct buf b = BUF_INIT;
struct workspace *workspace;
for (int i = nr_workspaces; i < rc.workspace_config.min_nr_workspaces; i++) { for (int i = nr_workspaces; i < rc.workspace_config.min_nr_workspaces; i++) {
workspace = znew(*workspace); struct workspace_config *conf = znew(*conf);
if (!string_null_or_empty(rc.workspace_config.prefix)) { if (!string_null_or_empty(rc.workspace_config.prefix)) {
buf_add_fmt(&b, "%s ", rc.workspace_config.prefix); buf_add_fmt(&b, "%s ", rc.workspace_config.prefix);
} }
buf_add_fmt(&b, "%d", i + 1); buf_add_fmt(&b, "%d", i + 1);
workspace->name = xstrdup(b.data); conf->name = xstrdup(b.data);
wl_list_append(&rc.workspace_config.workspaces, &workspace->link); wl_list_append(&rc.workspace_config.workspaces, &conf->link);
buf_clear(&b); buf_clear(&b);
} }
buf_reset(&b); buf_reset(&b);
@ -2011,7 +2010,7 @@ rcxml_finish(void)
zfree(l); zfree(l);
} }
struct workspace *w, *w_tmp; struct workspace_config *w, *w_tmp;
wl_list_for_each_safe(w, w_tmp, &rc.workspace_config.workspaces, link) { wl_list_for_each_safe(w, w_tmp, &rc.workspace_config.workspaces, link) {
wl_list_remove(&w->link); wl_list_remove(&w->link);
zfree(w->name); zfree(w->name);

View file

@ -413,7 +413,7 @@ workspaces_init(struct server *server)
wl_list_init(&server->workspaces.all); wl_list_init(&server->workspaces.all);
struct workspace *conf; struct workspace_config *conf;
wl_list_for_each(conf, &rc.workspace_config.workspaces, link) { wl_list_for_each(conf, &rc.workspace_config.workspaces, link) {
add_workspace(server, conf->name); add_workspace(server, conf->name);
} }
@ -590,36 +590,34 @@ workspaces_reconfigure(struct server *server)
* - Destroy workspaces if fewer workspace are desired * - Destroy workspaces if fewer workspace are desired
*/ */
struct wl_list *actual_workspace_link = server->workspaces.all.next; struct wl_list *workspace_link = server->workspaces.all.next;
struct workspace *configured_workspace; struct workspace_config *conf;
wl_list_for_each(configured_workspace, wl_list_for_each(conf, &rc.workspace_config.workspaces, link) {
&rc.workspace_config.workspaces, link) { struct workspace *workspace = wl_container_of(
struct workspace *actual_workspace = wl_container_of( workspace_link, workspace, link);
actual_workspace_link, actual_workspace, link);
if (actual_workspace_link == &server->workspaces.all) { if (workspace_link == &server->workspaces.all) {
/* # of configured workspaces increased */ /* # of configured workspaces increased */
wlr_log(WLR_DEBUG, "Adding workspace \"%s\"", wlr_log(WLR_DEBUG, "Adding workspace \"%s\"",
configured_workspace->name); conf->name);
add_workspace(server, configured_workspace->name); add_workspace(server, conf->name);
continue; continue;
} }
if (strcmp(actual_workspace->name, configured_workspace->name)) { if (strcmp(workspace->name, conf->name)) {
/* Workspace is renamed */ /* Workspace is renamed */
wlr_log(WLR_DEBUG, "Renaming workspace \"%s\" to \"%s\"", wlr_log(WLR_DEBUG, "Renaming workspace \"%s\" to \"%s\"",
actual_workspace->name, configured_workspace->name); workspace->name, conf->name);
free(actual_workspace->name); xstrdup_replace(workspace->name, conf->name);
actual_workspace->name = xstrdup(configured_workspace->name);
lab_cosmic_workspace_set_name( lab_cosmic_workspace_set_name(
actual_workspace->cosmic_workspace, actual_workspace->name); workspace->cosmic_workspace, workspace->name);
lab_ext_workspace_set_name( lab_ext_workspace_set_name(
actual_workspace->ext_workspace, actual_workspace->name); workspace->ext_workspace, workspace->name);
} }
actual_workspace_link = actual_workspace_link->next; workspace_link = workspace_link->next;
} }
if (actual_workspace_link == &server->workspaces.all) { if (workspace_link == &server->workspaces.all) {
return; return;
} }
@ -628,30 +626,30 @@ workspaces_reconfigure(struct server *server)
struct workspace *first_workspace = struct workspace *first_workspace =
wl_container_of(server->workspaces.all.next, first_workspace, link); wl_container_of(server->workspaces.all.next, first_workspace, link);
while (actual_workspace_link != &server->workspaces.all) { while (workspace_link != &server->workspaces.all) {
struct workspace *actual_workspace = wl_container_of( struct workspace *workspace = wl_container_of(
actual_workspace_link, actual_workspace, link); workspace_link, workspace, link);
wlr_log(WLR_DEBUG, "Destroying workspace \"%s\"", wlr_log(WLR_DEBUG, "Destroying workspace \"%s\"",
actual_workspace->name); workspace->name);
struct view *view; struct view *view;
wl_list_for_each(view, &server->views, link) { wl_list_for_each(view, &server->views, link) {
if (view->workspace == actual_workspace) { if (view->workspace == workspace) {
view_move_to_workspace(view, first_workspace); view_move_to_workspace(view, first_workspace);
} }
} }
if (server->workspaces.current == actual_workspace) { if (server->workspaces.current == workspace) {
workspaces_switch_to(first_workspace, workspaces_switch_to(first_workspace,
/* update_focus */ true); /* update_focus */ true);
} }
if (server->workspaces.last == actual_workspace) { if (server->workspaces.last == workspace) {
server->workspaces.last = first_workspace; server->workspaces.last = first_workspace;
} }
actual_workspace_link = actual_workspace_link->next; workspace_link = workspace_link->next;
destroy_workspace(actual_workspace); destroy_workspace(workspace);
} }
} }