diff options
author | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-26 18:36:46 +1000 |
---|---|---|
committer | Ryan Dwyer <ryandwyer1@gmail.com> | 2018-07-28 22:41:04 +1000 |
commit | 08cfba2192f5770d975c5fe70789a81aaee4dc7e (patch) | |
tree | 7f07e32020649ae5c049e8533f0cf040dc80e166 /sway/tree/container.c | |
parent | Merge pull request #2372 from RyanDwyer/fix-use-after-free-v2 (diff) | |
download | sway-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/container.c')
-rw-r--r-- | sway/tree/container.c | 82 |
1 files changed, 77 insertions, 5 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 | */ |
409 | struct sway_container *container_destroy(struct sway_container *con) { | 409 | struct 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 | ||
952 | void 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 | |||
948 | void container_set_floating(struct sway_container *container, bool enable) { | 1013 | void 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 | ||
1259 | bool 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 | |||
1198 | bool container_is_fullscreen_or_child(struct sway_container *container) { | 1270 | bool container_is_fullscreen_or_child(struct sway_container *container) { |
1199 | do { | 1271 | do { |
1200 | if (container->is_fullscreen) { | 1272 | if (container->is_fullscreen) { |