File indexing completed on 2024-04-28 16:45:09

0001 /*
0002     SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDED_GENERATOR_H
0008 #define KDED_GENERATOR_H
0009 
0010 #include <QObject>
0011 
0012 #include <kscreen/config.h>
0013 #include <kscreen/mode.h>
0014 #include <kscreen/output.h>
0015 
0016 namespace KScreen
0017 {
0018 class Config;
0019 }
0020 class Generator : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     enum DisplaySwitchAction {
0025         None = 0,
0026         Clone = 1,
0027         ExtendToLeft = 2,
0028         TurnOffEmbedded = 3,
0029         TurnOffExternal = 4,
0030         ExtendToRight = 5,
0031     };
0032 
0033     static Generator *self();
0034     static void destroy();
0035 
0036     void setCurrentConfig(const KScreen::ConfigPtr &currentConfig);
0037 
0038     KScreen::ConfigPtr idealConfig(const KScreen::ConfigPtr &currentConfig);
0039     KScreen::ConfigPtr displaySwitch(DisplaySwitchAction iteration);
0040 
0041     void setForceLaptop(bool force);
0042     void setForceLidClosed(bool force);
0043     void setForceDocked(bool force);
0044     void setForceNotLaptop(bool force);
0045 
0046     static KScreen::ModePtr biggestMode(const KScreen::ModeList &modes);
0047     qreal bestScaleForOutput(const KScreen::OutputPtr &output);
0048 
0049 Q_SIGNALS:
0050     void ready();
0051 
0052 private:
0053     explicit Generator();
0054     ~Generator() override;
0055 
0056     KScreen::ConfigPtr fallbackIfNeeded(const KScreen::ConfigPtr &config);
0057 
0058     void cloneScreens(const KScreen::ConfigPtr &config);
0059     void laptop(KScreen::ConfigPtr &config);
0060     void singleOutput(KScreen::ConfigPtr &config);
0061     void extendToRight(KScreen::ConfigPtr &config, KScreen::OutputList usableOutputs);
0062 
0063     void initializeOutput(const KScreen::OutputPtr &output, KScreen::Config::Features features);
0064     KScreen::ModePtr bestModeForSize(const KScreen::ModeList &modes, const QSize &size);
0065     KScreen::ModePtr bestModeForOutput(const KScreen::OutputPtr &output);
0066 
0067     KScreen::OutputPtr biggestOutput(const KScreen::OutputList &connectedOutputs);
0068     KScreen::OutputPtr embeddedOutput(const KScreen::OutputList &connectedOutputs);
0069     void disableAllDisconnectedOutputs(const KScreen::OutputList &connectedOutputs);
0070 
0071     bool isLaptop() const;
0072     bool isLidClosed() const;
0073     bool isDocked() const;
0074 
0075     bool m_forceLaptop;
0076     bool m_forceLidClosed;
0077     bool m_forceNotLaptop;
0078     bool m_forceDocked;
0079 
0080     KScreen::ConfigPtr m_currentConfig;
0081 
0082     static Generator *instance;
0083 };
0084 
0085 #endif // KDED_GENERATOR_H