From a13ecf8d0e03619d39e7e6065be79f63841af6a7 Mon Sep 17 00:00:00 2001 From: David Edmundson Date: Wed, 8 Apr 2020 10:38:41 +0100 Subject: [PATCH] [wayland] Add new XdgOutput properties Summary: AbstractOutput::name() behaviour is changed so that it matches the X11 behaviour, showing an identifier like "HDMI-0". XdgOutput.name is set to this name. XdgOutput.description is currently set to the manufacturer name and model, but it's not exposed to Qt so we probably don't care too much. This should fix plasmashell changing applets when switching between X11 and wayland. Test Plan: Relevant unit test I still need to run it on my laptop. Reviewers: #kwin, #plasma, zzag Reviewed By: #kwin, #plasma, zzag Subscribers: kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D28230 --- abstract_output.h | 2 +- abstract_wayland_output.cpp | 17 +++++++++++++---- abstract_wayland_output.h | 6 ++++++ autotests/integration/screen_changes_test.cpp | 4 ++++ plugins/platforms/drm/drm_output.cpp | 6 +++--- plugins/platforms/fbdev/fb_backend.cpp | 6 ++++++ plugins/platforms/fbdev/fb_backend.h | 2 +- plugins/platforms/virtual/virtual_output.cpp | 3 +++ plugins/platforms/wayland/wayland_output.cpp | 4 ++++ .../x11/windowed/x11windowed_output.cpp | 4 ++++ 10 files changed, 45 insertions(+), 9 deletions(-) diff --git a/abstract_output.h b/abstract_output.h index 16aaa90e9e..bf2741504f 100644 --- a/abstract_output.h +++ b/abstract_output.h @@ -104,7 +104,7 @@ public: ~AbstractOutput() override; /** - * Returns the human readable name of this output. + * Returns a short identifiable name of this output. */ virtual QString name() const = 0; diff --git a/abstract_wayland_output.cpp b/abstract_wayland_output.cpp index 060cb8bd41..4426b63926 100644 --- a/abstract_wayland_output.cpp +++ b/abstract_wayland_output.cpp @@ -54,8 +54,7 @@ AbstractWaylandOutput::~AbstractWaylandOutput() QString AbstractWaylandOutput::name() const { - return QStringLiteral("%1 %2").arg(m_waylandOutputDevice->manufacturer()).arg( - m_waylandOutputDevice->model()); + return m_name; } QByteArray AbstractWaylandOutput::uuid() const @@ -234,6 +233,12 @@ void AbstractWaylandOutput::setEnabled(bool enable) } } +QString AbstractWaylandOutput::description() const +{ + return QStringLiteral("%1 %2").arg(m_waylandOutputDevice->manufacturer()).arg( + m_waylandOutputDevice->model()); +} + void AbstractWaylandOutput::setWaylandMode(const QSize &size, int refreshRate) { m_waylandOutput->setCurrentMode(size, refreshRate); @@ -275,9 +280,13 @@ void AbstractWaylandOutput::initInterfaces(const QString &model, const QString & m_waylandOutput->addMode(mode.size, flags, mode.refreshRate); } - // start off enabled - m_waylandOutput->create(); m_waylandOutputDevice->create(); + + // start off enabled + + m_waylandOutput->create(); + m_xdgOutput->setName(name()); + m_xdgOutput->setDescription(description()); m_xdgOutput->setLogicalSize(pixelSize() / scale()); m_xdgOutput->done(); } diff --git a/abstract_wayland_output.h b/abstract_wayland_output.h index f89458c324..73ef7bd71d 100644 --- a/abstract_wayland_output.h +++ b/abstract_wayland_output.h @@ -124,6 +124,8 @@ public: */ void setEnabled(bool enable) override; + QString description() const; + Q_SIGNALS: void modeChanged(); @@ -137,6 +139,9 @@ protected: bool internal() const { return m_internal; } + void setName(const QString &name) { + m_name = name; + } void setInternal(bool set) { m_internal = set; } @@ -170,6 +175,7 @@ private: KWayland::Server::OutputDeviceInterface *m_waylandOutputDevice; KWayland::Server::OutputInterface::DpmsMode m_dpms = KWayland::Server::OutputInterface::DpmsMode::On; + QString m_name; bool m_internal = false; }; diff --git a/autotests/integration/screen_changes_test.cpp b/autotests/integration/screen_changes_test.cpp index e06afa1634..1ee2b4153f 100644 --- a/autotests/integration/screen_changes_test.cpp +++ b/autotests/integration/screen_changes_test.cpp @@ -155,6 +155,10 @@ void ScreenChangesTest::testScreenAddRemove() QCOMPARE(xdgO2->logicalPosition(), geometries.at(1).topLeft()); QCOMPARE(xdgO2->logicalSize(), geometries.at(1).size()); + QVERIFY(xdgO1->name().startsWith("Virtual-")); + QVERIFY(xdgO1->name() != xdgO2->name()); + QVERIFY(!xdgO1->description().isEmpty()); + // now let's try to remove one output again outputAnnouncedSpy.clear(); outputRemovedSpy.clear(); diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp index 4626bf0ec0..ad91d8aa63 100644 --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -300,7 +300,7 @@ void DrmOutput::initOutputDevice(drmModeConnector *connector) manufacturer = QString::fromLatin1(m_edid.eisaId()); } - QString connectorName = s_connectorNames.value(connector->connector_type, QByteArrayLiteral("Unknown")); + QString connectorName = s_connectorNames.value(connector->connector_type, QByteArrayLiteral("Unknown")) + QStringLiteral("-") + QString::number(connector->connector_type_id); QString modelName; if (!m_edid.monitorName().isEmpty()) { @@ -316,7 +316,7 @@ void DrmOutput::initOutputDevice(drmModeConnector *connector) modelName = i18n("unknown"); } - const QString model = connectorName + QStringLiteral("-") + QString::number(connector->connector_type_id) + QStringLiteral("-") + modelName; + const QString model = connectorName + QStringLiteral("-") + modelName; // read in mode information QVector modes; @@ -352,7 +352,7 @@ void DrmOutput::initOutputDevice(drmModeConnector *connector) qCWarning(KWIN_DRM) << "Overwriting monitor physical size for" << m_edid.eisaId() << "/" << m_edid.monitorName() << "/" << m_edid.serialNumber() << " from " << physicalSize << "to " << overwriteSize; physicalSize = overwriteSize; } - + setName(connectorName); initInterfaces(model, manufacturer, m_uuid, physicalSize, modes); } diff --git a/plugins/platforms/fbdev/fb_backend.cpp b/plugins/platforms/fbdev/fb_backend.cpp index dc0cfeba1d..931d7b7998 100644 --- a/plugins/platforms/fbdev/fb_backend.cpp +++ b/plugins/platforms/fbdev/fb_backend.cpp @@ -37,6 +37,12 @@ along with this program. If not, see . namespace KWin { +FramebufferOutput::FramebufferOutput(QObject *parent): + AbstractWaylandOutput(parent) +{ + setName("FB-0"); +} + void FramebufferOutput::init(const QSize &pixelSize, const QSize &physicalSize) { KWayland::Server::OutputDeviceInterface::Mode mode; diff --git a/plugins/platforms/fbdev/fb_backend.h b/plugins/platforms/fbdev/fb_backend.h index c71c377217..7edee4f2cc 100644 --- a/plugins/platforms/fbdev/fb_backend.h +++ b/plugins/platforms/fbdev/fb_backend.h @@ -34,7 +34,7 @@ class FramebufferOutput : public AbstractWaylandOutput Q_OBJECT public: - FramebufferOutput(QObject *parent = nullptr) : AbstractWaylandOutput(parent) {} + FramebufferOutput(QObject *parent = nullptr); ~FramebufferOutput() override = default; void init(const QSize &pixelSize, const QSize &physicalSize); diff --git a/plugins/platforms/virtual/virtual_output.cpp b/plugins/platforms/virtual/virtual_output.cpp index 6b7f114961..28ad0f15ea 100644 --- a/plugins/platforms/virtual/virtual_output.cpp +++ b/plugins/platforms/virtual/virtual_output.cpp @@ -26,6 +26,9 @@ VirtualOutput::VirtualOutput(QObject *parent) : AbstractWaylandOutput() { Q_UNUSED(parent); + static int identifier = -1; + identifier++; + setName("Virtual-" + QString::number(identifier)); } VirtualOutput::~VirtualOutput() diff --git a/plugins/platforms/wayland/wayland_output.cpp b/plugins/platforms/wayland/wayland_output.cpp index 54c4ba44c2..bd253c96b6 100644 --- a/plugins/platforms/wayland/wayland_output.cpp +++ b/plugins/platforms/wayland/wayland_output.cpp @@ -41,6 +41,10 @@ WaylandOutput::WaylandOutput(Surface *surface, WaylandBackend *backend) , m_surface(surface) , m_backend(backend) { + static int identifier = -1; + identifier++; + setName("WL-" + QString::number(identifier)); + connect(surface, &Surface::frameRendered, [this] { m_rendered = true; emit frameRendered(); diff --git a/plugins/platforms/x11/windowed/x11windowed_output.cpp b/plugins/platforms/x11/windowed/x11windowed_output.cpp index 57d032dd9a..896faf0368 100644 --- a/plugins/platforms/x11/windowed/x11windowed_output.cpp +++ b/plugins/platforms/x11/windowed/x11windowed_output.cpp @@ -37,6 +37,10 @@ X11WindowedOutput::X11WindowedOutput(X11WindowedBackend *backend) , m_backend(backend) { m_window = xcb_generate_id(m_backend->connection()); + + static int identifier = -1; + identifier++; + setName("X11-" + QString::number(identifier)); } X11WindowedOutput::~X11WindowedOutput()