1 /*
2     SPDX-FileCopyrightText: 2012 Alejandro Fiestas Olivares <afiestas@kde.org>
3 
4     SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #ifndef KDED_GENERATOR_H
8 #define KDED_GENERATOR_H
9 
10 #include <QObject>
11 
12 #include <kscreen/config.h>
13 #include <kscreen/mode.h>
14 #include <kscreen/output.h>
15 
16 namespace KScreen
17 {
18 class Config;
19 }
20 class Generator : public QObject
21 {
22     Q_OBJECT
23 public:
24     enum DisplaySwitchAction {
25         None = 0,
26         Clone = 1,
27         ExtendToLeft = 2,
28         TurnOffEmbedded = 3,
29         TurnOffExternal = 4,
30         ExtendToRight = 5,
31     };
32 
33     static Generator *self();
34     static void destroy();
35 
36     void setCurrentConfig(const KScreen::ConfigPtr &currentConfig);
37 
38     KScreen::ConfigPtr idealConfig(const KScreen::ConfigPtr &currentConfig);
39     KScreen::ConfigPtr displaySwitch(DisplaySwitchAction iteration);
40 
41     void setForceLaptop(bool force);
42     void setForceLidClosed(bool force);
43     void setForceDocked(bool force);
44     void setForceNotLaptop(bool force);
45 
46     static KScreen::ModePtr biggestMode(const KScreen::ModeList &modes);
47 
48 Q_SIGNALS:
49     void ready();
50 
51 private:
52     explicit Generator();
53     ~Generator() override;
54 
55     KScreen::ConfigPtr fallbackIfNeeded(const KScreen::ConfigPtr &config);
56 
57     void cloneScreens(KScreen::OutputList &connectedOutputs);
58     void laptop(KScreen::OutputList &connectedOutputs);
59     void singleOutput(KScreen::OutputList &connectedOutputs);
60     void extendToRight(KScreen::OutputList &connectedOutputs);
61 
62     void initializeOutput(const KScreen::OutputPtr &output, KScreen::Config::Features features);
63     KScreen::ModePtr bestModeForSize(const KScreen::ModeList &modes, const QSize &size);
64     KScreen::ModePtr bestModeForOutput(const KScreen::OutputPtr &output);
65     qreal bestScaleForOutput(const KScreen::OutputPtr &output);
66 
67     KScreen::OutputPtr biggestOutput(const KScreen::OutputList &connectedOutputs);
68     KScreen::OutputPtr embeddedOutput(const KScreen::OutputList &connectedOutputs);
69     void disableAllDisconnectedOutputs(const KScreen::OutputList &connectedOutputs);
70 
71     bool isLaptop() const;
72     bool isLidClosed() const;
73     bool isDocked() const;
74 
75     bool m_forceLaptop;
76     bool m_forceLidClosed;
77     bool m_forceNotLaptop;
78     bool m_forceDocked;
79 
80     KScreen::ConfigPtr m_currentConfig;
81 
82     static Generator *instance;
83 };
84 
85 #endif // KDED_GENERATOR_H
86