mirror of
https://github.com/swaywm/sway.git
synced 2026-04-22 06:46:27 -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
|
|
@ -264,6 +264,9 @@ void arrange_workspace(struct sway_workspace *workspace) {
|
|||
area->width, area->height, area->x, area->y);
|
||||
|
||||
bool first_arrange = workspace->width == 0 && workspace->height == 0;
|
||||
struct wlr_box prev_box;
|
||||
workspace_get_box(workspace, &prev_box);
|
||||
|
||||
double prev_x = workspace->x - workspace->current_gaps.left;
|
||||
double prev_y = workspace->y - workspace->current_gaps.top;
|
||||
workspace->width = area->width;
|
||||
|
|
@ -277,13 +280,14 @@ void arrange_workspace(struct sway_workspace *workspace) {
|
|||
if (!first_arrange && (diff_x != 0 || diff_y != 0)) {
|
||||
for (int i = 0; i < workspace->floating->length; ++i) {
|
||||
struct sway_container *floater = workspace->floating->items[i];
|
||||
container_floating_translate(floater, diff_x, diff_y);
|
||||
double center_x = floater->pending.x + floater->pending.width / 2;
|
||||
double center_y = floater->pending.y + floater->pending.height / 2;
|
||||
struct wlr_box workspace_box;
|
||||
workspace_get_box(workspace, &workspace_box);
|
||||
if (!wlr_box_contains_point(&workspace_box, center_x, center_y)) {
|
||||
container_floating_move_to_center(floater);
|
||||
floating_fix_coordinates(floater, &prev_box, &workspace_box);
|
||||
// Set transformation for scratchpad windows.
|
||||
if (floater->scratchpad) {
|
||||
struct wlr_box output_box;
|
||||
output_get_box(output, &output_box);
|
||||
floater->transform = output_box;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue