mirror of
https://github.com/swaywm/sway.git
synced 2025-11-16 06:59:49 -05:00
Merge pull request #2360 from RyanDwyer/floating-containers
Allow containers to float
This commit is contained in:
commit
53069f1403
15 changed files with 218 additions and 113 deletions
|
|
@ -410,6 +410,10 @@ struct sway_container *container_flatten(struct sway_container *container) {
|
|||
* This function just wraps container_destroy_noreaping(), then does reaping.
|
||||
*/
|
||||
struct sway_container *container_destroy(struct sway_container *con) {
|
||||
if (con->is_fullscreen) {
|
||||
struct sway_container *ws = container_parent(con, C_WORKSPACE);
|
||||
ws->sway_workspace->fullscreen = NULL;
|
||||
}
|
||||
struct sway_container *parent = container_destroy_noreaping(con);
|
||||
|
||||
if (!parent) {
|
||||
|
|
@ -948,37 +952,100 @@ size_t container_titlebar_height() {
|
|||
return config->font_height + TITLEBAR_V_PADDING * 2;
|
||||
}
|
||||
|
||||
void container_init_floating(struct sway_container *con) {
|
||||
if (!sway_assert(con->type == C_VIEW || con->type == C_CONTAINER,
|
||||
"Expected a view or container")) {
|
||||
return;
|
||||
}
|
||||
struct sway_container *ws = container_parent(con, C_WORKSPACE);
|
||||
int min_width, min_height;
|
||||
int max_width, max_height;
|
||||
|
||||
if (config->floating_minimum_width == -1) { // no minimum
|
||||
min_width = 0;
|
||||
} else if (config->floating_minimum_width == 0) { // automatic
|
||||
min_width = 75;
|
||||
} else {
|
||||
min_width = config->floating_minimum_width;
|
||||
}
|
||||
|
||||
if (config->floating_minimum_height == -1) { // no minimum
|
||||
min_height = 0;
|
||||
} else if (config->floating_minimum_height == 0) { // automatic
|
||||
min_height = 50;
|
||||
} else {
|
||||
min_height = config->floating_minimum_height;
|
||||
}
|
||||
|
||||
if (config->floating_maximum_width == -1) { // no maximum
|
||||
max_width = INT_MAX;
|
||||
} else if (config->floating_maximum_width == 0) { // automatic
|
||||
max_width = ws->width * 0.6666;
|
||||
} else {
|
||||
max_width = config->floating_maximum_width;
|
||||
}
|
||||
|
||||
if (config->floating_maximum_height == -1) { // no maximum
|
||||
max_height = INT_MAX;
|
||||
} else if (config->floating_maximum_height == 0) { // automatic
|
||||
max_height = ws->height * 0.6666;
|
||||
} else {
|
||||
max_height = config->floating_maximum_height;
|
||||
}
|
||||
|
||||
if (con->type == C_CONTAINER) {
|
||||
con->width = max_width;
|
||||
con->height = max_height;
|
||||
con->x = ws->x + (ws->width - con->width) / 2;
|
||||
con->y = ws->y + (ws->height - con->height) / 2;
|
||||
} else {
|
||||
struct sway_view *view = con->sway_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;
|
||||
|
||||
// If the view's border is B_NONE then these properties are ignored.
|
||||
view->border_top = view->border_bottom = true;
|
||||
view->border_left = view->border_right = true;
|
||||
|
||||
container_set_geometry_from_floating_view(view->swayc);
|
||||
}
|
||||
}
|
||||
|
||||
void container_set_floating(struct sway_container *container, bool enable) {
|
||||
if (container_is_floating(container) == enable) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
|
||||
struct sway_seat *seat = input_manager_current_seat(input_manager);
|
||||
struct sway_container *workspace = container_parent(container, C_WORKSPACE);
|
||||
|
||||
if (enable) {
|
||||
container_remove_child(container);
|
||||
container_add_child(workspace->sway_workspace->floating, container);
|
||||
container_init_floating(container);
|
||||
if (container->type == C_VIEW) {
|
||||
view_init_floating(container->sway_view);
|
||||
view_set_tiled(container->sway_view, false);
|
||||
}
|
||||
seat_set_focus(seat, seat_get_focus_inactive(seat, container));
|
||||
container_reap_empty_recursive(workspace);
|
||||
} else {
|
||||
// Returning to tiled
|
||||
if (container->scratchpad) {
|
||||
scratchpad_remove_container(container);
|
||||
}
|
||||
container_remove_child(container);
|
||||
container_add_child(workspace, container);
|
||||
struct sway_container *reference =
|
||||
seat_get_focus_inactive_tiling(seat, workspace);
|
||||
if (reference->type == C_VIEW) {
|
||||
reference = reference->parent;
|
||||
}
|
||||
container_add_child(reference, container);
|
||||
container->width = container->parent->width;
|
||||
container->height = container->parent->height;
|
||||
if (container->type == C_VIEW) {
|
||||
view_set_tiled(container->sway_view, true);
|
||||
}
|
||||
container->is_sticky = false;
|
||||
container_reap_empty_recursive(workspace->sway_workspace->floating);
|
||||
}
|
||||
|
||||
container_end_mouse_operation(container);
|
||||
|
|
@ -1198,6 +1265,17 @@ void container_set_fullscreen(struct sway_container *container, bool enable) {
|
|||
ipc_event_window(container, "fullscreen_mode");
|
||||
}
|
||||
|
||||
bool container_is_floating_or_child(struct sway_container *container) {
|
||||
do {
|
||||
if (container->parent && container->parent->layout == L_FLOATING) {
|
||||
return true;
|
||||
}
|
||||
container = container->parent;
|
||||
} while (container && container->type != C_WORKSPACE);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool container_is_fullscreen_or_child(struct sway_container *container) {
|
||||
do {
|
||||
if (container->is_fullscreen) {
|
||||
|
|
|
|||
|
|
@ -387,9 +387,11 @@ void container_move(struct sway_container *container,
|
|||
// If moving a fullscreen view, only consider outputs
|
||||
if (container->is_fullscreen) {
|
||||
current = container_parent(container, C_OUTPUT);
|
||||
} else if (container_is_fullscreen_or_child(container)) {
|
||||
} else if (container_is_fullscreen_or_child(container) ||
|
||||
container_is_floating_or_child(container)) {
|
||||
// If we've fullscreened a split container, only allow the child to move
|
||||
// around within the fullscreen parent.
|
||||
// Same with floating a split container.
|
||||
struct sway_container *ws = container_parent(container, C_WORKSPACE);
|
||||
top = ws->sway_workspace->fullscreen;
|
||||
}
|
||||
|
|
@ -465,6 +467,9 @@ void container_move(struct sway_container *container,
|
|||
if ((index == parent->children->length - 1 && offs > 0)
|
||||
|| (index == 0 && offs < 0)) {
|
||||
if (current->parent == container->parent) {
|
||||
if (parent->parent->layout == L_FLOATING) {
|
||||
return;
|
||||
}
|
||||
if (!parent->is_fullscreen &&
|
||||
(parent->layout == L_TABBED ||
|
||||
parent->layout == L_STACKED)) {
|
||||
|
|
@ -488,10 +493,14 @@ void container_move(struct sway_container *container,
|
|||
sibling = parent->children->items[index + offs];
|
||||
wlr_log(WLR_DEBUG, "Selecting sibling id:%zd", sibling->id);
|
||||
}
|
||||
} else if (!parent->is_fullscreen && (parent->layout == L_TABBED ||
|
||||
} else if (!parent->is_fullscreen &&
|
||||
parent->parent->layout != L_FLOATING &&
|
||||
(parent->layout == L_TABBED ||
|
||||
parent->layout == L_STACKED)) {
|
||||
move_out_of_tabs_stacks(container, current, move_dir, offs);
|
||||
return;
|
||||
} else if (parent->parent->layout == L_FLOATING) {
|
||||
return;
|
||||
} else {
|
||||
wlr_log(WLR_DEBUG, "Moving up to find a parallel container");
|
||||
current = current->parent;
|
||||
|
|
@ -717,10 +726,6 @@ struct sway_container *container_get_in_direction(
|
|||
enum movement_direction dir) {
|
||||
struct sway_container *parent = container->parent;
|
||||
|
||||
if (container_is_floating(container)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (dir == MOVE_CHILD) {
|
||||
return seat_get_focus_inactive(seat, container);
|
||||
}
|
||||
|
|
@ -732,7 +737,7 @@ struct sway_container *container_get_in_direction(
|
|||
parent = container->parent;
|
||||
} else {
|
||||
if (dir == MOVE_PARENT) {
|
||||
if (parent->type == C_OUTPUT) {
|
||||
if (parent->type == C_OUTPUT || container_is_floating(container)) {
|
||||
return NULL;
|
||||
} else {
|
||||
return parent;
|
||||
|
|
|
|||
|
|
@ -168,55 +168,6 @@ uint32_t view_configure(struct sway_view *view, double lx, double ly, int width,
|
|||
return 0;
|
||||
}
|
||||
|
||||
void view_init_floating(struct sway_view *view) {
|
||||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
int min_width, min_height;
|
||||
int max_width, max_height;
|
||||
|
||||
if (config->floating_minimum_width == -1) { // no minimum
|
||||
min_width = 0;
|
||||
} else if (config->floating_minimum_width == 0) { // automatic
|
||||
min_width = 75;
|
||||
} else {
|
||||
min_width = config->floating_minimum_width;
|
||||
}
|
||||
|
||||
if (config->floating_minimum_height == -1) { // no minimum
|
||||
min_height = 0;
|
||||
} else if (config->floating_minimum_height == 0) { // automatic
|
||||
min_height = 50;
|
||||
} else {
|
||||
min_height = config->floating_minimum_height;
|
||||
}
|
||||
|
||||
if (config->floating_maximum_width == -1) { // no maximum
|
||||
max_width = INT_MAX;
|
||||
} else if (config->floating_maximum_width == 0) { // automatic
|
||||
max_width = ws->width * 0.6666;
|
||||
} else {
|
||||
max_width = config->floating_maximum_width;
|
||||
}
|
||||
|
||||
if (config->floating_maximum_height == -1) { // no maximum
|
||||
max_height = INT_MAX;
|
||||
} else if (config->floating_maximum_height == 0) { // automatic
|
||||
max_height = ws->height * 0.6666;
|
||||
} else {
|
||||
max_height = config->floating_maximum_height;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
// If the view's border is B_NONE then these properties are ignored.
|
||||
view->border_top = view->border_bottom = true;
|
||||
view->border_left = view->border_right = true;
|
||||
|
||||
container_set_geometry_from_floating_view(view->swayc);
|
||||
}
|
||||
|
||||
void view_autoconfigure(struct sway_view *view) {
|
||||
if (!sway_assert(view->swayc,
|
||||
"Called view_autoconfigure() on a view without a swayc")) {
|
||||
|
|
@ -626,10 +577,8 @@ void view_unmap(struct sway_view *view) {
|
|||
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
|
||||
|
||||
struct sway_container *parent;
|
||||
if (view->swayc->is_fullscreen) {
|
||||
ws->sway_workspace->fullscreen = NULL;
|
||||
if (container_is_fullscreen_or_child(view->swayc)) {
|
||||
parent = container_destroy(view->swayc);
|
||||
|
||||
arrange_windows(ws->parent);
|
||||
} else {
|
||||
parent = container_destroy(view->swayc);
|
||||
|
|
@ -1050,11 +999,14 @@ void view_update_marks_textures(struct sway_view *view) {
|
|||
}
|
||||
|
||||
bool view_is_visible(struct sway_view *view) {
|
||||
if (!view->swayc || view->swayc->destroying || !view->swayc->parent) {
|
||||
if (!view->swayc || view->swayc->destroying) {
|
||||
return false;
|
||||
}
|
||||
struct sway_container *workspace =
|
||||
container_parent(view->swayc, C_WORKSPACE);
|
||||
if (!workspace) {
|
||||
return false;
|
||||
}
|
||||
// Determine if view is nested inside a floating container which is sticky.
|
||||
// A simple floating view will have this ancestry:
|
||||
// C_VIEW -> floating -> workspace
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue