Commit ad01ef16 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Fix activating existing settings window on Wayland

Add the necessary bits for XDG activation to work

Move the code for launching the settings from the daemon to the respective processes so that we don't need to pass activation tokens over another process boundary
parent 18412064
Pipeline #200491 passed with stage
in 12 minutes and 42 seconds
......@@ -47,6 +47,7 @@ set(kdeconnectcore_SRCS
device.cpp
core_debug.cpp
notificationserverinfo.cpp
openconfig.cpp
${debug_file_SRCS}
)
......@@ -66,7 +67,7 @@ PRIVATE
)
if(${KF5KIO_FOUND})
target_link_libraries(kdeconnectcore PUBLIC KF5::KIOCore)
target_link_libraries(kdeconnectcore PUBLIC KF5::KIOCore KF5::KIOGui)
endif()
if (BLUETOOTH_ENABLED)
......
......@@ -332,23 +332,3 @@ QString Daemon::selfId() const
{
return KdeConnectConfig::instance().deviceId();
}
void Daemon::openConfiguration(const QString &deviceId, const QString &pluginId)
{
QStringList args;
QString argument;
if (!deviceId.isEmpty()) {
args << QStringLiteral("--args");
argument = deviceId;
if (!pluginId.isEmpty()) {
argument += QLatin1Char(':') + pluginId;
}
args << argument;
}
QProcess::startDetached(QStringLiteral("kdeconnect-settings"), args);
}
......@@ -74,8 +74,6 @@ public Q_SLOTS:
Q_SCRIPTABLE virtual void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) = 0;
Q_SCRIPTABLE void openConfiguration(const QString &deviceId = QString(), const QString &pluginId = QString());
Q_SIGNALS:
Q_SCRIPTABLE void deviceAdded(const QString& id);
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
......
/**
* SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "openconfig.h"
#include <QDebug>
#if HAVE_KIO
#include <KIO/CommandLauncherJob>
#endif
void OpenConfig::setXdgActivationToken(const QString &token)
{
m_currentToken = token;
}
void OpenConfig::openConfiguration(const QString &deviceId, const QString &pluginId)
{
QStringList args;
QString argument;
if (!deviceId.isEmpty()) {
args << QStringLiteral("--args");
argument = deviceId;
if (!pluginId.isEmpty()) {
argument += QLatin1Char(':') + pluginId;
}
args << argument;
}
#if HAVE_KIO
auto job = new KIO::CommandLauncherJob(QStringLiteral("kdeconnect-settings"), args);
job->setDesktopName(QStringLiteral("org.kde.kdeconnect-settings"));
job->setStartupId(m_currentToken.toUtf8());
job->start();
#else
QProcess::startDetached(QStringLiteral("kdeconnect-settings"), args);
#endif
m_currentToken = QString();
}
/**
* SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include <QObject>
#include "kdeconnectcore_export.h"
class KDECONNECTCORE_EXPORT OpenConfig : public QObject
{
Q_OBJECT
public:
void setXdgActivationToken(const QString &token);
Q_INVOKABLE void openConfiguration(const QString &deviceId = QString(), const QString &pluginName = QString());
private:
QString m_currentToken;
};
......@@ -16,6 +16,7 @@ target_link_libraries(kdeconnectd
KF5::DBusAddons
KF5::Notifications
KF5::I18n
KF5::WindowSystem
Qt5::Widgets)
ecm_mark_nongui_executable(kdeconnectd)
......
......@@ -20,11 +20,13 @@
#include <KNotification>
#include <KLocalizedString>
#include <KIO/AccessManager>
#include <KWindowSystem>
#include <dbushelper.h>
#include "core/daemon.h"
#include "core/device.h"
#include "core/openconfig.h"
#include "core/backends/pairinghandler.h"
#include "kdeconnect-version.h"
#include "kdeconnectd_debug.h"
......@@ -54,8 +56,11 @@ public:
connect(notification, &KNotification::action1Activated, device, &Device::acceptPairing);
connect(notification, &KNotification::action2Activated, device, &Device::rejectPairing);
QString deviceId = device->id();
auto openSettings = [this, deviceId] {
openConfiguration(deviceId);
auto openSettings = [deviceId, notification] {
OpenConfig oc;
oc.setXdgActivationToken(notification->xdgActivationToken());
oc.openConfiguration(deviceId);
};
connect(notification, &KNotification::action3Activated, openSettings);
connect(notification, QOverload<>::of(&KNotification::activated), openSettings);
......
......@@ -22,6 +22,7 @@
#include <remotesinksmodel.h>
#include <pluginmodel.h>
#include "core/kdeconnectpluginconfig.h"
#include "openconfig.h"
#include "interfaces/commandsmodel.h"
#include "pointerlocker.h"
#if WITH_WAYLAND == 1
......@@ -79,6 +80,12 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
return ret;
});
qmlRegisterSingletonType<OpenConfig>(uri, 1, 0, "OpenConfig",
[](QQmlEngine*, QJSEngine*) -> QObject* {
return new OpenConfig;
}
);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
qmlRegisterAnonymousType<QAbstractItemModel>(uri, 1);
#else
......
......@@ -40,7 +40,7 @@ Item
Plasmoid.preferredRepresentation: isConstrained ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
function action_launchkcm() {
DaemonDbusInterface.openConfiguration()
OpenConfig.openConfiguration()
}
Component.onCompleted: {
......
......@@ -24,6 +24,7 @@
#include <core/networkpacket.h>
#include <core/device.h>
#include <core/daemon.h>
#include <core/openconfig.h>
#include "plugin_runcommand_debug.h"
......@@ -68,7 +69,8 @@ bool RunCommandPlugin::receivePacket(const NetworkPacket& np)
#endif
return true;
} else if (np.has(QStringLiteral("setup"))) {
Daemon::instance()->openConfiguration(device()->id(), QStringLiteral("kdeconnect_runcommand"));
OpenConfig oc;
oc.openConfiguration(device()->id(), QStringLiteral("kdeconnect_runcommand"));
}
return false;
......
......@@ -7,7 +7,7 @@ add_executable(kdeconnect-settings
${kdeconnect_custom_icons_SRCS}
)
target_link_libraries(kdeconnect-settings kdeconnectversion KF5::I18n KF5::KCMUtils KF5::DBusAddons)
target_link_libraries(kdeconnect-settings kdeconnectversion KF5::I18n KF5::KCMUtils KF5::DBusAddons KF5::WindowSystem)
install(TARGETS kdeconnect-settings ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES org.kde.kdeconnect-settings.desktop DESTINATION ${KDE_INSTALL_APPDIR})
......@@ -13,6 +13,7 @@
#include <KAboutData>
#include <KLocalizedString>
#include <KDBusService>
#include <KWindowSystem>
#include "kdeconnect-version.h"
int main(int argc, char** argv)
......@@ -47,6 +48,8 @@ int main(int argc, char** argv)
dialog->show();
QObject::connect(&dbusService, &KDBusService::activateRequested, dialog, [dialog](const QStringList &args, const QString &/*workingDir*/) {
KWindowSystem::updateStartupId(dialog->windowHandle());
KWindowSystem::activateWindow(dialog->windowHandle());
QCommandLineParser parser;
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the config module"), QStringLiteral("args")));
......
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