summaryrefslogtreecommitdiff
path: root/sway/tree/arrange.c
diff options
context:
space:
mode:
authorRyan Dwyer <[email protected]>2018-08-30 21:00:10 +1000
committerRyan Dwyer <[email protected]>2018-09-05 18:01:43 +1000
commit7586f150c058997d9dde387ea7c091ffa7a3c3c7 (patch)
tree63d19027974c1db62ce3a74ca1d2314eb6d5049b /sway/tree/arrange.c
parent309fcf23007a7c1b5c1c6da6b5ff7101312488cc (diff)
Implement type safe arguments and demote sway_container
This commit changes the meaning of sway_container so that it only refers to layout containers and view containers. Workspaces, outputs and the root are no longer known as containers. Instead, root, outputs, workspaces and containers are all a type of node, and containers come in two types: layout containers and view containers. In addition to the above, this implements type safe variables. This means we use specific types such as sway_output and sway_workspace instead of generic containers or nodes. However, it's worth noting that in a few places places (eg. seat focus and transactions) referring to them in a generic way is unavoidable which is why we still use nodes in some places. If you want a TL;DR, look at node.h, as well as the struct definitions for root, output, workspace and container. Note that sway_output now contains a workspaces list, and workspaces now contain a tiling and floating list, and containers now contain a pointer back to the workspace. There are now functions for seat_get_focused_workspace and seat_get_focused_container. The latter will return NULL if a workspace itself is focused. Most other seat functions like seat_get_focus and seat_set_focus now accept and return nodes. In the config->handler_context struct, current_container has been replaced with three pointers: node, container and workspace. node is the same as what current_container was, while workspace is the workspace that the node resides on and container is the actual container, which may be NULL if a workspace itself is focused. The global root_container variable has been replaced with one simply called root, which is a pointer to the sway_root instance. The way outputs are created, enabled, disabled and destroyed has changed. Previously we'd wrap the sway_output in a container when it is enabled, but as we don't have containers any more it needs a different approach. The output_create and output_destroy functions previously created/destroyed the container, but now they create/destroy the sway_output. There is a new function output_disable to disable an output without destroying it. Containers have a new view property. If this is populated then the container is a view container, otherwise it's a layout container. Like before, this property is immutable for the life of the container. Containers have both a `sway_container *parent` and `sway_workspace *workspace`. As we use specific types now, parent cannot point to a workspace so it'll be NULL for containers which are direct children of the workspace. The workspace property is set for all containers, except those which are hidden in the scratchpad as they have no workspace. In some cases we need to refer to workspaces in a container-like way. For example, workspaces have layout and children, but when using specific types this makes it difficult. Likewise, it's difficult for a container to get its parent's layout when the parent could be another container or a workspace. To make it easier, some helper functions have been created: container_parent_layout and container_get_siblings. container_remove_child has been renamed to container_detach and container_replace_child has been renamed to container_replace. `container_handle_fullscreen_reparent(con, old_parent)` has had the old_parent removed. We now unfullscreen the workspace when detaching the container, so this function is simplified and only needs one argument now. container_notify_subtree_changed has been renamed to container_update_representation. This is more descriptive of its purpose. I also wanted to be able to call it with whatever container was changed rather than the container's parent, which makes bubbling up to the workspace easier. There are now state structs per node thing. ie. sway_output_state, sway_workspace_state and sway_container_state. The focus, move and layout commands have been completely refactored to work with the specific types. I considered making these a separate PR, but I'd be backporting my changes only to replace them again, and it's easier just to test everything at once.
Diffstat (limited to 'sway/tree/arrange.c')
-rw-r--r--sway/tree/arrange.c110
1 files changed, 43 insertions, 67 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 92f20fcc..f86d4a74 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -166,29 +166,23 @@ void arrange_container(struct sway_container *container) {
if (config->reloading) {
return;
}
- if (container->type == C_VIEW) {
- view_autoconfigure(container->sway_view);
- container_set_dirty(container);
- return;
- }
- if (!sway_assert(container->type == C_CONTAINER, "Expected a container")) {
+ if (container->view) {
+ view_autoconfigure(container->view);
+ node_set_dirty(&container->node);
return;
}
struct wlr_box box;
container_get_box(container, &box);
arrange_children(container->children, container->layout, &box);
- container_set_dirty(container);
+ node_set_dirty(&container->node);
}
-void arrange_workspace(struct sway_container *workspace) {
+void arrange_workspace(struct sway_workspace *workspace) {
if (config->reloading) {
return;
}
- if (!sway_assert(workspace->type == C_WORKSPACE, "Expected a workspace")) {
- return;
- }
- struct sway_container *output = workspace->parent;
- struct wlr_box *area = &output->sway_output->usable_area;
+ struct sway_output *output = workspace->output;
+ struct wlr_box *area = &output->usable_area;
wlr_log(WLR_DEBUG, "Usable area for ws: %dx%d@%d,%d",
area->width, area->height, area->x, area->y);
workspace_remove_gaps(workspace);
@@ -197,21 +191,20 @@ void arrange_workspace(struct sway_container *workspace) {
double prev_y = workspace->y;
workspace->width = area->width;
workspace->height = area->height;
- workspace->x = output->x + area->x;
- workspace->y = output->y + area->y;
+ workspace->x = output->wlr_output->lx + area->x;
+ workspace->y = output->wlr_output->ly + area->y;
// Adjust any floating containers
double diff_x = workspace->x - prev_x;
double diff_y = workspace->y - prev_y;
if (diff_x != 0 || diff_y != 0) {
- for (int i = 0; i < workspace->sway_workspace->floating->length; ++i) {
- struct sway_container *floater =
- workspace->sway_workspace->floating->items[i];
+ for (int i = 0; i < workspace->floating->length; ++i) {
+ struct sway_container *floater = workspace->floating->items[i];
container_floating_translate(floater, diff_x, diff_y);
double center_x = floater->x + floater->width / 2;
double center_y = floater->y + floater->height / 2;
struct wlr_box workspace_box;
- container_get_box(workspace, &workspace_box);
+ workspace_get_box(workspace, &workspace_box);
if (!wlr_box_contains_point(&workspace_box, center_x, center_y)) {
container_floating_move_to_center(floater);
}
@@ -219,43 +212,32 @@ void arrange_workspace(struct sway_container *workspace) {
}
workspace_add_gaps(workspace);
- container_set_dirty(workspace);
+ node_set_dirty(&workspace->node);
wlr_log(WLR_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
workspace->x, workspace->y);
- if (workspace->sway_workspace->fullscreen) {
- struct sway_container *fs = workspace->sway_workspace->fullscreen;
- fs->x = workspace->parent->x;
- fs->y = workspace->parent->y;
- fs->width = workspace->parent->width;
- fs->height = workspace->parent->height;
+ if (workspace->fullscreen) {
+ struct sway_container *fs = workspace->fullscreen;
+ fs->x = output->wlr_output->lx;
+ fs->y = output->wlr_output->ly;
+ fs->width = output->wlr_output->width;
+ fs->height = output->wlr_output->height;
arrange_container(fs);
} else {
struct wlr_box box;
- container_get_box(workspace, &box);
- arrange_children(workspace->children, workspace->layout, &box);
- arrange_floating(workspace->sway_workspace->floating);
+ workspace_get_box(workspace, &box);
+ arrange_children(workspace->tiling, workspace->layout, &box);
+ arrange_floating(workspace->floating);
}
}
-void arrange_output(struct sway_container *output) {
+void arrange_output(struct sway_output *output) {
if (config->reloading) {
return;
}
- if (!sway_assert(output->type == C_OUTPUT, "Expected an output")) {
- return;
- }
- const struct wlr_box *output_box = wlr_output_layout_get_box(
- root_container.sway_root->output_layout,
- output->sway_output->wlr_output);
- output->x = output_box->x;
- output->y = output_box->y;
- output->width = output_box->width;
- output->height = output_box->height;
- container_set_dirty(output);
- wlr_log(WLR_DEBUG, "Arranging output '%s' at %f,%f",
- output->name, output->x, output->y);
- for (int i = 0; i < output->children->length; ++i) {
- struct sway_container *workspace = output->children->items[i];
+ // Outputs have no pending x/y/width/height,
+ // so all we do here is arrange the workspaces.
+ for (int i = 0; i < output->workspaces->length; ++i) {
+ struct sway_workspace *workspace = output->workspaces->items[i];
arrange_workspace(workspace);
}
}
@@ -264,37 +246,31 @@ void arrange_root(void) {
if (config->reloading) {
return;
}
- struct wlr_output_layout *output_layout =
- root_container.sway_root->output_layout;
const struct wlr_box *layout_box =
- wlr_output_layout_get_box(output_layout, NULL);
- root_container.x = layout_box->x;
- root_container.y = layout_box->y;
- root_container.width = layout_box->width;
- root_container.height = layout_box->height;
- container_set_dirty(&root_container);
- for (int i = 0; i < root_container.children->length; ++i) {
- struct sway_container *output = root_container.children->items[i];
+ wlr_output_layout_get_box(root->output_layout, NULL);
+ root->x = layout_box->x;
+ root->y = layout_box->y;
+ root->width = layout_box->width;
+ root->height = layout_box->height;
+ for (int i = 0; i < root->outputs->length; ++i) {
+ struct sway_output *output = root->outputs->items[i];
arrange_output(output);
}
}
-void arrange_windows(struct sway_container *container) {
- switch (container->type) {
- case C_ROOT:
+void arrange_node(struct sway_node *node) {
+ switch (node->type) {
+ case N_ROOT:
arrange_root();
break;
- case C_OUTPUT:
- arrange_output(container);
- break;
- case C_WORKSPACE:
- arrange_workspace(container);
+ case N_OUTPUT:
+ arrange_output(node->sway_output);
break;
- case C_CONTAINER:
- case C_VIEW:
- arrange_container(container);
+ case N_WORKSPACE:
+ arrange_workspace(node->sway_workspace);
break;
- case C_TYPES:
+ case N_CONTAINER:
+ arrange_container(node->sway_container);
break;
}
}