diff --git a/backends/kwayland/waylandoutput.cpp b/backends/kwayland/waylandoutput.cpp index 1a87f1c..a0f6865 100644 --- a/backends/kwayland/waylandoutput.cpp +++ b/backends/kwayland/waylandoutput.cpp @@ -1,225 +1,225 @@ /************************************************************************************* * Copyright 2014-2015 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ #include "waylandoutput.h" #include "waylandbackend.h" #include "waylandconfig.h" #include "../utils.h" #include #include #include #include using namespace KScreen; namespace Wl = KWayland::Client; const QMap s_rotationMap = { {Wl::OutputDevice::Transform::Normal, Output::None}, {Wl::OutputDevice::Transform::Rotated90, Output::Right}, {Wl::OutputDevice::Transform::Rotated180, Output::Inverted}, {Wl::OutputDevice::Transform::Rotated270, Output::Left}, {Wl::OutputDevice::Transform::Flipped, Output::None}, {Wl::OutputDevice::Transform::Flipped90, Output::Right}, {Wl::OutputDevice::Transform::Flipped180, Output::Inverted}, {Wl::OutputDevice::Transform::Flipped270, Output::Left} }; Output::Rotation toKScreenRotation(const Wl::OutputDevice::Transform transform) { auto it = s_rotationMap.constFind(transform); return it.value(); } Wl::OutputDevice::Transform toKWaylandTransform(const Output::Rotation rotation) { return s_rotationMap.key(rotation); } WaylandOutput::WaylandOutput(quint32 id, WaylandConfig *parent) : QObject(parent) , m_id(id) - , m_output(nullptr) + , m_device(nullptr) { } quint32 WaylandOutput::id() const { - Q_ASSERT(m_output); + Q_ASSERT(m_device); return m_id; } bool WaylandOutput::enabled() const { - return m_output != nullptr; + return m_device != nullptr; } Wl::OutputDevice* WaylandOutput::outputDevice() const { - return m_output; + return m_device; } void WaylandOutput::createOutputDevice(Wl::Registry *registry, quint32 name, quint32 version) { - Q_ASSERT(!m_output); - m_output = registry->createOutputDevice(name, version); + Q_ASSERT(!m_device); + m_device = registry->createOutputDevice(name, version); - connect(m_output, &Wl::OutputDevice::removed, this, &WaylandOutput::deviceRemoved); - connect(m_output, &Wl::OutputDevice::done, this, [this]() { + connect(m_device, &Wl::OutputDevice::removed, this, &WaylandOutput::deviceRemoved); + connect(m_device, &Wl::OutputDevice::done, this, [this]() { Q_EMIT complete(); - connect(m_output, &Wl::OutputDevice::changed, this, &WaylandOutput::changed); + connect(m_device, &Wl::OutputDevice::changed, this, &WaylandOutput::changed); }); } OutputPtr WaylandOutput::toKScreenOutput() { OutputPtr output(new Output()); output->setId(m_id); updateKScreenOutput(output); return output; } void WaylandOutput::updateKScreenOutput(OutputPtr &output) { // Initialize primary output output->setId(m_id); - output->setEnabled(m_output->enabled() == Wl::OutputDevice::Enablement::Enabled); + output->setEnabled(m_device->enabled() == Wl::OutputDevice::Enablement::Enabled); output->setConnected(true); output->setPrimary(true); // FIXME: wayland doesn't have the concept of a primary display output->setName(name()); - output->setSizeMm(m_output->physicalSize()); - output->setPos(m_output->globalPosition()); - output->setRotation(s_rotationMap[m_output->transform()]); + output->setSizeMm(m_device->physicalSize()); + output->setPos(m_device->globalPosition()); + output->setRotation(s_rotationMap[m_device->transform()]); ModeList modeList; QStringList preferredModeIds; m_modeIdMap.clear(); QString currentModeId = QStringLiteral("-1"); - for (const Wl::OutputDevice::Mode &wlMode : m_output->modes()) { + for (const Wl::OutputDevice::Mode &wlMode : m_device->modes()) { ModePtr mode(new Mode()); const QString name = modeName(wlMode); QString modeId = QString::number(wlMode.id); if (modeId.isEmpty()) { qCDebug(KSCREEN_WAYLAND) << "Could not create mode id from" << wlMode.id << ", using" << name << "instead."; modeId = name; } if (m_modeIdMap.contains(modeId)) { qCWarning(KSCREEN_WAYLAND) << "Mode id already in use:" << modeId; } mode->setId(modeId); // KWayland gives the refresh rate as int in mHz mode->setRefreshRate(wlMode.refreshRate / 1000.0); mode->setSize(wlMode.size); mode->setName(name); if (wlMode.flags.testFlag(Wl::OutputDevice::Mode::Flag::Current)) { currentModeId = modeId; } if (wlMode.flags.testFlag(Wl::OutputDevice::Mode::Flag::Preferred)) { preferredModeIds << modeId; } // Update the kscreen => kwayland mode id translation map m_modeIdMap.insert(modeId, wlMode.id); // Add to the modelist which gets set on the output modeList[modeId] = mode; } if (currentModeId == QLatin1String("-1")) { qCWarning(KSCREEN_WAYLAND) << "Could not find the current mode id" << modeList; } output->setCurrentModeId(currentModeId); output->setPreferredModes(preferredModeIds); output->setModes(modeList); - output->setScale(m_output->scale()); - output->setType(Utils::guessOutputType(m_output->model(), m_output->model())); + output->setScale(m_device->scale()); + output->setType(Utils::guessOutputType(m_device->model(), m_device->model())); } bool WaylandOutput::setWlConfig(Wl::OutputConfiguration *wlConfig, const KScreen::OutputPtr &output) { bool changed = false; // enabled? - if ((m_output->enabled() == Wl::OutputDevice::Enablement::Enabled) + if ((m_device->enabled() == Wl::OutputDevice::Enablement::Enabled) != output->isEnabled()) { changed = true; const auto enablement = output->isEnabled() ? Wl::OutputDevice::Enablement::Enabled : Wl::OutputDevice::Enablement::Disabled; - wlConfig->setEnabled(m_output, enablement); + wlConfig->setEnabled(m_device, enablement); } // position - if (m_output->globalPosition() != output->pos()) { + if (m_device->globalPosition() != output->pos()) { changed = true; - wlConfig->setPosition(m_output, output->pos()); + wlConfig->setPosition(m_device, output->pos()); } // scale - if (!qFuzzyCompare(m_output->scaleF(), output->scale())) { + if (!qFuzzyCompare(m_device->scaleF(), output->scale())) { changed = true; - wlConfig->setScaleF(m_output, output->scale()); + wlConfig->setScaleF(m_device, output->scale()); } // rotation - if (toKScreenRotation(m_output->transform()) != output->rotation()) { + if (toKScreenRotation(m_device->transform()) != output->rotation()) { changed = true; - wlConfig->setTransform(m_output, toKWaylandTransform(output->rotation())); + wlConfig->setTransform(m_device, toKWaylandTransform(output->rotation())); } // mode if (m_modeIdMap.contains(output->currentModeId())) { const int newModeId = m_modeIdMap.value(output->currentModeId(), -1); - if (newModeId != m_output->currentMode().id) { + if (newModeId != m_device->currentMode().id) { changed = true; - wlConfig->setMode(m_output, newModeId); + wlConfig->setMode(m_device, newModeId); } } else { qCWarning(KSCREEN_WAYLAND) << "Invalid kscreen mode id:" << output->currentModeId() << "\n\n" << m_modeIdMap; } return changed; } QString WaylandOutput::modeName(const Wl::OutputDevice::Mode &m) const { return QString::number(m.size.width()) + QLatin1Char('x') + QString::number(m.size.height()) + QLatin1Char('@') + QString::number(qRound(m.refreshRate/1000.0)); } QString WaylandOutput::name() const { - Q_ASSERT(m_output); - return QStringLiteral("%1 %2").arg(m_output->manufacturer(), m_output->model()); + Q_ASSERT(m_device); + return QStringLiteral("%1 %2").arg(m_device->manufacturer(), m_device->model()); } QDebug operator<<(QDebug dbg, const WaylandOutput *output) { dbg << "WaylandOutput(Id:" << output->id() <<", Name:" << \ QString(output->outputDevice()->manufacturer() + QLatin1Char(' ') + \ output->outputDevice()->model()) << ")"; return dbg; } diff --git a/backends/kwayland/waylandoutput.h b/backends/kwayland/waylandoutput.h index b70e0e2..c1b5de3 100644 --- a/backends/kwayland/waylandoutput.h +++ b/backends/kwayland/waylandoutput.h @@ -1,85 +1,85 @@ /************************************************************************************* * Copyright 2014-2015 Sebastian Kügler * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Lesser General Public * * License as published by the Free Software Foundation; either * * version 2.1 of the License, or (at your option) any later version. * * * * This library 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 * * Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License along with this library; if not, write to the Free Software * * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *************************************************************************************/ #pragma once #include "waylandconfig.h" #include "abstractbackend.h" #include "output.h" #include #include #include #include #include namespace KWayland { namespace Client { class OutputConfiguration; } } namespace KScreen { class WaylandOutput : public QObject { Q_OBJECT public: explicit WaylandOutput(quint32 id, WaylandConfig *parent = nullptr); ~WaylandOutput() override = default; KScreen::OutputPtr toKScreenOutput(); void updateKScreenOutput(KScreen::OutputPtr &output); quint32 id() const; QString name() const; bool enabled() const; KWayland::Client::OutputDevice* outputDevice() const; void createOutputDevice(KWayland::Client::Registry *registry, quint32 name, quint32 version); bool setWlConfig(KWayland::Client::OutputConfiguration *wlConfig, const KScreen::OutputPtr &output); Q_SIGNALS: void deviceRemoved(); void complete(); // only emitted after complete signal void changed(); private: void showOutput(); QString modeName(const KWayland::Client::OutputDevice::Mode &m) const; quint32 m_id; - KWayland::Client::OutputDevice *m_output; + KWayland::Client::OutputDevice *m_device; KWayland::Client::Registry *m_registry; // left-hand-side: KScreen::Mode, right-hand-side: KWayland's mode.id QMap m_modeIdMap; }; } KSCREEN_EXPORT QDebug operator<<(QDebug dbg, const KScreen::WaylandOutput *output);