aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/workspace.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-07 22:44:11 -0500
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-11-07 22:44:11 -0500
commit9e8aa3953098adb6175c26aebd984a32a2beccb0 (patch)
treeac64adf9f2720ddbb2476810f6ec05ec2a85a4ae /sway/tree/workspace.c
parentAdd focus_follows_mouse always. (#3081) (diff)
downloadsway-9e8aa3953098adb6175c26aebd984a32a2beccb0.tar.gz
sway-9e8aa3953098adb6175c26aebd984a32a2beccb0.tar.zst
sway-9e8aa3953098adb6175c26aebd984a32a2beccb0.zip
Implement per side and per direction outer gaps
This introduces the following command extensions from `i3-gaps`: * `gaps horizontal|vertical|top|right|bottom|left <amount>` * `gaps horizontal|vertical|top|right|bottom|left all|current set|plus|minus <amount>` * `workspace <ws> gaps horizontal|vertical|top|right|bottom|left <amount>` `inner` and `outer` are also still available as options for all three of the above commands. `outer` now acts as a shorthand to set/alter all sides. Additionally, this fixes two bugs with the prevention of invalid gap configurations for workspace configs: 1. If outer gaps were not set and inner gaps were, the outer gaps would be snapped to the negation of the inner gaps due to `INT_MIN` being less than the negation. This took precedence over the default outer gaps. 2. Similarly, if inner gaps were not set and outer gaps were, inner gaps would be set to zero, which would take precedence over the default inner gaps. Fixing both of the above items also requires checking the gaps again when creating a workspace since the default outer gaps can be smaller than the negation of the workspace specific inner gaps.
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 05cda5c0..93ce50de 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -49,6 +49,21 @@ struct sway_output *workspace_get_initial_output(const char *name) {
49 return focus->output; 49 return focus->output;
50} 50}
51 51
52static void prevent_invalid_outer_gaps(struct sway_workspace *ws) {
53 if (ws->gaps_outer.top < -ws->gaps_inner) {
54 ws->gaps_outer.top = -ws->gaps_inner;
55 }
56 if (ws->gaps_outer.right < -ws->gaps_inner) {
57 ws->gaps_outer.right = -ws->gaps_inner;
58 }
59 if (ws->gaps_outer.bottom < -ws->gaps_inner) {
60 ws->gaps_outer.bottom = -ws->gaps_inner;
61 }
62 if (ws->gaps_outer.left < -ws->gaps_inner) {
63 ws->gaps_outer.left = -ws->gaps_inner;
64 }
65}
66
52struct sway_workspace *workspace_create(struct sway_output *output, 67struct sway_workspace *workspace_create(struct sway_output *output,
53 const char *name) { 68 const char *name) {
54 if (output == NULL) { 69 if (output == NULL) {
@@ -77,12 +92,24 @@ struct sway_workspace *workspace_create(struct sway_output *output,
77 if (name) { 92 if (name) {
78 struct workspace_config *wsc = workspace_find_config(name); 93 struct workspace_config *wsc = workspace_find_config(name);
79 if (wsc) { 94 if (wsc) {
80 if (wsc->gaps_outer != INT_MIN) { 95 if (wsc->gaps_outer.top != INT_MIN) {
81 ws->gaps_outer = wsc->gaps_outer; 96 ws->gaps_outer.top = wsc->gaps_outer.top;
97 }
98 if (wsc->gaps_outer.right != INT_MIN) {
99 ws->gaps_outer.right = wsc->gaps_outer.right;
100 }
101 if (wsc->gaps_outer.bottom != INT_MIN) {
102 ws->gaps_outer.bottom = wsc->gaps_outer.bottom;
103 }
104 if (wsc->gaps_outer.left != INT_MIN) {
105 ws->gaps_outer.left = wsc->gaps_outer.left;
82 } 106 }
83 if (wsc->gaps_inner != INT_MIN) { 107 if (wsc->gaps_inner != INT_MIN) {
84 ws->gaps_inner = wsc->gaps_inner; 108 ws->gaps_inner = wsc->gaps_inner;
85 } 109 }
110 // Since default outer gaps can be smaller than the negation of
111 // workspace specific inner gaps, check outer gaps again
112 prevent_invalid_outer_gaps(ws);
86 } 113 }
87 } 114 }
88 115
@@ -615,19 +642,25 @@ void workspace_insert_tiling(struct sway_workspace *workspace,
615} 642}
616 643
617void workspace_remove_gaps(struct sway_workspace *ws) { 644void workspace_remove_gaps(struct sway_workspace *ws) {
618 if (ws->current_gaps == 0) { 645 if (ws->current_gaps.top == 0 && ws->current_gaps.right == 0 &&
646 ws->current_gaps.bottom == 0 && ws->current_gaps.left == 0) {
619 return; 647 return;
620 } 648 }
621 649
622 ws->width += ws->current_gaps * 2; 650 ws->width += ws->current_gaps.left + ws->current_gaps.right;
623 ws->height += ws->current_gaps * 2; 651 ws->height += ws->current_gaps.top + ws->current_gaps.bottom;
624 ws->x -= ws->current_gaps; 652 ws->x -= ws->current_gaps.left;
625 ws->y -= ws->current_gaps; 653 ws->y -= ws->current_gaps.top;
626 ws->current_gaps = 0; 654
655 ws->current_gaps.top = 0;
656 ws->current_gaps.right = 0;
657 ws->current_gaps.bottom = 0;
658 ws->current_gaps.left = 0;
627} 659}
628 660
629void workspace_add_gaps(struct sway_workspace *ws) { 661void workspace_add_gaps(struct sway_workspace *ws) {
630 if (ws->current_gaps > 0) { 662 if (ws->current_gaps.top > 0 || ws->current_gaps.right > 0 ||
663 ws->current_gaps.bottom > 0 || ws->current_gaps.left > 0) {
631 return; 664 return;
632 } 665 }
633 if (config->smart_gaps) { 666 if (config->smart_gaps) {
@@ -643,18 +676,20 @@ void workspace_add_gaps(struct sway_workspace *ws) {
643 } 676 }
644 677
645 ws->current_gaps = ws->gaps_outer; 678 ws->current_gaps = ws->gaps_outer;
646
647 if (ws->layout == L_TABBED || ws->layout == L_STACKED) { 679 if (ws->layout == L_TABBED || ws->layout == L_STACKED) {
648 // We have to add inner gaps for this, because children of tabbed and 680 // We have to add inner gaps for this, because children of tabbed and
649 // stacked containers don't apply their own gaps - they assume the 681 // stacked containers don't apply their own gaps - they assume the
650 // tabbed/stacked container is using gaps. 682 // tabbed/stacked container is using gaps.
651 ws->current_gaps += ws->gaps_inner; 683 ws->current_gaps.top += ws->gaps_inner;
684 ws->current_gaps.right += ws->gaps_inner;
685 ws->current_gaps.bottom += ws->gaps_inner;
686 ws->current_gaps.left += ws->gaps_inner;
652 } 687 }
653 688
654 ws->x += ws->current_gaps; 689 ws->x += ws->current_gaps.left;
655 ws->y += ws->current_gaps; 690 ws->y += ws->current_gaps.top;
656 ws->width -= 2 * ws->current_gaps; 691 ws->width -= ws->current_gaps.left + ws->current_gaps.right;
657 ws->height -= 2 * ws->current_gaps; 692 ws->height -= ws->current_gaps.top + ws->current_gaps.bottom;
658} 693}
659 694
660struct sway_container *workspace_split(struct sway_workspace *workspace, 695struct sway_container *workspace_split(struct sway_workspace *workspace,