From 396fd27436692a30d0a33d892f12b4c5cc782752 Mon Sep 17 00:00:00 2001 From: zhaoyingzhen Date: Thu, 5 Feb 2026 15:02:02 +0800 Subject: [PATCH] feat: Add support for modifying the plugin popup cursor shape via the protocol. add support in plugin-manager-v1.xml Log: Add support for modifying the plugin popup cursor shape via the protocol. --- src/loader/widgetplugin.cpp | 18 +++++++++++++++++- src/protocol/plugin-manager-v1.xml | 7 +++++++ src/tray-wayland-integration/plugin.h | 1 + src/tray-wayland-integration/pluginsurface.cpp | 4 ++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/loader/widgetplugin.cpp b/src/loader/widgetplugin.cpp index c6b9cd9d4..56fbfa8b7 100644 --- a/src/loader/widgetplugin.cpp +++ b/src/loader/widgetplugin.cpp @@ -34,12 +34,16 @@ class Q_DECL_HIDDEN EventFilter : public QObject public: bool eventFilter(QObject *watched, QEvent *event) { - Q_UNUSED(watched) if (event->type() == QEvent::ToolTip) { const auto pos = static_cast(event)->globalPos(); QMetaObject::invokeMethod(this, [this, pos] () { updateToolTipPosition(pos); }, Qt::QueuedConnection); + } else if (event->type() == QEvent::CursorChange) { + auto widget = qobject_cast(watched); + if (widget) { + handleCursorChange(widget); + } } return false; } @@ -67,6 +71,18 @@ class Q_DECL_HIDDEN EventFilter : public QObject } } } + + void handleCursorChange(QWidget *widget) + { + if (!widget || !widget->window() || !widget->window()->windowHandle()) + return; + + auto windowHandle = widget->window()->windowHandle(); + if (auto pluginPopup = Plugin::PluginPopup::getWithoutCreating(windowHandle)) { + Qt::CursorShape cursorShape = widget->cursor().shape(); + Q_EMIT pluginPopup->requestSetCursor(static_cast(cursorShape)); + } + } }; } diff --git a/src/protocol/plugin-manager-v1.xml b/src/protocol/plugin-manager-v1.xml index b246e26ed..09ff51c12 100644 --- a/src/protocol/plugin-manager-v1.xml +++ b/src/protocol/plugin-manager-v1.xml @@ -139,6 +139,13 @@ + + + This requests the compositor to change the cursor shape. + The cursor_shape follows Qt::CursorShape enum values. + + + diff --git a/src/tray-wayland-integration/plugin.h b/src/tray-wayland-integration/plugin.h index ebe0a3bf0..52f0a789a 100644 --- a/src/tray-wayland-integration/plugin.h +++ b/src/tray-wayland-integration/plugin.h @@ -153,6 +153,7 @@ class PluginPopup : public QObject void xChanged(); void yChanged(); void pluginPosChanged(const QPoint &point); + void requestSetCursor(int cursorShape); private: explicit PluginPopup(QWindow* window); diff --git a/src/tray-wayland-integration/pluginsurface.cpp b/src/tray-wayland-integration/pluginsurface.cpp index e4aa26111..170b41f3d 100644 --- a/src/tray-wayland-integration/pluginsurface.cpp +++ b/src/tray-wayland-integration/pluginsurface.cpp @@ -119,6 +119,10 @@ PluginPopupSurface::PluginPopupSurface(PluginManagerIntegration *manager, QtWayl connect(m_dirtyTimer, &QTimer::timeout, this, [this]{ set_position(m_popup->x(), m_popup->y()); }); + + connect(m_popup, &PluginPopup::requestSetCursor, this, [this](int cursorShape) { + set_cursor(cursorShape); + }); } PluginPopupSurface::~PluginPopupSurface()