diff --git a/include/sway/tree/workspace.h b/include/sway/tree/workspace.h index b0fef4ca..55412c37 100644 --- a/include/sway/tree/workspace.h +++ b/include/sway/tree/workspace.h @@ -42,6 +42,7 @@ struct sway_workspace { list_t *tiling; // struct sway_container list_t *output_priority; bool urgent; + bool persistent; struct sway_workspace_state current; }; diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 03e488ba..01da27fc 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c @@ -10,6 +10,7 @@ #include "list.h" #include "log.h" #include "stringop.h" +#include "util.h" static struct workspace_config *workspace_config_find_or_create(char *ws_name) { struct workspace_config *wsc = workspace_find_config(ws_name); @@ -130,6 +131,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { int output_location = -1; int gaps_location = -1; + int persistent_location = -1; for (int i = 0; i < argc; ++i) { if (strcasecmp(argv[i], "output") == 0) { @@ -143,6 +145,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { break; } } + for (int i = 0; i < argc; ++i) { + if (strcasecmp(argv[i], "persistent") == 0) { + persistent_location = i; + break; + } + } + if (output_location == 0) { return cmd_results_new(CMD_INVALID, "Expected 'workspace output '"); @@ -165,6 +174,24 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { if ((error = cmd_workspace_gaps(argc, argv, gaps_location))) { return error; } + } else if (persistent_location == 0) { + return cmd_results_new(CMD_INVALID, + "Expected 'workspace persistent yes|no'"); + } else if (persistent_location > 0) { + if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, + persistent_location + 2))) { + return error; + } + + struct sway_workspace *ws = NULL; + + char *ws_name = join_args(argv, persistent_location); + if (!(ws = workspace_by_name(ws_name))) { + ws = workspace_create(NULL, ws_name); + } + free(ws_name); + ws->persistent = parse_boolean(argv[persistent_location + 1], ws->persistent); + workspace_consider_destroy(ws); } else { if (config->reading || !config->active) { return cmd_results_new(CMD_DEFER, NULL); diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 18218768..b32f15aa 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c @@ -77,6 +77,7 @@ struct sway_workspace *workspace_create(struct sway_output *output, ws->floating = create_list(); ws->tiling = create_list(); ws->output_priority = create_list(); + ws->persistent = false; ws->gaps_outer = config->gaps_outer; ws->gaps_inner = config->gaps_inner; @@ -154,6 +155,10 @@ void workspace_begin_destroy(struct sway_workspace *workspace) { } void workspace_consider_destroy(struct sway_workspace *ws) { + if (ws->persistent) { + return; + } + if (ws->tiling->length || ws->floating->length) { return; }