Refactor if-else chain in Placement::place to a switch statement

Was using a long & fragmented if-else chain. A switch statement
is often more performant, as well as being easier to read and modify.
This commit is contained in:
Kristen McWilliam 2021-09-18 13:12:25 -04:00 committed by Vlad Zahorodnii
parent f2b6a6b2f6
commit b23f2ab3dd

View file

@ -70,28 +70,39 @@ void Placement::place(AbstractClient *c, const QRect &area)
void Placement::place(AbstractClient *c, const QRect &area, Policy policy, Policy nextPlacement)
{
if (policy == Unknown)
switch (policy) {
case Unknown:
policy = Default;
if (policy == Default)
break;
case Default:
policy = options->placement();
if (policy == NoPlacement)
break;
case NoPlacement:
return;
else if (policy == Random)
case Random:
placeAtRandom(c, area, nextPlacement);
else if (policy == Cascade)
break;
case Cascade:
placeCascaded(c, area, nextPlacement);
else if (policy == Centered)
break;
case Centered:
placeCentered(c, area, nextPlacement);
else if (policy == ZeroCornered)
break;
case ZeroCornered:
placeZeroCornered(c, area, nextPlacement);
else if (policy == UnderMouse)
break;
case UnderMouse:
placeUnderMouse(c, area, nextPlacement);
else if (policy == OnMainWindow)
break;
case OnMainWindow:
placeOnMainWindow(c, area, nextPlacement);
else if (policy == Maximizing)
break;
case Maximizing:
placeMaximizing(c, area, nextPlacement);
else
break;
default:
placeSmart(c, area, nextPlacement);
}
if (options->borderSnapZone()) {
// snap to titlebar / snap to window borders on inner screen edges