mirror of
https://github.com/gwenhael-le-moine/sway-patched-tray-menu.git
synced 2024-12-27 21:58:16 +01:00
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:
parent
f9e6d703d2
commit
bb66e6d578
24 changed files with 192 additions and 171 deletions
|
@ -16,12 +16,7 @@
|
|||
* the updates all at the same time.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
/**
|
||||
* Create a new transaction.
|
||||
|
|
|
@ -23,11 +23,4 @@ void arrange_windows(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
|
||||
|
|
|
@ -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,
|
||||
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
|
||||
* size, taking borders into consideration.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1238,13 +1238,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) {
|
||||
|
@ -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) {
|
||||
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) {
|
||||
|
@ -1314,5 +1314,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);
|
||||
}
|
||||
|
|
|
@ -17,6 +17,13 @@
|
|||
*/
|
||||
#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;
|
||||
|
@ -162,16 +169,18 @@ void transaction_commit(struct sway_transaction *transaction) {
|
|||
for (int 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;
|
||||
instruction->serial = view_configure(view,
|
||||
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(view);
|
||||
list_add(view->instructions, instruction);
|
||||
save_view_texture(con->sway_view);
|
||||
list_add(con->sway_view->instructions, instruction);
|
||||
++transaction->num_waiting;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include <wlr/types/wlr_xdg_shell.h>
|
||||
#include <wlr/util/edges.h>
|
||||
#include "log.h"
|
||||
#include "sway/desktop/transaction.h"
|
||||
#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"
|
||||
|
@ -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_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);
|
||||
|
@ -219,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) {
|
||||
|
@ -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_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",
|
||||
|
@ -247,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) {
|
||||
|
|
|
@ -3,10 +3,10 @@
|
|||
#include <stdlib.h>
|
||||
#include <wayland-server.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/layout.h"
|
||||
#include "sway/server.h"
|
||||
#include "sway/tree/view.h"
|
||||
#include "sway/input/seat.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_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);
|
||||
|
@ -219,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) {
|
||||
|
@ -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_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",
|
||||
|
@ -247,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) {
|
||||
|
|
|
@ -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"
|
||||
|
@ -292,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) {
|
||||
|
@ -325,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) {
|
||||
|
|
|
@ -138,7 +138,23 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
|
|||
}
|
||||
}
|
||||
|
||||
static void _arrange_children_of(struct sway_container *parent,
|
||||
static void arrange_children_of(struct sway_container *parent,
|
||||
struct sway_transaction *transaction);
|
||||
|
||||
static void arrange_floating(struct sway_container *floating,
|
||||
struct sway_transaction *transaction) {
|
||||
for (int i = 0; i < floating->children->length; ++i) {
|
||||
struct sway_container *floater = floating->children->items[i];
|
||||
if (floater->type == C_VIEW) {
|
||||
view_autoconfigure(floater->sway_view);
|
||||
} else {
|
||||
arrange_children_of(floater, transaction);
|
||||
}
|
||||
transaction_add_container(transaction, floater);
|
||||
}
|
||||
}
|
||||
|
||||
static void arrange_children_of(struct sway_container *parent,
|
||||
struct sway_transaction *transaction) {
|
||||
if (config->reloading) {
|
||||
return;
|
||||
|
@ -162,7 +178,8 @@ static void _arrange_children_of(struct sway_container *parent,
|
|||
apply_horiz_layout(parent);
|
||||
break;
|
||||
case L_FLOATING:
|
||||
sway_assert(false, "Didn't expect to see floating here");
|
||||
arrange_floating(parent, transaction);
|
||||
break;
|
||||
}
|
||||
|
||||
// Recurse into child containers
|
||||
|
@ -171,13 +188,13 @@ static void _arrange_children_of(struct sway_container *parent,
|
|||
if (child->type == C_VIEW) {
|
||||
view_autoconfigure(child->sway_view);
|
||||
} else {
|
||||
_arrange_children_of(child, transaction);
|
||||
arrange_children_of(child, transaction);
|
||||
}
|
||||
transaction_add_container(transaction, child);
|
||||
}
|
||||
}
|
||||
|
||||
static void _arrange_workspace(struct sway_container *workspace,
|
||||
static void arrange_workspace(struct sway_container *workspace,
|
||||
struct sway_transaction *transaction) {
|
||||
if (config->reloading) {
|
||||
return;
|
||||
|
@ -193,10 +210,11 @@ static void _arrange_workspace(struct sway_container *workspace,
|
|||
transaction_add_container(transaction, workspace);
|
||||
wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name,
|
||||
workspace->x, workspace->y);
|
||||
_arrange_children_of(workspace, transaction);
|
||||
arrange_floating(workspace->sway_workspace->floating, transaction);
|
||||
arrange_children_of(workspace, transaction);
|
||||
}
|
||||
|
||||
static void _arrange_output(struct sway_container *output,
|
||||
static void arrange_output(struct sway_container *output,
|
||||
struct sway_transaction *transaction) {
|
||||
if (config->reloading) {
|
||||
return;
|
||||
|
@ -213,11 +231,11 @@ static void _arrange_output(struct sway_container *output,
|
|||
output->name, output->x, output->y);
|
||||
for (int i = 0; i < output->children->length; ++i) {
|
||||
struct sway_container *workspace = output->children->items[i];
|
||||
_arrange_workspace(workspace, transaction);
|
||||
arrange_workspace(workspace, transaction);
|
||||
}
|
||||
}
|
||||
|
||||
static void _arrange_root(struct sway_transaction *transaction) {
|
||||
static void arrange_root(struct sway_transaction *transaction) {
|
||||
if (config->reloading) {
|
||||
return;
|
||||
}
|
||||
|
@ -232,7 +250,7 @@ static void _arrange_root(struct sway_transaction *transaction) {
|
|||
transaction_add_container(transaction, &root_container);
|
||||
for (int i = 0; i < root_container.children->length; ++i) {
|
||||
struct sway_container *output = root_container.children->items[i];
|
||||
_arrange_output(output, transaction);
|
||||
arrange_output(output, transaction);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -240,19 +258,21 @@ void arrange_windows(struct sway_container *container,
|
|||
struct sway_transaction *transaction) {
|
||||
switch (container->type) {
|
||||
case C_ROOT:
|
||||
_arrange_root(transaction);
|
||||
arrange_root(transaction);
|
||||
break;
|
||||
case C_OUTPUT:
|
||||
_arrange_output(container, transaction);
|
||||
arrange_output(container, transaction);
|
||||
break;
|
||||
case C_WORKSPACE:
|
||||
_arrange_workspace(container, transaction);
|
||||
arrange_workspace(container, transaction);
|
||||
break;
|
||||
case C_CONTAINER:
|
||||
_arrange_children_of(container, transaction);
|
||||
arrange_children_of(container, transaction);
|
||||
transaction_add_container(transaction, container);
|
||||
break;
|
||||
case C_VIEW:
|
||||
view_autoconfigure(container->sway_view);
|
||||
transaction_add_container(transaction, container);
|
||||
break;
|
||||
case C_TYPES:
|
||||
break;
|
||||
|
@ -265,20 +285,3 @@ void arrange_and_commit(struct sway_container *container) {
|
|||
arrange_windows(container, transaction);
|
||||
transaction_commit(transaction);
|
||||
}
|
||||
|
||||
// These functions are only temporary
|
||||
void arrange_root() {
|
||||
arrange_and_commit(&root_container);
|
||||
}
|
||||
|
||||
void arrange_output(struct sway_container *container) {
|
||||
arrange_and_commit(container);
|
||||
}
|
||||
|
||||
void arrange_workspace(struct sway_container *container) {
|
||||
arrange_and_commit(container);
|
||||
}
|
||||
|
||||
void arrange_children_of(struct sway_container *container) {
|
||||
arrange_and_commit(container);
|
||||
}
|
||||
|
|
|
@ -204,6 +204,7 @@ static struct sway_container *container_workspace_destroy(
|
|||
container_move_to(floating->children->items[i],
|
||||
new_workspace->sway_workspace->floating);
|
||||
}
|
||||
arrange_and_commit(new_workspace);
|
||||
}
|
||||
|
||||
struct sway_workspace *sway_workspace = workspace->sway_workspace;
|
||||
|
@ -264,10 +265,10 @@ static struct sway_container *container_output_destroy(
|
|||
}
|
||||
|
||||
container_sort_workspaces(new_output);
|
||||
arrange_output(new_output);
|
||||
}
|
||||
}
|
||||
}
|
||||
arrange_and_commit(&root_container);
|
||||
|
||||
wl_list_remove(&output->sway_output->mode.link);
|
||||
wl_list_remove(&output->sway_output->transform.link);
|
||||
|
@ -924,13 +925,12 @@ void container_set_floating(struct sway_container *container, bool enable) {
|
|||
|
||||
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
container_damage_whole(container);
|
||||
|
||||
if (enable) {
|
||||
container_remove_child(container);
|
||||
container_add_child(workspace->sway_workspace->floating, container);
|
||||
if (container->type == C_VIEW) {
|
||||
view_autoconfigure(container->sway_view);
|
||||
view_init_floating(container->sway_view);
|
||||
}
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, container));
|
||||
container_reap_empty_recursive(workspace);
|
||||
|
@ -943,8 +943,8 @@ void container_set_floating(struct sway_container *container, bool enable) {
|
|||
container->is_sticky = false;
|
||||
container_reap_empty_recursive(workspace->sway_workspace->floating);
|
||||
}
|
||||
arrange_workspace(workspace);
|
||||
container_damage_whole(container);
|
||||
|
||||
ipc_event_window(container, "floating");
|
||||
}
|
||||
|
||||
void container_set_geometry_from_floating_view(struct sway_container *con) {
|
||||
|
|
|
@ -22,7 +22,7 @@ struct sway_container root_container;
|
|||
|
||||
static void output_layout_handle_change(struct wl_listener *listener,
|
||||
void *data) {
|
||||
arrange_root();
|
||||
arrange_and_commit(&root_container);
|
||||
}
|
||||
|
||||
void layout_init(void) {
|
||||
|
@ -56,18 +56,17 @@ static int index_child(const struct sway_container *child) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
|
||||
static void container_handle_fullscreen_reparent(struct sway_container *con,
|
||||
struct sway_container *old_parent) {
|
||||
if (viewcon->type != C_VIEW || !viewcon->sway_view->is_fullscreen) {
|
||||
if (con->type != C_VIEW || !con->sway_view->is_fullscreen) {
|
||||
return;
|
||||
}
|
||||
struct sway_view *view = viewcon->sway_view;
|
||||
struct sway_view *view = con->sway_view;
|
||||
struct sway_container *old_workspace = old_parent;
|
||||
if (old_workspace && old_workspace->type != C_WORKSPACE) {
|
||||
old_workspace = container_parent(old_workspace, C_WORKSPACE);
|
||||
}
|
||||
struct sway_container *new_workspace = container_parent(view->swayc,
|
||||
C_WORKSPACE);
|
||||
struct sway_container *new_workspace = container_parent(con, C_WORKSPACE);
|
||||
if (old_workspace == new_workspace) {
|
||||
return;
|
||||
}
|
||||
|
@ -78,15 +77,19 @@ static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
|
|||
|
||||
// Mark the new workspace as fullscreen
|
||||
if (new_workspace->sway_workspace->fullscreen) {
|
||||
view_set_fullscreen_raw(
|
||||
new_workspace->sway_workspace->fullscreen, false);
|
||||
view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false);
|
||||
}
|
||||
new_workspace->sway_workspace->fullscreen = view;
|
||||
// Resize view to new output dimensions
|
||||
struct sway_container *output = new_workspace->parent;
|
||||
view_configure(view, 0, 0, output->width, output->height);
|
||||
view->swayc->width = output->width;
|
||||
view->swayc->height = output->height;
|
||||
view->x = output->x;
|
||||
view->y = output->y;
|
||||
view->width = output->width;
|
||||
view->height = output->height;
|
||||
con->x = output->x;
|
||||
con->y = output->y;
|
||||
con->width = output->width;
|
||||
con->height = output->height;
|
||||
}
|
||||
|
||||
void container_insert_child(struct sway_container *parent,
|
||||
|
@ -188,18 +191,7 @@ void container_move_to(struct sway_container *container,
|
|||
}
|
||||
container_notify_subtree_changed(old_parent);
|
||||
container_notify_subtree_changed(new_parent);
|
||||
if (old_parent) {
|
||||
if (old_parent->type == C_OUTPUT) {
|
||||
arrange_output(old_parent);
|
||||
} else {
|
||||
arrange_children_of(old_parent);
|
||||
}
|
||||
}
|
||||
if (new_parent->type == C_OUTPUT) {
|
||||
arrange_output(new_parent);
|
||||
} else {
|
||||
arrange_children_of(new_parent);
|
||||
}
|
||||
|
||||
// If view was moved to a fullscreen workspace, refocus the fullscreen view
|
||||
struct sway_container *new_workspace = container;
|
||||
if (new_workspace->type != C_WORKSPACE) {
|
||||
|
@ -214,7 +206,8 @@ void container_move_to(struct sway_container *container,
|
|||
if (focus_ws->type != C_WORKSPACE) {
|
||||
focus_ws = container_parent(focus_ws, C_WORKSPACE);
|
||||
}
|
||||
seat_set_focus(seat, new_workspace->sway_workspace->fullscreen->swayc);
|
||||
seat_set_focus(seat,
|
||||
new_workspace->sway_workspace->fullscreen->swayc);
|
||||
if (focus_ws != new_workspace) {
|
||||
seat_set_focus(seat, focus);
|
||||
}
|
||||
|
@ -308,7 +301,6 @@ static void workspace_rejigger(struct sway_container *ws,
|
|||
container_reap_empty_recursive(original_parent);
|
||||
wl_signal_emit(&child->events.reparent, original_parent);
|
||||
container_create_notify(new_parent);
|
||||
arrange_workspace(ws);
|
||||
}
|
||||
|
||||
static void move_out_of_tabs_stacks(struct sway_container *container,
|
||||
|
@ -319,11 +311,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
|
|||
wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id);
|
||||
current->parent->layout = move_dir ==
|
||||
MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
|
||||
if (current->parent->type == C_WORKSPACE) {
|
||||
arrange_workspace(current->parent);
|
||||
} else {
|
||||
arrange_children_of(current->parent);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -339,11 +326,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
|
|||
container_flatten(new_parent->parent);
|
||||
}
|
||||
container_create_notify(new_parent);
|
||||
if (is_workspace) {
|
||||
arrange_workspace(new_parent->parent);
|
||||
} else {
|
||||
arrange_children_of(new_parent);
|
||||
}
|
||||
container_notify_subtree_changed(new_parent);
|
||||
}
|
||||
|
||||
|
@ -367,10 +349,7 @@ void container_move(struct sway_container *container,
|
|||
|
||||
struct sway_container *new_parent = container_flatten(parent);
|
||||
if (new_parent != parent) {
|
||||
// Special case: we were the last one in this container, so flatten it
|
||||
// and leave
|
||||
arrange_children_of(new_parent);
|
||||
update_debug_tree();
|
||||
// Special case: we were the last one in this container, so leave
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -452,12 +431,9 @@ void container_move(struct sway_container *container,
|
|||
wlr_log(L_DEBUG, "Hit limit, "
|
||||
"promoting descendant to sibling");
|
||||
// Special case
|
||||
struct sway_container *old_parent = container->parent;
|
||||
container_insert_child(current->parent, container,
|
||||
index + (offs < 0 ? 0 : 1));
|
||||
container->width = container->height = 0;
|
||||
arrange_children_of(current->parent);
|
||||
arrange_children_of(old_parent);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
@ -491,14 +467,11 @@ void container_move(struct sway_container *container,
|
|||
wlr_log(L_DEBUG, "Swapping siblings");
|
||||
sibling->parent->children->items[index + offs] = container;
|
||||
sibling->parent->children->items[index] = sibling;
|
||||
arrange_children_of(sibling->parent);
|
||||
} else {
|
||||
wlr_log(L_DEBUG, "Promoting to sibling of cousin");
|
||||
container_insert_child(sibling->parent, container,
|
||||
index_child(sibling) + (offs > 0 ? 0 : 1));
|
||||
container->width = container->height = 0;
|
||||
arrange_children_of(sibling->parent);
|
||||
arrange_children_of(old_parent);
|
||||
}
|
||||
sibling = NULL;
|
||||
break;
|
||||
|
@ -512,8 +485,6 @@ void container_move(struct sway_container *container,
|
|||
"(move dir: %d)", limit, move_dir);
|
||||
container_insert_child(sibling, container, limit);
|
||||
container->width = container->height = 0;
|
||||
arrange_children_of(sibling);
|
||||
arrange_children_of(old_parent);
|
||||
sibling = NULL;
|
||||
} else {
|
||||
wlr_log(L_DEBUG, "Reparenting container (perpendicular)");
|
||||
|
@ -537,8 +508,6 @@ void container_move(struct sway_container *container,
|
|||
container_add_child(sibling, container);
|
||||
}
|
||||
container->width = container->height = 0;
|
||||
arrange_children_of(sibling);
|
||||
arrange_children_of(old_parent);
|
||||
sibling = NULL;
|
||||
}
|
||||
break;
|
||||
|
@ -863,7 +832,6 @@ struct sway_container *container_split(struct sway_container *child,
|
|||
// Special case: this just behaves like splitt
|
||||
child->prev_layout = child->layout;
|
||||
child->layout = layout;
|
||||
arrange_children_of(child);
|
||||
return child;
|
||||
}
|
||||
|
||||
|
@ -1044,9 +1012,6 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
|
|||
prev_workspace_name = stored_prev_name;
|
||||
}
|
||||
|
||||
arrange_children_of(con1->parent);
|
||||
arrange_children_of(con2->parent);
|
||||
|
||||
if (fs1 && con2->type == C_VIEW) {
|
||||
view_set_fullscreen(con2->sway_view, true);
|
||||
}
|
||||
|
|
|
@ -135,22 +135,22 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void view_autoconfigure_floating(struct sway_view *view) {
|
||||
void view_init_floating(struct sway_view *view) {
|
||||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
int max_width = ws->width * 0.6666;
|
||||
int max_height = ws->height * 0.6666;
|
||||
int width =
|
||||
view->width =
|
||||
view->natural_width > max_width ? max_width : view->natural_width;
|
||||
int height =
|
||||
view->height =
|
||||
view->natural_height > max_height ? max_height : view->natural_height;
|
||||
int lx = ws->x + (ws->width - width) / 2;
|
||||
int ly = ws->y + (ws->height - height) / 2;
|
||||
view->x = ws->x + (ws->width - view->width) / 2;
|
||||
view->y = ws->y + (ws->height - view->height) / 2;
|
||||
|
||||
// If the view's border is B_NONE then these properties are ignored.
|
||||
view->border_top = view->border_bottom = true;
|
||||
view->border_left = view->border_right = true;
|
||||
|
||||
view_configure(view, lx, ly, width, height);
|
||||
container_set_geometry_from_floating_view(view->swayc);
|
||||
}
|
||||
|
||||
void view_autoconfigure(struct sway_view *view) {
|
||||
|
@ -162,12 +162,14 @@ void view_autoconfigure(struct sway_view *view) {
|
|||
struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
|
||||
|
||||
if (view->is_fullscreen) {
|
||||
view_configure(view, output->x, output->y, output->width, output->height);
|
||||
view->x = output->x;
|
||||
view->y = output->y;
|
||||
view->width = output->width;
|
||||
view->height = output->height;
|
||||
return;
|
||||
}
|
||||
|
||||
if (container_is_floating(view->swayc)) {
|
||||
view_autoconfigure_floating(view);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -268,8 +270,7 @@ void view_set_activated(struct sway_view *view, bool activated) {
|
|||
}
|
||||
}
|
||||
|
||||
// Set fullscreen, but without IPC events or arranging windows.
|
||||
void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
|
||||
void view_set_fullscreen(struct sway_view *view, bool fullscreen) {
|
||||
if (view->is_fullscreen == fullscreen) {
|
||||
return;
|
||||
}
|
||||
|
@ -315,26 +316,17 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
|
|||
} else {
|
||||
workspace->sway_workspace->fullscreen = NULL;
|
||||
if (container_is_floating(view->swayc)) {
|
||||
view_configure(view, view->saved_x, view->saved_y,
|
||||
view->saved_width, view->saved_height);
|
||||
view->x = view->saved_x;
|
||||
view->y = view->saved_y;
|
||||
view->width = view->saved_width;
|
||||
view->height = view->saved_height;
|
||||
container_set_geometry_from_floating_view(view->swayc);
|
||||
} else {
|
||||
view->swayc->width = view->swayc->saved_width;
|
||||
view->swayc->height = view->swayc->saved_height;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void view_set_fullscreen(struct sway_view *view, bool fullscreen) {
|
||||
if (view->is_fullscreen == fullscreen) {
|
||||
return;
|
||||
}
|
||||
|
||||
view_set_fullscreen_raw(view, fullscreen);
|
||||
|
||||
struct sway_container *workspace =
|
||||
container_parent(view->swayc, C_WORKSPACE);
|
||||
arrange_workspace(workspace);
|
||||
output_damage_whole(workspace->parent->sway_output);
|
||||
ipc_event_window(view->swayc, "fullscreen_mode");
|
||||
}
|
||||
|
||||
|
@ -517,8 +509,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
|||
|
||||
if (view->impl->wants_floating && view->impl->wants_floating(view)) {
|
||||
container_set_floating(view->swayc, true);
|
||||
} else {
|
||||
arrange_children_of(cont->parent);
|
||||
}
|
||||
|
||||
input_manager_set_focus(input_manager, cont);
|
||||
|
@ -530,7 +520,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
|
|||
container_notify_subtree_changed(view->swayc->parent);
|
||||
view_execute_criteria(view);
|
||||
|
||||
container_damage_whole(cont);
|
||||
view_handle_container_reparent(&view->container_reparent, NULL);
|
||||
}
|
||||
|
||||
|
@ -561,11 +550,7 @@ void view_unmap(struct sway_view *view) {
|
|||
view->title_format = NULL;
|
||||
}
|
||||
|
||||
if (parent->type == C_OUTPUT) {
|
||||
arrange_output(parent);
|
||||
} else {
|
||||
arrange_children_of(parent);
|
||||
}
|
||||
arrange_and_commit(parent);
|
||||
}
|
||||
|
||||
void view_update_position(struct sway_view *view, double lx, double ly) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue