Implement atomic layout updates for tree operations

This implements atomic layout updates for when views map, reparent or
unmap.
This commit is contained in:
Ryan Dwyer 2018-06-23 16:24:11 +10:00
parent 1c89f32533
commit 38398e2d77
18 changed files with 545 additions and 389 deletions

View file

@ -1,5 +1,6 @@
#ifndef _SWAY_TRANSACTION_H #ifndef _SWAY_TRANSACTION_H
#define _SWAY_TRANSACTION_H #define _SWAY_TRANSACTION_H
#include <wlr/render/wlr_texture.h>
#include "sway/tree/container.h" #include "sway/tree/container.h"
/** /**
@ -48,4 +49,12 @@ void transaction_commit(struct sway_transaction *transaction);
*/ */
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial); void transaction_notify_view_ready(struct sway_view *view, uint32_t serial);
/**
* Get the texture that should be rendered for a view.
*
* In most cases this will return the normal live texture for a view, but if the
* view is in a transaction then it'll return a saved texture.
*/
struct wlr_texture *transaction_get_texture(struct sway_view *view);
#endif #endif

View file

@ -12,6 +12,7 @@
#include <wlr/render/wlr_renderer.h> #include <wlr/render/wlr_renderer.h>
// TODO WLR: make Xwayland optional // TODO WLR: make Xwayland optional
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#include "list.h"
struct sway_server { struct sway_server {
struct wl_display *wl_display; struct wl_display *wl_display;
@ -43,6 +44,12 @@ struct sway_server {
struct wlr_wl_shell *wl_shell; struct wlr_wl_shell *wl_shell;
struct wl_listener wl_shell_surface; struct wl_listener wl_shell_surface;
bool terminating;
// 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

@ -65,8 +65,8 @@ struct sway_container_state {
double gaps_inner; double gaps_inner;
double gaps_outer; double gaps_outer;
//struct sway_container *parent; struct sway_container *parent;
//list_t *children; list_t *children;
// View properties // View properties
double view_x, view_y; double view_x, view_y;
@ -79,6 +79,10 @@ struct sway_container_state {
bool border_bottom; bool border_bottom;
bool border_left; bool border_left;
bool border_right; bool border_right;
// Workspace properties
struct sway_view *ws_fullscreen;
struct sway_container *ws_floating;
}; };
struct sway_container { struct sway_container {
@ -128,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;
@ -138,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
@ -181,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);

View file

@ -37,7 +37,7 @@ struct sway_view_impl {
void (*for_each_surface)(struct sway_view *view, void (*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);
void (*close)(struct sway_view *view); void (*close)(struct sway_view *view);
void (*destroy)(struct sway_view *view); void (*free)(struct sway_view *view);
}; };
struct sway_view { struct sway_view {
@ -68,15 +68,10 @@ 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 *
list_t *instructions; // struct sway_transaction_instruction *
// If saved_buffer is set, the main surface of the view will render this
// buffer/texture instead of its own. This is used while waiting for
// transactions to complete.
struct wlr_buffer *saved_buffer;
int saved_surface_width, saved_surface_height;
struct wlr_texture *marks_focused; struct wlr_texture *marks_focused;
struct wlr_texture *marks_focused_inactive; struct wlr_texture *marks_focused_inactive;
@ -244,11 +239,16 @@ 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);
void view_unmap(struct sway_view *view); /**
* Unmap the view and return the surviving parent (after reaping).
*/
struct sway_container *view_unmap(struct sway_view *view);
void view_update_position(struct sway_view *view, double lx, double ly); void view_update_position(struct sway_view *view, double lx, double ly);

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_and_commit(parent); arrange_and_commit(parent->parent);
return cmd_results_new(CMD_SUCCESS, NULL, NULL); return cmd_results_new(CMD_SUCCESS, NULL, NULL);
} }

View file

@ -102,40 +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;
return wlr_box_intersection(&output_box, &rotated_box, &intersection);
}
static bool get_view_box(struct root_geometry *geo,
struct sway_output *output, struct sway_view *view, int sx, int sy,
struct wlr_box *surface_box) {
int sw = view->saved_surface_width;
int sh = view->saved_surface_height;
double _sx = sx, _sy = sy;
rotate_child_position(&_sx, &_sy, sw, sh, geo->width, geo->height,
geo->rotation);
struct wlr_box box = {
.x = geo->x + _sx,
.y = geo->y + _sy,
.width = sw,
.height = sh,
};
if (surface_box != NULL) {
memcpy(surface_box, &box, sizeof(struct wlr_box));
}
struct wlr_box rotated_box;
wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box);
struct wlr_box output_box = {
.width = output->swayc->width,
.height = output->swayc->height,
}; };
struct wlr_box intersection; struct wlr_box intersection;
@ -158,8 +126,8 @@ 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->swayc->current.view_x - data->output->swayc->x; geo->x = view->swayc->current.view_x - data->output->swayc->current.swayc_x;
geo->y = view->swayc->current.view_y - data->output->swayc->y; geo->y = view->swayc->current.view_y - data->output->swayc->current.swayc_y;
geo->width = view->swayc->current.view_width; geo->width = view->swayc->current.view_width;
geo->height = view->swayc->current.view_height; geo->height = view->swayc->current.view_height;
geo->rotation = 0; // TODO geo->rotation = 0; // TODO
@ -187,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);
@ -274,26 +242,14 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
pixman_region32_t *output_damage = data->damage; pixman_region32_t *output_damage = data->damage;
float alpha = data->alpha; float alpha = data->alpha;
struct wlr_texture *texture = NULL; struct wlr_texture *texture = wlr_surface_get_texture(surface);
struct wlr_box box; if (!texture) {
bool intersects;
// If this is the main surface of a view, render the saved_buffer instead
// if it exists. It exists when we are mid-transaction.
if (data->view && data->view->saved_buffer &&
data->view->surface == surface) {
texture = data->view->saved_buffer->texture;
intersects = get_view_box(&data->root_geo, data->output, data->view,
sx, sy, &box);
} else {
texture = wlr_surface_get_texture(surface);
if (texture == NULL) {
return; return;
} }
intersects = get_surface_box(&data->root_geo, data->output, surface,
sx, sy, &box);
}
struct wlr_box box;
bool intersects = get_surface_box(&data->root_geo, data->output, surface,
sx, sy, &box);
if (!intersects) { if (!intersects) {
return; return;
} }
@ -394,58 +350,98 @@ static void render_view_surfaces(struct sway_view *view,
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;
struct wlr_texture *texture = transaction_get_texture(view);
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 = view->swayc->current.view_width,
.height = view->swayc->current.view_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 (con->current.border != B_NONE) { if (state->border != B_NONE) {
if (con->current.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->current.swayc_x; box.x = state->swayc_x;
box.y = con->current.view_y; box.y = state->view_y;
box.width = con->current.border_thickness; box.width = state->border_thickness;
box.height = con->current.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 (con->current.border_right) { if (state->border_right) {
if (con->parent->children->length == 1 if (state->parent->current.children->length == 1
&& con->parent->current.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 = con->current.view_x + con->current.view_width; box.x = state->view_x + state->view_width;
box.y = con->current.view_y; box.y = state->view_y;
box.width = con->current.border_thickness; box.width = state->border_thickness;
box.height = con->current.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 (con->current.border_bottom) { if (state->border_bottom) {
if (con->parent->children->length == 1 if (state->parent->current.children->length == 1
&& con->parent->current.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->current.swayc_x; box.x = state->swayc_x;
box.y = con->current.view_y + con->current.view_height; box.y = state->view_y + state->view_height;
box.width = con->current.swayc_width; box.width = state->swayc_width;
box.height = con->current.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);
} }
@ -469,10 +465,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_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->current.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);
@ -490,10 +489,8 @@ static void render_titlebar(struct sway_output *output,
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 (con->type == C_VIEW) { if (con->type == C_VIEW) {
left_offset = left_offset = state->border_left * state->border_thickness;
con->current.border_left * con->current.border_thickness; right_offset = state->border_right * state->border_thickness;
right_offset =
con->current.border_right * con->current.border_thickness;
connects_sides = true; connects_sides = true;
} }
} }
@ -527,10 +524,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,
@ -551,10 +547,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,
@ -614,16 +608,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 = con->current.border_thickness * con->current.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 - box.x = x + width - state->border_thickness * state->border_right;
con->current.border_thickness * con->current.border_right;
box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS; box.y = y + container_titlebar_height() - TITLEBAR_BORDER_THICKNESS;
box.width = con->current.border_thickness * con->current.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);
@ -636,7 +629,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) {
if (!con->current.border_top) { struct sway_container_state *state = &con->current;
if (!state->border_top) {
return; return;
} }
struct wlr_box box; struct wlr_box box;
@ -646,10 +640,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->current.swayc_x; box.x = state->swayc_x;
box.y = con->current.swayc_y; box.y = state->swayc_y;
box.width = con->current.swayc_width; box.width = state->swayc_width;
box.height = con->current.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);
} }
@ -669,31 +663,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->current.border == B_NORMAL) { if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, child->current.swayc_x, render_titlebar(output, damage, child, state->swayc_x,
child->current.swayc_y, child->current.swayc_width, state->swayc_y, state->swayc_width, colors,
colors, title_texture, marks_texture); title_texture, marks_texture);
} else { } else {
render_top_border(output, damage, child, colors); render_top_border(output, damage, child, colors);
} }
@ -711,22 +708,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_child(seat, con);
struct border_colors *current_colors = NULL; struct border_colors *current_colors = NULL;
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) { if (focus == child || parent_focused) {
colors = &config->border_colors.focused; colors = &config->border_colors.focused;
@ -735,22 +733,22 @@ static void render_container_tabbed(struct sway_output *output,
} else if (child == current) { } else if (child == current) {
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 = view ? view->marks_focused : NULL; marks_texture = view ? view->marks_focused_inactive : NULL;
} else { } else {
colors = &config->border_colors.unfocused; colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused; title_texture = child->title_unfocused;
marks_texture = view ? view->marks_unfocused : NULL; marks_texture = view ? view->marks_unfocused : NULL;
} }
int tab_width = con->current.swayc_width / con->children->length; int tab_width = pstate->swayc_width / pstate->children->length;
int x = con->current.swayc_x + tab_width * i; int x = pstate->swayc_x + tab_width * i;
// Make last tab use the remaining width of the parent // Make last tab use the remaining width of the parent
if (i == con->children->length - 1) { if (i == pstate->children->length - 1) {
tab_width = con->current.swayc_width - tab_width * i; tab_width = pstate->swayc_width - tab_width * i;
} }
render_titlebar(output, damage, child, x, child->current.swayc_y, render_titlebar(output, damage, child, x, cstate->swayc_y, tab_width,
tab_width, colors, title_texture, marks_texture); colors, title_texture, marks_texture);
if (child == current) { if (child == current) {
current_colors = colors; current_colors = colors;
@ -772,22 +770,23 @@ static void render_container_tabbed(struct sway_output *output,
static void render_container_stacked(struct sway_output *output, static void render_container_stacked(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_child(seat, con);
struct border_colors *current_colors = NULL; struct border_colors *current_colors = NULL;
struct sway_container_state *pstate = &con->current;
// Render titles // Render titles
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) { if (focus == child || parent_focused) {
colors = &config->border_colors.focused; colors = &config->border_colors.focused;
@ -803,10 +802,9 @@ 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->current.swayc_y + container_titlebar_height() * i; int y = pstate->swayc_y + container_titlebar_height() * i;
render_titlebar(output, damage, child, child->current.swayc_x, y, render_titlebar(output, damage, child, cstate->swayc_x, y,
child->current.swayc_width, colors, cstate->swayc_width, colors, title_texture, marks_texture);
title_texture, marks_texture);
if (child == current) { if (child == current) {
current_colors = colors; current_colors = colors;
@ -877,17 +875,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);
} }
} }
@ -901,7 +900,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) {
@ -942,8 +941,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;
@ -954,10 +954,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);
} }
@ -1073,11 +1072,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);
} }

View file

@ -9,6 +9,7 @@
#include "sway/output.h" #include "sway/output.h"
#include "sway/tree/container.h" #include "sway/tree/container.h"
#include "sway/tree/view.h" #include "sway/tree/view.h"
#include "sway/tree/workspace.h"
#include "list.h" #include "list.h"
#include "log.h" #include "log.h"
@ -18,6 +19,13 @@
*/ */
#define TIMEOUT_MS 200 #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 sway_transaction {
struct wl_event_source *timer; struct wl_event_source *timer;
list_t *instructions; // struct sway_transaction_instruction * list_t *instructions; // struct sway_transaction_instruction *
@ -29,7 +37,9 @@ struct sway_transaction_instruction {
struct sway_transaction *transaction; struct sway_transaction *transaction;
struct sway_container *container; struct sway_container *container;
struct sway_container_state state; struct sway_container_state state;
struct wlr_buffer *saved_buffer;
uint32_t serial; uint32_t serial;
bool ready;
}; };
struct sway_transaction *transaction_create() { struct sway_transaction *transaction_create() {
@ -40,44 +50,55 @@ struct sway_transaction *transaction_create() {
return transaction; 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)) {
wlr_buffer_ref(view->surface->buffer);
instruction->saved_buffer = view->surface->buffer;
}
}
static void transaction_destroy(struct sway_transaction *transaction) { static void transaction_destroy(struct sway_transaction *transaction) {
int i;
// Free instructions // Free instructions
for (i = 0; i < transaction->instructions->length; ++i) { for (int i = 0; i < transaction->instructions->length; ++i) {
struct sway_transaction_instruction *instruction = struct sway_transaction_instruction *instruction =
transaction->instructions->items[i]; transaction->instructions->items[i];
if (instruction->container->type == C_VIEW) { struct sway_container *con = instruction->container;
struct sway_view *view = instruction->container->sway_view; for (int j = 0; j < con->instructions->length; ++j) {
for (int j = 0; j < view->instructions->length; ++j) { if (con->instructions->items[j] == instruction) {
if (view->instructions->items[j] == instruction) { list_del(con->instructions, j);
list_del(view->instructions, j);
break; break;
} }
} }
if (con->destroying && !con->instructions->length) {
container_free(con);
} }
remove_saved_view_buffer(instruction);
free(instruction); free(instruction);
} }
list_free(transaction->instructions); list_free(transaction->instructions);
// Free damage // Free damage
for (i = 0; i < transaction->damage->length; ++i) { list_foreach(transaction->damage, free);
struct wlr_box *box = transaction->damage->items[i];
free(box);
}
list_free(transaction->damage); list_free(transaction->damage);
free(transaction); free(transaction);
} }
void transaction_add_container(struct sway_transaction *transaction, static void copy_pending_state(struct sway_container *container,
struct sway_container *container) { struct sway_container_state *state) {
struct sway_transaction_instruction *instruction =
calloc(1, sizeof(struct sway_transaction_instruction));
instruction->transaction = transaction;
instruction->container = container;
// Copy the container's main (pending) properties into the instruction state
struct sway_container_state *state = &instruction->state;
state->layout = container->layout; state->layout = container->layout;
state->swayc_x = container->x; state->swayc_x = container->x;
state->swayc_y = container->y; state->swayc_y = container->y;
@ -87,6 +108,7 @@ void transaction_add_container(struct sway_transaction *transaction,
state->current_gaps = container->current_gaps; state->current_gaps = container->current_gaps;
state->gaps_inner = container->gaps_inner; state->gaps_inner = container->gaps_inner;
state->gaps_outer = container->gaps_outer; state->gaps_outer = container->gaps_outer;
state->parent = container->parent;
if (container->type == C_VIEW) { if (container->type == C_VIEW) {
struct sway_view *view = container->sway_view; struct sway_view *view = container->sway_view;
@ -101,8 +123,44 @@ void transaction_add_container(struct sway_transaction *transaction,
state->border_left = view->border_left; state->border_left = view->border_left;
state->border_right = view->border_right; state->border_right = view->border_right;
state->border_bottom = view->border_bottom; 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); list_add(transaction->instructions, instruction);
} }
@ -113,47 +171,29 @@ void transaction_add_damage(struct sway_transaction *transaction,
list_add(transaction->damage, box); list_add(transaction->damage, box);
} }
static void save_view_buffer(struct sway_view *view) {
if (view->saved_buffer) {
wlr_buffer_unref(view->saved_buffer);
}
wlr_buffer_ref(view->surface->buffer);
view->saved_buffer = view->surface->buffer;
view->saved_surface_width = view->surface->current->width;
view->saved_surface_height = view->surface->current->height;
}
static void remove_saved_view_buffer(struct sway_view *view) {
if (view->saved_buffer) {
wlr_buffer_unref(view->saved_buffer);
view->saved_buffer = NULL;
view->saved_surface_width = 0;
view->saved_surface_height = 0;
}
}
/** /**
* Apply a transaction to the "current" state of the tree. * Apply a transaction to the "current" state of the tree.
*
* This is mostly copying stuff from the pending state into the main swayc
* properties, but also includes reparenting and deleting containers.
*/ */
static void transaction_apply(struct sway_transaction *transaction) { static void transaction_apply(struct sway_transaction *transaction) {
int i; int i;
// Apply the instruction state to the container's current state
for (i = 0; i < transaction->instructions->length; ++i) { for (i = 0; i < transaction->instructions->length; ++i) {
struct sway_transaction_instruction *instruction = struct sway_transaction_instruction *instruction =
transaction->instructions->items[i]; transaction->instructions->items[i];
struct sway_container *container = instruction->container; struct sway_container *container = instruction->container;
memcpy(&instruction->container->current, &instruction->state, // 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)); sizeof(struct sway_container_state));
if (container->type == C_VIEW) {
remove_saved_view_buffer(container->sway_view);
}
} }
// Damage // Apply damage
for (i = 0; i < transaction->damage->length; ++i) { for (i = 0; i < transaction->damage->length; ++i) {
struct wlr_box *box = transaction->damage->items[i]; struct wlr_box *box = transaction->damage->items[i];
for (int j = 0; j < root_container.children->length; ++j) { for (int j = 0; j < root_container.children->length; ++j) {
@ -161,8 +201,6 @@ static void transaction_apply(struct sway_transaction *transaction) {
output_damage_box(output->sway_output, box); output_damage_box(output->sway_output, box);
} }
} }
update_debug_tree();
} }
static int handle_timeout(void *data) { static int handle_timeout(void *data) {
@ -182,7 +220,7 @@ void transaction_commit(struct sway_transaction *transaction) {
struct sway_transaction_instruction *instruction = struct sway_transaction_instruction *instruction =
transaction->instructions->items[i]; transaction->instructions->items[i];
struct sway_container *con = instruction->container; struct sway_container *con = instruction->container;
if (con->type == C_VIEW && if (con->type == C_VIEW && !con->destroying &&
(con->current.view_width != instruction->state.view_width || (con->current.view_width != instruction->state.view_width ||
con->current.view_height != instruction->state.view_height)) { con->current.view_height != instruction->state.view_height)) {
instruction->serial = view_configure(con->sway_view, instruction->serial = view_configure(con->sway_view,
@ -191,14 +229,12 @@ void transaction_commit(struct sway_transaction *transaction) {
instruction->state.view_width, instruction->state.view_width,
instruction->state.view_height); instruction->state.view_height);
if (instruction->serial) { if (instruction->serial) {
save_view_buffer(con->sway_view);
list_add(con->sway_view->instructions, instruction);
++transaction->num_waiting; ++transaction->num_waiting;
} }
} }
list_add(con->instructions, instruction);
} }
if (!transaction->num_waiting) { if (!transaction->num_waiting) {
// This can happen if the transaction only contains xwayland views
wlr_log(L_DEBUG, "Transaction %p has nothing to wait for, applying", wlr_log(L_DEBUG, "Transaction %p has nothing to wait for, applying",
transaction); transaction);
transaction_apply(transaction); transaction_apply(transaction);
@ -210,31 +246,47 @@ void transaction_commit(struct sway_transaction *transaction) {
transaction->timer = wl_event_loop_add_timer(server.wl_event_loop, transaction->timer = wl_event_loop_add_timer(server.wl_event_loop,
handle_timeout, transaction); handle_timeout, transaction);
wl_event_source_timer_update(transaction->timer, TIMEOUT_MS); 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();
} }
void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) { void transaction_notify_view_ready(struct sway_view *view, uint32_t serial) {
// Find the instruction // Find the instruction
struct sway_transaction_instruction *instruction = NULL; struct sway_transaction_instruction *instruction = NULL;
for (int i = 0; i < view->instructions->length; ++i) { for (int i = 0; i < view->swayc->instructions->length; ++i) {
struct sway_transaction_instruction *tmp_instruction = struct sway_transaction_instruction *tmp_instruction =
view->instructions->items[i]; view->swayc->instructions->items[i];
if (tmp_instruction->serial == serial) { if (tmp_instruction->serial == serial && !tmp_instruction->ready) {
instruction = tmp_instruction; instruction = tmp_instruction;
list_del(view->instructions, i);
break; break;
} }
} }
if (!instruction) { if (!instruction) {
// This can happen if the view acknowledges the configure after the
// transaction has timed out and applied.
return; return;
} }
instruction->ready = true;
// If all views are ready, apply the transaction // If all views are ready, apply the transaction
struct sway_transaction *transaction = instruction->transaction; struct sway_transaction *transaction = instruction->transaction;
if (--transaction->num_waiting == 0) { if (--transaction->num_waiting == 0) {
#if !TRANSACTION_DEBUG
wlr_log(L_DEBUG, "Transaction %p is ready, applying", transaction); wlr_log(L_DEBUG, "Transaction %p is ready, applying", transaction);
wl_event_source_timer_update(transaction->timer, 0); wl_event_source_timer_update(transaction->timer, 0);
transaction_apply(transaction); transaction_apply(transaction);
transaction_destroy(transaction); transaction_destroy(transaction);
#endif
} }
} }
struct wlr_texture *transaction_get_texture(struct sway_view *view) {
if (!view->swayc || !view->swayc->instructions->length) {
return view->surface->buffer->texture;
}
struct sway_transaction_instruction *instruction =
view->swayc->instructions->items[0];
return instruction->saved_buffer ?
instruction->saved_buffer->texture : NULL;
}

View file

@ -143,16 +143,12 @@ static void _close(struct sway_view *view) {
} }
} }
static void destroy(struct sway_view *view) { static void _free(struct sway_view *view) {
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;
} }
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);
} }
@ -164,7 +160,7 @@ static const struct sway_view_impl view_impl = {
.wants_floating = wants_floating, .wants_floating = wants_floating,
.for_each_surface = for_each_surface, .for_each_surface = for_each_surface,
.close = _close, .close = _close,
.destroy = destroy, .free = _free,
}; };
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
@ -173,7 +169,11 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_view *view = &xdg_shell_view->view; struct sway_view *view = &xdg_shell_view->view;
struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface; struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
if (view->instructions->length) { if (!view->swayc) {
return;
}
if (view->swayc->instructions->length) {
transaction_notify_view_ready(view, xdg_surface->configure_serial); transaction_notify_view_ready(view, xdg_surface->configure_serial);
} }
@ -191,11 +191,18 @@ 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;
}
struct sway_container *parent = view_unmap(view);
arrange_and_commit(parent);
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);
view->surface = NULL;
} }
static void handle_map(struct wl_listener *listener, void *data) { static void handle_map(struct wl_listener *listener, void *data) {
@ -230,7 +237,17 @@ static void handle_map(struct wl_listener *listener, void *data) {
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) {

View file

@ -143,16 +143,12 @@ static void _close(struct sway_view *view) {
} }
} }
static void destroy(struct sway_view *view) { static void _free(struct sway_view *view) {
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;
} }
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);
} }
@ -164,7 +160,7 @@ static const struct sway_view_impl view_impl = {
.wants_floating = wants_floating, .wants_floating = wants_floating,
.for_each_surface = for_each_surface, .for_each_surface = for_each_surface,
.close = _close, .close = _close,
.destroy = destroy, .free = _free,
}; };
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
@ -173,7 +169,10 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_view *view = &xdg_shell_v6_view->view; struct sway_view *view = &xdg_shell_v6_view->view;
struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6; struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6;
if (view->instructions->length) { if (!view->swayc) {
return;
}
if (view->swayc->instructions->length) {
transaction_notify_view_ready(view, xdg_surface_v6->configure_serial); transaction_notify_view_ready(view, xdg_surface_v6->configure_serial);
} }
@ -191,11 +190,18 @@ 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;
}
struct sway_container *parent = view_unmap(view);
arrange_and_commit(parent);
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);
view->surface = NULL;
} }
static void handle_map(struct wl_listener *listener, void *data) { static void handle_map(struct wl_listener *listener, void *data) {
@ -230,7 +236,13 @@ static void handle_map(struct wl_listener *listener, void *data) {
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) {

View file

@ -218,19 +218,11 @@ static void _close(struct sway_view *view) {
wlr_xwayland_surface_close(view->wlr_xwayland_surface); wlr_xwayland_surface_close(view->wlr_xwayland_surface);
} }
static void destroy(struct sway_view *view) { static void _free(struct sway_view *view) {
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;
} }
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);
} }
@ -242,7 +234,7 @@ static const struct sway_view_impl view_impl = {
.set_fullscreen = set_fullscreen, .set_fullscreen = set_fullscreen,
.wants_floating = wants_floating, .wants_floating = wants_floating,
.close = _close, .close = _close,
.destroy = destroy, .free = _free,
}; };
static void handle_commit(struct wl_listener *listener, void *data) { static void handle_commit(struct wl_listener *listener, void *data) {
@ -254,7 +246,7 @@ static void handle_commit(struct wl_listener *listener, void *data) {
// Don't allow xwayland views to do resize or reposition themselves if // Don't allow xwayland views to do resize or reposition themselves if
// they're involved in a transaction. Once the transaction has finished // they're involved in a transaction. Once the transaction has finished
// they'll apply the next time a commit happens. // they'll apply the next time a commit happens.
if (view->instructions->length) { if (view->swayc && view->swayc->instructions->length) {
if (view->swayc && container_is_floating(view->swayc)) { if (view->swayc && container_is_floating(view->swayc)) {
view_update_size(view, xsurface->width, xsurface->height); view_update_size(view, xsurface->width, xsurface->height);
} else { } else {
@ -268,8 +260,17 @@ static void handle_commit(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_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;
}
struct sway_container *parent = view_unmap(view);
arrange_and_commit(parent);
wl_list_remove(&xwayland_view->commit.link); wl_list_remove(&xwayland_view->commit.link);
view_unmap(&xwayland_view->view); view->surface = NULL;
} }
static void handle_map(struct wl_listener *listener, void *data) { static void handle_map(struct wl_listener *listener, void *data) {
@ -293,12 +294,30 @@ 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);
} }
arrange_and_commit(view->swayc); 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) {
struct sway_container *parent = view_unmap(view);
arrange_and_commit(parent);
wl_list_remove(&xwayland_view->commit.link);
view->surface = NULL;
}
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);
} }

