aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree
diff options
context:
space:
mode:
authorLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-26 18:36:46 +1000
committerLibravatar Ryan Dwyer <ryandwyer1@gmail.com>2018-07-28 22:41:04 +1000
commit08cfba2192f5770d975c5fe70789a81aaee4dc7e (patch)
tree7f07e32020649ae5c049e8533f0cf040dc80e166 /sway/tree
parentMerge pull request #2372 from RyanDwyer/fix-use-after-free-v2 (diff)
downloadsway-08cfba2192f5770d975c5fe70789a81aaee4dc7e.tar.gz
sway-08cfba2192f5770d975c5fe70789a81aaee4dc7e.tar.zst
sway-08cfba2192f5770d975c5fe70789a81aaee4dc7e.zip
Allow containers to float
Things worth noting: * When a fullscreen view unmaps, the check to unset fullscreen on the workspace has been moved out of view_unmap and into container_destroy, because containers can be fullscreen too * The calls to `container_reap_empty_recursive(workspace)` have been removed from `container_set_floating`. That function reaps upwards so it wouldn't do anything. I'm probably the one who originally added it... * My fix (b14bd1b0b1536039e4f46fe94515c7c44e7afc61) for the tabbed child crash has a side effect where when you close a floating container, focus is not given to the tiled container again. I've removed my fix and removed the call to `send_cursor_motion` from `seat_set_focus_warp`. We should consider calling it from somewhere earlier in the call stack.
Diffstat (limited to 'sway/tree')
-rw-r--r--sway/tree/container.c82
-rw-r--r--sway/tree/layout.c19
-rw-r--r--sway/tree/view.c53
3 files changed, 90 insertions, 64 deletions
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 6ebf2653..566432b1 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -407,6 +407,10 @@ struct sway_container *container_flatten(struct sway_container *container) {
407 * This function just wraps container_destroy_noreaping(), then does reaping. 407 * This function just wraps container_destroy_noreaping(), then does reaping.
408 */ 408 */
409struct sway_container *container_destroy(struct sway_container *con) { 409struct sway_container *container_destroy(struct sway_container *con) {
410 if (con->is_fullscreen) {
411 struct sway_container *ws = container_parent(con, C_WORKSPACE);
412 ws->sway_workspace->fullscreen = NULL;
413 }
410 struct sway_container *parent = container_destroy_noreaping(con); 414 struct sway_container *parent = container_destroy_noreaping(con);
411 415
412 if (!parent) { 416 if (!parent) {
@@ -945,23 +949,81 @@ size_t container_titlebar_height() {
945 return config->font_height + TITLEBAR_V_PADDING * 2; 949 return config->font_height + TITLEBAR_V_PADDING * 2;
946} 950}
947 951
952void container_init_floating(struct sway_container *con) {
953 if (!sway_assert(con->type == C_VIEW || con->type == C_CONTAINER,
954 "Expected a view or container")) {
955 return;
956 }
957 struct sway_container *ws = container_parent(con, C_WORKSPACE);
958 int min_width, min_height;
959 int max_width, max_height;
960
961 if (config->floating_minimum_width == -1) { // no minimum
962 min_width = 0;
963 } else if (config->floating_minimum_width == 0) { // automatic
964 min_width = 75;
965 } else {
966 min_width = config->floating_minimum_width;
967 }
968
969 if (config->floating_minimum_height == -1) { // no minimum
970 min_height = 0;
971 } else if (config->floating_minimum_height == 0) { // automatic
972 min_height = 50;
973 } else {
974 min_height = config->floating_minimum_height;
975 }
976
977 if (config->floating_maximum_width == -1) { // no maximum
978 max_width = INT_MAX;
979 } else if (config->floating_maximum_width == 0) { // automatic
980 max_width = ws->width * 0.6666;
981 } else {
982 max_width = config->floating_maximum_width;
983 }
984
985 if (config->floating_maximum_height == -1) { // no maximum
986 max_height = INT_MAX;
987 } else if (config->floating_maximum_height == 0) { // automatic
988 max_height = ws->height * 0.6666;
989 } else {
990 max_height = config->floating_maximum_height;
991 }
992
993 if (con->type == C_CONTAINER) {
994 con->width = max_width;
995 con->height = max_height;
996 con->x = ws->x + (ws->width - con->width) / 2;
997 con->y = ws->y + (ws->height - con->height) / 2;
998 } else {
999 struct sway_view *view = con->sway_view;
1000 view->width = fmax(min_width, fmin(view->natural_width, max_width));
1001 view->height = fmax(min_height, fmin(view->natural_height, max_height));
1002 view->x = ws->x + (ws->width - view->width) / 2;
1003 view->y = ws->y + (ws->height - view->height) / 2;
1004
1005 // If the view's border is B_NONE then these properties are ignored.
1006 view->border_top = view->border_bottom = true;
1007 view->border_left = view->border_right = true;
1008
1009 container_set_geometry_from_floating_view(view->swayc);
1010 }
1011}
1012
948void container_set_floating(struct sway_container *container, bool enable) { 1013void container_set_floating(struct sway_container *container, bool enable) {
949 if (container_is_floating(container) == enable) { 1014 if (container_is_floating(container) == enable) {
950 return; 1015 return;
951 } 1016 }
952 1017
953 struct sway_container *workspace = container_parent(container, C_WORKSPACE); 1018 struct sway_container *workspace = container_parent(container, C_WORKSPACE);
954 struct sway_seat *seat = input_manager_current_seat(input_manager);
955 1019
956 if (enable) { 1020 if (enable) {
957 container_remove_child(container); 1021 container_remove_child(container);
958 container_add_child(workspace->sway_workspace->floating, container); 1022 container_add_child(workspace->sway_workspace->floating, container);
1023 container_init_floating(container);
959 if (container->type == C_VIEW) { 1024 if (container->type == C_VIEW) {
960 view_init_floating(container->sway_view);
961 view_set_tiled(container->sway_view, false); 1025 view_set_tiled(container->sway_view, false);
962 } 1026 }
963 seat_set_focus(seat, seat_get_focus_inactive(seat, container));
964 container_reap_empty_recursive(workspace);
965 } else { 1027 } else {
966 // Returning to tiled 1028 // Returning to tiled
967 if (container->scratchpad) { 1029 if (container->scratchpad) {
@@ -975,7 +1037,6 @@ void container_set_floating(struct sway_container *container, bool enable) {
975 view_set_tiled(container->sway_view, true); 1037 view_set_tiled(container->sway_view, true);
976 } 1038 }
977 container->is_sticky = false; 1039 container->is_sticky = false;
978 container_reap_empty_recursive(workspace->sway_workspace->floating);
979 } 1040 }
980 1041
981 container_end_mouse_operation(container); 1042 container_end_mouse_operation(container);
@@ -1195,6 +1256,17 @@ void container_set_fullscreen(struct sway_container *container, bool enable) {
1195 ipc_event_window(container, "fullscreen_mode"); 1256 ipc_event_window(container, "fullscreen_mode");
1196} 1257}
1197 1258
1259bool container_is_floating_or_child(struct sway_container *container) {
1260 do {
1261 if (container->parent && container->parent->layout == L_FLOATING) {
1262 return true;
1263 }
1264 container = container->parent;
1265 } while (container && container->type != C_WORKSPACE);
1266
1267 return false;
1268}
1269
1198bool container_is_fullscreen_or_child(struct sway_container *container) { 1270bool container_is_fullscreen_or_child(struct sway_container *container) {
1199 do { 1271 do {
1200 if (container->is_fullscreen) { 1272 if (container->is_fullscreen) {
diff --git a/sway/tree/layout.c b/sway/tree/layout.c
index ab5acc16..a0764a54 100644
--- a/sway/tree/layout.c
+++ b/sway/tree/layout.c
@@ -387,9 +387,11 @@ void container_move(struct sway_container *container,
387 // If moving a fullscreen view, only consider outputs 387 // If moving a fullscreen view, only consider outputs
388 if (container->is_fullscreen) { 388 if (container->is_fullscreen) {
389 current = container_parent(container, C_OUTPUT); 389 current = container_parent(container, C_OUTPUT);
390 } else if (container_is_fullscreen_or_child(container)) { 390 } else if (container_is_fullscreen_or_child(container) ||
391 container_is_floating_or_child(container)) {
391 // If we've fullscreened a split container, only allow the child to move 392 // If we've fullscreened a split container, only allow the child to move
392 // around within the fullscreen parent. 393 // around within the fullscreen parent.
394 // Same with floating a split container.
393 struct sway_container *ws = container_parent(container, C_WORKSPACE); 395 struct sway_container *ws = container_parent(container, C_WORKSPACE);
394 top = ws->sway_workspace->fullscreen; 396 top = ws->sway_workspace->fullscreen;
395 } 397 }
@@ -465,6 +467,9 @@ void container_move(struct sway_container *container,
465 if ((index == parent->children->length - 1 && offs > 0) 467 if ((index == parent->children->length - 1 && offs > 0)
466 || (index == 0 && offs < 0)) { 468 || (index == 0 && offs < 0)) {
467 if (current->parent == container->parent) { 469 if (current->parent == container->parent) {
470 if (parent->parent->layout == L_FLOATING) {
471 return;
472 }
468 if (!parent->is_fullscreen && 473 if (!parent->is_fullscreen &&
469 (parent->layout == L_TABBED || 474 (parent->layout == L_TABBED ||
470 parent->layout == L_STACKED)) { 475 parent->layout == L_STACKED)) {
@@ -488,10 +493,14 @@ void container_move(struct sway_container *container,
488 sibling = parent->children->items[index + offs]; 493 sibling = parent->children->items[index + offs];
489 wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id); 494 wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id);
490 } 495 }
491 } else if (!parent->is_fullscreen && (parent->layout == L_TABBED || 496 } else if (!parent->is_fullscreen &&
497 parent->parent->layout != L_FLOATING &&
498 (parent->layout == L_TABBED ||
492 parent->layout == L_STACKED)) { 499 parent->layout == L_STACKED)) {
493 move_out_of_tabs_stacks(container, current, move_dir, offs); 500 move_out_of_tabs_stacks(container, current, move_dir, offs);
494 return; 501 return;
502 } else if (parent->parent->layout == L_FLOATING) {
503 return;
495 } else { 504 } else {
496 wlr_log(WLR_DEBUG, "Moving up to find a parallel container"); 505 wlr_log(WLR_DEBUG, "Moving up to find a parallel container");
497 current = current->parent; 506 current = current->parent;
@@ -717,10 +726,6 @@ struct sway_container *container_get_in_direction(
717 enum movement_direction dir) { 726 enum movement_direction dir) {
718 struct sway_container *parent = container->parent; 727 struct sway_container *parent = container->parent;
719 728
720 if (container_is_floating(container)) {
721 return NULL;
722 }
723
724 if (dir == MOVE_CHILD) { 729 if (dir == MOVE_CHILD) {
725 return seat_get_focus_inactive(seat, container); 730 return seat_get_focus_inactive(seat, container);
726 } 731 }
@@ -732,7 +737,7 @@ struct sway_container *container_get_in_direction(
732 parent = container->parent; 737 parent = container->parent;
733 } else { 738 } else {
734 if (dir == MOVE_PARENT) { 739 if (dir == MOVE_PARENT) {
735 if (parent->type == C_OUTPUT) { 740 if (parent->type == C_OUTPUT || container_is_floating(container)) {
736 return NULL; 741 return NULL;
737 } else { 742 } else {
738 return parent; 743 return parent;
diff --git a/sway/tree/view.c b/sway/tree/view.c
index e641544e..253f3001 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -168,55 +168,6 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
168 return 0; 168 return 0;
169} 169}
170 170
171void view_init_floating(struct sway_view *view) {
172 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
173 int min_width, min_height;
174 int max_width, max_height;
175
176 if (config->floating_minimum_width == -1) { // no minimum
177 min_width = 0;
178 } else if (config->floating_minimum_width == 0) { // automatic
179 min_width = 75;
180 } else {
181 min_width = config->floating_minimum_width;
182 }
183
184 if (config->floating_minimum_height == -1) { // no minimum
185 min_height = 0;
186 } else if (config->floating_minimum_height == 0) { // automatic
187 min_height = 50;
188 } else {
189 min_height = config->floating_minimum_height;
190 }
191
192 if (config->floating_maximum_width == -1) { // no maximum
193 max_width = INT_MAX;
194 } else if (config->floating_maximum_width == 0) { // automatic
195 max_width = ws->width * 0.6666;
196 } else {
197 max_width = config->floating_maximum_width;
198 }
199
200 if (config->floating_maximum_height == -1) { // no maximum
201 max_height = INT_MAX;
202 } else if (config->floating_maximum_height == 0) { // automatic
203 max_height = ws->height * 0.6666;
204 } else {
205 max_height = config->floating_maximum_height;
206 }
207
208 view->width = fmax(min_width, fmin(view->natural_width, max_width));
209 view->height = fmax(min_height, fmin(view->natural_height, max_height));
210 view->x = ws->x + (ws->width - view->width) / 2;
211 view->y = ws->y + (ws->height - view->height) / 2;
212
213 // If the view's border is B_NONE then these properties are ignored.
214 view->border_top = view->border_bottom = true;
215 view->border_left = view->border_right = true;
216
217 container_set_geometry_from_floating_view(view->swayc);
218}
219
220void view_autoconfigure(struct sway_view *view) { 171void view_autoconfigure(struct sway_view *view) {
221 if (!sway_assert(view->swayc, 172 if (!sway_assert(view->swayc,
222 "Called view_autoconfigure() on a view without a swayc")) { 173 "Called view_autoconfigure() on a view without a swayc")) {
@@ -626,10 +577,8 @@ void view_unmap(struct sway_view *view) {
626 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); 577 struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
627 578
628 struct sway_container *parent; 579 struct sway_container *parent;
629 if (view->swayc->is_fullscreen) { 580 if (container_is_fullscreen_or_child(view->swayc)) {
630 ws->sway_workspace->fullscreen = NULL;
631 parent = container_destroy(view->swayc); 581 parent = container_destroy(view->swayc);
632
633 arrange_windows(ws->parent); 582 arrange_windows(ws->parent);
634 } else { 583 } else {
635 parent = container_destroy(view->swayc); 584 parent = container_destroy(view->swayc);