summaryrefslogtreecommitdiffstats
path: root/sway/commands/gaps.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/gaps.c')
-rw-r--r--sway/commands/gaps.c50
1 files changed, 13 insertions, 37 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 {
20 int amount; 20 int amount;
21}; 21};
22 22
23// gaps edge_gaps on|off|toggle
24static struct cmd_results *gaps_edge_gaps(int argc, char **argv) {
25 struct cmd_results *error;
26 if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 2))) {
27 return error;
28 }
29
30 if (strcmp(argv[1], "on") == 0) {
31 config->edge_gaps = true;
32 } else if (strcmp(argv[1], "off") == 0) {
33 config->edge_gaps = false;
34 } else if (strcmp(argv[1], "toggle") == 0) {
35 if (!config->active) {
36 return cmd_results_new(CMD_INVALID, "gaps",
37 "Cannot toggle gaps while not running.");
38 }
39 config->edge_gaps = !config->edge_gaps;
40 } else {
41 return cmd_results_new(CMD_INVALID, "gaps",
42 "gaps edge_gaps on|off|toggle");
43 }
44 arrange_root();
45 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
46}
47
48// gaps inner|outer <px> 23// gaps inner|outer <px>
49static struct cmd_results *gaps_set_defaults(int argc, char **argv) { 24static struct cmd_results *gaps_set_defaults(int argc, char **argv) {
50 struct cmd_results *error = checkarg(argc, "gaps", EXPECTED_EQUAL_TO, 2); 25 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) {
68 return cmd_results_new(CMD_INVALID, "gaps", 43 return cmd_results_new(CMD_INVALID, "gaps",
69 "Expected 'gaps inner|outer <px>'"); 44 "Expected 'gaps inner|outer <px>'");
70 } 45 }
71 if (amount < 0) {
72 amount = 0;
73 }
74
75 if (inner) { 46 if (inner) {
76 config->gaps_inner = amount; 47 config->gaps_inner = (amount >= 0) ? amount : 0;
77 } else { 48 } else {
78 config->gaps_outer = amount; 49 config->gaps_outer = amount;
79 } 50 }
51
52 // Prevent negative outer gaps from moving windows out of the workspace.
53 if (config->gaps_outer < -config->gaps_inner) {
54 config->gaps_outer = -config->gaps_inner;
55 }
56
80 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 57 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
81} 58}
82 59
@@ -95,8 +72,12 @@ static void configure_gaps(struct sway_workspace *ws, void *_data) {
95 *prop -= data->amount; 72 *prop -= data->amount;
96 break; 73 break;
97 } 74 }
98 if (*prop < 0) { 75 // Prevent invalid gaps configurations.
99 *prop = 0; 76 if (ws->gaps_inner < 0) {
77 ws->gaps_inner = 0;
78 }
79 if (ws->gaps_outer < -ws->gaps_inner) {
80 ws->gaps_outer = -ws->gaps_inner;
100 } 81 }
101 arrange_workspace(ws); 82 arrange_workspace(ws);
102} 83}
@@ -156,7 +137,6 @@ static struct cmd_results *gaps_set_runtime(int argc, char **argv) {
156 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 137 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
157} 138}
158 139
159// gaps edge_gaps on|off|toggle
160// gaps inner|outer <px> - sets defaults for workspaces 140// gaps inner|outer <px> - sets defaults for workspaces
161// gaps inner|outer current|all set|plus|minus <px> - runtime only 141// gaps inner|outer current|all set|plus|minus <px> - runtime only
162struct cmd_results *cmd_gaps(int argc, char **argv) { 142struct cmd_results *cmd_gaps(int argc, char **argv) {
@@ -165,10 +145,6 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
165 return error; 145 return error;
166 } 146 }
167 147
168 if (strcmp(argv[0], "edge_gaps") == 0) {
169 return gaps_edge_gaps(argc, argv);
170 }
171
172 if (argc == 2) { 148 if (argc == 2) {
173 return gaps_set_defaults(argc, argv); 149 return gaps_set_defaults(argc, argv);
174 } 150 }