View file

@ -34,6 +34,7 @@ struct sway_server server;
void sway_terminate(int exit_code) { void sway_terminate(int exit_code) {
terminate_request = true; terminate_request = true;
exit_value = exit_code; exit_value = exit_code;
server.terminating = true;
wl_display_terminate(server.wl_display); wl_display_terminate(server.wl_display);
} }

View file

@ -19,6 +19,7 @@
#include <wlr/util/log.h> #include <wlr/util/log.h>
// TODO WLR: make Xwayland optional // TODO WLR: make Xwayland optional
#include <wlr/xwayland.h> #include <wlr/xwayland.h>
#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"
@ -105,6 +106,8 @@ bool server_init(struct sway_server *server) {
return false; return false;
} }
server->destroying_containers = create_list();
input_manager = input_manager_create(server); input_manager = input_manager_create(server);
return true; return true;
} }
@ -112,6 +115,7 @@ 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);
} }
void server_run(struct sway_server *server) { void server_run(struct sway_server *server) {

View file

@ -144,6 +144,19 @@ static void apply_tabbed_or_stacked_layout(struct sway_container *parent) {
} }
} }
/**
* 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, static void arrange_children_of(struct sway_container *parent,
struct sway_transaction *transaction); struct sway_transaction *transaction);
@ -158,6 +171,7 @@ static void arrange_floating(struct sway_container *floating,
} }
transaction_add_container(transaction, floater); transaction_add_container(transaction, floater);
} }
transaction_add_container(transaction, floating);
} }
static void arrange_children_of(struct sway_container *parent, static void arrange_children_of(struct sway_container *parent,
@ -290,8 +304,17 @@ void arrange_windows(struct sway_container *container,
case C_TYPES: case C_TYPES:
break; break;
} }
// Add damage for whatever container arrange_windows() was called with,
// unless it was called with the special floating container, in which case
// we'll damage the entire output.
if (container->type == C_CONTAINER && container->layout == L_FLOATING) {
struct sway_container *output = container_parent(container, C_OUTPUT);
transaction_add_damage(transaction, container_get_box(output));
} else {
transaction_add_damage(transaction, container_get_box(container)); transaction_add_damage(transaction, container_get_box(container));
} }
add_deleted_containers(transaction);
}
void arrange_and_commit(struct sway_container *container) { void arrange_and_commit(struct sway_container *container) {
struct sway_transaction *transaction = transaction_create(); struct sway_transaction *transaction = transaction_create();

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,10 +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->pending.children = create_list(); c->current.children = create_list();
} }
wl_signal_init(&c->events.destroy); wl_signal_init(&c->events.destroy);
@ -133,43 +133,68 @@ 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);
//list_free(cont->pending.children); list_free(cont->current.children);
cont->children = NULL;
switch (cont->type) {
case C_ROOT:
break;
case C_OUTPUT:
cont->sway_output->swayc = NULL;
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);
} }
@ -186,7 +211,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,25 +233,6 @@ static struct sway_container *container_workspace_destroy(
container_move_to(floating->children->items[i], container_move_to(floating->children->items[i],
new_workspace->sway_workspace->floating); new_workspace->sway_workspace->floating);
} }
arrange_and_commit(new_workspace);
}
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;
@ -266,14 +271,13 @@ 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_and_commit(&root_container);
wl_list_remove(&output->sway_output->mode.link); wl_list_remove(&output->sway_output->mode.link);
wl_list_remove(&output->sway_output->transform.link); wl_list_remove(&output->sway_output->transform.link);
@ -285,12 +289,8 @@ static struct sway_container *container_output_destroy(
output->sway_output->swayc = NULL; output->sway_output->swayc = 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;
}
static void container_root_finish(struct sway_container *con) { return &root_container;
wlr_log(L_ERROR, "TODO: destroy the root container");
} }
bool container_reap_empty(struct sway_container *con) { bool container_reap_empty(struct sway_container *con) {
@ -306,13 +306,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(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(con);
return true; return true;
} }
case C_VIEW: case C_VIEW:
@ -349,45 +349,47 @@ struct sway_container *container_flatten(struct sway_container *container) {
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().
*/
struct sway_container *container_destroy(struct sway_container *con) { struct sway_container *container_destroy(struct sway_container *con) {
if (con == NULL) { if (con == NULL) {
return NULL; return NULL;
} }
if (con->destroying) {
return NULL;
}
struct sway_container *parent = con->parent; // The below functions move their children to somewhere else.
if (con->type == C_OUTPUT) {
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); container_output_destroy(con);
break; } else if (con->type == C_WORKSPACE) {
case C_WORKSPACE: // Workspaces will refuse to be destroyed if they're the last workspace
// dont try to reap the output after this // on their output.
container_workspace_destroy(con); if (!container_workspace_destroy(con)) {
break; return NULL;
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);
} }
} }
// At this point the container being destroyed shouldn't have any children
// unless sway is terminating.
if (!server.terminating) {
if (!sway_assert(!con->children || con->children->length == 0,
"Didn't expect to see children here")) {
return NULL;
}
}
wl_signal_emit(&con->events.destroy, con);
ipc_event_window(con, "close"); ipc_event_window(con, "close");
_container_destroy(con);
break; struct sway_container *parent = container_remove_child(con);
case C_VIEW:
_container_destroy(con); con->destroying = true;
break; list_add(server.destroying_containers, con);
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);
} }

