From ee7f70afc8880e42136db75d998679f7870f5b8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 20 Nov 2015 16:11:35 +0100 Subject: [PATCH] [wayland] BasicScreens can serve multiple screens For this AbstractBackend has a new virtual screenGeometries() method which returns a QVector. By default it's just one QRect at 0/0 with the size of the one screenSize(). --- abstract_backend.cpp | 5 +++++ abstract_backend.h | 7 +++++++ screens.cpp | 30 +++++++++++++++++++++++------- screens.h | 2 ++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/abstract_backend.cpp b/abstract_backend.cpp index e02bb89d9b..b1b477882c 100644 --- a/abstract_backend.cpp +++ b/abstract_backend.cpp @@ -335,4 +335,9 @@ QSize AbstractBackend::screenSize() const return QSize(); } +QVector AbstractBackend::screenGeometries() const +{ + return QVector({QRect(QPoint(0, 0), screenSize())}); +} + } diff --git a/abstract_backend.h b/abstract_backend.h index 79d7fc2204..2e12aa0825 100644 --- a/abstract_backend.h +++ b/abstract_backend.h @@ -67,6 +67,13 @@ public: * Base implementation returns an invalid size. **/ virtual QSize screenSize() const; + /** + * Implementing subclasses should provide all geometries in case the backend represents + * a basic screen and uses the BasicScreens. + * + * Base implementation returns one QRect positioned at 0/0 with screenSize() as size. + **/ + virtual QVector screenGeometries() const; bool usesSoftwareCursor() const { return m_softWareCursor; diff --git a/screens.cpp b/screens.cpp index 5a372ce344..72e32ed2fe 100644 --- a/screens.cpp +++ b/screens.cpp @@ -205,29 +205,45 @@ void BasicScreens::init() QRect BasicScreens::geometry(int screen) const { - if (screen == 0) { - return QRect(QPoint(0, 0), size(screen)); + if (screen < m_geometries.count()) { + return m_geometries.at(screen); } return QRect(); } QSize BasicScreens::size(int screen) const { - if (screen == 0) { - return m_backend->screenSize(); + if (screen < m_geometries.count()) { + return m_geometries.at(screen).size(); } return QSize(); } void BasicScreens::updateCount() { - setCount(1); + m_geometries = m_backend->screenGeometries(); + setCount(m_geometries.count()); } int BasicScreens::number(const QPoint &pos) const { - Q_UNUSED(pos) - return 0; + int bestScreen = 0; + int minDistance = INT_MAX; + for (int i = 0; i < m_geometries.count(); ++i) { + const QRect &geo = m_geometries.at(i); + if (geo.contains(pos)) { + return i; + } + int distance = QPoint(geo.topLeft() - pos).manhattanLength(); + distance = qMin(distance, QPoint(geo.topRight() - pos).manhattanLength()); + distance = qMin(distance, QPoint(geo.bottomRight() - pos).manhattanLength()); + distance = qMin(distance, QPoint(geo.bottomLeft() - pos).manhattanLength()); + if (distance < minDistance) { + minDistance = distance; + bestScreen = i; + } + } + return bestScreen; } } // namespace diff --git a/screens.h b/screens.h index 97f1fed399..859ed3cbe1 100644 --- a/screens.h +++ b/screens.h @@ -29,6 +29,7 @@ along with this program. If not, see . #include #include #include +#include namespace KWin { @@ -167,6 +168,7 @@ public: private: AbstractBackend *m_backend; + QVector m_geometries; }; inline