mirror of
https://github.com/labwc/labwc.git
synced 2026-02-05 04:06:33 -05:00
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:
parent
4819f47f98
commit
37618a1456
4 changed files with 39 additions and 41 deletions
|
|
@ -57,6 +57,11 @@ struct usable_area_override {
|
|||
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 {
|
||||
/* from command line */
|
||||
char *config_dir;
|
||||
|
|
@ -170,7 +175,7 @@ struct rcxml {
|
|||
int min_nr_workspaces;
|
||||
char *initial_workspace_name;
|
||||
char *prefix;
|
||||
struct wl_list workspaces; /* struct workspace.link */
|
||||
struct wl_list workspaces; /* struct workspace_config.link */
|
||||
} workspace_config;
|
||||
|
||||
/* Regions */
|
||||
|
|
|
|||
|
|
@ -10,12 +10,8 @@ struct seat;
|
|||
struct server;
|
||||
struct wlr_scene_tree;
|
||||
|
||||
/* Double use: as config in config/rcxml.c and as instance in workspaces.c */
|
||||
struct workspace {
|
||||
struct wl_list link; /*
|
||||
* struct server.workspaces
|
||||
* struct rcxml.workspace_config.workspaces
|
||||
*/
|
||||
struct wl_list link; /* struct server.workspaces */
|
||||
struct server *server;
|
||||
|
||||
char *name;
|
||||
|
|
|
|||
|
|
@ -1309,9 +1309,9 @@ entry(xmlNode *node, char *nodename, char *content)
|
|||
" Use <windowSwitcher outlines=\"\" />");
|
||||
|
||||
} else if (!strcasecmp(nodename, "name.names.desktops")) {
|
||||
struct workspace *workspace = znew(*workspace);
|
||||
workspace->name = xstrdup(content);
|
||||
wl_list_append(&rc.workspace_config.workspaces, &workspace->link);
|
||||
struct workspace_config *conf = znew(*conf);
|
||||
conf->name = xstrdup(content);
|
||||
wl_list_append(&rc.workspace_config.workspaces, &conf->link);
|
||||
} else if (!strcasecmp(nodename, "popupTime.desktops")) {
|
||||
rc.workspace_config.popuptime = atoi(content);
|
||||
} else if (!strcasecmp(nodename, "initial.desktops")) {
|
||||
|
|
@ -1784,15 +1784,14 @@ post_processing(void)
|
|||
}
|
||||
|
||||
struct buf b = BUF_INIT;
|
||||
struct workspace *workspace;
|
||||
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)) {
|
||||
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);
|
||||
conf->name = xstrdup(b.data);
|
||||
wl_list_append(&rc.workspace_config.workspaces, &conf->link);
|
||||
buf_clear(&b);
|
||||
}
|
||||
buf_reset(&b);
|
||||
|
|
@ -2011,7 +2010,7 @@ rcxml_finish(void)
|
|||
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_remove(&w->link);
|
||||
zfree(w->name);
|
||||
|
|
|
|||
|
|
@ -413,7 +413,7 @@ workspaces_init(struct server *server)
|
|||
|
||||
wl_list_init(&server->workspaces.all);
|
||||
|
||||
struct workspace *conf;
|
||||
struct workspace_config *conf;
|
||||
wl_list_for_each(conf, &rc.workspace_config.workspaces, link) {
|
||||
add_workspace(server, conf->name);
|
||||
}
|
||||
|
|
@ -590,36 +590,34 @@ workspaces_reconfigure(struct server *server)
|
|||
* - 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;
|
||||
wl_list_for_each(configured_workspace,
|
||||
&rc.workspace_config.workspaces, link) {
|
||||
struct workspace *actual_workspace = wl_container_of(
|
||||
actual_workspace_link, actual_workspace, link);
|
||||
struct workspace_config *conf;
|
||||
wl_list_for_each(conf, &rc.workspace_config.workspaces, link) {
|
||||
struct workspace *workspace = wl_container_of(
|
||||
workspace_link, workspace, link);
|
||||
|
||||
if (actual_workspace_link == &server->workspaces.all) {
|
||||
if (workspace_link == &server->workspaces.all) {
|
||||
/* # of configured workspaces increased */
|
||||
wlr_log(WLR_DEBUG, "Adding workspace \"%s\"",
|
||||
configured_workspace->name);
|
||||
add_workspace(server, configured_workspace->name);
|
||||
conf->name);
|
||||
add_workspace(server, conf->name);
|
||||
continue;
|
||||
}
|
||||
if (strcmp(actual_workspace->name, configured_workspace->name)) {
|
||||
if (strcmp(workspace->name, conf->name)) {
|
||||
/* Workspace is renamed */
|
||||
wlr_log(WLR_DEBUG, "Renaming workspace \"%s\" to \"%s\"",
|
||||
actual_workspace->name, configured_workspace->name);
|
||||
free(actual_workspace->name);
|
||||
actual_workspace->name = xstrdup(configured_workspace->name);
|
||||
workspace->name, conf->name);
|
||||
xstrdup_replace(workspace->name, conf->name);
|
||||
lab_cosmic_workspace_set_name(
|
||||
actual_workspace->cosmic_workspace, actual_workspace->name);
|
||||
workspace->cosmic_workspace, workspace->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;
|
||||
}
|
||||
|
||||
|
|
@ -628,30 +626,30 @@ workspaces_reconfigure(struct server *server)
|
|||
struct workspace *first_workspace =
|
||||
wl_container_of(server->workspaces.all.next, first_workspace, link);
|
||||
|
||||
while (actual_workspace_link != &server->workspaces.all) {
|
||||
struct workspace *actual_workspace = wl_container_of(
|
||||
actual_workspace_link, actual_workspace, link);
|
||||
while (workspace_link != &server->workspaces.all) {
|
||||
struct workspace *workspace = wl_container_of(
|
||||
workspace_link, workspace, link);
|
||||
|
||||
wlr_log(WLR_DEBUG, "Destroying workspace \"%s\"",
|
||||
actual_workspace->name);
|
||||
workspace->name);
|
||||
|
||||
struct view *view;
|
||||
wl_list_for_each(view, &server->views, link) {
|
||||
if (view->workspace == actual_workspace) {
|
||||
if (view->workspace == workspace) {
|
||||
view_move_to_workspace(view, first_workspace);
|
||||
}
|
||||
}
|
||||
|
||||
if (server->workspaces.current == actual_workspace) {
|
||||
if (server->workspaces.current == workspace) {
|
||||
workspaces_switch_to(first_workspace,
|
||||
/* update_focus */ true);
|
||||
}
|
||||
if (server->workspaces.last == actual_workspace) {
|
||||
if (server->workspaces.last == workspace) {
|
||||
server->workspaces.last = first_workspace;
|
||||
}
|
||||
|
||||
actual_workspace_link = actual_workspace_link->next;
|
||||
destroy_workspace(actual_workspace);
|
||||
workspace_link = workspace_link->next;
|
||||
destroy_workspace(workspace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue