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
This commit is contained in:
parent
184120642a
commit
ad01ef1695
12 changed files with 92 additions and 28 deletions
|
@ -47,6 +47,7 @@ set(kdeconnectcore_SRCS
|
||||||
device.cpp
|
device.cpp
|
||||||
core_debug.cpp
|
core_debug.cpp
|
||||||
notificationserverinfo.cpp
|
notificationserverinfo.cpp
|
||||||
|
openconfig.cpp
|
||||||
${debug_file_SRCS}
|
${debug_file_SRCS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -66,7 +67,7 @@ PRIVATE
|
||||||
)
|
)
|
||||||
|
|
||||||
if(${KF5KIO_FOUND})
|
if(${KF5KIO_FOUND})
|
||||||
target_link_libraries(kdeconnectcore PUBLIC KF5::KIOCore)
|
target_link_libraries(kdeconnectcore PUBLIC KF5::KIOCore KF5::KIOGui)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (BLUETOOTH_ENABLED)
|
if (BLUETOOTH_ENABLED)
|
||||||
|
|
|
@ -332,23 +332,3 @@ QString Daemon::selfId() const
|
||||||
{
|
{
|
||||||
return KdeConnectConfig::instance().deviceId();
|
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 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_SIGNALS:
|
||||||
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
||||||
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
|
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
|
||||||
|
|
47
core/openconfig.cpp
Normal file
47
core/openconfig.cpp
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/**
|
||||||
|
* 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();
|
||||||
|
}
|
20
core/openconfig.h
Normal file
20
core/openconfig.h
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/**
|
||||||
|
* 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::DBusAddons
|
||||||
KF5::Notifications
|
KF5::Notifications
|
||||||
KF5::I18n
|
KF5::I18n
|
||||||
|
KF5::WindowSystem
|
||||||
Qt5::Widgets)
|
Qt5::Widgets)
|
||||||
|
|
||||||
ecm_mark_nongui_executable(kdeconnectd)
|
ecm_mark_nongui_executable(kdeconnectd)
|
||||||
|
|
|
@ -20,11 +20,13 @@
|
||||||
#include <KNotification>
|
#include <KNotification>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KIO/AccessManager>
|
#include <KIO/AccessManager>
|
||||||
|
#include <KWindowSystem>
|
||||||
|
|
||||||
#include <dbushelper.h>
|
#include <dbushelper.h>
|
||||||
|
|
||||||
#include "core/daemon.h"
|
#include "core/daemon.h"
|
||||||
#include "core/device.h"
|
#include "core/device.h"
|
||||||
|
#include "core/openconfig.h"
|
||||||
#include "core/backends/pairinghandler.h"
|
#include "core/backends/pairinghandler.h"
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
#include "kdeconnectd_debug.h"
|
#include "kdeconnectd_debug.h"
|
||||||
|
@ -54,8 +56,11 @@ public:
|
||||||
connect(notification, &KNotification::action1Activated, device, &Device::acceptPairing);
|
connect(notification, &KNotification::action1Activated, device, &Device::acceptPairing);
|
||||||
connect(notification, &KNotification::action2Activated, device, &Device::rejectPairing);
|
connect(notification, &KNotification::action2Activated, device, &Device::rejectPairing);
|
||||||
QString deviceId = device->id();
|
QString deviceId = device->id();
|
||||||
auto openSettings = [this, deviceId] {
|
auto openSettings = [deviceId, notification] {
|
||||||
openConfiguration(deviceId);
|
OpenConfig oc;
|
||||||
|
oc.setXdgActivationToken(notification->xdgActivationToken());
|
||||||
|
oc.openConfiguration(deviceId);
|
||||||
|
|
||||||
};
|
};
|
||||||
connect(notification, &KNotification::action3Activated, openSettings);
|
connect(notification, &KNotification::action3Activated, openSettings);
|
||||||
connect(notification, QOverload<>::of(&KNotification::activated), openSettings);
|
connect(notification, QOverload<>::of(&KNotification::activated), openSettings);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <remotesinksmodel.h>
|
#include <remotesinksmodel.h>
|
||||||
#include <pluginmodel.h>
|
#include <pluginmodel.h>
|
||||||
#include "core/kdeconnectpluginconfig.h"
|
#include "core/kdeconnectpluginconfig.h"
|
||||||
|
#include "openconfig.h"
|
||||||
#include "interfaces/commandsmodel.h"
|
#include "interfaces/commandsmodel.h"
|
||||||
#include "pointerlocker.h"
|
#include "pointerlocker.h"
|
||||||
#if WITH_WAYLAND == 1
|
#if WITH_WAYLAND == 1
|
||||||
|
@ -79,6 +80,12 @@ void KdeConnectDeclarativePlugin::registerTypes(const char* uri)
|
||||||
return ret;
|
return ret;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
qmlRegisterSingletonType<OpenConfig>(uri, 1, 0, "OpenConfig",
|
||||||
|
[](QQmlEngine*, QJSEngine*) -> QObject* {
|
||||||
|
return new OpenConfig;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
|
||||||
qmlRegisterAnonymousType<QAbstractItemModel>(uri, 1);
|
qmlRegisterAnonymousType<QAbstractItemModel>(uri, 1);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -40,7 +40,7 @@ Item
|
||||||
Plasmoid.preferredRepresentation: isConstrained ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
|
Plasmoid.preferredRepresentation: isConstrained ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
|
||||||
|
|
||||||
function action_launchkcm() {
|
function action_launchkcm() {
|
||||||
DaemonDbusInterface.openConfiguration()
|
OpenConfig.openConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include <core/networkpacket.h>
|
#include <core/networkpacket.h>
|
||||||
#include <core/device.h>
|
#include <core/device.h>
|
||||||
#include <core/daemon.h>
|
#include <core/daemon.h>
|
||||||
|
#include <core/openconfig.h>
|
||||||
|
|
||||||
#include "plugin_runcommand_debug.h"
|
#include "plugin_runcommand_debug.h"
|
||||||
|
|
||||||
|
@ -68,7 +69,8 @@ bool RunCommandPlugin::receivePacket(const NetworkPacket& np)
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
} else if (np.has(QStringLiteral("setup"))) {
|
} 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;
|
return false;
|
||||||
|
|
|
@ -7,7 +7,7 @@ add_executable(kdeconnect-settings
|
||||||
${kdeconnect_custom_icons_SRCS}
|
${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(TARGETS kdeconnect-settings ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
|
||||||
install(FILES org.kde.kdeconnect-settings.desktop DESTINATION ${KDE_INSTALL_APPDIR})
|
install(FILES org.kde.kdeconnect-settings.desktop DESTINATION ${KDE_INSTALL_APPDIR})
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#include <KLocalizedString>
|
#include <KLocalizedString>
|
||||||
#include <KDBusService>
|
#include <KDBusService>
|
||||||
|
#include <KWindowSystem>
|
||||||
#include "kdeconnect-version.h"
|
#include "kdeconnect-version.h"
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
|
@ -47,6 +48,8 @@ int main(int argc, char** argv)
|
||||||
dialog->show();
|
dialog->show();
|
||||||
|
|
||||||
QObject::connect(&dbusService, &KDBusService::activateRequested, dialog, [dialog](const QStringList &args, const QString &/*workingDir*/) {
|
QObject::connect(&dbusService, &KDBusService::activateRequested, dialog, [dialog](const QStringList &args, const QString &/*workingDir*/) {
|
||||||
|
KWindowSystem::updateStartupId(dialog->windowHandle());
|
||||||
|
KWindowSystem::activateWindow(dialog->windowHandle());
|
||||||
|
|
||||||
QCommandLineParser parser;
|
QCommandLineParser parser;
|
||||||
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the config module"), QStringLiteral("args")));
|
parser.addOption(QCommandLineOption(QStringLiteral("args"), i18n("Arguments for the config module"), QStringLiteral("args")));
|
||||||
|
|
Loading…
Reference in a new issue