File indexing completed on 2024-04-28 16:45:06
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 "../common/control.h" 0009 0010 #include <kscreen/config.h> 0011 0012 #include <memory> 0013 0014 class OutputModel; 0015 0016 class ConfigHandler : public QObject 0017 { 0018 Q_OBJECT 0019 public: 0020 explicit ConfigHandler(QObject *parent = nullptr); 0021 ~ConfigHandler() override = default; 0022 0023 void setConfig(KScreen::ConfigPtr config); 0024 void updateInitialData(); 0025 0026 OutputModel *outputModel() const 0027 { 0028 return m_outputModel; 0029 } 0030 0031 QSize normalizeScreen(); 0032 0033 KScreen::ConfigPtr config() const 0034 { 0035 return m_config; 0036 } 0037 0038 KScreen::ConfigPtr initialConfig() const 0039 { 0040 return m_initialConfig; 0041 } 0042 0043 void revertConfig() 0044 { 0045 m_config = (m_previousConfig ? m_previousConfig : m_initialConfig)->clone(); 0046 } 0047 0048 int retention() const; 0049 void setRetention(int retention); 0050 0051 KScreen::OutputPtr replicationSource(const KScreen::OutputPtr &output) const; 0052 void setReplicationSource(KScreen::OutputPtr &output, const KScreen::OutputPtr &source); 0053 0054 bool autoRotate(const KScreen::OutputPtr &output) const; 0055 void setAutoRotate(KScreen::OutputPtr &output, bool autoRotate); 0056 bool autoRotateOnlyInTabletMode(const KScreen::OutputPtr &output) const; 0057 void setAutoRotateOnlyInTabletMode(KScreen::OutputPtr &output, bool value); 0058 0059 uint32_t overscan(const KScreen::OutputPtr &output) const; 0060 void setOverscan(const KScreen::OutputPtr &output, uint32_t value); 0061 0062 KScreen::Output::VrrPolicy vrrPolicy(const KScreen::OutputPtr &output) const; 0063 void setVrrPolicy(const KScreen::OutputPtr &output, KScreen::Output::VrrPolicy value); 0064 0065 KScreen::Output::RgbRange rgbRange(const KScreen::OutputPtr &output) const; 0066 void setRgbRange(const KScreen::OutputPtr &output, KScreen::Output::RgbRange value); 0067 0068 void writeControl(); 0069 0070 void checkNeedsSave(); 0071 bool shouldTestNewSettings(); 0072 0073 Q_SIGNALS: 0074 void outputModelChanged(); 0075 void changed(); 0076 void screenNormalizationUpdate(bool normalized); 0077 void needsSaveChecked(bool need); 0078 void retentionChanged(); 0079 void outputConnect(bool connected); 0080 0081 private: 0082 void checkScreenNormalization(); 0083 QSize screenSize() const; 0084 Control::OutputRetention getRetention() const; 0085 void outputPrioritiesChanged(); 0086 void initOutput(const KScreen::OutputPtr &output); 0087 /** 0088 * @brief checkSaveandTestCommon - compairs common config changes that would make the config dirty and needed to have the config checked when applied. 0089 * @param isSaveCheck - True if your checking to see if the changes should request a save. 0090 * False if you want to check if you should test the config when applied. 0091 * @return true, if you should check for a save or test the new configuration 0092 */ 0093 bool checkSaveandTestCommon(bool isSaveCheck); 0094 bool checkPrioritiesNeedSave(); 0095 0096 KScreen::ConfigPtr m_config = nullptr; 0097 KScreen::ConfigPtr m_initialConfig; 0098 KScreen::ConfigPtr m_previousConfig = nullptr; 0099 OutputModel *m_outputModel = nullptr; 0100 0101 std::unique_ptr<ControlConfig> m_control; 0102 std::unique_ptr<ControlConfig> m_initialControl; 0103 Control::OutputRetention m_initialRetention = Control::OutputRetention::Undefined; 0104 QSize m_lastNormalizedScreenSize; 0105 };