diff options
author | 2021-10-28 15:31:23 +0200 | |
---|---|---|
committer | 2021-10-29 13:37:58 +0200 | |
commit | 9969de9e00a1ca89ded85d418a72c4ebbce91331 (patch) | |
tree | 28cf0f1d6e77e7e99a0df51c165e769a262b6920 | |
parent | fix cursor input for layer-shell surfaces (diff) | |
download | sway-9969de9e00a1ca89ded85d418a72c4ebbce91331.tar.gz sway-9969de9e00a1ca89ded85d418a72c4ebbce91331.tar.zst sway-9969de9e00a1ca89ded85d418a72c4ebbce91331.zip |
Add smart_gaps inverse_outer command
Add a subcommand for `smart_gaps` that enables outer gaps only
on workspaces with exactly one visible child.
Also add documentation for `smart_gaps toggle`.
-rw-r--r-- | include/sway/config.h | 8 | ||||
-rw-r--r-- | sway/commands/smart_gaps.c | 7 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/sway.5.scd | 5 | ||||
-rw-r--r-- | sway/tree/workspace.c | 42 |
5 files changed, 44 insertions, 20 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 46dd4ffe..660245c1 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -283,6 +283,12 @@ struct side_gaps { | |||
283 | int left; | 283 | int left; |
284 | }; | 284 | }; |
285 | 285 | ||
286 | enum smart_gaps_mode { | ||
287 | SMART_GAPS_OFF, | ||
288 | SMART_GAPS_ON, | ||
289 | SMART_GAPS_INVERSE_OUTER, | ||
290 | }; | ||
291 | |||
286 | /** | 292 | /** |
287 | * Stores configuration for a workspace, regardless of whether the workspace | 293 | * Stores configuration for a workspace, regardless of whether the workspace |
288 | * exists. | 294 | * exists. |
@@ -512,7 +518,7 @@ struct sway_config { | |||
512 | bool tiling_drag; | 518 | bool tiling_drag; |
513 | int tiling_drag_threshold; | 519 | int tiling_drag_threshold; |
514 | 520 | ||
515 | bool smart_gaps; | 521 | enum smart_gaps_mode smart_gaps; |
516 | int gaps_inner; | 522 | int gaps_inner; |
517 | struct side_gaps gaps_outer; | 523 | struct side_gaps gaps_outer; |
518 | 524 | ||
diff --git a/sway/commands/smart_gaps.c b/sway/commands/smart_gaps.c index b27f9ccd..a6d165dc 100644 --- a/sway/commands/smart_gaps.c +++ b/sway/commands/smart_gaps.c | |||
@@ -15,7 +15,12 @@ struct cmd_results *cmd_smart_gaps(int argc, char **argv) { | |||
15 | return error; | 15 | return error; |
16 | } | 16 | } |
17 | 17 | ||
18 | config->smart_gaps = parse_boolean(argv[0], config->smart_gaps); | 18 | if (strcmp(argv[0], "inverse_outer") == 0) { |
19 | config->smart_gaps = SMART_GAPS_INVERSE_OUTER; | ||
20 | } else { | ||
21 | config->smart_gaps = parse_boolean(argv[0], config->smart_gaps) | ||
22 | ? SMART_GAPS_ON : SMART_GAPS_OFF; | ||
23 | } | ||
19 | 24 | ||
20 | arrange_root(); | 25 | arrange_root(); |
21 | 26 | ||
diff --git a/sway/config.c b/sway/config.c index e3daacda..35837212 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -266,7 +266,7 @@ static void config_defaults(struct sway_config *config) { | |||
266 | config->tiling_drag = true; | 266 | config->tiling_drag = true; |
267 | config->tiling_drag_threshold = 9; | 267 | config->tiling_drag_threshold = 9; |
268 | 268 | ||
269 | config->smart_gaps = false; | 269 | config->smart_gaps = SMART_GAPS_OFF; |
270 | config->gaps_inner = 0; | 270 | config->gaps_inner = 0; |
271 | config->gaps_outer.top = 0; | 271 | config->gaps_outer.top = 0; |
272 | config->gaps_outer.right = 0; | 272 | config->gaps_outer.right = 0; |
diff --git a/sway/sway.5.scd b/sway/sway.5.scd index e8d3d606..ec34a56c 100644 --- a/sway/sway.5.scd +++ b/sway/sway.5.scd | |||
@@ -692,9 +692,10 @@ The default colors are: | |||
692 | borders will only be enabled if the workspace has more than one visible | 692 | borders will only be enabled if the workspace has more than one visible |
693 | child and gaps equal to zero. | 693 | child and gaps equal to zero. |
694 | 694 | ||
695 | *smart_gaps* on|off | 695 | *smart_gaps* on|off|toggle|inverse_outer |
696 | If smart_gaps are _on_ gaps will only be enabled if a workspace has more | 696 | If smart_gaps are _on_ gaps will only be enabled if a workspace has more |
697 | than one child. | 697 | than one child. If smart_gaps are _inverse_outer_ outer gaps will only |
698 | be enabled if a workspace has exactly one child. | ||
698 | 699 | ||
699 | *mark* --add|--replace [--toggle] <identifier> | 700 | *mark* --add|--replace [--toggle] <identifier> |
700 | Marks are arbitrary labels that can be used to identify certain windows and | 701 | Marks are arbitrary labels that can be used to identify certain windows and |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 8dd7789d..e3ff1513 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -844,24 +844,36 @@ struct sway_container *workspace_insert_tiling(struct sway_workspace *workspace, | |||
844 | return con; | 844 | return con; |
845 | } | 845 | } |
846 | 846 | ||
847 | bool workspace_has_single_visible_container(struct sway_workspace *ws) { | ||
848 | struct sway_seat *seat = input_manager_get_default_seat(); | ||
849 | struct sway_container *focus = | ||
850 | seat_get_focus_inactive_tiling(seat, ws); | ||
851 | if (focus && !focus->view) { | ||
852 | focus = seat_get_focus_inactive_view(seat, &focus->node); | ||
853 | } | ||
854 | return (focus && focus->view && view_ancestor_is_only_visible(focus->view)); | ||
855 | } | ||
856 | |||
847 | void workspace_add_gaps(struct sway_workspace *ws) { | 857 | void workspace_add_gaps(struct sway_workspace *ws) { |
848 | if (config->smart_gaps) { | 858 | if (config->smart_gaps == SMART_GAPS_ON |
849 | struct sway_seat *seat = input_manager_get_default_seat(); | 859 | && workspace_has_single_visible_container(ws)) { |
850 | struct sway_container *focus = | 860 | ws->current_gaps.top = 0; |
851 | seat_get_focus_inactive_tiling(seat, ws); | 861 | ws->current_gaps.right = 0; |
852 | if (focus && !focus->view) { | 862 | ws->current_gaps.bottom = 0; |
853 | focus = seat_get_focus_inactive_view(seat, &focus->node); | 863 | ws->current_gaps.left = 0; |
854 | } | 864 | return; |
855 | if (focus && focus->view && view_ancestor_is_only_visible(focus->view)) { | 865 | } |
856 | ws->current_gaps.top = 0; | 866 | |
857 | ws->current_gaps.right = 0; | 867 | if (config->smart_gaps == SMART_GAPS_INVERSE_OUTER |
858 | ws->current_gaps.bottom = 0; | 868 | && !workspace_has_single_visible_container(ws)) { |
859 | ws->current_gaps.left = 0; | 869 | ws->current_gaps.top = 0; |
860 | return; | 870 | ws->current_gaps.right = 0; |
861 | } | 871 | ws->current_gaps.bottom = 0; |
872 | ws->current_gaps.left = 0; | ||
873 | } else { | ||
874 | ws->current_gaps = ws->gaps_outer; | ||
862 | } | 875 | } |
863 | 876 | ||
864 | ws->current_gaps = ws->gaps_outer; | ||
865 | // Add inner gaps and make sure we don't turn out negative | 877 | // Add inner gaps and make sure we don't turn out negative |
866 | ws->current_gaps.top = fmax(0, ws->current_gaps.top + ws->gaps_inner); | 878 | ws->current_gaps.top = fmax(0, ws->current_gaps.top + ws->gaps_inner); |
867 | ws->current_gaps.right = fmax(0, ws->current_gaps.right + ws->gaps_inner); | 879 | ws->current_gaps.right = fmax(0, ws->current_gaps.right + ws->gaps_inner); |