aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-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.c41
-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
-rw-r--r--sway/config.c4
-rw-r--r--sway/desktop/desktop.c3
-rw-r--r--sway/desktop/layer_shell.c2
-rw-r--r--sway/desktop/output.c100
-rw-r--r--sway/desktop/transaction.c232
-rw-r--r--sway/desktop/xdg_shell.c45
-rw-r--r--sway/desktop/xdg_shell_v6.c48
-rw-r--r--sway/desktop/xwayland.c37
-rw-r--r--sway/meson.build1
-rw-r--r--sway/tree/arrange.c326
-rw-r--r--sway/tree/container.c21
-rw-r--r--sway/tree/layout.c74
-rw-r--r--sway/tree/output.c5
-rw-r--r--sway/tree/view.c111
-rw-r--r--sway/tree/workspace.c2
26 files changed, 710 insertions, 399 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..2c9fb77a 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"
@@ -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);
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..7ea14953 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);
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);
}
diff --git a/sway/config.c b/sway/config.c
index 949c5cd3..12a02163 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -531,7 +531,7 @@ static int detect_brace_on_following_line(FILE *file, char *line,
} while (peeked && strlen(peeked) == 0);
if (peeked && strlen(peeked) == 1 && peeked[0] == '{') {
- fseek(file, position, SEEK_SET);
+ fseek(file, position, SEEK_SET);
} else {
lines = 0;
}
@@ -735,6 +735,6 @@ void config_update_font_height(bool recalculate) {
}
if (config->font_height != prev_max_height) {
- arrange_root();
+ arrange_and_commit(&root_container);
}
}
diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c
index 66f33151..e495790c 100644
--- a/sway/desktop/desktop.c
+++ b/sway/desktop/desktop.c
@@ -7,7 +7,8 @@ void desktop_damage_surface(struct wlr_surface *surface, double lx, double ly,
for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *cont = root_container.children->items[i];
if (cont->type == C_OUTPUT) {
- output_damage_surface(cont->sway_output, lx - cont->x, ly - cont->y,
+ output_damage_surface(cont->sway_output,
+ lx - cont->current.swayc_x, ly - cont->current.swayc_y,
surface, whole);
}
}
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index 3accdefb..fe5fc316 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -176,7 +176,7 @@ void arrange_layers(struct sway_output *output) {
sizeof(struct wlr_box)) != 0) {
wlr_log(L_DEBUG, "Usable area changed, rearranging output");
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
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index d4115be8..37528cac 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -69,6 +69,7 @@ struct render_data {
struct root_geometry root_geo;
struct sway_output *output;
pixman_region32_t *damage;
+ struct sway_view *view;
float alpha;
};
@@ -108,6 +109,38 @@ static bool get_surface_box(struct root_geometry *geo,
return wlr_box_intersection(&output_box, &rotated_box, &intersection);
}
+static bool get_view_box(struct root_geometry *geo,
+ struct sway_output *output, struct sway_view *view, int sx, int sy,
+ struct wlr_box *surface_box) {
+ int sw = view->width;
+ int sh = view->height;
+
+ double _sx = sx, _sy = sy;
+ rotate_child_position(&_sx, &_sy, sw, sh, geo->width, geo->height,
+ geo->rotation);
+
+ struct wlr_box box = {
+ .x = geo->x + _sx,
+ .y = geo->y + _sy,
+ .width = sw,
+ .height = sh,
+ };
+ if (surface_box != NULL) {
+ memcpy(surface_box, &box, sizeof(struct wlr_box));
+ }
+
+ struct wlr_box rotated_box;
+ wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box);
+
+ struct wlr_box output_box = {
+ .width = output->swayc->width,
+ .height = output->swayc->height,
+ };
+
+ struct wlr_box intersection;
+ return wlr_box_intersection(&output_box, &rotated_box, &intersection);
+}
+
static void surface_for_each_surface(struct wlr_surface *surface,
double ox, double oy, struct root_geometry *geo,
wlr_surface_iterator_func_t iterator, void *user_data) {
@@ -240,14 +273,26 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
pixman_region32_t *output_damage = data->damage;
float alpha = data->alpha;
- struct wlr_texture *texture = wlr_surface_get_texture(surface);
- if (texture == NULL) {
- return;
+ struct wlr_texture *texture = NULL;
+ struct wlr_box box;
+ bool intersects;
+
+ // If this is the main surface of a view, render the saved_texture instead
+ // if it exists. It exists when we are mid-transaction.
+ if (data->view && data->view->saved_texture &&
+ data->view->surface == surface) {
+ texture = data->view->saved_texture;
+ intersects = get_view_box(&data->root_geo, data->output, data->view,
+ sx, sy, &box);
+ } else {
+ texture = wlr_surface_get_texture(surface);
+ if (texture == NULL) {
+ return;
+ }
+ intersects = get_surface_box(&data->root_geo, data->output, surface,
+ sx, sy, &box);
}
- struct wlr_box box;
- bool intersects = get_surface_box(&data->root_geo, data->output, surface,
- sx, sy, &box);
if (!intersects) {
return;
}
@@ -341,6 +386,7 @@ static void render_view_surfaces(struct sway_view *view,
struct render_data data = {
.output = output,
.damage = damage,
+ .view = view,
.alpha = alpha,
};
output_view_for_each_surface(
@@ -754,9 +800,10 @@ static void render_container_stacked(struct sway_output *output,
marks_texture = view ? view->marks_unfocused : NULL;
}
- int y = con->y + container_titlebar_height() * i;
- render_titlebar(output, damage, child, child->x, y, child->width,
- colors, title_texture, marks_texture);
+ int y = con->current.swayc_y + container_titlebar_height() * i;
+ render_titlebar(output, damage, child, child->current.swayc_x, y,
+ child->current.swayc_width, colors,
+ title_texture, marks_texture);
if (child == current) {
current_colors = colors;
@@ -775,7 +822,7 @@ static void render_container_stacked(struct sway_output *output,
static void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) {
- switch (con->layout) {
+ switch (con->current.layout) {
case L_NONE:
case L_HORIZ:
case L_VERT:
@@ -812,9 +859,10 @@ static void render_floating_container(struct sway_output *soutput,
marks_texture = view->marks_unfocused;
}
- if (con->sway_view->border == B_NORMAL) {
- render_titlebar(soutput, damage, con, con->x, con->y, con->width,
- colors, title_texture, marks_texture);
+ if (con->current.border == B_NORMAL) {
+ render_titlebar(soutput, damage, con, con->current.swayc_x,
+ con->current.swayc_y, con->current.swayc_width, colors,
+ title_texture, marks_texture);
} else {
render_top_border(soutput, damage, con, colors);
}
@@ -1168,6 +1216,16 @@ void output_damage_from_view(struct sway_output *output,
output_damage_view(output, view, false);
}
+// Expecting an unscaled box in layout coordinates
+void output_damage_box(struct sway_output *output, struct wlr_box *_box) {
+ struct wlr_box box;
+ memcpy(&box, _box, sizeof(struct wlr_box));
+ box.x -= output->swayc->current.swayc_x;
+ box.y -= output->swayc->current.swayc_y;
+ scale_box(&box, output->wlr_output->scale);
+ wlr_output_damage_add_box(output->damage, &box);
+}
+
static void output_damage_whole_container_iterator(struct sway_container *con,
void *data) {
struct sway_output *output = data;
@@ -1182,10 +1240,10 @@ static void output_damage_whole_container_iterator(struct sway_container *con,
void output_damage_whole_container(struct sway_output *output,
struct sway_container *con) {
struct wlr_box box = {
- .x = con->x - output->wlr_output->lx,
- .y = con->y - output->wlr_output->ly,
- .width = con->width,
- .height = con->height,
+ .x = con->current.swayc_x - output->wlr_output->lx,
+ .y = con->current.swayc_y - output->wlr_output->ly,
+ .width = con->current.swayc_width,
+ .height = con->current.swayc_height,
};
scale_box(&box, output->wlr_output->scale);
wlr_output_damage_add_box(output->damage, &box);
@@ -1212,13 +1270,13 @@ static void handle_destroy(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);
arrange_layers(output);
- arrange_output(output->swayc);
+ arrange_and_commit(output->swayc);
}
static void handle_transform(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, transform);
arrange_layers(output);
- arrange_output(output->swayc);
+ arrange_and_commit(output->swayc);
}
static void handle_scale_iterator(struct sway_container *view, void *data) {
@@ -1228,8 +1286,8 @@ static void handle_scale_iterator(struct sway_container *view, void *data) {
static void handle_scale(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, scale);
arrange_layers(output);
- arrange_output(output->swayc);
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) {
@@ -1293,5 +1351,5 @@ void output_enable(struct sway_output *output) {
output->damage_destroy.notify = damage_handle_destroy;
arrange_layers(output);
- arrange_root();
+ arrange_and_commit(&root_container);
}
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
new file mode 100644
index 00000000..07bfbf7a
--- /dev/null
+++ b/sway/desktop/transaction.c
@@ -0,0 +1,232 @@
+#define _POSIX_C_SOURCE 200809L
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <wlr/types/wlr_linux_dmabuf.h>
+#include "sway/debug.h"
+#include "sway/desktop/transaction.h"
+#include "sway/output.h"
+#include "sway/tree/container.h"
+#include "sway/tree/view.h"
+#include "list.h"
+#include "log.h"
+
+/**
+ * How long we should wait for views to respond to the configure before giving
+ * up and applying the transaction anyway.
+ */
+#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 *transaction;
+ struct sway_container *container;
+ struct sway_container_state state;
+ uint32_t serial;
+};
+
+struct sway_transaction *transaction_create() {
+ struct sway_transaction *transaction =
+ calloc(1, sizeof(struct sway_transaction));
+ transaction->instructions = create_list();
+ transaction->damage = create_list();
+ return transaction;
+}
+
+static void transaction_destroy(struct sway_transaction *transaction) {
+ int i;
+ // Free instructions
+ for (i = 0; i < transaction->instructions->length; ++i) {
+ struct sway_transaction_instruction *instruction =
+ transaction->instructions->items[i];
+ if (instruction->container->type == C_VIEW) {
+ struct sway_view *view = instruction->container->sway_view;
+ for (int j = 0; j < view->instructions->length; ++j) {
+ if (view->instructions->items[j] == instruction) {
+ list_del(view->instructions, j);
+ break;
+ }
+ }
+ }
+ free(instruction);
+ }
+ list_free(transaction->instructions);
+
+ // Free damage
+ for (i = 0; i < transaction->damage->length; ++i) {
+ struct wlr_box *box = transaction->damage->items[i];
+ free(box);
+ }
+ list_free(transaction->damage);
+
+ free(transaction);
+}
+
+void transaction_add_container(struct sway_transaction *transaction,
+ struct sway_container *container) {
+ struct sway_transaction_instruction *instruction =
+ calloc(1, sizeof(struct sway_transaction_instruction));
+ instruction->transaction = transaction;
+ instruction->container = container;
+
+ // Copy the container's main (pending) properties into the instruction state
+ struct sway_container_state *state = &instruction->state;
+ state->layout = container->layout;
+ state->swayc_x = container->x;
+ state->swayc_y = container->y;
+ state->swayc_width = container->width;
+ state->swayc_height = container->height;
+ state->has_gaps = container->has_gaps;
+ state->current_gaps = container->current_gaps;
+ state->gaps_inner = container->gaps_inner;
+ state->gaps_outer = container->gaps_outer;
+
+ if (container->type == C_VIEW) {
+ struct sway_view *view = container->sway_view;
+ state->view_x = view->x;
+ state->view_y = view->y;
+ state->view_width = view->width;
+ state->view_height = view->height;
+ state->is_fullscreen = view->is_fullscreen;
+ state->border = view->border;
+ state->border_thickness = view->border_thickness;
+ state->border_top = view->border_top;
+ state->border_left = view->border_left;
+ state->border_right = view->border_right;
+ state->border_bottom = view->border_bottom;
+ }
+
+ list_add(transaction->instructions, instruction);
+}
+
+void transaction_add_damage(struct sway_transaction *transaction,
+ struct wlr_box *_box) {
+ struct wlr_box *box = calloc(1, sizeof(struct wlr_box));
+ memcpy(box, _box, sizeof(struct wlr_box));
+ list_add(transaction->damage, box);
+}
+
+static void save_view_texture(struct sway_view *view) {
+ wlr_texture_destroy(view->saved_texture);
+ view->saved_texture = NULL;
+
+ // TODO: Copy the texture and store it in view->saved_texture.
+}
+
+static void remove_saved_view_texture(struct sway_view *view) {
+ wlr_texture_destroy(view->saved_texture);
+ view->saved_texture = NULL;
+}
+
+/**
+ * Apply a transaction to the "current" state of the tree.
+ *
+ * This is mostly copying stuff from the pending state into the main swayc
+ * properties, but also includes reparenting and deleting containers.
+ */
+static void transaction_apply(struct sway_transaction *transaction) {
+ int i;
+ for (i = 0; i < transaction->instructions->length; ++i) {
+ struct sway_transaction_instruction *instruction =
+ transaction->instructions->items[i];
+ struct sway_container *container = instruction->container;
+
+ memcpy(&instruction->container->current, &instruction->state,
+ sizeof(struct sway_container_state));
+
+ if (container->type == C_VIEW) {
+ remove_saved_view_texture(container->sway_view);
+ }
+ }
+
+ // Damage
+ for (i = 0; i < transaction->damage->length; ++i) {
+ struct wlr_box *box = transaction->damage->items[i];
+ for (int j = 0; j < root_container.children->length; ++j) {
+ struct sway_container *output = root_container.children->items[j];
+ output_damage_box(output->sway_output, box);
+ }
+ }
+
+ update_debug_tree();
+}
+
+static int handle_timeout(void *data) {
+ struct sway_transaction *transaction = data;
+ wlr_log(L_DEBUG, "Transaction %p timed out (%li waiting), applying anyway",
+ transaction, transaction->num_waiting);
+ transaction_apply(transaction);
+ transaction_destroy(transaction);
+ return 0;
+}
+
+void transaction_commit(struct sway_transaction *transaction) {
+ wlr_log(L_DEBUG, "Transaction %p committing with %i instructions",
+ transaction, transaction->instructions->length);
+ transaction->num_waiting = 0;
+ for (int i = 0; i < transaction->instructions->length; ++i) {
+ struct sway_transaction_instruction *instruction =
+ transaction->instructions->items[i];
+ struct sway_container *con = instruction->container;
+ if (con->type == C_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_y,
+ instruction->state.view_width,
+ instruction->state.view_height);
+ if (instruction->serial) {
+ save_view_texture(con->sway_view);
+ list_add(con->sway_view->instructions, instruction);
+ ++transaction->num_waiting;
+ }
+ }
+ }
+ if (!transaction->num_waiting) {
+ // This can happen if the transaction only contains xwayland views
+ wlr_log(L_DEBUG, "Transaction %p has nothing to wait for, applying",
+ transaction);
+ transaction_apply(transaction);
+ transaction_destroy(transaction);
+ return;
+ }
+
+ // Set up a timer which the views must respond within
+ transaction->timer = wl_event_loop_add_timer(server.wl_event_loop,
+ handle_timeout, transaction);
+ wl_event_source_timer_update(transaction->timer, TIMEOUT_MS);
+}
+
+void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) {
+ // Find the instruction
+ struct sway_transaction_instruction *instruction = NULL;
+ for (int i = 0; i < view->instructions->length; ++i) {
+ struct sway_transaction_instruction *tmp_instruction =
+ view->instructions->items[i];
+ if (tmp_instruction->serial == serial) {
+ instruction = tmp_instruction;
+ list_del(view->instructions, i);
+ break;
+ }
+ }
+ if (!instruction) {
+ // This can happen if the view acknowledges the configure after the
+ // transaction has timed out and applied.
+ return;
+ }
+ // If all views are ready, apply the transaction
+ struct sway_transaction *transaction = instruction->transaction;
+ if (--transaction->num_waiting == 0) {
+ wlr_log(L_DEBUG, "Transaction %p is ready, applying", transaction);
+ wl_event_source_timer_update(transaction->timer, 0);
+ transaction_apply(transaction);
+ transaction_destroy(transaction);
+ }
+}
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index d2b8822c..d22c967c 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -8,6 +8,7 @@
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
#include "sway/tree/view.h"
@@ -87,18 +88,14 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p
}
}
-static void configure(struct sway_view *view, double lx, double ly, int width,
- int height) {
+static uint32_t configure(struct sway_view *view, double lx, double ly,
+ int width, int height) {
struct sway_xdg_shell_view *xdg_shell_view =
xdg_shell_view_from_view(view);
if (xdg_shell_view == NULL) {
- return;
+ return 0;
}
-
- xdg_shell_view->pending_width = width;
- xdg_shell_view->pending_height = height;
- wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
- view_update_position(view, lx, ly);
+ return wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
}
static void set_activated(struct sway_view *view, bool activated) {
@@ -174,18 +171,12 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, commit);
struct sway_view *view = &xdg_shell_view->view;
- if (view->swayc && container_is_floating(view->swayc)) {
- int width = view->wlr_xdg_surface->geometry.width;
- int height = view->wlr_xdg_surface->geometry.height;
- if (!width && !height) {
- width = view->wlr_xdg_surface->surface->current->width;
- height = view->wlr_xdg_surface->surface->current->height;
- }
- view_update_size(view, width, height);
- } else {
- view_update_size(view, xdg_shell_view->pending_width,
- xdg_shell_view->pending_height);
+ struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
+
+ if (view->instructions->length) {
+ transaction_notify_view_ready(view, xdg_surface->configure_serial);
}
+
view_update_title(view, false);
view_damage_from(view);
}
@@ -219,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_height = view->wlr_xdg_surface->surface->current->height;
}
+
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;
wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_view->commit);
@@ -228,10 +225,6 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_view->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_surface->events.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) {
@@ -246,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_surface *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,
"xdg_shell requested fullscreen of surface with role %i",
@@ -256,7 +250,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
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) {
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index 6ffe334a..7ec9e6cb 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -3,9 +3,10 @@
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
+#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
-#include "sway/server.h"
#include "sway/tree/view.h"
#include "sway/input/seat.h"
#include "sway/input/input-manager.h"
@@ -86,18 +87,15 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p
}
}
-static void configure(struct sway_view *view, double lx, double ly, int width,
- int height) {
+static uint32_t configure(struct sway_view *view, double lx, double ly,
+ int width, int height) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
xdg_shell_v6_view_from_view(view);
if (xdg_shell_v6_view == NULL) {
- return;
+ return 0;
}
-
- xdg_shell_v6_view->pending_width = width;
- xdg_shell_v6_view->pending_height = height;
- wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height);
- view_update_position(view, lx, ly);
+ return wlr_xdg_toplevel_v6_set_size(
+ view->wlr_xdg_surface_v6, width, height);
}
static void set_activated(struct sway_view *view, bool activated) {
@@ -173,18 +171,12 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, commit);
struct sway_view *view = &xdg_shell_v6_view->view;
- if (view->swayc && container_is_floating(view->swayc)) {
- int width = view->wlr_xdg_surface_v6->geometry.width;
- int height = view->wlr_xdg_surface_v6->geometry.height;
- if (!width && !height) {
- width = view->wlr_xdg_surface_v6->surface->current->width;
- height = view->wlr_xdg_surface_v6->surface->current->height;
- }
- view_update_size(view, width, height);
- } else {
- view_update_size(view, xdg_shell_v6_view->pending_width,
- xdg_shell_v6_view->pending_height);
+ struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6;
+
+ if (view->instructions->length) {
+ transaction_notify_view_ready(view, xdg_surface_v6->configure_serial);
}
+
view_update_title(view, false);
view_damage_from(view);
}
@@ -218,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_height = view->wlr_xdg_surface_v6->surface->current->height;
}
+
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;
wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_v6_view->commit);
@@ -227,10 +225,6 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_v6_view->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_surface->events.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) {
@@ -245,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_surface_v6 *xdg_surface =
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,
"xdg_shell_v6 requested fullscreen of surface with role %i",
@@ -255,7 +250,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
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) {
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index 6447b711..70929d48 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -11,6 +11,7 @@
#include "sway/input/seat.h"
#include "sway/output.h"
#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
#include "sway/tree/view.h"
@@ -167,19 +168,18 @@ static uint32_t get_int_prop(struct sway_view *view, enum sway_view_prop prop) {
}
}
-static void configure(struct sway_view *view, double lx, double ly, int width,
+static uint32_t configure(struct sway_view *view, double lx, double ly, int width,
int height) {
struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view);
if (xwayland_view == NULL) {
- return;
+ return 0;
}
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
- xwayland_view->pending_lx = lx;
- xwayland_view->pending_ly = ly;
- xwayland_view->pending_width = width;
- xwayland_view->pending_height = height;
wlr_xwayland_surface_configure(xsurface, lx, ly, width, height);
+
+ // xwayland doesn't give us a serial for the configure
+ return 0;
}
static void set_activated(struct sway_view *view, bool activated) {
@@ -250,15 +250,19 @@ static void handle_commit(struct wl_listener *listener, void *data) {
wl_container_of(listener, xwayland_view, commit);
struct sway_view *view = &xwayland_view->view;
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
- if (view->swayc && container_is_floating(view->swayc)) {
- view_update_size(view, xsurface->width, xsurface->height);
- } else {
- view_update_size(view, xwayland_view->pending_width,
- xwayland_view->pending_height);
+
+ // Don't allow xwayland views to do resize or reposition themselves if
+ // they're involved in a transaction. Once the transaction has finished
+ // they'll apply the next time a commit happens.
+ if (view->instructions->length) {
+ if (view->swayc && container_is_floating(view->swayc)) {
+ view_update_size(view, xsurface->width, xsurface->height);
+ } else {
+ view_update_size(view, view->swayc->width, view->swayc->height);
+ }
+ view_update_position(view, view->x, view->y);
+ view_damage_from(view);
}
- view_update_position(view,
- xwayland_view->pending_lx, xwayland_view->pending_ly);
- view_damage_from(view);
}
static void handle_unmap(struct wl_listener *listener, void *data) {
@@ -289,6 +293,7 @@ static void handle_map(struct wl_listener *listener, void *data) {
if (xsurface->fullscreen) {
view_set_fullscreen(view, true);
}
+ arrange_and_commit(view->swayc);
}
static void handle_destroy(struct wl_listener *listener, void *data) {
@@ -309,7 +314,8 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
return;
}
// TODO: Let floating views do whatever
- configure(view, view->swayc->x, view->swayc->y, view->width, view->height);
+ configure(view, view->swayc->current.view_x, view->swayc->current.view_y,
+ view->swayc->current.view_width, view->swayc->current.view_height);
}
static void handle_request_fullscreen(struct wl_listener *listener, void *data) {
@@ -321,6 +327,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return;
}
view_set_fullscreen(view, xsurface->fullscreen);
+ arrange_and_commit(view->swayc);
}
static void handle_set_title(struct wl_listener *listener, void *data) {
diff --git a/sway/meson.build b/sway/meson.build
index 0da67ed7..c461b0ff 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -12,6 +12,7 @@ sway_sources = files(
'desktop/desktop.c',
'desktop/layer_shell.c',
'desktop/output.c',
+ 'desktop/transaction.c',
'desktop/xdg_shell_v6.c',
'desktop/xdg_shell.c',
'desktop/xwayland.c',
diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c
index 53c95820..ac99c5df 100644
--- a/sway/tree/arrange.c
+++ b/sway/tree/arrange.c
@@ -5,7 +5,6 @@
#include <string.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h>
-#include "sway/debug.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
@@ -17,116 +16,6 @@
struct sway_container root_container;
-void arrange_root() {
- if (config->reloading) {
- return;
- }
- struct wlr_output_layout *output_layout =
- root_container.sway_root->output_layout;
- const struct wlr_box *layout_box =
- wlr_output_layout_get_box(output_layout, NULL);
- root_container.x = layout_box->x;
- root_container.y = layout_box->y;
- root_container.width = layout_box->width;
- root_container.height = layout_box->height;
- for (int i = 0; i < root_container.children->length; ++i) {
- struct sway_container *output = root_container.children->items[i];
- arrange_output(output);
- }
-}
-
-void arrange_output(struct sway_container *output) {
- if (config->reloading) {
- return;
- }
- if (!sway_assert(output->type == C_OUTPUT,
- "called arrange_output() on non-output container")) {
- return;
- }
-
- const struct wlr_box *output_box = wlr_output_layout_get_box(
- root_container.sway_root->output_layout,
- output->sway_output->wlr_output);
- output->x = output_box->x;
- output->y = output_box->y;
- output->width = output_box->width;
- output->height = output_box->height;
- wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f",
- 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);
- }
- container_damage_whole(output);
-}
-
-void arrange_workspace(struct sway_container *workspace) {
- if (config->reloading) {
- return;
- }
- if (!sway_assert(workspace->type == C_WORKSPACE,
- "called arrange_workspace() on non-workspace container")) {
- return;
- }
-
- struct sway_container *output = workspace->parent;
- 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);
-
- wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f",
- workspace->name, workspace->x, workspace->y);
- arrange_children_of(workspace);
-}
-
-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);
-}
-
static void apply_horiz_layout(struct sway_container *parent) {
size_t num_children = parent->children->length;
if (!num_children) {
@@ -136,8 +25,8 @@ static void apply_horiz_layout(struct sway_container *parent) {
if (parent->parent->layout == L_TABBED) {
parent_offset = container_titlebar_height();
} else if (parent->parent->layout == L_STACKED) {
- parent_offset =
- container_titlebar_height() * parent->parent->children->length;
+ parent_offset = container_titlebar_height() *
+ parent->parent->children->length;
}
size_t parent_height = parent->height - parent_offset;
@@ -145,7 +34,6 @@ static void apply_horiz_layout(struct sway_container *parent) {
double total_width = 0;
for (size_t i = 0; i < num_children; ++i) {
struct sway_container *child = parent->children->items[i];
-
if (child->width <= 0) {
if (num_children > 1) {
child->width = parent->width / (num_children - 1);
@@ -161,25 +49,21 @@ static void apply_horiz_layout(struct sway_container *parent) {
// Resize windows
wlr_log(L_DEBUG, "Arranging %p horizontally", parent);
double child_x = parent->x;
- struct sway_container *child;
for (size_t i = 0; i < num_children; ++i) {
- child = parent->children->items[i];
+ struct sway_container *child = parent->children->items[i];
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, child->width, scale);
child->x = child_x;
child->y = parent->y + parent_offset;
+ child->width = floor(child->width * scale);
child->height = parent_height;
+ child_x += child->width;
+ // Make last child use remaining width of parent
if (i == num_children - 1) {
- // Make last child use remaining width of parent
child->width = parent->x + parent->width - child->x;
- } else {
- child->width = floor(child->width * scale);
}
-
- child_x += child->width;
-
add_gaps(child);
}
}
@@ -202,7 +86,6 @@ static void apply_vert_layout(struct sway_container *parent) {
double total_height = 0;
for (size_t i = 0; i < num_children; ++i) {
struct sway_container *child = parent->children->items[i];
-
if (child->height <= 0) {
if (num_children > 1) {
child->height = parent_height / (num_children - 1);
@@ -218,25 +101,22 @@ static void apply_vert_layout(struct sway_container *parent) {
// Resize
wlr_log(L_DEBUG, "Arranging %p vertically", parent);
double child_y = parent->y + parent_offset;
- struct sway_container *child;
for (size_t i = 0; i < num_children; ++i) {
- child = parent->children->items[i];
+ struct sway_container *child = parent->children->items[i];
wlr_log(L_DEBUG,
"Calculating arrangement for %p:%d (will scale %f by %f)",
child, child->type, child->height, scale);
child->x = parent->x;
child->y = child_y;
child->width = parent->width;
+ child->height = floor(child->height * scale);
+ child_y += child->height;
+ // Make last child use remaining height of parent
if (i == num_children - 1) {
- // Make last child use remaining height of parent
- child->height = parent->y + parent_offset + parent_height - child->y;
- } else {
- child->height = floor(child->height * scale);
+ child->height =
+ parent->y + parent_offset + parent_height - child->y;
}
-
- child_y += child->height;
-
add_gaps(child);
}
}
@@ -264,26 +144,27 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
}
}
-void arrange_children_of(struct sway_container *parent) {
- if (config->reloading) {
- return;
- }
- if (!sway_assert(parent->type == C_WORKSPACE || parent->type == C_CONTAINER,
- "container is a %s", container_type_to_str(parent->type))) {
- return;
- }
+static void arrange_children_of(struct sway_container *parent,
+ struct sway_transaction *transaction);
- struct sway_container *workspace = parent;
- if (workspace->type != C_WORKSPACE) {
- workspace = container_parent(workspace, C_WORKSPACE);
+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);
}
+}
- if (workspace->sway_workspace->fullscreen) {
- // Just arrange the fullscreen view and jump out
- view_autoconfigure(workspace->sway_workspace->fullscreen);
+static void arrange_children_of(struct sway_container *parent,
+ struct sway_transaction *transaction) {
+ if (config->reloading) {
return;
}
-
wlr_log(L_DEBUG, "Arranging layout for %p %s %fx%f+%f,%f", parent,
parent->name, parent->width, parent->height, parent->x, parent->y);
@@ -299,13 +180,15 @@ void arrange_children_of(struct sway_container *parent) {
case L_STACKED:
apply_tabbed_or_stacked_layout(parent);
break;
- default:
- wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout);
+ case L_NONE:
apply_horiz_layout(parent);
break;
+ case L_FLOATING:
+ arrange_floating(parent, transaction);
+ break;
}
- // Apply x, y, width and height to children and recurse if needed
+ // 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) {
@@ -316,21 +199,140 @@ void arrange_children_of(struct sway_container *parent) {
if (child->type == C_VIEW) {
view_autoconfigure(child->sway_view);
} else {
- arrange_children_of(child);
+ arrange_children_of(child, transaction);
}
+ transaction_add_container(transaction, child);
}
+}
- // If container is a workspace, process floating containers too
- if (parent->type == C_WORKSPACE) {
- struct sway_workspace *ws = workspace->sway_workspace;
- for (int i = 0; i < ws->floating->children->length; ++i) {
- struct sway_container *child = ws->floating->children->items[i];
- if (child->type != C_VIEW) {
- arrange_children_of(child);
- }
- }
+static void arrange_workspace(struct sway_container *workspace,
+ struct sway_transaction *transaction) {
+ if (config->reloading) {
+ return;
}
+ struct sway_container *output = workspace->parent;
+ 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);
+ arrange_floating(workspace->sway_workspace->floating, transaction);
+ arrange_children_of(workspace, transaction);
+}
- container_damage_whole(parent);
- update_debug_tree();
+static void arrange_output(struct sway_container *output,
+ struct sway_transaction *transaction) {
+ if (config->reloading) {
+ return;
+ }
+ const struct wlr_box *output_box = wlr_output_layout_get_box(
+ root_container.sway_root->output_layout,
+ output->sway_output->wlr_output);
+ output->x = output_box->x;
+ output->y = output_box->y;
+ output->width = output_box->width;
+ output->height = output_box->height;
+ transaction_add_container(transaction, output);
+ wlr_log(L_DEBUG, "Arranging output '%s' at %f,%f",
+ 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);
+ }
+}
+
+static void arrange_root(struct sway_transaction *transaction) {
+ if (config->reloading) {
+ return;
+ }
+ struct wlr_output_layout *output_layout =
+ root_container.sway_root->output_layout;
+ const struct wlr_box *layout_box =
+ wlr_output_layout_get_box(output_layout, NULL);
+ root_container.x = layout_box->x;
+ root_container.y = layout_box->y;
+ root_container.width = layout_box->width;
+ root_container.height = layout_box->height;
+ 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);
+ }
+}
+
+void arrange_windows(struct sway_container *container,
+ struct sway_transaction *transaction) {
+ switch (container->type) {
+ case C_ROOT:
+ arrange_root(transaction);
+ break;
+ case C_OUTPUT:
+ arrange_output(container, transaction);
+ break;
+ case C_WORKSPACE:
+ arrange_workspace(container, transaction);
+ break;
+ case C_CONTAINER:
+ 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;
+ }
+ transaction_add_damage(transaction, container_get_box(container));
+}
+
+void arrange_and_commit(struct sway_container *container) {
+ struct sway_transaction *transaction = transaction_create();
+ 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 af55a54e..f8620b72 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -116,6 +116,7 @@ struct sway_container *container_create(enum sway_container_type type) {
if (type != C_VIEW) {
c->children = create_list();
+ //c->pending.children = create_list();
}
wl_signal_init(&c->events.destroy);
@@ -167,6 +168,7 @@ static void _container_destroy(struct sway_container *cont) {
wlr_texture_destroy(cont->title_urgent);
list_free(cont->children);
+ //list_free(cont->pending.children);
cont->children = NULL;
free(cont);
}
@@ -207,6 +209,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;
@@ -267,10 +270,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);
@@ -927,13 +930,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);
@@ -946,8 +948,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) {
@@ -976,3 +978,12 @@ bool container_is_floating(struct sway_container *container) {
}
return container->parent == workspace->sway_workspace->floating;
}
+
+struct wlr_box *container_get_box(struct sway_container *container) {
+ struct wlr_box *box = calloc(1, sizeof(struct wlr_box));
+ box->x = container->x;
+ box->y = container->y;
+ box->width = container->width;
+ box->height = container->height;
+ return box;
+}
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index d1ad044d..3724361d 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) {
@@ -57,18 +57,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;
}
@@ -79,15 +78,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,
@@ -189,18 +192,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) {
@@ -215,7 +207,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);
}
@@ -309,7 +302,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,
@@ -320,11 +312,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;
}
@@ -340,11 +327,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);
}
@@ -368,10 +350,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;
}
@@ -453,12 +432,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 {
@@ -492,14 +468,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;
@@ -513,8 +486,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)");
@@ -538,8 +509,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;
@@ -864,7 +833,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;
}
@@ -882,7 +850,7 @@ 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) {
@@ -912,7 +880,6 @@ struct sway_container *container_split(struct sway_container *child,
}
container_notify_subtree_changed(cont);
- arrange_children_of(cont);
return cont;
}
@@ -1050,9 +1017,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/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);
diff --git a/sway/tree/view.c b/sway/tree/view.c
index c9c82405..658a94e8 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -25,6 +25,7 @@ void view_init(struct sway_view *view, enum sway_view_type type,
view->impl = impl;
view->executed_criteria = create_list();
view->marks = create_list();
+ view->instructions = create_list();
wl_signal_init(&view->events.unmap);
}
@@ -37,6 +38,11 @@ void view_destroy(struct sway_view *view) {
view_unmap(view);
}
+ if (!sway_assert(view->instructions->length == 0,
+ "Tried to destroy view with pending instructions")) {
+ return;
+ }
+
list_free(view->executed_criteria);
for (int i = 0; i < view->marks->length; ++i) {
@@ -44,6 +50,8 @@ void view_destroy(struct sway_view *view) {
}
list_free(view->marks);
+ list_free(view->instructions);
+
wlr_texture_destroy(view->marks_focused);
wlr_texture_destroy(view->marks_focused_inactive);
wlr_texture_destroy(view->marks_unfocused);
@@ -119,29 +127,30 @@ const char *view_get_shell(struct sway_view *view) {
return "unknown";
}
-void 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) {
if (view->impl->configure) {
- view->impl->configure(view, lx, ly, width, height);
+ return view->impl->configure(view, lx, ly, width, height);
}
+ 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) {
@@ -153,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;
}
@@ -178,20 +189,22 @@ void view_autoconfigure(struct sway_view *view) {
}
}
+ struct sway_container *con = view->swayc;
+
view->border_top = view->border_bottom = true;
view->border_left = view->border_right = true;
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL
|| (config->hide_edge_borders == E_SMART && !other_views)) {
- view->border_left = view->swayc->x != ws->x;
- int right_x = view->swayc->x + view->swayc->width;
+ view->border_left = con->x != ws->x;
+ int right_x = con->x + con->width;
view->border_right = right_x != ws->x + ws->width;
}
if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL
|| (config->hide_edge_borders == E_SMART && !other_views)) {
- view->border_top = view->swayc->y != ws->y;
- int bottom_y = view->swayc->y + view->swayc->height;
+ view->border_top = con->y != ws->y;
+ int bottom_y = con->y + con->height;
view->border_bottom = bottom_y != ws->y + ws->height;
}
@@ -202,45 +215,44 @@ void view_autoconfigure(struct sway_view *view) {
// In a tabbed or stacked container, the swayc's y is the top of the title
// area. We have to offset the surface y by the height of the title bar, and
// disable any top border because we'll always have the title bar.
- if (view->swayc->parent->layout == L_TABBED) {
+ if (con->parent->layout == L_TABBED) {
y_offset = container_titlebar_height();
view->border_top = false;
- } else if (view->swayc->parent->layout == L_STACKED) {
- y_offset = container_titlebar_height()
- * view->swayc->parent->children->length;
+ } else if (con->parent->layout == L_STACKED) {
+ y_offset = container_titlebar_height() * con->parent->children->length;
view->border_top = false;
}
switch (view->border) {
case B_NONE:
- x = view->swayc->x;
- y = view->swayc->y + y_offset;
- width = view->swayc->width;
- height = view->swayc->height - y_offset;
+ x = con->x;
+ y = con->y + y_offset;
+ width = con->width;
+ height = con->height - y_offset;
break;
case B_PIXEL:
- x = view->swayc->x + view->border_thickness * view->border_left;
- y = view->swayc->y + view->border_thickness * view->border_top + y_offset;
- width = view->swayc->width
+ x = con->x + view->border_thickness * view->border_left;
+ y = con->y + view->border_thickness * view->border_top + y_offset;
+ width = con->width
- view->border_thickness * view->border_left
- view->border_thickness * view->border_right;
- height = view->swayc->height - y_offset
+ height = con->height - y_offset
- view->border_thickness * view->border_top
- view->border_thickness * view->border_bottom;
break;
case B_NORMAL:
// Height is: 1px border + 3px pad + title height + 3px pad + 1px border
- x = view->swayc->x + view->border_thickness * view->border_left;
- width = view->swayc->width
+ x = con->x + view->border_thickness * view->border_left;
+ width = con->width
- view->border_thickness * view->border_left
- view->border_thickness * view->border_right;
if (y_offset) {
- y = view->swayc->y + y_offset;
- height = view->swayc->height - y_offset
+ y = con->y + y_offset;
+ height = con->height - y_offset
- view->border_thickness * view->border_bottom;
} else {
- y = view->swayc->y + container_titlebar_height();
- height = view->swayc->height - container_titlebar_height()
+ y = con->y + container_titlebar_height();
+ height = con->height - container_titlebar_height()
- view->border_thickness * view->border_bottom;
}
break;
@@ -248,7 +260,8 @@ void view_autoconfigure(struct sway_view *view) {
view->x = x;
view->y = y;
- view_configure(view, x, y, width, height);
+ view->width = width;
+ view->height = height;
}
void view_set_activated(struct sway_view *view, bool activated) {
@@ -257,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;
}
@@ -304,27 +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;
- view_autoconfigure(view);
}
}
-}
-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");
}
@@ -507,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);
@@ -520,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);
}
@@ -551,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;
}