[kcms/virtualdesktops] Properly track synchronizing state

When the user applies a change like adding a desktop
DesktopsModel::syncWithServer is called and m_synchronizing is set to
true. The server then sends some kind of response (e.g. desktopCreated)
and updateModifiedState is called which sets m_synchronizing to false
again.

However if a setting is changed that does not trigger any server change
(e.g. the show OSD setting) m_synchonizing is never set to false again,
causing problems down the line.

Instead of relying on updateModifiedState to reset m_synchronizing track
the syncronizing state by refcounting the DBus calls

BUG: 437466
This commit is contained in:
Nicolas Fella 2021-05-22 12:48:32 +02:00
parent 99b84a321a
commit 7f36f01247
2 changed files with 9 additions and 11 deletions

View file

@ -37,7 +37,6 @@ DesktopsModel::DesktopsModel(QObject *parent)
, m_serverModified(false)
, m_serverSideRows(-1)
, m_rows(-1)
, m_synchronizing(false)
{
qDBusRegisterMetaType<KWin::DBusDesktopDataStruct>();
qDBusRegisterMetaType<KWin::DBusDesktopDataVector>();
@ -239,8 +238,6 @@ void DesktopsModel::setDesktopName(const QString &id, const QString &name)
void DesktopsModel::syncWithServer()
{
m_synchronizing = true;
auto callFinished = [this](QDBusPendingCallWatcher *call) {
QDBusPendingReply<void> reply = *call;
@ -248,6 +245,8 @@ void DesktopsModel::syncWithServer()
handleCallError();
}
--m_pendingCalls;
call->deleteLater();
};
@ -262,6 +261,7 @@ void DesktopsModel::syncWithServer()
call.setArguments({(uint)newIndex, m_names.value(m_desktops.at(newIndex))});
++m_pendingCalls;
QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call);
const auto *watcher = new QDBusPendingCallWatcher(pending, this);
@ -288,6 +288,7 @@ void DesktopsModel::syncWithServer()
call.setArguments({previous});
++m_pendingCalls;
QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call);
const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this);
@ -325,6 +326,7 @@ void DesktopsModel::syncWithServer()
call.setArguments({i.key(), i.value()});
++m_pendingCalls;
QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call);
const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this);
@ -349,6 +351,7 @@ void DesktopsModel::syncWithServer()
call.setArguments({s_virtualDesktopsInterface,
QStringLiteral("rows"), QVariant::fromValue(QDBusVariant(QVariant((uint)m_rows)))});
++m_pendingCalls;
QDBusPendingCall pending = QDBusConnection::sessionBus().asyncCall(call);
const QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pending, this);
@ -358,8 +361,6 @@ void DesktopsModel::syncWithServer()
void DesktopsModel::reset()
{
m_synchronizing = false; // Sanity.
auto getAllAndConnectCall = QDBusMessage::createMethodCall(
s_serviceName,
s_virtDesktopsPath,
@ -638,10 +639,8 @@ void DesktopsModel::updateModifiedState(bool server)
m_serverModified = false;
emit serverModifiedChanged();
m_synchronizing = false;
} else {
if (m_synchronizing) {
if (m_pendingCalls > 0) {
m_serverModified = false;
emit serverModifiedChanged();
@ -658,8 +657,7 @@ void DesktopsModel::updateModifiedState(bool server)
void DesktopsModel::handleCallError()
{
if (m_synchronizing) {
m_synchronizing = false;
if (m_pendingCalls > 0) {
m_serverModified = false;
emit serverModifiedChanged();

View file

@ -120,7 +120,7 @@ private:
QStringList m_desktops;
QHash<QString,QString> m_names;
int m_rows;
bool m_synchronizing;
int m_pendingCalls = 0;
};
}