diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-11 11:03:43 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-06-11 11:03:43 +1000 |
commit | 9e96cfd310c4e5dc60f07d772e60b139ff7dc448 (patch) | |
tree | 9961c8705208b2f127133f0533bd305a6f75015e /sway/tree | |
parent | bb66e6d578fdc68fb33d0fde921390d74f20bb31 (diff) | |
parent | 867fb6aedbbe4cd1c7f4817848682609e8489880 (diff) | |
download | sway-9e96cfd310c4e5dc60f07d772e60b139ff7dc448.tar.xz |
Merge remote-tracking branch 'upstream/master' into atomic
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/arrange.c | 53 | ||||
-rw-r--r-- | sway/tree/container.c | 5 | ||||
-rw-r--r-- | sway/tree/layout.c | 7 | ||||
-rw-r--r-- | sway/tree/output.c | 5 |
4 files changed, 65 insertions, 5 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index e138410d..ac99c5df 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -41,6 +41,7 @@ static void apply_horiz_layout(struct sway_container *parent) { child->width = parent->width; } } + remove_gaps(child); total_width += child->width; } double scale = parent->width / total_width; @@ -63,6 +64,7 @@ static void apply_horiz_layout(struct sway_container *parent) { if (i == num_children - 1) { child->width = parent->x + parent->width - child->x; } + add_gaps(child); } } @@ -78,7 +80,7 @@ static void apply_vert_layout(struct sway_container *parent) { parent_offset = container_titlebar_height() * parent->parent->children->length; } - size_t parent_height = parent->height - parent_offset; + size_t parent_height = parent->height + parent_offset; // Calculate total height of children double total_height = 0; @@ -91,6 +93,7 @@ static void apply_vert_layout(struct sway_container *parent) { child->height = parent_height; } } + remove_gaps(child); total_height += child->height; } double scale = parent_height / total_height; @@ -114,6 +117,7 @@ static void apply_vert_layout(struct sway_container *parent) { child->height = parent->y + parent_offset + parent_height - child->y; } + add_gaps(child); } } @@ -131,10 +135,12 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) { size_t parent_height = parent->height - parent_offset; for (int i = 0; i < parent->children->length; ++i) { struct sway_container *child = parent->children->items[i]; + remove_gaps(child); child->x = parent->x; child->y = parent->y + parent_offset; child->width = parent->width; child->height = parent_height; + add_gaps(child); } } @@ -185,6 +191,11 @@ static void arrange_children_of(struct sway_container *parent, // Recurse into child containers for (int i = 0; i < parent->children->length; ++i) { struct sway_container *child = parent->children->items[i]; + if (parent->has_gaps && !child->has_gaps) { + child->has_gaps = true; + child->gaps_inner = parent->gaps_inner; + child->gaps_outer = parent->gaps_outer; + } if (child->type == C_VIEW) { view_autoconfigure(child->sway_view); } else { @@ -203,10 +214,12 @@ static void arrange_workspace(struct sway_container *workspace, struct wlr_box *area = &output->sway_output->usable_area; wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", area->width, area->height, area->x, area->y); + remove_gaps(workspace); workspace->width = area->width; workspace->height = area->height; workspace->x = output->x + area->x; workspace->y = output->y + area->y; + add_gaps(workspace); transaction_add_container(transaction, workspace); wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, workspace->x, workspace->y); @@ -285,3 +298,41 @@ void arrange_and_commit(struct sway_container *container) { arrange_windows(container, transaction); transaction_commit(transaction); } + +void remove_gaps(struct sway_container *c) { + if (c->current_gaps == 0) { + wlr_log(L_DEBUG, "Removing gaps: not gapped: %p", c); + return; + } + + c->width += c->current_gaps * 2; + c->height += c->current_gaps * 2; + c->x -= c->current_gaps; + c->y -= c->current_gaps; + + c->current_gaps = 0; + + wlr_log(L_DEBUG, "Removing gaps %p", c); +} + +void add_gaps(struct sway_container *c) { + if (c->current_gaps > 0 || c->type == C_CONTAINER) { + wlr_log(L_DEBUG, "Not adding gaps: %p", c); + return; + } + + if (c->type == C_WORKSPACE && + !(config->edge_gaps || (config->smart_gaps && c->children->length > 1))) { + return; + } + + double gaps = c->has_gaps ? c->gaps_inner : config->gaps_inner; + + c->x += gaps; + c->y += gaps; + c->width -= 2 * gaps; + c->height -= 2 * gaps; + c->current_gaps = gaps; + + wlr_log(L_DEBUG, "Adding gaps: %p", c); +} diff --git a/sway/tree/container.c b/sway/tree/container.c index d312eb60..f8620b72 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -125,6 +125,11 @@ struct sway_container *container_create(enum sway_container_type type) { wl_signal_add(&c->events.reparent, &c->reparent); c->reparent.notify = handle_reparent; + c->has_gaps = false; + c->gaps_inner = 0; + c->gaps_outer = 0; + c->current_gaps = 0; + return c; } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 65b61495..3724361d 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -37,6 +37,7 @@ void layout_init(void) { root_container.sway_root->output_layout = wlr_output_layout_create(); wl_list_init(&root_container.sway_root->outputs); wl_list_init(&root_container.sway_root->xwayland_unmanaged); + wl_list_init(&root_container.sway_root->drag_icons); wl_signal_init(&root_container.sway_root->events.new_container); root_container.sway_root->output_layout_change.notify = @@ -839,6 +840,8 @@ struct sway_container *container_split(struct sway_container *child, wlr_log(L_DEBUG, "creating container %p around %p", cont, child); + remove_gaps(child); + cont->prev_layout = L_NONE; cont->width = child->width; cont->height = child->height; @@ -847,6 +850,9 @@ struct sway_container *container_split(struct sway_container *child, struct sway_seat *seat = input_manager_get_default_seat(input_manager); bool set_focus = (seat_get_focus(seat) == child); + + add_gaps(cont); + if (child->type == C_WORKSPACE) { struct sway_container *workspace = child; while (workspace->children->length) { @@ -874,7 +880,6 @@ struct sway_container *container_split(struct sway_container *child, } container_notify_subtree_changed(cont); - return cont; } diff --git a/sway/tree/output.c b/sway/tree/output.c index ed7e941e..8af319d5 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -26,12 +26,10 @@ static void restore_workspaces(struct sway_container *output) { j--; } } - - arrange_output(other); } container_sort_workspaces(output); - arrange_output(output); + arrange_and_commit(&root_container); } struct sway_container *output_create( @@ -68,6 +66,7 @@ struct sway_container *output_create( struct sway_container *output = container_create(C_OUTPUT); output->sway_output = sway_output; + sway_output->swayc = output; output->name = strdup(name); if (output->name == NULL) { container_destroy(output); |