aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r--sway/commands/workspace.c74
1 files changed, 63 insertions, 11 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index f026a39d..63f29641 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -10,6 +10,28 @@
#include "log.h"
#include "stringop.h"
+static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
+ struct workspace_config *wsc = workspace_find_config(ws_name);
+ if (wsc) {
+ return wsc;
+ }
+ wsc = calloc(1, sizeof(struct workspace_config));
+ if (!wsc) {
+ return NULL;
+ }
+ wsc->workspace = strdup(ws_name);
+ wsc->gaps_inner = -1;
+ wsc->gaps_outer = -1;
+ list_add(config->workspace_configs, wsc);
+ return wsc;
+}
+
+void free_workspace_config(struct workspace_config *wsc) {
+ free(wsc->workspace);
+ free(wsc->output);
+ free(wsc);
+}
+
struct cmd_results *cmd_workspace(int argc, char **argv) {
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1))) {
@@ -17,6 +39,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
}
int output_location = -1;
+ int gaps_location = -1;
for (int i = 0; i < argc; ++i) {
if (strcasecmp(argv[i], "output") == 0) {
@@ -24,25 +47,54 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
break;
}
}
+ for (int i = 0; i < argc; ++i) {
+ if (strcasecmp(argv[i], "gaps") == 0) {
+ gaps_location = i;
+ break;
+ }
+ }
if (output_location >= 0) {
if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, output_location + 2))) {
return error;
}
- struct workspace_output *wso = calloc(1, sizeof(struct workspace_output));
- if (!wso) {
+ char *ws_name = join_args(argv, argc - 2);
+ struct workspace_config *wsc = workspace_config_find_or_create(ws_name);
+ free(ws_name);
+ if (!wsc) {
return cmd_results_new(CMD_FAILURE, "workspace output",
"Unable to allocate workspace output");
}
- wso->workspace = join_args(argv, argc - 2);
- wso->output = strdup(argv[output_location + 1]);
- int i = -1;
- if ((i = list_seq_find(config->workspace_outputs, workspace_output_cmp_workspace, wso)) != -1) {
- struct workspace_output *old = config->workspace_outputs->items[i];
- free(old); // workspaces can only be assigned to a single output
- list_del(config->workspace_outputs, i);
+ free(wsc->output);
+ wsc->output = strdup(argv[output_location + 1]);
+ } else if (gaps_location >= 0) {
+ if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, gaps_location + 3))) {
+ return error;
+ }
+ char *ws_name = join_args(argv, argc - 3);
+ struct workspace_config *wsc = workspace_config_find_or_create(ws_name);
+ free(ws_name);
+ if (!wsc) {
+ return cmd_results_new(CMD_FAILURE, "workspace gaps",
+ "Unable to allocate workspace output");
+ }
+ int *prop = NULL;
+ if (strcasecmp(argv[gaps_location + 1], "inner") == 0) {
+ prop = &wsc->gaps_inner;
+ } else if (strcasecmp(argv[gaps_location + 1], "outer") == 0) {
+ prop = &wsc->gaps_outer;
+ } else {
+ return cmd_results_new(CMD_FAILURE, "workspace gaps",
+ "Expected 'workspace <ws> gaps inner|outer <px>'");
+ }
+ char *end;
+ int val = strtol(argv[gaps_location + 2], &end, 10);
+
+ if (strlen(end)) {
+ free(end);
+ return cmd_results_new(CMD_FAILURE, "workspace gaps",
+ "Expected 'workspace <ws> gaps inner|outer <px>'");
}
- wlr_log(WLR_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output);
- list_add(config->workspace_outputs, wso);
+ *prop = val >= 0 ? val : 0;
} else {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, "workspace", NULL);