File indexing completed on 2024-04-28 05:36:00

0001 /*
0002     SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QAbstractNativeEventFilter>
0010 #include <QHash>
0011 #include <QObject>
0012 #include <QSet>
0013 #include <QString>
0014 #include <QTimer>
0015 
0016 #include <KConfigGroup>
0017 #include <KSharedConfig>
0018 
0019 class QScreen;
0020 class OutputOrderWatcher;
0021 
0022 class ScreenPool : public QObject
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     explicit ScreenPool(QObject *parent = nullptr);
0028     ~ScreenPool() override;
0029 
0030     int idForName(const QString &connector) const;
0031     int idForScreen(const QScreen *screen) const;
0032 
0033     QScreen *screenForId(int id) const;
0034 
0035     QList<QScreen *> screenOrder() const;
0036     QScreen *primaryScreen() const;
0037     bool noRealOutputsConnected() const;
0038 
0039 Q_SIGNALS:
0040     void screenRemoved(QScreen *screen); // TODO: necessary?
0041     void screenOrderChanged(const QList<QScreen *> &screens);
0042 
0043 private:
0044     void insertScreenMapping(int id, const QString &connector);
0045     int firstAvailableId() const;
0046 
0047     QScreen *outputRedundantTo(QScreen *screen) const;
0048     void reconsiderOutputs();
0049     void reconsiderOutputOrder();
0050     bool isOutputFake(QScreen *screen) const;
0051 
0052     void insertSortedScreen(QScreen *screen);
0053     void handleScreenAdded(QScreen *screen);
0054     void handleScreenRemoved(QScreen *screen);
0055     void handleOutputOrderChanged(const QStringList &newOrder);
0056     void handleScreenGeometryChanged(QScreen *screen);
0057 
0058     void screenInvariants();
0059 
0060     // List correspondent to qGuiApp->screens(), but sorted first by size then by Id,
0061     // determines the screen importance while figuring out the reduntant ones
0062     QList<QScreen *> m_sizeSortedScreens;
0063     // This will always be true: m_availableScreens + m_redundantScreens + m_fakeScreens == qGuiApp->screens()
0064     QList<QScreen *> m_availableScreens; // Those are all the screen that are available to Corona, ordered by id coming from the protocol
0065     QHash<QScreen *, QScreen *> m_redundantScreens;
0066     QSet<QScreen *> m_fakeScreens;
0067 
0068     bool m_orderChangedPendingSignal = false;
0069 
0070     OutputOrderWatcher *m_outputOrderWatcher;
0071     friend QDebug operator<<(QDebug d, const ScreenPool *pool);
0072 };
0073 
0074 QDebug operator<<(QDebug d, const ScreenPool *pool);