File indexing completed on 2024-05-05 05:30:26

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