From 143a6ad82ea0ded69da482eff1750082fd5b2a6a Mon Sep 17 00:00:00 2001 From: Johan Klokkhammer Helsing Date: Wed, 2 Jan 2019 12:33:03 +0100 Subject: Client: Don't assume windows have surfaces in QWaylandInputContext::update Fixes: QTBUG-72751 Change-Id: I6018a34d4a4cfcbdef5d6cd05d2d4ef12846efea Reviewed-by: Paul Olav Tvete --- src/client/qwaylandinputcontext.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client/qwaylandinputcontext.cpp b/src/client/qwaylandinputcontext.cpp index 58ad90d41..e85faaf8e 100644 --- a/src/client/qwaylandinputcontext.cpp +++ b/src/client/qwaylandinputcontext.cpp @@ -417,6 +417,15 @@ void QWaylandInputContext::commit() textInput()->commit(); } +static ::wl_surface *surfaceForWindow(QWindow *window) +{ + if (!window || !window->handle()) + return nullptr; + + auto *waylandWindow = static_cast(window->handle()); + return waylandWindow->wl_surface::object(); +} + void QWaylandInputContext::update(Qt::InputMethodQueries queries) { qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO << queries; @@ -424,15 +433,15 @@ void QWaylandInputContext::update(Qt::InputMethodQueries queries) if (!QGuiApplication::focusObject() || !textInput()) return; - if (mCurrentWindow && mCurrentWindow->handle() && !inputMethodAccepted()) { - struct ::wl_surface *surface = static_cast(mCurrentWindow->handle())->object(); - textInput()->disable(surface); + auto *currentSurface = surfaceForWindow(mCurrentWindow); + + if (currentSurface && !inputMethodAccepted()) { + textInput()->disable(currentSurface); mCurrentWindow.clear(); - } else if (!mCurrentWindow && inputMethodAccepted()) { + } else if (!currentSurface && inputMethodAccepted()) { QWindow *window = QGuiApplication::focusWindow(); - if (window && window->handle()) { - struct ::wl_surface *surface = static_cast(window->handle())->object(); - textInput()->enable(surface); + if (auto *focusSurface = surfaceForWindow(window)) { + textInput()->enable(focusSurface); mCurrentWindow = window; } } -- cgit v1.2.3