File indexing completed on 2024-04-28 05:27:38

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 QSortFilterProxyModel;
0024 
0025 class KCMKScreen : public KQuickManagedConfigModule
0026 {
0027     Q_OBJECT
0028 
0029     Q_PROPERTY(QAbstractItemModel *outputModel READ outputModel CONSTANT)
0030     Q_PROPERTY(bool backendReady READ backendReady NOTIFY backendReadyChanged)
0031     Q_PROPERTY(bool screenNormalized READ screenNormalized NOTIFY screenNormalizedChanged)
0032     Q_PROPERTY(bool perOutputScaling READ perOutputScaling NOTIFY perOutputScalingChanged)
0033     Q_PROPERTY(bool xwaylandClientsScaleSupported READ xwaylandClientsScaleSupported NOTIFY xwaylandClientsScaleSupportedChanged)
0034     Q_PROPERTY(bool primaryOutputSupported READ primaryOutputSupported NOTIFY primaryOutputSupportedChanged)
0035     Q_PROPERTY(bool outputReplicationSupported READ outputReplicationSupported NOTIFY outputReplicationSupportedChanged)
0036     Q_PROPERTY(bool tearingSupported READ tearingSupported NOTIFY tearingSupportedChanged)
0037     Q_PROPERTY(qreal globalScale READ globalScale WRITE setGlobalScale NOTIFY globalScaleChanged)
0038     Q_PROPERTY(bool autoRotationSupported READ autoRotationSupported NOTIFY autoRotationSupportedChanged)
0039     Q_PROPERTY(bool orientationSensorAvailable READ orientationSensorAvailable NOTIFY orientationSensorAvailableChanged)
0040     Q_PROPERTY(bool tabletModeAvailable READ tabletModeAvailable NOTIFY tabletModeAvailableChanged)
0041     Q_PROPERTY(bool xwaylandClientsScale READ xwaylandClientsScale WRITE setXwaylandClientsScale NOTIFY xwaylandClientsScaleChanged)
0042     Q_PROPERTY(bool tearingAllowed READ allowTearing WRITE setAllowTearing NOTIFY tearingAllowedChanged)
0043     Q_PROPERTY(bool multipleScreensAvailable READ multipleScreensAvailable NOTIFY multipleScreensAvailableChanged)
0044 
0045 public:
0046     enum InvalidConfigReason {
0047         NoEnabledOutputs,
0048         ConfigHasGaps,
0049     };
0050     Q_ENUM(InvalidConfigReason)
0051 
0052     explicit KCMKScreen(QObject *parent, const KPluginMetaData &data);
0053 
0054     void load() override;
0055     void save() override;
0056     void defaults() override;
0057 
0058     bool isSaveNeeded() const override;
0059 
0060     QAbstractItemModel *outputModel() const;
0061 
0062     Q_INVOKABLE void identifyOutputs();
0063 
0064     bool backendReady() const;
0065 
0066     Q_INVOKABLE QSize normalizeScreen() const;
0067     bool screenNormalized() const;
0068 
0069     bool perOutputScaling() const;
0070     bool primaryOutputSupported() const;
0071     bool outputReplicationSupported() const;
0072 
0073     qreal globalScale() const;
0074     void setGlobalScale(qreal scale);
0075 
0076     bool xwaylandClientsScale() const;
0077     void setXwaylandClientsScale(bool scale);
0078     bool xwaylandClientsScaleSupported() const;
0079 
0080     void setAllowTearing(bool allow);
0081     bool allowTearing() const;
0082     bool tearingSupported() const;
0083 
0084     bool autoRotationSupported() const;
0085     bool orientationSensorAvailable() const;
0086     bool tabletModeAvailable() const;
0087 
0088     bool multipleScreensAvailable() const;
0089 
0090     void doSave();
0091     Q_INVOKABLE void revertSettings();
0092     Q_INVOKABLE void requestReboot();
0093 
0094     Q_INVOKABLE void setStopUpdatesFromBackend(bool value);
0095     Q_INVOKABLE void updateFromBackend();
0096 
0097 Q_SIGNALS:
0098     void backendReadyChanged();
0099     void backendError();
0100     void changed();
0101     void screenNormalizedChanged();
0102     void perOutputScalingChanged();
0103     void primaryOutputSupportedChanged();
0104     void outputReplicationSupportedChanged();
0105     void globalScaleChanged();
0106     void autoRotationSupportedChanged();
0107     void orientationSensorAvailableChanged();
0108     void tabletModeAvailableChanged();
0109     void invalidConfig(InvalidConfigReason reason);
0110     void errorOnSave();
0111     void globalScaleWritten();
0112     void outputConnect(bool connected);
0113     void settingsReverted();
0114     void showRevertWarning();
0115     void xwaylandClientsScaleChanged();
0116     void xwaylandClientsScaleSupportedChanged();
0117     void tearingSupportedChanged();
0118     void tearingAllowedChanged();
0119     void multipleScreensAvailableChanged();
0120 
0121 private:
0122     void setBackendReady(bool error);
0123     void setScreenNormalized(bool normalized);
0124 
0125     void exportGlobalScale();
0126 
0127     void configReady(KScreen::ConfigOperation *op);
0128     void continueNeedsSaveCheck(bool needs);
0129     void checkConfig();
0130 
0131     std::unique_ptr<ConfigHandler> m_configHandler;
0132     OrientationSensor *m_orientationSensor;
0133     bool m_backendReady = false;
0134     bool m_screenNormalized = true;
0135     bool m_settingsReverted = false;
0136     bool m_stopUpdatesFromBackend = false;
0137     bool m_configNeedsSave = false;
0138 
0139     QSortFilterProxyModel *m_outputProxyModel;
0140 
0141     QTimer *m_loadCompressor;
0142 };