diff --git a/effects/presentwindows/presentwindows.cpp b/effects/presentwindows/presentwindows.cpp --- a/effects/presentwindows/presentwindows.cpp +++ b/effects/presentwindows/presentwindows.cpp @@ -1407,6 +1407,9 @@ int xDiff = widthDiff / 2; // Also move a bit in the direction of the enlarge, allows the int yDiff = heightDiff / 2; // center windows to be enlarged if there is gaps on the side. + // heightDiff (and yDiff) will be re-computed after each successfull enlargement attempt + // so that the error introduced in the window's aspect ratio is minimized + // Attempt enlarging to the top-right oldRect = *target; target->setRect(target->x() + xDiff, @@ -1416,8 +1419,11 @@ ); if (isOverlappingAny(w, targets, borderRegion)) *target = oldRect; - else + else { moved = true; + heightDiff = heightForWidth(w, target->width() + widthDiff) - target->height(); + yDiff = heightDiff / 2; + } // Attempt enlarging to the bottom-right oldRect = *target; @@ -1429,8 +1435,11 @@ ); if (isOverlappingAny(w, targets, borderRegion)) *target = oldRect; - else + else { moved = true; + heightDiff = heightForWidth(w, target->width() + widthDiff) - target->height(); + yDiff = heightDiff / 2; + } // Attempt enlarging to the bottom-left oldRect = *target; @@ -1442,8 +1451,11 @@ ); if (isOverlappingAny(w, targets, borderRegion)) *target = oldRect; - else + else { moved = true; + heightDiff = heightForWidth(w, target->width() + widthDiff) - target->height(); + yDiff = heightDiff / 2; + } // Attempt enlarging to the top-left oldRect = *target;