diff options
-rw-r--r-- | src/client/qwaylandinputdevice.cpp | 25 | ||||
-rw-r--r-- | src/client/qwaylandinputdevice_p.h | 2 |
2 files changed, 15 insertions, 12 deletions
diff --git a/src/client/qwaylandinputdevice.cpp b/src/client/qwaylandinputdevice.cpp index 79a881a6e..738c57463 100644 --- a/src/client/qwaylandinputdevice.cpp +++ b/src/client/qwaylandinputdevice.cpp @@ -118,7 +118,7 @@ QWaylandInputDevice::Keyboard::~Keyboard() QWaylandWindow *QWaylandInputDevice::Keyboard::focusWindow() const { - return mFocus ? QWaylandWindow::fromWlSurface(mFocus) : nullptr; + return mFocus ? mFocus->waylandWindow() : nullptr; } QWaylandInputDevice::Pointer::Pointer(QWaylandInputDevice *seat) @@ -1215,13 +1215,17 @@ void QWaylandInputDevice::Keyboard::keyboard_enter(uint32_t time, struct wl_surf return; } + QWaylandWindow *window = QWaylandWindow::fromWlSurface(surface); + if (!window) + return; + if (mFocus) { qCWarning(lcQpaWayland()) << "Unexpected wl_keyboard.enter event. Keyboard already has focus"; - disconnect(focusWindow(), &QWaylandWindow::wlSurfaceDestroyed, this, &Keyboard::handleFocusDestroyed); + disconnect(mFocus, &QWaylandSurface::destroyed, this, &Keyboard::handleFocusDestroyed); } - mFocus = surface; - connect(focusWindow(), &QWaylandWindow::wlSurfaceDestroyed, this, &Keyboard::handleFocusDestroyed); + mFocus = window->waylandSurface(); + connect(mFocus, &QWaylandSurface::destroyed, this, &Keyboard::handleFocusDestroyed); mParent->mQDisplay->handleKeyboardFocusChanged(mParent); } @@ -1235,13 +1239,17 @@ void QWaylandInputDevice::Keyboard::keyboard_leave(uint32_t time, struct wl_surf return; } - if (surface != mFocus) { + QWaylandWindow *window = QWaylandWindow::fromWlSurface(surface); + if (!window) + return; + + if (window->waylandSurface() != mFocus) { qCWarning(lcQpaWayland) << "Ignoring unexpected wl_keyboard.leave event." << "wl_surface argument does not match the current focus" << "This is most likely a compositor bug"; return; } - disconnect(focusWindow(), &QWaylandWindow::wlSurfaceDestroyed, this, &Keyboard::handleFocusDestroyed); + disconnect(mFocus, &QWaylandSurface::destroyed, this, &Keyboard::handleFocusDestroyed); handleFocusLost(); } @@ -1341,11 +1349,6 @@ void QWaylandInputDevice::Keyboard::keyboard_key(uint32_t serial, uint32_t time, void QWaylandInputDevice::Keyboard::handleFocusDestroyed() { - // The signal is emitted by QWaylandWindow, which is not necessarily destroyed along with the - // surface, so we still need to disconnect the signal - auto *window = qobject_cast<QWaylandWindow *>(sender()); - disconnect(window, &QWaylandWindow::wlSurfaceDestroyed, this, &Keyboard::handleFocusDestroyed); - Q_ASSERT(window->wlSurface() == mFocus); handleFocusLost(); } diff --git a/src/client/qwaylandinputdevice_p.h b/src/client/qwaylandinputdevice_p.h index 0f36852b0..84ba84e82 100644 --- a/src/client/qwaylandinputdevice_p.h +++ b/src/client/qwaylandinputdevice_p.h @@ -223,7 +223,7 @@ public: void keyboard_repeat_info(int32_t rate, int32_t delay) override; QWaylandInputDevice *mParent = nullptr; - ::wl_surface *mFocus = nullptr; + QPointer<QWaylandSurface> mFocus; uint32_t mNativeModifiers = 0; |