]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix Wayland window activation when attaching to an existing instance
authorNicolas Fella <nicolas.fella@gmx.de>
Tue, 11 Oct 2022 19:21:09 +0000 (21:21 +0200)
committerNicolas Fella <nicolas.fella@gmx.de>
Fri, 14 Oct 2022 14:46:29 +0000 (14:46 +0000)
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

src/dbusinterface.cpp
src/dolphinmainwindow.cpp
src/dolphinmainwindow.h
src/global.cpp
src/global.h
src/main.cpp

index 0d43dfc2316f64dfd2ed62841d43e4c340a9db33..8d5bf7645b9feeeba326f8f00908c2b520445339 100644 (file)
@@ -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);
     };
 }
index 305c7f2821b8366182aca1665adcd9ef1532c2cf..384e91ec913f15611b3ec087d6740e07dde1bda1 100644 (file)
@@ -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()
index 6f922168c06826a9d91d7cfe3b66c106aed5f54f..bf74b77b72a9fbaf730b55742e5baac9b51b0b01 100644 (file)
@@ -139,7 +139,7 @@ public Q_SLOTS:
     /**
      * Tries to raise/activate the Dolphin window.
      */
-    void activateWindow();
+    void activateWindow(const QString &activationToken);
 
     bool isActiveWindow();
 
index c9ec6a1200036caaa1b7e6fb15bb6f516bc7e709..d5fbec6bc47666dda08edfad8f75867c7dbcfd12 100644 (file)
@@ -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;
         }
     }
index ee9a7ec2716a6bf834f099200bffbe82fa9d522f..80ec03fd02752d5ffcf0920be790803d935458cb 100644 (file)
@@ -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
index 017a31f1d0dbdaba27d2245027671ad21517997d..9da0c6fe81d5381dc70a67e19a0bc688399802af 100644 (file)
@@ -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;
         }