diff options
author | Brian Ashworth <RedSoxFan@users.noreply.github.com> | 2018-10-13 18:49:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-13 18:49:31 -0400 |
commit | 350f7d34605264eb029f6f7d88d6a54e81f455ed (patch) | |
tree | 874a3157f2778518a87009c35b47de9d5451b257 | |
parent | Merge pull request #2828 from RyanDwyer/fix-locked-map-crash (diff) | |
parent | Merge branch 'master' into fix_edge_gaps (diff) | |
download | sway-350f7d34605264eb029f6f7d88d6a54e81f455ed.tar.gz sway-350f7d34605264eb029f6f7d88d6a54e81f455ed.tar.zst sway-350f7d34605264eb029f6f7d88d6a54e81f455ed.zip |
Merge pull request #2823 from tarmack/fix_edge_gaps
Fix edge gaps
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | sway/commands/gaps.c | 50 | ||||
-rw-r--r-- | sway/commands/workspace.c | 16 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/sway.5.scd | 8 | ||||
-rw-r--r-- | sway/tree/workspace.c | 7 |
6 files changed, 30 insertions, 53 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index bc02c0fd..ca17a645 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -389,7 +389,6 @@ struct sway_config { | |||
389 | bool show_marks; | 389 | bool show_marks; |
390 | bool tiling_drag; | 390 | bool tiling_drag; |
391 | 391 | ||
392 | bool edge_gaps; | ||
393 | bool smart_gaps; | 392 | bool smart_gaps; |
394 | int gaps_inner; | 393 | int gaps_inner; |
395 | int gaps_outer; | 394 | int gaps_outer; |
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 | ||
24 | static 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> |
49 | static struct cmd_results *gaps_set_defaults(int argc, char **argv) { | 24 | static 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 |
162 | struct cmd_results *cmd_gaps(int argc, char **argv) { | 142 | struct 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 | } |
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 @@ | |||
1 | #define _XOPEN_SOURCE 500 | 1 | #define _XOPEN_SOURCE 500 |
2 | #include <ctype.h> | 2 | #include <ctype.h> |
3 | #include <limits.h> | ||
3 | #include <string.h> | 4 | #include <string.h> |
4 | #include <strings.h> | 5 | #include <strings.h> |
5 | #include "sway/commands.h" | 6 | #include "sway/commands.h" |
@@ -20,8 +21,8 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) { | |||
20 | return NULL; | 21 | return NULL; |
21 | } | 22 | } |
22 | wsc->workspace = strdup(ws_name); | 23 | wsc->workspace = strdup(ws_name); |
23 | wsc->gaps_inner = -1; | 24 | wsc->gaps_inner = INT_MIN; |
24 | wsc->gaps_outer = -1; | 25 | wsc->gaps_outer = INT_MIN; |
25 | list_add(config->workspace_configs, wsc); | 26 | list_add(config->workspace_configs, wsc); |
26 | return wsc; | 27 | return wsc; |
27 | } | 28 | } |
@@ -94,7 +95,16 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
94 | return cmd_results_new(CMD_FAILURE, "workspace gaps", | 95 | return cmd_results_new(CMD_FAILURE, "workspace gaps", |
95 | "Expected 'workspace <ws> gaps inner|outer <px>'"); | 96 | "Expected 'workspace <ws> gaps inner|outer <px>'"); |
96 | } | 97 | } |
97 | *prop = val >= 0 ? val : 0; | 98 | *prop = val; |
99 | |||
100 | // Prevent invalid gaps configurations. | ||
101 | if (wsc->gaps_inner < 0) { | ||
102 | wsc->gaps_inner = 0; | ||
103 | } | ||
104 | if (wsc->gaps_outer < -wsc->gaps_inner) { | ||
105 | wsc->gaps_outer = -wsc->gaps_inner; | ||
106 | } | ||
107 | |||
98 | } else { | 108 | } else { |
99 | if (config->reading || !config->active) { | 109 | if (config->reading || !config->active) { |
100 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 110 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |
diff --git a/sway/config.c b/sway/config.c index f239ba1d..89b89464 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -234,7 +234,6 @@ static void config_defaults(struct sway_config *config) { | |||
234 | config->show_marks = true; | 234 | config->show_marks = true; |
235 | config->tiling_drag = true; | 235 | config->tiling_drag = true; |
236 | 236 | ||
237 | config->edge_gaps = true; | ||
238 | config->smart_gaps = false; | 237 | config->smart_gaps = false; |
239 | config->gaps_inner = 0; | 238 | config->gaps_inner = 0; |
240 | config->gaps_outer = 0; | 239 | config->gaps_outer = 0; |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index f7b778cf..2e1d13a8 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -420,15 +420,11 @@ The default colors are: | |||
420 | _focus\_wrapping force_. This is only available for convenience. Please | 420 | _focus\_wrapping force_. This is only available for convenience. Please |
421 | use _focus\_wrapping_ instead when possible. | 421 | use _focus\_wrapping_ instead when possible. |
422 | 422 | ||
423 | *gaps* edge\_gaps on|off|toggle | ||
424 | When _on_, gaps will be added between windows and workspace edges if the | ||
425 | inner gap is nonzero. When _off_, gaps will only be added between views. | ||
426 | _toggle_ cannot be used in the configuration file. | ||
427 | |||
428 | *gaps* inner|outer <amount> | 423 | *gaps* inner|outer <amount> |
429 | Sets default _amount_ pixels of _inner_ or _outer_ gap, where the inner | 424 | Sets default _amount_ pixels of _inner_ or _outer_ gap, where the inner |
430 | affects spacing around each view and outer affects the spacing around each | 425 | affects spacing around each view and outer affects the spacing around each |
431 | workspace. Outer gaps are in addition to inner gaps. | 426 | workspace. Outer gaps are in addition to inner gaps. To reduce or remove |
427 | outer gaps, outer gaps can be set to a negative value. | ||
432 | 428 | ||
433 | This affects new workspaces only, and is used when the workspace doesn't | 429 | This affects new workspaces only, and is used when the workspace doesn't |
434 | have its own gaps settings (see: workspace <ws> gaps inner|outer <amount>). | 430 | have its own gaps settings (see: workspace <ws> gaps inner|outer <amount>). |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index d7650560..a1282c1e 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -73,10 +73,10 @@ struct sway_workspace *workspace_create(struct sway_output *output, | |||
73 | if (name) { | 73 | if (name) { |
74 | struct workspace_config *wsc = workspace_find_config(name); | 74 | struct workspace_config *wsc = workspace_find_config(name); |
75 | if (wsc) { | 75 | if (wsc) { |
76 | if (wsc->gaps_outer != -1) { | 76 | if (wsc->gaps_outer != INT_MIN) { |
77 | ws->gaps_outer = wsc->gaps_outer; | 77 | ws->gaps_outer = wsc->gaps_outer; |
78 | } | 78 | } |
79 | if (wsc->gaps_inner != -1) { | 79 | if (wsc->gaps_inner != INT_MIN) { |
80 | ws->gaps_inner = wsc->gaps_inner; | 80 | ws->gaps_inner = wsc->gaps_inner; |
81 | } | 81 | } |
82 | } | 82 | } |
@@ -618,9 +618,6 @@ void workspace_add_gaps(struct sway_workspace *ws) { | |||
618 | if (ws->current_gaps > 0) { | 618 | if (ws->current_gaps > 0) { |
619 | return; | 619 | return; |
620 | } | 620 | } |
621 | if (!config->edge_gaps) { | ||
622 | return; | ||
623 | } | ||
624 | if (config->smart_gaps) { | 621 | if (config->smart_gaps) { |
625 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | 622 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); |
626 | struct sway_container *focus = | 623 | struct sway_container *focus = |