Refactor everything that needs to arrange windows

* The arrange_foo functions are now replaced with arrange_and_commit, or
with manually created transactions and arrange_windows x2.
* The arrange functions are now only called from the highest level
functions rather than from both high level and low level functions.
* Due to the previous point, view_set_fullscreen_raw and
view_set_fullscreen are both merged into one function again.
* Floating and fullscreen are now working with transactions.
This commit is contained in:
Ryan Dwyer 2018-06-06 22:57:34 +10:00
parent f9e6d703d2
commit bb66e6d578
24 changed files with 192 additions and 171 deletions

View file

@ -16,12 +16,7 @@
* the updates all at the same time. * the updates all at the same time.
*/ */
struct sway_transaction { struct sway_transaction;
struct wl_event_source *timer;
list_t *instructions; // struct sway_transaction_instruction *
list_t *damage; // struct wlr_box *
size_t num_waiting;
};
/** /**
* Create a new transaction. * Create a new transaction.

View file

@ -23,11 +23,4 @@ void arrange_windows(struct sway_container *container,
*/ */
void arrange_and_commit(struct sway_container *container); void arrange_and_commit(struct sway_container *container);
// These functions are temporary and are only here to make everything compile.
// They are wrappers around arrange_and_commit.
void arrange_root(void);
void arrange_output(struct sway_container *container);
void arrange_workspace(struct sway_container *container);
void arrange_children_of(struct sway_container *container);
#endif #endif

View file

@ -214,6 +214,11 @@ const char *view_get_shell(struct sway_view *view);
uint32_t view_configure(struct sway_view *view, double lx, double ly, int width, uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
int height); int height);
/**
* Center the view in its workspace and build the swayc decorations around it.
*/
void view_init_floating(struct sway_view *view);
/** /**
* Configure the view's position and size based on the swayc's position and * Configure the view's position and size based on the swayc's position and
* size, taking borders into consideration. * size, taking borders into consideration.

View file

@ -3,6 +3,7 @@
#include "sway/config.h" #include "sway/config.h"
#include "sway/input/cursor.h" #include "sway/input/cursor.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
@ -38,13 +39,11 @@ struct cmd_results *cmd_border(int argc, char **argv) {
} }
if (container_is_floating(view->swayc)) { if (container_is_floating(view->swayc)) {
container_damage_whole(view->swayc);
container_set_geometry_from_floating_view(view->swayc); container_set_geometry_from_floating_view(view->swayc);
container_damage_whole(view->swayc);
} else {
view_autoconfigure(view);
} }
arrange_and_commit(view->swayc);
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
if (seat->cursor) { if (seat->cursor) {
cursor_send_pointer_motion(seat->cursor, 0, false); cursor_send_pointer_motion(seat->cursor, 0, false);

View file

@ -36,5 +36,8 @@ struct cmd_results *cmd_floating(int argc, char **argv) {
container_set_floating(container, wants_floating); container_set_floating(container, wants_floating);
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
arrange_and_commit(workspace);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -1,6 +1,7 @@
#include "log.h" #include "log.h"
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/config.h" #include "sway/config.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
@ -32,5 +33,8 @@ struct cmd_results *cmd_fullscreen(int argc, char **argv) {
view_set_fullscreen(view, wants_fullscreen); view_set_fullscreen(view, wants_fullscreen);
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
arrange_and_commit(workspace->parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -49,7 +49,7 @@ struct cmd_results *cmd_layout(int argc, char **argv) {
} }
container_notify_subtree_changed(parent); container_notify_subtree_changed(parent);
arrange_children_of(parent); arrange_and_commit(parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -5,8 +5,10 @@
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/desktop/transaction.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
@ -96,6 +98,12 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
seat_set_focus(config->handler_context.seat, focus); seat_set_focus(config->handler_context.seat, focus);
container_reap_empty(old_parent); container_reap_empty(old_parent);
container_reap_empty(destination->parent); container_reap_empty(destination->parent);
struct sway_transaction *txn = transaction_create();
arrange_windows(old_parent, txn);
arrange_windows(destination->parent, txn);
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} else if (strcasecmp(argv[1], "to") == 0 } else if (strcasecmp(argv[1], "to") == 0
&& strcasecmp(argv[2], "output") == 0) { && strcasecmp(argv[2], "output") == 0) {
@ -125,6 +133,12 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
seat_set_focus(config->handler_context.seat, old_parent); seat_set_focus(config->handler_context.seat, old_parent);
container_reap_empty(old_parent); container_reap_empty(old_parent);
container_reap_empty(focus->parent); container_reap_empty(focus->parent);
struct sway_transaction *txn = transaction_create();
arrange_windows(old_parent, txn);
arrange_windows(focus->parent, txn);
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, "move", expected_syntax);
@ -152,9 +166,28 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current,
current = container_parent(current, C_WORKSPACE); current = container_parent(current, C_WORKSPACE);
} }
container_move_to(current, destination); container_move_to(current, destination);
struct sway_transaction *txn = transaction_create();
arrange_windows(source, txn);
arrange_windows(destination, txn);
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
static void move_in_direction(struct sway_container *container,
enum wlr_direction direction, int move_amt) {
struct sway_container *old_parent = container->parent;
container_move(container, direction, move_amt);
struct sway_transaction *txn = transaction_create();
arrange_windows(old_parent, txn);
if (container->parent != old_parent) {
arrange_windows(container->parent, txn);
}
transaction_commit(txn);
}
struct cmd_results *cmd_move(int argc, char **argv) { struct cmd_results *cmd_move(int argc, char **argv) {
struct cmd_results *error = NULL; struct cmd_results *error = NULL;
int move_amt = 10; int move_amt = 10;
@ -173,13 +206,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
} }
if (strcasecmp(argv[0], "left") == 0) { if (strcasecmp(argv[0], "left") == 0) {
container_move(current, MOVE_LEFT, move_amt); move_in_direction(current, MOVE_LEFT, move_amt);
} else if (strcasecmp(argv[0], "right") == 0) { } else if (strcasecmp(argv[0], "right") == 0) {
container_move(current, MOVE_RIGHT, move_amt); move_in_direction(current, MOVE_RIGHT, move_amt);
} else if (strcasecmp(argv[0], "up") == 0) { } else if (strcasecmp(argv[0], "up") == 0) {
container_move(current, MOVE_UP, move_amt); move_in_direction(current, MOVE_UP, move_amt);
} else if (strcasecmp(argv[0], "down") == 0) { } else if (strcasecmp(argv[0], "down") == 0) {
container_move(current, MOVE_DOWN, move_amt); move_in_direction(current, MOVE_DOWN, move_amt);
} else if (strcasecmp(argv[0], "container") == 0 } else if (strcasecmp(argv[0], "container") == 0
|| strcasecmp(argv[0], "window") == 0) { || strcasecmp(argv[0], "window") == 0) {
return cmd_move_container(current, argc, argv); return cmd_move_container(current, argc, argv);

View file

@ -12,6 +12,6 @@ struct cmd_results *cmd_reload(int argc, char **argv) {
} }
load_swaybars(); load_swaybars();
arrange_root(); arrange_and_commit(&root_container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -182,7 +182,7 @@ static void resize_tiled(int amount, enum resize_axis axis) {
} }
} }
arrange_children_of(parent->parent); arrange_and_commit(parent->parent);
} }
static void resize(int amount, enum resize_axis axis, enum resize_unit unit) { static void resize(int amount, enum resize_axis axis, enum resize_unit unit) {

View file

@ -16,7 +16,7 @@ static struct cmd_results *do_split(int layout) {
} }
struct sway_container *parent = container_split(con, layout); struct sway_container *parent = container_split(con, layout);
container_create_notify(parent); container_create_notify(parent);
arrange_children_of(parent); arrange_and_commit(parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -1,6 +1,8 @@
#include <strings.h> #include <strings.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/desktop/transaction.h"
#include "sway/tree/arrange.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "stringop.h" #include "stringop.h"
@ -76,5 +78,15 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
} }
container_swap(current, other); container_swap(current, other);
struct sway_transaction *txn = transaction_create();
arrange_windows(current->parent, txn);
if (other->parent != current->parent) {
arrange_windows(other->parent, txn);
}
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -735,6 +735,6 @@ void config_update_font_height(bool recalculate) {
} }
if (config->font_height != prev_max_height) { if (config->font_height != prev_max_height) {
arrange_root(); arrange_and_commit(&root_container);
} }
} }

View file

@ -176,7 +176,7 @@ void arrange_layers(struct sway_output *output) {
sizeof(struct wlr_box)) != 0) { sizeof(struct wlr_box)) != 0) {
wlr_log(L_DEBUG, "Usable area changed, rearranging output"); wlr_log(L_DEBUG, "Usable area changed, rearranging output");
memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box)); memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box));
arrange_output(output->swayc); arrange_and_commit(output->swayc);
} }
// Arrange non-exlusive surfaces from top->bottom // Arrange non-exlusive surfaces from top->bottom

View file

@ -1238,13 +1238,13 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
static void handle_mode(struct wl_listener *listener, void *data) { static void handle_mode(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, mode); struct sway_output *output = wl_container_of(listener, output, mode);
arrange_layers(output); arrange_layers(output);
arrange_output(output->swayc); arrange_and_commit(output->swayc);
} }
static void handle_transform(struct wl_listener *listener, void *data) { static void handle_transform(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, transform); struct sway_output *output = wl_container_of(listener, output, transform);
arrange_layers(output); arrange_layers(output);
arrange_output(output->swayc); arrange_and_commit(output->swayc);
} }
static void handle_scale_iterator(struct sway_container *view, void *data) { static void handle_scale_iterator(struct sway_container *view, void *data) {
@ -1254,8 +1254,8 @@ static void handle_scale_iterator(struct sway_container *view, void *data) {
static void handle_scale(struct wl_listener *listener, void *data) { static void handle_scale(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, scale); struct sway_output *output = wl_container_of(listener, output, scale);
arrange_layers(output); arrange_layers(output);
arrange_output(output->swayc);
container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL); container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL);
arrange_and_commit(output->swayc);
} }
void handle_new_output(struct wl_listener *listener, void *data) { void handle_new_output(struct wl_listener *listener, void *data) {
@ -1314,5 +1314,5 @@ void output_enable(struct sway_output *output) {
output->damage_destroy.notify = damage_handle_destroy; output->damage_destroy.notify = damage_handle_destroy;
arrange_layers(output); arrange_layers(output);
arrange_root(); arrange_and_commit(&root_container);
} }

View file

@ -17,6 +17,13 @@
*/ */
#define TIMEOUT_MS 200 #define TIMEOUT_MS 200
struct sway_transaction {
struct wl_event_source *timer;
list_t *instructions; // struct sway_transaction_instruction *
list_t *damage; // struct wlr_box *
size_t num_waiting;
};
struct sway_transaction_instruction { struct sway_transaction_instruction {
struct sway_transaction *transaction; struct sway_transaction *transaction;
struct sway_container *container; struct sway_container *container;
@ -162,16 +169,18 @@ void transaction_commit(struct sway_transaction *transaction) {
for (int i = 0; i < transaction->instructions->length; ++i) { for (int i = 0; i < transaction->instructions->length; ++i) {
struct sway_transaction_instruction *instruction = struct sway_transaction_instruction *instruction =
transaction->instructions->items[i]; transaction->instructions->items[i];
if (instruction->container->type == C_VIEW) { struct sway_container *con = instruction->container;
struct sway_view *view = instruction->container->sway_view; if (con->type == C_VIEW &&
instruction->serial = view_configure(view, (con->current.view_width != instruction->state.view_width ||
con->current.view_height != instruction->state.view_height)) {
instruction->serial = view_configure(con->sway_view,
instruction->state.view_x, instruction->state.view_x,
instruction->state.view_y, instruction->state.view_y,
instruction->state.view_width, instruction->state.view_width,
instruction->state.view_height); instruction->state.view_height);
if (instruction->serial) { if (instruction->serial) {
save_view_texture(view); save_view_texture(con->sway_view);
list_add(view->instructions, instruction); list_add(con->sway_view->instructions, instruction);
++transaction->num_waiting; ++transaction->num_waiting;
} }
} }

View file

@ -5,10 +5,10 @@
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/util/edges.h> #include <wlr/util/edges.h>
#include "log.h" #include "log.h"
#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
@ -210,8 +210,14 @@ static void handle_map(struct wl_listener *listener, void *data) {
view->natural_width = view->wlr_xdg_surface->surface->current->width; view->natural_width = view->wlr_xdg_surface->surface->current->width;
view->natural_height = view->wlr_xdg_surface->surface->current->height; view->natural_height = view->wlr_xdg_surface->surface->current->height;
} }
view_map(view, view->wlr_xdg_surface->surface); view_map(view, view->wlr_xdg_surface->surface);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
}
arrange_and_commit(view->swayc->parent);
xdg_shell_view->commit.notify = handle_commit; xdg_shell_view->commit.notify = handle_commit;
wl_signal_add(&xdg_surface->surface->events.commit, wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_view->commit); &xdg_shell_view->commit);
@ -219,10 +225,6 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_view->new_popup.notify = handle_new_popup; xdg_shell_view->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_surface->events.new_popup, wl_signal_add(&xdg_surface->events.new_popup,
&xdg_shell_view->new_popup); &xdg_shell_view->new_popup);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
}
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -237,6 +239,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
struct wlr_xdg_toplevel_set_fullscreen_event *e = data; struct wlr_xdg_toplevel_set_fullscreen_event *e = data;
struct wlr_xdg_surface *xdg_surface = struct wlr_xdg_surface *xdg_surface =
xdg_shell_view->view.wlr_xdg_surface; xdg_shell_view->view.wlr_xdg_surface;
struct sway_view *view = &xdg_shell_view->view;
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL, if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL,
"xdg_shell requested fullscreen of surface with role %i", "xdg_shell requested fullscreen of surface with role %i",
@ -247,7 +250,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return; return;
} }
view_set_fullscreen(&xdg_shell_view->view, e->fullscreen); view_set_fullscreen(view, e->fullscreen);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} }
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {

View file

@ -3,10 +3,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include "sway/desktop/transaction.h" #include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/server.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
@ -210,8 +210,14 @@ static void handle_map(struct wl_listener *listener, void *data) {
view->natural_width = view->wlr_xdg_surface_v6->surface->current->width; view->natural_width = view->wlr_xdg_surface_v6->surface->current->width;
view->natural_height = view->wlr_xdg_surface_v6->surface->current->height; view->natural_height = view->wlr_xdg_surface_v6->surface->current->height;
} }
view_map(view, view->wlr_xdg_surface_v6->surface); view_map(view, view->wlr_xdg_surface_v6->surface);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
}
arrange_and_commit(view->swayc->parent);
xdg_shell_v6_view->commit.notify = handle_commit; xdg_shell_v6_view->commit.notify = handle_commit;
wl_signal_add(&xdg_surface->surface->events.commit, wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_v6_view->commit); &xdg_shell_v6_view->commit);
@ -219,10 +225,6 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_v6_view->new_popup.notify = handle_new_popup; xdg_shell_v6_view->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_surface->events.new_popup, wl_signal_add(&xdg_surface->events.new_popup,
&xdg_shell_v6_view->new_popup); &xdg_shell_v6_view->new_popup);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
}
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -237,6 +239,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data; struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data;
struct wlr_xdg_surface_v6 *xdg_surface = struct wlr_xdg_surface_v6 *xdg_surface =
xdg_shell_v6_view->view.wlr_xdg_surface_v6; xdg_shell_v6_view->view.wlr_xdg_surface_v6;
struct sway_view *view = &xdg_shell_v6_view->view;
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL, if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL,
"xdg_shell_v6 requested fullscreen of surface with role %i", "xdg_shell_v6 requested fullscreen of surface with role %i",
@ -247,7 +250,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return; return;
} }
view_set_fullscreen(&xdg_shell_v6_view->view, e->fullscreen); view_set_fullscreen(view, e->fullscreen);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} }
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {

View file

@ -11,6 +11,7 @@
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
@ -292,6 +293,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
if (xsurface->fullscreen) { if (xsurface->fullscreen) {
view_set_fullscreen(view, true); view_set_fullscreen(view, true);
} }
arrange_and_commit(view->swayc);
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
@ -325,6 +327,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return; return;
} }
view_set_fullscreen(view, xsurface->fullscreen); view_set_fullscreen(view, xsurface->fullscreen);
arrange_and_commit(view->swayc);
} }
static void handle_set_title(struct wl_listener *listener, void *data) { static void handle_set_title(struct wl_listener *listener, void *data) {

View file

@ -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) { struct sway_transaction *transaction) {
if (config->reloading) { if (config->reloading) {
return; return;
@ -162,7 +178,8 @@ static void _arrange_children_of(struct sway_container *parent,
apply_horiz_layout(parent); apply_horiz_layout(parent);
break; break;
case L_FLOATING: case L_FLOATING:
sway_assert(false, "Didn't expect to see floating here"); arrange_floating(parent, transaction);
break;
} }
// Recurse into child containers // Recurse into child containers
@ -171,13 +188,13 @@ static void _arrange_children_of(struct sway_container *parent,
if (child->type == C_VIEW) { if (child->type == C_VIEW) {
view_autoconfigure(child->sway_view); view_autoconfigure(child->sway_view);
} else { } else {
_arrange_children_of(child, transaction); arrange_children_of(child, transaction);
} }
transaction_add_container(transaction, child); 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) { struct sway_transaction *transaction) {
if (config->reloading) { if (config->reloading) {
return; return;
@ -193,10 +210,11 @@ static void _arrange_workspace(struct sway_container *workspace,
transaction_add_container(transaction, workspace); transaction_add_container(transaction, workspace);
wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
workspace->x, workspace->y); 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) { struct sway_transaction *transaction) {
if (config->reloading) { if (config->reloading) {
return; return;
@ -213,11 +231,11 @@ static void _arrange_output(struct sway_container *output,
output->name, output->x, output->y); output->name, output->x, output->y);
for (int i = 0; i < output->children->length; ++i) { for (int i = 0; i < output->children->length; ++i) {
struct sway_container *workspace = output->children->items[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) { if (config->reloading) {
return; return;
} }
@ -232,7 +250,7 @@ static void _arrange_root(struct sway_transaction *transaction) {
transaction_add_container(transaction, &root_container); transaction_add_container(transaction, &root_container);
for (int i = 0; i < root_container.children->length; ++i) { for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *output = root_container.children->items[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) { struct sway_transaction *transaction) {
switch (container->type) { switch (container->type) {
case C_ROOT: case C_ROOT:
_arrange_root(transaction); arrange_root(transaction);
break; break;
case C_OUTPUT: case C_OUTPUT:
_arrange_output(container, transaction); arrange_output(container, transaction);
break; break;
case C_WORKSPACE: case C_WORKSPACE:
_arrange_workspace(container, transaction); arrange_workspace(container, transaction);
break; break;
case C_CONTAINER: case C_CONTAINER:
_arrange_children_of(container, transaction); arrange_children_of(container, transaction);
transaction_add_container(transaction, container); transaction_add_container(transaction, container);
break; break;
case C_VIEW: case C_VIEW:
view_autoconfigure(container->sway_view);
transaction_add_container(transaction, container);
break; break;
case C_TYPES: case C_TYPES:
break; break;
@ -265,20 +285,3 @@ void arrange_and_commit(struct sway_container *container) {
arrange_windows(container, transaction); arrange_windows(container, transaction);
transaction_commit(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);
}

View file

@ -204,6 +204,7 @@ static struct sway_container *container_workspace_destroy(
container_move_to(floating->children->items[i], container_move_to(floating->children->items[i],
new_workspace->sway_workspace->floating); new_workspace->sway_workspace->floating);
} }
arrange_and_commit(new_workspace);
} }
struct sway_workspace *sway_workspace = workspace->sway_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); 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->mode.link);
wl_list_remove(&output->sway_output->transform.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_container *workspace = container_parent(container, C_WORKSPACE);
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
container_damage_whole(container);
if (enable) { if (enable) {
container_remove_child(container); container_remove_child(container);
container_add_child(workspace->sway_workspace->floating, container); container_add_child(workspace->sway_workspace->floating, container);
if (container->type == C_VIEW) { 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)); seat_set_focus(seat, seat_get_focus_inactive(seat, container));
container_reap_empty_recursive(workspace); container_reap_empty_recursive(workspace);
@ -943,8 +943,8 @@ void container_set_floating(struct sway_container *container, bool enable) {
container->is_sticky = false; container->is_sticky = false;
container_reap_empty_recursive(workspace->sway_workspace->floating); 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) { void container_set_geometry_from_floating_view(struct sway_container *con) {

View file

@ -22,7 +22,7 @@ struct sway_container root_container;
static void output_layout_handle_change(struct wl_listener *listener, static void output_layout_handle_change(struct wl_listener *listener,
void *data) { void *data) {
arrange_root(); arrange_and_commit(&root_container);
} }
void layout_init(void) { void layout_init(void) {
@ -56,18 +56,17 @@ static int index_child(const struct sway_container *child) {
return -1; 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) { 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; return;
} }
struct sway_view *view = viewcon->sway_view; struct sway_view *view = con->sway_view;
struct sway_container *old_workspace = old_parent; struct sway_container *old_workspace = old_parent;
if (old_workspace && old_workspace->type != C_WORKSPACE) { if (old_workspace && old_workspace->type != C_WORKSPACE) {
old_workspace = container_parent(old_workspace, C_WORKSPACE); old_workspace = container_parent(old_workspace, C_WORKSPACE);
} }
struct sway_container *new_workspace = container_parent(view->swayc, struct sway_container *new_workspace = container_parent(con, C_WORKSPACE);
C_WORKSPACE);
if (old_workspace == new_workspace) { if (old_workspace == new_workspace) {
return; return;
} }
@ -78,15 +77,19 @@ static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
// Mark the new workspace as fullscreen // Mark the new workspace as fullscreen
if (new_workspace->sway_workspace->fullscreen) { if (new_workspace->sway_workspace->fullscreen) {
view_set_fullscreen_raw( view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false);
new_workspace->sway_workspace->fullscreen, false);
} }
new_workspace->sway_workspace->fullscreen = view; new_workspace->sway_workspace->fullscreen = view;
// Resize view to new output dimensions // Resize view to new output dimensions
struct sway_container *output = new_workspace->parent; struct sway_container *output = new_workspace->parent;
view_configure(view, 0, 0, output->width, output->height); view->x = output->x;
view->swayc->width = output->width; view->y = output->y;
view->swayc->height = output->height; 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, 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(old_parent);
container_notify_subtree_changed(new_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 // If view was moved to a fullscreen workspace, refocus the fullscreen view
struct sway_container *new_workspace = container; struct sway_container *new_workspace = container;
if (new_workspace->type != C_WORKSPACE) { if (new_workspace->type != C_WORKSPACE) {
@ -214,7 +206,8 @@ void container_move_to(struct sway_container *container,
if (focus_ws->type != C_WORKSPACE) { if (focus_ws->type != C_WORKSPACE) {
focus_ws = container_parent(focus_ws, 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) { if (focus_ws != new_workspace) {
seat_set_focus(seat, focus); seat_set_focus(seat, focus);
} }
@ -308,7 +301,6 @@ static void workspace_rejigger(struct sway_container *ws,
container_reap_empty_recursive(original_parent); container_reap_empty_recursive(original_parent);
wl_signal_emit(&child->events.reparent, original_parent); wl_signal_emit(&child->events.reparent, original_parent);
container_create_notify(new_parent); container_create_notify(new_parent);
arrange_workspace(ws);
} }
static void move_out_of_tabs_stacks(struct sway_container *container, 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); wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id);
current->parent->layout = move_dir == current->parent->layout = move_dir ==
MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; 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; return;
} }
@ -339,11 +326,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
container_flatten(new_parent->parent); container_flatten(new_parent->parent);
} }
container_create_notify(new_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); 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); struct sway_container *new_parent = container_flatten(parent);
if (new_parent != parent) { if (new_parent != parent) {
// Special case: we were the last one in this container, so flatten it // Special case: we were the last one in this container, so leave
// and leave
arrange_children_of(new_parent);
update_debug_tree();
return; return;
} }
@ -452,12 +431,9 @@ void container_move(struct sway_container *container,
wlr_log(L_DEBUG, "Hit limit, " wlr_log(L_DEBUG, "Hit limit, "
"promoting descendant to sibling"); "promoting descendant to sibling");
// Special case // Special case
struct sway_container *old_parent = container->parent;
container_insert_child(current->parent, container, container_insert_child(current->parent, container,
index + (offs < 0 ? 0 : 1)); index + (offs < 0 ? 0 : 1));
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(current->parent);
arrange_children_of(old_parent);
return; return;
} }
} else { } else {
@ -491,14 +467,11 @@ void container_move(struct sway_container *container,
wlr_log(L_DEBUG, "Swapping siblings"); wlr_log(L_DEBUG, "Swapping siblings");
sibling->parent->children->items[index + offs] = container; sibling->parent->children->items[index + offs] = container;
sibling->parent->children->items[index] = sibling; sibling->parent->children->items[index] = sibling;
arrange_children_of(sibling->parent);
} else { } else {
wlr_log(L_DEBUG, "Promoting to sibling of cousin"); wlr_log(L_DEBUG, "Promoting to sibling of cousin");
container_insert_child(sibling->parent, container, container_insert_child(sibling->parent, container,
index_child(sibling) + (offs > 0 ? 0 : 1)); index_child(sibling) + (offs > 0 ? 0 : 1));
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(sibling->parent);
arrange_children_of(old_parent);
} }
sibling = NULL; sibling = NULL;
break; break;
@ -512,8 +485,6 @@ void container_move(struct sway_container *container,
"(move dir: %d)", limit, move_dir); "(move dir: %d)", limit, move_dir);
container_insert_child(sibling, container, limit); container_insert_child(sibling, container, limit);
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(sibling);
arrange_children_of(old_parent);
sibling = NULL; sibling = NULL;
} else { } else {
wlr_log(L_DEBUG, "Reparenting container (perpendicular)"); wlr_log(L_DEBUG, "Reparenting container (perpendicular)");
@ -537,8 +508,6 @@ void container_move(struct sway_container *container,
container_add_child(sibling, container); container_add_child(sibling, container);
} }
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(sibling);
arrange_children_of(old_parent);
sibling = NULL; sibling = NULL;
} }
break; break;
@ -863,7 +832,6 @@ struct sway_container *container_split(struct sway_container *child,
// Special case: this just behaves like splitt // Special case: this just behaves like splitt
child->prev_layout = child->layout; child->prev_layout = child->layout;
child->layout = layout; child->layout = layout;
arrange_children_of(child);
return child; return child;
} }
@ -1044,9 +1012,6 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
prev_workspace_name = stored_prev_name; prev_workspace_name = stored_prev_name;
} }
arrange_children_of(con1->parent);
arrange_children_of(con2->parent);
if (fs1 && con2->type == C_VIEW) { if (fs1 && con2->type == C_VIEW) {
view_set_fullscreen(con2->sway_view, true); view_set_fullscreen(con2->sway_view, true);
} }

View file

@ -135,22 +135,22 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
return 0; 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); struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
int max_width = ws->width * 0.6666; int max_width = ws->width * 0.6666;
int max_height = ws->height * 0.6666; int max_height = ws->height * 0.6666;
int width = view->width =
view->natural_width > max_width ? max_width : view->natural_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; view->natural_height > max_height ? max_height : view->natural_height;
int lx = ws->x + (ws->width - width) / 2; view->x = ws->x + (ws->width - view->width) / 2;
int ly = ws->y + (ws->height - height) / 2; view->y = ws->y + (ws->height - view->height) / 2;
// If the view's border is B_NONE then these properties are ignored. // If the view's border is B_NONE then these properties are ignored.
view->border_top = view->border_bottom = true; view->border_top = view->border_bottom = true;
view->border_left = view->border_right = 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) { 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); struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
if (view->is_fullscreen) { 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; return;
} }
if (container_is_floating(view->swayc)) { if (container_is_floating(view->swayc)) {
view_autoconfigure_floating(view);
return; 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(struct sway_view *view, bool fullscreen) {
void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
if (view->is_fullscreen == fullscreen) { if (view->is_fullscreen == fullscreen) {
return; return;
} }
@ -315,26 +316,17 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
} else { } else {
workspace->sway_workspace->fullscreen = NULL; workspace->sway_workspace->fullscreen = NULL;
if (container_is_floating(view->swayc)) { if (container_is_floating(view->swayc)) {
view_configure(view, view->saved_x, view->saved_y, view->x = view->saved_x;
view->saved_width, view->saved_height); view->y = view->saved_y;
view->width = view->saved_width;
view->height = view->saved_height;
container_set_geometry_from_floating_view(view->swayc);
} else { } else {
view->swayc->width = view->swayc->saved_width; view->swayc->width = view->swayc->saved_width;
view->swayc->height = view->swayc->saved_height; 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"); 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)) { if (view->impl->wants_floating && view->impl->wants_floating(view)) {
container_set_floating(view->swayc, true); container_set_floating(view->swayc, true);
} else {
arrange_children_of(cont->parent);
} }
input_manager_set_focus(input_manager, cont); 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); container_notify_subtree_changed(view->swayc->parent);
view_execute_criteria(view); view_execute_criteria(view);
container_damage_whole(cont);
view_handle_container_reparent(&view->container_reparent, NULL); view_handle_container_reparent(&view->container_reparent, NULL);
} }
@ -561,11 +550,7 @@ void view_unmap(struct sway_view *view) {
view->title_format = NULL; view->title_format = NULL;
} }
if (parent->type == C_OUTPUT) { arrange_and_commit(parent);
arrange_output(parent);
} else {
arrange_children_of(parent);
}
} }
void view_update_position(struct sway_view *view, double lx, double ly) { void view_update_position(struct sway_view *view, double lx, double ly) {

View file

@ -425,7 +425,7 @@ bool workspace_switch(struct sway_container *workspace) {
} }
seat_set_focus(seat, next); seat_set_focus(seat, next);
struct sway_container *output = container_parent(workspace, C_OUTPUT); struct sway_container *output = container_parent(workspace, C_OUTPUT);
arrange_output(output); arrange_and_commit(output);
return true; return true;
} }