diff --git a/plugins/platforms/virtual/screens_virtual.cpp b/plugins/platforms/virtual/screens_virtual.cpp index 49b3836c6..18f29680c 100644 --- a/plugins/platforms/virtual/screens_virtual.cpp +++ b/plugins/platforms/virtual/screens_virtual.cpp @@ -1,94 +1,94 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2015 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "screens_virtual.h" #include "virtual_backend.h" #include "virtual_output.h" namespace KWin { VirtualScreens::VirtualScreens(VirtualBackend *backend, QObject *parent) : Screens(parent) , m_backend(backend) { } VirtualScreens::~VirtualScreens() = default; void VirtualScreens::init() { updateCount(); KWin::Screens::init(); connect(m_backend, &VirtualBackend::virtualOutputsSet, this, [this] (bool countChanged) { if (countChanged) { setCount(m_backend->outputCount()); } else { emit changed(); } } ); emit changed(); } QRect VirtualScreens::geometry(int screen) const { const auto outputs = m_backend->outputs(); if (screen >= outputs.size()) { return QRect(); } - return outputs.at(screen).geometry(); + return outputs.at(screen)->geometry(); } QSize VirtualScreens::size(int screen) const { return geometry(screen).size(); } void VirtualScreens::updateCount() { setCount(m_backend->outputCount()); } int VirtualScreens::number(const QPoint &pos) const { int bestScreen = 0; int minDistance = INT_MAX; const auto outputs = m_backend->outputs(); for (int i = 0; i < outputs.size(); ++i) { - const QRect &geo = outputs.at(i).geometry(); + const QRect &geo = outputs.at(i)->geometry(); 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; } } diff --git a/plugins/platforms/virtual/virtual_backend.cpp b/plugins/platforms/virtual/virtual_backend.cpp index 1afc3d68a..fe6d4c443 100644 --- a/plugins/platforms/virtual/virtual_backend.cpp +++ b/plugins/platforms/virtual/virtual_backend.cpp @@ -1,146 +1,148 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2015 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #include "virtual_backend.h" +#include "virtual_output.h" #include "scene_qpainter_virtual_backend.h" #include "screens_virtual.h" #include "wayland_server.h" #include "egl_gbm_backend.h" // Qt #include // KWayland #include // system #include #include #include #if HAVE_GBM #include #endif -#include namespace KWin { VirtualBackend::VirtualBackend(QObject *parent) : Platform(parent) { if (qEnvironmentVariableIsSet("KWIN_WAYLAND_VIRTUAL_SCREENSHOTS")) { m_screenshotDir.reset(new QTemporaryDir); if (!m_screenshotDir->isValid()) { m_screenshotDir.reset(); } if (!m_screenshotDir.isNull()) { qDebug() << "Screenshots saved to: " << m_screenshotDir->path(); } } setSupportsPointerWarping(true); setSupportsGammaControl(true); } VirtualBackend::~VirtualBackend() { #if HAVE_GBM if (m_gbmDevice) { gbm_device_destroy(m_gbmDevice); } #endif if (m_drmFd != -1) { close(m_drmFd); } } void VirtualBackend::init() { /* * Some tests currently expect one output present at start, * others set them explicitly. * * TODO: rewrite all tests to explicitly set the outputs. */ if (!m_outputs.size()) { - auto dummyOutput = VirtualOutput(this); - dummyOutput.m_geo = QRect(QPoint(0, 0), initialWindowSize()); + VirtualOutput *dummyOutput = new VirtualOutput(this); + dummyOutput->m_geo = QRect(QPoint(0, 0), initialWindowSize()); m_outputs = { dummyOutput }; } setSoftWareCursor(true); setReady(true); waylandServer()->seat()->setHasPointer(true); waylandServer()->seat()->setHasKeyboard(true); waylandServer()->seat()->setHasTouch(true); emit screensQueried(); } QString VirtualBackend::screenshotDirPath() const { if (m_screenshotDir.isNull()) { return QString(); } return m_screenshotDir->path(); } Screens *VirtualBackend::createScreens(QObject *parent) { return new VirtualScreens(this, parent); } QPainterBackend *VirtualBackend::createQPainterBackend() { return new VirtualQPainterBackend(this); } OpenGLBackend *VirtualBackend::createOpenGLBackend() { return new EglGbmBackend(this); } void VirtualBackend::setVirtualOutputs(int count, QVector geometries) { Q_ASSERT(geometries.size() == 0 || geometries.size() == count); bool countChanged = m_outputs.size() != count; + qDeleteAll(m_outputs.begin(), m_outputs.end()); m_outputs.resize(count); int sumWidth = 0; for (int i = 0; i < count; i++) { - VirtualOutput& o = m_outputs[i]; + VirtualOutput *vo = new VirtualOutput(this); if (geometries.size()) { - o.m_geo = geometries.at(i); - } else if (!o.m_geo.isValid()) { - o.m_geo = QRect(QPoint(sumWidth, 0), initialWindowSize()); - sumWidth += o.m_geo.width(); + vo->m_geo = geometries.at(i); + } else if (!vo->m_geo.isValid()) { + vo->m_geo = QRect(QPoint(sumWidth, 0), initialWindowSize()); + sumWidth += vo->m_geo.width(); } + m_outputs[i] = vo; } emit virtualOutputsSet(countChanged); } int VirtualBackend::gammaRampSize(int screen) const { - return m_outputs[screen].m_gammaSize; + return m_outputs[screen]->m_gammaSize; } bool VirtualBackend::setGammaRamp(int screen, ColorCorrect::GammaRamp &gamma) { Q_UNUSED(gamma); - return m_outputs[screen].m_gammaResult; + return m_outputs[screen]->m_gammaResult; } } diff --git a/plugins/platforms/virtual/virtual_backend.h b/plugins/platforms/virtual/virtual_backend.h index c0baa698b..eda2c118a 100644 --- a/plugins/platforms/virtual/virtual_backend.h +++ b/plugins/platforms/virtual/virtual_backend.h @@ -1,109 +1,108 @@ /******************************************************************** KWin - the KDE window manager This file is part of the KDE project. Copyright (C) 2015 Martin Gräßlin This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . *********************************************************************/ #ifndef KWIN_VIRTUAL_BACKEND_H #define KWIN_VIRTUAL_BACKEND_H #include "platform.h" -#include "virtual_output.h" #include #include #include class QTemporaryDir; struct gbm_device; namespace KWin { -struct ColorCorrect::GammaRamp; +class VirtualOutput; class KWIN_EXPORT VirtualBackend : public Platform { Q_OBJECT Q_INTERFACES(KWin::Platform) Q_PLUGIN_METADATA(IID "org.kde.kwin.Platform" FILE "virtual.json") public: VirtualBackend(QObject *parent = nullptr); virtual ~VirtualBackend(); void init() override; int outputCount() const { return m_outputs.size(); } - const QVector outputs() const { + const QVector outputs() const { return m_outputs; } qreal outputScale() const { return m_outputScale; } bool saveFrames() const { return !m_screenshotDir.isNull(); } QString screenshotDirPath() const; Screens *createScreens(QObject *parent = nullptr) override; QPainterBackend* createQPainterBackend() override; OpenGLBackend *createOpenGLBackend() override; Q_INVOKABLE void setVirtualOutputs(int count, QVector geometries = QVector()); Q_INVOKABLE void setOutputScale(qreal scale) { m_outputScale = scale; } int drmFd() const { return m_drmFd; } void setDrmFd(int fd) { m_drmFd = fd; } gbm_device *gbmDevice() const { return m_gbmDevice; } void setGbmDevice(gbm_device *device) { m_gbmDevice = device; } virtual int gammaRampSize(int screen) const override; virtual bool setGammaRamp(int screen, ColorCorrect::GammaRamp &gamma) override; QVector supportedCompositors() const override { return QVector{OpenGLCompositing, QPainterCompositing}; } Q_SIGNALS: void virtualOutputsSet(bool countChanged); private: - QVector m_outputs; + QVector m_outputs; qreal m_outputScale = 1; QScopedPointer m_screenshotDir; int m_drmFd = -1; gbm_device *m_gbmDevice = nullptr; }; } #endif