From 80d45c4c21456d91460da528463b0a106459d073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 24 Oct 2016 11:17:36 +0200 Subject: [PATCH] [server] Fix crash on updating focused keyboard surface Summary: In case the current selection does not have a DataSourceInterface updating the focused keyboard surface resulted in a crash. The current selection is sent to the DataDeviceInterface of the newly focused client and thus a DataOfferInterface would be created for a null DataSourceInterface. This is a similar fix as D3148 and D3149. Test Plan: Test case added which used to crash before Reviewers: #plasma_on_wayland Subscribers: plasma-devel Tags: #plasma_on_wayland Differential Revision: https://phabricator.kde.org/D3150 --- src/wayland/autotests/client/test_wayland_seat.cpp | 4 ++++ src/wayland/seat_interface.cpp | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index e1c30a1791..29d97e3e87 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -1680,6 +1680,10 @@ void TestWaylandSeat::testDataDeviceForKeyboardSurface() QVERIFY(dd->isValid()); QVERIFY(ddiCreatedSpy.wait()); + // unset surface and set again + m_seatInterface->setFocusedKeyboardSurface(nullptr); + m_seatInterface->setFocusedKeyboardSurface(serverSurface); + // and delete the connection thread again dd1.reset(); ddm1.reset(); diff --git a/src/wayland/seat_interface.cpp b/src/wayland/seat_interface.cpp index e18c0ecf7a..a94cedf9d5 100644 --- a/src/wayland/seat_interface.cpp +++ b/src/wayland/seat_interface.cpp @@ -929,7 +929,7 @@ void SeatInterface::setFocusedKeyboardSurface(SurfaceInterface *surface) // selection? d->keys.focus.selection = d->dataDeviceForSurface(surface); if (d->keys.focus.selection) { - if (d->currentSelection) { + if (d->currentSelection && d->currentSelection->selection()) { d->keys.focus.selection->sendSelection(d->currentSelection); } else { d->keys.focus.selection->sendClearSelection();