View file

@ -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));

View file

@ -29,7 +29,6 @@ static void restore_workspaces(struct sway_container *output) {
} }
container_sort_workspaces(output); container_sort_workspaces(output);
arrange_and_commit(&root_container);
} }
struct sway_container *output_create( struct sway_container *output_create(
@ -66,7 +65,6 @@ struct sway_container *output_create(
struct sway_container *output = container_create(C_OUTPUT); struct sway_container *output = container_create(C_OUTPUT);
output->sway_output = sway_output; output->sway_output = sway_output;
sway_output->swayc = output;
output->name = strdup(name); output->name = strdup(name);
if (output->name == NULL) { if (output->name == NULL) {
container_destroy(output); container_destroy(output);

View file

@ -25,47 +25,60 @@ void view_init(struct sway_view *view, enum sway_view_type type,
view->impl = impl; view->impl = impl;
view->executed_criteria = create_list(); view->executed_criteria = create_list();
view->marks = create_list(); view->marks = create_list();
view->instructions = create_list();
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,
if (!sway_assert(view->instructions->length == 0, "Tried to free view which still has a swayc "
"Tried to destroy view with pending instructions")) { "(might have a pending transaction?)")) {
return; 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);
list_free(view->instructions);
wlr_texture_destroy(view->marks_focused); wlr_texture_destroy(view->marks_focused);
wlr_texture_destroy(view->marks_focused_inactive); wlr_texture_destroy(view->marks_focused_inactive);
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->free) {
view->impl->free(view);
if (view->impl->destroy) {
view->impl->destroy(view);
} else { } else {
free(view); free(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);
@ -356,6 +369,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 {
@ -523,11 +539,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) {
view_handle_container_reparent(&view->container_reparent, NULL); view_handle_container_reparent(&view->container_reparent, NULL);
} }
void view_unmap(struct sway_view *view) { struct sway_container *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) { if (view->is_fullscreen) {
@ -535,22 +547,10 @@ void view_unmap(struct sway_view *view) {
ws->sway_workspace->fullscreen = NULL; 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); return container_destroy(view->swayc);
view->swayc = NULL;
view->surface = NULL;
if (view->title_format) {
free(view->title_format);
view->title_format = NULL;
}
arrange_and_commit(parent);
} }
void view_update_position(struct sway_view *view, double lx, double ly) { void view_update_position(struct sway_view *view, double lx, double ly) {
@ -924,7 +924,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

@ -430,6 +430,9 @@ bool workspace_switch(struct sway_container *workspace) {
} }
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);