File indexing completed on 2024-05-12 09:36:12

0001 /*
0002  *  SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003  *  SPDX-FileCopyrightText: 2012, 2013 Daniel Vrátil <dvratil@redhat.com>
0004  *  SPDX-FileCopyrightText: 2014-2015 Sebastian Kügler <sebas@kde.org>
0005  *  SPDX-FileCopyrightText: 2021 Méven Car <meven.car@enioka.com>
0006  *
0007  *  SPDX-License-Identifier: LGPL-2.1-or-later
0008  */
0009 #include "waylandbackend.h"
0010 
0011 #include "waylandconfig.h"
0012 #include "waylandoutputdevice.h"
0013 
0014 #include "kscreen_kwayland_logging.h"
0015 
0016 #include <configmonitor.h>
0017 #include <mode.h>
0018 #include <output.h>
0019 
0020 #include <QEventLoop>
0021 #include <QProcess>
0022 #include <QSettings>
0023 #include <QStandardPaths>
0024 
0025 using namespace KScreen;
0026 
0027 WaylandBackend::WaylandBackend()
0028     : KScreen::AbstractBackend()
0029     , m_internalConfig(new WaylandConfig(this))
0030 {
0031     qCDebug(KSCREEN_WAYLAND) << "Loading Wayland backend.";
0032     connect(m_internalConfig, &WaylandConfig::configChanged, this, [this] {
0033         Q_EMIT configChanged(m_internalConfig->currentConfig());
0034     });
0035 }
0036 
0037 QString WaylandBackend::name() const
0038 {
0039     return QStringLiteral("kwayland");
0040 }
0041 
0042 QString WaylandBackend::serviceName() const
0043 {
0044     return QStringLiteral("org.kde.KScreen.Backend.KWayland");
0045 }
0046 
0047 ConfigPtr WaylandBackend::config() const
0048 {
0049     // Note: This should ONLY be called from GetConfigOperation!
0050     return m_internalConfig->currentConfig();
0051 }
0052 
0053 void WaylandBackend::setConfig(const KScreen::ConfigPtr &newconfig)
0054 {
0055     if (!newconfig) {
0056         return;
0057     }
0058     // wait for KWin reply
0059     QEventLoop loop;
0060 
0061     connect(m_internalConfig, &WaylandConfig::configChanged, &loop, &QEventLoop::quit);
0062     m_internalConfig->applyConfig(newconfig);
0063 
0064     loop.exec();
0065 }
0066 
0067 QByteArray WaylandBackend::edid(int outputId) const
0068 {
0069     WaylandOutputDevice *output = m_internalConfig->outputMap().value(outputId);
0070     if (!output) {
0071         return QByteArray();
0072     }
0073     return output->edid();
0074 }
0075 
0076 bool WaylandBackend::isValid() const
0077 {
0078     return m_internalConfig->isReady();
0079 }
0080 
0081 #include "moc_waylandbackend.cpp"