Commit 6c19e733 authored by Nicolas Fella's avatar Nicolas Fella
Browse files

Fix Wayland window activation when attaching to an existing instance

The application launching Dolphin passes a token via the XDG_ACTIVATION_TOKEN environment variable

We need to pass that to the running instance so that it can use it to raise itself
parent 354aba3c
Pipeline #247835 passed with stage
in 20 minutes and 7 seconds
......@@ -31,9 +31,8 @@ void DBusInterface::ShowFolders(const QStringList& uriList, const QString& start
if (urls.isEmpty()) {
return;
}
KWindowSystem::setCurrentXdgActivationToken(startUpId);
const auto serviceName = isDaemon() ? QString() : QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
if(!Dolphin::attachToExistingInstance(urls, false, GeneralSettings::splitView(), serviceName)) {
if(!Dolphin::attachToExistingInstance(urls, false, GeneralSettings::splitView(), serviceName, startUpId)) {
Dolphin::openNewWindow(urls);
}
}
......@@ -44,9 +43,8 @@ void DBusInterface::ShowItems(const QStringList& uriList, const QString& startUp
if (urls.isEmpty()) {
return;
}
KWindowSystem::setCurrentXdgActivationToken(startUpId);
const auto serviceName = isDaemon() ? QString() : QStringLiteral("org.kde.dolphin-%1").arg(QCoreApplication::applicationPid());
if(!Dolphin::attachToExistingInstance(urls, true, GeneralSettings::splitView(), serviceName)) {
if(!Dolphin::attachToExistingInstance(urls, true, GeneralSettings::splitView(), serviceName, startUpId)) {
Dolphin::openNewWindow(urls, nullptr, Dolphin::OpenNewWindowFlag::Select);
};
}
......
......@@ -281,11 +281,17 @@ void DolphinMainWindow::openFiles(const QStringList& files, bool splitView)
openFiles(QUrl::fromStringList(files), splitView);
}
void DolphinMainWindow::activateWindow()
void DolphinMainWindow::activateWindow(const QString &activationToken)
{
window()->setAttribute(Qt::WA_NativeWindow, true);
KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
KWindowSystem::activateWindow(window()->effectiveWinId());
if (KWindowSystem::isPlatformWayland()) {
KWindowSystem::setCurrentXdgActivationToken(activationToken);
} else {
KStartupInfo::setNewStartupId(window()->windowHandle(), KStartupInfo::startupId());
}
KWindowSystem::activateWindow(window()->windowHandle());
}
bool DolphinMainWindow::isActiveWindow()
......
......@@ -139,7 +139,7 @@ public Q_SLOTS:
/**
* Tries to raise/activate the Dolphin window.
*/
void activateWindow();
void activateWindow(const QString &activationToken);
bool isActiveWindow();
......
......@@ -15,6 +15,7 @@
#include <KDialogJobUiDelegate>
#include <KIO/ApplicationLauncherJob>
#include <KService>
#include <KWindowSystem>
#include <QApplication>
......@@ -56,7 +57,7 @@ void Dolphin::openNewWindow(const QList<QUrl> &urls, QWidget *window, const Open
job->start();
}
bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService)
bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService, const QString &activationToken)
{
bool attached = false;
......@@ -121,7 +122,7 @@ bool Dolphin::attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFi
interface.first->openDirectories(interface.second, splitView);
reply.waitForFinished();
if (!reply.isError()) {
interface.first->activateWindow();
interface.first->activateWindow(activationToken);
attached = true;
}
}
......
......@@ -39,7 +39,7 @@ namespace Dolphin {
* @p preferredService needs to support the org.kde.dolphin.MainWindow dbus interface with the /dolphin/Dolphin_1 path.
* Returns true if the URLs were successfully attached.
*/
bool attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService = QString());
bool attachToExistingInstance(const QList<QUrl>& inputUrls, bool openFiles, bool splitView, const QString& preferredService, const QString &activationToken);
/**
* Returns a QVector with all GUI-capable Dolphin instances
......
......@@ -23,6 +23,7 @@
#include <KLocalizedString>
#include <KConfigGui>
#include <KIO/PreviewJob>
#include <KWindowSystem>
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#include <Kdelibs4ConfigMigrator>
......@@ -175,7 +176,14 @@ int main(int argc, char **argv)
}
if (!parser.isSet(QStringLiteral("new-window"))) {
if (Dolphin::attachToExistingInstance(urls, openFiles, splitView)) {
QString token;
if (KWindowSystem::isPlatformWayland()) {
token = qEnvironmentVariable("XDG_ACTIVATION_TOKEN");
qunsetenv("XDG_ACTIVATION_TOKEN");
}
if (Dolphin::attachToExistingInstance(urls, openFiles, splitView, QString(), token)) {
// Successfully attached to existing instance of Dolphin
return 0;
}
......
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