mirror of
https://github.com/swaywm/sway.git
synced 2026-04-17 06:46:32 -04:00
root: Try to preserve relative positions of floating containers
This makes the behavior of floating containers more consistent with i3. The coordinates of the container are scaled when the size of the workspace it is on changes or when the container is moved between workspaces on different outputs. For scratchpad containers, add a new state that preserves the dimensions of the last output the window appeared on. This is necessary because after a container is hidden in the scratchpad, we expect it to be in the same relative position on the output when it reappears. We can't just use the container's attached workspace because that workspace's dimensions might have been changed or the workspace as a whole could have been destroyed.
This commit is contained in:
parent
ebeed7e303
commit
90c2d631e2
5 changed files with 68 additions and 15 deletions
|
|
@ -712,6 +712,21 @@ void floating_calculate_constraints(int *min_width, int *max_width,
|
|||
|
||||
}
|
||||
|
||||
void floating_fix_coordinates(struct sway_container *con, struct wlr_box *old, struct wlr_box *new) {
|
||||
if (!old->width || !old->height) {
|
||||
// Fall back to centering on the workspace.
|
||||
container_floating_move_to_center(con);
|
||||
} else {
|
||||
int rel_x = con->pending.x - old->x + (con->pending.width / 2);
|
||||
int rel_y = con->pending.y - old->y + (con->pending.height / 2);
|
||||
|
||||
con->pending.x = new->x + (double)(rel_x * new->width) / old->width - (con->pending.width / 2);
|
||||
con->pending.y = new->y + (double)(rel_y * new->height) / old->height - (con->pending.height / 2);
|
||||
|
||||
sway_log(SWAY_DEBUG, "Transformed container %p to coords (%f, %f)", con, con->pending.x, con->pending.y);
|
||||
}
|
||||
}
|
||||
|
||||
static void floating_natural_resize(struct sway_container *con) {
|
||||
int min_width, max_width, min_height, max_height;
|
||||
floating_calculate_constraints(&min_width, &max_width,
|
||||
|
|
@ -1025,6 +1040,13 @@ void container_floating_move_to(struct sway_container *con,
|
|||
workspace_add_floating(new_workspace, con);
|
||||
arrange_workspace(old_workspace);
|
||||
arrange_workspace(new_workspace);
|
||||
// If the moved container was a visible scratchpad container, then
|
||||
// update its transform.
|
||||
if (con->scratchpad) {
|
||||
struct wlr_box output_box;
|
||||
output_get_box(new_output, &output_box);
|
||||
con->transform = output_box;
|
||||
}
|
||||
workspace_detect_urgent(old_workspace);
|
||||
workspace_detect_urgent(new_workspace);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue