diff options
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 65 |
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 | ||
52 | static 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 | |||
52 | struct sway_workspace *workspace_create(struct sway_output *output, | 67 | struct 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 | ||
617 | void workspace_remove_gaps(struct sway_workspace *ws) { | 644 | void 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 | ||
629 | void workspace_add_gaps(struct sway_workspace *ws) { | 661 | void 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 | ||
660 | struct sway_container *workspace_split(struct sway_workspace *workspace, | 695 | struct sway_container *workspace_split(struct sway_workspace *workspace, |