From 744e2be3f626dcb14e60f3b5da5e2fa5ec17c551 Mon Sep 17 00:00:00 2001 From: Vlad Zagorodniy Date: Sat, 10 Aug 2019 17:31:06 +0300 Subject: [PATCH] refactor: Minimize use of geom in Toplevel subclasses Summary: This change makes easier to refactor geometry handling in the future. The main motivation for avoiding using geom directly is to make code more readable and ensure that the geometry is updated only through designated methods, e.g. setGeometry, plainResize, etc. Reviewers: #kwin, romangg Reviewed By: #kwin, romangg Subscribers: romangg, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D23072 --- abstract_client.cpp | 6 +++--- shell_client.cpp | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index 0ce7f7eb1e..df637aeaf9 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -889,7 +889,7 @@ void AbstractClient::setupWindowManagementInterface() w->setMovable(isMovable()); w->setVirtualDesktopChangeable(true); // FIXME Matches Client::actionSupported(), but both should be implemented. w->setParentWindow(transientFor() ? transientFor()->windowManagementInterface() : nullptr); - w->setGeometry(geom); + w->setGeometry(geometry()); connect(this, &AbstractClient::skipTaskbarChanged, w, [w, this] { w->setSkipTaskbar(skipTaskbar()); @@ -929,7 +929,7 @@ void AbstractClient::setupWindowManagementInterface() ); connect(this, &AbstractClient::geometryChanged, w, [w, this] { - w->setGeometry(geom); + w->setGeometry(geometry()); } ); connect(w, &PlasmaWindowInterface::closeRequested, this, [this] { closeWindow(); }); @@ -1402,7 +1402,7 @@ void AbstractClient::addRepaintDuringGeometryUpdates() void AbstractClient::updateGeometryBeforeUpdateBlocking() { - m_geometryBeforeUpdateBlocking = geom; + m_geometryBeforeUpdateBlocking = geometry(); } void AbstractClient::updateTabGroupStates(TabGroup::States) diff --git a/shell_client.cpp b/shell_client.cpp index fd2edaef19..5fc7f31d5b 100644 --- a/shell_client.cpp +++ b/shell_client.cpp @@ -238,7 +238,7 @@ void ShellClient::init() connect(s, &SurfaceInterface::sizeChanged, this, [this] { m_clientSize = surface()->size(); - doSetGeometry(QRect(geom.topLeft(), m_clientSize + QSize(borderLeft() + borderRight(), borderTop() + borderBottom()))); + doSetGeometry(QRect(pos(), m_clientSize + QSize(borderLeft() + borderRight(), borderTop() + borderBottom()))); } ); connect(s, &SurfaceInterface::unmapped, this, &ShellClient::unmap); @@ -1231,7 +1231,7 @@ bool ShellClient::requestGeometry(const QRect &rect) void ShellClient::updatePendingGeometry() { - QPoint position = geom.topLeft(); + QPoint position = pos(); MaximizeMode maximizeMode = m_maximizeMode; for (auto it = m_pendingConfigureRequests.begin(); it != m_pendingConfigureRequests.end(); it++) { if (it->serialId > m_lastAckedConfigureRequest) { @@ -1389,19 +1389,20 @@ void ShellClient::updateShowOnScreenEdge() if ((m_plasmaShellSurface->panelBehavior() == PlasmaShellSurfaceInterface::PanelBehavior::AutoHide && m_hidden) || m_plasmaShellSurface->panelBehavior() == PlasmaShellSurfaceInterface::PanelBehavior::WindowsCanCover) { // screen edge API requires an edge, thus we need to figure out which edge the window borders + const QRect clientGeometry = geometry(); Qt::Edges edges; for (int i = 0; i < screens()->count(); i++) { - const auto &screenGeo = screens()->geometry(i); - if (screenGeo.x() == geom.x()) { + const QRect screenGeometry = screens()->geometry(i); + if (screenGeometry.left() == clientGeometry.left()) { edges |= Qt::LeftEdge; } - if (screenGeo.x() + screenGeo.width() == geom.x() + geom.width()) { + if (screenGeometry.right() == clientGeometry.right()) { edges |= Qt::RightEdge; } - if (screenGeo.y() == geom.y()) { + if (screenGeometry.top() == clientGeometry.top()) { edges |= Qt::TopEdge; } - if (screenGeo.y() + screenGeo.height() == geom.y() + geom.height()) { + if (screenGeometry.bottom() == clientGeometry.bottom()) { edges |= Qt::BottomEdge; } } @@ -1416,9 +1417,9 @@ void ShellClient::updateShowOnScreenEdge() } // it's still possible that a panel borders two edges, e.g. bottom and left // in that case the one which is sharing more with the edge wins - auto check = [this](Qt::Edges edges, Qt::Edge horiz, Qt::Edge vert) { + auto check = [clientGeometry](Qt::Edges edges, Qt::Edge horiz, Qt::Edge vert) { if (edges.testFlag(horiz) && edges.testFlag(vert)) { - if (geom.width() >= geom.height()) { + if (clientGeometry.width() >= clientGeometry.height()) { return edges & ~horiz; } else { return edges & ~vert;