aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-19 22:54:50 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-05-21 20:16:56 +1000
commitc08f9bf257c38c92a75988d89fba2d4de6bb2aea (patch)
tree76ea44c5548301ff4892c44838b783eeeb569c62 /sway/tree/arrange.c
parentMerge pull request #2011 from RyanDwyer/fix-hide-edge-border-bottom (diff)
downloadsway-c08f9bf257c38c92a75988d89fba2d4de6bb2aea.tar.gz
sway-c08f9bf257c38c92a75988d89fba2d4de6bb2aea.tar.zst
sway-c08f9bf257c38c92a75988d89fba2d4de6bb2aea.zip
Implement tabbed layout
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c44
1 files changed, 37 insertions, 7 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 83bb20fb..8aebc0cc 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -86,6 +86,13 @@ static void apply_horiz_layout(struct sway_container *parent) {
86 if (!num_children) { 86 if (!num_children) {
87 return; 87 return;
88 } 88 }
89 size_t parent_height = parent->height;
90 size_t parent_offset = 0;
91 if (parent->parent->layout == L_TABBED) {
92 parent_offset = config->border_thickness * 2 + config->font_height;
93 parent_height -= parent_offset;
94 }
95
89 // Calculate total width of children 96 // Calculate total width of children
90 double total_width = 0; 97 double total_width = 0;
91 for (size_t i = 0; i < num_children; ++i) { 98 for (size_t i = 0; i < num_children; ++i) {
@@ -111,9 +118,9 @@ static void apply_horiz_layout(struct sway_container *parent) {
111 "Calculating arrangement for %p:%d (will scale %f by %f)", 118 "Calculating arrangement for %p:%d (will scale %f by %f)",
112 child, child->type, child->width, scale); 119 child, child->type, child->width, scale);
113 child->x = child_x; 120 child->x = child_x;
114 child->y = parent->y; 121 child->y = parent->y + parent_offset;
115 child->width = floor(child->width * scale); 122 child->width = floor(child->width * scale);
116 child->height = parent->height; 123 child->height = parent_height;
117 child_x += child->width; 124 child_x += child->width;
118 } 125 }
119 // Make last child use remaining width of parent 126 // Make last child use remaining width of parent
@@ -125,24 +132,31 @@ static void apply_vert_layout(struct sway_container *parent) {
125 if (!num_children) { 132 if (!num_children) {
126 return; 133 return;
127 } 134 }
135 size_t parent_height = parent->height;
136 size_t parent_offset = 0;
137 if (parent->parent->layout == L_TABBED) {
138 parent_offset = config->border_thickness * 2 + config->font_height;
139 parent_height -= parent_offset;
140 }
141
128 // Calculate total height of children 142 // Calculate total height of children
129 double total_height = 0; 143 double total_height = 0;
130 for (size_t i = 0; i < num_children; ++i) { 144 for (size_t i = 0; i < num_children; ++i) {
131 struct sway_container *child = parent->children->items[i]; 145 struct sway_container *child = parent->children->items[i];
132 if (child->height <= 0) { 146 if (child->height <= 0) {
133 if (num_children > 1) { 147 if (num_children > 1) {
134 child->height = parent->height / (num_children - 1); 148 child->height = parent_height / (num_children - 1);
135 } else { 149 } else {
136 child->height = parent->height; 150 child->height = parent_height;
137 } 151 }
138 } 152 }
139 total_height += child->height; 153 total_height += child->height;
140 } 154 }
141 double scale = parent->height / total_height; 155 double scale = parent_height / total_height;
142 156
143 // Resize 157 // Resize
144 wlr_log(L_DEBUG, "Arranging %p vertically", parent); 158 wlr_log(L_DEBUG, "Arranging %p vertically", parent);
145 double child_y = parent->y; 159 double child_y = parent->y + parent_offset;
146 struct sway_container *child; 160 struct sway_container *child;
147 for (size_t i = 0; i < num_children; ++i) { 161 for (size_t i = 0; i < num_children; ++i) {
148 child = parent->children->items[i]; 162 child = parent->children->items[i];
@@ -156,7 +170,20 @@ static void apply_vert_layout(struct sway_container *parent) {
156 child_y += child->height; 170 child_y += child->height;
157 } 171 }
158 // Make last child use remaining height of parent 172 // Make last child use remaining height of parent
159 child->height = parent->y + parent->height - child->y; 173 child->height = parent->y + parent_offset + parent_height - child->y;
174}
175
176static void apply_tabbed_layout(struct sway_container *parent) {
177 if (!parent->children->length) {
178 return;
179 }
180 for (int i = 0; i < parent->children->length; ++i) {
181 struct sway_container *child = parent->children->items[i];
182 child->x = parent->x;
183 child->y = parent->y;
184 child->width = parent->width;
185 child->height = parent->height;
186 }
160} 187}
161 188
162void arrange_children_of(struct sway_container *parent) { 189void arrange_children_of(struct sway_container *parent) {
@@ -189,6 +216,9 @@ void arrange_children_of(struct sway_container *parent) {
189 case L_VERT: 216 case L_VERT:
190 apply_vert_layout(parent); 217 apply_vert_layout(parent);
191 break; 218 break;
219 case L_TABBED:
220 apply_tabbed_layout(parent);
221 break;
192 default: 222 default:
193 wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout); 223 wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout);
194 apply_horiz_layout(parent); 224 apply_horiz_layout(parent);