diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2017-09-28 16:21:21 +0200 |
---|---|---|
committer | Johan Helsing <johan.helsing@qt.io> | 2017-10-18 11:39:25 +0000 |
commit | fa7a1f77226795ece274b3505655e522881a0e24 (patch) | |
tree | 3e3e730642b9f03dbdbbd385ae1a4900f5b7cb19 /src/compositor/compositor_api/qwaylandseat.cpp | |
parent | 3876d75305d3a1d2967c887b9591a327f726d91e (diff) |
Fix crash after destroying view with mouse focus
Don't emit QWaylandSeat::mouseFocusChanged with a destroyed QWaylandView.
QWaylandPointer has been refactored to make it easier to follow enter and
leave logic. A missing emit for buttonPressedChanged has been fixed as well.
This also adds a test for pointer events to verify that setting mouse focus
works and that the crash has been fixed.
Task-number: QTBUG-63208
Change-Id: Id0c174a7b609dfd0152f3ae446dd51fd8befd554
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
Diffstat (limited to 'src/compositor/compositor_api/qwaylandseat.cpp')
-rw-r--r-- | src/compositor/compositor_api/qwaylandseat.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/compositor/compositor_api/qwaylandseat.cpp b/src/compositor/compositor_api/qwaylandseat.cpp index 80b75d617..b4b45392c 100644 --- a/src/compositor/compositor_api/qwaylandseat.cpp +++ b/src/compositor/compositor_api/qwaylandseat.cpp @@ -456,6 +456,12 @@ void QWaylandSeat::setMouseFocus(QWaylandView *view) QWaylandView *oldFocus = d->mouseFocus; d->mouseFocus = view; + + if (oldFocus) + disconnect(oldFocus, &QObject::destroyed, this, &QWaylandSeat::handleMouseFocusDestroyed); + if (d->mouseFocus) + connect(d->mouseFocus, &QObject::destroyed, this, &QWaylandSeat::handleMouseFocusDestroyed); + emit mouseFocusChanged(d->mouseFocus, oldFocus); } @@ -512,4 +518,15 @@ QWaylandSeat *QWaylandSeat::fromSeatResource(struct ::wl_resource *resource) * This signal is emitted when the mouse focus has changed from \a oldFocus to \a newFocus. */ +void QWaylandSeat::handleMouseFocusDestroyed() +{ + // This is triggered when the QWaylandView is destroyed, NOT the surface. + // ... so this is for the rare case when the view that currently holds the mouse focus is + // destroyed before its surface + Q_D(QWaylandSeat); + d->mouseFocus = nullptr; + QWaylandView *oldFocus = nullptr; // we have to send nullptr because the old focus is already destroyed at this point + emit mouseFocusChanged(d->mouseFocus, oldFocus); +} + QT_END_NAMESPACE |