aboutsummaryrefslogtreecommitdiff
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/border.c7
-rw-r--r--sway/commands/floating.c3
-rw-r--r--sway/commands/fullscreen.c4
-rw-r--r--sway/commands/gaps.c18
-rw-r--r--sway/commands/layout.c2
-rw-r--r--sway/commands/move.c61
-rw-r--r--sway/commands/reload.c2
-rw-r--r--sway/commands/resize.c2
-rw-r--r--sway/commands/smart_gaps.c5
-rw-r--r--sway/commands/split.c2
-rw-r--r--sway/commands/swap.c12
11 files changed, 92 insertions, 26 deletions
diff --git a/sway/commands/border.c b/sway/commands/border.c
index 0b059562..6db85395 100644
--- a/sway/commands/border.c
+++ b/sway/commands/border.c
@@ -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);
diff --git a/sway/commands/floating.c b/sway/commands/floating.c
index 46b761da..e6003521 100644
--- a/sway/commands/floating.c
+++ b/sway/commands/floating.c
@@ -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);
}
diff --git a/sway/commands/fullscreen.c b/sway/commands/fullscreen.c
index ec9ec276..1a4d8b41 100644
--- a/sway/commands/fullscreen.c
+++ b/sway/commands/fullscreen.c
@@ -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);
}
diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c
index aacb792b..801fb179 100644
--- a/sway/commands/gaps.c
+++ b/sway/commands/gaps.c
@@ -31,21 +31,19 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
if (strcmp(argv[1], "on") == 0) {
config->edge_gaps = true;
- arrange_root();
} else if (strcmp(argv[1], "off") == 0) {
config->edge_gaps = false;
- arrange_root();
} else if (strcmp(argv[1], "toggle") == 0) {
if (!config->active) {
return cmd_results_new(CMD_INVALID, "gaps",
"Cannot toggle gaps while not running.");
}
config->edge_gaps = !config->edge_gaps;
- arrange_root();
} else {
return cmd_results_new(CMD_INVALID, "gaps",
"gaps edge_gaps on|off|toggle");
}
+ arrange_and_commit(&root_container);
} else {
int amount_idx = 0; // the current index in argv
enum gaps_op op = GAPS_OP_SET;
@@ -120,13 +118,13 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
"gaps inner|outer <amount>");
}
return cmd_results_new(CMD_INVALID, "gaps",
- "gaps inner|outer all|workspace|current set|plus|minus <amount>");
+ "gaps inner|outer all|workspace|current set|plus|minus <amount>");
}
if (amount_idx == 0) { // gaps <amount>
config->gaps_inner = val;
config->gaps_outer = val;
- arrange_root();
+ arrange_and_commit(&root_container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
// Other variants. The middle-length variant (gaps inner|outer <amount>)
@@ -150,14 +148,14 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
break;
}
}
-
+
if (scope == GAPS_SCOPE_ALL) {
if (inner) {
config->gaps_inner = total;
} else {
config->gaps_outer = total;
}
- arrange_root();
+ arrange_and_commit(&root_container);
} else {
struct sway_container *c =
config->handler_context.current_container;
@@ -171,11 +169,7 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
c->gaps_outer = total;
}
- if (c->parent) {
- arrange_children_of(c->parent);
- } else {
- arrange_root();
- }
+ arrange_and_commit(c->parent ? c->parent : &root_container);
}
}
diff --git a/sway/commands/layout.c b/sway/commands/layout.c
index a009e38f..9945fa5c 100644
--- a/sway/commands/layout.c
+++ b/sway/commands/layout.c
@@ -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);
}
diff --git a/sway/commands/move.c b/sway/commands/move.c
index dc9a6f6f..a4fae388 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -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"
@@ -88,6 +90,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
}
free(ws_name);
struct sway_container *old_parent = current->parent;
+ struct sway_container *old_ws = container_parent(current, C_WORKSPACE);
struct sway_container *destination = seat_get_focus_inactive(
config->handler_context.seat, ws);
container_move_to(current, destination);
@@ -96,6 +99,15 @@ 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);
+
+ // TODO: Ideally we would arrange the surviving parent after reaping,
+ // but container_reap_empty does not return it, so we arrange the
+ // workspace instead.
+ struct sway_transaction *txn = transaction_create();
+ arrange_windows(old_ws, 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) {
@@ -121,10 +133,20 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
focus = destination->children->items[0];
}
struct sway_container *old_parent = current->parent;
+ struct sway_container *old_ws = container_parent(current, C_WORKSPACE);
container_move_to(current, focus);
seat_set_focus(config->handler_context.seat, old_parent);
container_reap_empty(old_parent);
container_reap_empty(focus->parent);
+
+ // TODO: Ideally we would arrange the surviving parent after reaping,
+ // but container_reap_empty does not return it, so we arrange the
+ // workspace instead.
+ struct sway_transaction *txn = transaction_create();
+ arrange_windows(old_ws, 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,6 +174,37 @@ 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 struct cmd_results *move_in_direction(struct sway_container *container,
+ enum movement_direction direction, int move_amt) {
+ if (container->type == C_WORKSPACE) {
+ return cmd_results_new(CMD_FAILURE, "move",
+ "Cannot move workspaces in a direction");
+ }
+ // For simplicity, we'll arrange the entire workspace. The reason for this
+ // is moving the container might reap the old parent, and container_move
+ // does not return a surviving parent.
+ // TODO: Make container_move return the surviving parent so we can arrange
+ // just that.
+ struct sway_container *old_ws = container_parent(container, C_WORKSPACE);
+ container_move(container, direction, move_amt);
+ struct sway_container *new_ws = container_parent(container, C_WORKSPACE);
+
+ struct sway_transaction *txn = transaction_create();
+ arrange_windows(old_ws, txn);
+ if (new_ws != old_ws) {
+ arrange_windows(new_ws, txn);
+ }
+ transaction_commit(txn);
+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
@@ -173,13 +226,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
}
if (strcasecmp(argv[0], "left") == 0) {
- container_move(current, MOVE_LEFT, move_amt);
+ return move_in_direction(current, MOVE_LEFT, move_amt);
} else if (strcasecmp(argv[0], "right") == 0) {
- container_move(current, MOVE_RIGHT, move_amt);
+ return move_in_direction(current, MOVE_RIGHT, move_amt);
} else if (strcasecmp(argv[0], "up") == 0) {
- container_move(current, MOVE_UP, move_amt);
+ return move_in_direction(current, MOVE_UP, move_amt);
} else if (strcasecmp(argv[0], "down") == 0) {
- container_move(current, MOVE_DOWN, move_amt);
+ return 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);
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index 092dd46f..9fc213c4 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -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);
}
diff --git a/sway/commands/resize.c b/sway/commands/resize.c
index 29637953..6357343e 100644
--- a/sway/commands/resize.c
+++ b/sway/commands/resize.c
@@ -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) {
diff --git a/sway/commands/smart_gaps.c b/sway/commands/smart_gaps.c
index 38700d65..f687e78e 100644
--- a/sway/commands/smart_gaps.c
+++ b/sway/commands/smart_gaps.c
@@ -16,13 +16,14 @@ struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
if (strcmp(argv[0], "on") == 0) {
config->smart_gaps = true;
- arrange_root();
} else if (strcmp(argv[0], "off") == 0) {
config->smart_gaps = false;
- arrange_root();
} else {
return cmd_results_new(CMD_INVALID, "smart_gaps",
"Expected 'smart_gaps <on|off>' ");
}
+
+ arrange_and_commit(&root_container);
+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/split.c b/sway/commands/split.c
index 57e42a5a..c40f4d9f 100644
--- a/sway/commands/split.c
+++ b/sway/commands/split.c
@@ -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->parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
diff --git a/sway/commands/swap.c b/sway/commands/swap.c
index e8dfc57f..e052058f 100644
--- a/sway/commands/swap.c
+++ b/sway/commands/swap.c
@@ -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);
}