Commit b0dc9aea authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

Use frame margins wherever possible

Summary:
AbstractClient has a method that exposes frame margins. Use that instead
to make code simpler and ready for upcoming xdg-shell changes.

Reviewers: #kwin

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D24188
parent bf47afcf
......@@ -498,40 +498,42 @@ QPoint Workspace::adjustClientPosition(AbstractClient* c, QPoint pos, bool unres
const int snapY = borderSnapZone.height() * snapAdjust;
if (snapX || snapY) {
QRect geo = c->geometry();
const QPoint cp = c->clientPos();
const QSize cs = geo.size() - c->clientSize();
int padding[4] = { cp.x(), cs.width() - cp.x(), cp.y(), cs.height() - cp.y() };
QMargins frameMargins = c->frameMargins();
// snap to titlebar / snap to window borders on inner screen edges
AbstractClient::Position titlePos = c->titlebarPosition();
if (padding[0] && (titlePos == AbstractClient::PositionLeft || (c->maximizeMode() & MaximizeHorizontal) ||
screens()->intersecting(geo.translated(maxRect.x() - (padding[0] + geo.x()), 0)) > 1))
padding[0] = 0;
if (padding[1] && (titlePos == AbstractClient::PositionRight || (c->maximizeMode() & MaximizeHorizontal) ||
screens()->intersecting(geo.translated(maxRect.right() + padding[1] - geo.right(), 0)) > 1))
padding[1] = 0;
if (padding[2] && (titlePos == AbstractClient::PositionTop || (c->maximizeMode() & MaximizeVertical) ||
screens()->intersecting(geo.translated(0, maxRect.y() - (padding[2] + geo.y()))) > 1))
padding[2] = 0;
if (padding[3] && (titlePos == AbstractClient::PositionBottom || (c->maximizeMode() & MaximizeVertical) ||
screens()->intersecting(geo.translated(0, maxRect.bottom() + padding[3] - geo.bottom())) > 1))
padding[3] = 0;
if (frameMargins.left() && (titlePos == AbstractClient::PositionLeft || (c->maximizeMode() & MaximizeHorizontal) ||
screens()->intersecting(geo.translated(maxRect.x() - (frameMargins.left() + geo.x()), 0)) > 1)) {
frameMargins.setLeft(0);
}
if (frameMargins.right() && (titlePos == AbstractClient::PositionRight || (c->maximizeMode() & MaximizeHorizontal) ||
screens()->intersecting(geo.translated(maxRect.right() + frameMargins.right() - geo.right(), 0)) > 1)) {
frameMargins.setRight(0);
}
if (frameMargins.top() && (titlePos == AbstractClient::PositionTop || (c->maximizeMode() & MaximizeVertical) ||
screens()->intersecting(geo.translated(0, maxRect.y() - (frameMargins.top() + geo.y()))) > 1)) {
frameMargins.setTop(0);
}
if (frameMargins.bottom() && (titlePos == AbstractClient::PositionBottom || (c->maximizeMode() & MaximizeVertical) ||
screens()->intersecting(geo.translated(0, maxRect.bottom() + frameMargins.bottom() - geo.bottom())) > 1)) {
frameMargins.setBottom(0);
}
if ((sOWO ? (cx < xmin) : true) && (qAbs(xmin - cx) < snapX)) {
deltaX = xmin - cx;
nx = xmin - padding[0];
nx = xmin - frameMargins.left();
}
if ((sOWO ? (rx > xmax) : true) && (qAbs(rx - xmax) < snapX) && (qAbs(xmax - rx) < deltaX)) {
deltaX = rx - xmax;
nx = xmax - cw + padding[1];
nx = xmax - cw + frameMargins.right();
}
if ((sOWO ? (cy < ymin) : true) && (qAbs(ymin - cy) < snapY)) {
deltaY = ymin - cy;
ny = ymin - padding[2];
ny = ymin - frameMargins.top();
}
if ((sOWO ? (ry > ymax) : true) && (qAbs(ry - ymax) < snapY) && (qAbs(ymax - ry) < deltaY)) {
deltaY = ry - ymax;
ny = ymax - ch + padding[3];
ny = ymax - ch + frameMargins.bottom();
}
}
......
......@@ -107,22 +107,25 @@ void Placement::place(AbstractClient *c, const QRect &area, Policy policy, Polic
// snap to titlebar / snap to window borders on inner screen edges
const QRect geo(c->geometry());
QPoint corner = geo.topLeft();
const QPoint cp = c->clientPos();
const QSize cs = geo.size() - c->clientSize();
const QMargins frameMargins = c->frameMargins();
AbstractClient::Position titlePos = c->titlebarPosition();
const QRect fullRect = workspace()->clientArea(FullArea, c);
if (!(c->maximizeMode() & MaximizeHorizontal)) {
if (titlePos != AbstractClient::PositionRight && geo.right() == fullRect.right())
corner.rx() += cs.width() - cp.x();
if (titlePos != AbstractClient::PositionLeft && geo.x() == fullRect.x())
corner.rx() -= cp.x();
if (titlePos != AbstractClient::PositionRight && geo.right() == fullRect.right()) {
corner.rx() += frameMargins.right();
}
if (titlePos != AbstractClient::PositionLeft && geo.left() == fullRect.left()) {
corner.rx() -= frameMargins.left();
}
}
if (!(c->maximizeMode() & MaximizeVertical)) {
if (titlePos != AbstractClient::PositionBottom && geo.bottom() == fullRect.bottom())
corner.ry() += cs.height() - cp.y();
if (titlePos != AbstractClient::PositionTop && geo.y() == fullRect.y())
corner.ry() -= cp.y();
if (titlePos != AbstractClient::PositionBottom && geo.bottom() == fullRect.bottom()) {
corner.ry() += frameMargins.bottom();
}
if (titlePos != AbstractClient::PositionTop && geo.top() == fullRect.top()) {
corner.ry() -= frameMargins.top();
}
}
c->move(corner);
}
......
Markdown is supported
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