mirror of
https://github.com/swaywm/sway.git
synced 2024-11-28 02:41:28 +00:00
Implement workspace <name> persistent yes|no
This commit is contained in:
parent
6a1c176d14
commit
f57149dedd
|
@ -42,6 +42,7 @@ struct sway_workspace {
|
||||||
list_t *tiling; // struct sway_container
|
list_t *tiling; // struct sway_container
|
||||||
list_t *output_priority;
|
list_t *output_priority;
|
||||||
bool urgent;
|
bool urgent;
|
||||||
|
bool persistent;
|
||||||
|
|
||||||
struct sway_workspace_state current;
|
struct sway_workspace_state current;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "stringop.h"
|
#include "stringop.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
|
static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
|
||||||
struct workspace_config *wsc = workspace_find_config(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 output_location = -1;
|
||||||
int gaps_location = -1;
|
int gaps_location = -1;
|
||||||
|
int persistent_location = -1;
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i) {
|
for (int i = 0; i < argc; ++i) {
|
||||||
if (strcasecmp(argv[i], "output") == 0) {
|
if (strcasecmp(argv[i], "output") == 0) {
|
||||||
|
@ -143,6 +145,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for (int i = 0; i < argc; ++i) {
|
||||||
|
if (strcasecmp(argv[i], "persistent") == 0) {
|
||||||
|
persistent_location = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (output_location == 0) {
|
if (output_location == 0) {
|
||||||
return cmd_results_new(CMD_INVALID,
|
return cmd_results_new(CMD_INVALID,
|
||||||
"Expected 'workspace <name> output <output>'");
|
"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))) {
|
if ((error = cmd_workspace_gaps(argc, argv, gaps_location))) {
|
||||||
return error;
|
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 {
|
} else {
|
||||||
if (config->reading || !config->active) {
|
if (config->reading || !config->active) {
|
||||||
return cmd_results_new(CMD_DEFER, NULL);
|
return cmd_results_new(CMD_DEFER, NULL);
|
||||||
|
|
|
@ -77,6 +77,7 @@ struct sway_workspace *workspace_create(struct sway_output *output,
|
||||||
ws->floating = create_list();
|
ws->floating = create_list();
|
||||||
ws->tiling = create_list();
|
ws->tiling = create_list();
|
||||||
ws->output_priority = create_list();
|
ws->output_priority = create_list();
|
||||||
|
ws->persistent = false;
|
||||||
|
|
||||||
ws->gaps_outer = config->gaps_outer;
|
ws->gaps_outer = config->gaps_outer;
|
||||||
ws->gaps_inner = config->gaps_inner;
|
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) {
|
void workspace_consider_destroy(struct sway_workspace *ws) {
|
||||||
|
if (ws->persistent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (ws->tiling->length || ws->floating->length) {
|
if (ws->tiling->length || ws->floating->length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue