|
15 | 15 | #include <QtWaylandCompositor/QWaylandResource> |
16 | 16 | #include <QtWaylandCompositor/QWaylandCompositor> |
17 | 17 | #include <QtWaylandCompositor/QWaylandView> |
| 18 | +#include <QtWaylandCompositor/QWaylandBufferRef> |
18 | 19 |
|
19 | 20 | #include <QJsonObject> |
20 | 21 | #include <QJsonParseError> |
| 22 | +#include <QGuiApplication> |
| 23 | +#include <QCursor> |
| 24 | +#include <QPixmap> |
21 | 25 |
|
22 | 26 | #define protected public |
23 | 27 | #include <private/qwaylandcompositor_p.h> |
| 28 | +#include <private/qwaylandsurface_p.h> |
24 | 29 | #undef protected |
25 | 30 | #include <qpa/qwindowsysteminterface_p.h> |
26 | 31 |
|
@@ -709,13 +714,50 @@ void PluginManager::setupMouseFocusListener() |
709 | 714 |
|
710 | 715 | QObject::connect(seat, &QWaylandSeat::mouseFocusChanged, this, |
711 | 716 | [seat](QWaylandView *newFocus, QWaylandView *oldFocus) { |
712 | | - Q_UNUSED(oldFocus); |
713 | | - if(!newFocus) |
714 | | - return; |
| 717 | + // Restore default cursor when mouse leaves all plugin areas |
| 718 | + if (!newFocus && oldFocus) { |
| 719 | + qApp->restoreOverrideCursor(); |
| 720 | + } |
| 721 | + |
| 722 | + if (newFocus) { |
| 723 | + if (auto surface = newFocus->surface()) { |
| 724 | + seat->setKeyboardFocus(surface); |
| 725 | + } |
| 726 | + } |
| 727 | + }); |
715 | 728 |
|
716 | | - if (auto surface = newFocus->surface()) { |
717 | | - qDebug()<<"setKeyboardFocus"; |
718 | | - seat->setKeyboardFocus(surface); |
| 729 | + // Handle client cursor requests and apply cursor changes to the host window |
| 730 | + QObject::connect(seat, &QWaylandSeat::cursorSurfaceRequested, this, |
| 731 | + [this](QWaylandSurface *surface, int hotspotX, int hotspotY) { |
| 732 | + // Disconnect previous connection |
| 733 | + if (m_cursorSurfaceConn) { |
| 734 | + QObject::disconnect(m_cursorSurfaceConn); |
| 735 | + m_cursorSurfaceConn = {}; |
719 | 736 | } |
| 737 | + |
| 738 | + if (!surface) { |
| 739 | + qApp->restoreOverrideCursor(); |
| 740 | + return; |
| 741 | + } |
| 742 | + |
| 743 | + auto updateCursor = [surface, hotspotX, hotspotY]() { |
| 744 | + QWaylandSurfacePrivate *surf = QWaylandSurfacePrivate::get(surface); |
| 745 | + QWaylandBufferRef buf = surf->bufferRef; |
| 746 | + if (!buf.hasBuffer()) { |
| 747 | + return; |
| 748 | + } |
| 749 | + QImage image = buf.image(); |
| 750 | + if (!image.isNull() && image.width() > 0 && image.height() > 0) { |
| 751 | + QPixmap pixmap = QPixmap::fromImage(image); |
| 752 | + QCursor cursor(QPixmap::fromImage(image), hotspotX, hotspotY); |
| 753 | + if (qApp->overrideCursor()) { |
| 754 | + qApp->changeOverrideCursor(cursor); |
| 755 | + } else { |
| 756 | + qApp->setOverrideCursor(cursor); |
| 757 | + } |
| 758 | + } |
| 759 | + }; |
| 760 | + // Listen to surface redraw signal to grab cursor after buffer is updated |
| 761 | + m_cursorSurfaceConn = QObject::connect(surface, &QWaylandSurface::redraw, updateCursor); |
720 | 762 | }); |
721 | 763 | } |
0 commit comments