Commit 554a4f9c authored by Nate Graham's avatar Nate Graham
Browse files

Make virtual desktop scroll action respect wrap setting

The KWin setting for whether or not to wrap around was not respected, so
wrap was always true even if the user has turned it off. This commit
fixes that.

BUG: 425787
parent d375034d
......@@ -94,7 +94,11 @@ void SwitchDesktop::performNextAction()
int nextDesktopIndex = currentDesktopIndex + 1;
if (nextDesktopIndex == desktopIds.count()) {
nextDesktopIndex = 0;
if (m_virtualDesktopInfo->navigationWrappingAround()) {
nextDesktopIndex = 0;
} else {
return;
}
}
m_virtualDesktopInfo->requestActivate(desktopIds.at(nextDesktopIndex));
......@@ -112,7 +116,11 @@ void SwitchDesktop::performPreviousAction()
int previousDesktopIndex = currentDesktopIndex - 1;
if (previousDesktopIndex < 0) {
previousDesktopIndex = desktopIds.count() - 1;
if (m_virtualDesktopInfo->navigationWrappingAround()) {
previousDesktopIndex = desktopIds.count() - 1;
} else {
return;
}
}
m_virtualDesktopInfo->requestActivate(desktopIds.at(previousDesktopIndex));
......
......@@ -26,7 +26,11 @@ License along with this library. If not, see <http://www.gnu.org/licenses/>.
#include <KWayland/Client/registry.h>
#include <KWindowSystem>
#include <QDebug>
#include <QDBusConnection>
#include <QDBusMessage>
#include <QDBusPendingCallWatcher>
#include <QDBusPendingReply>
#include <config-X11.h>
......@@ -48,6 +52,10 @@ public:
}
uint refCount = 1;
// Fall back to true if we get an invalid DBus response when asking for the
// user's preference since that's what it was for years and years while
// 425787 was broken.
bool navigationWrappingAround = true;
virtual void init() = 0;
virtual QVariant currentDesktop() const = 0;
......@@ -66,10 +74,59 @@ Q_SIGNALS:
void desktopIdsChanged() const;
void desktopNamesChanged() const;
void desktopLayoutRowsChanged() const;
void navigationWrappingAroundChanged() const;
protected Q_SLOTS:
void navigationWrappingAroundChanged(bool newVal);
};
VirtualDesktopInfo::Private::Private()
{
// Connect to navigationWrappingAroundChanged signal
const bool connection = QDBusConnection::sessionBus().connect(
QStringLiteral("org.kde.KWin"),
QStringLiteral("/VirtualDesktopManager"),
QStringLiteral("org.kde.KWin.VirtualDesktopManager"),
QStringLiteral("navigationWrappingAroundChanged"),
this,
SLOT(navigationWrappingAroundChanged(bool)));
if (!connection) {
qWarning() << "Could not connect to org.kde.KWin.VirtualDesktopManager.navigationWrappingAroundChanged signal";
}
// ...Then get the property's current value
QDBusMessage msg = QDBusMessage::createMethodCall(
QStringLiteral("org.kde.KWin"),
QStringLiteral("/VirtualDesktopManager"),
QStringLiteral("org.freedesktop.DBus.Properties"),
QStringLiteral("Get")
);
msg.setArguments({
QStringLiteral("org.kde.KWin.VirtualDesktopManager"),
QStringLiteral("navigationWrappingAround")
});
auto *watcher = new QDBusPendingCallWatcher( QDBusConnection::sessionBus().asyncCall(msg), this);
QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
QDBusPendingReply<QVariant> reply = *watcher;
watcher->deleteLater();
if (reply.isError()) {
qWarning() << "Failed to determine whether virtual desktop navigation wrapping is enabled: " << reply.error().message();
return;
}
navigationWrappingAroundChanged(reply.value().toBool());
});
}
void VirtualDesktopInfo::Private::navigationWrappingAroundChanged(bool newVal)
{
if (navigationWrappingAround == newVal) {
return;
}
navigationWrappingAround = newVal;
emit navigationWrappingAroundChanged();
}
#if HAVE_X11
......@@ -473,6 +530,11 @@ void VirtualDesktopInfo::requestRemoveDesktop(quint32 position)
return d->requestRemoveDesktop(position);
}
bool VirtualDesktopInfo::navigationWrappingAround()
{
return d->navigationWrappingAround;
}
}
#include "virtualdesktopinfo.moc"
......@@ -46,6 +46,7 @@ class TASKMANAGER_EXPORT VirtualDesktopInfo : public QObject
Q_PROPERTY(QVariantList desktopIds READ desktopIds NOTIFY desktopIdsChanged)
Q_PROPERTY(QStringList desktopNames READ desktopNames NOTIFY desktopNamesChanged)
Q_PROPERTY(int desktopLayoutRows READ desktopLayoutRows NOTIFY desktopLayoutRowsChanged)
Q_PROPERTY(int navigationWrappingAround READ navigationWrappingAround NOTIFY navigationWrappingAroundChanged)
public:
explicit VirtualDesktopInfo(QObject *parent = nullptr);
......@@ -129,12 +130,20 @@ public:
**/
void requestRemoveDesktop(quint32 position);
/**
* Whether or not to wrap navigation such that activating the next virtual
* desktop when at the last one will go to the first one, and activating the
* previous virtual desktop when at the first one will go to the last one.
*/
bool navigationWrappingAround() const;
Q_SIGNALS:
void currentDesktopChanged() const;
void numberOfDesktopsChanged() const;
void desktopIdsChanged() const;
void desktopNamesChanged() const;
void desktopLayoutRowsChanged() const;
void navigationWrappingAroundChanged() const;
private:
class Private;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment