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

@ -165,8 +165,8 @@ static struct sway_container *surface_at_view(struct sway_container *con, double
return NULL;
}
struct sway_view *view = con->view;
double view_sx = lx - view->x + view->geometry.x;
double view_sy = ly - view->y + view->geometry.y;
double view_sx = lx - con->content_x + view->geometry.x;
double view_sy = ly - con->content_y + view->geometry.y;
double _sx, _sy;
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;
} else {
struct sway_view *view = con->view;
view->width = fmax(min_width, fmin(view->natural_width, max_width));
view->height = fmax(min_height, fmin(view->natural_height, max_height));
view->x = ws->x + (ws->width - view->width) / 2;
view->y = ws->y + (ws->height - view->height) / 2;
con->content_width =
fmax(min_width, fmin(view->natural_width, max_width));
con->content_height =
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.
con->border_top = con->border_bottom = 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");
}
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")) {
return;
}
if (!sway_assert(container_is_floating(con), "Expected a floating view")) {
return;
}
struct sway_view *view = con->view;
size_t border_width = 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;
}
con->x = view->x - border_width;
con->y = view->y - top;
con->width = view->width + border_width * 2;
con->height = top + view->height + border_width;
con->x = con->content_x - border_width;
con->y = con->content_y - top;
con->width = con->content_width + border_width * 2;
con->height = top + con->content_height + border_width;
node_set_dirty(&con->node);
}
@ -756,15 +757,16 @@ void container_floating_translate(struct sway_container *con,
double x_amount, double y_amount) {
con->x += x_amount;
con->y += y_amount;
if (con->view) {
con->view->x += x_amount;
con->view->y += y_amount;
} else {
con->content_x += x_amount;
con->content_y += y_amount;
if (con->children) {
for (int i = 0; i < con->children->length; ++i) {
struct sway_container *child = con->children->items[i];
container_floating_translate(child, x_amount, y_amount);
}
}
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) {
struct wlr_box con_box = {
.x = con->current.con_x,
.y = con->current.con_y,
.width = con->current.con_width,
.height = con->current.con_height,
.x = con->current.x,
.y = con->current.y,
.width = con->current.width,
.height = con->current.height,
};
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) {
if (!view->container->workspace) {
struct sway_container *con = view->container;
if (!con->workspace) {
// Hidden in the scratchpad
return;
}
struct sway_output *output = view->container->workspace->output;
struct sway_output *output = con->workspace->output;
if (view->container->is_fullscreen) {
view->x = output->lx;
view->y = output->ly;
view->width = output->width;
view->height = output->height;
if (con->is_fullscreen) {
con->content_x = output->lx;
con->content_y = output->ly;
con->content_width = output->width;
con->content_height = output->height;
return;
}
struct sway_workspace *ws = view->container->workspace;
struct sway_container *con = view->container;
bool smart = config->hide_edge_borders == E_SMART ||
config->hide_edge_borders == E_SMART_NO_GAPS;
@ -289,10 +289,10 @@ void view_autoconfigure(struct sway_view *view) {
break;
}
view->x = x;
view->y = y;
view->width = width;
view->height = height;
con->content_x = x;
con->content_y = y;
con->content_width = width;
con->content_height = height;
}
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")) {
return;
}
view->width = width;
view->height = height;
view->container->current.view_width = width;
view->container->current.view_height = height;
container_set_geometry_from_floating_view(view->container);
view->container->content_width = width;
view->container->content_height = height;
view->container->current.content_width = width;
view->container->current.content_height = height;
container_set_geometry_from_content(view->container);
}
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;
child->impl->get_root_coords(child, &sx, &sy);
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,