From 9266a944007e1bc91282961f271a5f9d18043d1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Fl=C3=B6ser?= Date: Thu, 13 Jul 2017 17:45:24 +0200 Subject: [PATCH] [server] Send keyboard leave when client destroys the focused surface Summary: This is a change inspired by https://bugreports.qt.io/browse/QTBUG-61930. When Qt closes a window due to a key press event it starts to repeat the event as KWayland does not send a keyboard leave event. Weston on the other hand does send out the keyboard leave. In my opinion it doesn't make much sense to send out the keyboard leave in this situation and in my opinion that is a client bug, but if it makes clients happy we can send them the keyboard leave. Similar this should be done for pointer, touch, etc. BUG: 382280 Test Plan: Run the example added to the Qt bug and it worked fine Reviewers: #frameworks, #plasma Subscribers: plasma-devel Tags: #plasma_on_wayland, #frameworks Differential Revision: https://phabricator.kde.org/D6683 --- src/wayland/autotests/client/test_wayland_seat.cpp | 3 ++- src/wayland/keyboard_interface.cpp | 5 ++++- src/wayland/server/resource.cpp | 1 + src/wayland/server/resource.h | 10 ++++++++++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/wayland/autotests/client/test_wayland_seat.cpp b/src/wayland/autotests/client/test_wayland_seat.cpp index 26e21527f0..4ea8a2bb40 100644 --- a/src/wayland/autotests/client/test_wayland_seat.cpp +++ b/src/wayland/autotests/client/test_wayland_seat.cpp @@ -1563,7 +1563,8 @@ void TestWaylandSeat::testKeyboard() QSignalSpy serverSurfaceDestroyedSpy(serverSurface, &QObject::destroyed); QVERIFY(serverSurfaceDestroyedSpy.isValid()); delete s; - QVERIFY(serverSurfaceDestroyedSpy.wait()); + QVERIFY(leftSpy.wait()); + QCOMPARE(serverSurfaceDestroyedSpy.count(), 1); QVERIFY(!m_seatInterface->focusedKeyboardSurface()); QVERIFY(!m_seatInterface->focusedKeyboard()); QVERIFY(!serverKeyboard->focusedSurface()); diff --git a/src/wayland/keyboard_interface.cpp b/src/wayland/keyboard_interface.cpp index a5ffd8ab70..671fc1d9de 100644 --- a/src/wayland/keyboard_interface.cpp +++ b/src/wayland/keyboard_interface.cpp @@ -121,9 +121,12 @@ void KeyboardInterface::setFocusedSurface(SurfaceInterface *surface, quint32 ser if (!d->focusedSurface) { return; } - d->destroyConnection = connect(d->focusedSurface, &QObject::destroyed, this, + d->destroyConnection = connect(d->focusedSurface, &Resource::aboutToBeUnbound, this, [this] { Q_D(); + if (d->resource) { + wl_keyboard_send_leave(d->resource, d->global->display()->nextSerial(), d->focusedSurface->resource()); + } d->focusedSurface = nullptr; d->focusedChildSurface.clear(); } diff --git a/src/wayland/server/resource.cpp b/src/wayland/server/resource.cpp index eb735e9dd5..f728ff3905 100644 --- a/src/wayland/server/resource.cpp +++ b/src/wayland/server/resource.cpp @@ -63,6 +63,7 @@ void Resource::Private::create(ClientConnection *c, quint32 version, quint32 id) void Resource::Private::unbind(wl_resource *r) { Private *p = cast(r); + emit p->q->aboutToBeUnbound(); p->resource = nullptr; emit p->q->unbound(); p->q->deleteLater(); diff --git a/src/wayland/server/resource.h b/src/wayland/server/resource.h index 0cf51fb44d..c513815db4 100644 --- a/src/wayland/server/resource.h +++ b/src/wayland/server/resource.h @@ -81,6 +81,16 @@ Q_SIGNALS: * @since 5.24 **/ void unbound(); + /** + * This signal is emitted when the client is in the process of unbinding the Resource. + * In opposite to @link{unbound} the @link{resource} is still valid and allows to perform + * cleanup tasks. Example: send a keyboard leave for the Surface which is in the process of + * getting destroyed. + * + * @see unbound + * @since 5.37 + **/ + void aboutToBeUnbound(); protected: class Private;