summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/desktop/output.c1
-rw-r--r--sway/desktop/render.c8
-rw-r--r--sway/desktop/xdg_shell.c1
-rw-r--r--sway/desktop/xdg_shell_v6.c1
-rw-r--r--sway/tree/arrange.c197
-rw-r--r--sway/tree/container.c4
-rw-r--r--sway/tree/root.c1
-rw-r--r--sway/tree/view.c35
8 files changed, 115 insertions, 133 deletions
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index bbebe453..c228979d 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -16,6 +16,7 @@
16#include "log.h" 16#include "log.h"
17#include "config.h" 17#include "config.h"
18#include "sway/config.h" 18#include "sway/config.h"
19#include "sway/desktop/transaction.h"
19#include "sway/input/input-manager.h" 20#include "sway/input/input-manager.h"
20#include "sway/input/seat.h" 21#include "sway/input/seat.h"
21#include "sway/layers.h" 22#include "sway/layers.h"
diff --git a/sway/desktop/render.c b/sway/desktop/render.c
index b5a10370..b52dd196 100644
--- a/sway/desktop/render.c
+++ b/sway/desktop/render.c
@@ -660,7 +660,7 @@ static void render_container_tabbed(struct sway_output *output,
660 pstate->swayc_width - width_gap_adjustment - tab_width * i; 660 pstate->swayc_width - width_gap_adjustment - tab_width * i;
661 } 661 }
662 662
663 render_titlebar(output, damage, child, x, cstate->swayc_y, tab_width, 663 render_titlebar(output, damage, child, x, pstate->swayc_y, tab_width,
664 colors, title_texture, marks_texture); 664 colors, title_texture, marks_texture);
665 665
666 if (child == current) { 666 if (child == current) {
@@ -721,9 +721,9 @@ static void render_container_stacked(struct sway_output *output,
721 marks_texture = view ? view->marks_unfocused : NULL; 721 marks_texture = view ? view->marks_unfocused : NULL;
722 } 722 }
723 723
724 int y = cstate->swayc_y + titlebar_height * i; 724 int y = pstate->swayc_y + titlebar_height * i;
725 render_titlebar(output, damage, child, cstate->swayc_x, y, 725 render_titlebar(output, damage, child, pstate->swayc_x, y,
726 cstate->swayc_width, colors, title_texture, marks_texture); 726 pstate->swayc_width, colors, title_texture, marks_texture);
727 727
728 if (child == current) { 728 if (child == current) {
729 current_colors = colors; 729 current_colors = colors;
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 7d1824f1..587deb0f 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -8,6 +8,7 @@
8#include "log.h" 8#include "log.h"
9#include "sway/decoration.h" 9#include "sway/decoration.h"
10#include "sway/desktop.h" 10#include "sway/desktop.h"
11#include "sway/desktop/transaction.h"
11#include "sway/input/input-manager.h" 12#include "sway/input/input-manager.h"
12#include "sway/input/seat.h" 13#include "sway/input/seat.h"
13#include "sway/server.h" 14#include "sway/server.h"
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 522fddca..175416f3 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -7,6 +7,7 @@
7#include "log.h" 7#include "log.h"
8#include "sway/decoration.h" 8#include "sway/decoration.h"
9#include "sway/desktop.h" 9#include "sway/desktop.h"
10#include "sway/desktop/transaction.h"
10#include "sway/input/input-manager.h" 11#include "sway/input/input-manager.h"
11#include "sway/input/seat.h" 12#include "sway/input/seat.h"
12#include "sway/server.h" 13#include "sway/server.h"
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 8d67116a..92f20fcc 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -13,27 +13,18 @@
13#include "list.h" 13#include "list.h"
14#include "log.h" 14#include "log.h"
15 15
16static void apply_horiz_layout(struct sway_container *parent) { 16static void apply_horiz_layout(list_t *children, struct wlr_box *parent) {
17 size_t num_children = parent->children->length; 17 if (!children->length) {
18 if (!num_children) {
19 return; 18 return;
20 } 19 }
21 size_t parent_offset = 0;
22 if (parent->parent->layout == L_TABBED) {
23 parent_offset = container_titlebar_height();
24 } else if (parent->parent->layout == L_STACKED) {
25 parent_offset = container_titlebar_height() *
26 parent->parent->children->length;
27 }
28 size_t parent_height = parent->height - parent_offset;
29 20
30 // Calculate total width of children 21 // Calculate total width of children
31 double total_width = 0; 22 double total_width = 0;
32 for (size_t i = 0; i < num_children; ++i) { 23 for (int i = 0; i < children->length; ++i) {
33 struct sway_container *child = parent->children->items[i]; 24 struct sway_container *child = children->items[i];
34 if (child->width <= 0) { 25 if (child->width <= 0) {
35 if (num_children > 1) { 26 if (children->length > 1) {
36 child->width = parent->width / (num_children - 1); 27 child->width = parent->width / (children->length - 1);
37 } else { 28 } else {
38 child->width = parent->width; 29 child->width = parent->width;
39 } 30 }
@@ -46,63 +37,48 @@ static void apply_horiz_layout(struct sway_container *parent) {
46 // Resize windows 37 // Resize windows
47 wlr_log(WLR_DEBUG, "Arranging %p horizontally", parent); 38 wlr_log(WLR_DEBUG, "Arranging %p horizontally", parent);
48 double child_x = parent->x; 39 double child_x = parent->x;
49 for (size_t i = 0; i < num_children; ++i) { 40 for (int i = 0; i < children->length; ++i) {
50 struct sway_container *child = parent->children->items[i]; 41 struct sway_container *child = children->items[i];
51 wlr_log(WLR_DEBUG,
52 "Calculating arrangement for %p:%d (will scale %f by %f)",
53 child, child->type, child->width, scale);
54 child->x = child_x; 42 child->x = child_x;
55 child->y = parent->y + parent_offset; 43 child->y = parent->y;
56 child->width = floor(child->width * scale); 44 child->width = floor(child->width * scale);
57 child->height = parent_height; 45 child->height = parent->height;
58 child_x += child->width; 46 child_x += child->width;
59 47
60 // Make last child use remaining width of parent 48 // Make last child use remaining width of parent
61 if (i == num_children - 1) { 49 if (i == children->length - 1) {
62 child->width = parent->x + parent->width - child->x; 50 child->width = parent->x + parent->width - child->x;
63 } 51 }
64 container_add_gaps(child); 52 container_add_gaps(child);
65 } 53 }
66} 54}
67 55
68static void apply_vert_layout(struct sway_container *parent) { 56static void apply_vert_layout(list_t *children, struct wlr_box *parent) {
69 size_t num_children = parent->children->length; 57 if (!children->length) {
70 if (!num_children) {
71 return; 58 return;
72 } 59 }
73 size_t parent_offset = 0;
74 if (parent->parent->layout == L_TABBED) {
75 parent_offset = container_titlebar_height();
76 } else if (parent->parent->layout == L_STACKED) {
77 parent_offset =
78 container_titlebar_height() * parent->parent->children->length;
79 }
80 size_t parent_height = parent->height + parent_offset;
81 60
82 // Calculate total height of children 61 // Calculate total height of children
83 double total_height = 0; 62 double total_height = 0;
84 for (size_t i = 0; i < num_children; ++i) { 63 for (int i = 0; i < children->length; ++i) {
85 struct sway_container *child = parent->children->items[i]; 64 struct sway_container *child = children->items[i];
86 if (child->height <= 0) { 65 if (child->height <= 0) {
87 if (num_children > 1) { 66 if (children->length > 1) {
88 child->height = parent_height / (num_children - 1); 67 child->height = parent->height / (children->length - 1);
89 } else { 68 } else {
90 child->height = parent_height; 69 child->height = parent->height;
91 } 70 }
92 } 71 }
93 container_remove_gaps(child); 72 container_remove_gaps(child);
94 total_height += child->height; 73 total_height += child->height;
95 } 74 }
96 double scale = parent_height / total_height; 75 double scale = parent->height / total_height;
97 76
98 // Resize 77 // Resize
99 wlr_log(WLR_DEBUG, "Arranging %p vertically", parent); 78 wlr_log(WLR_DEBUG, "Arranging %p vertically", parent);
100 double child_y = parent->y + parent_offset; 79 double child_y = parent->y;
101 for (size_t i = 0; i < num_children; ++i) { 80 for (int i = 0; i < children->length; ++i) {
102 struct sway_container *child = parent->children->items[i]; 81 struct sway_container *child = children->items[i];
103 wlr_log(WLR_DEBUG,
104 "Calculating arrangement for %p:%d (will scale %f by %f)",
105 child, child->type, child->height, scale);
106 child->x = parent->x; 82 child->x = parent->x;
107 child->y = child_y; 83 child->y = child_y;
108 child->width = parent->width; 84 child->width = parent->width;
@@ -110,28 +86,21 @@ static void apply_vert_layout(struct sway_container *parent) {
110 child_y += child->height; 86 child_y += child->height;
111 87
112 // Make last child use remaining height of parent 88 // Make last child use remaining height of parent
113 if (i == num_children - 1) { 89 if (i == children->length - 1) {
114 child->height = 90 child->height = parent->y + parent->height - child->y;
115 parent->y + parent_offset + parent_height - child->y;
116 } 91 }
117 container_add_gaps(child); 92 container_add_gaps(child);
118 } 93 }
119} 94}
120 95
121static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { 96static void apply_tabbed_layout(list_t *children, struct wlr_box *parent) {
122 if (!parent->children->length) { 97 if (!children->length) {
123 return; 98 return;
124 } 99 }
125 size_t parent_offset = 0; 100 size_t parent_offset = container_titlebar_height();
126 if (parent->parent->layout == L_TABBED) {
127 parent_offset = container_titlebar_height();
128 } else if (parent->parent->layout == L_STACKED) {
129 parent_offset =
130 container_titlebar_height() * parent->parent->children->length;
131 }
132 size_t parent_height = parent->height - parent_offset; 101 size_t parent_height = parent->height - parent_offset;
133 for (int i = 0; i < parent->children->length; ++i) { 102 for (int i = 0; i < children->length; ++i) {
134 struct sway_container *child = parent->children->items[i]; 103 struct sway_container *child = children->items[i];
135 container_remove_gaps(child); 104 container_remove_gaps(child);
136 child->x = parent->x; 105 child->x = parent->x;
137 child->y = parent->y + parent_offset; 106 child->y = parent->y + parent_offset;
@@ -141,65 +110,83 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
141 } 110 }
142} 111}
143 112
144static void arrange_children_of(struct sway_container *parent); 113static void apply_stacked_layout(list_t *children, struct wlr_box *parent) {
114 if (!children->length) {
115 return;
116 }
117 size_t parent_offset = container_titlebar_height() * children->length;
118 size_t parent_height = parent->height - parent_offset;
119 for (int i = 0; i < children->length; ++i) {
120 struct sway_container *child = children->items[i];
121 container_remove_gaps(child);
122 child->x = parent->x;
123 child->y = parent->y + parent_offset;
124 child->width = parent->width;
125 child->height = parent_height;
126 container_add_gaps(child);
127 }
128}
145 129
146static void arrange_floating(list_t *floating) { 130static void arrange_floating(list_t *floating) {
147 for (int i = 0; i < floating->length; ++i) { 131 for (int i = 0; i < floating->length; ++i) {
148 struct sway_container *floater = floating->items[i]; 132 struct sway_container *floater = floating->items[i];
149 if (floater->type == C_VIEW) { 133 arrange_container(floater);
150 view_autoconfigure(floater->sway_view);
151 } else {
152 arrange_children_of(floater);
153 }
154 container_set_dirty(floater);
155 } 134 }
156} 135}
157 136
158static void arrange_children_of(struct sway_container *parent) { 137static void arrange_children(list_t *children,
159 if (config->reloading) { 138 enum sway_container_layout layout, struct wlr_box *parent) {
160 return;
161 }
162 wlr_log(WLR_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent,
163 parent->name, parent->width, parent->height, parent->x, parent->y);
164
165 // Calculate x, y, width and height of children 139 // Calculate x, y, width and height of children
166 switch (parent->layout) { 140 switch (layout) {
167 case L_HORIZ: 141 case L_HORIZ:
168 apply_horiz_layout(parent); 142 apply_horiz_layout(children, parent);
169 break; 143 break;
170 case L_VERT: 144 case L_VERT:
171 apply_vert_layout(parent); 145 apply_vert_layout(children, parent);
172 break; 146 break;
173 case L_TABBED: 147 case L_TABBED:
148 apply_tabbed_layout(children, parent);
149 break;
174 case L_STACKED: 150 case L_STACKED:
175 apply_tabbed_or_stacked_layout(parent); 151 apply_stacked_layout(children, parent);
176 break; 152 break;
177 case L_NONE: 153 case L_NONE:
178 apply_horiz_layout(parent); 154 apply_horiz_layout(children, parent);
179 break; 155 break;
180 } 156 }
181 157
182 // Recurse into child containers 158 // Recurse into child containers
183 for (int i = 0; i < parent->children->length; ++i) { 159 for (int i = 0; i < children->length; ++i) {
184 struct sway_container *child = parent->children->items[i]; 160 struct sway_container *child = children->items[i];
185 if (parent->has_gaps && !child->has_gaps) { 161 arrange_container(child);
186 child->has_gaps = true; 162 }
187 child->gaps_inner = parent->gaps_inner; 163}
188 child->gaps_outer = parent->gaps_outer; 164
189 } 165void arrange_container(struct sway_container *container) {
190 if (child->type == C_VIEW) { 166 if (config->reloading) {
191 view_autoconfigure(child->sway_view); 167 return;
192 } else { 168 }
193 arrange_children_of(child); 169 if (container->type == C_VIEW) {
194 } 170 view_autoconfigure(container->sway_view);
195 container_set_dirty(child); 171 container_set_dirty(container);
172 return;
196 } 173 }
174 if (!sway_assert(container->type == C_CONTAINER, "Expected a container")) {
175 return;
176 }
177 struct wlr_box box;
178 container_get_box(container, &box);
179 arrange_children(container->children, container->layout, &box);
180 container_set_dirty(container);
197} 181}
198 182
199static void arrange_workspace(struct sway_container *workspace) { 183void arrange_workspace(struct sway_container *workspace) {
200 if (config->reloading) { 184 if (config->reloading) {
201 return; 185 return;
202 } 186 }
187 if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
188 return;
189 }
203 struct sway_container *output = workspace->parent; 190 struct sway_container *output = workspace->parent;
204 struct wlr_box *area = &output->sway_output->usable_area; 191 struct wlr_box *area = &output->sway_output->usable_area;
205 wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d", 192 wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d",
@@ -241,22 +228,22 @@ static void arrange_workspace(struct sway_container *workspace) {
241 fs->y = workspace->parent->y; 228 fs->y = workspace->parent->y;
242 fs->width = workspace->parent->width; 229 fs->width = workspace->parent->width;
243 fs->height = workspace->parent->height; 230 fs->height = workspace->parent->height;
244 if (fs->type == C_VIEW) { 231 arrange_container(fs);
245 view_autoconfigure(fs->sway_view);
246 } else {
247 arrange_children_of(fs);
248 }
249 container_set_dirty(fs);
250 } else { 232 } else {
233 struct wlr_box box;
234 container_get_box(workspace, &box);
235 arrange_children(workspace->children, workspace->layout, &box);
251 arrange_floating(workspace->sway_workspace->floating); 236 arrange_floating(workspace->sway_workspace->floating);
252 arrange_children_of(workspace);
253 } 237 }
254} 238}
255 239
256static void arrange_output(struct sway_container *output) { 240void arrange_output(struct sway_container *output) {
257 if (config->reloading) { 241 if (config->reloading) {
258 return; 242 return;
259 } 243 }
244 if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
245 return;
246 }
260 const struct wlr_box *output_box = wlr_output_layout_get_box( 247 const struct wlr_box *output_box = wlr_output_layout_get_box(
261 root_container.sway_root->output_layout, 248 root_container.sway_root->output_layout,
262 output->sway_output->wlr_output); 249 output->sway_output->wlr_output);
@@ -273,7 +260,7 @@ static void arrange_output(struct sway_container *output) {
273 } 260 }
274} 261}
275 262
276static void arrange_root() { 263void arrange_root(void) {
277 if (config->reloading) { 264 if (config->reloading) {
278 return; 265 return;
279 } 266 }
@@ -304,12 +291,8 @@ void arrange_windows(struct sway_container *container) {
304 arrange_workspace(container); 291 arrange_workspace(container);
305 break; 292 break;
306 case C_CONTAINER: 293 case C_CONTAINER:
307 arrange_children_of(container);
308 container_set_dirty(container);
309 break;
310 case C_VIEW: 294 case C_VIEW:
311 view_autoconfigure(container->sway_view); 295 arrange_container(container);
312 container_set_dirty(container);
313 break; 296 break;
314 case C_TYPES: 297 case C_TYPES:
315 break; 298 break;
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 04454ab6..1b193944 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -1163,7 +1163,9 @@ void container_add_gaps(struct sway_container *c) {
1163 return; 1163 return;
1164 } 1164 }
1165 1165
1166 c->current_gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; 1166 struct sway_container *ws = container_parent(c, C_WORKSPACE);
1167
1168 c->current_gaps = ws->has_gaps ? ws->gaps_inner : config->gaps_inner;
1167 c->x += c->current_gaps; 1169 c->x += c->current_gaps;
1168 c->y += c->current_gaps; 1170 c->y += c->current_gaps;
1169 c->width -= 2 * c->current_gaps; 1171 c->width -= 2 * c->current_gaps;
diff --git a/sway/tree/root.c b/sway/tree/root.c
index 2dd8f9f2..b42371de 100644
--- a/sway/tree/root.c
+++ b/sway/tree/root.c
@@ -3,6 +3,7 @@
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h> 4#include <string.h>
5#include <wlr/types/wlr_output_layout.h> 5#include <wlr/types/wlr_output_layout.h>
6#include "sway/desktop/transaction.h"
6#include "sway/input/seat.h" 7#include "sway/input/seat.h"
7#include "sway/output.h" 8#include "sway/output.h"
8#include "sway/tree/arrange.h" 9#include "sway/tree/arrange.h"
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 2870d4f5..1a98c5f2 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -13,6 +13,7 @@
13#include "log.h" 13#include "log.h"
14#include "sway/criteria.h" 14#include "sway/criteria.h"
15#include "sway/commands.h" 15#include "sway/commands.h"
16#include "sway/desktop/transaction.h"
16#include "sway/ipc-server.h" 17#include "sway/ipc-server.h"
17#include "sway/output.h" 18#include "sway/output.h"
18#include "sway/input/seat.h" 19#include "sway/input/seat.h"
@@ -224,15 +225,13 @@ void view_autoconfigure(struct sway_view *view) {
224 x = y = width = height = 0; 225 x = y = width = height = 0;
225 double y_offset = 0; 226 double y_offset = 0;
226 227
227 // In a tabbed or stacked container, the swayc's y is the top of the title 228 // In a tabbed or stacked container, the swayc's y is the bottom of the
228 // area. We have to offset the surface y by the height of the title bar, and 229 // title area. We have to disable any top border because the title bar is
229 // disable any top border because we'll always have the title bar. 230 // rendered by the parent.
230 if (con->parent->layout == L_TABBED) { 231 if (con->parent->layout == L_TABBED || con->parent->layout == L_STACKED) {
231 y_offset = container_titlebar_height();
232 view->border_top = false;
233 } else if (con->parent->layout == L_STACKED) {
234 y_offset = container_titlebar_height() * con->parent->children->length;
235 view->border_top = false; 232 view->border_top = false;
233 } else {
234 y_offset = container_titlebar_height();
236 } 235 }
237 236
238 enum sway_container_border border = view->border; 237 enum sway_container_border border = view->border;
@@ -243,17 +242,17 @@ void view_autoconfigure(struct sway_view *view) {
243 switch (border) { 242 switch (border) {
244 case B_NONE: 243 case B_NONE:
245 x = con->x; 244 x = con->x;
246 y = con->y + y_offset; 245 y = con->y;
247 width = con->width; 246 width = con->width;
248 height = con->height - y_offset; 247 height = con->height;
249 break; 248 break;
250 case B_PIXEL: 249 case B_PIXEL:
251 x = con->x + view->border_thickness * view->border_left; 250 x = con->x + view->border_thickness * view->border_left;
252 y = con->y + view->border_thickness * view->border_top + y_offset; 251 y = con->y + view->border_thickness * view->border_top;
253 width = con->width 252 width = con->width
254 - view->border_thickness * view->border_left 253 - view->border_thickness * view->border_left
255 - view->border_thickness * view->border_right; 254 - view->border_thickness * view->border_right;
256 height = con->height - y_offset 255 height = con->height
257 - view->border_thickness * view->border_top 256 - view->border_thickness * view->border_top
258 - view->border_thickness * view->border_bottom; 257 - view->border_thickness * view->border_bottom;
259 break; 258 break;
@@ -263,15 +262,9 @@ void view_autoconfigure(struct sway_view *view) {
263 width = con->width 262 width = con->width
264 - view->border_thickness * view->border_left 263 - view->border_thickness * view->border_left
265 - view->border_thickness * view->border_right; 264 - view->border_thickness * view->border_right;
266 if (y_offset) { 265 y = con->y + y_offset;
267 y = con->y + y_offset; 266 height = con->height - y_offset
268 height = con->height - y_offset 267 - view->border_thickness * view->border_bottom;
269 - view->border_thickness * view->border_bottom;
270 } else {
271 y = con->y + container_titlebar_height();
272 height = con->height - container_titlebar_height()
273 - view->border_thickness * view->border_bottom;
274 }
275 break; 268 break;
276 } 269 }
277 270