aboutsummaryrefslogtreecommitdiffstats
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,
533 return container; 533 return container;
534} 534}
535 535
536static struct sway_container *container_at_view(struct sway_container *swayc, 536static void surface_at_view(struct sway_container *swayc, double lx, double ly,
537 double lx, double ly,
538 struct wlr_surface **surface, double *sx, double *sy) { 537 struct wlr_surface **surface, double *sx, double *sy) {
539 if (!sway_assert(swayc->type == C_VIEW, "Expected a view")) { 538 if (!sway_assert(swayc->type == C_VIEW, "Expected a view")) {
540 return NULL; 539 return;
541 } 540 }
542 struct sway_view *sview = swayc->sway_view; 541 struct sway_view *sview = swayc->sway_view;
543 double view_sx = lx - sview->x; 542 double view_sx = lx - sview->x;
@@ -567,9 +566,7 @@ static struct sway_container *container_at_view(struct sway_container *swayc,
567 *sx = _sx; 566 *sx = _sx;
568 *sy = _sy; 567 *sy = _sy;
569 *surface = _surface; 568 *surface = _surface;
570 return swayc;
571 } 569 }
572 return NULL;
573} 570}
574 571
575/** 572/**
@@ -682,7 +679,8 @@ struct sway_container *tiling_container_at(
682 struct sway_container *con, double lx, double ly, 679 struct sway_container *con, double lx, double ly,
683 struct wlr_surface **surface, double *sx, double *sy) { 680 struct wlr_surface **surface, double *sx, double *sy) {
684 if (con->type == C_VIEW) { 681 if (con->type == C_VIEW) {
685 return container_at_view(con, lx, ly, surface, sx, sy); 682 surface_at_view(con, lx, ly, surface, sx, sy);
683 return con;
686 } 684 }
687 if (!con->children->length) { 685 if (!con->children->length) {
688 return NULL; 686 return NULL;
@@ -745,7 +743,7 @@ struct sway_container *container_at(struct sway_container *workspace,
745 struct sway_container *focus = 743 struct sway_container *focus =
746 seat_get_focus_inactive(seat, &root_container); 744 seat_get_focus_inactive(seat, &root_container);
747 if (focus && focus->type == C_VIEW) { 745 if (focus && focus->type == C_VIEW) {
748 container_at_view(focus, lx, ly, surface, sx, sy); 746 surface_at_view(focus, lx, ly, surface, sx, sy);
749 if (*surface && surface_is_popup(*surface)) { 747 if (*surface && surface_is_popup(*surface)) {
750 return focus; 748 return focus;
751 } 749 }
@@ -1163,19 +1161,16 @@ void container_floating_translate(struct sway_container *con,
1163 double x_amount, double y_amount) { 1161 double x_amount, double y_amount) {
1164 con->x += x_amount; 1162 con->x += x_amount;
1165 con->y += y_amount; 1163 con->y += y_amount;
1166 con->current.swayc_x += x_amount;
1167 con->current.swayc_y += y_amount;
1168 if (con->type == C_VIEW) { 1164 if (con->type == C_VIEW) {
1169 con->sway_view->x += x_amount; 1165 con->sway_view->x += x_amount;
1170 con->sway_view->y += y_amount; 1166 con->sway_view->y += y_amount;
1171 con->current.view_x += x_amount;
1172 con->current.view_y += y_amount;
1173 } else { 1167 } else {
1174 for (int i = 0; i < con->children->length; ++i) { 1168 for (int i = 0; i < con->children->length; ++i) {
1175 struct sway_container *child = con->children->items[i]; 1169 struct sway_container *child = con->children->items[i];
1176 container_floating_translate(child, x_amount, y_amount); 1170 container_floating_translate(child, x_amount, y_amount);
1177 } 1171 }
1178 } 1172 }
1173 container_set_dirty(con);
1179} 1174}
1180 1175
1181/** 1176/**
@@ -1185,7 +1180,7 @@ void container_floating_translate(struct sway_container *con,
1185 * one, otherwise we'll choose whichever output is closest to the container's 1180 * one, otherwise we'll choose whichever output is closest to the container's
1186 * center. 1181 * center.
1187 */ 1182 */
1188static struct sway_container *container_floating_find_output( 1183struct sway_container *container_floating_find_output(
1189 struct sway_container *con) { 1184 struct sway_container *con) {
1190 double center_x = con->x + con->width / 2; 1185 double center_x = con->x + con->width / 2;
1191 double center_y = con->y + con->height / 2; 1186 double center_y = con->y + con->height / 2;
@@ -1219,9 +1214,7 @@ void container_floating_move_to(struct sway_container *con,
1219 "Expected a floating container")) { 1214 "Expected a floating container")) {
1220 return; 1215 return;
1221 } 1216 }
1222 desktop_damage_whole_container(con);
1223 container_floating_translate(con, lx - con->x, ly - con->y); 1217 container_floating_translate(con, lx - con->x, ly - con->y);
1224 desktop_damage_whole_container(con);
1225 struct sway_container *old_workspace = container_parent(con, C_WORKSPACE); 1218 struct sway_container *old_workspace = container_parent(con, C_WORKSPACE);
1226 struct sway_container *new_output = container_floating_find_output(con); 1219 struct sway_container *new_output = container_floating_find_output(con);
1227 if (!sway_assert(new_output, "Unable to find any output")) { 1220 if (!sway_assert(new_output, "Unable to find any output")) {
@@ -1239,6 +1232,17 @@ void container_floating_move_to(struct sway_container *con,
1239 } 1232 }
1240} 1233}
1241 1234
1235void container_floating_move_to_center(struct sway_container *con) {
1236 if (!sway_assert(container_is_floating(con),
1237 "Expected a floating container")) {
1238 return;
1239 }
1240 struct sway_container *ws = container_parent(con, C_WORKSPACE);
1241 double new_lx = ws->x + (ws->width - con->width) / 2;
1242 double new_ly = ws->y + (ws->height - con->height) / 2;
1243 container_floating_translate(con, new_lx - con->x, new_ly - con->y);
1244}
1245
1242void container_set_dirty(struct sway_container *container) { 1246void container_set_dirty(struct sway_container *container) {
1243 if (container->dirty) { 1247 if (container->dirty) {
1244 return; 1248 return;
@@ -1318,6 +1322,11 @@ void container_set_fullscreen(struct sway_container *container, bool enable) {
1318 container->y = container->saved_y; 1322 container->y = container->saved_y;
1319 container->width = container->saved_width; 1323 container->width = container->saved_width;
1320 container->height = container->saved_height; 1324 container->height = container->saved_height;
1325 struct sway_container *output =
1326 container_floating_find_output(container);
1327 if (!container_has_ancestor(container, output)) {
1328 container_floating_move_to_center(container);
1329 }
1321 } else { 1330 } else {
1322 container->width = container->saved_width; 1331 container->width = container->saved_width;
1323 container->height = container->saved_height; 1332 container->height = container->saved_height;