aboutsummaryrefslogtreecommitdiff
path: root/sway/tree
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/arrange.c63
-rw-r--r--sway/tree/container.c10
-rw-r--r--sway/tree/layout.c71
-rw-r--r--sway/tree/view.c49
-rw-r--r--sway/tree/workspace.c2
5 files changed, 74 insertions, 121 deletions
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index cf7ce61c..e138410d 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -138,7 +138,23 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
}
}
-static void _arrange_children_of(struct sway_container *parent,
+static void arrange_children_of(struct sway_container *parent,
+ struct sway_transaction *transaction);
+
+static void arrange_floating(struct sway_container *floating,
+ struct sway_transaction *transaction) {
+ for (int i = 0; i < floating->children->length; ++i) {
+ struct sway_container *floater = floating->children->items[i];
+ if (floater->type == C_VIEW) {
+ view_autoconfigure(floater->sway_view);
+ } else {
+ arrange_children_of(floater, transaction);
+ }
+ transaction_add_container(transaction, floater);
+ }
+}
+
+static void arrange_children_of(struct sway_container *parent,
struct sway_transaction *transaction) {
if (config->reloading) {
return;
@@ -162,7 +178,8 @@ static void _arrange_children_of(struct sway_container *parent,
apply_horiz_layout(parent);
break;
case L_FLOATING:
- sway_assert(false, "Didn't expect to see floating here");
+ arrange_floating(parent, transaction);
+ break;
}
// Recurse into child containers
@@ -171,13 +188,13 @@ static void _arrange_children_of(struct sway_container *parent,
if (child->type == C_VIEW) {
view_autoconfigure(child->sway_view);
} else {
- _arrange_children_of(child, transaction);
+ arrange_children_of(child, transaction);
}
transaction_add_container(transaction, child);
}
}
-static void _arrange_workspace(struct sway_container *workspace,
+static void arrange_workspace(struct sway_container *workspace,
struct sway_transaction *transaction) {
if (config->reloading) {
return;
@@ -193,10 +210,11 @@ static void _arrange_workspace(struct sway_container *workspace,
transaction_add_container(transaction, workspace);
wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
workspace->x, workspace->y);
- _arrange_children_of(workspace, transaction);
+ arrange_floating(workspace->sway_workspace->floating, transaction);
+ arrange_children_of(workspace, transaction);
}
-static void _arrange_output(struct sway_container *output,
+static void arrange_output(struct sway_container *output,
struct sway_transaction *transaction) {
if (config->reloading) {
return;
@@ -213,11 +231,11 @@ static void _arrange_output(struct sway_container *output,
output->name, output->x, output->y);
for (int i = 0; i < output->children->length; ++i) {
struct sway_container *workspace = output->children->items[i];
- _arrange_workspace(workspace, transaction);
+ arrange_workspace(workspace, transaction);
}
}
-static void _arrange_root(struct sway_transaction *transaction) {
+static void arrange_root(struct sway_transaction *transaction) {
if (config->reloading) {
return;
}
@@ -232,7 +250,7 @@ static void _arrange_root(struct sway_transaction *transaction) {
transaction_add_container(transaction, &root_container);
for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *output = root_container.children->items[i];
- _arrange_output(output, transaction);
+ arrange_output(output, transaction);
}
}
@@ -240,19 +258,21 @@ void arrange_windows(struct sway_container *container,
struct sway_transaction *transaction) {
switch (container->type) {
case C_ROOT:
- _arrange_root(transaction);
+ arrange_root(transaction);
break;
case C_OUTPUT:
- _arrange_output(container, transaction);
+ arrange_output(container, transaction);
break;
case C_WORKSPACE:
- _arrange_workspace(container, transaction);
+ arrange_workspace(container, transaction);
break;
case C_CONTAINER:
- _arrange_children_of(container, transaction);
+ arrange_children_of(container, transaction);
transaction_add_container(transaction, container);
break;
case C_VIEW:
+ view_autoconfigure(container->sway_view);
+ transaction_add_container(transaction, container);
break;
case C_TYPES:
break;
@@ -265,20 +285,3 @@ void arrange_and_commit(struct sway_container *container) {
arrange_windows(container, transaction);
transaction_commit(transaction);
}
-
-// These functions are only temporary
-void arrange_root() {
- arrange_and_commit(&root_container);
-}
-
-void arrange_output(struct sway_container *container) {
- arrange_and_commit(container);
-}
-
-void arrange_workspace(struct sway_container *container) {
- arrange_and_commit(container);
-}
-
-void arrange_children_of(struct sway_container *container) {
- arrange_and_commit(container);
-}
diff --git a/sway/tree/container.c b/sway/tree/container.c
index e6956f5c..d312eb60 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -204,6 +204,7 @@ static struct sway_container *container_workspace_destroy(
container_move_to(floating->children->items[i],
new_workspace->sway_workspace->floating);
}
+ arrange_and_commit(new_workspace);
}
struct sway_workspace *sway_workspace = workspace->sway_workspace;
@@ -264,10 +265,10 @@ static struct sway_container *container_output_destroy(
}
container_sort_workspaces(new_output);
- arrange_output(new_output);
}
}
}
+ arrange_and_commit(&root_container);
wl_list_remove(&output->sway_output->mode.link);
wl_list_remove(&output->sway_output->transform.link);
@@ -924,13 +925,12 @@ void container_set_floating(struct sway_container *container, bool enable) {
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
struct sway_seat *seat = input_manager_current_seat(input_manager);
- container_damage_whole(container);
if (enable) {
container_remove_child(container);
container_add_child(workspace->sway_workspace->floating, container);
if (container->type == C_VIEW) {
- view_autoconfigure(container->sway_view);
+ view_init_floating(container->sway_view);
}
seat_set_focus(seat, seat_get_focus_inactive(seat, container));
container_reap_empty_recursive(workspace);
@@ -943,8 +943,8 @@ void container_set_floating(struct sway_container *container, bool enable) {
container->is_sticky = false;
container_reap_empty_recursive(workspace->sway_workspace->floating);
}
- arrange_workspace(workspace);
- container_damage_whole(container);
+
+ ipc_event_window(container, "floating");
}
void container_set_geometry_from_floating_view(struct sway_container *con) {
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index 6d4cd088..65b61495 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -22,7 +22,7 @@ struct sway_container root_container;
static void output_layout_handle_change(struct wl_listener *listener,
void *data) {
- arrange_root();
+ arrange_and_commit(&root_container);
}
void layout_init(void) {
@@ -56,18 +56,17 @@ static int index_child(const struct sway_container *child) {
return -1;
}
-static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
+static void container_handle_fullscreen_reparent(struct sway_container *con,
struct sway_container *old_parent) {
- if (viewcon->type != C_VIEW || !viewcon->sway_view->is_fullscreen) {
+ if (con->type != C_VIEW || !con->sway_view->is_fullscreen) {
return;
}
- struct sway_view *view = viewcon->sway_view;
+ struct sway_view *view = con->sway_view;
struct sway_container *old_workspace = old_parent;
if (old_workspace && old_workspace->type != C_WORKSPACE) {
old_workspace = container_parent(old_workspace, C_WORKSPACE);
}
- struct sway_container *new_workspace = container_parent(view->swayc,
- C_WORKSPACE);
+ struct sway_container *new_workspace = container_parent(con, C_WORKSPACE);
if (old_workspace == new_workspace) {
return;
}
@@ -78,15 +77,19 @@ static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
// Mark the new workspace as fullscreen
if (new_workspace->sway_workspace->fullscreen) {
- view_set_fullscreen_raw(
- new_workspace->sway_workspace->fullscreen, false);
+ view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false);
}
new_workspace->sway_workspace->fullscreen = view;
// Resize view to new output dimensions
struct sway_container *output = new_workspace->parent;
- view_configure(view, 0, 0, output->width, output->height);
- view->swayc->width = output->width;
- view->swayc->height = output->height;
+ view->x = output->x;
+ view->y = output->y;
+ view->width = output->width;
+ view->height = output->height;
+ con->x = output->x;
+ con->y = output->y;
+ con->width = output->width;
+ con->height = output->height;
}
void container_insert_child(struct sway_container *parent,
@@ -188,18 +191,7 @@ void container_move_to(struct sway_container *container,
}
container_notify_subtree_changed(old_parent);
container_notify_subtree_changed(new_parent);
- if (old_parent) {
- if (old_parent->type == C_OUTPUT) {
- arrange_output(old_parent);
- } else {
- arrange_children_of(old_parent);
- }
- }
- if (new_parent->type == C_OUTPUT) {
- arrange_output(new_parent);
- } else {
- arrange_children_of(new_parent);
- }
+
// If view was moved to a fullscreen workspace, refocus the fullscreen view
struct sway_container *new_workspace = container;
if (new_workspace->type != C_WORKSPACE) {
@@ -214,7 +206,8 @@ void container_move_to(struct sway_container *container,
if (focus_ws->type != C_WORKSPACE) {
focus_ws = container_parent(focus_ws, C_WORKSPACE);
}
- seat_set_focus(seat, new_workspace->sway_workspace->fullscreen->swayc);
+ seat_set_focus(seat,
+ new_workspace->sway_workspace->fullscreen->swayc);
if (focus_ws != new_workspace) {
seat_set_focus(seat, focus);
}
@@ -308,7 +301,6 @@ static void workspace_rejigger(struct sway_container *ws,
container_reap_empty_recursive(original_parent);
wl_signal_emit(&child->events.reparent, original_parent);
container_create_notify(new_parent);
- arrange_workspace(ws);
}
static void move_out_of_tabs_stacks(struct sway_container *container,
@@ -319,11 +311,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id);
current->parent->layout = move_dir ==
MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
- if (current->parent->type == C_WORKSPACE) {
- arrange_workspace(current->parent);
- } else {
- arrange_children_of(current->parent);
- }
return;
}
@@ -339,11 +326,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
container_flatten(new_parent->parent);
}
container_create_notify(new_parent);
- if (is_workspace) {
- arrange_workspace(new_parent->parent);
- } else {
- arrange_children_of(new_parent);
- }
container_notify_subtree_changed(new_parent);
}
@@ -367,10 +349,7 @@ void container_move(struct sway_container *container,
struct sway_container *new_parent = container_flatten(parent);
if (new_parent != parent) {
- // Special case: we were the last one in this container, so flatten it
- // and leave
- arrange_children_of(new_parent);
- update_debug_tree();
+ // Special case: we were the last one in this container, so leave
return;
}
@@ -452,12 +431,9 @@ void container_move(struct sway_container *container,
wlr_log(L_DEBUG, "Hit limit, "
"promoting descendant to sibling");
// Special case
- struct sway_container *old_parent = container->parent;
container_insert_child(current->parent, container,
index + (offs < 0 ? 0 : 1));
container->width = container->height = 0;
- arrange_children_of(current->parent);
- arrange_children_of(old_parent);
return;
}
} else {
@@ -491,14 +467,11 @@ void container_move(struct sway_container *container,
wlr_log(L_DEBUG, "Swapping siblings");
sibling->parent->children->items[index + offs] = container;
sibling->parent->children->items[index] = sibling;
- arrange_children_of(sibling->parent);
} else {
wlr_log(L_DEBUG, "Promoting to sibling of cousin");
container_insert_child(sibling->parent, container,
index_child(sibling) + (offs > 0 ? 0 : 1));
container->width = container->height = 0;
- arrange_children_of(sibling->parent);
- arrange_children_of(old_parent);
}
sibling = NULL;
break;
@@ -512,8 +485,6 @@ void container_move(struct sway_container *container,
"(move dir: %d)", limit, move_dir);
container_insert_child(sibling, container, limit);
container->width = container->height = 0;
- arrange_children_of(sibling);
- arrange_children_of(old_parent);
sibling = NULL;
} else {
wlr_log(L_DEBUG, "Reparenting container (perpendicular)");
@@ -537,8 +508,6 @@ void container_move(struct sway_container *container,
container_add_child(sibling, container);
}
container->width = container->height = 0;
- arrange_children_of(sibling);
- arrange_children_of(old_parent);
sibling = NULL;
}
break;
@@ -863,7 +832,6 @@ struct sway_container *container_split(struct sway_container *child,
// Special case: this just behaves like splitt
child->prev_layout = child->layout;
child->layout = layout;
- arrange_children_of(child);
return child;
}
@@ -1044,9 +1012,6 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
prev_workspace_name = stored_prev_name;
}
- arrange_children_of(con1->parent);
- arrange_children_of(con2->parent);
-
if (fs1 && con2->type == C_VIEW) {
view_set_fullscreen(con2->sway_view, true);
}
diff --git a/sway/tree/view.c b/sway/tree/view.c
index dbf803c6..658a94e8 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -135,22 +135,22 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
return 0;
}
-static void view_autoconfigure_floating(struct sway_view *view) {
+void view_init_floating(struct sway_view *view) {
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
int max_width = ws->width * 0.6666;
int max_height = ws->height * 0.6666;
- int width =
+ view->width =
view->natural_width > max_width ? max_width : view->natural_width;
- int height =
+ view->height =
view->natural_height > max_height ? max_height : view->natural_height;
- int lx = ws->x + (ws->width - width) / 2;
- int ly = ws->y + (ws->height - height) / 2;
+ view->x = ws->x + (ws->width - view->width) / 2;
+ view->y = ws->y + (ws->height - view->height) / 2;
// If the view's border is B_NONE then these properties are ignored.
view->border_top = view->border_bottom = true;
view->border_left = view->border_right = true;
- view_configure(view, lx, ly, width, height);
+ container_set_geometry_from_floating_view(view->swayc);
}
void view_autoconfigure(struct sway_view *view) {
@@ -162,12 +162,14 @@ void view_autoconfigure(struct sway_view *view) {
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
if (view->is_fullscreen) {
- view_configure(view, output->x, output->y, output->width, output->height);
+ view->x = output->x;
+ view->y = output->y;
+ view->width = output->width;
+ view->height = output->height;
return;
}
if (container_is_floating(view->swayc)) {
- view_autoconfigure_floating(view);
return;
}
@@ -268,8 +270,7 @@ void view_set_activated(struct sway_view *view, bool activated) {
}
}
-// Set fullscreen, but without IPC events or arranging windows.
-void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
+void view_set_fullscreen(struct sway_view *view, bool fullscreen) {
if (view->is_fullscreen == fullscreen) {
return;
}
@@ -315,26 +316,17 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
} else {
workspace->sway_workspace->fullscreen = NULL;
if (container_is_floating(view->swayc)) {
- view_configure(view, view->saved_x, view->saved_y,
- view->saved_width, view->saved_height);
+ view->x = view->saved_x;
+ view->y = view->saved_y;
+ view->width = view->saved_width;
+ view->height = view->saved_height;
+ container_set_geometry_from_floating_view(view->swayc);
} else {
view->swayc->width = view->swayc->saved_width;
view->swayc->height = view->swayc->saved_height;
}
}
-}
-
-void view_set_fullscreen(struct sway_view *view, bool fullscreen) {
- if (view->is_fullscreen == fullscreen) {
- return;
- }
- view_set_fullscreen_raw(view, fullscreen);
-
- struct sway_container *workspace =
- container_parent(view->swayc, C_WORKSPACE);
- arrange_workspace(workspace);
- output_damage_whole(workspace->parent->sway_output);
ipc_event_window(view->swayc, "fullscreen_mode");
}
@@ -517,8 +509,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
container_set_floating(view->swayc, true);
- } else {
- arrange_children_of(cont->parent);
}
input_manager_set_focus(input_manager, cont);
@@ -530,7 +520,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
container_notify_subtree_changed(view->swayc->parent);
view_execute_criteria(view);
- container_damage_whole(cont);
view_handle_container_reparent(&view->container_reparent, NULL);
}
@@ -561,11 +550,7 @@ void view_unmap(struct sway_view *view) {
view->title_format = NULL;
}
- if (parent->type == C_OUTPUT) {
- arrange_output(parent);
- } else {
- arrange_children_of(parent);
- }
+ arrange_and_commit(parent);
}
void view_update_position(struct sway_view *view, double lx, double ly) {
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 9ba210fd..ead752ad 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -425,7 +425,7 @@ bool workspace_switch(struct sway_container *workspace) {
}
seat_set_focus(seat, next);
struct sway_container *output = container_parent(workspace, C_OUTPUT);
- arrange_output(output);
+ arrange_and_commit(output);
return true;
}