aboutsummaryrefslogtreecommitdiff
path: root/sway/desktop
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-06-30 06:27:39 -0700
committerGitHub <noreply@github.com>2018-06-30 06:27:39 -0700
commitd8c61c976372eedf271f505ffd82c461b6503f6f (patch)
tree323739dc80680dd774acfdcf43eb76cfe93aa64c /sway/desktop
parent9ba72433b6c87086f2772405e09e8ac8c0136a01 (diff)
parente396af853b01438f7e5ef34bfa6fd2507d11ce5a (diff)
Merge pull request #2072 from RyanDwyer/atomic
Atomic layout updates
Diffstat (limited to 'sway/desktop')
-rw-r--r--sway/desktop/desktop.c3
-rw-r--r--sway/desktop/layer_shell.c2
-rw-r--r--sway/desktop/output.c320
-rw-r--r--sway/desktop/transaction.c415
-rw-r--r--sway/desktop/xdg_shell.c75
-rw-r--r--sway/desktop/xdg_shell_v6.c73
-rw-r--r--sway/desktop/xwayland.c72
7 files changed, 746 insertions, 214 deletions
diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c
index 66f33151..e495790c 100644
--- a/sway/desktop/desktop.c
+++ b/sway/desktop/desktop.c
@@ -7,7 +7,8 @@ void desktop_damage_surface(struct wlr_surface *surface, double lx, double ly,
for (int i = 0; i < root_container.children->length; ++i) {
struct sway_container *cont = root_container.children->items[i];
if (cont->type == C_OUTPUT) {
- output_damage_surface(cont->sway_output, lx - cont->x, ly - cont->y,
+ output_damage_surface(cont->sway_output,
+ lx - cont->current.swayc_x, ly - cont->current.swayc_y,
surface, whole);
}
}
diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c
index b57d1ee6..ff37bbf1 100644
--- a/sway/desktop/layer_shell.c
+++ b/sway/desktop/layer_shell.c
@@ -176,7 +176,7 @@ void arrange_layers(struct sway_output *output) {
sizeof(struct wlr_box)) != 0) {
wlr_log(L_DEBUG, "Usable area changed, rearranging output");
memcpy(&output->usable_area, &usable_area, sizeof(struct wlr_box));
- arrange_output(output->swayc);
+ arrange_and_commit(output->swayc);
}
// Arrange non-exlusive surfaces from top->bottom
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 6244ca4a..541d765d 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -6,6 +6,7 @@
#include <wayland-server.h>
#include <wlr/render/wlr_renderer.h>
#include <wlr/types/wlr_box.h>
+#include <wlr/types/wlr_buffer.h>
#include <wlr/types/wlr_matrix.h>
#include <wlr/types/wlr_output_damage.h>
#include <wlr/types/wlr_output_layout.h>
@@ -69,6 +70,7 @@ struct render_data {
struct root_geometry root_geo;
struct sway_output *output;
pixman_region32_t *damage;
+ struct sway_view *view;
float alpha;
};
@@ -100,8 +102,8 @@ static bool get_surface_box(struct root_geometry *geo,
wlr_box_rotated_bounds(&box, geo->rotation, &rotated_box);
struct wlr_box output_box = {
- .width = output->swayc->width,
- .height = output->swayc->height,
+ .width = output->swayc->current.swayc_width,
+ .height = output->swayc->current.swayc_height,
};
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,
void *user_data) {
struct render_data *data = user_data;
- geo->x = view->x - data->output->swayc->x;
- geo->y = view->y - data->output->swayc->y;
- geo->width = view->surface->current->width;
- geo->height = view->surface->current->height;
+ geo->x = view->swayc->current.view_x - data->output->swayc->current.swayc_x;
+ geo->y = view->swayc->current.view_y - data->output->swayc->current.swayc_y;
+ geo->width = view->swayc->current.view_width;
+ geo->height = view->swayc->current.view_height;
geo->rotation = 0; // TODO
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) {
struct wlr_xwayland_surface *xsurface =
unmanaged_surface->wlr_xwayland_surface;
- double ox = unmanaged_surface->lx - output->swayc->x;
- double oy = unmanaged_surface->ly - output->swayc->y;
+ double ox = unmanaged_surface->lx - output->swayc->current.swayc_x;
+ double oy = unmanaged_surface->ly - output->swayc->current.swayc_y;
surface_for_each_surface(xsurface->surface, ox, oy, geo,
iterator, user_data);
@@ -241,13 +243,13 @@ static void render_surface_iterator(struct wlr_surface *surface, int sx, int sy,
float alpha = data->alpha;
struct wlr_texture *texture = wlr_surface_get_texture(surface);
- if (texture == NULL) {
+ if (!texture) {
return;
}
struct wlr_box box;
bool intersects = get_surface_box(&data->root_geo, data->output, surface,
- sx, sy, &box);
+ sx, sy, &box);
if (!intersects) {
return;
}
@@ -341,64 +343,107 @@ static void render_view_surfaces(struct sway_view *view,
struct render_data data = {
.output = output,
.damage = damage,
+ .view = view,
.alpha = alpha,
};
output_view_for_each_surface(
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.
*/
static void render_view(struct sway_output *output, pixman_region32_t *damage,
struct sway_container *con, struct border_colors *colors) {
struct sway_view *view = con->sway_view;
- render_view_surfaces(view, output, damage, view->swayc->alpha);
+ if (view->swayc->instructions->length) {
+ render_saved_view(view, output, damage, view->swayc->alpha);
+ } else {
+ render_view_surfaces(view, output, damage, view->swayc->alpha);
+ }
struct wlr_box box;
float output_scale = output->wlr_output->scale;
float color[4];
+ struct sway_container_state *state = &con->current;
- if (view->border != B_NONE) {
- if (view->border_left) {
+ if (state->border != B_NONE) {
+ if (state->border_left) {
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
- box.x = con->x;
- box.y = view->y;
- box.width = view->border_thickness;
- box.height = view->height;
+ box.x = state->swayc_x;
+ box.y = state->view_y;
+ box.width = state->border_thickness;
+ box.height = state->view_height;
scale_box(&box, output_scale);
render_rect(output->wlr_output, damage, &box, color);
}
- if (view->border_right) {
- if (con->parent->children->length == 1
- && con->parent->layout == L_HORIZ) {
+ if (state->border_right) {
+ if (state->parent->current.children->length == 1
+ && state->parent->current.layout == L_HORIZ) {
memcpy(&color, colors->indicator, sizeof(float) * 4);
} else {
memcpy(&color, colors->child_border, sizeof(float) * 4);
}
premultiply_alpha(color, con->alpha);
- box.x = view->x + view->width;
- box.y = view->y;
- box.width = view->border_thickness;
- box.height = view->height;
+ box.x = state->view_x + state->view_width;
+ box.y = state->view_y;
+ box.width = state->border_thickness;
+ box.height = state->view_height;
scale_box(&box, output_scale);
render_rect(output->wlr_output, damage, &box, color);
}
- if (view->border_bottom) {
- if (con->parent->children->length == 1
- && con->parent->layout == L_VERT) {
+ if (state->border_bottom) {
+ if (state->parent->current.children->length == 1
+ && con->current.parent->current.layout == L_VERT) {
memcpy(&color, colors->indicator, sizeof(float) * 4);
} else {
memcpy(&color, colors->child_border, sizeof(float) * 4);
}
premultiply_alpha(color, con->alpha);
- box.x = con->x;
- box.y = view->y + view->height;
- box.width = con->width;
- box.height = view->border_thickness;
+ box.x = state->swayc_x;
+ box.y = state->view_y + state->view_height;
+ box.width = state->swayc_width;
+ box.height = state->border_thickness;
scale_box(&box, output_scale);
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_box box;
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;
- enum sway_container_layout layout = con->parent->layout;
- bool is_last_child =
- con->parent->children->items[con->parent->children->length - 1] == con;
+ enum sway_container_layout layout = state->parent->current.layout;
+ list_t *children = state->parent->current.children;
+ 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
memcpy(&color, colors->border, sizeof(float) * 4);
@@ -443,9 +490,9 @@ static void render_titlebar(struct sway_output *output,
bool connects_sides = false;
if (layout == L_HORIZ || layout == L_VERT ||
(layout == L_STACKED && is_last_child)) {
- if (view) {
- left_offset = view->border_left * view->border_thickness;
- right_offset = view->border_right * view->border_thickness;
+ if (con->type == C_VIEW) {
+ left_offset = state->border_left * state->border_thickness;
+ right_offset = state->border_right * state->border_thickness;
connects_sides = true;
}
}
@@ -479,10 +526,9 @@ static void render_titlebar(struct sway_output *output,
struct wlr_box texture_box;
wlr_texture_get_size(marks_texture,
&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;
- texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING)
- * output_scale;
+ texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale;
float matrix[9];
wlr_matrix_project_box(matrix, &texture_box,
@@ -503,10 +549,8 @@ static void render_titlebar(struct sway_output *output,
struct wlr_box texture_box;
wlr_texture_get_size(title_texture,
&texture_box.width, &texture_box.height);
- texture_box.x = (x - output->swayc->x + TITLEBAR_H_PADDING)
- * output_scale;
- texture_box.y = (y - output->swayc->y + TITLEBAR_V_PADDING)
- * output_scale;
+ texture_box.x = (x - output_x + TITLEBAR_H_PADDING) * output_scale;
+ texture_box.y = (y - output_y + TITLEBAR_V_PADDING) * output_scale;
float matrix[9];
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
box.x = x;
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;
scale_box(&box, output_scale);
render_rect(output->wlr_output, output_damage, &box, color);
// 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.width = view->border_thickness * view->border_right;
+ box.width = state->border_thickness * state->border_right;
box.height = TITLEBAR_BORDER_THICKNESS;
scale_box(&box, output_scale);
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,
pixman_region32_t *output_damage, struct sway_container *con,
struct border_colors *colors) {
- struct sway_view *view = con->sway_view;
- if (!view->border_top) {
+ struct sway_container_state *state = &con->current;
+ if (!state->border_top) {
return;
}
struct wlr_box box;
@@ -598,10 +642,10 @@ static void render_top_border(struct sway_output *output,
// Child border - top edge
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
- box.x = con->x;
- box.y = con->y;
- box.width = con->width;
- box.height = view->border_thickness;
+ box.x = state->swayc_x;
+ box.y = state->swayc_y;
+ box.width = state->swayc_width;
+ box.height = state->border_thickness;
scale_box(&box, output_scale);
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_container *focus = seat_get_focus(seat);
- for (int i = 0; i < con->children->length; ++i) {
- struct sway_container *child = con->children->items[i];
+ for (int i = 0; i < con->current.children->length; ++i) {
+ struct sway_container *child = con->current.children->items[i];
if (child->type == C_VIEW) {
+ struct sway_view *view = child->sway_view;
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
+ struct sway_container_state *state = &child->current;
+
if (focus == child || parent_focused) {
colors = &config->border_colors.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) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
- marks_texture = child->sway_view->marks_focused_inactive;
+ marks_texture = view->marks_focused_inactive;
} else {
colors = &config->border_colors.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) {
- render_titlebar(output, damage, child, child->x, child->y,
- child->width, colors, title_texture, marks_texture);
+ if (state->border == B_NORMAL) {
+ render_titlebar(output, damage, child, state->swayc_x,
+ state->swayc_y, state->swayc_width, colors,
+ title_texture, marks_texture);
} else {
render_top_border(output, damage, child, colors);
}
@@ -662,22 +710,23 @@ static void render_container_simple(struct sway_output *output,
static void render_container_tabbed(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) {
- if (!con->children->length) {
+ 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_child(seat, con);
- struct border_colors *current_colors = NULL;
+ 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 tabs
- for (int i = 0; i < con->children->length; ++i) {
- struct sway_container *child = con->children->items[i];
+ 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;
- struct sway_view *view =
- child->type == C_VIEW ? child->sway_view : NULL;
if (focus == child || parent_focused) {
colors = &config->border_colors.focused;
@@ -686,22 +735,22 @@ static void render_container_tabbed(struct sway_output *output,
} else if (child == current) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
- marks_texture = view ? view->marks_focused : NULL;
+ 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 tab_width = con->width / con->children->length;
- int x = con->x + tab_width * i;
+ int tab_width = pstate->swayc_width / pstate->children->length;
+ int x = pstate->swayc_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;
+ if (i == pstate->children->length - 1) {
+ tab_width = pstate->swayc_width - tab_width * i;
}
- render_titlebar(output, damage, child, x, child->y, tab_width, colors,
- title_texture, marks_texture);
+ render_titlebar(output, damage, child, x, cstate->swayc_y, tab_width,
+ colors, title_texture, marks_texture);
if (child == current) {
current_colors = colors;
@@ -709,11 +758,13 @@ static void render_container_tabbed(struct sway_output *output,
}
// 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);
+ if (current) {
+ if (current->type == C_VIEW) {
+ render_view(output, damage, current, current_colors);
+ } else {
+ render_container(output, damage, current,
+ parent_focused || current == focus);
+ }
}
}
@@ -723,22 +774,23 @@ static void render_container_tabbed(struct sway_output *output,
static void render_container_stacked(struct sway_output *output,
pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) {
- if (!con->children->length) {
+ 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_child(seat, con);
- struct border_colors *current_colors = NULL;
+ 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->children->length; ++i) {
- struct sway_container *child = con->children->items[i];
+ 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;
- struct sway_view *view =
- child->type == C_VIEW ? child->sway_view : NULL;
if (focus == child || parent_focused) {
colors = &config->border_colors.focused;
@@ -754,9 +806,9 @@ static void render_container_stacked(struct sway_output *output,
marks_texture = view ? view->marks_unfocused : NULL;
}
- int y = con->y + container_titlebar_height() * i;
- render_titlebar(output, damage, child, child->x, y, child->width,
- colors, title_texture, marks_texture);
+ int y = 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;
@@ -764,18 +816,20 @@ static void render_container_stacked(struct sway_output *output,
}
// 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);
+ 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,
pixman_region32_t *damage, struct sway_container *con,
bool parent_focused) {
- switch (con->layout) {
+ switch (con->current.layout) {
case L_NONE:
case L_HORIZ:
case L_VERT:
@@ -812,10 +866,11 @@ static void render_floating_container(struct sway_output *soutput,
marks_texture = view->marks_unfocused;
}
- if (con->sway_view->border == B_NORMAL) {
- render_titlebar(soutput, damage, con, con->x, con->y, con->width,
- colors, title_texture, marks_texture);
- } else if (con->sway_view->border != B_NONE) {
+ if (con->current.border == B_NORMAL) {
+ render_titlebar(soutput, damage, con, con->current.swayc_x,
+ con->current.swayc_y, con->current.swayc_width, colors,
+ title_texture, marks_texture);
+ } else if (con->current.border != B_NONE) {
render_top_border(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,
pixman_region32_t *damage) {
- for (int i = 0; i < root_container.children->length; ++i) {
- struct sway_container *output = root_container.children->items[i];
- for (int j = 0; j < output->children->length; ++j) {
- struct sway_container *workspace = output->children->items[j];
- struct sway_workspace *ws = workspace->sway_workspace;
- if (!workspace_is_visible(workspace)) {
+ for (int i = 0; i < root_container.current.children->length; ++i) {
+ struct sway_container *output =
+ root_container.current.children->items[i];
+ for (int j = 0; j < output->current.children->length; ++j) {
+ struct sway_container *ws = output->current.children->items[j];
+ if (!workspace_is_visible(ws)) {
continue;
}
- for (int k = 0; k < ws->floating->children->length; ++k) {
- struct sway_container *floater =
- ws->floating->children->items[k];
+ list_t *floating =
+ ws->current.ws_floating->current.children;
+ for (int k = 0; k < floating->length; ++k) {
+ struct sway_container *floater = floating->items[k];
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);
if (!focus) {
// 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;
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_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};
int nrects;
@@ -903,10 +960,9 @@ static void render_output(struct sway_output *output, struct timespec *when,
}
// TODO: handle views smaller than the output
- render_view_surfaces(
- workspace->sway_workspace->fullscreen, output, damage, 1.0f);
+ render_view_surfaces(fullscreen_view, output, damage, 1.0f);
- if (workspace->sway_workspace->fullscreen->type == SWAY_VIEW_XWAYLAND) {
+ if (fullscreen_view->type == SWAY_VIEW_XWAYLAND) {
render_unmanaged(output, damage,
&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);
- if (workspace->sway_workspace->fullscreen) {
+ if (workspace->current.ws_fullscreen) {
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,
&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);
}
+// Expecting an unscaled box in layout coordinates
+void output_damage_box(struct sway_output *output, struct wlr_box *_box) {
+ struct wlr_box box;
+ memcpy(&box, _box, sizeof(struct wlr_box));
+ box.x -= output->swayc->current.swayc_x;
+ box.y -= output->swayc->current.swayc_y;
+ scale_box(&box, output->wlr_output->scale);
+ wlr_output_damage_add_box(output->damage, &box);
+}
+
static void output_damage_whole_container_iterator(struct sway_container *con,
void *data) {
struct sway_output *output = data;
@@ -1182,10 +1248,10 @@ static void output_damage_whole_container_iterator(struct sway_container *con,
void output_damage_whole_container(struct sway_output *output,
struct sway_container *con) {
struct wlr_box box = {
- .x = con->x - output->wlr_output->lx,
- .y = con->y - output->wlr_output->ly,
- .width = con->width,
- .height = con->height,
+ .x = con->current.swayc_x - output->wlr_output->lx,
+ .y = con->current.swayc_y - output->wlr_output->ly,
+ .width = con->current.swayc_width,
+ .height = con->current.swayc_height,
};
scale_box(&box, output->wlr_output->scale);
wlr_output_damage_add_box(output->damage, &box);
@@ -1209,18 +1275,20 @@ static void handle_destroy(struct wl_listener *listener, void *data) {
wl_list_remove(&output->destroy.link);
output->wlr_output->data = NULL;
free(output);
+
+ arrange_and_commit(&root_container);
}
static void handle_mode(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, mode);
arrange_layers(output);
- arrange_output(output->swayc);
+ arrange_and_commit(output->swayc);
}
static void handle_transform(struct wl_listener *listener, void *data) {
struct sway_output *output = wl_container_of(listener, output, transform);
arrange_layers(output);
- arrange_output(output->swayc);
+ arrange_and_commit(output->swayc);
}
static void handle_scale_iterator(struct sway_container *view, void *data) {
@@ -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) {
struct sway_output *output = wl_container_of(listener, output, scale);
arrange_layers(output);
- arrange_output(output->swayc);
container_descendants(output->swayc, C_VIEW, handle_scale_iterator, NULL);
+ arrange_and_commit(output->swayc);
}
void handle_new_output(struct wl_listener *listener, void *data) {
@@ -1296,5 +1364,5 @@ void output_enable(struct sway_output *output) {
output->damage_destroy.notify = damage_handle_destroy;
arrange_layers(output);
- arrange_root();
+ arrange_and_commit(&root_container);
}
diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c
new file mode 100644
index 00000000..d2932c87
--- /dev/null
+++ b/sway/desktop/transaction.c
@@ -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;
+}
diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c
index 6ac0f9c7..da3a1cdd 100644
--- a/sway/desktop/xdg_shell.c
+++ b/sway/desktop/xdg_shell.c
@@ -8,6 +8,7 @@
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
#include "sway/tree/view.h"
@@ -87,18 +88,14 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p
}
}
-static void configure(struct sway_view *view, double lx, double ly, int width,
- int height) {
+static uint32_t configure(struct sway_view *view, double lx, double ly,
+ int width, int height) {
struct sway_xdg_shell_view *xdg_shell_view =
xdg_shell_view_from_view(view);
if (xdg_shell_view == NULL) {
- return;
+ return 0;
}
-
- xdg_shell_view->pending_width = width;
- xdg_shell_view->pending_height = height;
- wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
- view_update_position(view, lx, ly);
+ return wlr_xdg_toplevel_set_size(view->wlr_xdg_surface, width, height);
}
static void set_activated(struct sway_view *view, bool activated) {
@@ -166,10 +163,6 @@ static void destroy(struct sway_view *view) {
if (xdg_shell_view == NULL) {
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);
}
@@ -189,18 +182,16 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view =
wl_container_of(listener, xdg_shell_view, commit);
struct sway_view *view = &xdg_shell_view->view;
- if (view->swayc && container_is_floating(view->swayc)) {
- int width = view->wlr_xdg_surface->geometry.width;
- int height = view->wlr_xdg_surface->geometry.height;
- if (!width && !height) {
- width = view->wlr_xdg_surface->surface->current->width;
- height = view->wlr_xdg_surface->surface->current->height;
- }
- view_update_size(view, width, height);
- } else {
- view_update_size(view, xdg_shell_view->pending_width,
- xdg_shell_view->pending_height);
+ struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface;
+
+ if (!view->swayc) {
+ return;
+ }
+
+ if (view->swayc->instructions->length) {
+ transaction_notify_view_ready(view, xdg_surface->configure_serial);
}
+
view_update_title(view, false);
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) {
struct sway_xdg_shell_view *xdg_shell_view =
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->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_height = view->wlr_xdg_surface->surface->current->height;
}
+
view_map(view, view->wlr_xdg_surface->surface);
+ if (xdg_surface->toplevel->client_pending.fullscreen) {
+ view_set_fullscreen(view, true);
+ 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;
wl_signal_add(&xdg_surface->surface->events.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;
wl_signal_add(&xdg_surface->events.new_popup,
&xdg_shell_view->new_popup);
-
- if (xdg_surface->toplevel->client_pending.fullscreen) {
- view_set_fullscreen(view, true);
- }
}
static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_view *xdg_shell_view =
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) {
@@ -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_surface *xdg_surface =
xdg_shell_view->view.wlr_xdg_surface;
+ struct sway_view *view = &xdg_shell_view->view;
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL,
"xdg_shell requested fullscreen of surface with role %i",
@@ -271,7 +283,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return;
}
- view_set_fullscreen(&xdg_shell_view->view, e->fullscreen);
+ view_set_fullscreen(view, e->fullscreen);
+
+ struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
+ arrange_and_commit(ws);
}
void handle_xdg_shell_surface(struct wl_listener *listener, void *data) {
diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c
index a37a4caf..69819280 100644
--- a/sway/desktop/xdg_shell_v6.c
+++ b/sway/desktop/xdg_shell_v6.c
@@ -3,9 +3,10 @@
#include <stdlib.h>
#include <wayland-server.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
+#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
-#include "sway/server.h"
#include "sway/tree/view.h"
#include "sway/input/seat.h"
#include "sway/input/input-manager.h"
@@ -86,18 +87,15 @@ static const char *get_string_prop(struct sway_view *view, enum sway_view_prop p
}
}
-static void configure(struct sway_view *view, double lx, double ly, int width,
- int height) {
+static uint32_t configure(struct sway_view *view, double lx, double ly,
+ int width, int height) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
xdg_shell_v6_view_from_view(view);
if (xdg_shell_v6_view == NULL) {
- return;
+ return 0;
}
-
- xdg_shell_v6_view->pending_width = width;
- xdg_shell_v6_view->pending_height = height;
- wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height);
- view_update_position(view, lx, ly);
+ return wlr_xdg_toplevel_v6_set_size(
+ view->wlr_xdg_surface_v6, width, height);
}
static void set_activated(struct sway_view *view, bool activated) {
@@ -161,10 +159,6 @@ static void destroy(struct sway_view *view) {
if (xdg_shell_v6_view == NULL) {
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);
}
@@ -184,18 +178,15 @@ static void handle_commit(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, commit);
struct sway_view *view = &xdg_shell_v6_view->view;
- if (view->swayc && container_is_floating(view->swayc)) {
- int width = view->wlr_xdg_surface_v6->geometry.width;
- int height = view->wlr_xdg_surface_v6->geometry.height;
- if (!width && !height) {
- width = view->wlr_xdg_surface_v6->surface->current->width;
- height = view->wlr_xdg_surface_v6->surface->current->height;
- }
- view_update_size(view, width, height);
- } else {
- view_update_size(view, xdg_shell_v6_view->pending_width,
- xdg_shell_v6_view->pending_height);
+ struct wlr_xdg_surface_v6 *xdg_surface_v6 = view->wlr_xdg_surface_v6;
+
+ if (!view->swayc) {
+ return;
}
+ if (view->swayc->instructions->length) {
+ transaction_notify_view_ready(view, xdg_surface_v6->configure_serial);
+ }
+
view_update_title(view, false);
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) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
wl_container_of(listener, xdg_shell_v6_view, unmap);
+ struct sway_view *view = &xdg_shell_v6_view->view;
+
+ if (!sway_assert(view->surface, "Cannot unmap unmapped view")) {
+ return;
+ }
- view_unmap(&xdg_shell_v6_view->view);
+ view_unmap(view);
wl_list_remove(&xdg_shell_v6_view->commit.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_height = view->wlr_xdg_surface_v6->surface->current->height;
}
+
view_map(view, view->wlr_xdg_surface_v6->surface);
+ if (xdg_surface->toplevel->client_pending.fullscreen) {
+ view_set_fullscreen(view, true);
+ 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;
wl_signal_add(&xdg_surface->surface->events.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;
wl_signal_add(&xdg_surface->events.new_popup,
&xdg_shell_v6_view->new_popup);
-
- if (xdg_surface->toplevel->client_pending.fullscreen) {
- view_set_fullscreen(view, true);
- }
}
static void handle_destroy(struct wl_listener *listener, void *data) {
struct sway_xdg_shell_v6_view *xdg_shell_v6_view =
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) {
@@ -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_surface_v6 *xdg_surface =
xdg_shell_v6_view->view.wlr_xdg_surface_v6;
+ struct sway_view *view = &xdg_shell_v6_view->view;
if (!sway_assert(xdg_surface->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL,
"xdg_shell_v6 requested fullscreen of surface with role %i",
@@ -266,7 +274,10 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return;
}
- view_set_fullscreen(&xdg_shell_v6_view->view, e->fullscreen);
+ view_set_fullscreen(view, e->fullscreen);
+
+ struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
+ arrange_and_commit(ws);
}
void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c
index fcc8164f..6e63c505 100644
--- a/sway/desktop/xwayland.c
+++ b/sway/desktop/xwayland.c
@@ -7,10 +7,12 @@
#include <wlr/xwayland.h>
#include "log.h"
#include "sway/desktop.h"
+#include "sway/desktop/transaction.h"
#include "sway/input/input-manager.h"
#include "sway/input/seat.h"
#include "sway/output.h"
#include "sway/server.h"
+#include "sway/tree/arrange.h"
#include "sway/tree/container.h"
#include "sway/tree/layout.h"
#include "sway/tree/view.h"
@@ -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) {
struct sway_xwayland_view *xwayland_view = xwayland_view_from_view(view);
if (xwayland_view == NULL) {
- return;
+ return 0;
}
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
- xwayland_view->pending_lx = lx;
- xwayland_view->pending_ly = ly;
- xwayland_view->pending_width = width;
- xwayland_view->pending_height = height;
wlr_xwayland_surface_configure(xsurface, lx, ly, width, height);
+
+ // xwayland doesn't give us a serial for the configure
+ return 0;
}
static void set_activated(struct sway_view *view, bool activated) {
@@ -257,14 +258,6 @@ static void destroy(struct sway_view *view) {
if (xwayland_view == NULL) {
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);
}
@@ -285,22 +278,27 @@ static void handle_commit(struct wl_listener *listener, void *data) {
wl_container_of(listener, xwayland_view, commit);
struct sway_view *view = &xwayland_view->view;
struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface;
- if (view->swayc && container_is_floating(view->swayc)) {
- view_update_size(view, xsurface->width, xsurface->height);
- } else {
- view_update_size(view, xwayland_view->pending_width,
- xwayland_view->pending_height);
+ struct wlr_surface_state *surface_state = xsurface->surface->current;
+
+ if (view->swayc->instructions->length) {
+ transaction_notify_view_ready_by_size(view,
+ surface_state->width, surface_state->height);
}
- view_update_position(view,
- xwayland_view->pending_lx, xwayland_view->pending_ly);
view_damage_from(view);
}
static void handle_unmap(struct wl_listener *listener, void *data) {
struct sway_xwayland_view *xwayland_view =
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);
- view_unmap(&xwayland_view->view);
}
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) {
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) {
struct sway_xwayland_view *xwayland_view =
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);
}
@@ -343,10 +360,12 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
return;
}
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 {
- configure(view, view->x, view->y,
- view->width, view->height);
+ configure(view, view->swayc->current.view_x,
+ view->swayc->current.view_y, view->swayc->current.view_width,
+ view->swayc->current.view_height);
}
}
@@ -359,6 +378,9 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data)
return;
}
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) {