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
This commit is contained in:
parent
bf47afcf6a
commit
b0dc9aea5e
2 changed files with 34 additions and 29 deletions
40
geometry.cpp
40
geometry.cpp
|
@ -498,40 +498,42 @@ QPoint Workspace::adjustClientPosition(AbstractClient* c, QPoint pos, bool unres
|
||||||
const int snapY = borderSnapZone.height() * snapAdjust;
|
const int snapY = borderSnapZone.height() * snapAdjust;
|
||||||
if (snapX || snapY) {
|
if (snapX || snapY) {
|
||||||
QRect geo = c->geometry();
|
QRect geo = c->geometry();
|
||||||
const QPoint cp = c->clientPos();
|
QMargins frameMargins = c->frameMargins();
|
||||||
const QSize cs = geo.size() - c->clientSize();
|
|
||||||
int padding[4] = { cp.x(), cs.width() - cp.x(), cp.y(), cs.height() - cp.y() };
|
|
||||||
|
|
||||||
// snap to titlebar / snap to window borders on inner screen edges
|
// snap to titlebar / snap to window borders on inner screen edges
|
||||||
AbstractClient::Position titlePos = c->titlebarPosition();
|
AbstractClient::Position titlePos = c->titlebarPosition();
|
||||||
if (padding[0] && (titlePos == AbstractClient::PositionLeft || (c->maximizeMode() & MaximizeHorizontal) ||
|
if (frameMargins.left() && (titlePos == AbstractClient::PositionLeft || (c->maximizeMode() & MaximizeHorizontal) ||
|
||||||
screens()->intersecting(geo.translated(maxRect.x() - (padding[0] + geo.x()), 0)) > 1))
|
screens()->intersecting(geo.translated(maxRect.x() - (frameMargins.left() + geo.x()), 0)) > 1)) {
|
||||||
padding[0] = 0;
|
frameMargins.setLeft(0);
|
||||||
if (padding[1] && (titlePos == AbstractClient::PositionRight || (c->maximizeMode() & MaximizeHorizontal) ||
|
}
|
||||||
screens()->intersecting(geo.translated(maxRect.right() + padding[1] - geo.right(), 0)) > 1))
|
if (frameMargins.right() && (titlePos == AbstractClient::PositionRight || (c->maximizeMode() & MaximizeHorizontal) ||
|
||||||
padding[1] = 0;
|
screens()->intersecting(geo.translated(maxRect.right() + frameMargins.right() - geo.right(), 0)) > 1)) {
|
||||||
if (padding[2] && (titlePos == AbstractClient::PositionTop || (c->maximizeMode() & MaximizeVertical) ||
|
frameMargins.setRight(0);
|
||||||
screens()->intersecting(geo.translated(0, maxRect.y() - (padding[2] + geo.y()))) > 1))
|
}
|
||||||
padding[2] = 0;
|
if (frameMargins.top() && (titlePos == AbstractClient::PositionTop || (c->maximizeMode() & MaximizeVertical) ||
|
||||||
if (padding[3] && (titlePos == AbstractClient::PositionBottom || (c->maximizeMode() & MaximizeVertical) ||
|
screens()->intersecting(geo.translated(0, maxRect.y() - (frameMargins.top() + geo.y()))) > 1)) {
|
||||||
screens()->intersecting(geo.translated(0, maxRect.bottom() + padding[3] - geo.bottom())) > 1))
|
frameMargins.setTop(0);
|
||||||
padding[3] = 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)) {
|
if ((sOWO ? (cx < xmin) : true) && (qAbs(xmin - cx) < snapX)) {
|
||||||
deltaX = xmin - cx;
|
deltaX = xmin - cx;
|
||||||
nx = xmin - padding[0];
|
nx = xmin - frameMargins.left();
|
||||||
}
|
}
|
||||||
if ((sOWO ? (rx > xmax) : true) && (qAbs(rx - xmax) < snapX) && (qAbs(xmax - rx) < deltaX)) {
|
if ((sOWO ? (rx > xmax) : true) && (qAbs(rx - xmax) < snapX) && (qAbs(xmax - rx) < deltaX)) {
|
||||||
deltaX = rx - xmax;
|
deltaX = rx - xmax;
|
||||||
nx = xmax - cw + padding[1];
|
nx = xmax - cw + frameMargins.right();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sOWO ? (cy < ymin) : true) && (qAbs(ymin - cy) < snapY)) {
|
if ((sOWO ? (cy < ymin) : true) && (qAbs(ymin - cy) < snapY)) {
|
||||||
deltaY = ymin - cy;
|
deltaY = ymin - cy;
|
||||||
ny = ymin - padding[2];
|
ny = ymin - frameMargins.top();
|
||||||
}
|
}
|
||||||
if ((sOWO ? (ry > ymax) : true) && (qAbs(ry - ymax) < snapY) && (qAbs(ymax - ry) < deltaY)) {
|
if ((sOWO ? (ry > ymax) : true) && (qAbs(ry - ymax) < snapY) && (qAbs(ymax - ry) < deltaY)) {
|
||||||
deltaY = ry - ymax;
|
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
|
// snap to titlebar / snap to window borders on inner screen edges
|
||||||
const QRect geo(c->geometry());
|
const QRect geo(c->geometry());
|
||||||
QPoint corner = geo.topLeft();
|
QPoint corner = geo.topLeft();
|
||||||
const QPoint cp = c->clientPos();
|
const QMargins frameMargins = c->frameMargins();
|
||||||
const QSize cs = geo.size() - c->clientSize();
|
|
||||||
AbstractClient::Position titlePos = c->titlebarPosition();
|
AbstractClient::Position titlePos = c->titlebarPosition();
|
||||||
|
|
||||||
const QRect fullRect = workspace()->clientArea(FullArea, c);
|
const QRect fullRect = workspace()->clientArea(FullArea, c);
|
||||||
if (!(c->maximizeMode() & MaximizeHorizontal)) {
|
if (!(c->maximizeMode() & MaximizeHorizontal)) {
|
||||||
if (titlePos != AbstractClient::PositionRight && geo.right() == fullRect.right())
|
if (titlePos != AbstractClient::PositionRight && geo.right() == fullRect.right()) {
|
||||||
corner.rx() += cs.width() - cp.x();
|
corner.rx() += frameMargins.right();
|
||||||
if (titlePos != AbstractClient::PositionLeft && geo.x() == fullRect.x())
|
}
|
||||||
corner.rx() -= cp.x();
|
if (titlePos != AbstractClient::PositionLeft && geo.left() == fullRect.left()) {
|
||||||
|
corner.rx() -= frameMargins.left();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!(c->maximizeMode() & MaximizeVertical)) {
|
if (!(c->maximizeMode() & MaximizeVertical)) {
|
||||||
if (titlePos != AbstractClient::PositionBottom && geo.bottom() == fullRect.bottom())
|
if (titlePos != AbstractClient::PositionBottom && geo.bottom() == fullRect.bottom()) {
|
||||||
corner.ry() += cs.height() - cp.y();
|
corner.ry() += frameMargins.bottom();
|
||||||
if (titlePos != AbstractClient::PositionTop && geo.y() == fullRect.y())
|
}
|
||||||
corner.ry() -= cp.y();
|
if (titlePos != AbstractClient::PositionTop && geo.top() == fullRect.top()) {
|
||||||
|
corner.ry() -= frameMargins.top();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c->move(corner);
|
c->move(corner);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue