From ad0f9901b7c4cefbc303e1f99fb98d5bcb3f5a07 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 17 Feb 2021 13:37:02 +0200 Subject: [PATCH] provide single screens data table --- app/data/generictable.cpp | 12 +++++ app/data/generictable.h | 2 + app/data/screendata.cpp | 10 +++- app/data/screendata.h | 2 +- app/layouts/importer.cpp | 2 +- app/screenpool.cpp | 103 +++++++++++++++++++------------------- app/screenpool.h | 9 ++-- 7 files changed, 79 insertions(+), 61 deletions(-) diff --git a/app/data/generictable.cpp b/app/data/generictable.cpp index f643dcca6..6ad09265c 100644 --- a/app/data/generictable.cpp +++ b/app/data/generictable.cpp @@ -172,6 +172,12 @@ const T GenericTable::operator[](const uint &index) const return m_list[index]; } +template +bool GenericTable::containsId(const int &id) const +{ + return containsId(QString::number(id)); +} + template bool GenericTable::containsId(const QString &id) const { @@ -202,6 +208,12 @@ bool GenericTable::rowExists(const int &row) const return (m_list.count()>=0 && row>=0 && row +int GenericTable::indexOf(const int &id) const +{ + return indexOf(QString::number(id)); +} + template int GenericTable::indexOf(const QString &id) const { diff --git a/app/data/generictable.h b/app/data/generictable.h index 4646b6bad..403fb5226 100644 --- a/app/data/generictable.h +++ b/app/data/generictable.h @@ -55,10 +55,12 @@ public: T &operator[](const uint &index); const T operator[](const uint &index) const; + bool containsId(const int &id) const; bool containsId(const QString &id) const; bool containsName(const QString &name) const; bool rowExists(const int &row) const; + int indexOf(const int &id) const; int indexOf(const QString &id) const; int rowCount() const; int sortedPosForName(const QString &name) const; diff --git a/app/data/screendata.cpp b/app/data/screendata.cpp index aac87ebe8..f0d7d0dc3 100644 --- a/app/data/screendata.cpp +++ b/app/data/screendata.cpp @@ -26,7 +26,9 @@ namespace Latte { namespace Data { Screen::Screen() - : Generic() + : Generic(), + hasExplicitViews(false), + geometry(QRect(0, 0, 1920, 1080)) { } @@ -45,6 +47,7 @@ Screen::Screen(const Screen &o) } Screen::Screen(const QString &screenId, const QString &serialized) + : Screen() { init(screenId, serialized); } @@ -88,7 +91,10 @@ void Screen::init(const QString &screenId, const QString &serialized) id = screenId; name = parts[0]; - geometry = parts.count() > 1 ? Latte::stringToRect(parts[1]) : QRect(0, 0, 1920, 1080); + + if (parts.count() > 1) { + geometry = Latte::stringToRect(parts[1]); + } } QString Screen::serialize() const diff --git a/app/data/screendata.h b/app/data/screendata.h index 872928a76..01bc3f1cf 100644 --- a/app/data/screendata.h +++ b/app/data/screendata.h @@ -36,7 +36,7 @@ namespace Data { class Screen : public Generic { public: - static constexpr const char* SERIALIZESPLITTER = "##"; + static constexpr const char* SERIALIZESPLITTER = ":::"; Screen(); Screen(Screen &&o); diff --git a/app/layouts/importer.cpp b/app/layouts/importer.cpp index b300fa0b7..245241ce1 100644 --- a/app/layouts/importer.cpp +++ b/app/layouts/importer.cpp @@ -378,7 +378,7 @@ bool Importer::importOldConfiguration(QString oldConfigPath, QString newName) QString connector = m_screensGroup.readEntry(key, QString()); int id = key.toInt(); - if (id >= 10 && !m_manager->corona()->screenPool()->knownIds().contains(id)) { + if (id >= 10 && !m_manager->corona()->screenPool()->hasScreenId(id)) { m_manager->corona()->screenPool()->insertScreenMapping(id, connector); } } diff --git a/app/screenpool.cpp b/app/screenpool.cpp index 6ef2efcd4..d76a23419 100644 --- a/app/screenpool.cpp +++ b/app/screenpool.cpp @@ -56,8 +56,7 @@ ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent) void ScreenPool::load() { m_lastPrimaryConnector = QString(); - m_connectorForId.clear(); - m_idForConnector.clear(); + m_screensTable.clear(); QScreen *primary = qGuiApp->primaryScreen(); @@ -67,17 +66,15 @@ void ScreenPool::load() //restore the known ids to connector mappings for (const QString &key : m_configGroup.keyList()) { - QString connector = m_configGroup.readEntry(key, QString()); - qDebug() << "connector :" << connector << " - " << key; - - if (!key.isEmpty() && !connector.isEmpty() && - !m_connectorForId.contains(key.toInt()) && - !m_idForConnector.contains(connector)) { - m_connectorForId[key.toInt()] = connector; - m_idForConnector[connector] = key.toInt(); - qDebug() << "Known Screen - " << connector << " - " << key.toInt(); - } else if (m_idForConnector.value(connector) != key.toInt()) { - m_configGroup.deleteEntry(key); + QString serialized = m_configGroup.readEntry(key, QString()); + //qDebug() << "connector :" << connector << " - " << key; + + Data::Screen screenRecord(key, serialized); + //qDebug() << "org.kde.latte ::: " << screenRecord.id << ":" << screenRecord.serialize(); + + if (!key.isEmpty() && !serialized.isEmpty() && !m_screensTable.containsId(key)) { + m_screensTable << screenRecord; + qDebug() << "Known Screen - " << screenRecord.id << " : " << screenRecord.name << " : " << screenRecord.geometry; } } @@ -87,7 +84,7 @@ void ScreenPool::load() // at startup, if it' asked before corona::addOutput() // is performed, driving to the creation of a new containment for (QScreen *screen : qGuiApp->screens()) { - if (!m_idForConnector.contains(screen->name())) { + if (!m_screensTable.containsName(screen->name())) { insertScreenMapping(firstAvailableId(), screen->name()); } } @@ -103,7 +100,7 @@ QString ScreenPool::reportHtml(const QList &assignedScreens) const { QString report; - report += ""; + /* report += "
"; report += "" + "" + "" + @@ -158,7 +155,7 @@ QString ScreenPool::reportHtml(const QList &assignedScreens) const report += ""; } - report += "
" + i18nc("screen id","ID") + "" + i18nc("screen name", "Name") + "" + i18nc("screen type", "Type") + "
"; + report += "";*/ return report; } @@ -184,15 +181,16 @@ void ScreenPool::save() { QMap::const_iterator i; - for (i = m_connectorForId.constBegin(); i != m_connectorForId.constEnd(); ++i) { - m_configGroup.writeEntry(QString::number(i.key()), i.value()); + for (int i=0; iscreens()) { + if (scr->name() == connector) { + screenRecord.geometry = scr->geometry(); + break; + } + } + + //! add/update + if (m_screensTable.containsId(screenId)) { + m_screensTable[screenId] = screenRecord; + } else { + m_screensTable << screenRecord; + } } save(); @@ -218,48 +233,35 @@ void ScreenPool::insertScreenMapping(int id, const QString &connector) int ScreenPool::id(const QString &connector) const { - if (!m_idForConnector.contains(connector)) { - return -1; - } - - return m_idForConnector.value(connector); + QString screenId = m_screensTable.idForName(connector); + return screenId.isEmpty() ? -1 : screenId.toInt(); } QString ScreenPool::connector(int id) const { - Q_ASSERT(m_connectorForId.contains(id)); - - return m_connectorForId.value(id); + int ind = m_screensTable.indexOf(id); + return (ind>=0 ? m_screensTable[ind].name : QString()); } int ScreenPool::firstAvailableId() const { - //start counting from 10, first numbers will - //be used for special cases. - //e.g primaryScreen, id=0 - int i = 10; - - //find the first integer not stored in m_connectorForId - //m_connectorForId is the only map, so the ids are sorted - for (const int &existingId : m_connectorForId.keys()) { - if (i != existingId) { - return i; + //start counting from 10, first numbers will be used for special cases e.g. primaryScreen, id=0 + int availableId = 10; + + for (int row=0; row ScreenPool::knownIds() const -{ - return m_connectorForId.keys(); + return availableId; } bool ScreenPool::hasScreenId(int screenId) const { - return ((screenId!=-1) && knownIds().contains(screenId)); + return ((screenId!=-1) && m_screensTable.containsId(screenId)); } bool ScreenPool::isScreenActive(int screenId) const @@ -282,7 +284,7 @@ QScreen *ScreenPool::screenForId(int id) const auto screens = qGuiApp->screens(); QScreen *screen{qGuiApp->primaryScreen()}; - if (id != -1 && knownIds().contains(id)) { + if (hasScreenId(id)) { QString scrName = connector(id); for (const auto scr : screens) { @@ -295,7 +297,6 @@ QScreen *ScreenPool::screenForId(int id) return screen; } - bool ScreenPool::nativeEventFilter(const QByteArray &eventType, void *message, long int *result) { Q_UNUSED(result); diff --git a/app/screenpool.h b/app/screenpool.h index 23e24e09f..133c943b6 100644 --- a/app/screenpool.h +++ b/app/screenpool.h @@ -50,7 +50,7 @@ public: bool isScreenActive(int screenId) const; int primaryScreenId() const; - void insertScreenMapping(int id, const QString &connector); + void insertScreenMapping(int screenId, const QString &connector); void reload(QString path); int id(const QString &connector) const; @@ -61,9 +61,6 @@ public: QString reportHtml(const QList &assignedScreens) const; - //all ids that are known, included screens not enabled at the moment - QList knownIds() const; - QScreen *screenForId(int id); signals: @@ -81,8 +78,8 @@ private: QString m_lastPrimaryConnector; //order is important - QMap m_connectorForId; - QHash m_idForConnector; + // QMap m_connectorForId; + // QHash m_idForConnector; QTimer m_configSaveTimer; };