mirror of
https://github.com/KDE/latte-dock.git
synced 2025-02-05 05:47:26 +03:00
provide single screens data table
This commit is contained in:
parent
41ebee5a71
commit
ad0f9901b7
@ -172,6 +172,12 @@ const T GenericTable<T>::operator[](const uint &index) const
|
|||||||
return m_list[index];
|
return m_list[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
bool GenericTable<T>::containsId(const int &id) const
|
||||||
|
{
|
||||||
|
return containsId(QString::number(id));
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
bool GenericTable<T>::containsId(const QString &id) const
|
bool GenericTable<T>::containsId(const QString &id) const
|
||||||
{
|
{
|
||||||
@ -202,6 +208,12 @@ bool GenericTable<T>::rowExists(const int &row) const
|
|||||||
return (m_list.count()>=0 && row>=0 && row<rowCount());
|
return (m_list.count()>=0 && row>=0 && row<rowCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
int GenericTable<T>::indexOf(const int &id) const
|
||||||
|
{
|
||||||
|
return indexOf(QString::number(id));
|
||||||
|
}
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
int GenericTable<T>::indexOf(const QString &id) const
|
int GenericTable<T>::indexOf(const QString &id) const
|
||||||
{
|
{
|
||||||
|
@ -55,10 +55,12 @@ public:
|
|||||||
T &operator[](const uint &index);
|
T &operator[](const uint &index);
|
||||||
const T operator[](const uint &index) const;
|
const T operator[](const uint &index) const;
|
||||||
|
|
||||||
|
bool containsId(const int &id) const;
|
||||||
bool containsId(const QString &id) const;
|
bool containsId(const QString &id) const;
|
||||||
bool containsName(const QString &name) const;
|
bool containsName(const QString &name) const;
|
||||||
bool rowExists(const int &row) const;
|
bool rowExists(const int &row) const;
|
||||||
|
|
||||||
|
int indexOf(const int &id) const;
|
||||||
int indexOf(const QString &id) const;
|
int indexOf(const QString &id) const;
|
||||||
int rowCount() const;
|
int rowCount() const;
|
||||||
int sortedPosForName(const QString &name) const;
|
int sortedPosForName(const QString &name) const;
|
||||||
|
@ -26,7 +26,9 @@ namespace Latte {
|
|||||||
namespace Data {
|
namespace Data {
|
||||||
|
|
||||||
Screen::Screen()
|
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::Screen(const QString &screenId, const QString &serialized)
|
||||||
|
: Screen()
|
||||||
{
|
{
|
||||||
init(screenId, serialized);
|
init(screenId, serialized);
|
||||||
}
|
}
|
||||||
@ -88,7 +91,10 @@ void Screen::init(const QString &screenId, const QString &serialized)
|
|||||||
|
|
||||||
id = screenId;
|
id = screenId;
|
||||||
name = parts[0];
|
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
|
QString Screen::serialize() const
|
||||||
|
@ -36,7 +36,7 @@ namespace Data {
|
|||||||
class Screen : public Generic
|
class Screen : public Generic
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static constexpr const char* SERIALIZESPLITTER = "##";
|
static constexpr const char* SERIALIZESPLITTER = ":::";
|
||||||
|
|
||||||
Screen();
|
Screen();
|
||||||
Screen(Screen &&o);
|
Screen(Screen &&o);
|
||||||
|
@ -378,7 +378,7 @@ bool Importer::importOldConfiguration(QString oldConfigPath, QString newName)
|
|||||||
QString connector = m_screensGroup.readEntry(key, QString());
|
QString connector = m_screensGroup.readEntry(key, QString());
|
||||||
int id = key.toInt();
|
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);
|
m_manager->corona()->screenPool()->insertScreenMapping(id, connector);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -56,8 +56,7 @@ ScreenPool::ScreenPool(KSharedConfig::Ptr config, QObject *parent)
|
|||||||
void ScreenPool::load()
|
void ScreenPool::load()
|
||||||
{
|
{
|
||||||
m_lastPrimaryConnector = QString();
|
m_lastPrimaryConnector = QString();
|
||||||
m_connectorForId.clear();
|
m_screensTable.clear();
|
||||||
m_idForConnector.clear();
|
|
||||||
|
|
||||||
QScreen *primary = qGuiApp->primaryScreen();
|
QScreen *primary = qGuiApp->primaryScreen();
|
||||||
|
|
||||||
@ -67,17 +66,15 @@ void ScreenPool::load()
|
|||||||
|
|
||||||
//restore the known ids to connector mappings
|
//restore the known ids to connector mappings
|
||||||
for (const QString &key : m_configGroup.keyList()) {
|
for (const QString &key : m_configGroup.keyList()) {
|
||||||
QString connector = m_configGroup.readEntry(key, QString());
|
QString serialized = m_configGroup.readEntry(key, QString());
|
||||||
qDebug() << "connector :" << connector << " - " << key;
|
//qDebug() << "connector :" << connector << " - " << key;
|
||||||
|
|
||||||
if (!key.isEmpty() && !connector.isEmpty() &&
|
Data::Screen screenRecord(key, serialized);
|
||||||
!m_connectorForId.contains(key.toInt()) &&
|
//qDebug() << "org.kde.latte ::: " << screenRecord.id << ":" << screenRecord.serialize();
|
||||||
!m_idForConnector.contains(connector)) {
|
|
||||||
m_connectorForId[key.toInt()] = connector;
|
if (!key.isEmpty() && !serialized.isEmpty() && !m_screensTable.containsId(key)) {
|
||||||
m_idForConnector[connector] = key.toInt();
|
m_screensTable << screenRecord;
|
||||||
qDebug() << "Known Screen - " << connector << " - " << key.toInt();
|
qDebug() << "Known Screen - " << screenRecord.id << " : " << screenRecord.name << " : " << screenRecord.geometry;
|
||||||
} else if (m_idForConnector.value(connector) != key.toInt()) {
|
|
||||||
m_configGroup.deleteEntry(key);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +84,7 @@ void ScreenPool::load()
|
|||||||
// at startup, if it' asked before corona::addOutput()
|
// at startup, if it' asked before corona::addOutput()
|
||||||
// is performed, driving to the creation of a new containment
|
// is performed, driving to the creation of a new containment
|
||||||
for (QScreen *screen : qGuiApp->screens()) {
|
for (QScreen *screen : qGuiApp->screens()) {
|
||||||
if (!m_idForConnector.contains(screen->name())) {
|
if (!m_screensTable.containsName(screen->name())) {
|
||||||
insertScreenMapping(firstAvailableId(), screen->name());
|
insertScreenMapping(firstAvailableId(), screen->name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +100,7 @@ QString ScreenPool::reportHtml(const QList<int> &assignedScreens) const
|
|||||||
{
|
{
|
||||||
QString report;
|
QString report;
|
||||||
|
|
||||||
report += "<table cellspacing='8'>";
|
/* report += "<table cellspacing='8'>";
|
||||||
report += "<tr><td align='center'><b>" + i18nc("screen id","ID") + "</b></td>" +
|
report += "<tr><td align='center'><b>" + i18nc("screen id","ID") + "</b></td>" +
|
||||||
"<td align='center'><b>" + i18nc("screen name", "Name") + "</b></td>" +
|
"<td align='center'><b>" + i18nc("screen name", "Name") + "</b></td>" +
|
||||||
"<td align='center'><b>" + i18nc("screen type", "Type") + "</b></td>" +
|
"<td align='center'><b>" + i18nc("screen type", "Type") + "</b></td>" +
|
||||||
@ -158,7 +155,7 @@ QString ScreenPool::reportHtml(const QList<int> &assignedScreens) const
|
|||||||
report += "</tr>";
|
report += "</tr>";
|
||||||
}
|
}
|
||||||
|
|
||||||
report += "</table>";
|
report += "</table>";*/
|
||||||
|
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
@ -184,15 +181,16 @@ void ScreenPool::save()
|
|||||||
{
|
{
|
||||||
QMap<int, QString>::const_iterator i;
|
QMap<int, QString>::const_iterator i;
|
||||||
|
|
||||||
for (i = m_connectorForId.constBegin(); i != m_connectorForId.constEnd(); ++i) {
|
for (int i=0; i<m_screensTable.rowCount(); ++i) {
|
||||||
m_configGroup.writeEntry(QString::number(i.key()), i.value());
|
Data::Screen screenRecord = m_screensTable[i];
|
||||||
|
m_configGroup.writeEntry(screenRecord.id, screenRecord.serialize());
|
||||||
}
|
}
|
||||||
|
|
||||||
//write to disck every 30 seconds at most
|
//write to disck every 30 seconds at most
|
||||||
m_configSaveTimer.start(30000);
|
m_configSaveTimer.start(30000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenPool::insertScreenMapping(int id, const QString &connector)
|
void ScreenPool::insertScreenMapping(int screenId, const QString &connector)
|
||||||
{
|
{
|
||||||
//Q_ASSERT(!m_connectorForId.contains(id) || m_connectorForId.value(id) == connector);
|
//Q_ASSERT(!m_connectorForId.contains(id) || m_connectorForId.value(id) == connector);
|
||||||
//Q_ASSERT(!m_idForConnector.contains(connector) || m_idForConnector.value(connector) == id);
|
//Q_ASSERT(!m_idForConnector.contains(connector) || m_idForConnector.value(connector) == id);
|
||||||
@ -201,16 +199,33 @@ void ScreenPool::insertScreenMapping(int id, const QString &connector)
|
|||||||
//there are case that the QScreen instead of the correct screen name
|
//there are case that the QScreen instead of the correct screen name
|
||||||
//returns "0:0", this check prevents from breaking the screens database
|
//returns "0:0", this check prevents from breaking the screens database
|
||||||
//from garbage ids
|
//from garbage ids
|
||||||
if (connector.startsWith(":"))
|
if (connector.startsWith(":")) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
qDebug() << "add connector..." << connector;
|
qDebug() << "add connector..." << connector;
|
||||||
|
|
||||||
if (id == 0) {
|
if (screenId == 0) {
|
||||||
m_lastPrimaryConnector = connector;
|
m_lastPrimaryConnector = connector;
|
||||||
} else {
|
} else {
|
||||||
m_connectorForId[id] = connector;
|
Data::Screen screenRecord;
|
||||||
m_idForConnector[connector] = id;
|
screenRecord.id = screenId;
|
||||||
|
screenRecord.name = connector;
|
||||||
|
|
||||||
|
//! update screen geometry
|
||||||
|
for (const auto scr : qGuiApp->screens()) {
|
||||||
|
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();
|
save();
|
||||||
@ -218,48 +233,35 @@ void ScreenPool::insertScreenMapping(int id, const QString &connector)
|
|||||||
|
|
||||||
int ScreenPool::id(const QString &connector) const
|
int ScreenPool::id(const QString &connector) const
|
||||||
{
|
{
|
||||||
if (!m_idForConnector.contains(connector)) {
|
QString screenId = m_screensTable.idForName(connector);
|
||||||
return -1;
|
return screenId.isEmpty() ? -1 : screenId.toInt();
|
||||||
}
|
|
||||||
|
|
||||||
return m_idForConnector.value(connector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScreenPool::connector(int id) const
|
QString ScreenPool::connector(int id) const
|
||||||
{
|
{
|
||||||
Q_ASSERT(m_connectorForId.contains(id));
|
int ind = m_screensTable.indexOf(id);
|
||||||
|
return (ind>=0 ? m_screensTable[ind].name : QString());
|
||||||
return m_connectorForId.value(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScreenPool::firstAvailableId() const
|
int ScreenPool::firstAvailableId() const
|
||||||
{
|
{
|
||||||
//start counting from 10, first numbers will
|
//start counting from 10, first numbers will be used for special cases e.g. primaryScreen, id=0
|
||||||
//be used for special cases.
|
int availableId = 10;
|
||||||
//e.g primaryScreen, id=0
|
|
||||||
int i = 10;
|
|
||||||
|
|
||||||
//find the first integer not stored in m_connectorForId
|
for (int row=0; row<m_screensTable.rowCount(); ++row) {
|
||||||
//m_connectorForId is the only map, so the ids are sorted
|
if (!m_screensTable.containsId(availableId)) {
|
||||||
for (const int &existingId : m_connectorForId.keys()) {
|
return availableId;
|
||||||
if (i != existingId) {
|
|
||||||
return i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
++i;
|
availableId++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return availableId;
|
||||||
}
|
|
||||||
|
|
||||||
QList <int> ScreenPool::knownIds() const
|
|
||||||
{
|
|
||||||
return m_connectorForId.keys();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScreenPool::hasScreenId(int screenId) const
|
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
|
bool ScreenPool::isScreenActive(int screenId) const
|
||||||
@ -282,7 +284,7 @@ QScreen *ScreenPool::screenForId(int id)
|
|||||||
const auto screens = qGuiApp->screens();
|
const auto screens = qGuiApp->screens();
|
||||||
QScreen *screen{qGuiApp->primaryScreen()};
|
QScreen *screen{qGuiApp->primaryScreen()};
|
||||||
|
|
||||||
if (id != -1 && knownIds().contains(id)) {
|
if (hasScreenId(id)) {
|
||||||
QString scrName = connector(id);
|
QString scrName = connector(id);
|
||||||
|
|
||||||
for (const auto scr : screens) {
|
for (const auto scr : screens) {
|
||||||
@ -295,7 +297,6 @@ QScreen *ScreenPool::screenForId(int id)
|
|||||||
return screen;
|
return screen;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ScreenPool::nativeEventFilter(const QByteArray &eventType, void *message, long int *result)
|
bool ScreenPool::nativeEventFilter(const QByteArray &eventType, void *message, long int *result)
|
||||||
{
|
{
|
||||||
Q_UNUSED(result);
|
Q_UNUSED(result);
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
bool isScreenActive(int screenId) const;
|
bool isScreenActive(int screenId) const;
|
||||||
int primaryScreenId() const;
|
int primaryScreenId() const;
|
||||||
|
|
||||||
void insertScreenMapping(int id, const QString &connector);
|
void insertScreenMapping(int screenId, const QString &connector);
|
||||||
void reload(QString path);
|
void reload(QString path);
|
||||||
|
|
||||||
int id(const QString &connector) const;
|
int id(const QString &connector) const;
|
||||||
@ -61,9 +61,6 @@ public:
|
|||||||
|
|
||||||
QString reportHtml(const QList<int> &assignedScreens) const;
|
QString reportHtml(const QList<int> &assignedScreens) const;
|
||||||
|
|
||||||
//all ids that are known, included screens not enabled at the moment
|
|
||||||
QList <int> knownIds() const;
|
|
||||||
|
|
||||||
QScreen *screenForId(int id);
|
QScreen *screenForId(int id);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@ -81,8 +78,8 @@ private:
|
|||||||
QString m_lastPrimaryConnector;
|
QString m_lastPrimaryConnector;
|
||||||
|
|
||||||
//order is important
|
//order is important
|
||||||
QMap<int, QString> m_connectorForId;
|
// QMap<int, QString> m_connectorForId;
|
||||||
QHash<QString, int> m_idForConnector;
|
// QHash<QString, int> m_idForConnector;
|
||||||
|
|
||||||
QTimer m_configSaveTimer;
|
QTimer m_configSaveTimer;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user