aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/gaps.c50
-rw-r--r--sway/commands/workspace.c16
2 files changed, 26 insertions, 40 deletions
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c
index 2e0876a9..042b415f 100644
--- a/sway/commands/gaps.c
+++ b/sway/commands/gaps.c
@@ -20,31 +20,6 @@ struct gaps_data {
int amount;
};
-// gaps edge_gaps on|off|toggle
-static struct cmd_results *gaps_edge_gaps(int argc, char **argv) {
- struct cmd_results *error;
- if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
- return error;
- }
-
- if (strcmp(argv[1], "on") == 0) {
- config->edge_gaps = true;
- } else if (strcmp(argv[1], "off") == 0) {
- config->edge_gaps = false;
- } else if (strcmp(argv[1], "toggle") == 0) {
- if (!config->active) {
- return cmd_results_new(CMD_INVALID, "gaps",
- "Cannot toggle gaps while not running.");
- }
- config->edge_gaps = !config->edge_gaps;
- } else {
- return cmd_results_new(CMD_INVALID, "gaps",
- "gaps edge_gaps on|off|toggle");
- }
- arrange_root();
- return cmd_results_new(CMD_SUCCESS, NULL, NULL);
-}
-
// gaps inner|outer <px>
static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2);
@@ -68,15 +43,17 @@ static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
return cmd_results_new(CMD_INVALID, "gaps",
"Expected 'gaps inner|outer <px>'");
}
- if (amount < 0) {
- amount = 0;
- }
-
if (inner) {
- config->gaps_inner = amount;
+ config->gaps_inner = (amount >= 0) ? amount : 0;
} else {
config->gaps_outer = amount;
}
+
+ // Prevent negative outer gaps from moving windows out of the workspace.
+ if (config->gaps_outer < -config->gaps_inner) {
+ config->gaps_outer = -config->gaps_inner;
+ }
+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
@@ -95,8 +72,12 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) {
*prop -= data->amount;
break;
}
- if (*prop < 0) {
- *prop = 0;
+ // Prevent invalid gaps configurations.
+ if (ws->gaps_inner < 0) {
+ ws->gaps_inner = 0;
+ }
+ if (ws->gaps_outer < -ws->gaps_inner) {
+ ws->gaps_outer = -ws->gaps_inner;
}
arrange_workspace(ws);
}
@@ -156,7 +137,6 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
-// gaps edge_gaps on|off|toggle
// gaps inner|outer <px> - sets defaults for workspaces
// gaps inner|outer current|all set|plus|minus <px> - runtime only
struct cmd_results *cmd_gaps(int argc, char **argv) {
@@ -165,10 +145,6 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
return error;
}
- if (strcmp(argv[0], "edge_gaps") == 0) {
- return gaps_edge_gaps(argc, argv);
- }
-
if (argc == 2) {
return gaps_set_defaults(argc, argv);
}
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 63f29641..61aa443d 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -1,5 +1,6 @@
#define _XOPEN_SOURCE 500
#include <ctype.h>
+#include <limits.h>
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
@@ -20,8 +21,8 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
return NULL;
}
wsc->workspace = strdup(ws_name);
- wsc->gaps_inner = -1;
- wsc->gaps_outer = -1;
+ wsc->gaps_inner = INT_MIN;
+ wsc->gaps_outer = INT_MIN;
list_add(config->workspace_configs, wsc);
return wsc;
}
@@ -94,7 +95,16 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
return cmd_results_new(CMD_FAILURE, "workspace gaps",
"Expected 'workspace <ws> gaps inner|outer <px>'");
}
- *prop = val >= 0 ? val : 0;
+ *prop = val;
+
+ // Prevent invalid gaps configurations.
+ if (wsc->gaps_inner < 0) {
+ wsc->gaps_inner = 0;
+ }
+ if (wsc->gaps_outer < -wsc->gaps_inner) {
+ wsc->gaps_outer = -wsc->gaps_inner;
+ }
+
} else {
if (config->reading || !config->active) {
return cmd_results_new(CMD_DEFER, "workspace", NULL);