aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorLibravatar Pedro CĂ´rte-Real <pedro@pedrocr.net>2019-07-06 11:57:32 +0100
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2019-07-15 23:46:27 -0400
commitd0233af3b39475b47be4248846536811ddca2624 (patch)
treeacc61150bd9e6bc1a69c8e7f38a700e8a9e8b2ed /sway/tree/arrange.c
parentUse -fmacro-prefix-map to strip build path (diff)
downloadsway-d0233af3b39475b47be4248846536811ddca2624.tar.gz
sway-d0233af3b39475b47be4248846536811ddca2624.tar.zst
sway-d0233af3b39475b47be4248846536811ddca2624.zip
Rework gaps code to be simpler and correct
Instead of tracking gaps per child apply gaps in two logical places: 1. In tiled containers use the layout code to add the gaps between windows. This is much simpler and guarantees that the sizing of children is correct. 2. In the workspace itself apply all the gaps around the edge. Here we're in the correct position to size inner and outer gaps correctly and decide on smart gaps in a single location. Fixes #4296
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c55
1 files changed, 41 insertions, 14 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index dd0a72cd..caafb1af 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -52,23 +52,39 @@ static void apply_horiz_layout(list_t *children, struct wlr_box *parent) {
52 child->width_fraction /= total_width_fraction; 52 child->width_fraction /= total_width_fraction;
53 } 53 }
54 54
55 // Calculate gap size
56 double inner_gap = 0;
57 struct sway_container *child = children->items[0];
58 struct sway_workspace *ws = child->workspace;
59 if (ws) {
60 inner_gap = ws->gaps_inner;
61 }
62 // Descendants of tabbed/stacked containers don't have gaps
63 struct sway_container *temp = child;
64 while (temp) {
65 enum sway_container_layout layout = container_parent_layout(temp);
66 if (layout == L_TABBED || layout == L_STACKED) {
67 inner_gap = 0;
68 }
69 temp = temp->parent;
70 }
71 double child_total_width = parent->width - inner_gap * (children->length - 1);
72
55 // Resize windows 73 // Resize windows
56 sway_log(SWAY_DEBUG, "Arranging %p horizontally", parent); 74 sway_log(SWAY_DEBUG, "Arranging %p horizontally", parent);
57 double child_x = parent->x; 75 double child_x = parent->x;
58 for (int i = 0; i < children->length; ++i) { 76 for (int i = 0; i < children->length; ++i) {
59 struct sway_container *child = children->items[i]; 77 struct sway_container *child = children->items[i];
60 container_remove_gaps(child);
61 child->x = child_x; 78 child->x = child_x;
62 child->y = parent->y; 79 child->y = parent->y;
63 child->width = floor(child->width_fraction * parent->width); 80 child->width = floor(child->width_fraction * child_total_width);
64 child->height = parent->height; 81 child->height = parent->height;
65 child_x += child->width; 82 child_x += child->width + inner_gap;
66 83
67 // Make last child use remaining width of parent 84 // Make last child use remaining width of parent
68 if (i == children->length - 1) { 85 if (i == children->length - 1) {
69 child->width = parent->x + parent->width - child->x; 86 child->width = parent->x + parent->width - child->x;
70 } 87 }
71 container_add_gaps(child);
72 } 88 }
73} 89}
74 90
@@ -111,23 +127,39 @@ static void apply_vert_layout(list_t *children, struct wlr_box *parent) {
111 child->height_fraction /= total_height_fraction; 127 child->height_fraction /= total_height_fraction;
112 } 128 }
113 129
114 // Resize 130 // Calculate gap size
131 double inner_gap = 0;
132 struct sway_container *child = children->items[0];
133 struct sway_workspace *ws = child->workspace;
134 if (ws) {
135 inner_gap = ws->gaps_inner;
136 }
137 // Descendants of tabbed/stacked containers don't have gaps
138 struct sway_container *temp = child;
139 while (temp) {
140 enum sway_container_layout layout = container_parent_layout(temp);
141 if (layout == L_TABBED || layout == L_STACKED) {
142 inner_gap = 0;
143 }
144 temp = temp->parent;
145 }
146 double child_total_height = parent->height - inner_gap * (children->length - 1);
147
148 // Resize windows
115 sway_log(SWAY_DEBUG, "Arranging %p vertically", parent); 149 sway_log(SWAY_DEBUG, "Arranging %p vertically", parent);
116 double child_y = parent->y; 150 double child_y = parent->y;
117 for (int i = 0; i < children->length; ++i) { 151 for (int i = 0; i < children->length; ++i) {
118 struct sway_container *child = children->items[i]; 152 struct sway_container *child = children->items[i];
119 container_remove_gaps(child);
120 child->x = parent->x; 153 child->x = parent->x;
121 child->y = child_y; 154 child->y = child_y;
122 child->width = parent->width; 155 child->width = parent->width;
123 child->height = floor(child->height_fraction * parent->height); 156 child->height = floor(child->height_fraction * child_total_height);
124 child_y += child->height; 157 child_y += child->height + inner_gap;
125 158
126 // Make last child use remaining height of parent 159 // Make last child use remaining height of parent
127 if (i == children->length - 1) { 160 if (i == children->length - 1) {
128 child->height = parent->y + parent->height - child->y; 161 child->height = parent->y + parent->height - child->y;
129 } 162 }
130 container_add_gaps(child);
131 } 163 }
132} 164}
133 165
@@ -138,12 +170,10 @@ static void apply_tabbed_layout(list_t *children, struct wlr_box *parent) {
138 for (int i = 0; i < children->length; ++i) { 170 for (int i = 0; i < children->length; ++i) {
139 struct sway_container *child = children->items[i]; 171 struct sway_container *child = children->items[i];
140 int parent_offset = child->view ? 0 : container_titlebar_height(); 172 int parent_offset = child->view ? 0 : container_titlebar_height();
141 container_remove_gaps(child);
142 child->x = parent->x; 173 child->x = parent->x;
143 child->y = parent->y + parent_offset; 174 child->y = parent->y + parent_offset;
144 child->width = parent->width; 175 child->width = parent->width;
145 child->height = parent->height - parent_offset; 176 child->height = parent->height - parent_offset;
146 container_add_gaps(child);
147 } 177 }
148} 178}
149 179
@@ -155,12 +185,10 @@ static void apply_stacked_layout(list_t *children, struct wlr_box *parent) {
155 struct sway_container *child = children->items[i]; 185 struct sway_container *child = children->items[i];
156 int parent_offset = child->view ? 0 : 186 int parent_offset = child->view ? 0 :
157 container_titlebar_height() * children->length; 187 container_titlebar_height() * children->length;
158 container_remove_gaps(child);
159 child->x = parent->x; 188 child->x = parent->x;
160 child->y = parent->y + parent_offset; 189 child->y = parent->y + parent_offset;
161 child->width = parent->width; 190 child->width = parent->width;
162 child->height = parent->height - parent_offset; 191 child->height = parent->height - parent_offset;
163 container_add_gaps(child);
164 } 192 }
165} 193}
166 194
@@ -226,7 +254,6 @@ void arrange_workspace(struct sway_workspace *workspace) {
226 struct wlr_box *area = &output->usable_area; 254 struct wlr_box *area = &output->usable_area;
227 sway_log(SWAY_DEBUG, "Usable area for ws: %dx%d@%d,%d", 255 sway_log(SWAY_DEBUG, "Usable area for ws: %dx%d@%d,%d",
228 area->width, area->height, area->x, area->y); 256 area->width, area->height, area->x, area->y);
229 workspace_remove_gaps(workspace);
230 257
231 bool first_arrange = workspace->width == 0 && workspace->height == 0; 258 bool first_arrange = workspace->width == 0 && workspace->height == 0;
232 double prev_x = workspace->x; 259 double prev_x = workspace->x;