From 5eb84af469353c9b7a5402feaedd02bef54a0d03 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 25 Mar 2020 16:15:23 +0100 Subject: [PATCH] Remove overloads on virtual methods Summary: Prefer virtual methods that take QRect and QSize rather than multi-int versions. Makes for clearer API and reduces the amount of code that was taking all of the components and turn it into a class. Reviewers: #kwin, zzag Reviewed By: #kwin, zzag Subscribers: zzag, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D28283 --- abstract_client.cpp | 2 +- abstract_client.h | 16 ++-------------- internal_client.cpp | 17 ++++------------- internal_client.h | 6 ++---- x11client.cpp | 6 +++--- x11client.h | 10 ++++------ xdgshellclient.cpp | 16 +++++----------- xdgshellclient.h | 6 ++---- 8 files changed, 23 insertions(+), 56 deletions(-) diff --git a/abstract_client.cpp b/abstract_client.cpp index 5dd8349d93..f6911129b6 100644 --- a/abstract_client.cpp +++ b/abstract_client.cpp @@ -710,7 +710,7 @@ void AbstractClient::keepInArea(QRect area, bool partial) if (!partial) { // resize to fit into area if (area.width() < width() || area.height() < height()) - resizeWithChecks(qMin(area.width(), width()), qMin(area.height(), height())); + resizeWithChecks(size().boundedTo(area.size())); } int tx = x(), ty = y(); if (frameGeometry().right() > area.right() && width() <= area.width()) diff --git a/abstract_client.h b/abstract_client.h index cf322cbe71..cbde9b1482 100644 --- a/abstract_client.h +++ b/abstract_client.h @@ -619,13 +619,11 @@ public: enum ForceGeometry_t { NormalGeometrySet, ForceGeometrySet }; virtual void move(int x, int y, ForceGeometry_t force = NormalGeometrySet); void move(const QPoint &p, ForceGeometry_t force = NormalGeometrySet); - virtual void resizeWithChecks(int w, int h, ForceGeometry_t force = NormalGeometrySet) = 0; - void resizeWithChecks(const QSize& s, ForceGeometry_t force = NormalGeometrySet); + virtual void resizeWithChecks(const QSize& s, ForceGeometry_t force = NormalGeometrySet) = 0; void keepInArea(QRect area, bool partial = false); virtual QSize minSize() const; virtual QSize maxSize() const; - virtual void setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force = NormalGeometrySet) = 0; - void setFrameGeometry(const QRect &rect, ForceGeometry_t force = NormalGeometrySet); + virtual void setFrameGeometry(const QRect &rect, ForceGeometry_t force = NormalGeometrySet) = 0; /** * How to resize the window in order to obey constraints (mainly aspect ratios). @@ -1312,16 +1310,6 @@ inline void AbstractClient::move(const QPoint& p, ForceGeometry_t force) move(p.x(), p.y(), force); } -inline void AbstractClient::resizeWithChecks(const QSize& s, AbstractClient::ForceGeometry_t force) -{ - resizeWithChecks(s.width(), s.height(), force); -} - -inline void AbstractClient::setFrameGeometry(const QRect &rect, ForceGeometry_t force) -{ - setFrameGeometry(rect.x(), rect.y(), rect.width(), rect.height(), force); -} - inline const QList& AbstractClient::transients() const { return m_transients; diff --git a/internal_client.cpp b/internal_client.cpp index 6ca3d2b261..f22840b29d 100644 --- a/internal_client.cpp +++ b/internal_client.cpp @@ -299,27 +299,18 @@ void InternalClient::hideClient(bool hide) Q_UNUSED(hide) } -void InternalClient::resizeWithChecks(int w, int h, ForceGeometry_t force) +void InternalClient::resizeWithChecks(const QSize &size, ForceGeometry_t force) { Q_UNUSED(force) if (!m_internalWindow) { return; } - QRect area = workspace()->clientArea(WorkArea, this); - // don't allow growing larger than workarea - if (w > area.width()) { - w = area.width(); - } - if (h > area.height()) { - h = area.height(); - } - setFrameGeometry(QRect(x(), y(), w, h)); + const QRect area = workspace()->clientArea(WorkArea, this); + setFrameGeometry(QRect{pos(), size.boundedTo(area.size())}, force); } -void InternalClient::setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force) +void InternalClient::setFrameGeometry(const QRect &rect, ForceGeometry_t force) { - const QRect rect(x, y, w, h); - if (areGeometryUpdatesBlocked()) { m_frameGeometry = rect; if (pendingGeometryUpdate() == PendingGeometryForced) { diff --git a/internal_client.h b/internal_client.h index b4d08ab41a..ec038f0695 100644 --- a/internal_client.h +++ b/internal_client.h @@ -69,10 +69,8 @@ public: bool isShown(bool shaded_is_shown) const override; bool isHiddenInternal() const override; void hideClient(bool hide) override; - using AbstractClient::resizeWithChecks; - void resizeWithChecks(int w, int h, ForceGeometry_t force = NormalGeometrySet) override; - using AbstractClient::setFrameGeometry; - void setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force = NormalGeometrySet) override; + void resizeWithChecks(const QSize &size, ForceGeometry_t force = NormalGeometrySet) override; + void setFrameGeometry(const QRect &rect, ForceGeometry_t force = NormalGeometrySet) override; bool supportsWindowRules() const override; AbstractClient *findModal(bool allow_itself = false) override; void setOnAllActivities(bool set) override; diff --git a/x11client.cpp b/x11client.cpp index a553e133e3..3b51dcae3b 100644 --- a/x11client.cpp +++ b/x11client.cpp @@ -4097,7 +4097,7 @@ void X11Client::resizeWithChecks(int w, int h, xcb_gravity_t gravity, ForceGeome newy = newy + height() - h; break; } - setFrameGeometry(newx, newy, w, h, force); + setFrameGeometry(QRect{newx, newy, w, h}, force); } // _NET_MOVERESIZE_WINDOW @@ -4180,7 +4180,7 @@ bool X11Client::isMaximizable() const /** * Reimplemented to inform the client about the new window position. */ -void X11Client::setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force) +void X11Client::setFrameGeometry(const QRect &rect, ForceGeometry_t force) { // this code is also duplicated in X11Client::plainResize() // Ok, the shading geometry stuff. Generally, code doesn't care about shaded geometry, @@ -4194,7 +4194,7 @@ void X11Client::setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t for // Such code is wrong and should be changed to handle the case when the window is shaded, // for example using X11Client::clientSize() - QRect frameGeometry(x, y, w, h); + QRect frameGeometry = rect; if (shade_geometry_change) ; // nothing diff --git a/x11client.h b/x11client.h index 38e85517ed..0bc52ce19b 100644 --- a/x11client.h +++ b/x11client.h @@ -187,14 +187,12 @@ public: using AbstractClient::move; void move(int x, int y, ForceGeometry_t force = NormalGeometrySet) override; - using AbstractClient::setFrameGeometry; - void setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force = NormalGeometrySet) override; + void setFrameGeometry(const QRect &rect, ForceGeometry_t force = NormalGeometrySet) override; /// plainResize() simply resizes void plainResize(int w, int h, ForceGeometry_t force = NormalGeometrySet); void plainResize(const QSize& s, ForceGeometry_t force = NormalGeometrySet); /// resizeWithChecks() resizes according to gravity, and checks workarea position - using AbstractClient::resizeWithChecks; - void resizeWithChecks(int w, int h, ForceGeometry_t force = NormalGeometrySet) override; + void resizeWithChecks(const QSize &size, ForceGeometry_t force = NormalGeometrySet) override; void resizeWithChecks(int w, int h, xcb_gravity_t gravity, ForceGeometry_t force = NormalGeometrySet); void resizeWithChecks(const QSize& s, xcb_gravity_t gravity, ForceGeometry_t force = NormalGeometrySet); QSize constrainClientSize(const QSize &size, SizeMode mode = SizeModeAny) const override; @@ -655,9 +653,9 @@ inline void X11Client::plainResize(const QSize& s, ForceGeometry_t force) plainResize(s.width(), s.height(), force); } -inline void X11Client::resizeWithChecks(int w, int h, AbstractClient::ForceGeometry_t force) +inline void X11Client::resizeWithChecks(const QSize &s, AbstractClient::ForceGeometry_t force) { - resizeWithChecks(w, h, XCB_GRAVITY_BIT_FORGET, force); + resizeWithChecks(s.width(), s.height(), XCB_GRAVITY_BIT_FORGET, force); } inline void X11Client::resizeWithChecks(const QSize& s, xcb_gravity_t gravity, ForceGeometry_t force) diff --git a/xdgshellclient.cpp b/xdgshellclient.cpp index d38705b87b..5d487b66e9 100644 --- a/xdgshellclient.cpp +++ b/xdgshellclient.cpp @@ -470,9 +470,9 @@ void XdgShellClient::updateDecoration(bool check_workspace_pos, bool force) blockGeometryUpdates(false); } -void XdgShellClient::setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force) +void XdgShellClient::setFrameGeometry(const QRect &rect, ForceGeometry_t force) { - const QRect newGeometry = rules()->checkGeometry(QRect(x, y, w, h)); + const QRect newGeometry = rules()->checkGeometry(rect); if (areGeometryUpdatesBlocked()) { // when the GeometryUpdateBlocker exits the current geom is passed to setGeometry @@ -1310,17 +1310,11 @@ void XdgShellClient::handleCommitted() markAsMapped(); } -void XdgShellClient::resizeWithChecks(int w, int h, ForceGeometry_t force) +void XdgShellClient::resizeWithChecks(const QSize &size, ForceGeometry_t force) { - const QRect area = workspace()->clientArea(WorkArea, this); // don't allow growing larger than workarea - if (w > area.width()) { - w = area.width(); - } - if (h > area.height()) { - h = area.height(); - } - setFrameGeometry(x(), y(), w, h, force); + const QRect area = workspace()->clientArea(WorkArea, this); + setFrameGeometry(QRect{pos(), size.boundedTo(area.size())}, force); } void XdgShellClient::unmap() diff --git a/xdgshellclient.h b/xdgshellclient.h index 7a1f0fb554..c82c9c52ef 100644 --- a/xdgshellclient.h +++ b/xdgshellclient.h @@ -99,10 +99,8 @@ public: bool userCanSetNoBorder() const override; bool wantsInput() const override; bool dockWantsInput() const override; - using AbstractClient::resizeWithChecks; - void resizeWithChecks(int w, int h, ForceGeometry_t force = NormalGeometrySet) override; - using AbstractClient::setFrameGeometry; - void setFrameGeometry(int x, int y, int w, int h, ForceGeometry_t force = NormalGeometrySet) override; + void resizeWithChecks(const QSize &size, ForceGeometry_t force = NormalGeometrySet) override; + void setFrameGeometry(const QRect &rect, ForceGeometry_t force = NormalGeometrySet) override; bool hasStrut() const override; quint32 windowId() const override; pid_t pid() const override;