Commit 99ff9d96 authored by Kevin Ottens's avatar Kevin Ottens Committed by David Edmundson
Browse files

Add maintainSnapping method to OutputModel

The intent here is to impact the position of screens around a given
screen when its size changes. This way we avoid weird overlaps or gaps
on resize with the screens snapped to a given one.

Note that even though it'll fully respect snapping in one direction,
it won't respect snapping between other screens in different directions.
This would require a full fledged layout engine which would be
complicated to grow in the current model.

Since it's also a less common case, I chose to ignore it. Let's make it
work for the 80% of the cases which are generally in one direction only.
parent 18a034e5
......@@ -951,3 +951,33 @@ void OutputModel::snap(const Output &output, QPoint &dest)
}
}
}
void OutputModel::maintainSnapping(const OutputModel::Output &changedOutput, const QSize &oldSize, const QSize &newSize)
{
const auto changedCenter = QRect(changedOutput.ptr->pos(), oldSize).center();
const auto dSize = newSize - oldSize;
const auto delta = QPoint(dSize.width(), dSize.height());
auto updated = false;
for (auto &output : m_outputs) {
if (output.ptr->id() == changedOutput.ptr->id()) {
continue;
}
const auto pos = output.ptr->pos();
const auto isXTranslate = pos.x() >= changedCenter.x();
const auto isYTranslate = pos.y() >= changedCenter.y();
const auto translation = QPoint(isXTranslate ? delta.x() : 0, isYTranslate ? delta.y() : 0);
if (translation.isNull()) {
continue;
}
output.pos = pos + translation;
updated = true;
}
if (updated) {
updatePositions();
}
}
......@@ -121,6 +121,7 @@ private:
* @param dest the desired destination to be adjusted by snapping
*/
void snap(const Output &output, QPoint &dest);
void maintainSnapping(const Output &changedOutput, const QSize &oldSize, const QSize &newSize);
bool setEnabled(int outputIndex, bool enable);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment