Merge pull request #2072 from RyanDwyer/atomic

Atomic layout updates
This commit is contained in:
Drew DeVault 2018-06-30 06:27:39 -07:00 committed by GitHub
commit d8c61c9763
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 1580 additions and 811 deletions

View file

@ -0,0 +1,67 @@
#ifndef _SWAY_TRANSACTION_H
#define _SWAY_TRANSACTION_H
#include <wlr/render/wlr_texture.h>
#include "sway/tree/container.h"
/**
* Transactions enable us to perform atomic layout updates.
*
* When we want to make adjustments to the layout, we create a transaction.
* A transaction contains a list of affected containers and their new state.
* A state might contain a new size, or new border settings, or new parent/child
* relationships.
*
* Calling transaction_commit() makes sway notify of all the affected clients
* with their new sizes. We then wait for all the views to respond with their
* new surface sizes. When all are ready, or when a timeout has passed, we apply
* the updates all at the same time.
*/
struct sway_transaction;
/**
* Create a new transaction.
*/
struct sway_transaction *transaction_create(void);
/**
* Add a container's pending state to the transaction.
*/
void transaction_add_container(struct sway_transaction *transaction,
struct sway_container *container);
/**
* Submit a transaction to the client views for configuration.
*/
void transaction_commit(struct sway_transaction *transaction);
/**
* Notify the transaction system that a view is ready for the new layout.
*
* When all views in the transaction are ready, the layout will be applied.
*/
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial);
/**
* Notify the transaction system that a view is ready for the new layout, but
* identifying the instruction by width and height rather than by serial.
*
* This is used by xwayland views, as they don't have serials.
*/
void transaction_notify_view_ready_by_size(struct sway_view *view,
int width, int height);
/**
* Get the saved texture that should be rendered for a view.
*
* The addresses pointed at by the width and height pointers will be populated
* with the surface's dimensions, which may be different to the texture's
* dimensions if output scaling is used.
*
* This function should only be called if it is known that the view has
* instructions.
*/
struct wlr_texture *transaction_get_saved_texture(struct sway_view *view,
int *width, int *height);
#endif

View file

@ -118,6 +118,17 @@ struct sway_container *seat_get_focus_inactive_view(struct sway_seat *seat,
struct sway_container *seat_get_active_child(struct sway_seat *seat, struct sway_container *seat_get_active_child(struct sway_seat *seat,
struct sway_container *container); struct sway_container *container);
/**
* Return the immediate child of container which was most recently focused, with
* fallback to selecting the child in the parent's `current` (rendered) children
* list.
*
* This is useful for when a tabbed container and its children are destroyed but
* still being rendered, and we have to render an appropriate child.
*/
struct sway_container *seat_get_active_current_child(struct sway_seat *seat,
struct sway_container *container);
/** /**
* Iterate over the focus-inactive children of the container calling the * Iterate over the focus-inactive children of the container calling the
* function on each. * function on each.

View file

@ -46,6 +46,8 @@ void output_damage_surface(struct sway_output *output, double ox, double oy,
void output_damage_from_view(struct sway_output *output, void output_damage_from_view(struct sway_output *output,
struct sway_view *view); struct sway_view *view);
void output_damage_box(struct sway_output *output, struct wlr_box *box);
void output_damage_whole_container(struct sway_output *output, void output_damage_whole_container(struct sway_output *output,
struct sway_container *con); struct sway_container *con);

View file

@ -11,6 +11,7 @@
#include <wlr/types/wlr_xdg_shell.h> #include <wlr/types/wlr_xdg_shell.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
// TODO WLR: make Xwayland optional // TODO WLR: make Xwayland optional
#include "list.h"
#include "sway/xwayland.h" #include "sway/xwayland.h"
struct sway_server { struct sway_server {
@ -40,6 +41,14 @@ struct sway_server {
struct sway_xwayland xwayland; struct sway_xwayland xwayland;
struct wl_listener xwayland_surface; struct wl_listener xwayland_surface;
struct wl_listener xwayland_ready; struct wl_listener xwayland_ready;
bool debug_txn_timings;
list_t *transactions;
// When a view is being destroyed and is waiting for a transaction to
// complete it will be stored here.
list_t *destroying_containers;
}; };
struct sway_server server; struct sway_server server;

View file

@ -1,5 +1,6 @@
#ifndef _SWAY_ARRANGE_H #ifndef _SWAY_ARRANGE_H
#define _SWAY_ARRANGE_H #define _SWAY_ARRANGE_H
#include "sway/desktop/transaction.h"
struct sway_container; struct sway_container;
@ -9,16 +10,27 @@ void remove_gaps(struct sway_container *c);
// Add gaps around container // Add gaps around container
void add_gaps(struct sway_container *c); void add_gaps(struct sway_container *c);
// Determine the root container's geometry, then iterate to everything below /**
void arrange_root(void); * Arrange layout for all the children of the given container, and add them to
* the given transaction.
*
* Use this function if you need to arrange multiple sections of the tree in one
* transaction.
*
* You must set the desired state of the container before calling
* arrange_windows, then don't change any state-tracked properties in the
* container until you've called transaction_commit.
*/
void arrange_windows(struct sway_container *container,
struct sway_transaction *transaction);
// Determine the output's geometry, then iterate to everything below /**
void arrange_output(struct sway_container *output); * Arrange layout for the given container and commit the transaction.
*
// Determine the workspace's geometry, then iterate to everything below * This function is a wrapper around arrange_windows, and handles creating and
void arrange_workspace(struct sway_container *workspace); * committing the transaction for you. Use this function if you're only doing
* one arrange operation.
// Arrange layout for all the children of the given workspace/container */
void arrange_children_of(struct sway_container *parent); void arrange_and_commit(struct sway_container *container);
#endif #endif

View file

@ -54,6 +54,37 @@ struct sway_output;
struct sway_workspace; struct sway_workspace;
struct sway_view; struct sway_view;
struct sway_container_state {
// Container/swayc properties
enum sway_container_layout layout;
double swayc_x, swayc_y;
double swayc_width, swayc_height;
bool has_gaps;
double current_gaps;
double gaps_inner;
double gaps_outer;
struct sway_container *parent;
list_t *children;
// View properties
double view_x, view_y;
double view_width, view_height;
bool is_fullscreen;
enum sway_container_border border;
int border_thickness;
bool border_top;
bool border_bottom;
bool border_left;
bool border_right;
// Workspace properties
struct sway_view *ws_fullscreen;
struct sway_container *ws_floating;
};
struct sway_container { struct sway_container {
union { union {
// TODO: Encapsulate state for other node types as well like C_CONTAINER // TODO: Encapsulate state for other node types as well like C_CONTAINER
@ -69,6 +100,10 @@ struct sway_container {
*/ */
size_t id; size_t id;
// The pending state is the main container properties, and the current state is in the below struct.
// This means most places of the code can refer to the main variables (pending state) and it'll just work.
struct sway_container_state current;
char *name; // The view's title (unformatted) char *name; // The view's title (unformatted)
char *formatted_title; // The title displayed in the title bar char *formatted_title; // The title displayed in the title bar
@ -97,8 +132,6 @@ struct sway_container {
struct sway_container *parent; struct sway_container *parent;
list_t *marks; // list of char*
float alpha; float alpha;
struct wlr_texture *title_focused; struct wlr_texture *title_focused;
@ -107,6 +140,10 @@ struct sway_container {
struct wlr_texture *title_urgent; struct wlr_texture *title_urgent;
size_t title_height; size_t title_height;
list_t *instructions; // struct sway_transaction_instruction *
bool destroying;
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
// Raised after the tree updates, but before arrange_windows // Raised after the tree updates, but before arrange_windows
@ -150,6 +187,8 @@ struct sway_container *workspace_create(struct sway_container *output,
struct sway_container *container_view_create( struct sway_container *container_view_create(
struct sway_container *sibling, struct sway_view *sway_view); struct sway_container *sibling, struct sway_view *sway_view);
void container_free(struct sway_container *cont);
struct sway_container *container_destroy(struct sway_container *container); struct sway_container *container_destroy(struct sway_container *container);
struct sway_container *container_close(struct sway_container *container); struct sway_container *container_close(struct sway_container *container);
@ -253,4 +292,9 @@ void container_set_geometry_from_floating_view(struct sway_container *con);
*/ */
bool container_is_floating(struct sway_container *container); bool container_is_floating(struct sway_container *container);
/**
* Get a container's box in layout coordinates.
*/
void container_get_box(struct sway_container *container, struct wlr_box *box);
#endif #endif

View file

@ -29,8 +29,8 @@ struct sway_view_impl {
const char *(*get_string_prop)(struct sway_view *view, const char *(*get_string_prop)(struct sway_view *view,
enum sway_view_prop prop); enum sway_view_prop prop);
uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop); uint32_t (*get_int_prop)(struct sway_view *view, enum sway_view_prop prop);
void (*configure)(struct sway_view *view, double lx, double ly, int width, uint32_t (*configure)(struct sway_view *view, double lx, double ly,
int height); int width, int height);
void (*set_activated)(struct sway_view *view, bool activated); void (*set_activated)(struct sway_view *view, bool activated);
void (*set_tiled)(struct sway_view *view, bool tiled); void (*set_tiled)(struct sway_view *view, bool tiled);
void (*set_fullscreen)(struct sway_view *view, bool fullscreen); void (*set_fullscreen)(struct sway_view *view, bool fullscreen);
@ -69,6 +69,8 @@ struct sway_view {
bool border_left; bool border_left;
bool border_right; bool border_right;
bool destroying;
list_t *executed_criteria; // struct criteria * list_t *executed_criteria; // struct criteria *
list_t *marks; // char * list_t *marks; // char *
@ -104,8 +106,6 @@ struct sway_xdg_shell_v6_view {
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener destroy; struct wl_listener destroy;
int pending_width, pending_height;
}; };
struct sway_xdg_shell_view { struct sway_xdg_shell_view {
@ -120,8 +120,6 @@ struct sway_xdg_shell_view {
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener destroy; struct wl_listener destroy;
int pending_width, pending_height;
}; };
struct sway_xwayland_view { struct sway_xwayland_view {
@ -139,9 +137,6 @@ struct sway_xwayland_view {
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener destroy; struct wl_listener destroy;
int pending_lx, pending_ly;
int pending_width, pending_height;
}; };
struct sway_xwayland_unmanaged { struct sway_xwayland_unmanaged {
@ -213,9 +208,14 @@ uint32_t view_get_window_type(struct sway_view *view);
const char *view_get_shell(struct sway_view *view); const char *view_get_shell(struct sway_view *view);
void view_configure(struct sway_view *view, double ox, double oy, int width, uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
int height); int height);
/**
* Center the view in its workspace and build the swayc decorations around it.
*/
void view_init_floating(struct sway_view *view);
/** /**
* Configure the view's position and size based on the swayc's position and * Configure the view's position and size based on the swayc's position and
* size, taking borders into consideration. * size, taking borders into consideration.
@ -242,6 +242,8 @@ void view_for_each_surface(struct sway_view *view,
void view_init(struct sway_view *view, enum sway_view_type type, void view_init(struct sway_view *view, enum sway_view_type type,
const struct sway_view_impl *impl); const struct sway_view_impl *impl);
void view_free(struct sway_view *view);
void view_destroy(struct sway_view *view); void view_destroy(struct sway_view *view);
void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); void view_map(struct sway_view *view, struct wlr_surface *wlr_surface);

View file

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

View file

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

View file

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

View file

@ -31,21 +31,19 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
if (strcmp(argv[1], "on") == 0) { if (strcmp(argv[1], "on") == 0) {
config->edge_gaps = true; config->edge_gaps = true;
arrange_root();
} else if (strcmp(argv[1], "off") == 0) { } else if (strcmp(argv[1], "off") == 0) {
config->edge_gaps = false; config->edge_gaps = false;
arrange_root();
} else if (strcmp(argv[1], "toggle") == 0) { } else if (strcmp(argv[1], "toggle") == 0) {
if (!config->active) { if (!config->active) {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "gaps",
"Cannot toggle gaps while not running."); "Cannot toggle gaps while not running.");
} }
config->edge_gaps = !config->edge_gaps; config->edge_gaps = !config->edge_gaps;
arrange_root();
} else { } else {
return cmd_results_new(CMD_INVALID, "gaps", return cmd_results_new(CMD_INVALID, "gaps",
"gaps edge_gaps on|off|toggle"); "gaps edge_gaps on|off|toggle");
} }
arrange_and_commit(&root_container);
} else { } else {
int amount_idx = 0; // the current index in argv int amount_idx = 0; // the current index in argv
enum gaps_op op = GAPS_OP_SET; enum gaps_op op = GAPS_OP_SET;
@ -126,7 +124,7 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
if (amount_idx == 0) { // gaps <amount> if (amount_idx == 0) { // gaps <amount>
config->gaps_inner = val; config->gaps_inner = val;
config->gaps_outer = val; config->gaps_outer = val;
arrange_root(); arrange_and_commit(&root_container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
// Other variants. The middle-length variant (gaps inner|outer <amount>) // Other variants. The middle-length variant (gaps inner|outer <amount>)
@ -157,7 +155,7 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
} else { } else {
config->gaps_outer = total; config->gaps_outer = total;
} }
arrange_root(); arrange_and_commit(&root_container);
} else { } else {
struct sway_container *c = struct sway_container *c =
config->handler_context.current_container; config->handler_context.current_container;
@ -171,11 +169,7 @@ struct cmd_results *cmd_gaps(int argc, char **argv) {
c->gaps_outer = total; c->gaps_outer = total;
} }
if (c->parent) { arrange_and_commit(c->parent ? c->parent : &root_container);
arrange_children_of(c->parent);
} else {
arrange_root();
}
} }
} }

View file

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

View file

@ -5,8 +5,10 @@
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
#include "sway/commands.h" #include "sway/commands.h"
#include "sway/desktop/transaction.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
@ -88,6 +90,7 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
} }
free(ws_name); free(ws_name);
struct sway_container *old_parent = current->parent; struct sway_container *old_parent = current->parent;
struct sway_container *old_ws = container_parent(current, C_WORKSPACE);
struct sway_container *destination = seat_get_focus_inactive( struct sway_container *destination = seat_get_focus_inactive(
config->handler_context.seat, ws); config->handler_context.seat, ws);
container_move_to(current, destination); container_move_to(current, destination);
@ -96,6 +99,15 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
seat_set_focus(config->handler_context.seat, focus); seat_set_focus(config->handler_context.seat, focus);
container_reap_empty(old_parent); container_reap_empty(old_parent);
container_reap_empty(destination->parent); container_reap_empty(destination->parent);
// TODO: Ideally we would arrange the surviving parent after reaping,
// but container_reap_empty does not return it, so we arrange the
// workspace instead.
struct sway_transaction *txn = transaction_create();
arrange_windows(old_ws, txn);
arrange_windows(destination->parent, txn);
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} else if (strcasecmp(argv[1], "to") == 0 } else if (strcasecmp(argv[1], "to") == 0
&& strcasecmp(argv[2], "output") == 0) { && strcasecmp(argv[2], "output") == 0) {
@ -121,10 +133,20 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
focus = destination->children->items[0]; focus = destination->children->items[0];
} }
struct sway_container *old_parent = current->parent; struct sway_container *old_parent = current->parent;
struct sway_container *old_ws = container_parent(current, C_WORKSPACE);
container_move_to(current, focus); container_move_to(current, focus);
seat_set_focus(config->handler_context.seat, old_parent); seat_set_focus(config->handler_context.seat, old_parent);
container_reap_empty(old_parent); container_reap_empty(old_parent);
container_reap_empty(focus->parent); container_reap_empty(focus->parent);
// TODO: Ideally we would arrange the surviving parent after reaping,
// but container_reap_empty does not return it, so we arrange the
// workspace instead.
struct sway_transaction *txn = transaction_create();
arrange_windows(old_ws, txn);
arrange_windows(focus->parent, txn);
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
return cmd_results_new(CMD_INVALID, "move", expected_syntax); return cmd_results_new(CMD_INVALID, "move", expected_syntax);
@ -152,6 +174,37 @@ static struct cmd_results *cmd_move_workspace(struct sway_container *current,
current = container_parent(current, C_WORKSPACE); current = container_parent(current, C_WORKSPACE);
} }
container_move_to(current, destination); container_move_to(current, destination);
struct sway_transaction *txn = transaction_create();
arrange_windows(source, txn);
arrange_windows(destination, txn);
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
static struct cmd_results *move_in_direction(struct sway_container *container,
enum movement_direction direction, int move_amt) {
if (container->type == C_WORKSPACE) {
return cmd_results_new(CMD_FAILURE, "move",
"Cannot move workspaces in a direction");
}
// For simplicity, we'll arrange the entire workspace. The reason for this
// is moving the container might reap the old parent, and container_move
// does not return a surviving parent.
// TODO: Make container_move return the surviving parent so we can arrange
// just that.
struct sway_container *old_ws = container_parent(container, C_WORKSPACE);
container_move(container, direction, move_amt);
struct sway_container *new_ws = container_parent(container, C_WORKSPACE);
struct sway_transaction *txn = transaction_create();
arrange_windows(old_ws, txn);
if (new_ws != old_ws) {
arrange_windows(new_ws, txn);
}
transaction_commit(txn);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }
@ -173,13 +226,13 @@ struct cmd_results *cmd_move(int argc, char **argv) {
} }
if (strcasecmp(argv[0], "left") == 0) { if (strcasecmp(argv[0], "left") == 0) {
container_move(current, MOVE_LEFT, move_amt); return move_in_direction(current, MOVE_LEFT, move_amt);
} else if (strcasecmp(argv[0], "right") == 0) { } else if (strcasecmp(argv[0], "right") == 0) {
container_move(current, MOVE_RIGHT, move_amt); return move_in_direction(current, MOVE_RIGHT, move_amt);
} else if (strcasecmp(argv[0], "up") == 0) { } else if (strcasecmp(argv[0], "up") == 0) {
container_move(current, MOVE_UP, move_amt); return move_in_direction(current, MOVE_UP, move_amt);
} else if (strcasecmp(argv[0], "down") == 0) { } else if (strcasecmp(argv[0], "down") == 0) {
container_move(current, MOVE_DOWN, move_amt); return move_in_direction(current, MOVE_DOWN, move_amt);
} else if (strcasecmp(argv[0], "container") == 0 } else if (strcasecmp(argv[0], "container") == 0
|| strcasecmp(argv[0], "window") == 0) { || strcasecmp(argv[0], "window") == 0) {
return cmd_move_container(current, argc, argv); return cmd_move_container(current, argc, argv);

View file

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

View file

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

View file

@ -16,13 +16,14 @@ struct cmd_results *cmd_smart_gaps(int argc, char **argv) {
if (strcmp(argv[0], "on") == 0) { if (strcmp(argv[0], "on") == 0) {
config->smart_gaps = true; config->smart_gaps = true;
arrange_root();
} else if (strcmp(argv[0], "off") == 0) { } else if (strcmp(argv[0], "off") == 0) {
config->smart_gaps = false; config->smart_gaps = false;
arrange_root();
} else { } else {
return cmd_results_new(CMD_INVALID, "smart_gaps", return cmd_results_new(CMD_INVALID, "smart_gaps",
"Expected 'smart_gaps <on|off>' "); "Expected 'smart_gaps <on|off>' ");
} }
arrange_and_commit(&root_container);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

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

View file

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

View file

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

View file

@ -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) { for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *cont = root_container.children->items[i]; struct sway_container *cont = root_container.children->items[i];
if (cont->type == C_OUTPUT) { 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); surface, whole);
} }
} }

View file

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

View file

@ -6,6 +6,7 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_box.h> #include <wlr/types/wlr_box.h>
#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_matrix.h> #include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_damage.h> #include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
@ -69,6 +70,7 @@ struct render_data {
struct root_geometry root_geo; struct root_geometry root_geo;
struct sway_output *output; struct sway_output *output;
pixman_region32_t *damage; pixman_region32_t *damage;
struct sway_view *view;
float alpha; float alpha;
}; };
@ -100,8 +102,8 @@ static bool get_surface_box(struct root_geometry *geo,
wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box); wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box);
struct wlr_box output_box = { struct wlr_box output_box = {
.width = output->swayc->width, .width = output->swayc->current.swayc_width,
.height = output->swayc->height, .height = output->swayc->current.swayc_height,
}; };
struct wlr_box intersection; struct wlr_box intersection;
@ -124,10 +126,10 @@ static void output_view_for_each_surface(struct sway_view *view,
struct root_geometry *geo, wlr_surface_iterator_func_t iterator, struct root_geometry *geo, wlr_surface_iterator_func_t iterator,
void *user_data) { void *user_data) {
struct render_data *data = user_data; struct render_data *data = user_data;
geo->x = view->x - data->output->swayc->x; geo->x = view->swayc->current.view_x - data->output->swayc->current.swayc_x;
geo->y = view->y - data->output->swayc->y; geo->y = view->swayc->current.view_y - data->output->swayc->current.swayc_y;
geo->width = view->surface->current->width; geo->width = view->swayc->current.view_width;
geo->height = view->surface->current->height; geo->height = view->swayc->current.view_height;
geo->rotation = 0; // TODO geo->rotation = 0; // TODO
view_for_each_surface(view, iterator, user_data); view_for_each_surface(view, iterator, user_data);
@ -153,8 +155,8 @@ static void unmanaged_for_each_surface(struct wl_list *unmanaged,
wl_list_for_each(unmanaged_surface, unmanaged, link) { wl_list_for_each(unmanaged_surface, unmanaged, link) {
struct wlr_xwayland_surface *xsurface = struct wlr_xwayland_surface *xsurface =
unmanaged_surface->wlr_xwayland_surface; unmanaged_surface->wlr_xwayland_surface;
double ox = unmanaged_surface->lx - output->swayc->x; double ox = unmanaged_surface->lx - output->swayc->current.swayc_x;
double oy = unmanaged_surface->ly - output->swayc->y; double oy = unmanaged_surface->ly - output->swayc->current.swayc_y;
surface_for_each_surface(xsurface->surface, ox, oy, geo, surface_for_each_surface(xsurface->surface, ox, oy, geo,
iterator, user_data); iterator, user_data);
@ -241,7 +243,7 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
float alpha = data->alpha; float alpha = data->alpha;
struct wlr_texture *texture = wlr_surface_get_texture(surface); struct wlr_texture *texture = wlr_surface_get_texture(surface);
if (texture == NULL) { if (!texture) {
return; return;
} }
@ -341,64 +343,107 @@ static void render_view_surfaces(struct sway_view *view,
struct render_data data = { struct render_data data = {
.output = output, .output = output,
.damage = damage, .damage = damage,
.view = view,
.alpha = alpha, .alpha = alpha,
}; };
output_view_for_each_surface( output_view_for_each_surface(
view, &data.root_geo, render_surface_iterator, &data); view, &data.root_geo, render_surface_iterator, &data);
} }
static void render_saved_view(struct sway_view *view,
struct sway_output *output, pixman_region32_t *damage, float alpha) {
struct wlr_output *wlr_output = output->wlr_output;
int width, height;
struct wlr_texture *texture =
transaction_get_saved_texture(view, &width, &height);
if (!texture) {
return;
}
struct wlr_box box = {
.x = view->swayc->current.view_x - output->swayc->current.swayc_x,
.y = view->swayc->current.view_y - output->swayc->current.swayc_y,
.width = width,
.height = height,
};
struct wlr_box output_box = {
.width = output->swayc->current.swayc_width,
.height = output->swayc->current.swayc_height,
};
struct wlr_box intersection;
bool intersects = wlr_box_intersection(&output_box, &box, &intersection);
if (!intersects) {
return;
}
scale_box(&box, wlr_output->scale);
float matrix[9];
wlr_matrix_project_box(matrix, &box, WL_OUTPUT_TRANSFORM_NORMAL, 0,
wlr_output->transform_matrix);
render_texture(wlr_output, damage, texture, &box, matrix, alpha);
}
/** /**
* Render a view's surface and left/bottom/right borders. * Render a view's surface and left/bottom/right borders.
*/ */
static void render_view(struct sway_output *output, pixman_region32_t *damage, static void render_view(struct sway_output *output, pixman_region32_t *damage,
struct sway_container *con, struct border_colors *colors) { struct sway_container *con, struct border_colors *colors) {
struct sway_view *view = con->sway_view; struct sway_view *view = con->sway_view;
if (view->swayc->instructions->length) {
render_saved_view(view, output, damage, view->swayc->alpha);
} else {
render_view_surfaces(view, output, damage, view->swayc->alpha); render_view_surfaces(view, output, damage, view->swayc->alpha);
}
struct wlr_box box; struct wlr_box box;
float output_scale = output->wlr_output->scale; float output_scale = output->wlr_output->scale;
float color[4]; float color[4];
struct sway_container_state *state = &con->current;
if (view->border != B_NONE) { if (state->border != B_NONE) {
if (view->border_left) { if (state->border_left) {
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = state->swayc_x;
box.y = view->y; box.y = state->view_y;
box.width = view->border_thickness; box.width = state->border_thickness;
box.height = view->height; box.height = state->view_height;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, damage, &box, color); render_rect(output->wlr_output, damage, &box, color);
} }
if (view->border_right) { if (state->border_right) {
if (con->parent->children->length == 1 if (state->parent->current.children->length == 1
&& con->parent->layout == L_HORIZ) { && state->parent->current.layout == L_HORIZ) {
memcpy(&color, colors->indicator, sizeof(float) * 4); memcpy(&color, colors->indicator, sizeof(float) * 4);
} else { } else {
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
} }
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = view->x + view->width; box.x = state->view_x + state->view_width;
box.y = view->y; box.y = state->view_y;
box.width = view->border_thickness; box.width = state->border_thickness;
box.height = view->height; box.height = state->view_height;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, damage, &box, color); render_rect(output->wlr_output, damage, &box, color);
} }
if (view->border_bottom) { if (state->border_bottom) {
if (con->parent->children->length == 1 if (state->parent->current.children->length == 1
&& con->parent->layout == L_VERT) { && con->current.parent->current.layout == L_VERT) {
memcpy(&color, colors->indicator, sizeof(float) * 4); memcpy(&color, colors->indicator, sizeof(float) * 4);
} else { } else {
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
} }
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = state->swayc_x;
box.y = view->y + view->height; box.y = state->view_y + state->view_height;
box.width = con->width; box.width = state->swayc_width;
box.height = view->border_thickness; box.height = state->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, damage, &box, color); render_rect(output->wlr_output, damage, &box, color);
} }
@ -422,11 +467,13 @@ static void render_titlebar(struct sway_output *output,
struct wlr_texture *marks_texture) { struct wlr_texture *marks_texture) {
struct wlr_box box; struct wlr_box box;
float color[4]; float color[4];
struct sway_view *view = con->type == C_VIEW ? con->sway_view : NULL; struct sway_container_state *state = &con->current;
float output_scale = output->wlr_output->scale; float output_scale = output->wlr_output->scale;
enum sway_container_layout layout = con->parent->layout; enum sway_container_layout layout = state->parent->current.layout;
bool is_last_child = list_t *children = state->parent->current.children;
con->parent->children->items[con->parent->children->length - 1] == con; bool is_last_child = children->items[children->length - 1] == con;
double output_x = output->swayc->current.swayc_x;
double output_y = output->swayc->current.swayc_y;
// Single pixel bar above title // Single pixel bar above title
memcpy(&color, colors->border, sizeof(float) * 4); memcpy(&color, colors->border, sizeof(float) * 4);
@ -443,9 +490,9 @@ static void render_titlebar(struct sway_output *output,
bool connects_sides = false; bool connects_sides = false;
if (layout == L_HORIZ || layout == L_VERT || if (layout == L_HORIZ || layout == L_VERT ||
(layout == L_STACKED && is_last_child)) { (layout == L_STACKED && is_last_child)) {
if (view) { if (con->type == C_VIEW) {
left_offset = view->border_left * view->border_thickness; left_offset = state->border_left * state->border_thickness;
right_offset = view->border_right * view->border_thickness; right_offset = state->border_right * state->border_thickness;
connects_sides = true; connects_sides = true;
} }
} }
@ -479,10 +526,9 @@ static void render_titlebar(struct sway_output *output,
struct wlr_box texture_box; struct wlr_box texture_box;
wlr_texture_get_size(marks_texture, wlr_texture_get_size(marks_texture,
&texture_box.width, &texture_box.height); &texture_box.width, &texture_box.height);
texture_box.x = (x - output->swayc->x + width - TITLEBAR_H_PADDING) texture_box.x = (x - output_x + width - TITLEBAR_H_PADDING)
* output_scale - texture_box.width; * output_scale - texture_box.width;
texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING) texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale;
* output_scale;
float matrix[9]; float matrix[9];
wlr_matrix_project_box(matrix, &texture_box, wlr_matrix_project_box(matrix, &texture_box,
@ -503,10 +549,8 @@ static void render_titlebar(struct sway_output *output,
struct wlr_box texture_box; struct wlr_box texture_box;
wlr_texture_get_size(title_texture, wlr_texture_get_size(title_texture,
&texture_box.width, &texture_box.height); &texture_box.width, &texture_box.height);
texture_box.x = (x - output->swayc->x + TITLEBAR_H_PADDING) texture_box.x = (x - output_x + TITLEBAR_H_PADDING) * output_scale;
* output_scale; texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale;
texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING)
* output_scale;
float matrix[9]; float matrix[9];
wlr_matrix_project_box(matrix, &texture_box, wlr_matrix_project_box(matrix, &texture_box,
@ -566,15 +610,15 @@ static void render_titlebar(struct sway_output *output,
// Left pixel in line with bottom bar // Left pixel in line with bottom bar
box.x = x; box.x = x;
box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
box.width = view->border_thickness * view->border_left; box.width = state->border_thickness * state->border_left;
box.height = TITLEBAR_BORDER_THICKNESS; box.height = TITLEBAR_BORDER_THICKNESS;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
// Right pixel in line with bottom bar // Right pixel in line with bottom bar
box.x = x + width - view->border_thickness * view->border_right; box.x = x + width - state->border_thickness * state->border_right;
box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
box.width = view->border_thickness * view->border_right; box.width = state->border_thickness * state->border_right;
box.height = TITLEBAR_BORDER_THICKNESS; box.height = TITLEBAR_BORDER_THICKNESS;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
@ -587,8 +631,8 @@ static void render_titlebar(struct sway_output *output,
static void render_top_border(struct sway_output *output, static void render_top_border(struct sway_output *output,
pixman_region32_t *output_damage, struct sway_container *con, pixman_region32_t *output_damage, struct sway_container *con,
struct border_colors *colors) { struct border_colors *colors) {
struct sway_view *view = con->sway_view; struct sway_container_state *state = &con->current;
if (!view->border_top) { if (!state->border_top) {
return; return;
} }
struct wlr_box box; struct wlr_box box;
@ -598,10 +642,10 @@ static void render_top_border(struct sway_output *output,
// Child border - top edge // Child border - top edge
memcpy(&color, colors->child_border, sizeof(float) * 4); memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha); premultiply_alpha(color, con->alpha);
box.x = con->x; box.x = state->swayc_x;
box.y = con->y; box.y = state->swayc_y;
box.width = con->width; box.width = state->swayc_width;
box.height = view->border_thickness; box.height = state->border_thickness;
scale_box(&box, output_scale); scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color); render_rect(output->wlr_output, output_damage, &box, color);
} }
@ -621,30 +665,34 @@ static void render_container_simple(struct sway_output *output,
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat); struct sway_container *focus = seat_get_focus(seat);
for (int i = 0; i < con->children->length; ++i) { for (int i = 0; i < con->current.children->length; ++i) {
struct sway_container *child = con->children->items[i]; struct sway_container *child = con->current.children->items[i];
if (child->type == C_VIEW) { if (child->type == C_VIEW) {
struct sway_view *view = child->sway_view;
struct border_colors *colors; struct border_colors *colors;
struct wlr_texture *title_texture; struct wlr_texture *title_texture;
struct wlr_texture *marks_texture; struct wlr_texture *marks_texture;
struct sway_container_state *state = &child->current;
if (focus == child || parent_focused) { if (focus == child || parent_focused) {
colors = &config->border_colors.focused; colors = &config->border_colors.focused;
title_texture = child->title_focused; title_texture = child->title_focused;
marks_texture = child->sway_view->marks_focused; marks_texture = view->marks_focused;
} else if (seat_get_focus_inactive(seat, con) == child) { } else if (seat_get_focus_inactive(seat, con) == child) {
colors = &config->border_colors.focused_inactive; colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive; title_texture = child->title_focused_inactive;
marks_texture = child->sway_view->marks_focused_inactive; marks_texture = view->marks_focused_inactive;
} else { } else {
colors = &config->border_colors.unfocused; colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused; title_texture = child->title_unfocused;
marks_texture = child->sway_view->marks_unfocused; marks_texture = view->marks_unfocused;
} }
if (child->sway_view->border == B_NORMAL) { if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, child->x, child->y, render_titlebar(output, damage, child, state->swayc_x,
child->width, colors, title_texture, marks_texture); state->swayc_y, state->swayc_width, colors,
title_texture, marks_texture);
} else { } else {
render_top_border(output, damage, child, colors); render_top_border(output, damage, child, colors);
} }
@ -662,83 +710,23 @@ static void render_container_simple(struct sway_output *output,
static void render_container_tabbed(struct sway_output *output, static void render_container_tabbed(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con, pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) { bool parent_focused) {
if (!con->children->length) { if (!con->current.children->length) {
return; return;
} }
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat); struct sway_container *focus = seat_get_focus(seat);
struct sway_container *current = seat_get_active_child(seat, con); struct sway_container *current = seat_get_active_current_child(seat, con);
struct border_colors *current_colors = NULL; struct border_colors *current_colors = &config->border_colors.unfocused;
struct sway_container_state *pstate = &con->current;
// Render tabs // Render tabs
for (int i = 0; i < con->children->length; ++i) { for (int i = 0; i < con->current.children->length; ++i) {
struct sway_container *child = con->children->items[i]; struct sway_container *child = con->current.children->items[i];
struct sway_view *view = child->type == C_VIEW ? child->sway_view : NULL;
struct sway_container_state *cstate = &child->current;
struct border_colors *colors; struct border_colors *colors;
struct wlr_texture *title_texture; struct wlr_texture *title_texture;
struct wlr_texture *marks_texture; struct wlr_texture *marks_texture;
struct sway_view *view =
child->type == C_VIEW ? child->sway_view : NULL;
if (focus == child || parent_focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
marks_texture = view ? view->marks_focused : NULL;
} else if (child == current) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
marks_texture = view ? view->marks_focused : NULL;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
marks_texture = view ? view->marks_unfocused : NULL;
}
int tab_width = con->width / con->children->length;
int x = con->x + tab_width * i;
// Make last tab use the remaining width of the parent
if (i == con->children->length - 1) {
tab_width = con->width - tab_width * i;
}
render_titlebar(output, damage, child, x, child->y, tab_width, colors,
title_texture, marks_texture);
if (child == current) {
current_colors = colors;
}
}
// Render surface and left/right/bottom borders
if (current->type == C_VIEW) {
render_view(output, damage, current, current_colors);
} else {
render_container(output, damage, current,
parent_focused || current == focus);
}
}
/**
* Render a container's children using the L_STACKED layout.
*/
static void render_container_stacked(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) {
if (!con->children->length) {
return;
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat);
struct sway_container *current = seat_get_active_child(seat, con);
struct border_colors *current_colors = NULL;
// Render titles
for (int i = 0; i < con->children->length; ++i) {
struct sway_container *child = con->children->items[i];
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
struct sway_view *view =
child->type == C_VIEW ? child->sway_view : NULL;
if (focus == child || parent_focused) { if (focus == child || parent_focused) {
colors = &config->border_colors.focused; colors = &config->border_colors.focused;
@ -754,8 +742,14 @@ static void render_container_stacked(struct sway_output *output,
marks_texture = view ? view->marks_unfocused : NULL; marks_texture = view ? view->marks_unfocused : NULL;
} }
int y = con->y + container_titlebar_height() * i; int tab_width = pstate->swayc_width / pstate->children->length;
render_titlebar(output, damage, child, child->x, y, child->width, int x = pstate->swayc_x + tab_width * i;
// Make last tab use the remaining width of the parent
if (i == pstate->children->length - 1) {
tab_width = pstate->swayc_width - tab_width * i;
}
render_titlebar(output, damage, child, x, cstate->swayc_y, tab_width,
colors, title_texture, marks_texture); colors, title_texture, marks_texture);
if (child == current) { if (child == current) {
@ -764,6 +758,7 @@ static void render_container_stacked(struct sway_output *output,
} }
// Render surface and left/right/bottom borders // Render surface and left/right/bottom borders
if (current) {
if (current->type == C_VIEW) { if (current->type == C_VIEW) {
render_view(output, damage, current, current_colors); render_view(output, damage, current, current_colors);
} else { } else {
@ -771,11 +766,70 @@ static void render_container_stacked(struct sway_output *output,
parent_focused || current == focus); parent_focused || current == focus);
} }
} }
}
/**
* Render a container's children using the L_STACKED layout.
*/
static void render_container_stacked(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) {
if (!con->current.children->length) {
return;
}
struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus(seat);
struct sway_container *current = seat_get_active_current_child(seat, con);
struct border_colors *current_colors = &config->border_colors.unfocused;
struct sway_container_state *pstate = &con->current;
// Render titles
for (int i = 0; i < con->current.children->length; ++i) {
struct sway_container *child = con->current.children->items[i];
struct sway_view *view = child->type == C_VIEW ? child->sway_view : NULL;
struct sway_container_state *cstate = &child->current;
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
if (focus == child || parent_focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
marks_texture = view ? view->marks_focused : NULL;
} else if (child == current) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
marks_texture = view ? view->marks_focused_inactive : NULL;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
marks_texture = view ? view->marks_unfocused : NULL;
}
int y = pstate->swayc_y + container_titlebar_height() * i;
render_titlebar(output, damage, child, cstate->swayc_x, y,
cstate->swayc_width, colors, title_texture, marks_texture);
if (child == current) {
current_colors = colors;
}
}
// Render surface and left/right/bottom borders
if (current) {
if (current->type == C_VIEW) {
render_view(output, damage, current, current_colors);
} else {
render_container(output, damage, current,
parent_focused || current == focus);
}
}
}
static void render_container(struct sway_output *output, static void render_container(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con, pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) { bool parent_focused) {
switch (con->layout) { switch (con->current.layout) {
case L_NONE: case L_NONE:
case L_HORIZ: case L_HORIZ:
case L_VERT: case L_VERT:
@ -812,10 +866,11 @@ static void render_floating_container(struct sway_output *soutput,
marks_texture = view->marks_unfocused; marks_texture = view->marks_unfocused;
} }
if (con->sway_view->border == B_NORMAL) { if (con->current.border == B_NORMAL) {
render_titlebar(soutput, damage, con, con->x, con->y, con->width, render_titlebar(soutput, damage, con, con->current.swayc_x,
colors, title_texture, marks_texture); con->current.swayc_y, con->current.swayc_width, colors,
} else if (con->sway_view->border != B_NONE) { title_texture, marks_texture);
} else if (con->current.border != B_NONE) {
render_top_border(soutput, damage, con, colors); render_top_border(soutput, damage, con, colors);
} }
render_view(soutput, damage, con, colors); render_view(soutput, damage, con, colors);
@ -826,17 +881,18 @@ static void render_floating_container(struct sway_output *soutput,
static void render_floating(struct sway_output *soutput, static void render_floating(struct sway_output *soutput,
pixman_region32_t *damage) { pixman_region32_t *damage) {
for (int i = 0; i < root_container.children->length; ++i) { for (int i = 0; i < root_container.current.children->length; ++i) {
struct sway_container *output = root_container.children->items[i]; struct sway_container *output =
for (int j = 0; j < output->children->length; ++j) { root_container.current.children->items[i];
struct sway_container *workspace = output->children->items[j]; for (int j = 0; j < output->current.children->length; ++j) {
struct sway_workspace *ws = workspace->sway_workspace; struct sway_container *ws = output->current.children->items[j];
if (!workspace_is_visible(workspace)) { if (!workspace_is_visible(ws)) {
continue; continue;
} }
for (int k = 0; k < ws->floating->children->length; ++k) { list_t *floating =
struct sway_container *floater = ws->current.ws_floating->current.children;
ws->floating->children->items[k]; for (int k = 0; k < floating->length; ++k) {
struct sway_container *floater = floating->items[k];
render_floating_container(soutput, damage, floater); render_floating_container(soutput, damage, floater);
} }
} }
@ -850,7 +906,7 @@ static struct sway_container *output_get_active_workspace(
seat_get_focus_inactive(seat, output->swayc); seat_get_focus_inactive(seat, output->swayc);
if (!focus) { if (!focus) {
// We've never been to this output before // We've never been to this output before
focus = output->swayc->children->items[0]; focus = output->swayc->current.children->items[0];
} }
struct sway_container *workspace = focus; struct sway_container *workspace = focus;
if (workspace->type != C_WORKSPACE) { if (workspace->type != C_WORKSPACE) {
@ -891,8 +947,9 @@ static void render_output(struct sway_output *output, struct timespec *when,
} }
struct sway_container *workspace = output_get_active_workspace(output); struct sway_container *workspace = output_get_active_workspace(output);
struct sway_view *fullscreen_view = workspace->current.ws_fullscreen;
if (workspace->sway_workspace->fullscreen) { if (fullscreen_view) {
float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f}; float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f};
int nrects; int nrects;
@ -903,10 +960,9 @@ static void render_output(struct sway_output *output, struct timespec *when,
} }
// TODO: handle views smaller than the output // TODO: handle views smaller than the output
render_view_surfaces( render_view_surfaces(fullscreen_view, output, damage, 1.0f);
workspace->sway_workspace->fullscreen, output, damage, 1.0f);
if (workspace->sway_workspace->fullscreen->type == SWAY_VIEW_XWAYLAND) { if (fullscreen_view->type == SWAY_VIEW_XWAYLAND) {
render_unmanaged(output, damage, render_unmanaged(output, damage,
&root_container.sway_root->xwayland_unmanaged); &root_container.sway_root->xwayland_unmanaged);
} }
@ -1022,11 +1078,11 @@ static void send_frame_done(struct sway_output *output, struct timespec *when) {
}; };
struct sway_container *workspace = output_get_active_workspace(output); struct sway_container *workspace = output_get_active_workspace(output);
if (workspace->sway_workspace->fullscreen) { if (workspace->current.ws_fullscreen) {
send_frame_done_container_iterator( send_frame_done_container_iterator(
workspace->sway_workspace->fullscreen->swayc, &data); workspace->current.ws_fullscreen->swayc, &data);
if (workspace->sway_workspace->fullscreen->type == SWAY_VIEW_XWAYLAND) { if (workspace->current.ws_fullscreen->type == SWAY_VIEW_XWAYLAND) {
send_frame_done_unmanaged(&data, send_frame_done_unmanaged(&data,
&root_container.sway_root->xwayland_unmanaged); &root_container.sway_root->xwayland_unmanaged);
} }
@ -1168,6 +1224,16 @@ void output_damage_from_view(struct sway_output *output,
output_damage_view(output, view, false); 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, static void output_damage_whole_container_iterator(struct sway_container *con,
void *data) { void *data) {
struct sway_output *output = data; struct sway_output *output = data;
@ -1182,10 +1248,10 @@ static void output_damage_whole_container_iterator(struct sway_container *con,
void output_damage_whole_container(struct sway_output *output, void output_damage_whole_container(struct sway_output *output,
struct sway_container *con) { struct sway_container *con) {
struct wlr_box box = { struct wlr_box box = {
.x = con->x - output->wlr_output->lx, .x = con->current.swayc_x - output->wlr_output->lx,
.y = con->y - output->wlr_output->ly, .y = con->current.swayc_y - output->wlr_output->ly,
.width = con->width, .width = con->current.swayc_width,
.height = con->height, .height = con->current.swayc_height,
}; };
scale_box(&box, output->wlr_output->scale); scale_box(&box, output->wlr_output->scale);
wlr_output_damage_add_box(output->damage, &box); wlr_output_damage_add_box(output->damage, &box);
@ -1209,18 +1275,20 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&output->destroy.link); wl_list_remove(&output->destroy.link);
output->wlr_output->data = NULL; output->wlr_output->data = NULL;
free(output); free(output);
arrange_and_commit(&root_container);
} }
static void handle_mode(struct wl_listener *listener, void *data) { static void handle_mode(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, mode); struct sway_output *output = wl_container_of(listener, output, mode);
arrange_layers(output); arrange_layers(output);
arrange_output(output->swayc); arrange_and_commit(output->swayc);
} }
static void handle_transform(struct wl_listener *listener, void *data) { static void handle_transform(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, transform); struct sway_output *output = wl_container_of(listener, output, transform);
arrange_layers(output); arrange_layers(output);
arrange_output(output->swayc); arrange_and_commit(output->swayc);
} }
static void handle_scale_iterator(struct sway_container *view, void *data) { static void handle_scale_iterator(struct sway_container *view, void *data) {
@ -1230,8 +1298,8 @@ static void handle_scale_iterator(struct sway_container *view, void *data) {
static void handle_scale(struct wl_listener *listener, void *data) { static void handle_scale(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, scale); struct sway_output *output = wl_container_of(listener, output, scale);
arrange_layers(output); arrange_layers(output);
arrange_output(output->swayc);
container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL); container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL);
arrange_and_commit(output->swayc);
} }
void handle_new_output(struct wl_listener *listener, void *data) { void handle_new_output(struct wl_listener *listener, void *data) {
@ -1296,5 +1364,5 @@ void output_enable(struct sway_output *output) {
output->damage_destroy.notify = damage_handle_destroy; output->damage_destroy.notify = damage_handle_destroy;
arrange_layers(output); arrange_layers(output);
arrange_root(); arrange_and_commit(&root_container);
} }

415
sway/desktop/transaction.c Normal file
View file

@ -0,0 +1,415 @@
#define _POSIX_C_SOURCE 200809L
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <wlr/types/wlr_buffer.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 "sway/tree/workspace.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
/**
* If enabled, sway will always wait for the transaction timeout before
* applying it, rather than applying it when the views are ready. This allows us
* to observe the rendered state while a transaction is in progress.
*/
#define TRANSACTION_DEBUG false
struct sway_transaction {
struct wl_event_source *timer;
list_t *instructions; // struct sway_transaction_instruction *
size_t num_waiting;
size_t num_configures;
struct timespec create_time;
struct timespec commit_time;
};
struct sway_transaction_instruction {
struct sway_transaction *transaction;
struct sway_container *container;
struct sway_container_state state;
struct wlr_buffer *saved_buffer;
int saved_buffer_width, saved_buffer_height;
uint32_t serial;
bool ready;
};
struct sway_transaction *transaction_create() {
struct sway_transaction *transaction =
calloc(1, sizeof(struct sway_transaction));
transaction->instructions = create_list();
if (server.debug_txn_timings) {
clock_gettime(CLOCK_MONOTONIC, &transaction->create_time);
}
return transaction;
}
static void remove_saved_view_buffer(
struct sway_transaction_instruction *instruction) {
if (instruction->saved_buffer) {
wlr_buffer_unref(instruction->saved_buffer);
instruction->saved_buffer = NULL;
}
}
static void save_view_buffer(struct sway_view *view,
struct sway_transaction_instruction *instruction) {
if (!sway_assert(instruction->saved_buffer == NULL,
"Didn't expect instruction to have a saved buffer already")) {
remove_saved_view_buffer(instruction);
}
if (view->surface && wlr_surface_has_buffer(view->surface)) {
instruction->saved_buffer = wlr_buffer_ref(view->surface->buffer);
instruction->saved_buffer_width = view->surface->current->width;
instruction->saved_buffer_height = view->surface->current->height;
}
}
static void transaction_destroy(struct sway_transaction *transaction) {
// Free instructions
for (int i = 0; i < transaction->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
transaction->instructions->items[i];
struct sway_container *con = instruction->container;
for (int j = 0; j < con->instructions->length; ++j) {
if (con->instructions->items[j] == instruction) {
list_del(con->instructions, j);
break;
}
}
if (con->destroying && !con->instructions->length) {
container_free(con);
}
remove_saved_view_buffer(instruction);
free(instruction);
}
list_free(transaction->instructions);
if (transaction->timer) {
wl_event_source_remove(transaction->timer);
}
free(transaction);
}
static void copy_pending_state(struct sway_container *container,
struct sway_container_state *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;
state->parent = container->parent;
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;
} else if (container->type == C_WORKSPACE) {
state->ws_fullscreen = container->sway_workspace->fullscreen;
state->ws_floating = container->sway_workspace->floating;
state->children = create_list();
list_cat(state->children, container->children);
} else {
state->children = create_list();
list_cat(state->children, container->children);
}
}
static bool transaction_has_container(struct sway_transaction *transaction,
struct sway_container *container) {
for (int i = 0; i < transaction->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
transaction->instructions->items[i];
if (instruction->container == container) {
return true;
}
}
return false;
}
void transaction_add_container(struct sway_transaction *transaction,
struct sway_container *container) {
if (transaction_has_container(transaction, container)) {
return;
}
struct sway_transaction_instruction *instruction =
calloc(1, sizeof(struct sway_transaction_instruction));
instruction->transaction = transaction;
instruction->container = container;
copy_pending_state(container, &instruction->state);
if (container->type == C_VIEW) {
save_view_buffer(container->sway_view, instruction);
}
list_add(transaction->instructions, instruction);
}
/**
* Apply a transaction to the "current" state of the tree.
*/
static void transaction_apply(struct sway_transaction *transaction) {
wlr_log(L_DEBUG, "Applying transaction %p", transaction);
if (server.debug_txn_timings) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct timespec *create = &transaction->create_time;
struct timespec *commit = &transaction->commit_time;
float ms_arranging = (commit->tv_sec - create->tv_sec) * 1000 +
(commit->tv_nsec - create->tv_nsec) / 1000000.0;
float ms_waiting = (now.tv_sec - commit->tv_sec) * 1000 +
(now.tv_nsec - commit->tv_nsec) / 1000000.0;
float ms_total = ms_arranging + ms_waiting;
wlr_log(L_DEBUG, "Transaction %p: %.1fms arranging, %.1fms waiting, "
"%.1fms total (%.1f frames if 60Hz)", transaction,
ms_arranging, ms_waiting, ms_total, ms_total / (1000 / 60));
}
// Apply the instruction state to the container's current state
for (int i = 0; i < transaction->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
transaction->instructions->items[i];
struct sway_container *container = instruction->container;
// Damage the old and new locations
struct wlr_box old_box = {
.x = container->current.swayc_x,
.y = container->current.swayc_y,
.width = container->current.swayc_width,
.height = container->current.swayc_height,
};
struct wlr_box new_box = {
.x = instruction->state.swayc_x,
.y = instruction->state.swayc_y,
.width = instruction->state.swayc_width,
.height = instruction->state.swayc_height,
};
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, &old_box);
output_damage_box(output->sway_output, &new_box);
}
// There are separate children lists for each instruction state, the
// container's current state and the container's pending state
// (ie. con->children). The list itself needs to be freed here.
// Any child containers which are being deleted will be cleaned up in
// transaction_destroy().
list_free(container->current.children);
memcpy(&container->current, &instruction->state,
sizeof(struct sway_container_state));
}
}
/**
* For simplicity, we only progress the queue if it can be completely flushed.
*/
static void transaction_progress_queue() {
// We iterate this list in reverse because we're more likely to find a
// waiting transactions at the end of the list.
for (int i = server.transactions->length - 1; i >= 0; --i) {
struct sway_transaction *transaction = server.transactions->items[i];
if (transaction->num_waiting) {
return;
}
}
for (int i = 0; i < server.transactions->length; ++i) {
struct sway_transaction *transaction = server.transactions->items[i];
transaction_apply(transaction);
transaction_destroy(transaction);
}
server.transactions->length = 0;
}
static int handle_timeout(void *data) {
struct sway_transaction *transaction = data;
wlr_log(L_DEBUG, "Transaction %p timed out (%li waiting)",
transaction, transaction->num_waiting);
transaction->num_waiting = 0;
transaction_progress_queue();
return 0;
}
static bool should_configure(struct sway_container *con,
struct sway_transaction_instruction *instruction) {
if (con->type != C_VIEW) {
return false;
}
if (con->destroying) {
return false;
}
// The settled dimensions are what size the view will be once any pending
// configures have applied (excluding the one we might be configuring now).
// If these match the dimensions that this transaction wants then we don't
// need to configure it.
int settled_width = con->current.view_width;
int settled_height = con->current.view_height;
if (con->instructions->length) {
struct sway_transaction_instruction *last_instruction =
con->instructions->items[con->instructions->length - 1];
settled_width = last_instruction->state.view_width;
settled_height = last_instruction->state.view_height;
}
if (settled_width == instruction->state.view_width &&
settled_height == instruction->state.view_height) {
return false;
}
return true;
}
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 (should_configure(con, instruction)) {
instruction->serial = view_configure(con->sway_view,
instruction->state.view_x,
instruction->state.view_y,
instruction->state.view_width,
instruction->state.view_height);
++transaction->num_waiting;
// From here on we are rendering a saved buffer of the view, which
// means we can send a frame done event to make the client redraw it
// as soon as possible. Additionally, this is required if a view is
// mapping and its default geometry doesn't intersect an output.
struct timespec when;
wlr_surface_send_frame_done(con->sway_view->surface, &when);
}
list_add(con->instructions, instruction);
}
transaction->num_configures = transaction->num_waiting;
if (server.debug_txn_timings) {
clock_gettime(CLOCK_MONOTONIC, &transaction->commit_time);
}
if (server.transactions->length || transaction->num_waiting) {
list_add(server.transactions, transaction);
} else {
// There are no other transactions in progress, and this one has nothing
// to wait for, so we can skip the queue.
wlr_log(L_DEBUG, "Transaction %p has nothing to wait for", transaction);
transaction_apply(transaction);
transaction_destroy(transaction);
return;
}
if (transaction->num_waiting) {
// 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);
}
// The debug tree shows the pending/live tree. Here is a good place to
// update it, because we make a transaction every time we change the pending
// tree.
update_debug_tree();
}
static void set_instruction_ready(
struct sway_transaction_instruction *instruction) {
instruction->ready = true;
struct sway_transaction *transaction = instruction->transaction;
if (server.debug_txn_timings) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
struct timespec *start = &transaction->commit_time;
float ms = (now.tv_sec - start->tv_sec) * 1000 +
(now.tv_nsec - start->tv_nsec) / 1000000.0;
wlr_log(L_DEBUG, "Transaction %p: %li/%li ready in %.1fms (%s)",
transaction,
transaction->num_configures - transaction->num_waiting + 1,
transaction->num_configures, ms,
instruction->container->name);
}
// If all views are ready, apply the transaction.
// If the transaction has timed out then its num_waiting will be 0 already.
if (transaction->num_waiting > 0 && --transaction->num_waiting == 0) {
#if !TRANSACTION_DEBUG
wlr_log(L_DEBUG, "Transaction %p is ready", transaction);
wl_event_source_timer_update(transaction->timer, 0);
transaction_progress_queue();
#endif
}
}
/**
* Mark all of the view's instructions as ready up to and including the
* instruction at the given index. This allows the view to skip a configure.
*/
static void set_instructions_ready(struct sway_view *view, int index) {
for (int i = 0; i <= index; ++i) {
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[i];
set_instruction_ready(instruction);
}
}
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) {
for (int i = 0; i < view->swayc->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[i];
if (instruction->serial == serial && !instruction->ready) {
set_instructions_ready(view, i);
return;
}
}
}
void transaction_notify_view_ready_by_size(struct sway_view *view,
int width, int height) {
for (int i = 0; i < view->swayc->instructions->length; ++i) {
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[i];
if (!instruction->ready && instruction->state.view_width == width &&
instruction->state.view_height == height) {
set_instructions_ready(view, i);
return;
}
}
}
struct wlr_texture *transaction_get_saved_texture(struct sway_view *view,
int *width, int *height) {
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[0];
if (!instruction->saved_buffer) {
return NULL;
}
*width = instruction->saved_buffer_width;
*height = instruction->saved_buffer_height;
return instruction->saved_buffer->texture;
}

View file

@ -8,6 +8,7 @@
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
@ -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, static uint32_t configure(struct sway_view *view, double lx, double ly,
int height) { int width, int height) {
struct sway_xdg_shell_view *xdg_shell_view = struct sway_xdg_shell_view *xdg_shell_view =
xdg_shell_view_from_view(view); xdg_shell_view_from_view(view);
if (xdg_shell_view == NULL) { if (xdg_shell_view == NULL) {
return; return 0;
} }
return wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
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);
} }
static void set_activated(struct sway_view *view, bool activated) { static void set_activated(struct sway_view *view, bool activated) {
@ -166,10 +163,6 @@ static void destroy(struct sway_view *view) {
if (xdg_shell_view == NULL) { if (xdg_shell_view == NULL) {
return; return;
} }
wl_list_remove(&xdg_shell_view->destroy.link);
wl_list_remove(&xdg_shell_view->map.link);
wl_list_remove(&xdg_shell_view->unmap.link);
wl_list_remove(&xdg_shell_view->request_fullscreen.link);
free(xdg_shell_view); free(xdg_shell_view);
} }
@ -189,18 +182,16 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view = struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, commit); wl_container_of(listener, xdg_shell_view, commit);
struct sway_view *view = &xdg_shell_view->view; struct sway_view *view = &xdg_shell_view->view;
if (view->swayc && container_is_floating(view->swayc)) { struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
int width = view->wlr_xdg_surface->geometry.width;
int height = view->wlr_xdg_surface->geometry.height; if (!view->swayc) {
if (!width && !height) { return;
width = view->wlr_xdg_surface->surface->current->width;
height = view->wlr_xdg_surface->surface->current->height;
} }
view_update_size(view, width, height);
} else { if (view->swayc->instructions->length) {
view_update_size(view, xdg_shell_view->pending_width, transaction_notify_view_ready(view, xdg_surface->configure_serial);
xdg_shell_view->pending_height);
} }
view_update_title(view, false); view_update_title(view, false);
view_damage_from(view); view_damage_from(view);
} }
@ -215,8 +206,13 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
static void handle_unmap(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view = struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, unmap); wl_container_of(listener, xdg_shell_view, unmap);
struct sway_view *view = &xdg_shell_view->view;
view_unmap(&xdg_shell_view->view); if (!sway_assert(view->surface, "Cannot unmap unmapped view")) {
return;
}
view_unmap(view);
wl_list_remove(&xdg_shell_view->commit.link); wl_list_remove(&xdg_shell_view->commit.link);
wl_list_remove(&xdg_shell_view->new_popup.link); wl_list_remove(&xdg_shell_view->new_popup.link);
@ -234,8 +230,17 @@ static void handle_map(struct wl_listener *listener, void *data) {
view->natural_width = view->wlr_xdg_surface->surface->current->width; view->natural_width = view->wlr_xdg_surface->surface->current->width;
view->natural_height = view->wlr_xdg_surface->surface->current->height; view->natural_height = view->wlr_xdg_surface->surface->current->height;
} }
view_map(view, view->wlr_xdg_surface->surface); view_map(view, view->wlr_xdg_surface->surface);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} else {
arrange_and_commit(view->swayc->parent);
}
xdg_shell_view->commit.notify = handle_commit; xdg_shell_view->commit.notify = handle_commit;
wl_signal_add(&xdg_surface->surface->events.commit, wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_view->commit); &xdg_shell_view->commit);
@ -243,16 +248,22 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_view->new_popup.notify = handle_new_popup; xdg_shell_view->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_surface->events.new_popup, wl_signal_add(&xdg_surface->events.new_popup,
&xdg_shell_view->new_popup); &xdg_shell_view->new_popup);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
}
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view = struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, destroy); wl_container_of(listener, xdg_shell_view, destroy);
view_destroy(&xdg_shell_view->view); struct sway_view *view = &xdg_shell_view->view;
if (!sway_assert(view->swayc == NULL || view->swayc->destroying,
"Tried to destroy a mapped view")) {
return;
}
wl_list_remove(&xdg_shell_view->destroy.link);
wl_list_remove(&xdg_shell_view->map.link);
wl_list_remove(&xdg_shell_view->unmap.link);
wl_list_remove(&xdg_shell_view->request_fullscreen.link);
view->wlr_xdg_surface = NULL;
view_destroy(view);
} }
static void handle_request_fullscreen(struct wl_listener *listener, void *data) { static void handle_request_fullscreen(struct wl_listener *listener, void *data) {
@ -261,6 +272,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
struct wlr_xdg_toplevel_set_fullscreen_event *e = data; struct wlr_xdg_toplevel_set_fullscreen_event *e = data;
struct wlr_xdg_surface *xdg_surface = struct wlr_xdg_surface *xdg_surface =
xdg_shell_view->view.wlr_xdg_surface; xdg_shell_view->view.wlr_xdg_surface;
struct sway_view *view = &xdg_shell_view->view;
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL, if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL,
"xdg_shell requested fullscreen of surface with role %i", "xdg_shell requested fullscreen of surface with role %i",
@ -271,7 +283,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return; return;
} }
view_set_fullscreen(&xdg_shell_view->view, e->fullscreen); view_set_fullscreen(view, e->fullscreen);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} }
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {

View file

@ -3,9 +3,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <wayland-server.h> #include <wayland-server.h>
#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/types/wlr_xdg_shell_v6.h>
#include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/server.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
@ -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, static uint32_t configure(struct sway_view *view, double lx, double ly,
int height) { int width, int height) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view = struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
xdg_shell_v6_view_from_view(view); xdg_shell_v6_view_from_view(view);
if (xdg_shell_v6_view == NULL) { if (xdg_shell_v6_view == NULL) {
return; return 0;
} }
return wlr_xdg_toplevel_v6_set_size(
xdg_shell_v6_view->pending_width = width; view->wlr_xdg_surface_v6, width, height);
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);
} }
static void set_activated(struct sway_view *view, bool activated) { static void set_activated(struct sway_view *view, bool activated) {
@ -161,10 +159,6 @@ static void destroy(struct sway_view *view) {
if (xdg_shell_v6_view == NULL) { if (xdg_shell_v6_view == NULL) {
return; return;
} }
wl_list_remove(&xdg_shell_v6_view->destroy.link);
wl_list_remove(&xdg_shell_v6_view->map.link);
wl_list_remove(&xdg_shell_v6_view->unmap.link);
wl_list_remove(&xdg_shell_v6_view->request_fullscreen.link);
free(xdg_shell_v6_view); free(xdg_shell_v6_view);
} }
@ -184,18 +178,15 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view = struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, commit); wl_container_of(listener, xdg_shell_v6_view, commit);
struct sway_view *view = &xdg_shell_v6_view->view; struct sway_view *view = &xdg_shell_v6_view->view;
if (view->swayc && container_is_floating(view->swayc)) { struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6;
int width = view->wlr_xdg_surface_v6->geometry.width;
int height = view->wlr_xdg_surface_v6->geometry.height; if (!view->swayc) {
if (!width && !height) { return;
width = view->wlr_xdg_surface_v6->surface->current->width;
height = view->wlr_xdg_surface_v6->surface->current->height;
} }
view_update_size(view, width, height); if (view->swayc->instructions->length) {
} else { transaction_notify_view_ready(view, xdg_surface_v6->configure_serial);
view_update_size(view, xdg_shell_v6_view->pending_width,
xdg_shell_v6_view->pending_height);
} }
view_update_title(view, false); view_update_title(view, false);
view_damage_from(view); view_damage_from(view);
} }
@ -210,8 +201,13 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
static void handle_unmap(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view = struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, unmap); wl_container_of(listener, xdg_shell_v6_view, unmap);
struct sway_view *view = &xdg_shell_v6_view->view;
view_unmap(&xdg_shell_v6_view->view); if (!sway_assert(view->surface, "Cannot unmap unmapped view")) {
return;
}
view_unmap(view);
wl_list_remove(&xdg_shell_v6_view->commit.link); wl_list_remove(&xdg_shell_v6_view->commit.link);
wl_list_remove(&xdg_shell_v6_view->new_popup.link); wl_list_remove(&xdg_shell_v6_view->new_popup.link);
@ -229,8 +225,17 @@ static void handle_map(struct wl_listener *listener, void *data) {
view->natural_width = view->wlr_xdg_surface_v6->surface->current->width; view->natural_width = view->wlr_xdg_surface_v6->surface->current->width;
view->natural_height = view->wlr_xdg_surface_v6->surface->current->height; view->natural_height = view->wlr_xdg_surface_v6->surface->current->height;
} }
view_map(view, view->wlr_xdg_surface_v6->surface); view_map(view, view->wlr_xdg_surface_v6->surface);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} else {
arrange_and_commit(view->swayc->parent);
}
xdg_shell_v6_view->commit.notify = handle_commit; xdg_shell_v6_view->commit.notify = handle_commit;
wl_signal_add(&xdg_surface->surface->events.commit, wl_signal_add(&xdg_surface->surface->events.commit,
&xdg_shell_v6_view->commit); &xdg_shell_v6_view->commit);
@ -238,16 +243,18 @@ static void handle_map(struct wl_listener *listener, void *data) {
xdg_shell_v6_view->new_popup.notify = handle_new_popup; xdg_shell_v6_view->new_popup.notify = handle_new_popup;
wl_signal_add(&xdg_surface->events.new_popup, wl_signal_add(&xdg_surface->events.new_popup,
&xdg_shell_v6_view->new_popup); &xdg_shell_v6_view->new_popup);
if (xdg_surface->toplevel->client_pending.fullscreen) {
view_set_fullscreen(view, true);
}
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view = struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, destroy); wl_container_of(listener, xdg_shell_v6_view, destroy);
view_destroy(&xdg_shell_v6_view->view); struct sway_view *view = &xdg_shell_v6_view->view;
wl_list_remove(&xdg_shell_v6_view->destroy.link);
wl_list_remove(&xdg_shell_v6_view->map.link);
wl_list_remove(&xdg_shell_v6_view->unmap.link);
wl_list_remove(&xdg_shell_v6_view->request_fullscreen.link);
view->wlr_xdg_surface_v6 = NULL;
view_destroy(view);
} }
static void handle_request_fullscreen(struct wl_listener *listener, void *data) { static void handle_request_fullscreen(struct wl_listener *listener, void *data) {
@ -256,6 +263,7 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data; struct wlr_xdg_toplevel_v6_set_fullscreen_event *e = data;
struct wlr_xdg_surface_v6 *xdg_surface = struct wlr_xdg_surface_v6 *xdg_surface =
xdg_shell_v6_view->view.wlr_xdg_surface_v6; xdg_shell_v6_view->view.wlr_xdg_surface_v6;
struct sway_view *view = &xdg_shell_v6_view->view;
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL, if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL,
"xdg_shell_v6 requested fullscreen of surface with role %i", "xdg_shell_v6 requested fullscreen of surface with role %i",
@ -266,7 +274,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return; return;
} }
view_set_fullscreen(&xdg_shell_v6_view->view, e->fullscreen); view_set_fullscreen(view, e->fullscreen);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} }
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {

View file

@ -7,10 +7,12 @@
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#include "log.h" #include "log.h"
#include "sway/desktop.h" #include "sway/desktop.h"
#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/input/seat.h" #include "sway/input/seat.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
@ -176,19 +178,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) { int height) {
struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view); struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view);
if (xwayland_view == NULL) { if (xwayland_view == NULL) {
return; return 0;
} }
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; 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); 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) { static void set_activated(struct sway_view *view, bool activated) {
@ -257,14 +258,6 @@ static void destroy(struct sway_view *view) {
if (xwayland_view == NULL) { if (xwayland_view == NULL) {
return; return;
} }
wl_list_remove(&xwayland_view->destroy.link);
wl_list_remove(&xwayland_view->request_configure.link);
wl_list_remove(&xwayland_view->request_fullscreen.link);
wl_list_remove(&xwayland_view->set_title.link);
wl_list_remove(&xwayland_view->set_class.link);
wl_list_remove(&xwayland_view->set_window_type.link);
wl_list_remove(&xwayland_view->map.link);
wl_list_remove(&xwayland_view->unmap.link);
free(xwayland_view); free(xwayland_view);
} }
@ -285,22 +278,27 @@ static void handle_commit(struct wl_listener *listener, void *data) {
wl_container_of(listener, xwayland_view, commit); wl_container_of(listener, xwayland_view, commit);
struct sway_view *view = &xwayland_view->view; struct sway_view *view = &xwayland_view->view;
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
if (view->swayc && container_is_floating(view->swayc)) { struct wlr_surface_state *surface_state = xsurface->surface->current;
view_update_size(view, xsurface->width, xsurface->height);
} else { if (view->swayc->instructions->length) {
view_update_size(view, xwayland_view->pending_width, transaction_notify_view_ready_by_size(view,
xwayland_view->pending_height); surface_state->width, surface_state->height);
} }
view_update_position(view,
xwayland_view->pending_lx, xwayland_view->pending_ly);
view_damage_from(view); view_damage_from(view);
} }
static void handle_unmap(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view = struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, unmap); wl_container_of(listener, xwayland_view, unmap);
struct sway_view *view = &xwayland_view->view;
if (!sway_assert(view->surface, "Cannot unmap unmapped view")) {
return;
}
view_unmap(view);
wl_list_remove(&xwayland_view->commit.link); wl_list_remove(&xwayland_view->commit.link);
view_unmap(&xwayland_view->view);
} }
static void handle_map(struct wl_listener *listener, void *data) { static void handle_map(struct wl_listener *listener, void *data) {
@ -322,12 +320,31 @@ static void handle_map(struct wl_listener *listener, void *data) {
if (xsurface->fullscreen) { if (xsurface->fullscreen) {
view_set_fullscreen(view, true); view_set_fullscreen(view, true);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} else {
arrange_and_commit(view->swayc->parent);
} }
} }
static void handle_destroy(struct wl_listener *listener, void *data) { static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view = struct sway_xwayland_view *xwayland_view =
wl_container_of(listener, xwayland_view, destroy); wl_container_of(listener, xwayland_view, destroy);
struct sway_view *view = &xwayland_view->view;
if (view->surface) {
view_unmap(view);
wl_list_remove(&xwayland_view->commit.link);
}
wl_list_remove(&xwayland_view->destroy.link);
wl_list_remove(&xwayland_view->request_configure.link);
wl_list_remove(&xwayland_view->request_fullscreen.link);
wl_list_remove(&xwayland_view->set_title.link);
wl_list_remove(&xwayland_view->set_class.link);
wl_list_remove(&xwayland_view->set_window_type.link);
wl_list_remove(&xwayland_view->map.link);
wl_list_remove(&xwayland_view->unmap.link);
view_destroy(&xwayland_view->view); view_destroy(&xwayland_view->view);
} }
@ -343,10 +360,12 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
return; return;
} }
if (container_is_floating(view->swayc)) { if (container_is_floating(view->swayc)) {
configure(view, view->x, view->y, ev->width, ev->height); configure(view, view->swayc->current.view_x,
view->swayc->current.view_y, ev->width, ev->height);
} else { } else {
configure(view, view->x, view->y, configure(view, view->swayc->current.view_x,
view->width, view->height); view->swayc->current.view_y, view->swayc->current.view_width,
view->swayc->current.view_height);
} }
} }
@ -359,6 +378,9 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return; return;
} }
view_set_fullscreen(view, xsurface->fullscreen); view_set_fullscreen(view, xsurface->fullscreen);
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
arrange_and_commit(ws);
} }
static void handle_set_title(struct wl_listener *listener, void *data) { static void handle_set_title(struct wl_listener *listener, void *data) {

View file

@ -830,6 +830,18 @@ struct sway_container *seat_get_active_child(struct sway_seat *seat,
return NULL; return NULL;
} }
struct sway_container *seat_get_active_current_child(struct sway_seat *seat,
struct sway_container *container) {
struct sway_container *child = seat_get_active_child(seat, container);
if (child) {
return child;
}
if (container->current.children->length == 1) {
return container->current.children->items[0];
}
return NULL;
}
struct sway_container *seat_get_focus(struct sway_seat *seat) { struct sway_container *seat_get_focus(struct sway_seat *seat) {
if (!seat->has_focus) { if (!seat->has_focus) {
return NULL; return NULL;

View file

@ -12,6 +12,7 @@ sway_sources = files(
'desktop/desktop.c', 'desktop/desktop.c',
'desktop/layer_shell.c', 'desktop/layer_shell.c',
'desktop/output.c', 'desktop/output.c',
'desktop/transaction.c',
'desktop/xdg_shell_v6.c', 'desktop/xdg_shell_v6.c',
'desktop/xdg_shell.c', 'desktop/xdg_shell.c',
'desktop/xwayland.c', 'desktop/xwayland.c',

View file

@ -19,6 +19,7 @@
#include <wlr/types/wlr_xdg_output.h> #include <wlr/types/wlr_xdg_output.h>
#include <wlr/util/log.h> #include <wlr/util/log.h>
// TODO WLR: make Xwayland optional // TODO WLR: make Xwayland optional
#include "list.h"
#include "sway/config.h" #include "sway/config.h"
#include "sway/input/input-manager.h" #include "sway/input/input-manager.h"
#include "sway/server.h" #include "sway/server.h"
@ -114,6 +115,14 @@ bool server_init(struct sway_server *server) {
return false; return false;
} }
const char *debug = getenv("SWAY_DEBUG");
if (debug != NULL && strcmp(debug, "txn_timings") == 0) {
server->debug_txn_timings = true;
}
server->destroying_containers = create_list();
server->transactions = create_list();
input_manager = input_manager_create(server); input_manager = input_manager_create(server);
return true; return true;
} }
@ -121,6 +130,8 @@ bool server_init(struct sway_server *server) {
void server_fini(struct sway_server *server) { void server_fini(struct sway_server *server) {
// TODO: free sway-specific resources // TODO: free sway-specific resources
wl_display_destroy(server->wl_display); wl_display_destroy(server->wl_display);
list_free(server->destroying_containers);
list_free(server->transactions);
} }
void server_run(struct sway_server *server) { void server_run(struct sway_server *server) {

View file

@ -5,7 +5,6 @@
#include <string.h> #include <string.h>
#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output_layout.h>
#include "sway/debug.h"
#include "sway/tree/arrange.h" #include "sway/tree/arrange.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
@ -17,7 +16,253 @@
struct sway_container root_container; struct sway_container root_container;
void arrange_root() { static void apply_horiz_layout(struct sway_container *parent) {
size_t num_children = parent->children->length;
if (!num_children) {
return;
}
size_t parent_offset = 0;
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;
}
size_t parent_height = parent->height - parent_offset;
// Calculate total width of children
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);
} else {
child->width = parent->width;
}
}
remove_gaps(child);
total_width += child->width;
}
double scale = parent->width / total_width;
// Resize windows
wlr_log(L_DEBUG, "Arranging %p horizontally", parent);
double child_x = parent->x;
for (size_t i = 0; i < num_children; ++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) {
child->width = parent->x + parent->width - child->x;
}
add_gaps(child);
}
}
static void apply_vert_layout(struct sway_container *parent) {
size_t num_children = parent->children->length;
if (!num_children) {
return;
}
size_t parent_offset = 0;
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;
}
size_t parent_height = parent->height + parent_offset;
// Calculate total height of children
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);
} else {
child->height = parent_height;
}
}
remove_gaps(child);
total_height += child->height;
}
double scale = parent_height / total_height;
// Resize
wlr_log(L_DEBUG, "Arranging %p vertically", parent);
double child_y = parent->y + parent_offset;
for (size_t i = 0; i < num_children; ++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) {
child->height =
parent->y + parent_offset + parent_height - child->y;
}
add_gaps(child);
}
}
static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
if (!parent->children->length) {
return;
}
size_t parent_offset = 0;
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;
}
size_t parent_height = parent->height - parent_offset;
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
remove_gaps(child);
child->x = parent->x;
child->y = parent->y + parent_offset;
child->width = parent->width;
child->height = parent_height;
add_gaps(child);
}
}
/**
* If a container has been deleted from the pending tree state, we must add it
* to the transaction so it can be freed afterwards. To do this, we iterate the
* server's destroying_containers list and add all of them. We may add more than
* what we need to, but this is easy and has no negative consequences.
*/
static void add_deleted_containers(struct sway_transaction *transaction) {
for (int i = 0; i < server.destroying_containers->length; ++i) {
struct sway_container *child = server.destroying_containers->items[i];
transaction_add_container(transaction, child);
}
}
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);
}
transaction_add_container(transaction, floating);
}
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);
// Calculate x, y, width and height of children
switch (parent->layout) {
case L_HORIZ:
apply_horiz_layout(parent);
break;
case L_VERT:
apply_vert_layout(parent);
break;
case L_TABBED:
case L_STACKED:
apply_tabbed_or_stacked_layout(parent);
break;
case L_NONE:
apply_horiz_layout(parent);
break;
case L_FLOATING:
arrange_floating(parent, transaction);
break;
}
// 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) {
child->has_gaps = true;
child->gaps_inner = parent->gaps_inner;
child->gaps_outer = parent->gaps_outer;
}
if (child->type == C_VIEW) {
view_autoconfigure(child->sway_view);
} else {
arrange_children_of(child, transaction);
}
transaction_add_container(transaction, 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);
}
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) { if (config->reloading) {
return; return;
} }
@ -29,64 +274,43 @@ void arrange_root() {
root_container.y = layout_box->y; root_container.y = layout_box->y;
root_container.width = layout_box->width; root_container.width = layout_box->width;
root_container.height = layout_box->height; root_container.height = layout_box->height;
transaction_add_container(transaction, &root_container);
for (int i = 0; i < root_container.children->length; ++i) { for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *output = root_container.children->items[i]; struct sway_container *output = root_container.children->items[i];
arrange_output(output); arrange_output(output, transaction);
} }
} }
void arrange_output(struct sway_container *output) { void arrange_windows(struct sway_container *container,
if (config->reloading) { struct sway_transaction *transaction) {
return; 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;
} }
if (!sway_assert(output->type == C_OUTPUT, add_deleted_containers(transaction);
"called arrange_output() on non-output container")) {
return;
} }
const struct wlr_box *output_box = wlr_output_layout_get_box( void arrange_and_commit(struct sway_container *container) {
root_container.sway_root->output_layout, struct sway_transaction *transaction = transaction_create();
output->sway_output->wlr_output); arrange_windows(container, transaction);
output->x = output_box->x; transaction_commit(transaction);
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) { void remove_gaps(struct sway_container *c) {
@ -126,211 +350,3 @@ void add_gaps(struct sway_container *c) {
wlr_log(L_DEBUG, "Adding gaps: %p", c); 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) {
return;
}
size_t parent_offset = 0;
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;
}
size_t parent_height = parent->height - parent_offset;
// Calculate total width of children
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);
} else {
child->width = parent->width;
}
}
remove_gaps(child);
total_width += child->width;
}
double scale = parent->width / total_width;
// 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];
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->height = parent_height;
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);
}
}
static void apply_vert_layout(struct sway_container *parent) {
size_t num_children = parent->children->length;
if (!num_children) {
return;
}
size_t parent_offset = 0;
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;
}
size_t parent_height = parent->height + parent_offset;
// Calculate total height of children
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);
} else {
child->height = parent_height;
}
}
remove_gaps(child);
total_height += child->height;
}
double scale = parent_height / total_height;
// 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];
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;
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_y += child->height;
add_gaps(child);
}
}
static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
if (!parent->children->length) {
return;
}
size_t parent_offset = 0;
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;
}
size_t parent_height = parent->height - parent_offset;
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
remove_gaps(child);
child->x = parent->x;
child->y = parent->y + parent_offset;
child->width = parent->width;
child->height = parent_height;
add_gaps(child);
}
}
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;
}
struct sway_container *workspace = parent;
if (workspace->type != C_WORKSPACE) {
workspace = container_parent(workspace, C_WORKSPACE);
}
if (workspace->sway_workspace->fullscreen) {
// Just arrange the fullscreen view and jump out
view_autoconfigure(workspace->sway_workspace->fullscreen);
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);
// Calculate x, y, width and height of children
switch (parent->layout) {
case L_HORIZ:
apply_horiz_layout(parent);
break;
case L_VERT:
apply_vert_layout(parent);
break;
case L_TABBED:
case L_STACKED:
apply_tabbed_or_stacked_layout(parent);
break;
default:
wlr_log(L_DEBUG, "TODO: arrange layout type %d", parent->layout);
apply_horiz_layout(parent);
break;
}
// Apply x, y, width and height to children and recurse if needed
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
if (parent->has_gaps && !child->has_gaps) {
child->has_gaps = true;
child->gaps_inner = parent->gaps_inner;
child->gaps_outer = parent->gaps_outer;
}
if (child->type == C_VIEW) {
view_autoconfigure(child->sway_view);
} else {
arrange_children_of(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);
}
}
}
container_damage_whole(parent);
update_debug_tree();
}

View file

@ -16,7 +16,6 @@
#include "sway/ipc-server.h" #include "sway/ipc-server.h"
#include "sway/output.h" #include "sway/output.h"
#include "sway/server.h" #include "sway/server.h"
#include "sway/tree/arrange.h"
#include "sway/tree/layout.h" #include "sway/tree/layout.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/tree/workspace.h" #include "sway/tree/workspace.h"
@ -113,9 +112,11 @@ struct sway_container *container_create(enum sway_container_type type) {
c->layout = L_NONE; c->layout = L_NONE;
c->type = type; c->type = type;
c->alpha = 1.0f; c->alpha = 1.0f;
c->instructions = create_list();
if (type != C_VIEW) { if (type != C_VIEW) {
c->children = create_list(); c->children = create_list();
c->current.children = create_list();
} }
wl_signal_init(&c->events.destroy); wl_signal_init(&c->events.destroy);
@ -132,42 +133,67 @@ struct sway_container *container_create(enum sway_container_type type) {
return c; return c;
} }
static void _container_destroy(struct sway_container *cont) { static void container_workspace_free(struct sway_workspace *ws) {
if (cont == NULL) { list_foreach(ws->output_priority, free);
list_free(ws->output_priority);
ws->floating->destroying = true;
container_free(ws->floating);
free(ws);
}
void container_free(struct sway_container *cont) {
if (!sway_assert(cont->destroying,
"Tried to free container which wasn't marked as destroying")) {
return; return;
} }
if (!sway_assert(cont->instructions->length == 0,
wl_signal_emit(&cont->events.destroy, cont); "Tried to free container with pending instructions")) {
return;
struct sway_container *parent = cont->parent;
if (cont->children != NULL && cont->children->length) {
// remove children until there are no more, container_destroy calls
// container_remove_child, which removes child from this container
while (cont->children != NULL && cont->children->length > 0) {
struct sway_container *child = cont->children->items[0];
ipc_event_window(child, "close");
container_remove_child(child);
_container_destroy(child);
} }
}
if (cont->marks) {
list_foreach(cont->marks, free);
list_free(cont->marks);
}
if (parent) {
parent = container_remove_child(cont);
}
if (cont->name) {
free(cont->name); free(cont->name);
}
wlr_texture_destroy(cont->title_focused); wlr_texture_destroy(cont->title_focused);
wlr_texture_destroy(cont->title_focused_inactive); wlr_texture_destroy(cont->title_focused_inactive);
wlr_texture_destroy(cont->title_unfocused); wlr_texture_destroy(cont->title_unfocused);
wlr_texture_destroy(cont->title_urgent); wlr_texture_destroy(cont->title_urgent);
for (int i = 0; i < server.destroying_containers->length; ++i) {
if (server.destroying_containers->items[i] == cont) {
list_del(server.destroying_containers, i);
break;
}
}
list_free(cont->instructions);
list_free(cont->children); list_free(cont->children);
cont->children = NULL; list_free(cont->current.children);
switch (cont->type) {
case C_ROOT:
break;
case C_OUTPUT:
break;
case C_WORKSPACE:
container_workspace_free(cont->sway_workspace);
break;
case C_CONTAINER:
break;
case C_VIEW:
{
struct sway_view *view = cont->sway_view;
view->swayc = NULL;
free(view->title_format);
view->title_format = NULL;
if (view->destroying) {
view_free(view);
}
}
break;
case C_TYPES:
sway_assert(false, "Didn't expect to see C_TYPES here");
break;
}
free(cont); free(cont);
} }
@ -184,7 +210,6 @@ static struct sway_container *container_workspace_destroy(
} }
wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name); wlr_log(L_DEBUG, "destroying workspace '%s'", workspace->name);
ipc_event_window(workspace, "close");
struct sway_container *parent = workspace->parent; struct sway_container *parent = workspace->parent;
if (!workspace_is_empty(workspace) && output) { if (!workspace_is_empty(workspace) && output) {
@ -209,24 +234,6 @@ static struct sway_container *container_workspace_destroy(
} }
} }
struct sway_workspace *sway_workspace = workspace->sway_workspace;
// This emits the destroy event and also destroys the swayc.
_container_destroy(workspace);
// Clean up the floating container
sway_workspace->floating->parent = NULL;
_container_destroy(sway_workspace->floating);
list_foreach(sway_workspace->output_priority, free);
list_free(sway_workspace->output_priority);
free(sway_workspace);
if (output) {
output_damage_whole(output->sway_output);
}
return parent; return parent;
} }
@ -263,11 +270,10 @@ static struct sway_container *container_output_destroy(
container_add_child(new_output, workspace); container_add_child(new_output, workspace);
ipc_event_workspace(workspace, NULL, "move"); ipc_event_workspace(workspace, NULL, "move");
} else { } else {
container_workspace_destroy(workspace); container_destroy(workspace);
} }
container_sort_workspaces(new_output); container_sort_workspaces(new_output);
arrange_output(new_output);
} }
} }
} }
@ -280,14 +286,48 @@ static struct sway_container *container_output_destroy(
wl_list_remove(&output->sway_output->damage_frame.link); wl_list_remove(&output->sway_output->damage_frame.link);
output->sway_output->swayc = NULL; output->sway_output->swayc = NULL;
output->sway_output = NULL;
wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name); wlr_log(L_DEBUG, "OUTPUT: Destroying output '%s'", output->name);
_container_destroy(output);
return &root_container; return &root_container;
} }
static void container_root_finish(struct sway_container *con) { /**
wlr_log(L_ERROR, "TODO: destroy the root container"); * Implement the actual destroy logic, without reaping.
*/
static struct sway_container *container_destroy_noreaping(
struct sway_container *con) {
if (con == NULL) {
return NULL;
}
if (con->destroying) {
return NULL;
}
wl_signal_emit(&con->events.destroy, con);
ipc_event_window(con, "close");
// The below functions move their children to somewhere else.
if (con->type == C_OUTPUT) {
container_output_destroy(con);
} else if (con->type == C_WORKSPACE) {
// Workspaces will refuse to be destroyed if they're the last workspace
// on their output.
if (!container_workspace_destroy(con)) {
wlr_log(L_ERROR, "workspace doesn't want to destroy");
return NULL;
}
}
con->destroying = true;
list_add(server.destroying_containers, con);
if (!con->parent) {
return NULL;
}
return container_remove_child(con);
} }
bool container_reap_empty(struct sway_container *con) { bool container_reap_empty(struct sway_container *con) {
@ -303,13 +343,13 @@ bool container_reap_empty(struct sway_container *con) {
case C_WORKSPACE: case C_WORKSPACE:
if (!workspace_is_visible(con) && workspace_is_empty(con)) { if (!workspace_is_visible(con) && workspace_is_empty(con)) {
wlr_log(L_DEBUG, "Destroying workspace via reaper"); wlr_log(L_DEBUG, "Destroying workspace via reaper");
container_workspace_destroy(con); container_destroy_noreaping(con);
return true; return true;
} }
break; break;
case C_CONTAINER: case C_CONTAINER:
if (con->children->length == 0) { if (con->children->length == 0) {
_container_destroy(con); container_destroy_noreaping(con);
return true; return true;
} }
case C_VIEW: case C_VIEW:
@ -340,52 +380,27 @@ struct sway_container *container_flatten(struct sway_container *container) {
struct sway_container *child = container->children->items[0]; struct sway_container *child = container->children->items[0];
struct sway_container *parent = container->parent; struct sway_container *parent = container->parent;
container_replace_child(container, child); container_replace_child(container, child);
container_destroy(container); container_destroy_noreaping(container);
container = parent; container = parent;
} }
return container; return container;
} }
/**
* container_destroy() is the first step in destroying a container. We'll emit
* events, detach it from the tree and mark it as destroying. The container will
* remain in memory until it's no longer used by a transaction, then it will be
* freed via container_free().
*
* This function just wraps container_destroy_noreaping(), then does reaping.
*/
struct sway_container *container_destroy(struct sway_container *con) { struct sway_container *container_destroy(struct sway_container *con) {
if (con == NULL) { struct sway_container *parent = container_destroy_noreaping(con);
if (!parent) {
return NULL; return NULL;
} }
struct sway_container *parent = con->parent;
switch (con->type) {
case C_ROOT:
container_root_finish(con);
break;
case C_OUTPUT:
// dont try to reap the root after this
container_output_destroy(con);
break;
case C_WORKSPACE:
// dont try to reap the output after this
container_workspace_destroy(con);
break;
case C_CONTAINER:
if (con->children->length) {
for (int i = 0; i < con->children->length; ++i) {
struct sway_container *child = con->children->items[0];
ipc_event_window(child, "close");
container_remove_child(child);
container_add_child(parent, child);
}
}
ipc_event_window(con, "close");
_container_destroy(con);
break;
case C_VIEW:
_container_destroy(con);
break;
case C_TYPES:
wlr_log(L_ERROR, "container_destroy called on an invalid "
"container");
break;
}
return container_reap_empty_recursive(parent); return container_reap_empty_recursive(parent);
} }
@ -753,9 +768,6 @@ static void update_title_texture(struct sway_container *con,
"Unexpected type %s", container_type_to_str(con->type))) { "Unexpected type %s", container_type_to_str(con->type))) {
return; return;
} }
if (!con->width) {
return;
}
struct sway_container *output = container_parent(con, C_OUTPUT); struct sway_container *output = container_parent(con, C_OUTPUT);
if (!output) { if (!output) {
return; return;
@ -917,13 +929,12 @@ void container_set_floating(struct sway_container *container, bool enable) {
struct sway_container *workspace = container_parent(container, C_WORKSPACE); struct sway_container *workspace = container_parent(container, C_WORKSPACE);
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
container_damage_whole(container);
if (enable) { if (enable) {
container_remove_child(container); container_remove_child(container);
container_add_child(workspace->sway_workspace->floating, container); container_add_child(workspace->sway_workspace->floating, container);
if (container->type == C_VIEW) { if (container->type == C_VIEW) {
view_autoconfigure(container->sway_view); view_init_floating(container->sway_view);
} }
seat_set_focus(seat, seat_get_focus_inactive(seat, container)); seat_set_focus(seat, seat_get_focus_inactive(seat, container));
container_reap_empty_recursive(workspace); container_reap_empty_recursive(workspace);
@ -939,8 +950,8 @@ void container_set_floating(struct sway_container *container, bool enable) {
container->is_sticky = false; container->is_sticky = false;
container_reap_empty_recursive(workspace->sway_workspace->floating); container_reap_empty_recursive(workspace->sway_workspace->floating);
} }
arrange_workspace(workspace);
container_damage_whole(container); ipc_event_window(container, "floating");
} }
void container_set_geometry_from_floating_view(struct sway_container *con) { void container_set_geometry_from_floating_view(struct sway_container *con) {
@ -969,3 +980,10 @@ bool container_is_floating(struct sway_container *container) {
} }
return container->parent == workspace->sway_workspace->floating; return container->parent == workspace->sway_workspace->floating;
} }
void container_get_box(struct sway_container *container, struct wlr_box *box) {
box->x = container->x;
box->y = container->y;
box->width = container->width;
box->height = container->height;
}

View file

@ -22,7 +22,7 @@ struct sway_container root_container;
static void output_layout_handle_change(struct wl_listener *listener, static void output_layout_handle_change(struct wl_listener *listener,
void *data) { void *data) {
arrange_root(); arrange_and_commit(&root_container);
} }
void layout_init(void) { void layout_init(void) {
@ -30,7 +30,9 @@ void layout_init(void) {
root_container.type = C_ROOT; root_container.type = C_ROOT;
root_container.layout = L_NONE; root_container.layout = L_NONE;
root_container.name = strdup("root"); root_container.name = strdup("root");
root_container.instructions = create_list();
root_container.children = create_list(); root_container.children = create_list();
root_container.current.children = create_list();
wl_signal_init(&root_container.events.destroy); wl_signal_init(&root_container.events.destroy);
root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); root_container.sway_root = calloc(1, sizeof(*root_container.sway_root));
@ -57,18 +59,17 @@ static int index_child(const struct sway_container *child) {
return -1; return -1;
} }
static void container_handle_fullscreen_reparent(struct sway_container *viewcon, static void container_handle_fullscreen_reparent(struct sway_container *con,
struct sway_container *old_parent) { struct sway_container *old_parent) {
if (viewcon->type != C_VIEW || !viewcon->sway_view->is_fullscreen) { if (con->type != C_VIEW || !con->sway_view->is_fullscreen) {
return; return;
} }
struct sway_view *view = viewcon->sway_view; struct sway_view *view = con->sway_view;
struct sway_container *old_workspace = old_parent; struct sway_container *old_workspace = old_parent;
if (old_workspace && old_workspace->type != C_WORKSPACE) { if (old_workspace && old_workspace->type != C_WORKSPACE) {
old_workspace = container_parent(old_workspace, C_WORKSPACE); old_workspace = container_parent(old_workspace, C_WORKSPACE);
} }
struct sway_container *new_workspace = container_parent(view->swayc, struct sway_container *new_workspace = container_parent(con, C_WORKSPACE);
C_WORKSPACE);
if (old_workspace == new_workspace) { if (old_workspace == new_workspace) {
return; return;
} }
@ -79,15 +80,19 @@ static void container_handle_fullscreen_reparent(struct sway_container *viewcon,
// Mark the new workspace as fullscreen // Mark the new workspace as fullscreen
if (new_workspace->sway_workspace->fullscreen) { if (new_workspace->sway_workspace->fullscreen) {
view_set_fullscreen_raw( view_set_fullscreen(new_workspace->sway_workspace->fullscreen, false);
new_workspace->sway_workspace->fullscreen, false);
} }
new_workspace->sway_workspace->fullscreen = view; new_workspace->sway_workspace->fullscreen = view;
// Resize view to new output dimensions // Resize view to new output dimensions
struct sway_container *output = new_workspace->parent; struct sway_container *output = new_workspace->parent;
view_configure(view, 0, 0, output->width, output->height); view->x = output->x;
view->swayc->width = output->width; view->y = output->y;
view->swayc->height = output->height; view->width = output->width;
view->height = output->height;
con->x = output->x;
con->y = output->y;
con->width = output->width;
con->height = output->height;
} }
void container_insert_child(struct sway_container *parent, void container_insert_child(struct sway_container *parent,
@ -189,18 +194,7 @@ void container_move_to(struct sway_container *container,
} }
container_notify_subtree_changed(old_parent); container_notify_subtree_changed(old_parent);
container_notify_subtree_changed(new_parent); container_notify_subtree_changed(new_parent);
if (old_parent) {
if (old_parent->type == C_OUTPUT) {
arrange_output(old_parent);
} else {
arrange_children_of(old_parent);
}
}
if (new_parent->type == C_OUTPUT) {
arrange_output(new_parent);
} else {
arrange_children_of(new_parent);
}
// If view was moved to a fullscreen workspace, refocus the fullscreen view // If view was moved to a fullscreen workspace, refocus the fullscreen view
struct sway_container *new_workspace = container; struct sway_container *new_workspace = container;
if (new_workspace->type != C_WORKSPACE) { if (new_workspace->type != C_WORKSPACE) {
@ -215,7 +209,8 @@ void container_move_to(struct sway_container *container,
if (focus_ws->type != C_WORKSPACE) { if (focus_ws->type != C_WORKSPACE) {
focus_ws = container_parent(focus_ws, C_WORKSPACE); focus_ws = container_parent(focus_ws, C_WORKSPACE);
} }
seat_set_focus(seat, new_workspace->sway_workspace->fullscreen->swayc); seat_set_focus(seat,
new_workspace->sway_workspace->fullscreen->swayc);
if (focus_ws != new_workspace) { if (focus_ws != new_workspace) {
seat_set_focus(seat, focus); seat_set_focus(seat, focus);
} }
@ -309,7 +304,6 @@ static void workspace_rejigger(struct sway_container *ws,
container_reap_empty_recursive(original_parent); container_reap_empty_recursive(original_parent);
wl_signal_emit(&child->events.reparent, original_parent); wl_signal_emit(&child->events.reparent, original_parent);
container_create_notify(new_parent); container_create_notify(new_parent);
arrange_workspace(ws);
} }
static void move_out_of_tabs_stacks(struct sway_container *container, static void move_out_of_tabs_stacks(struct sway_container *container,
@ -320,11 +314,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id); wlr_log(L_DEBUG, "Changing layout of %zd", current->parent->id);
current->parent->layout = move_dir == current->parent->layout = move_dir ==
MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT; MOVE_LEFT || move_dir == MOVE_RIGHT ? L_HORIZ : L_VERT;
if (current->parent->type == C_WORKSPACE) {
arrange_workspace(current->parent);
} else {
arrange_children_of(current->parent);
}
return; return;
} }
@ -340,11 +329,6 @@ static void move_out_of_tabs_stacks(struct sway_container *container,
container_flatten(new_parent->parent); container_flatten(new_parent->parent);
} }
container_create_notify(new_parent); container_create_notify(new_parent);
if (is_workspace) {
arrange_workspace(new_parent->parent);
} else {
arrange_children_of(new_parent);
}
container_notify_subtree_changed(new_parent); container_notify_subtree_changed(new_parent);
} }
@ -368,10 +352,7 @@ void container_move(struct sway_container *container,
struct sway_container *new_parent = container_flatten(parent); struct sway_container *new_parent = container_flatten(parent);
if (new_parent != parent) { if (new_parent != parent) {
// Special case: we were the last one in this container, so flatten it // Special case: we were the last one in this container, so leave
// and leave
arrange_children_of(new_parent);
update_debug_tree();
return; return;
} }
@ -453,12 +434,9 @@ void container_move(struct sway_container *container,
wlr_log(L_DEBUG, "Hit limit, " wlr_log(L_DEBUG, "Hit limit, "
"promoting descendant to sibling"); "promoting descendant to sibling");
// Special case // Special case
struct sway_container *old_parent = container->parent;
container_insert_child(current->parent, container, container_insert_child(current->parent, container,
index + (offs < 0 ? 0 : 1)); index + (offs < 0 ? 0 : 1));
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(current->parent);
arrange_children_of(old_parent);
return; return;
} }
} else { } else {
@ -492,14 +470,11 @@ void container_move(struct sway_container *container,
wlr_log(L_DEBUG, "Swapping siblings"); wlr_log(L_DEBUG, "Swapping siblings");
sibling->parent->children->items[index + offs] = container; sibling->parent->children->items[index + offs] = container;
sibling->parent->children->items[index] = sibling; sibling->parent->children->items[index] = sibling;
arrange_children_of(sibling->parent);
} else { } else {
wlr_log(L_DEBUG, "Promoting to sibling of cousin"); wlr_log(L_DEBUG, "Promoting to sibling of cousin");
container_insert_child(sibling->parent, container, container_insert_child(sibling->parent, container,
index_child(sibling) + (offs > 0 ? 0 : 1)); index_child(sibling) + (offs > 0 ? 0 : 1));
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(sibling->parent);
arrange_children_of(old_parent);
} }
sibling = NULL; sibling = NULL;
break; break;
@ -513,8 +488,6 @@ void container_move(struct sway_container *container,
"(move dir: %d)", limit, move_dir); "(move dir: %d)", limit, move_dir);
container_insert_child(sibling, container, limit); container_insert_child(sibling, container, limit);
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(sibling);
arrange_children_of(old_parent);
sibling = NULL; sibling = NULL;
} else { } else {
wlr_log(L_DEBUG, "Reparenting container (perpendicular)"); wlr_log(L_DEBUG, "Reparenting container (perpendicular)");
@ -538,8 +511,6 @@ void container_move(struct sway_container *container,
container_add_child(sibling, container); container_add_child(sibling, container);
} }
container->width = container->height = 0; container->width = container->height = 0;
arrange_children_of(sibling);
arrange_children_of(old_parent);
sibling = NULL; sibling = NULL;
} }
break; break;
@ -864,7 +835,6 @@ struct sway_container *container_split(struct sway_container *child,
// Special case: this just behaves like splitt // Special case: this just behaves like splitt
child->prev_layout = child->layout; child->prev_layout = child->layout;
child->layout = layout; child->layout = layout;
arrange_children_of(child);
return child; return child;
} }
@ -912,7 +882,6 @@ struct sway_container *container_split(struct sway_container *child,
} }
container_notify_subtree_changed(cont); container_notify_subtree_changed(cont);
arrange_children_of(cont);
return cont; return cont;
} }
@ -1050,9 +1019,6 @@ void container_swap(struct sway_container *con1, struct sway_container *con2) {
prev_workspace_name = stored_prev_name; prev_workspace_name = stored_prev_name;
} }
arrange_children_of(con1->parent);
arrange_children_of(con2->parent);
if (fs1 && con2->type == C_VIEW) { if (fs1 && con2->type == C_VIEW) {
view_set_fullscreen(con2->sway_view, true); view_set_fullscreen(con2->sway_view, true);
} }

View file

@ -26,12 +26,9 @@ static void restore_workspaces(struct sway_container *output) {
j--; j--;
} }
} }
arrange_output(other);
} }
container_sort_workspaces(output); container_sort_workspaces(output);
arrange_output(output);
} }
struct sway_container *output_create( struct sway_container *output_create(

View file

@ -28,20 +28,22 @@ void view_init(struct sway_view *view, enum sway_view_type type,
wl_signal_init(&view->events.unmap); wl_signal_init(&view->events.unmap);
} }
void view_destroy(struct sway_view *view) { void view_free(struct sway_view *view) {
if (view == NULL) { if (!sway_assert(view->surface == NULL, "Tried to free mapped view")) {
return; return;
} }
if (!sway_assert(view->destroying,
if (view->surface != NULL) { "Tried to free view which wasn't marked as destroying")) {
view_unmap(view); return;
}
if (!sway_assert(view->swayc == NULL,
"Tried to free view which still has a swayc "
"(might have a pending transaction?)")) {
return;
} }
list_free(view->executed_criteria); list_free(view->executed_criteria);
for (int i = 0; i < view->marks->length; ++i) { list_foreach(view->marks, free);
free(view->marks->items[i]);
}
list_free(view->marks); list_free(view->marks);
wlr_texture_destroy(view->marks_focused); wlr_texture_destroy(view->marks_focused);
@ -49,8 +51,6 @@ void view_destroy(struct sway_view *view) {
wlr_texture_destroy(view->marks_unfocused); wlr_texture_destroy(view->marks_unfocused);
wlr_texture_destroy(view->marks_urgent); wlr_texture_destroy(view->marks_urgent);
container_destroy(view->swayc);
if (view->impl->destroy) { if (view->impl->destroy) {
view->impl->destroy(view); view->impl->destroy(view);
} else { } else {
@ -58,6 +58,27 @@ void view_destroy(struct sway_view *view) {
} }
} }
/**
* The view may or may not be involved in a transaction. For example, a view may
* unmap then attempt to destroy itself before we've applied the new layout. If
* an unmapping view is still involved in a transaction then it'll still have a
* swayc.
*
* If there's no transaction we can simply free the view. Otherwise the
* destroying flag will make the view get freed when the transaction is
* finished.
*/
void view_destroy(struct sway_view *view) {
if (!sway_assert(view->surface == NULL, "Tried to destroy a mapped view")) {
return;
}
view->destroying = true;
if (!view->swayc) {
view_free(view);
}
}
const char *view_get_title(struct sway_view *view) { const char *view_get_title(struct sway_view *view) {
if (view->impl->get_string_prop) { if (view->impl->get_string_prop) {
return view->impl->get_string_prop(view, VIEW_PROP_TITLE); return view->impl->get_string_prop(view, VIEW_PROP_TITLE);
@ -119,32 +140,33 @@ const char *view_get_shell(struct sway_view *view) {
return "unknown"; 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) { int height) {
if (view->impl->configure) { 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); struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
int max_width = ws->width * 0.6666; int max_width = ws->width * 0.6666;
int max_height = ws->height * 0.6666; int max_height = ws->height * 0.6666;
int width = view->width =
view->natural_width > max_width ? max_width : view->natural_width; view->natural_width > max_width ? max_width : view->natural_width;
int height = view->height =
view->natural_height > max_height ? max_height : view->natural_height; view->natural_height > max_height ? max_height : view->natural_height;
int lx = ws->x + (ws->width - width) / 2; view->x = ws->x + (ws->width - view->width) / 2;
int ly = ws->y + (ws->height - height) / 2; view->y = ws->y + (ws->height - view->height) / 2;
// If the view's border is B_NONE then these properties are ignored. // If the view's border is B_NONE then these properties are ignored.
view->border_top = view->border_bottom = true; view->border_top = view->border_bottom = true;
view->border_left = view->border_right = true; view->border_left = view->border_right = true;
container_set_geometry_from_floating_view(view->swayc);
// Don't maximize floating windows // Don't maximize floating windows
view_set_tiled(view, false); view_set_tiled(view, false);
view_configure(view, lx, ly, width, height);
} }
void view_autoconfigure(struct sway_view *view) { void view_autoconfigure(struct sway_view *view) {
@ -156,12 +178,14 @@ void view_autoconfigure(struct sway_view *view) {
struct sway_container *output = container_parent(view->swayc, C_OUTPUT); struct sway_container *output = container_parent(view->swayc, C_OUTPUT);
if (view->is_fullscreen) { if (view->is_fullscreen) {
view_configure(view, output->x, output->y, output->width, output->height); view->x = output->x;
view->y = output->y;
view->width = output->width;
view->height = output->height;
return; return;
} }
if (container_is_floating(view->swayc)) { if (container_is_floating(view->swayc)) {
view_autoconfigure_floating(view);
return; return;
} }
@ -181,20 +205,22 @@ void view_autoconfigure(struct sway_view *view) {
} }
} }
struct sway_container *con = view->swayc;
view->border_top = view->border_bottom = true; view->border_top = view->border_bottom = true;
view->border_left = view->border_right = true; view->border_left = view->border_right = true;
if (config->hide_edge_borders == E_BOTH if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_VERTICAL || config->hide_edge_borders == E_VERTICAL
|| (config->hide_edge_borders == E_SMART && !other_views)) { || (config->hide_edge_borders == E_SMART && !other_views)) {
view->border_left = view->swayc->x != ws->x; view->border_left = con->x != ws->x;
int right_x = view->swayc->x + view->swayc->width; int right_x = con->x + con->width;
view->border_right = right_x != ws->x + ws->width; view->border_right = right_x != ws->x + ws->width;
} }
if (config->hide_edge_borders == E_BOTH if (config->hide_edge_borders == E_BOTH
|| config->hide_edge_borders == E_HORIZONTAL || config->hide_edge_borders == E_HORIZONTAL
|| (config->hide_edge_borders == E_SMART && !other_views)) { || (config->hide_edge_borders == E_SMART && !other_views)) {
view->border_top = view->swayc->y != ws->y; view->border_top = con->y != ws->y;
int bottom_y = view->swayc->y + view->swayc->height; int bottom_y = con->y + con->height;
view->border_bottom = bottom_y != ws->y + ws->height; view->border_bottom = bottom_y != ws->y + ws->height;
} }
@ -205,45 +231,44 @@ void view_autoconfigure(struct sway_view *view) {
// In a tabbed or stacked container, the swayc's y is the top of the title // 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 // 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. // 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(); y_offset = container_titlebar_height();
view->border_top = false; view->border_top = false;
} else if (view->swayc->parent->layout == L_STACKED) { } else if (con->parent->layout == L_STACKED) {
y_offset = container_titlebar_height() y_offset = container_titlebar_height() * con->parent->children->length;
* view->swayc->parent->children->length;
view->border_top = false; view->border_top = false;
} }
switch (view->border) { switch (view->border) {
case B_NONE: case B_NONE:
x = view->swayc->x; x = con->x;
y = view->swayc->y + y_offset; y = con->y + y_offset;
width = view->swayc->width; width = con->width;
height = view->swayc->height - y_offset; height = con->height - y_offset;
break; break;
case B_PIXEL: case B_PIXEL:
x = view->swayc->x + view->border_thickness * view->border_left; x = con->x + view->border_thickness * view->border_left;
y = view->swayc->y + view->border_thickness * view->border_top + y_offset; y = con->y + view->border_thickness * view->border_top + y_offset;
width = view->swayc->width width = con->width
- view->border_thickness * view->border_left - view->border_thickness * view->border_left
- view->border_thickness * view->border_right; - 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_top
- view->border_thickness * view->border_bottom; - view->border_thickness * view->border_bottom;
break; break;
case B_NORMAL: case B_NORMAL:
// Height is: 1px border + 3px pad + title height + 3px pad + 1px border // Height is: 1px border + 3px pad + title height + 3px pad + 1px border
x = view->swayc->x + view->border_thickness * view->border_left; x = con->x + view->border_thickness * view->border_left;
width = view->swayc->width width = con->width
- view->border_thickness * view->border_left - view->border_thickness * view->border_left
- view->border_thickness * view->border_right; - view->border_thickness * view->border_right;
if (y_offset) { if (y_offset) {
y = view->swayc->y + y_offset; y = con->y + y_offset;
height = view->swayc->height - y_offset height = con->height - y_offset
- view->border_thickness * view->border_bottom; - view->border_thickness * view->border_bottom;
} else { } else {
y = view->swayc->y + container_titlebar_height(); y = con->y + container_titlebar_height();
height = view->swayc->height - container_titlebar_height() height = con->height - container_titlebar_height()
- view->border_thickness * view->border_bottom; - view->border_thickness * view->border_bottom;
} }
break; break;
@ -251,8 +276,9 @@ void view_autoconfigure(struct sway_view *view) {
view->x = x; view->x = x;
view->y = y; view->y = y;
view->width = width;
view->height = height;
view_set_tiled(view, true); view_set_tiled(view, true);
view_configure(view, x, y, width, height);
} }
void view_set_activated(struct sway_view *view, bool activated) { void view_set_activated(struct sway_view *view, bool activated) {
@ -268,8 +294,7 @@ void view_set_tiled(struct sway_view *view, bool tiled) {
} }
} }
// Set fullscreen, but without IPC events or arranging windows. void view_set_fullscreen(struct sway_view *view, bool fullscreen) {
void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
if (view->is_fullscreen == fullscreen) { if (view->is_fullscreen == fullscreen) {
return; return;
} }
@ -315,27 +340,17 @@ void view_set_fullscreen_raw(struct sway_view *view, bool fullscreen) {
} else { } else {
workspace->sway_workspace->fullscreen = NULL; workspace->sway_workspace->fullscreen = NULL;
if (container_is_floating(view->swayc)) { if (container_is_floating(view->swayc)) {
view_configure(view, view->saved_x, view->saved_y, view->x = view->saved_x;
view->saved_width, view->saved_height); view->y = view->saved_y;
view->width = view->saved_width;
view->height = view->saved_height;
container_set_geometry_from_floating_view(view->swayc);
} else { } else {
view->swayc->width = view->swayc->saved_width; view->swayc->width = view->swayc->saved_width;
view->swayc->height = view->swayc->saved_height; view->swayc->height = view->swayc->saved_height;
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"); ipc_event_window(view->swayc, "fullscreen_mode");
} }
@ -365,6 +380,9 @@ static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) {
void view_for_each_surface(struct sway_view *view, void view_for_each_surface(struct sway_view *view,
wlr_surface_iterator_func_t iterator, void *user_data) { wlr_surface_iterator_func_t iterator, void *user_data) {
if (!view->surface) {
return;
}
if (view->impl->for_each_surface) { if (view->impl->for_each_surface) {
view->impl->for_each_surface(view, iterator, user_data); view->impl->for_each_surface(view, iterator, user_data);
} else { } else {
@ -518,8 +536,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
if (view->impl->wants_floating && view->impl->wants_floating(view)) { if (view->impl->wants_floating && view->impl->wants_floating(view)) {
container_set_floating(view->swayc, true); container_set_floating(view->swayc, true);
} else {
arrange_children_of(cont->parent);
} }
input_manager_set_focus(input_manager, cont); input_manager_set_focus(input_manager, cont);
@ -531,42 +547,26 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
container_notify_subtree_changed(view->swayc->parent); container_notify_subtree_changed(view->swayc->parent);
view_execute_criteria(view); view_execute_criteria(view);
container_damage_whole(cont);
view_handle_container_reparent(&view->container_reparent, NULL); view_handle_container_reparent(&view->container_reparent, NULL);
} }
void view_unmap(struct sway_view *view) { void view_unmap(struct sway_view *view) {
if (!sway_assert(view->surface != NULL, "cannot unmap unmapped view")) {
return;
}
wl_signal_emit(&view->events.unmap, view); wl_signal_emit(&view->events.unmap, view);
if (view->is_fullscreen) {
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
ws->sway_workspace->fullscreen = NULL;
}
container_damage_whole(view->swayc);
wl_list_remove(&view->surface_new_subsurface.link); wl_list_remove(&view->surface_new_subsurface.link);
wl_list_remove(&view->container_reparent.link); wl_list_remove(&view->container_reparent.link);
struct sway_container *parent = container_destroy(view->swayc); if (view->is_fullscreen) {
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
ws->sway_workspace->fullscreen = NULL;
container_destroy(view->swayc);
view->swayc = NULL; arrange_and_commit(ws->parent);
view->surface = NULL;
if (view->title_format) {
free(view->title_format);
view->title_format = NULL;
}
if (parent->type == C_OUTPUT) {
arrange_output(parent);
} else { } else {
arrange_children_of(parent); struct sway_container *parent = container_destroy(view->swayc);
arrange_and_commit(parent);
} }
view->surface = NULL;
} }
void view_update_position(struct sway_view *view, double lx, double ly) { void view_update_position(struct sway_view *view, double lx, double ly) {
@ -940,7 +940,7 @@ void view_update_marks_textures(struct sway_view *view) {
} }
bool view_is_visible(struct sway_view *view) { bool view_is_visible(struct sway_view *view) {
if (!view->swayc) { if (!view->swayc || view->swayc->destroying) {
return false; return false;
} }
struct sway_container *workspace = struct sway_container *workspace =

View file

@ -425,11 +425,14 @@ bool workspace_switch(struct sway_container *workspace) {
} }
seat_set_focus(seat, next); seat_set_focus(seat, next);
struct sway_container *output = container_parent(workspace, C_OUTPUT); struct sway_container *output = container_parent(workspace, C_OUTPUT);
arrange_output(output); arrange_and_commit(output);
return true; return true;
} }
bool workspace_is_visible(struct sway_container *ws) { bool workspace_is_visible(struct sway_container *ws) {
if (ws->destroying) {
return false;
}
struct sway_container *output = container_parent(ws, C_OUTPUT); struct sway_container *output = container_parent(ws, C_OUTPUT);
struct sway_seat *seat = input_manager_current_seat(input_manager); struct sway_seat *seat = input_manager_current_seat(input_manager);
struct sway_container *focus = seat_get_focus_inactive(seat, output); struct sway_container *focus = seat_get_focus_inactive(seat, output);