diff options
Diffstat (limited to 'sway/layout.c')
-rw-r--r-- | sway/layout.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/sway/layout.c b/sway/layout.c index e61094e2..e95ee423 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -2,12 +2,18 @@ #include <stdbool.h> #include <wlc/wlc.h> #include "list.h" +#include "log.h" #include "layout.h" list_t *outputs; +wlc_handle focused_view; + +void arrange_windows() { +} void init_layout() { outputs = create_list(); + focused_view = -1; } struct sway_container *get_container(wlc_handle output, int *index) { @@ -21,6 +27,74 @@ struct sway_container *get_container(wlc_handle output, int *index) { return NULL; } +struct sway_container *get_container_for_view_recurse(wlc_handle handle, int *index, struct sway_container *parent) { + int j; + for (j = 0; j < parent->children->length; ++j) { + struct sway_container *child = parent->children->items[j]; + if (child->layout == LAYOUT_IS_VIEW) { + if (child->output == handle) { + *index = j; + return parent; + } + } else { + struct sway_container *res; + if ((res = get_container_for_view_recurse(handle, index, child))) { + return res; + } + } + } + return NULL; +} + +struct sway_container *get_container_for_view(wlc_handle handle, int *index) { + int i; + for (i = 0; i < outputs->length; ++i) { + struct sway_container *c = outputs->items[i]; + struct sway_container *res; + if ((res = get_container_for_view_recurse(handle, index, c))) { + return res; + } + } + return NULL; +} + +void add_view(wlc_handle view_handle) { + struct sway_container *container; + int _; + + if (focused_view == -1) { // Add it to the output container + sway_log(L_DEBUG, "Adding initial view for output", view_handle); + wlc_handle output = wlc_get_focused_output(); + container = get_container(output, &_); + } else { + sway_log(L_DEBUG, "Adding view %d to output", view_handle); + // TODO + } + + // Create "container" for this view + struct sway_container *view = malloc(sizeof(struct sway_container)); + view->layout = LAYOUT_IS_VIEW; + view->children = NULL; + view->output = view_handle; + list_add(container->children, view); + + wlc_view_focus(view_handle); + + arrange_windows(); +} + +void destroy_view(wlc_handle view) { + sway_log(L_DEBUG, "Destroying view %d", view); + + int index; + struct sway_container *container = get_container_for_view(view, &index); + list_del(container->children, index); + + wlc_view_focus(get_topmost(wlc_view_get_output(view), 0)); + + arrange_windows(); +} + void add_output(wlc_handle output) { struct sway_container *container = malloc(sizeof(struct sway_container)); // TODO: Get default layout from config |