[wayland] BasicScreens can serve multiple screens

For this AbstractBackend has a new virtual screenGeometries() method
which returns a QVector<QRect>. By default it's just one QRect at 0/0
with the size of the one screenSize().
This commit is contained in:
Martin Gräßlin 2015-11-20 16:11:35 +01:00
parent 7c5fc2ff96
commit ee7f70afc8
4 changed files with 37 additions and 7 deletions

View file

@ -335,4 +335,9 @@ QSize AbstractBackend::screenSize() const
return QSize();
}
QVector<QRect> AbstractBackend::screenGeometries() const
{
return QVector<QRect>({QRect(QPoint(0, 0), screenSize())});
}
}

View file

@ -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<QRect> screenGeometries() const;
bool usesSoftwareCursor() const {
return m_softWareCursor;

View file

@ -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

View file

@ -29,6 +29,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <QObject>
#include <QRect>
#include <QTimer>
#include <QVector>
namespace KWin
{
@ -167,6 +168,7 @@ public:
private:
AbstractBackend *m_backend;
QVector<QRect> m_geometries;
};
inline