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

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

klipper: Port away from KWayland

M  +7    -1    klipper/CMakeLists.txt
M  +8    -33   klipper/klipper.cpp
M  +0    -6    klipper/klipper.h
M  +7    -20   klipper/klipperpopup.cpp
M  +0    -8    klipper/klipperpopup.h

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

diff --git a/klipper/CMakeLists.txt b/klipper/CMakeLists.txt
index e6c4952a70..29d30e14b8 100644
--- a/klipper/CMakeLists.txt
+++ b/klipper/CMakeLists.txt
@@ -26,6 +26,13 @@ kconfig_add_kcfg_files(libklipper_common_SRCS klippersettings.kcfgc)
 
 add_library(klipper SHARED ${libklipper_common_SRCS})
 generate_export_header(klipper)
+
+qt_generate_wayland_protocol_client_sources(klipper
+    PRIVATE_CODE
+    FILES
+        "${PLASMA_WAYLAND_PROTOCOLS_DIR}/plasma-shell.xml"
+)
+
 target_link_libraries(klipper
     Qt::Concurrent
     Qt::DBus
@@ -45,7 +52,6 @@ target_link_libraries(klipper
     KF6::WidgetsAddons
     KF6::WindowSystem
     KF6::XmlGui
-    Plasma::KWaylandClient
     Plasma::PlasmaQuick
     Wayland::Client
     LayerShellQt::Interface
diff --git a/klipper/klipper.cpp b/klipper/klipper.cpp
index b97b12a2e8..0da2c8cae3 100644
--- a/klipper/klipper.cpp
+++ b/klipper/klipper.cpp
@@ -20,12 +20,10 @@
 #include <KLocalizedString>
 #include <KNotification>
 #include <KToggleAction>
-#include <KWayland/Client/connection_thread.h>
-#include <KWayland/Client/plasmashell.h>
-#include <KWayland/Client/registry.h>
-#include <KWayland/Client/surface.h>
 #include <KWindowSystem>
 
+#include <PlasmaQuick/PlasmaShellWaylandIntegration>
+
 #include "configdialog.h"
 #include "historycycler.h"
 #include "historyitem.h"
@@ -57,7 +55,6 @@ Klipper::Klipper(QObject *parent)
     : QObject(parent)
     , m_clip(SystemClipboard::self())
     , m_historyCycler(new HistoryCycler(this))
-    , m_plasmashell(nullptr)
 {
     QDBusConnection::sessionBus().registerService(QStringLiteral("org.kde.klipper"));
     QDBusConnection::sessionBus().registerObject(QStringLiteral("/klipper"),
@@ -145,22 +142,6 @@ Klipper::Klipper(QObject *parent)
             m_notification->setHint(QStringLiteral("desktop-entry"), QStringLiteral("org.kde.klipper"));
         }
     });
-
-    if (KWindowSystem::isPlatformWayland()) {
-        auto registry = new KWayland::Client::Registry(this);
-        auto connection = KWayland::Client::ConnectionThread::fromApplication(qGuiApp);
-        connect(registry, &KWayland::Client::Registry::plasmaShellAnnounced, this, [registry, this](quint32 name, quint32 version) {
-            if (!m_plasmashell) {
-                m_plasmashell = registry->createPlasmaShell(name, version);
-                m_popup->setPlasmaShell(m_plasmashell);
-            }
-        });
-        connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, registry, [registry] {
-            delete registry; // Avoid freeing resource when gui is deleted
-        });
-        registry->create(connection);
-        registry->setup();
-    }
 }
 
 Klipper::~Klipper()
@@ -253,14 +234,10 @@ void Klipper::saveSettings() const
 void Klipper::showPopupMenu(QMenu *menu)
 {
     Q_ASSERT(menu != nullptr);
-    if (m_plasmashell) {
-        menu->hide();
-    }
+    menu->hide();
     menu->popup(QCursor::pos());
     QWindow *menuWindow = menu->windowHandle();
-    if (m_plasmashell) {
-        menuWindow->installEventFilter(this);
-    }
+    menuWindow->installEventFilter(this);
     if (!menu->windowFlags().testFlag(Qt::Popup)) {
         connect(menuWindow, &QWindow::activeChanged, menu, [menu] {
             if (!menu->windowHandle()->isActive()) {
@@ -275,12 +252,10 @@ bool Klipper::eventFilter(QObject *filtered, QEvent *event)
     const bool ret = QObject::eventFilter(filtered, event);
     auto menuWindow = qobject_cast<QWindow *>(filtered);
     if (menuWindow && event->type() == QEvent::Expose && menuWindow->isVisible()) {
-        auto surface = KWayland::Client::Surface::fromWindow(menuWindow);
-        auto plasmaSurface = m_plasmashell->createSurface(surface, menuWindow);
-        plasmaSurface->openUnderCursor();
-        plasmaSurface->setSkipTaskbar(true);
-        plasmaSurface->setSkipSwitcher(true);
-        plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::AppletPopup);
+        auto integration = PlasmaShellWaylandIntegration::get(menuWindow);
+        integration->openUnderCursor();
+        integration->setRole(QtWayland::org_kde_plasma_surface::role_appletpopup);
+
         menuWindow->removeEventFilter(this);
     }
     return ret;
diff --git a/klipper/klipper.h b/klipper/klipper.h
index 659e6cd45b..d47abe0f0a 100644
--- a/klipper/klipper.h
+++ b/klipper/klipper.h
@@ -31,11 +31,6 @@ class HistoryModel;
 class KNotification;
 class SystemClipboard;
 
-namespace KWayland::Client
-{
-class PlasmaShell;
-}
-
 class KLIPPER_EXPORT Klipper : public QObject, public QDBusContext
 {
     Q_OBJECT
@@ -133,5 +128,4 @@ private:
     QString cycleText() const;
     KActionCollection *m_collection;
     QPointer<KNotification> m_notification;
-    KWayland::Client::PlasmaShell *m_plasmashell;
 };
diff --git a/klipper/klipperpopup.cpp b/klipper/klipperpopup.cpp
index 38a25de10c..ac791cdc4f 100644
--- a/klipper/klipperpopup.cpp
+++ b/klipper/klipperpopup.cpp
@@ -15,13 +15,12 @@
 #include <QQuickItem>
 
 #include <KLocalizedString>
-#include <KWayland/Client/plasmashell.h>
-#include <KWayland/Client/surface.h>
 #include <KWindowSystem>
 #include <KX11Extras>
 
 #include <Plasma/Plasma>
 #include <PlasmaQuick/PlasmaQuick>
+#include <PlasmaQuick/PlasmaShellWaylandIntegration>
 
 #include <algorithm>
 
@@ -57,20 +56,13 @@ KlipperPopup::~KlipperPopup()
 
 void KlipperPopup::show()
 {
-    if (m_plasmashell) {
-        hide();
-    }
+    hide();
     positionOnScreen();
     QMetaObject::invokeMethod(mainItem(), "updateContentSize", Q_ARG(QSizeF, screen()->availableSize().toSizeF()));
     resizePopup();
     setVisible(true);
 }
 
-void KlipperPopup::setPlasmaShell(KWayland::Client::PlasmaShell *plasmashell)
-{
-    m_plasmashell = plasmashell;
-}
-
 void KlipperPopup::editCurrentClipboard()
 {
     if (!isVisible()) {
@@ -90,9 +82,7 @@ void KlipperPopup::showCurrentBarcode()
 void KlipperPopup::hide()
 {
     QWindow::hide();
-    if (m_plasmashell) {
-        destroy(); // Required to recreate wl_surface
-    }
+    destroy(); // Required to recreate wl_surface
 }
 
 void KlipperPopup::resizePopup()
@@ -136,13 +126,10 @@ void KlipperPopup::positionOnScreen()
         setPosition(QCursor::pos(shownOnScreen));
         setScreen(shownOnScreen);
         KX11Extras::setOnDesktop(winId(), KX11Extras::currentDesktop());
-    } else if (m_plasmashell && KWindowSystem::isPlatformWayland()) {
-        auto surface = KWayland::Client::Surface::fromWindow(this);
-        auto plasmaSurface = m_plasmashell->createSurface(surface, this);
-        plasmaSurface->openUnderCursor();
-        plasmaSurface->setSkipTaskbar(true);
-        plasmaSurface->setSkipSwitcher(true);
-        plasmaSurface->setRole(KWayland::Client::PlasmaShellSurface::Role::AppletPopup);
+    } else if (KWindowSystem::isPlatformWayland()) {
+        auto integration = PlasmaShellWaylandIntegration::get(this);
+        integration->openUnderCursor();
+        integration->setRole(QtWayland::org_kde_plasma_surface::role_appletpopup);
 
         if (screens.size() > 1) {
             auto message = QDBusMessage::createMethodCall(u"org.kde.KWin"_s, u"/KWin"_s, u"org.kde.KWin"_s, u"activeOutputName"_s);
diff --git a/klipper/klipperpopup.h b/klipper/klipperpopup.h
index 7c9249bdd2..f668ccc1eb 100644
--- a/klipper/klipperpopup.h
+++ b/klipper/klipperpopup.h
@@ -12,11 +12,6 @@ class QWindow;
 
 class HistoryModel;
 
-namespace KWayland::Client
-{
-class PlasmaShell;
-}
-
 class KlipperPopup : public PlasmaQuick::PlasmaWindow
 {
     Q_OBJECT
@@ -27,8 +22,6 @@ public:
 
     void show();
 
-    void setPlasmaShell(KWayland::Client::PlasmaShell *plasmashell);
-
     void editCurrentClipboard();
     void showCurrentBarcode();
 
@@ -49,5 +42,4 @@ private:
     std::shared_ptr<HistoryModel> m_model;
 
     std::shared_ptr<QQmlEngine> m_engine;
-    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.