From 5ece6d55d6bae6af126b6c6b46d6ff1a771369d5 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 16 May 2021 17:32:07 +0300 Subject: [PATCH] Replace Toplevel::clientContentPos() with a better solution The Toplevel::clientContentPos() function is needed to map the surface local coordinates to the global coordinates. But its name is highly confusing as there's already a function with a similar name. This change introduces a helper with a better name to fix the readability issue. --- src/deleted.cpp | 1 - src/deleted.h | 4 ---- src/internal_client.cpp | 5 ----- src/internal_client.h | 1 - src/pointer_input.cpp | 4 ++-- src/toplevel.cpp | 5 +++++ src/toplevel.h | 11 +---------- src/waylandclient.cpp | 5 ----- src/waylandclient.h | 1 - 9 files changed, 8 insertions(+), 29 deletions(-) diff --git a/src/deleted.cpp b/src/deleted.cpp index f04a18fe32..c52808f4ab 100644 --- a/src/deleted.cpp +++ b/src/deleted.cpp @@ -77,7 +77,6 @@ void Deleted::copyToDeleted(Toplevel* c) m_desktops = c->desktops(); activityList = c->activities(); contentsRect = QRect(c->clientPos(), c->clientSize()); - m_contentPos = c->clientContentPos(); transparent_rect = c->transparentRect(); m_layer = c->layer(); m_frame = c->frameId(); diff --git a/src/deleted.h b/src/deleted.h index 215bb8a674..7512426f97 100644 --- a/src/deleted.h +++ b/src/deleted.h @@ -38,9 +38,6 @@ public: QStringList activities() const override; QVector desktops() const override; QPoint clientPos() const override; - QPoint clientContentPos() const override { - return m_contentPos; - } QRect transparentRect() const override; bool isDeleted() const override; xcb_window_t frameId() const override; @@ -117,7 +114,6 @@ private: int desk; QStringList activityList; QRect contentsRect; // for clientPos()/clientSize() - QPoint m_contentPos; QRect transparent_rect; xcb_window_t m_frame; QVector m_desktops; diff --git a/src/internal_client.cpp b/src/internal_client.cpp index 9109831b6c..aa9af8caab 100644 --- a/src/internal_client.cpp +++ b/src/internal_client.cpp @@ -120,11 +120,6 @@ QString InternalClient::captionSuffix() const return m_captionSuffix; } -QPoint InternalClient::clientContentPos() const -{ - return -1 * clientPos(); -} - QSize InternalClient::minSize() const { return m_internalWindow->minimumSize(); diff --git a/src/internal_client.h b/src/internal_client.h index f33be0fd8c..b11f1ab481 100644 --- a/src/internal_client.h +++ b/src/internal_client.h @@ -27,7 +27,6 @@ public: qreal bufferScale() const override; QString captionNormal() const override; QString captionSuffix() const override; - QPoint clientContentPos() const override; QSize minSize() const override; QSize maxSize() const override; QRect transparentRect() const override; diff --git a/src/pointer_input.cpp b/src/pointer_input.cpp index aa8c78788b..d85915b06e 100644 --- a/src/pointer_input.cpp +++ b/src/pointer_input.cpp @@ -701,7 +701,7 @@ void PointerInputRedirection::updatePointerConstraints() m_locked = false; disconnectLockedPointerAboutToBeUnboundConnection(); if (! (hint.x() < 0 || hint.y() < 0) && focus()) { - processMotion(focus()->pos() - focus()->clientContentPos() + hint, waylandServer()->seat()->timestamp()); + processMotion(focus()->mapFromLocal(hint), waylandServer()->seat()->timestamp()); } } return; @@ -719,7 +719,7 @@ void PointerInputRedirection::updatePointerConstraints() if (hint.x() < 0 || hint.y() < 0 || !focus()) { return; } - auto globalHint = focus()->pos() - focus()->clientContentPos() + hint; + auto globalHint = focus()->mapFromLocal(hint); // When the resource finally goes away, reposition the cursor according to the hint connect(lock, &KWaylandServer::LockedPointerV1Interface::destroyed, this, diff --git a/src/toplevel.cpp b/src/toplevel.cpp index 90af9bcd2e..6026aa5a47 100644 --- a/src/toplevel.cpp +++ b/src/toplevel.cpp @@ -686,6 +686,11 @@ QPointF Toplevel::mapToLocal(const QPointF &point) const return point - bufferGeometry().topLeft(); } +QPointF Toplevel::mapFromLocal(const QPointF &point) const +{ + return point + bufferGeometry().topLeft(); +} + QRect Toplevel::inputGeometry() const { return frameGeometry(); diff --git a/src/toplevel.h b/src/toplevel.h index 076fabd362..456a7d8a6a 100644 --- a/src/toplevel.h +++ b/src/toplevel.h @@ -357,11 +357,6 @@ public: */ virtual qreal bufferScale() const; virtual QPoint clientPos() const = 0; // inside of geometry() - /** - * Describes how the client's content maps to the window geometry including the frame. - * The default implementation is a 1:1 mapping meaning the frame is part of the content. - */ - virtual QPoint clientContentPos() const; QSize clientSize() const; /** * Returns a rectangle that the window occupies on the screen, including drop-shadows. @@ -382,6 +377,7 @@ public: */ QPoint mapToLocal(const QPoint &point) const; QPointF mapToLocal(const QPointF &point) const; + QPointF mapFromLocal(const QPointF &point) const; // prefer isXXX() instead // 0 for supported types means default for managed/unmanaged types @@ -1006,11 +1002,6 @@ inline QImage Toplevel::internalImageObject() const return m_internalImage; } -inline QPoint Toplevel::clientContentPos() const -{ - return QPoint(0, 0); -} - template inline T *Toplevel::findInList(const QList &list, std::function func) { diff --git a/src/waylandclient.cpp b/src/waylandclient.cpp index 1d869b9224..b2543de563 100644 --- a/src/waylandclient.cpp +++ b/src/waylandclient.cpp @@ -65,11 +65,6 @@ QString WaylandClient::captionSuffix() const return m_captionSuffix; } -QPoint WaylandClient::clientContentPos() const -{ - return -clientPos(); -} - QRect WaylandClient::transparentRect() const { return QRect(); diff --git a/src/waylandclient.h b/src/waylandclient.h index 308656f101..84e76e0c39 100644 --- a/src/waylandclient.h +++ b/src/waylandclient.h @@ -25,7 +25,6 @@ public: QString captionNormal() const override; QString captionSuffix() const override; - QPoint clientContentPos() const override; QRect transparentRect() const override; pid_t pid() const override; bool isLockScreen() const override;