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

@ -3,6 +3,7 @@
#include "sway/config.h"
#include "sway/input/cursor.h"
#include "sway/input/input-manager.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.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)) {
container_damage_whole(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);
if (seat->cursor) {
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);
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
arrange_and_commit(workspace);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -1,6 +1,7 @@
#include "log.h"
#include "sway/commands.h"
#include "sway/config.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/view.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);
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
arrange_and_commit(workspace->parent);
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);
arrange_children_of(parent);
arrange_and_commit(parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}

View file

@ -5,8 +5,10 @@
#include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h>
#include "sway/commands.h"
#include "sway/desktop/transaction.h"
#include "sway/input/seat.h"
#include "sway/output.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.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);
container_reap_empty(old_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);
} else if (strcasecmp(argv[1], "to") == 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);
container_reap_empty(old_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_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);
}
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);
}
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 *error = NULL;
int move_amt = 10;
@ -173,13 +206,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
}
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) {
container_move(current, MOVE_RIGHT, move_amt);
move_in_direction(current, MOVE_RIGHT, move_amt);
} 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) {
container_move(current, MOVE_DOWN, move_amt);
move_in_direction(current, MOVE_DOWN, move_amt);
} else if (strcasecmp(argv[0], "container") == 0
|| strcasecmp(argv[0], "window") == 0) {
return cmd_move_container(current, argc, argv);

View file

@ -12,6 +12,6 @@ struct cmd_results *cmd_reload(int argc, char **argv) {
}
load_swaybars();
arrange_root();
arrange_and_commit(&root_container);
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) {

View file

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

View file

@ -1,6 +1,8 @@
#include <strings.h>
#include <wlr/util/log.h>
#include "sway/commands.h"
#include "sway/desktop/transaction.h"
#include "sway/tree/arrange.h"
#include "sway/tree/layout.h"
#include "sway/tree/view.h"
#include "stringop.h"
@ -76,5 +78,15 @@ struct cmd_results *cmd_swap(int argc, char **argv) {
}
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);
}