aboutsummaryrefslogtreecommitdiff
path: root/sway/tree/container.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/tree/container.c')
-rw-r--r--sway/tree/container.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 6da5ac3c..aecb2ac6 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -533,11 +533,10 @@ struct sway_container *container_parent(struct sway_container *container,
return container;
}
-static struct sway_container *container_at_view(struct sway_container *swayc,
- double lx, double ly,
+static void surface_at_view(struct sway_container *swayc, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) {
if (!sway_assert(swayc->type == C_VIEW, "Expected a view")) {
- return NULL;
+ return;
}
struct sway_view *sview = swayc->sway_view;
double view_sx = lx - sview->x;
@@ -567,9 +566,7 @@ static struct sway_container *container_at_view(struct sway_container *swayc,
*sx = _sx;
*sy = _sy;
*surface = _surface;
- return swayc;
}
- return NULL;
}
/**
@@ -682,7 +679,8 @@ struct sway_container *tiling_container_at(
struct sway_container *con, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy) {
if (con->type == C_VIEW) {
- return container_at_view(con, lx, ly, surface, sx, sy);
+ surface_at_view(con, lx, ly, surface, sx, sy);
+ return con;
}
if (!con->children->length) {
return NULL;
@@ -745,7 +743,7 @@ struct sway_container *container_at(struct sway_container *workspace,
struct sway_container *focus =
seat_get_focus_inactive(seat, &root_container);
if (focus && focus->type == C_VIEW) {
- container_at_view(focus, lx, ly, surface, sx, sy);
+ surface_at_view(focus, lx, ly, surface, sx, sy);
if (*surface && surface_is_popup(*surface)) {
return focus;
}
@@ -1163,19 +1161,16 @@ void container_floating_translate(struct sway_container *con,
double x_amount, double y_amount) {
con->x += x_amount;
con->y += y_amount;
- con->current.swayc_x += x_amount;
- con->current.swayc_y += y_amount;
if (con->type == C_VIEW) {
con->sway_view->x += x_amount;
con->sway_view->y += y_amount;
- con->current.view_x += x_amount;
- con->current.view_y += y_amount;
} else {
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);
}
}
+ container_set_dirty(con);
}
/**
@@ -1185,7 +1180,7 @@ void container_floating_translate(struct sway_container *con,
* one, otherwise we'll choose whichever output is closest to the container's
* center.
*/
-static struct sway_container *container_floating_find_output(
+struct sway_container *container_floating_find_output(
struct sway_container *con) {
double center_x = con->x + con->width / 2;
double center_y = con->y + con->height / 2;
@@ -1219,9 +1214,7 @@ void container_floating_move_to(struct sway_container *con,
"Expected a floating container")) {
return;
}
- desktop_damage_whole_container(con);
container_floating_translate(con, lx - con->x, ly - con->y);
- desktop_damage_whole_container(con);
struct sway_container *old_workspace = container_parent(con, C_WORKSPACE);
struct sway_container *new_output = container_floating_find_output(con);
if (!sway_assert(new_output, "Unable to find any output")) {
@@ -1239,6 +1232,17 @@ void container_floating_move_to(struct sway_container *con,
}
}
+void container_floating_move_to_center(struct sway_container *con) {
+ if (!sway_assert(container_is_floating(con),
+ "Expected a floating container")) {
+ return;
+ }
+ struct sway_container *ws = container_parent(con, C_WORKSPACE);
+ double new_lx = ws->x + (ws->width - con->width) / 2;
+ double new_ly = ws->y + (ws->height - con->height) / 2;
+ container_floating_translate(con, new_lx - con->x, new_ly - con->y);
+}
+
void container_set_dirty(struct sway_container *container) {
if (container->dirty) {
return;
@@ -1318,6 +1322,11 @@ void container_set_fullscreen(struct sway_container *container, bool enable) {
container->y = container->saved_y;
container->width = container->saved_width;
container->height = container->saved_height;
+ struct sway_container *output =
+ container_floating_find_output(container);
+ if (!container_has_ancestor(container, output)) {
+ container_floating_move_to_center(container);
+ }
} else {
container->width = container->saved_width;
container->height = container->saved_height;