diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-08-25 20:07:37 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-25 20:07:37 -0400 |
commit | 1a30c50ef40e918942f96c9a399f9bf94c1c0116 (patch) | |
tree | 6bb0cd51d006de03535d4019d05c6787e8dd17aa /sway/tree | |
parent | Merge pull request #2512 from apreiml/workspace_move_wrap (diff) | |
parent | Make separate gaps functions per container type (diff) | |
download | sway-1a30c50ef40e918942f96c9a399f9bf94c1c0116.tar.gz sway-1a30c50ef40e918942f96c9a399f9bf94c1c0116.tar.zst sway-1a30c50ef40e918942f96c9a399f9bf94c1c0116.zip |
Merge pull request #2488 from RyanDwyer/separate-gaps-functions
Make separate gaps functions per container type
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/arrange.c | 54 | ||||
-rw-r--r-- | sway/tree/container.c | 33 | ||||
-rw-r--r-- | sway/tree/layout.c | 5 | ||||
-rw-r--r-- | sway/tree/workspace.c | 35 |
4 files changed, 78 insertions, 49 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index a4b058f3..0da61a4c 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c | |||
@@ -39,7 +39,7 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
39 | child->width = parent->width; | 39 | child->width = parent->width; |
40 | } | 40 | } |
41 | } | 41 | } |
42 | remove_gaps(child); | 42 | container_remove_gaps(child); |
43 | total_width += child->width; | 43 | total_width += child->width; |
44 | } | 44 | } |
45 | double scale = parent->width / total_width; | 45 | double scale = parent->width / total_width; |
@@ -62,7 +62,7 @@ static void apply_horiz_layout(struct sway_container *parent) { | |||
62 | if (i == num_children - 1) { | 62 | if (i == num_children - 1) { |
63 | child->width = parent->x + parent->width - child->x; | 63 | child->width = parent->x + parent->width - child->x; |
64 | } | 64 | } |
65 | add_gaps(child); | 65 | container_add_gaps(child); |
66 | } | 66 | } |
67 | } | 67 | } |
68 | 68 | ||
@@ -91,7 +91,7 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
91 | child->height = parent_height; | 91 | child->height = parent_height; |
92 | } | 92 | } |
93 | } | 93 | } |
94 | remove_gaps(child); | 94 | container_remove_gaps(child); |
95 | total_height += child->height; | 95 | total_height += child->height; |
96 | } | 96 | } |
97 | double scale = parent_height / total_height; | 97 | double scale = parent_height / total_height; |
@@ -115,7 +115,7 @@ static void apply_vert_layout(struct sway_container *parent) { | |||
115 | child->height = | 115 | child->height = |
116 | parent->y + parent_offset + parent_height - child->y; | 116 | parent->y + parent_offset + parent_height - child->y; |
117 | } | 117 | } |
118 | add_gaps(child); | 118 | container_add_gaps(child); |
119 | } | 119 | } |
120 | } | 120 | } |
121 | 121 | ||
@@ -133,12 +133,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { | |||
133 | size_t parent_height = parent->height - parent_offset; | 133 | size_t parent_height = parent->height - parent_offset; |
134 | for (int i = 0; i < parent->children->length; ++i) { | 134 | for (int i = 0; i < parent->children->length; ++i) { |
135 | struct sway_container *child = parent->children->items[i]; | 135 | struct sway_container *child = parent->children->items[i]; |
136 | remove_gaps(child); | 136 | container_remove_gaps(child); |
137 | child->x = parent->x; | 137 | child->x = parent->x; |
138 | child->y = parent->y + parent_offset; | 138 | child->y = parent->y + parent_offset; |
139 | child->width = parent->width; | 139 | child->width = parent->width; |
140 | child->height = parent_height; | 140 | child->height = parent_height; |
141 | add_gaps(child); | 141 | container_add_gaps(child); |
142 | } | 142 | } |
143 | } | 143 | } |
144 | 144 | ||
@@ -205,7 +205,7 @@ static void arrange_workspace(struct sway_container *workspace) { | |||
205 | struct wlr_box *area = &output->sway_output->usable_area; | 205 | struct wlr_box *area = &output->sway_output->usable_area; |
206 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", | 206 | wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", |
207 | area->width, area->height, area->x, area->y); | 207 | area->width, area->height, area->x, area->y); |
208 | remove_gaps(workspace); | 208 | workspace_remove_gaps(workspace); |
209 | 209 | ||
210 | double prev_x = workspace->x; | 210 | double prev_x = workspace->x; |
211 | double prev_y = workspace->y; | 211 | double prev_y = workspace->y; |
@@ -230,7 +230,7 @@ static void arrange_workspace(struct sway_container *workspace) { | |||
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | add_gaps(workspace); | 233 | workspace_add_gaps(workspace); |
234 | container_set_dirty(workspace); | 234 | container_set_dirty(workspace); |
235 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, | 235 | wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, |
236 | workspace->x, workspace->y); | 236 | workspace->x, workspace->y); |
@@ -314,41 +314,3 @@ void arrange_windows(struct sway_container *container) { | |||
314 | break; | 314 | break; |
315 | } | 315 | } |
316 | } | 316 | } |
317 | |||
318 | void remove_gaps(struct sway_container *c) { | ||
319 | if (c->current_gaps == 0) { | ||
320 | wlr_log(WLR_DEBUG, "Removing gaps: not gapped: %p", c); | ||
321 | return; | ||
322 | } | ||
323 | |||
324 | c->width += c->current_gaps * 2; | ||
325 | c->height += c->current_gaps * 2; | ||
326 | c->x -= c->current_gaps; | ||
327 | c->y -= c->current_gaps; | ||
328 | |||
329 | c->current_gaps = 0; | ||
330 | |||
331 | wlr_log(WLR_DEBUG, "Removing gaps %p", c); | ||
332 | } | ||
333 | |||
334 | void add_gaps(struct sway_container *c) { | ||
335 | if (c->current_gaps > 0 || c->type == C_CONTAINER) { | ||
336 | wlr_log(WLR_DEBUG, "Not adding gaps: %p", c); | ||
337 | return; | ||
338 | } | ||
339 | |||
340 | if (c->type == C_WORKSPACE && | ||
341 | !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) { | ||
342 | return; | ||
343 | } | ||
344 | |||
345 | double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; | ||
346 | |||
347 | c->x += gaps; | ||
348 | c->y += gaps; | ||
349 | c->width -= 2 * gaps; | ||
350 | c->height -= 2 * gaps; | ||
351 | c->current_gaps = gaps; | ||
352 | |||
353 | wlr_log(WLR_DEBUG, "Adding gaps: %p", c); | ||
354 | } | ||
diff --git a/sway/tree/container.c b/sway/tree/container.c index 5721c35c..f9611342 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -1124,7 +1124,38 @@ void container_discover_outputs(struct sway_container *con) { | |||
1124 | } | 1124 | } |
1125 | } | 1125 | } |
1126 | 1126 | ||
1127 | void container_remove_gaps(struct sway_container *c) { | ||
1128 | if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW, | ||
1129 | "Expected a container or view")) { | ||
1130 | return; | ||
1131 | } | ||
1132 | if (c->current_gaps == 0) { | ||
1133 | return; | ||
1134 | } | ||
1135 | |||
1136 | c->width += c->current_gaps * 2; | ||
1137 | c->height += c->current_gaps * 2; | ||
1138 | c->x -= c->current_gaps; | ||
1139 | c->y -= c->current_gaps; | ||
1140 | c->current_gaps = 0; | ||
1141 | } | ||
1142 | |||
1143 | void container_add_gaps(struct sway_container *c) { | ||
1144 | if (!sway_assert(c->type == C_CONTAINER || c->type == C_VIEW, | ||
1145 | "Expected a container or view")) { | ||
1146 | return; | ||
1147 | } | ||
1148 | if (c->current_gaps > 0 || c->type != C_VIEW) { | ||
1149 | return; | ||
1150 | } | ||
1151 | |||
1152 | c->current_gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; | ||
1153 | c->x += c->current_gaps; | ||
1154 | c->y += c->current_gaps; | ||
1155 | c->width -= 2 * c->current_gaps; | ||
1156 | c->height -= 2 * c->current_gaps; | ||
1157 | } | ||
1158 | |||
1127 | int container_sibling_index(const struct sway_container *child) { | 1159 | int container_sibling_index(const struct sway_container *child) { |
1128 | return list_find(child->parent->children, child); | 1160 | return list_find(child->parent->children, child); |
1129 | } | 1161 | } |
1130 | |||
diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 601d0e91..85fe7643 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c | |||
@@ -218,7 +218,8 @@ struct sway_container *container_split(struct sway_container *child, | |||
218 | 218 | ||
219 | wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child); | 219 | wlr_log(WLR_DEBUG, "creating container %p around %p", cont, child); |
220 | 220 | ||
221 | remove_gaps(child); | 221 | child->type == C_WORKSPACE ? workspace_remove_gaps(child) |
222 | : container_remove_gaps(child); | ||
222 | 223 | ||
223 | cont->prev_split_layout = L_NONE; | 224 | cont->prev_split_layout = L_NONE; |
224 | cont->width = child->width; | 225 | cont->width = child->width; |
@@ -229,7 +230,7 @@ struct sway_container *container_split(struct sway_container *child, | |||
229 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); | 230 | struct sway_seat *seat = input_manager_get_default_seat(input_manager); |
230 | bool set_focus = (seat_get_focus(seat) == child); | 231 | bool set_focus = (seat_get_focus(seat) == child); |
231 | 232 | ||
232 | add_gaps(cont); | 233 | container_add_gaps(cont); |
233 | 234 | ||
234 | if (child->type == C_WORKSPACE) { | 235 | if (child->type == C_WORKSPACE) { |
235 | struct sway_container *workspace = child; | 236 | struct sway_container *workspace = child; |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 93c4b3d3..d930826e 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -665,3 +665,38 @@ void workspace_add_floating(struct sway_container *workspace, | |||
665 | container_set_dirty(workspace); | 665 | container_set_dirty(workspace); |
666 | container_set_dirty(con); | 666 | container_set_dirty(con); |
667 | } | 667 | } |
668 | |||
669 | void workspace_remove_gaps(struct sway_container *ws) { | ||
670 | if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { | ||
671 | return; | ||
672 | } | ||
673 | if (ws->current_gaps == 0) { | ||
674 | return; | ||
675 | } | ||
676 | |||
677 | ws->width += ws->current_gaps * 2; | ||
678 | ws->height += ws->current_gaps * 2; | ||
679 | ws->x -= ws->current_gaps; | ||
680 | ws->y -= ws->current_gaps; | ||
681 | ws->current_gaps = 0; | ||
682 | } | ||
683 | |||
684 | void workspace_add_gaps(struct sway_container *ws) { | ||
685 | if (!sway_assert(ws->type == C_WORKSPACE, "Expected a workspace")) { | ||
686 | return; | ||
687 | } | ||
688 | if (ws->current_gaps > 0) { | ||
689 | return; | ||
690 | } | ||
691 | bool should_apply = | ||
692 | config->edge_gaps || (config->smart_gaps && ws->children->length > 1); | ||
693 | if (!should_apply) { | ||
694 | return; | ||
695 | } | ||
696 | |||
697 | ws->current_gaps = ws->has_gaps ? ws->gaps_inner : config->gaps_inner; | ||
698 | ws->x += ws->current_gaps; | ||
699 | ws->y += ws->current_gaps; | ||
700 | ws->width -= 2 * ws->current_gaps; | ||
701 | ws->height -= 2 * ws->current_gaps; | ||
702 | } | ||