Warning, file /plasma/libkscreen/backends/kwayland/waylandbackend.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

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 <QProcess>
0021 #include <QSettings>
0022 #include <QStandardPaths>
0023 
0024 #include <KConfig>
0025 #include <KConfigGroup>
0026 
0027 using namespace KScreen;
0028 
0029 WaylandBackend::WaylandBackend()
0030     : KScreen::AbstractBackend()
0031     , m_internalConfig(new WaylandConfig(this))
0032 {
0033     qCDebug(KSCREEN_WAYLAND) << "Loading Wayland backend.";
0034 
0035     connect(m_internalConfig, &WaylandConfig::configChanged, this, [this]() {
0036         const auto newConfig = m_internalConfig->currentConfig();
0037 
0038         KConfig cfg(QStringLiteral("kdeglobals"));
0039 
0040         KConfigGroup kscreenGroup = cfg.group("KScreen");
0041         const bool xwaylandClientsScale = kscreenGroup.readEntry("XwaylandClientsScale", true);
0042 
0043         KConfig kwinCfg(QStringLiteral("kwinrc"));
0044         KConfigGroup xwaylandGroup = kwinCfg.group("Xwayland");
0045         if (xwaylandClientsScale) {
0046             qreal scaleFactor = 1;
0047             const auto outputs = newConfig->outputs();
0048             for (auto output : outputs) {
0049                 if (output->isEnabled()) {
0050                     scaleFactor = std::max(scaleFactor, output->scale());
0051                 }
0052             }
0053 
0054             xwaylandGroup.writeEntry("Scale", scaleFactor, KConfig::Notify);
0055 
0056         } else {
0057             xwaylandGroup.deleteEntry("Scale", KConfig::Notify);
0058         }
0059         // here we rerun the fonts kcm init that does the appropriate xrdb call with the new settings
0060         QProcess::startDetached("kcminit", {"kcm_fonts"});
0061 
0062         Q_EMIT configChanged(newConfig);
0063     });
0064 }
0065 
0066 QString WaylandBackend::name() const
0067 {
0068     return QStringLiteral("kwayland");
0069 }
0070 
0071 QString WaylandBackend::serviceName() const
0072 {
0073     return QStringLiteral("org.kde.KScreen.Backend.KWayland");
0074 }
0075 
0076 ConfigPtr WaylandBackend::config() const
0077 {
0078     // Note: This should ONLY be called from GetConfigOperation!
0079     return m_internalConfig->currentConfig();
0080 }
0081 
0082 void WaylandBackend::setConfig(const KScreen::ConfigPtr &newconfig)
0083 {
0084     if (!newconfig) {
0085         return;
0086     }
0087     // wait for KWin reply
0088     QEventLoop loop;
0089 
0090     connect(m_internalConfig, &WaylandConfig::configChanged, &loop, &QEventLoop::quit);
0091     m_internalConfig->applyConfig(newconfig);
0092 
0093     loop.exec();
0094 }
0095 
0096 QByteArray WaylandBackend::edid(int outputId) const
0097 {
0098     WaylandOutputDevice *output = m_internalConfig->outputMap().value(outputId);
0099     if (!output) {
0100         return QByteArray();
0101     }
0102     return output->edid();
0103 }
0104 
0105 bool WaylandBackend::isValid() const
0106 {
0107     return m_internalConfig->isReady();
0108 }