diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2018-10-01 12:56:27 -0400 |
---|---|---|
committer | Brian Ashworth <bosrsf04@gmail.com> | 2018-10-01 21:19:06 -0400 |
commit | bb25194844599bb653a78633c9c09c0c0ff225ee (patch) | |
tree | a19bcbc62ff5d4ddcb822914a4f3516c7766406a | |
parent | Merge pull request #2739 from RedSoxFan/fix-2653 (diff) | |
download | sway-bb25194844599bb653a78633c9c09c0c0ff225ee.tar.gz sway-bb25194844599bb653a78633c9c09c0c0ff225ee.tar.zst sway-bb25194844599bb653a78633c9c09c0c0ff225ee.zip |
Handle border options for gaps
Fixes `hide_edge_borders smart` when gaps are in use.
Implements `hide_edge_borders smart_no_gaps` and `smart_borders
on|no_gaps|off`.
Since `smart_borders on` is equivalent to `hide_edge_borders smart`
and `smart_borders no_gaps` is equivalent to `hide_edge_borders
smart_no_gaps`, I opted to just save the last value set for
`hide_edge_borders` and restore that on `smart_borders off`. This
simplifies the conditions for setting the border.
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 4 | ||||
-rw-r--r-- | sway/commands.c | 1 | ||||
-rw-r--r-- | sway/commands/hide_edge_borders.c | 16 | ||||
-rw-r--r-- | sway/commands/smart_borders.c | 25 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway.5.scd | 8 | ||||
-rw-r--r-- | sway/tree/view.c | 31 |
9 files changed, 68 insertions, 20 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index afa65340..64f707f4 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -160,6 +160,7 @@ sway_cmd cmd_scratchpad; | |||
160 | sway_cmd cmd_seamless_mouse; | 160 | sway_cmd cmd_seamless_mouse; |
161 | sway_cmd cmd_set; | 161 | sway_cmd cmd_set; |
162 | sway_cmd cmd_show_marks; | 162 | sway_cmd cmd_show_marks; |
163 | sway_cmd cmd_smart_borders; | ||
163 | sway_cmd cmd_smart_gaps; | 164 | sway_cmd cmd_smart_gaps; |
164 | sway_cmd cmd_split; | 165 | sway_cmd cmd_split; |
165 | sway_cmd cmd_splith; | 166 | sway_cmd cmd_splith; |
diff --git a/include/sway/config.h b/include/sway/config.h index eab48aed..98a18b76 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -253,7 +253,8 @@ enum edge_border_types { | |||
253 | E_VERTICAL, /**< hide vertical edge borders */ | 253 | E_VERTICAL, /**< hide vertical edge borders */ |
254 | E_HORIZONTAL, /**< hide horizontal edge borders */ | 254 | E_HORIZONTAL, /**< hide horizontal edge borders */ |
255 | E_BOTH, /**< hide vertical and horizontal edge borders */ | 255 | E_BOTH, /**< hide vertical and horizontal edge borders */ |
256 | E_SMART /**< hide both if precisely one window is present in workspace */ | 256 | E_SMART, /**< hide both if precisely one window is present in workspace */ |
257 | E_SMART_NO_GAPS, /**< hide both if one window and gaps to edge is zero */ | ||
257 | }; | 258 | }; |
258 | 259 | ||
259 | enum command_context { | 260 | enum command_context { |
@@ -383,6 +384,7 @@ struct sway_config { | |||
383 | int border_thickness; | 384 | int border_thickness; |
384 | int floating_border_thickness; | 385 | int floating_border_thickness; |
385 | enum edge_border_types hide_edge_borders; | 386 | enum edge_border_types hide_edge_borders; |
387 | enum edge_border_types saved_edge_borders; | ||
386 | 388 | ||
387 | // border colors | 389 | // border colors |
388 | struct { | 390 | struct { |
diff --git a/sway/commands.c b/sway/commands.c index 03cfebd7..72db8ab9 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -110,6 +110,7 @@ static struct cmd_handler handlers[] = { | |||
110 | { "seat", cmd_seat }, | 110 | { "seat", cmd_seat }, |
111 | { "set", cmd_set }, | 111 | { "set", cmd_set }, |
112 | { "show_marks", cmd_show_marks }, | 112 | { "show_marks", cmd_show_marks }, |
113 | { "smart_borders", cmd_smart_borders }, | ||
113 | { "smart_gaps", cmd_smart_gaps }, | 114 | { "smart_gaps", cmd_smart_gaps }, |
114 | { "tiling_drag", cmd_tiling_drag }, | 115 | { "tiling_drag", cmd_tiling_drag }, |
115 | { "workspace", cmd_workspace }, | 116 | { "workspace", cmd_workspace }, |
diff --git a/sway/commands/hide_edge_borders.c b/sway/commands/hide_edge_borders.c index 0a5c7f28..ea261fb1 100644 --- a/sway/commands/hide_edge_borders.c +++ b/sway/commands/hide_edge_borders.c | |||
@@ -1,15 +1,8 @@ | |||
1 | #include "sway/commands.h" | 1 | #include "sway/commands.h" |
2 | #include "sway/config.h" | 2 | #include "sway/config.h" |
3 | #include "sway/tree/container.h" | 3 | #include "sway/tree/arrange.h" |
4 | #include "sway/tree/root.h" | ||
5 | #include "sway/tree/view.h" | 4 | #include "sway/tree/view.h" |
6 | 5 | ||
7 | static void _configure_view(struct sway_container *con, void *data) { | ||
8 | if (con->view) { | ||
9 | view_autoconfigure(con->view); | ||
10 | } | ||
11 | } | ||
12 | |||
13 | struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | 6 | struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { |
14 | struct cmd_results *error = NULL; | 7 | struct cmd_results *error = NULL; |
15 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { | 8 | if ((error = checkarg(argc, "hide_edge_borders", EXPECTED_EQUAL_TO, 1))) { |
@@ -26,13 +19,16 @@ struct cmd_results *cmd_hide_edge_borders(int argc, char **argv) { | |||
26 | config->hide_edge_borders = E_BOTH; | 19 | config->hide_edge_borders = E_BOTH; |
27 | } else if (strcmp(argv[0], "smart") == 0) { | 20 | } else if (strcmp(argv[0], "smart") == 0) { |
28 | config->hide_edge_borders = E_SMART; | 21 | config->hide_edge_borders = E_SMART; |
22 | } else if (strcmp(argv[0], "smart_no_gaps") == 0) { | ||
23 | config->hide_edge_borders = E_SMART_NO_GAPS; | ||
29 | } else { | 24 | } else { |
30 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", | 25 | return cmd_results_new(CMD_INVALID, "hide_edge_borders", |
31 | "Expected 'hide_edge_borders " | 26 | "Expected 'hide_edge_borders " |
32 | "<none|vertical|horizontal|both|smart>'"); | 27 | "<none|vertical|horizontal|both|smart|smart_no_gaps>'"); |
33 | } | 28 | } |
29 | config->saved_edge_borders = config->hide_edge_borders; | ||
34 | 30 | ||
35 | root_for_each_container(_configure_view, NULL); | 31 | arrange_root(); |
36 | 32 | ||
37 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 33 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
38 | } | 34 | } |
diff --git a/sway/commands/smart_borders.c b/sway/commands/smart_borders.c new file mode 100644 index 00000000..fcb4040e --- /dev/null +++ b/sway/commands/smart_borders.c | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "sway/commands.h" | ||
2 | #include "sway/config.h" | ||
3 | #include "sway/tree/arrange.h" | ||
4 | #include "sway/tree/view.h" | ||
5 | #include "util.h" | ||
6 | |||
7 | struct cmd_results *cmd_smart_borders(int argc, char **argv) { | ||
8 | struct cmd_results *error = NULL; | ||
9 | if ((error = checkarg(argc, "smart_borders", EXPECTED_EQUAL_TO, 1))) { | ||
10 | return error; | ||
11 | } | ||
12 | |||
13 | enum edge_border_types saved = config->hide_edge_borders; | ||
14 | if (strcmp(argv[0], "no_gaps") == 0) { | ||
15 | config->hide_edge_borders = E_SMART_NO_GAPS; | ||
16 | } else { | ||
17 | config->hide_edge_borders = parse_boolean(argv[0], true) ? | ||
18 | E_SMART : config->saved_edge_borders; | ||
19 | } | ||
20 | config->saved_edge_borders = saved; | ||
21 | |||
22 | arrange_root(); | ||
23 | |||
24 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | ||
25 | } | ||
diff --git a/sway/config.c b/sway/config.c index 1e08559d..048b57de 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -249,6 +249,7 @@ static void config_defaults(struct sway_config *config) { | |||
249 | config->border_thickness = 2; | 249 | config->border_thickness = 2; |
250 | config->floating_border_thickness = 2; | 250 | config->floating_border_thickness = 2; |
251 | config->hide_edge_borders = E_NONE; | 251 | config->hide_edge_borders = E_NONE; |
252 | config->saved_edge_borders = E_NONE; | ||
252 | 253 | ||
253 | // border colors | 254 | // border colors |
254 | set_color(config->border_colors.focused.border, 0x4C7899); | 255 | set_color(config->border_colors.focused.border, 0x4C7899); |
diff --git a/sway/meson.build b/sway/meson.build index 6eb9a9d7..ec6546a2 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -78,6 +78,7 @@ sway_sources = files( | |||
78 | 'commands/seat/fallback.c', | 78 | 'commands/seat/fallback.c', |
79 | 'commands/set.c', | 79 | 'commands/set.c', |
80 | 'commands/show_marks.c', | 80 | 'commands/show_marks.c', |
81 | 'commands/smart_borders.c', | ||
81 | 'commands/smart_gaps.c', | 82 | 'commands/smart_gaps.c', |
82 | 'commands/split.c', | 83 | 'commands/split.c', |
83 | 'commands/sticky.c', | 84 | 'commands/sticky.c', |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index aa5b38ab..3202d517 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -431,7 +431,7 @@ The default colors are: | |||
431 | Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the | 431 | Changes the _inner_ or _outer_ gaps for either _all_ workspaces or the |
432 | _current_ workspace. | 432 | _current_ workspace. |
433 | 433 | ||
434 | *hide\_edge\_borders* none|vertical|horizontal|both|smart | 434 | *hide\_edge\_borders* none|vertical|horizontal|both|smart|smart\_no\_gaps |
435 | Hides window borders adjacent to the screen edges. Default is _none_. | 435 | Hides window borders adjacent to the screen edges. Default is _none_. |
436 | 436 | ||
437 | *input* <input\_device> <input-subcommands...> | 437 | *input* <input\_device> <input-subcommands...> |
@@ -456,6 +456,12 @@ The default colors are: | |||
456 | *kill* | 456 | *kill* |
457 | Kills (closes) the currently focused container and all of its children. | 457 | Kills (closes) the currently focused container and all of its children. |
458 | 458 | ||
459 | *smart\_borders* on|no\_gaps|off | ||
460 | If smart\_borders are _on_, borders will only be enabled if the workspace | ||
461 | only has one visible child (identical to _hide\_edge\_borders_ smart). If | ||
462 | smart\_borders is set to _no\_gaps_, borders will only be enabled if the | ||
463 | workspace only has one visible child and gaps greater than zero. | ||
464 | |||
459 | *smart\_gaps* on|off | 465 | *smart\_gaps* on|off |
460 | If smart\_gaps are _on_ gaps will only be enabled if a workspace has more | 466 | If smart\_gaps are _on_ gaps will only be enabled if a workspace has more |
461 | than one child. | 467 | than one child. |
diff --git a/sway/tree/view.c b/sway/tree/view.c index 3b271159..ca5e6ab0 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c | |||
@@ -179,6 +179,17 @@ bool view_is_only_visible(struct sway_view *view) { | |||
179 | return only_view; | 179 | return only_view; |
180 | } | 180 | } |
181 | 181 | ||
182 | static bool gaps_to_edge(struct sway_view *view) { | ||
183 | struct sway_container *con = view->container; | ||
184 | while (con) { | ||
185 | if (con->current_gaps > 0) { | ||
186 | return true; | ||
187 | } | ||
188 | con = con->parent; | ||
189 | } | ||
190 | return view->container->workspace->current_gaps > 0; | ||
191 | } | ||
192 | |||
182 | void view_autoconfigure(struct sway_view *view) { | 193 | void view_autoconfigure(struct sway_view *view) { |
183 | if (!view->container->workspace) { | 194 | if (!view->container->workspace) { |
184 | // Hidden in the scratchpad | 195 | // Hidden in the scratchpad |
@@ -196,23 +207,27 @@ void view_autoconfigure(struct sway_view *view) { | |||
196 | 207 | ||
197 | struct sway_workspace *ws = view->container->workspace; | 208 | struct sway_workspace *ws = view->container->workspace; |
198 | struct sway_container *con = view->container; | 209 | struct sway_container *con = view->container; |
199 | bool other_views = config->hide_edge_borders == E_SMART ? | 210 | |
200 | !view_is_only_visible(view) : false; | 211 | bool smart = config->hide_edge_borders == E_SMART || |
212 | config->hide_edge_borders == E_SMART_NO_GAPS; | ||
213 | bool other_views = smart && !view_is_only_visible(view); | ||
214 | bool no_gaps = config->hide_edge_borders != E_SMART_NO_GAPS | ||
215 | || !gaps_to_edge(view); | ||
201 | 216 | ||
202 | view->border_top = view->border_bottom = true; | 217 | view->border_top = view->border_bottom = true; |
203 | view->border_left = view->border_right = true; | 218 | view->border_left = view->border_right = true; |
204 | if (config->hide_edge_borders == E_BOTH | 219 | if (config->hide_edge_borders == E_BOTH |
205 | || config->hide_edge_borders == E_VERTICAL | 220 | || config->hide_edge_borders == E_VERTICAL |
206 | || (config->hide_edge_borders == E_SMART && !other_views)) { | 221 | || (smart && !other_views && no_gaps)) { |
207 | view->border_left = con->x != ws->x; | 222 | view->border_left = con->x - con->current_gaps != ws->x; |
208 | int right_x = con->x + con->width; | 223 | int right_x = con->x + con->width + con->current_gaps; |
209 | view->border_right = right_x != ws->x + ws->width; | 224 | view->border_right = right_x != ws->x + ws->width; |
210 | } | 225 | } |
211 | if (config->hide_edge_borders == E_BOTH | 226 | if (config->hide_edge_borders == E_BOTH |
212 | || config->hide_edge_borders == E_HORIZONTAL | 227 | || config->hide_edge_borders == E_HORIZONTAL |
213 | || (config->hide_edge_borders == E_SMART && !other_views)) { | 228 | || (smart && !other_views && no_gaps)) { |
214 | view->border_top = con->y != ws->y; | 229 | view->border_top = con->y - con->current_gaps != ws->y; |
215 | int bottom_y = con->y + con->height; | 230 | int bottom_y = con->y + con->height + con->current_gaps; |
216 | view->border_bottom = bottom_y != ws->y + ws->height; | 231 | view->border_bottom = bottom_y != ws->y + ws->height; |
217 | } | 232 | } |
218 | 233 | ||