Move view {x,y,width,height} into container struct

This renames/moves the following properties:

* sway_view.{x,y,width,height} ->
sway_container.content_{x,y,width,height}
    * This is required to support placeholder containers as they don't
    have a view.
* sway_container_state.view_{x,y,width,height} ->
sway_container_state.content_{x,y,width,height}
    * To remain consistent with the above.
* sway_container_state.con_{x,y,width,height} ->
sway_container_state.{x,y,width,height}
    * The con prefix was there to give it contrast from the view
    properties, and is no longer useful.

The function container_set_geometry_from_floating_view has also been
renamed to container_set_geometry_from_content.
This commit is contained in:
Ryan Dwyer 2018-11-17 18:32:03 +10:00
parent cb63321de6
commit be9348d25c
15 changed files with 156 additions and 160 deletions

View file

@ -41,8 +41,8 @@ enum wlr_direction;
struct sway_container_state { struct sway_container_state {
// Container properties // Container properties
enum sway_container_layout layout; enum sway_container_layout layout;
double con_x, con_y; double x, y;
double con_width, con_height; double width, height;
bool is_fullscreen; bool is_fullscreen;
@ -60,9 +60,8 @@ struct sway_container_state {
bool border_left; bool border_left;
bool border_right; bool border_right;
// View properties double content_x, content_y;
double view_x, view_y; double content_width, content_height;
double view_width, view_height;
}; };
struct sway_container { struct sway_container {
@ -89,6 +88,9 @@ struct sway_container {
double saved_x, saved_y; double saved_x, saved_y;
double saved_width, saved_height; double saved_width, saved_height;
double content_x, content_y;
int content_width, content_height;
bool is_fullscreen; bool is_fullscreen;
enum sway_container_border border; enum sway_container_border border;
@ -210,7 +212,7 @@ void container_init_floating(struct sway_container *container);
void container_set_floating(struct sway_container *container, bool enable); void container_set_floating(struct sway_container *container, bool enable);
void container_set_geometry_from_floating_view(struct sway_container *con); void container_set_geometry_from_content(struct sway_container *con);
/** /**
* Determine if the given container is itself floating. * Determine if the given container is itself floating.

View file

@ -67,10 +67,6 @@ struct sway_view {
pid_t pid; pid_t pid;
// Geometry of the view itself (excludes borders) in layout coordinates
double x, y;
int width, height;
double saved_x, saved_y; double saved_x, saved_y;
int saved_width, saved_height; int saved_width, saved_height;

View file

@ -93,7 +93,7 @@ struct cmd_results *cmd_border(int argc, char **argv) {
} }
if (container_is_floating(container)) { if (container_is_floating(container)) {
container_set_geometry_from_floating_view(container); container_set_geometry_from_content(container);
} }
arrange_container(container); arrange_container(container);

View file

@ -404,13 +404,10 @@ static struct cmd_results *resize_adjust_floating(enum resize_axis axis,
con->width += grow_width; con->width += grow_width;
con->height += grow_height; con->height += grow_height;
if (con->view) { con->content_x += grow_x;
struct sway_view *view = con->view; con->content_y += grow_y;
view->x += grow_x; con->content_width += grow_width;
view->y += grow_y; con->content_height += grow_height;
view->width += grow_width;
view->height += grow_height;
}
arrange_container(con); arrange_container(con);
@ -546,13 +543,10 @@ static struct cmd_results *resize_set_floating(struct sway_container *con,
} }
} }
if (con->view) { con->content_x -= grow_width / 2;
struct sway_view *view = con->view; con->content_y -= grow_height / 2;
view->x -= grow_width / 2; con->content_width += grow_width;
view->y -= grow_height / 2; con->content_height += grow_height;
view->width += grow_width;
view->height += grow_height;
}
arrange_container(con); arrange_container(con);

View file

@ -28,8 +28,8 @@ void desktop_damage_box(struct wlr_box *box) {
void desktop_damage_view(struct sway_view *view) { void desktop_damage_view(struct sway_view *view) {
desktop_damage_whole_container(view->container); desktop_damage_whole_container(view->container);
struct wlr_box box = { struct wlr_box box = {
.x = view->container->current.view_x - view->geometry.x, .x = view->container->current.content_x - view->geometry.x,
.y = view->container->current.view_y - view->geometry.y, .y = view->container->current.content_y - view->geometry.y,
.width = view->surface->current.width, .width = view->surface->current.width,
.height = view->surface->current.height, .height = view->surface->current.height,
}; };

View file

@ -160,12 +160,12 @@ void output_view_for_each_surface(struct sway_output *output,
.user_iterator = iterator, .user_iterator = iterator,
.user_data = user_data, .user_data = user_data,
.output = output, .output = output,
.ox = view->container->current.view_x - output->wlr_output->lx .ox = view->container->current.content_x - output->wlr_output->lx
- view->geometry.x, - view->geometry.x,
.oy = view->container->current.view_y - output->wlr_output->ly .oy = view->container->current.content_y - output->wlr_output->ly
- view->geometry.y, - view->geometry.y,
.width = view->container->current.view_width, .width = view->container->current.content_width,
.height = view->container->current.view_height, .height = view->container->current.content_height,
.rotation = 0, // TODO .rotation = 0, // TODO
}; };
@ -179,12 +179,12 @@ void output_view_for_each_popup(struct sway_output *output,
.user_iterator = iterator, .user_iterator = iterator,
.user_data = user_data, .user_data = user_data,
.output = output, .output = output,
.ox = view->container->current.view_x - output->wlr_output->lx .ox = view->container->current.content_x - output->wlr_output->lx
- view->geometry.x, - view->geometry.x,
.oy = view->container->current.view_y - output->wlr_output->ly .oy = view->container->current.content_y - output->wlr_output->ly
- view->geometry.y, - view->geometry.y,
.width = view->container->current.view_width, .width = view->container->current.content_width,
.height = view->container->current.view_height, .height = view->container->current.content_height,
.rotation = 0, // TODO .rotation = 0, // TODO
}; };
@ -473,10 +473,10 @@ void output_damage_whole_container(struct sway_output *output,
struct sway_container *con) { struct sway_container *con) {
// Pad the box by 1px, because the width is a double and might be a fraction // Pad the box by 1px, because the width is a double and might be a fraction
struct wlr_box box = { struct wlr_box box = {
.x = con->current.con_x - output->wlr_output->lx - 1, .x = con->current.x - output->wlr_output->lx - 1,
.y = con->current.con_y - output->wlr_output->ly - 1, .y = con->current.y - output->wlr_output->ly - 1,
.width = con->current.con_width + 2, .width = con->current.width + 2,
.height = con->current.con_height + 2, .height = con->current.height + 2,
}; };
scale_box(&box, output->wlr_output->scale); scale_box(&box, output->wlr_output->scale);
wlr_output_damage_add_box(output->damage, &box); wlr_output_damage_add_box(output->damage, &box);

View file

@ -211,9 +211,9 @@ static void render_view_toplevels(struct sway_view *view,
.alpha = alpha, .alpha = alpha,
}; };
// Render all toplevels without descending into popups // Render all toplevels without descending into popups
double ox = view->container->current.view_x - double ox = view->container->current.content_x -
output->wlr_output->lx - view->geometry.x; output->wlr_output->lx - view->geometry.x;
double oy = view->container->current.view_y - double oy = view->container->current.content_y -
output->wlr_output->ly - view->geometry.y; output->wlr_output->ly - view->geometry.y;
output_surface_for_each_surface(output, view->surface, ox, oy, output_surface_for_each_surface(output, view->surface, ox, oy,
render_surface_iterator, &data); render_surface_iterator, &data);
@ -247,9 +247,9 @@ static void render_saved_view(struct sway_view *view,
return; return;
} }
struct wlr_box box = { struct wlr_box box = {
.x = view->container->current.view_x - output->wlr_output->lx - .x = view->container->current.content_x - output->wlr_output->lx -
view->saved_geometry.x, view->saved_geometry.x,
.y = view->container->current.view_y - output->wlr_output->ly - .y = view->container->current.content_y - output->wlr_output->ly -
view->saved_geometry.y, view->saved_geometry.y,
.width = view->saved_buffer_width, .width = view->saved_buffer_width,
.height = view->saved_buffer_height, .height = view->saved_buffer_height,
@ -300,10 +300,10 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
if (state->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 = state->con_x; box.x = state->x;
box.y = state->view_y; box.y = state->content_y;
box.width = state->border_thickness; box.width = state->border_thickness;
box.height = state->view_height; box.height = state->content_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);
} }
@ -319,10 +319,10 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
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 = state->view_x + state->view_width; box.x = state->content_x + state->content_width;
box.y = state->view_y; box.y = state->content_y;
box.width = state->border_thickness; box.width = state->border_thickness;
box.height = state->view_height; box.height = state->content_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);
} }
@ -334,9 +334,9 @@ static void render_view(struct sway_output *output, pixman_region32_t *damage,
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 = state->con_x; box.x = state->x;
box.y = state->view_y + state->view_height; box.y = state->content_y + state->content_height;
box.width = state->con_width; box.width = state->width;
box.height = state->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);
@ -585,9 +585,9 @@ 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 = state->con_x; box.x = state->x;
box.y = state->con_y; box.y = state->y;
box.width = state->con_width; box.width = state->width;
box.height = state->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);
@ -641,8 +641,8 @@ static void render_containers_linear(struct sway_output *output,
} }
if (state->border == B_NORMAL) { if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, state->con_x, render_titlebar(output, damage, child, state->x,
state->con_y, state->con_width, colors, state->y, state->width, colors,
title_texture, marks_texture); title_texture, marks_texture);
} else if (state->border == B_PIXEL) { } else if (state->border == B_PIXEL) {
render_top_border(output, damage, child, colors); render_top_border(output, damage, child, colors);
@ -696,7 +696,7 @@ static void render_containers_tabbed(struct sway_output *output,
marks_texture = child->marks_unfocused; marks_texture = child->marks_unfocused;
} }
int x = cstate->con_x + tab_width * i; int x = cstate->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 == parent->children->length - 1) { if (i == parent->children->length - 1) {
@ -801,10 +801,10 @@ static void render_container(struct sway_output *output,
struct parent_data data = { struct parent_data data = {
.layout = con->current.layout, .layout = con->current.layout,
.box = { .box = {
.x = con->current.con_x, .x = con->current.x,
.y = con->current.con_y, .y = con->current.y,
.width = con->current.con_width, .width = con->current.width,
.height = con->current.con_height, .height = con->current.height,
}, },
.children = con->current.children, .children = con->current.children,
.focused = focused, .focused = focused,
@ -853,8 +853,8 @@ static void render_floating_container(struct sway_output *soutput,
} }
if (con->current.border == B_NORMAL) { if (con->current.border == B_NORMAL) {
render_titlebar(soutput, damage, con, con->current.con_x, render_titlebar(soutput, damage, con, con->current.x,
con->current.con_y, con->current.con_width, colors, con->current.y, con->current.width, colors,
title_texture, marks_texture); title_texture, marks_texture);
} else if (con->current.border == B_PIXEL) { } else if (con->current.border == B_PIXEL) {
render_top_border(soutput, damage, con, colors); render_top_border(soutput, damage, con, colors);

View file

@ -130,10 +130,10 @@ static void copy_container_state(struct sway_container *container,
struct sway_container_state *state = &instruction->container_state; struct sway_container_state *state = &instruction->container_state;
state->layout = container->layout; state->layout = container->layout;
state->con_x = container->x; state->x = container->x;
state->con_y = container->y; state->y = container->y;
state->con_width = container->width; state->width = container->width;
state->con_height = container->height; state->height = container->height;
state->is_fullscreen = container->is_fullscreen; state->is_fullscreen = container->is_fullscreen;
state->parent = container->parent; state->parent = container->parent;
state->workspace = container->workspace; state->workspace = container->workspace;
@ -143,14 +143,12 @@ static void copy_container_state(struct sway_container *container,
state->border_left = container->border_left; state->border_left = container->border_left;
state->border_right = container->border_right; state->border_right = container->border_right;
state->border_bottom = container->border_bottom; state->border_bottom = container->border_bottom;
state->content_x = container->content_x;
state->content_y = container->content_y;
state->content_width = container->content_width;
state->content_height = container->content_height;
if (container->view) { if (!container->view) {
struct sway_view *view = container->view;
state->view_x = view->x;
state->view_y = view->y;
state->view_width = view->width;
state->view_height = view->height;
} else {
state->children = create_list(); state->children = create_list();
list_cat(state->children, container->children); list_cat(state->children, container->children);
} }
@ -217,8 +215,8 @@ static void apply_container_state(struct sway_container *container,
desktop_damage_whole_container(container); desktop_damage_whole_container(container);
if (view && view->saved_buffer) { if (view && view->saved_buffer) {
struct wlr_box box = { struct wlr_box box = {
.x = container->current.view_x - view->saved_geometry.x, .x = container->current.content_x - view->saved_geometry.x,
.y = container->current.view_y - view->saved_geometry.y, .y = container->current.content_y - view->saved_geometry.y,
.width = view->saved_buffer_width, .width = view->saved_buffer_width,
.height = view->saved_buffer_height, .height = view->saved_buffer_height,
}; };
@ -245,8 +243,8 @@ static void apply_container_state(struct sway_container *container,
if (view && view->surface) { if (view && view->surface) {
struct wlr_surface *surface = view->surface; struct wlr_surface *surface = view->surface;
struct wlr_box box = { struct wlr_box box = {
.x = container->current.view_x - view->geometry.x, .x = container->current.content_x - view->geometry.x,
.y = container->current.view_y - view->geometry.y, .y = container->current.content_y - view->geometry.y,
.width = surface->current.width, .width = surface->current.width,
.height = surface->current.height, .height = surface->current.height,
}; };
@ -386,14 +384,14 @@ static bool should_configure(struct sway_node *node,
// Xwayland views are position-aware and need to be reconfigured // Xwayland views are position-aware and need to be reconfigured
// when their position changes. // when their position changes.
if (node->sway_container->view->type == SWAY_VIEW_XWAYLAND) { if (node->sway_container->view->type == SWAY_VIEW_XWAYLAND) {
if (cstate->view_x != istate->view_x || if (cstate->content_x != istate->content_x ||
cstate->view_y != istate->view_y) { cstate->content_y != istate->content_y) {
return true; return true;
} }
} }
#endif #endif
if (cstate->view_width == istate->view_width && if (cstate->content_width == istate->content_width &&
cstate->view_height == istate->view_height) { cstate->content_height == istate->content_height) {
return false; return false;
} }
return true; return true;
@ -409,10 +407,10 @@ static void transaction_commit(struct sway_transaction *transaction) {
struct sway_node *node = instruction->node; struct sway_node *node = instruction->node;
if (should_configure(node, instruction)) { if (should_configure(node, instruction)) {
instruction->serial = view_configure(node->sway_container->view, instruction->serial = view_configure(node->sway_container->view,
instruction->container_state.view_x, instruction->container_state.content_x,
instruction->container_state.view_y, instruction->container_state.content_y,
instruction->container_state.view_width, instruction->container_state.content_width,
instruction->container_state.view_height); instruction->container_state.content_height);
++transaction->num_waiting; ++transaction->num_waiting;
// From here on we are rendering a saved buffer of the view, which // From here on we are rendering a saved buffer of the view, which
@ -504,8 +502,8 @@ void transaction_notify_view_ready_by_size(struct sway_view *view,
int width, int height) { int width, int height) {
struct sway_transaction_instruction *instruction = struct sway_transaction_instruction *instruction =
view->container->node.instruction; view->container->node.instruction;
if (instruction->container_state.view_width == width && if (instruction->container_state.content_width == width &&
instruction->container_state.view_height == height) { instruction->container_state.content_height == height) {
set_instruction_ready(instruction); set_instruction_ready(instruction);
} }
} }

View file

@ -75,8 +75,8 @@ static void popup_unconstrain(struct sway_xdg_popup *popup) {
// the output box expressed in the coordinate system of the toplevel parent // the output box expressed in the coordinate system of the toplevel parent
// of the popup // of the popup
struct wlr_box output_toplevel_sx_box = { struct wlr_box output_toplevel_sx_box = {
.x = output->lx - view->x, .x = output->lx - view->container->content_x,
.y = output->ly - view->y, .y = output->ly - view->container->content_y,
.width = output->width, .width = output->width,
.height = output->height, .height = output->height,
}; };
@ -286,9 +286,11 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} else { } else {
struct wlr_box new_geo; struct wlr_box new_geo;
wlr_xdg_surface_get_geometry(xdg_surface, &new_geo); wlr_xdg_surface_get_geometry(xdg_surface, &new_geo);
struct sway_container *con = view->container;
if ((new_geo.width != view->width || new_geo.height != view->height) && if ((new_geo.width != con->content_width ||
container_is_floating(view->container)) { new_geo.height != con->content_height) &&
container_is_floating(con)) {
// A floating view has unexpectedly sent a new size // A floating view has unexpectedly sent a new size
desktop_damage_view(view); desktop_damage_view(view);
view_update_size(view, new_geo.width, new_geo.height); view_update_size(view, new_geo.width, new_geo.height);

View file

@ -74,8 +74,8 @@ static void popup_unconstrain(struct sway_xdg_popup_v6 *popup) {
// the output box expressed in the coordinate system of the toplevel parent // the output box expressed in the coordinate system of the toplevel parent
// of the popup // of the popup
struct wlr_box output_toplevel_sx_box = { struct wlr_box output_toplevel_sx_box = {
.x = output->lx - view->x, .x = output->lx - view->container->content_x,
.y = output->ly - view->y, .y = output->ly - view->container->content_y,
.width = output->width, .width = output->width,
.height = output->height, .height = output->height,
}; };
@ -283,9 +283,11 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} else { } else {
struct wlr_box new_geo; struct wlr_box new_geo;
wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &new_geo); wlr_xdg_surface_v6_get_geometry(xdg_surface_v6, &new_geo);
struct sway_container *con = view->container;
if ((new_geo.width != view->width || new_geo.height != view->height) && if ((new_geo.width != con->content_width ||
container_is_floating(view->container)) { new_geo.height != con->content_height) &&
container_is_floating(con)) {
// A floating view has unexpectedly sent a new size // A floating view has unexpectedly sent a new size
desktop_damage_view(view); desktop_damage_view(view);
view_update_size(view, new_geo.width, new_geo.height); view_update_size(view, new_geo.width, new_geo.height);

View file

@ -332,9 +332,11 @@ static void handle_commit(struct wl_listener *listener, void *data) {
} else { } else {
struct wlr_box new_geo; struct wlr_box new_geo;
get_geometry(view, &new_geo); get_geometry(view, &new_geo);
struct sway_container *con = view->container;
if ((new_geo.width != view->width || new_geo.height != view->height) && if ((new_geo.width != con->content_width ||
container_is_floating(view->container)) { new_geo.height != con->content_height) &&
container_is_floating(con)) {
// A floating view has unexpectedly sent a new size // A floating view has unexpectedly sent a new size
// eg. The Firefox "Save As" dialog when downloading a file // eg. The Firefox "Save As" dialog when downloading a file
desktop_damage_view(view); desktop_damage_view(view);
@ -432,13 +434,13 @@ static void handle_request_configure(struct wl_listener *listener, void *data) {
return; return;
} }
if (container_is_floating(view->container)) { if (container_is_floating(view->container)) {
configure(view, view->container->current.view_x, configure(view, view->container->current.content_x,
view->container->current.view_y, ev->width, ev->height); view->container->current.content_y, ev->width, ev->height);
} else { } else {
configure(view, view->container->current.view_x, configure(view, view->container->current.content_x,
view->container->current.view_y, view->container->current.content_y,
view->container->current.view_width, view->container->current.content_width,
view->container->current.view_height); view->container->current.content_height);
} }
} }

View file

@ -348,7 +348,7 @@ static void handle_move_tiling_motion(struct sway_seat *seat,
} }
// Find the closest edge // Find the closest edge
size_t thickness = fmin(con->view->width, con->view->height) * 0.3; size_t thickness = fmin(con->content_width, con->content_height) * 0.3;
size_t closest_dist = INT_MAX; size_t closest_dist = INT_MAX;
size_t dist; size_t dist;
seat->op_target_edge = WLR_EDGE_NONE; seat->op_target_edge = WLR_EDGE_NONE;
@ -374,10 +374,10 @@ static void handle_move_tiling_motion(struct sway_seat *seat,
} }
seat->op_target_node = node; seat->op_target_node = node;
seat->op_drop_box.x = con->view->x; seat->op_drop_box.x = con->content_x;
seat->op_drop_box.y = con->view->y; seat->op_drop_box.y = con->content_y;
seat->op_drop_box.width = con->view->width; seat->op_drop_box.width = con->content_width;
seat->op_drop_box.height = con->view->height; seat->op_drop_box.height = con->content_height;
resize_box(&seat->op_drop_box, seat->op_target_edge, thickness); resize_box(&seat->op_drop_box, seat->op_target_edge, thickness);
desktop_damage_box(&seat->op_drop_box); desktop_damage_box(&seat->op_drop_box);
} }
@ -498,13 +498,10 @@ static void handle_resize_floating_motion(struct sway_seat *seat,
con->width += relative_grow_width; con->width += relative_grow_width;
con->height += relative_grow_height; con->height += relative_grow_height;
if (con->view) { con->content_x += relative_grow_x;
struct sway_view *view = con->view; con->content_y += relative_grow_y;
view->x += relative_grow_x; con->content_width += relative_grow_width;
view->y += relative_grow_y; con->content_height += relative_grow_height;
view->width += relative_grow_width;
view->height += relative_grow_height;
}
arrange_container(con); arrange_container(con);
} }

View file

@ -246,10 +246,10 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
json_object_object_add(object, "marks", marks); json_object_object_add(object, "marks", marks);
struct wlr_box window_box = { struct wlr_box window_box = {
c->view->x - c->x, c->content_x - c->x,
(c->current.border == B_PIXEL) ? c->current.border_thickness : 0, (c->current.border == B_PIXEL) ? c->current.border_thickness : 0,
c->view->width, c->content_width,
c->view->height c->content_height
}; };
json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box)); json_object_object_add(object, "window_rect", ipc_json_create_rect(&window_box));
@ -258,7 +258,7 @@ static void ipc_json_describe_view(struct sway_container *c, json_object *object
if (c->current.border == B_NORMAL) { if (c->current.border == B_NORMAL) {
deco_box.width = c->width; deco_box.width = c->width;
deco_box.height = c->view->y - c->y; deco_box.height = c->content_y - c->y;
} }
json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box)); json_object_object_add(object, "deco_rect", ipc_json_create_rect(&deco_box));

View file

@ -165,8 +165,8 @@ static struct sway_container *surface_at_view(struct sway_container *con, double
return NULL; return NULL;
} }
struct sway_view *view = con->view; struct sway_view *view = con->view;
double view_sx = lx - view->x + view->geometry.x; double view_sx = lx - con->content_x + view->geometry.x;
double view_sy = ly - view->y + view->geometry.y; double view_sy = ly - con->content_y + view->geometry.y;
double _sx, _sy; double _sx, _sy;
struct wlr_surface *_surface = NULL; struct wlr_surface *_surface = NULL;
@ -641,16 +641,18 @@ void container_init_floating(struct sway_container *con) {
con->y = ws->y + (ws->height - con->height) / 2; con->y = ws->y + (ws->height - con->height) / 2;
} else { } else {
struct sway_view *view = con->view; struct sway_view *view = con->view;
view->width = fmax(min_width, fmin(view->natural_width, max_width)); con->content_width =
view->height = fmax(min_height, fmin(view->natural_height, max_height)); fmax(min_width, fmin(view->natural_width, max_width));
view->x = ws->x + (ws->width - view->width) / 2; con->content_height =
view->y = ws->y + (ws->height - view->height) / 2; fmax(min_height, fmin(view->natural_height, max_height));
con->content_x = ws->x + (ws->width - con->content_width) / 2;
con->content_y = ws->y + (ws->height - con->content_height) / 2;
// If the view's border is B_NONE then these properties are ignored. // If the view's border is B_NONE then these properties are ignored.
con->border_top = con->border_bottom = true; con->border_top = con->border_bottom = true;
con->border_left = con->border_right = true; con->border_left = con->border_right = true;
container_set_geometry_from_floating_view(con); container_set_geometry_from_content(con);
} }
} }
@ -707,14 +709,13 @@ void container_set_floating(struct sway_container *container, bool enable) {
ipc_event_window(container, "floating"); ipc_event_window(container, "floating");
} }
void container_set_geometry_from_floating_view(struct sway_container *con) { void container_set_geometry_from_content(struct sway_container *con) {
if (!sway_assert(con->view, "Expected a view")) { if (!sway_assert(con->view, "Expected a view")) {
return; return;
} }
if (!sway_assert(container_is_floating(con), "Expected a floating view")) { if (!sway_assert(container_is_floating(con), "Expected a floating view")) {
return; return;
} }
struct sway_view *view = con->view;
size_t border_width = 0; size_t border_width = 0;
size_t top = 0; size_t top = 0;
@ -724,10 +725,10 @@ void container_set_geometry_from_floating_view(struct sway_container *con) {
container_titlebar_height() : border_width; container_titlebar_height() : border_width;
} }
con->x = view->x - border_width; con->x = con->content_x - border_width;
con->y = view->y - top; con->y = con->content_y - top;
con->width = view->width + border_width * 2; con->width = con->content_width + border_width * 2;
con->height = top + view->height + border_width; con->height = top + con->content_height + border_width;
node_set_dirty(&con->node); node_set_dirty(&con->node);
} }
@ -756,15 +757,16 @@ void container_floating_translate(struct sway_container *con,
double x_amount, double y_amount) { double x_amount, double y_amount) {
con->x += x_amount; con->x += x_amount;
con->y += y_amount; con->y += y_amount;
if (con->view) { con->content_x += x_amount;
con->view->x += x_amount; con->content_y += y_amount;
con->view->y += y_amount;
} else { if (con->children) {
for (int i = 0; i < con->children->length; ++i) { for (int i = 0; i < con->children->length; ++i) {
struct sway_container *child = con->children->items[i]; struct sway_container *child = con->children->items[i];
container_floating_translate(child, x_amount, y_amount); container_floating_translate(child, x_amount, y_amount);
} }
} }
node_set_dirty(&con->node); node_set_dirty(&con->node);
} }
@ -964,10 +966,10 @@ static void surface_send_leave_iterator(struct wlr_surface *surface,
void container_discover_outputs(struct sway_container *con) { void container_discover_outputs(struct sway_container *con) {
struct wlr_box con_box = { struct wlr_box con_box = {
.x = con->current.con_x, .x = con->current.x,
.y = con->current.con_y, .y = con->current.y,
.width = con->current.con_width, .width = con->current.width,
.height = con->current.con_height, .height = con->current.height,
}; };
struct sway_output *old_output = container_get_effective_output(con); struct sway_output *old_output = container_get_effective_output(con);

View file

@ -196,22 +196,22 @@ static bool gaps_to_edge(struct sway_view *view) {
} }
void view_autoconfigure(struct sway_view *view) { void view_autoconfigure(struct sway_view *view) {
if (!view->container->workspace) { struct sway_container *con = view->container;
if (!con->workspace) {
// Hidden in the scratchpad // Hidden in the scratchpad
return; return;
} }
struct sway_output *output = view->container->workspace->output; struct sway_output *output = con->workspace->output;
if (view->container->is_fullscreen) { if (con->is_fullscreen) {
view->x = output->lx; con->content_x = output->lx;
view->y = output->ly; con->content_y = output->ly;
view->width = output->width; con->content_width = output->width;
view->height = output->height; con->content_height = output->height;
return; return;
} }
struct sway_workspace *ws = view->container->workspace; struct sway_workspace *ws = view->container->workspace;
struct sway_container *con = view->container;
bool smart = config->hide_edge_borders == E_SMART || bool smart = config->hide_edge_borders == E_SMART ||
config->hide_edge_borders == E_SMART_NO_GAPS; config->hide_edge_borders == E_SMART_NO_GAPS;
@ -289,10 +289,10 @@ void view_autoconfigure(struct sway_view *view) {
break; break;
} }
view->x = x; con->content_x = x;
view->y = y; con->content_y = y;
view->width = width; con->content_width = width;
view->height = height; con->content_height = height;
} }
void view_set_activated(struct sway_view *view, bool activated) { void view_set_activated(struct sway_view *view, bool activated) {
@ -667,11 +667,11 @@ void view_update_size(struct sway_view *view, int width, int height) {
"Expected a floating container")) { "Expected a floating container")) {
return; return;
} }
view->width = width; view->container->content_width = width;
view->height = height; view->container->content_height = height;
view->container->current.view_width = width; view->container->current.content_width = width;
view->container->current.view_height = height; view->container->current.content_height = height;
container_set_geometry_from_floating_view(view->container); container_set_geometry_from_content(view->container);
} }
static void subsurface_get_root_coords(struct sway_view_child *child, static void subsurface_get_root_coords(struct sway_view_child *child,
@ -707,7 +707,8 @@ static void view_child_damage(struct sway_view_child *child, bool whole) {
int sx, sy; int sx, sy;
child->impl->get_root_coords(child, &sx, &sy); child->impl->get_root_coords(child, &sx, &sy);
desktop_damage_surface(child->surface, desktop_damage_surface(child->surface,
child->view->x + sx, child->view->y + sy, whole); child->view->container->content_x + sx,
child->view->container->content_y + sy, whole);
} }
static void view_child_handle_surface_commit(struct wl_listener *listener, static void view_child_handle_surface_commit(struct wl_listener *listener,