aboutsummaryrefslogtreecommitdiffstats
path: root/sway/layout.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/layout.c')
-rw-r--r--sway/layout.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/sway/layout.c b/sway/layout.c
index 68d7cf7e..2ce0a559 100644
--- a/sway/layout.c
+++ b/sway/layout.c
@@ -72,6 +72,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
72 switch (container->layout) { 72 switch (container->layout) {
73 case L_HORIZ: 73 case L_HORIZ:
74 default: 74 default:
75 sway_log(L_DEBUG, "Arranging %p horizontally", container);
75 for (i = 0; i < container->children->length; ++i) { 76 for (i = 0; i < container->children->length; ++i) {
76 swayc_t *child = container->children->items[i]; 77 swayc_t *child = container->children->items[i];
77 double percent = child->weight / total_weight; 78 double percent = child->weight / total_weight;
@@ -85,6 +86,7 @@ void arrange_windows(swayc_t *container, int width, int height) {
85 } 86 }
86 break; 87 break;
87 case L_VERT: 88 case L_VERT:
89 sway_log(L_DEBUG, "Arranging %p vertically", container);
88 for (i = 0; i < container->children->length; ++i) { 90 for (i = 0; i < container->children->length; ++i) {
89 swayc_t *child = container->children->items[i]; 91 swayc_t *child = container->children->items[i];
90 double percent = child->weight / total_weight; 92 double percent = child->weight / total_weight;
@@ -166,6 +168,22 @@ void add_view(wlc_handle view_handle) {
166 arrange_windows(parent, -1, -1); 168 arrange_windows(parent, -1, -1);
167} 169}
168 170
171int remove_container_from_parent(swayc_t *parent, swayc_t *container) {
172 int i;
173 for (i = 0; i < parent->children->length; ++i) {
174 if (parent->children->items[i] == container) {
175 list_del(parent->children, i);
176 break;
177 }
178 }
179
180 if (parent->focused == container) {
181 parent->focused = NULL;
182 }
183
184 return i;
185}
186
169void destroy_view(swayc_t *view) { 187void destroy_view(swayc_t *view) {
170 if (view == NULL) { 188 if (view == NULL) {
171 sway_log(L_DEBUG, "Warning: NULL passed into destroy_view"); 189 sway_log(L_DEBUG, "Warning: NULL passed into destroy_view");
@@ -234,30 +252,32 @@ void add_child(swayc_t *parent, swayc_t *child) {
234 list_add(parent->children, child); 252 list_add(parent->children, child);
235} 253}
236 254
255swayc_t *create_container(swayc_t *parent, wlc_handle handle) {
256 swayc_t *c = calloc(1, sizeof(swayc_t));
257 c->weight = 1;
258 c->handle = handle;
259 c->parent = parent;
260 c->layout = L_NONE;
261 c->type = C_CONTAINER;
262 c->children = create_list();
263 return c;
264}
265
237void add_output(wlc_handle output) { 266void add_output(wlc_handle output) {
238 sway_log(L_DEBUG, "Adding output %d", output); 267 sway_log(L_DEBUG, "Adding output %d", output);
239 const struct wlc_size* size = wlc_output_get_resolution(output); 268 const struct wlc_size* size = wlc_output_get_resolution(output);
240 269
241 swayc_t *container = calloc(1, sizeof(swayc_t)); 270 swayc_t *container = create_container(&root_container, output);
242 container->weight = 1;
243 container->handle = output;
244 container->type = C_OUTPUT; 271 container->type = C_OUTPUT;
245 container->children = create_list();
246 container->parent = &root_container;
247 container->layout = L_NONE;
248 container->width = size->w; 272 container->width = size->w;
249 container->height = size->h; 273 container->height = size->h;
250 add_child(&root_container, container); 274 add_child(&root_container, container);
251 275
252 swayc_t *workspace = calloc(1, sizeof(swayc_t)); 276 swayc_t *workspace = create_container(container, -1);
253 workspace->weight = 1;
254 workspace->handle = -1;
255 workspace->type = C_WORKSPACE; 277 workspace->type = C_WORKSPACE;
256 workspace->parent = container;
257 workspace->width = size->w; // TODO: gaps 278 workspace->width = size->w; // TODO: gaps
258 workspace->height = size->h; 279 workspace->height = size->h;
259 workspace->layout = L_HORIZ; // TODO: Get default layout from config 280 workspace->layout = L_HORIZ; // TODO: Get default layout from config
260 workspace->children = create_list();
261 add_child(container, workspace); 281 add_child(container, workspace);
262 282
263 if (root_container.focused == NULL) { 283 if (root_container.focused == NULL) {