aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-06 19:19:30 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-06-09 10:08:43 +1000
commitf9e6d703d298dbdee0770fd9e0c64ab2d7ac7deb (patch)
tree8c8ffd879e368aff3d749a637aabfa784800db5c /sway/tree/arrange.c
parentWIP: Atomic layout updates ground work (diff)
downloadsway-f9e6d703d298dbdee0770fd9e0c64ab2d7ac7deb.tar.gz
sway-f9e6d703d298dbdee0770fd9e0c64ab2d7ac7deb.tar.zst
sway-f9e6d703d298dbdee0770fd9e0c64ab2d7ac7deb.zip
Make main properties be the pending state
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c107
1 files changed, 47 insertions, 60 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index d8b3aec1..cf7ce61c 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -22,48 +22,46 @@ static void apply_horiz_layout(struct sway_container *parent) {
22 return; 22 return;
23 } 23 }
24 size_t parent_offset = 0; 24 size_t parent_offset = 0;
25 if (parent->parent->pending.layout == L_TABBED) { 25 if (parent->parent->layout == L_TABBED) {
26 parent_offset = container_titlebar_height(); 26 parent_offset = container_titlebar_height();
27 } else if (parent->parent->pending.layout == L_STACKED) { 27 } else if (parent->parent->layout == L_STACKED) {
28 parent_offset = container_titlebar_height() * 28 parent_offset = container_titlebar_height() *
29 parent->parent->children->length; 29 parent->parent->children->length;
30 } 30 }
31 size_t parent_height = parent->pending.swayc_height - parent_offset; 31 size_t parent_height = parent->height - parent_offset;
32 32
33 // Calculate total width of children 33 // Calculate total width of children
34 double total_width = 0; 34 double total_width = 0;
35 for (size_t i = 0; i < num_children; ++i) { 35 for (size_t i = 0; i < num_children; ++i) {
36 struct sway_container *child = parent->children->items[i]; 36 struct sway_container *child = parent->children->items[i];
37 if (child->pending.swayc_width <= 0) { 37 if (child->width <= 0) {
38 if (num_children > 1) { 38 if (num_children > 1) {
39 child->pending.swayc_width = 39 child->width = parent->width / (num_children - 1);
40 parent->pending.swayc_width / (num_children - 1);
41 } else { 40 } else {
42 child->pending.swayc_width = parent->pending.swayc_width; 41 child->width = parent->width;
43 } 42 }
44 } 43 }
45 total_width += child->pending.swayc_width; 44 total_width += child->width;
46 } 45 }
47 double scale = parent->pending.swayc_width / total_width; 46 double scale = parent->width / total_width;
48 47
49 // Resize windows 48 // Resize windows
50 wlr_log(L_DEBUG, "Arranging %p horizontally", parent); 49 wlr_log(L_DEBUG, "Arranging %p horizontally", parent);
51 double child_x = parent->pending.swayc_x; 50 double child_x = parent->x;
52 for (size_t i = 0; i < num_children; ++i) { 51 for (size_t i = 0; i < num_children; ++i) {
53 struct sway_container *child = parent->children->items[i]; 52 struct sway_container *child = parent->children->items[i];
54 wlr_log(L_DEBUG, 53 wlr_log(L_DEBUG,
55 "Calculating arrangement for %p:%d (will scale %f by %f)", 54 "Calculating arrangement for %p:%d (will scale %f by %f)",
56 child, child->type, child->pending.swayc_width, scale); 55 child, child->type, child->width, scale);
57 child->pending.swayc_x = child_x; 56 child->x = child_x;
58 child->pending.swayc_y = parent->pending.swayc_y + parent_offset; 57 child->y = parent->y + parent_offset;
59 child->pending.swayc_width = floor(child->pending.swayc_width * scale); 58 child->width = floor(child->width * scale);
60 child->pending.swayc_height = parent_height; 59 child->height = parent_height;
61 child_x += child->pending.swayc_width; 60 child_x += child->width;
62 61
63 // Make last child use remaining width of parent 62 // Make last child use remaining width of parent
64 if (i == num_children - 1) { 63 if (i == num_children - 1) {
65 child->pending.swayc_width = parent->pending.swayc_x + 64 child->width = parent->x + parent->width - child->x;
66 parent->pending.swayc_width - child->pending.swayc_x;
67 } 65 }
68 } 66 }
69} 67}
@@ -74,49 +72,47 @@ static void apply_vert_layout(struct sway_container *parent) {
74 return; 72 return;
75 } 73 }
76 size_t parent_offset = 0; 74 size_t parent_offset = 0;
77 if (parent->parent->pending.layout == L_TABBED) { 75 if (parent->parent->layout == L_TABBED) {
78 parent_offset = container_titlebar_height(); 76 parent_offset = container_titlebar_height();
79 } else if (parent->parent->pending.layout == L_STACKED) { 77 } else if (parent->parent->layout == L_STACKED) {
80 parent_offset = 78 parent_offset =
81 container_titlebar_height() * parent->parent->children->length; 79 container_titlebar_height() * parent->parent->children->length;
82 } 80 }
83 size_t parent_height = parent->pending.swayc_height - parent_offset; 81 size_t parent_height = parent->height - parent_offset;
84 82
85 // Calculate total height of children 83 // Calculate total height of children
86 double total_height = 0; 84 double total_height = 0;
87 for (size_t i = 0; i < num_children; ++i) { 85 for (size_t i = 0; i < num_children; ++i) {
88 struct sway_container *child = parent->children->items[i]; 86 struct sway_container *child = parent->children->items[i];
89 if (child->pending.swayc_height <= 0) { 87 if (child->height <= 0) {
90 if (num_children > 1) { 88 if (num_children > 1) {
91 child->pending.swayc_height = 89 child->height = parent_height / (num_children - 1);
92 parent_height / (num_children - 1);
93 } else { 90 } else {
94 child->pending.swayc_height = parent_height; 91 child->height = parent_height;
95 } 92 }
96 } 93 }
97 total_height += child->pending.swayc_height; 94 total_height += child->height;
98 } 95 }
99 double scale = parent_height / total_height; 96 double scale = parent_height / total_height;
100 97
101 // Resize 98 // Resize
102 wlr_log(L_DEBUG, "Arranging %p vertically", parent); 99 wlr_log(L_DEBUG, "Arranging %p vertically", parent);
103 double child_y = parent->pending.swayc_y + parent_offset; 100 double child_y = parent->y + parent_offset;
104 for (size_t i = 0; i < num_children; ++i) { 101 for (size_t i = 0; i < num_children; ++i) {
105 struct sway_container *child = parent->children->items[i]; 102 struct sway_container *child = parent->children->items[i];
106 wlr_log(L_DEBUG, 103 wlr_log(L_DEBUG,
107 "Calculating arrangement for %p:%d (will scale %f by %f)", 104 "Calculating arrangement for %p:%d (will scale %f by %f)",
108 child, child->type, child->pending.swayc_height, scale); 105 child, child->type, child->height, scale);
109 child->pending.swayc_x = parent->pending.swayc_x; 106 child->x = parent->x;
110 child->pending.swayc_y = child_y; 107 child->y = child_y;
111 child->pending.swayc_width = parent->pending.swayc_width; 108 child->width = parent->width;
112 child->pending.swayc_height = 109 child->height = floor(child->height * scale);
113 floor(child->pending.swayc_height * scale); 110 child_y += child->height;
114 child_y += child->pending.swayc_height;
115 111
116 // Make last child use remaining height of parent 112 // Make last child use remaining height of parent
117 if (i == num_children - 1) { 113 if (i == num_children - 1) {
118 child->pending.swayc_height = parent->pending.swayc_y + 114 child->height =
119 parent_offset + parent_height - child->pending.swayc_y; 115 parent->y + parent_offset + parent_height - child->y;
120 } 116 }
121 } 117 }
122} 118}
@@ -126,19 +122,19 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
126 return; 122 return;
127 } 123 }
128 size_t parent_offset = 0; 124 size_t parent_offset = 0;
129 if (parent->parent->pending.layout == L_TABBED) { 125 if (parent->parent->layout == L_TABBED) {
130 parent_offset = container_titlebar_height(); 126 parent_offset = container_titlebar_height();
131 } else if (parent->parent->pending.layout == L_STACKED) { 127 } else if (parent->parent->layout == L_STACKED) {
132 parent_offset = 128 parent_offset =
133 container_titlebar_height() * parent->parent->children->length; 129 container_titlebar_height() * parent->parent->children->length;
134 } 130 }
135 size_t parent_height = parent->pending.swayc_height - parent_offset; 131 size_t parent_height = parent->height - parent_offset;
136 for (int i = 0; i < parent->children->length; ++i) { 132 for (int i = 0; i < parent->children->length; ++i) {
137 struct sway_container *child = parent->children->items[i]; 133 struct sway_container *child = parent->children->items[i];
138 child->pending.swayc_x = parent->pending.swayc_x; 134 child->x = parent->x;
139 child->pending.swayc_y = parent->pending.swayc_y + parent_offset; 135 child->y = parent->y + parent_offset;
140 child->pending.swayc_width = parent->pending.swayc_width; 136 child->width = parent->width;
141 child->pending.swayc_height = parent_height; 137 child->height = parent_height;
142 } 138 }
143} 139}
144 140
@@ -148,11 +144,10 @@ static void _arrange_children_of(struct sway_container *parent,
148 return; 144 return;
149 } 145 }
150 wlr_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent, 146 wlr_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent,
151 parent->name, parent->pending.swayc_width, parent->pending.swayc_height, 147 parent->name, parent->width, parent->height, parent->x, parent->y);
152 parent->pending.swayc_x, parent->pending.swayc_y);
153 148
154 // Calculate x, y, width and height of children 149 // Calculate x, y, width and height of children
155 switch (parent->pending.layout) { 150 switch (parent->layout) {
156 case L_HORIZ: 151 case L_HORIZ:
157 apply_horiz_layout(parent); 152 apply_horiz_layout(parent);
158 break; 153 break;
@@ -191,13 +186,13 @@ static void _arrange_workspace(struct sway_container *workspace,
191 struct wlr_box *area = &output->sway_output->usable_area; 186 struct wlr_box *area = &output->sway_output->usable_area;
192 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", 187 wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d",
193 area->width, area->height, area->x, area->y); 188 area->width, area->height, area->x, area->y);
194 workspace->pending.swayc_width = area->width; 189 workspace->width = area->width;
195 workspace->pending.swayc_height = area->height; 190 workspace->height = area->height;
196 workspace->pending.swayc_x = output->x + area->x; 191 workspace->x = output->x + area->x;
197 workspace->pending.swayc_y = output->y + area->y; 192 workspace->y = output->y + area->y;
198 transaction_add_container(transaction, workspace); 193 transaction_add_container(transaction, workspace);
199 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, 194 wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
200 workspace->pending.swayc_x, workspace->pending.swayc_y); 195 workspace->x, workspace->y);
201 _arrange_children_of(workspace, transaction); 196 _arrange_children_of(workspace, transaction);
202} 197}
203 198
@@ -213,13 +208,9 @@ static void _arrange_output(struct sway_container *output,
213 output->y = output_box->y; 208 output->y = output_box->y;
214 output->width = output_box->width; 209 output->width = output_box->width;
215 output->height = output_box->height; 210 output->height = output_box->height;
216 output->pending.swayc_x = output_box->x;
217 output->pending.swayc_y = output_box->y;
218 output->pending.swayc_width = output_box->width;
219 output->pending.swayc_height = output_box->height;
220 transaction_add_container(transaction, output); 211 transaction_add_container(transaction, output);
221 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f", 212 wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f",
222 output->name, output->pending.swayc_x, output->pending.swayc_y); 213 output->name, output->x, output->y);
223 for (int i = 0; i < output->children->length; ++i) { 214 for (int i = 0; i < output->children->length; ++i) {
224 struct sway_container *workspace = output->children->items[i]; 215 struct sway_container *workspace = output->children->items[i];
225 _arrange_workspace(workspace, transaction); 216 _arrange_workspace(workspace, transaction);
@@ -238,10 +229,6 @@ static void _arrange_root(struct sway_transaction *transaction) {
238 root_container.y = layout_box->y; 229 root_container.y = layout_box->y;
239 root_container.width = layout_box->width; 230 root_container.width = layout_box->width;
240 root_container.height = layout_box->height; 231 root_container.height = layout_box->height;
241 root_container.pending.swayc_x = layout_box->x;
242 root_container.pending.swayc_y = layout_box->y;
243 root_container.pending.swayc_width = layout_box->width;
244 root_container.pending.swayc_height = layout_box->height;
245 transaction_add_container(transaction, &root_container); 232 transaction_add_container(transaction, &root_container);
246 for (int i = 0; i < root_container.children->length; ++i) { 233 for (int i = 0; i < root_container.children->length; ++i) {
247 struct sway_container *output = root_container.children->items[i]; 234 struct sway_container *output = root_container.children->items[i];