[plasma/plasma-workspace] appmenu: appmenu: Port away from KWayland

Nicolas Fella <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit a1fa3e19a5b802a414b6f62ac7d34822f1cb71f0 by Nicolas Fella.
Committed on 22/07/2026 at 14:31.
Pushed by nicolasfella into branch 'master'.

appmenu: Port away from KWayland

M  +7    -1    appmenu/CMakeLists.txt
M  +25   -44   appmenu/appmenu.cpp
M  +0    -8    appmenu/appmenu.h

https://invent.kde.org/plasma/plasma-workspace/-/commit/a1fa3e19a5b802a414b6f62ac7d34822f1cb71f0

diff --git a/appmenu/CMakeLists.txt b/appmenu/CMakeLists.txt
index ce212aa80b..f4c0afdc33 100644
--- a/appmenu/CMakeLists.txt
+++ b/appmenu/CMakeLists.txt
@@ -43,15 +43,21 @@ endif()
 
 pkg_check_modules(XKBCommon REQUIRED IMPORTED_TARGET xkbcommon)
 
+qt_generate_wayland_protocol_client_sources(appmenu
+    PRIVATE_CODE
+    FILES
+        "${PLASMA_WAYLAND_PROTOCOLS_DIR}/plasma-shell.xml"
+)
+
 target_link_libraries(appmenu
     Qt::DBus
     Qt::WaylandClientPrivate
     KF6::DBusAddons
     KF6::KIOCore
-    Plasma::KWaylandClient
     KF6::WindowSystem
     Wayland::Client
     PkgConfig::XKBCommon
+    Plasma::PlasmaQuick
     dbusmenuqt
 )
 if (HAVE_X11)
diff --git a/appmenu/appmenu.cpp b/appmenu/appmenu.cpp
index 722ed25776..8af13c6316 100644
--- a/appmenu/appmenu.cpp
+++ b/appmenu/appmenu.cpp
@@ -24,10 +24,8 @@
 #include <private/qwaylandinputdevice_p.h>
 #include <private/qwaylandwindow_p.h>
 
-#include <KWayland/Client/connection_thread.h>
-#include <KWayland/Client/plasmashell.h>
-#include <KWayland/Client/registry.h>
-#include <KWayland/Client/surface.h>
+#include <PlasmaQuick/PlasmaShellWaylandIntegration>
+
 #include <kpluginfactory.h>
 
 K_PLUGIN_FACTORY_WITH_JSON(AppMenuFactory, "appmenu.json", registerPlugin<AppMenuModule>();)
@@ -97,16 +95,6 @@ AppMenuModule::AppMenuModule(QObject *parent, const QList<QVariant> &)
         m_xcbConn = xcb_connect(nullptr, nullptr);
     }
 #endif
-    if (qGuiApp->platformName() == QLatin1String("wayland")) {
-        auto connection = KWayland::Client::ConnectionThread::fromApplication();
-        KWayland::Client::Registry registry;
-        registry.create(connection);
-        connect(&registry, &KWayland::Client::Registry::plasmaShellAnnounced, this, [this, &registry](quint32 name, quint32 version) {
-            m_plasmashell = registry.createPlasmaShell(name, version, this);
-        });
-        registry.setup();
-        connection->roundtrip();
-    }
 }
 
 AppMenuModule::~AppMenuModule()
@@ -201,38 +189,31 @@ void AppMenuModule::slotShowMenu(int x, int y, const QString &serviceName, const
             importer->deleteLater();
         });
 
-        if (m_plasmashell) {
-            QScreen *screen = QGuiApplication::screenAt(QPoint(x, y));
-            if (!screen) {
-                screen = QGuiApplication::primaryScreen();
-            }
+        QScreen *screen = QGuiApplication::screenAt(QPoint(x, y));
+        if (!screen) {
+            screen = QGuiApplication::primaryScreen();
+        }
 
-            const QRect screenRect = screen->geometry();
-            if (!m_menu->isVisible()) {
-                // We create a invisible toplevel so the menu can be an xdg_popup which is important
-                // to have the expected UX of an menu. By using the ToolTip role it cannot receive
-                // focus which is important because some apps misbehave when they dont have focus when
-                // a menu is triggered
-                auto toplevelWindow = new ToplevelWindow;
-                toplevelWindow->setFlag(Qt::FramelessWindowHint);
-                toplevelWindow->QObject::setParent(menu);
-                toplevelWindow->setGeometry(QRect(screenRect.topLeft(), QSize(1, 1)));
-                auto surface = KWayland::Client::Surface::fromWindow(toplevelWindow);
-                auto plasmaSurface = m_plasmashell->createSurface(surface, surface);
-                plasmaSurface->setSkipSwitcher(true);
-                plasmaSurface->setSkipTaskbar(true);
-                plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::ToolTip);
-                plasmaSurface->setPosition({x - 1, y - 1});
-                toplevelWindow->show();
-                connect(m_menu, &QMenu::aboutToShow, toplevelWindow, [toplevelWindow, this] {
-                    m_menu->windowHandle()->setTransientParent(toplevelWindow);
-                });
-                ensureSerial(toplevelWindow);
-            }
-            m_menu.data()->popup(screenRect.topLeft());
-        } else {
-            m_menu.data()->popup(QPoint(x, y) / qApp->devicePixelRatio());
+        const QRect screenRect = screen->geometry();
+        if (!m_menu->isVisible()) {
+            // We create a invisible toplevel so the menu can be an xdg_popup which is important
+            // to have the expected UX of an menu. By using the ToolTip role it cannot receive
+            // focus which is important because some apps misbehave when they dont have focus when
+            // a menu is triggered
+            auto toplevelWindow = new ToplevelWindow;
+            toplevelWindow->setFlag(Qt::FramelessWindowHint);
+            toplevelWindow->QObject::setParent(menu);
+            toplevelWindow->setGeometry(QRect(screenRect.topLeft(), QSize(1, 1)));
+            auto integration = PlasmaShellWaylandIntegration::get(toplevelWindow);
+            integration->setRole(QtWayland::org_kde_plasma_surface::role_tooltip);
+            integration->setPosition({x - 1, y - 1});
+            toplevelWindow->show();
+            connect(m_menu, &QMenu::aboutToShow, toplevelWindow, [toplevelWindow, this] {
+                m_menu->windowHandle()->setTransientParent(toplevelWindow);
+            });
+            ensureSerial(toplevelWindow);
         }
+        m_menu.data()->popup(screenRect.topLeft());
 
         QAction *actiontoActivate = importer->actionForId(actionId);
 
diff --git a/appmenu/appmenu.h b/appmenu/appmenu.h
index f4234dcac6..76447b2fc1 100644
--- a/appmenu/appmenu.h
+++ b/appmenu/appmenu.h
@@ -22,13 +22,6 @@ class QDBusServiceWatcher;
 class KDBusMenuImporter;
 class AppmenuDBus;
 class VerticalMenu;
-namespace KWayland
-{
-namespace Client
-{
-class PlasmaShell;
-};
-};
 
 class AppMenuModule : public KDEDModule, protected QDBusContext
 {
@@ -89,5 +82,4 @@ private:
 #ifdef HAVE_X11
     xcb_connection_t *m_xcbConn = nullptr;
 #endif
-    KWayland::Client::PlasmaShell *m_plasmashell = nullptr;
 };
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.