diff --git a/effects/presentwindows/presentwindows.cpp b/effects/presentwindows/presentwindows.cpp index 024f573404..3a6bc6a46d 100755 --- a/effects/presentwindows/presentwindows.cpp +++ b/effects/presentwindows/presentwindows.cpp @@ -1407,6 +1407,9 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis 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 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis ); 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 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis ); 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 @@ void PresentWindowsEffect::calculateWindowTransformationsNatural(EffectWindowLis ); 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;