diff --git a/dbusinterface.cpp b/dbusinterface.cpp --- a/dbusinterface.cpp +++ b/dbusinterface.cpp @@ -445,6 +445,7 @@ } m_manager->setNavigationWrappingAround(wraps); + m_manager->save(); } bool VirtualDesktopManagerDBusInterface::isNavigationWrappingAround() const @@ -471,6 +472,7 @@ void VirtualDesktopManagerDBusInterface::createDesktop(uint position, const QString &name) { m_manager->createVirtualDesktop(position + 1, name); + m_manager->save(); } void VirtualDesktopManagerDBusInterface::setDesktopName(const QString &id, const QString &name) @@ -490,6 +492,7 @@ void VirtualDesktopManagerDBusInterface::removeDesktop(const QString &id) { m_manager->removeVirtualDesktop(id.toUtf8()); + m_manager->save(); } } // namespace diff --git a/virtualdesktops.h b/virtualdesktops.h --- a/virtualdesktops.h +++ b/virtualdesktops.h @@ -489,6 +489,8 @@ QVector m_desktops; QPointer m_current; + QList m_deskopsToRemoveFromConfig; + quint32 m_rows = 2; bool m_navigationWrapsAround; VirtualDesktopGrid m_grid; // TODO: QPointer @@ -709,12 +711,6 @@ return m_navigationWrapsAround; } -inline -void VirtualDesktopManager::setRootInfo(NETRootInfo *info) -{ - m_rootInfo = info; -} - inline void VirtualDesktopManager::setConfig(KSharedConfig::Ptr config) { diff --git a/virtualdesktops.cpp b/virtualdesktops.cpp --- a/virtualdesktops.cpp +++ b/virtualdesktops.cpp @@ -236,8 +236,31 @@ s_manager = NULL; } +void VirtualDesktopManager::setRootInfo(NETRootInfo *info) +{ + m_rootInfo = info; + + // Nothing will be connected to rootInfo + if (m_rootInfo) { + for (auto *vd : m_desktops) { + connect(vd, &VirtualDesktop::nameChanged, this, + [this, vd]() { + if (m_rootInfo) { + m_rootInfo->setDesktopName(vd->x11DesktopNumber(), vd->name().toUtf8().data()); + } + } + ); + m_rootInfo->setDesktopName(vd->x11DesktopNumber(), vd->name().toUtf8().data()); + } + } +} + QString VirtualDesktopManager::name(uint desktop) const { + if (m_desktops.length() > desktop - 1) { + return m_desktops[desktop - 1]->name(); + } + if (!m_rootInfo) { return defaultName(desktop); } @@ -461,6 +484,7 @@ } m_desktops.insert(actualNumber - 1, vd); + save(); updateRootInfo(); @@ -483,6 +507,7 @@ const uint oldCurrent = m_current->x11DesktopNumber(); const uint i = desktop->x11DesktopNumber() - 1; m_desktops.remove(i); + m_deskopsToRemoveFromConfig << desktop->x11DesktopNumber(); for (uint j = i; j < (uint)m_desktops.count(); ++j) { m_desktops[j]->setX11DesktopNumber(j + 1); @@ -558,6 +583,7 @@ } } for (auto desktop : desktopsToRemove) { + m_deskopsToRemoveFromConfig << desktop->x11DesktopNumber(); emit desktopRemoved(desktop); desktop->deleteLater(); } @@ -570,6 +596,7 @@ } m_desktops << vd; newDesktops << vd; + if (m_rootInfo) { connect(vd, &VirtualDesktop::nameChanged, this, [this, vd]() { @@ -585,7 +612,9 @@ updateRootInfo(); - save(); + if (!m_isLoading) { + save(); + } for (auto vd : newDesktops) { emit desktopCreated(vd); } @@ -604,12 +633,14 @@ return; } - int columns = count() / rows; - if (count() % rows > 0) { + m_rows = rows; + + int columns = count() / m_rows; + if (count() % m_rows > 0) { columns++; } if (m_rootInfo) { - m_rootInfo->setDesktopLayout(NET::OrientationHorizontal, columns, rows, NET::DesktopLayoutCornerTopLeft); + m_rootInfo->setDesktopLayout(NET::OrientationHorizontal, columns, m_rows, NET::DesktopLayoutCornerTopLeft); m_rootInfo->activate(); } @@ -636,21 +667,24 @@ void VirtualDesktopManager::updateLayout() { - int width = 0; - int height = 0; + m_rows = qMin(m_rows, count()); + int columns = count() / m_rows; Qt::Orientation orientation = Qt::Horizontal; + if (m_rootInfo) { // TODO: Is there a sane way to avoid overriding the existing grid? - width = m_rootInfo->desktopLayoutColumnsRows().width(); - height = m_rootInfo->desktopLayoutColumnsRows().height(); + columns = m_rootInfo->desktopLayoutColumnsRows().width(); + m_rows = m_rootInfo->desktopLayoutColumnsRows().height(); orientation = m_rootInfo->desktopLayoutOrientation() == NET::OrientationHorizontal ? Qt::Horizontal : Qt::Vertical; } - if (width == 0 && height == 0) { + + if (columns == 0) { // Not given, set default layout - height = count() == 1u ? 1 : 2; + m_rows = count() == 1u ? 1 : 2; + columns = count() / m_rows; } setNETDesktopLayout(orientation, - width, height, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now. + columns, m_rows, 0 //rootInfo->desktopLayoutCorner() // Not really worth implementing right now. ); } @@ -676,6 +710,7 @@ for (int i = 1; i <= n; i++) { QString s = group.readEntry(QStringLiteral("Name_%1").arg(i), i18n("Desktop %1", i)); + if (m_rootInfo) { m_rootInfo->setDesktopName(i, s.toUtf8().data()); } @@ -697,15 +732,16 @@ // m_desktopFocusChain.value()[i-1] = i; } + int rows = group.readEntry("Rows", 2); + m_rows = qBound(1, rows, n); + if (m_rootInfo) { - int rows = group.readEntry("Rows", 2); - rows = qBound(1, rows, n); // avoid weird cases like having 3 rows for 4 desktops, where the last row is unused - int columns = n / rows; - if (n % rows > 0) { + int columns = n / m_rows; + if (n % m_rows > 0) { columns++; } - m_rootInfo->setDesktopLayout(NET::OrientationHorizontal, columns, rows, NET::DesktopLayoutCornerTopLeft); + m_rootInfo->setDesktopLayout(NET::OrientationHorizontal, columns, m_rows, NET::DesktopLayoutCornerTopLeft); m_rootInfo->activate(); } @@ -729,6 +765,12 @@ } KConfigGroup group(m_config, groupname); + for (const int i : m_deskopsToRemoveFromConfig) { + group.deleteEntry(QStringLiteral("Id_%1").arg(i)); + group.deleteEntry(QStringLiteral("Name_%1").arg(i)); + } + m_deskopsToRemoveFromConfig.clear(); + group.writeEntry("Number", count()); for (uint i = 1; i <= count(); ++i) { QString s = name(i); @@ -751,6 +793,8 @@ group.writeEntry(QStringLiteral("Id_%1").arg(i), m_desktops[i-1]->id()); } + group.writeEntry("Rows", m_rows); + // Save to disk group.sync(); } @@ -780,6 +824,8 @@ } } + m_rows = height; + m_grid.update(QSize(width, height), orientation, m_desktops); // TODO: why is there no call to m_rootInfo->setDesktopLayout? emit layoutChanged(width, height);