File indexing completed on 2022-09-27 16:03:56

0001 /*
0002     SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef SCREENPOOL_H
0008 #define SCREENPOOL_H
0009 
0010 // local
0011 #include "data/screendata.h"
0012 
0013 // Qt
0014 #include <QObject>
0015 #include <QHash>
0016 #include <QScreen>
0017 #include <QString>
0018 #include <QTimer>
0019 
0020 // KDE
0021 #include <KConfigGroup>
0022 #include <KSharedConfig>
0023 
0024 class PrimaryOutputWatcher;
0025 
0026 namespace Latte {
0027 
0028 class ScreenPool : public QObject
0029 {
0030     Q_OBJECT
0031 
0032 public:
0033     static const int FIRSTSCREENID = 10;
0034     static const int NOSCREENID = -1;
0035 
0036     ScreenPool(KSharedConfig::Ptr config, QObject *parent = nullptr);
0037     ~ScreenPool() override;
0038 
0039     void load();
0040 
0041     bool hasScreenId(int screenId) const;
0042     bool isScreenActive(int screenId) const;
0043     int primaryScreenId() const;
0044     QList<int> secondaryScreenIds() const;
0045 
0046     void insertScreenMapping(const QString &connector);
0047     void reload(QString path);
0048     void removeScreens(const Latte::Data::ScreensTable &obsoleteScreens);
0049 
0050     int id(const QString &connector) const;
0051 
0052     QString connector(int id) const;
0053 
0054     QScreen *screenForId(int id);
0055     QScreen *primaryScreen() const;
0056 
0057     Latte::Data::ScreensTable screensTable();
0058 
0059 signals:
0060     void primaryScreenChanged(QScreen *screen);
0061     void screenGeometryChanged();
0062 
0063 protected:
0064     int firstAvailableId() const;
0065 
0066 private slots:
0067     void updateScreenGeometry(const QScreen *screen);
0068     void onPrimaryOutputNameChanged(const QString &oldOutputName, const QString &newOutputName);
0069     void onScreenAdded(const QScreen *screen);
0070     void onScreenRemoved(const QScreen *screen);
0071 
0072 private:
0073     void save();
0074     void updateScreenGeometry(const int &screenId, const QRect &screenGeometry);
0075 
0076 private:
0077     Latte::Data::ScreensTable m_screensTable;
0078 
0079     KConfigGroup m_configGroup;
0080 
0081     QTimer m_configSaveTimer;
0082 
0083     PrimaryOutputWatcher *m_primaryWatcher;
0084 };
0085 
0086 }
0087 
0088 #endif // SCREENPOOL_H