Implement workspace <name> persistent yes|no

This commit is contained in:
Marko 2023-06-09 20:15:00 +02:00
parent 6a1c176d14
commit f57149dedd
3 changed files with 33 additions and 0 deletions

View file

@ -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;
};

View file

@ -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 <name> output <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 <name> 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);

View file

@ -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;
}