File indexing completed on 2024-05-12 09:32:08

0001 /*
0002     SPDX-FileCopyrightText: 2019 Roman Gilg <subdiff@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include <QTimer>
0009 
0010 #include <KQuickManagedConfigModule>
0011 
0012 #include "output_model.h"
0013 
0014 namespace KScreen
0015 {
0016 class ConfigOperation;
0017 }
0018 
0019 class ConfigHandler;
0020 class OrientationSensor;
0021 class OutputIdentifier;
0022 
0023 class KCMKScreen : public KQuickManagedConfigModule
0024 {
0025     Q_OBJECT
0026 
0027     Q_PROPERTY(OutputModel *outputModel READ outputModel NOTIFY outputModelChanged)
0028     Q_PROPERTY(bool backendReady READ backendReady NOTIFY backendReadyChanged)
0029     Q_PROPERTY(bool screenNormalized READ screenNormalized NOTIFY screenNormalizedChanged)
0030     Q_PROPERTY(bool perOutputScaling READ perOutputScaling NOTIFY perOutputScalingChanged)
0031     Q_PROPERTY(bool xwaylandClientsScaleSupported READ xwaylandClientsScaleSupported NOTIFY xwaylandClientsScaleSupportedChanged)
0032     Q_PROPERTY(bool primaryOutputSupported READ primaryOutputSupported NOTIFY primaryOutputSupportedChanged)
0033     Q_PROPERTY(bool outputReplicationSupported READ outputReplicationSupported NOTIFY outputReplicationSupportedChanged)
0034     Q_PROPERTY(bool tearingSupported READ tearingSupported NOTIFY tearingSupportedChanged)
0035     Q_PROPERTY(qreal globalScale READ globalScale WRITE setGlobalScale NOTIFY globalScaleChanged)
0036     Q_PROPERTY(bool autoRotationSupported READ autoRotationSupported NOTIFY autoRotationSupportedChanged)
0037     Q_PROPERTY(bool orientationSensorAvailable READ orientationSensorAvailable NOTIFY orientationSensorAvailableChanged)
0038     Q_PROPERTY(bool tabletModeAvailable READ tabletModeAvailable NOTIFY tabletModeAvailableChanged)
0039     Q_PROPERTY(bool xwaylandClientsScale READ xwaylandClientsScale WRITE setXwaylandClientsScale NOTIFY xwaylandClientsScaleChanged)
0040     Q_PROPERTY(bool tearingAllowed READ allowTearing WRITE setAllowTearing NOTIFY tearingAllowedChanged)
0041 
0042 public:
0043     enum InvalidConfigReason {
0044         NoEnabledOutputs,
0045         ConfigHasGaps,
0046     };
0047     Q_ENUM(InvalidConfigReason)
0048 
0049     explicit KCMKScreen(QObject *parent, const KPluginMetaData &data);
0050 
0051     void load() override;
0052     void save() override;
0053     void defaults() override;
0054 
0055     bool isSaveNeeded() const override;
0056 
0057     OutputModel *outputModel() const;
0058 
0059     Q_INVOKABLE void identifyOutputs();
0060 
0061     bool backendReady() const;
0062 
0063     Q_INVOKABLE QSize normalizeScreen() const;
0064     bool screenNormalized() const;
0065 
0066     bool perOutputScaling() const;
0067     bool primaryOutputSupported() const;
0068     bool outputReplicationSupported() const;
0069 
0070     qreal globalScale() const;
0071     void setGlobalScale(qreal scale);
0072 
0073     bool xwaylandClientsScale() const;
0074     void setXwaylandClientsScale(bool scale);
0075     bool xwaylandClientsScaleSupported() const;
0076 
0077     void setAllowTearing(bool allow);
0078     bool allowTearing() const;
0079     bool tearingSupported() const;
0080 
0081     bool autoRotationSupported() const;
0082     bool orientationSensorAvailable() const;
0083     bool tabletModeAvailable() const;
0084 
0085     void doSave();
0086     Q_INVOKABLE void revertSettings();
0087     Q_INVOKABLE void requestReboot();
0088 
0089     Q_INVOKABLE void setStopUpdatesFromBackend(bool value);
0090     Q_INVOKABLE void updateFromBackend();
0091 
0092 Q_SIGNALS:
0093     void backendReadyChanged();
0094     void backendError();
0095     void outputModelChanged();
0096     void changed();
0097     void screenNormalizedChanged();
0098     void perOutputScalingChanged();
0099     void primaryOutputSupportedChanged();
0100     void outputReplicationSupportedChanged();
0101     void globalScaleChanged();
0102     void autoRotationSupportedChanged();
0103     void orientationSensorAvailableChanged();
0104     void tabletModeAvailableChanged();
0105     void invalidConfig(InvalidConfigReason reason);
0106     void errorOnSave();
0107     void globalScaleWritten();
0108     void outputConnect(bool connected);
0109     void settingsReverted();
0110     void showRevertWarning();
0111     void xwaylandClientsScaleChanged();
0112     void xwaylandClientsScaleSupportedChanged();
0113     void tearingSupportedChanged();
0114     void tearingAllowedChanged();
0115 
0116 private:
0117     void setBackendReady(bool error);
0118     void setScreenNormalized(bool normalized);
0119 
0120     void exportGlobalScale();
0121 
0122     void configReady(KScreen::ConfigOperation *op);
0123     void continueNeedsSaveCheck(bool needs);
0124     void checkConfig();
0125 
0126     std::unique_ptr<ConfigHandler> m_configHandler;
0127     OrientationSensor *m_orientationSensor;
0128     bool m_backendReady = false;
0129     bool m_screenNormalized = true;
0130     bool m_settingsReverted = false;
0131     bool m_stopUpdatesFromBackend = false;
0132     bool m_configNeedsSave = false;
0133 
0134     QTimer *m_loadCompressor;
0135 };