Remove redundant calls, textInput()

It is used repeatedly. Normally it can be optimized by a compiler
but it might be helpful to see what it is by the name, inputInterface.

Pick-to: 6.7 6.6 6.5
Change-Id: I7f4988674d7249c84b1321e69146dfd92189f142
Reviewed-by: David Edmundson <davidedmundson@kde.org>
This commit is contained in:
Inho Lee 2024-02-02 12:36:08 +01:00
parent 575448a77a
commit fc63491355

View File

@ -48,20 +48,22 @@ void QWaylandInputContext::reset()
QPlatformInputContext::reset(); QPlatformInputContext::reset();
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return; return;
textInput()->reset(); inputInterface->reset();
} }
void QWaylandInputContext::commit() void QWaylandInputContext::commit()
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return; return;
textInput()->commit(); inputInterface->commit();
} }
static ::wl_surface *surfaceForWindow(QWindow *window) static ::wl_surface *surfaceForWindow(QWindow *window)
@ -77,92 +79,100 @@ void QWaylandInputContext::update(Qt::InputMethodQueries queries)
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO << queries; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO << queries;
if (!QGuiApplication::focusObject() || !textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!QGuiApplication::focusObject() || !inputInterface)
return; return;
auto *currentSurface = surfaceForWindow(mCurrentWindow); auto *currentSurface = surfaceForWindow(mCurrentWindow);
if (currentSurface && !inputMethodAccepted()) { if (currentSurface && !inputMethodAccepted()) {
textInput()->disableSurface(currentSurface); inputInterface->disableSurface(currentSurface);
mCurrentWindow.clear(); mCurrentWindow.clear();
} else if (!currentSurface && inputMethodAccepted()) { } else if (!currentSurface && inputMethodAccepted()) {
QWindow *window = QGuiApplication::focusWindow(); QWindow *window = QGuiApplication::focusWindow();
if (auto *focusSurface = surfaceForWindow(window)) { if (auto *focusSurface = surfaceForWindow(window)) {
textInput()->enableSurface(focusSurface); inputInterface->enableSurface(focusSurface);
mCurrentWindow = window; mCurrentWindow = window;
} }
} }
textInput()->updateState(queries, QWaylandTextInputInterface::update_state_change); inputInterface->updateState(queries, QWaylandTextInputInterface::update_state_change);
} }
void QWaylandInputContext::invokeAction(QInputMethod::Action action, int cursorPostion) void QWaylandInputContext::invokeAction(QInputMethod::Action action, int cursorPostion)
{ {
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return; return;
if (action == QInputMethod::Click) if (action == QInputMethod::Click)
textInput()->setCursorInsidePreedit(cursorPostion); inputInterface->setCursorInsidePreedit(cursorPostion);
} }
void QWaylandInputContext::showInputPanel() void QWaylandInputContext::showInputPanel()
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return; return;
textInput()->showInputPanel(); inputInterface->showInputPanel();
} }
void QWaylandInputContext::hideInputPanel() void QWaylandInputContext::hideInputPanel()
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return; return;
textInput()->hideInputPanel(); inputInterface->hideInputPanel();
} }
bool QWaylandInputContext::isInputPanelVisible() const bool QWaylandInputContext::isInputPanelVisible() const
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return QPlatformInputContext::isInputPanelVisible(); return QPlatformInputContext::isInputPanelVisible();
return textInput()->isInputPanelVisible(); return inputInterface->isInputPanelVisible();
} }
QRectF QWaylandInputContext::keyboardRect() const QRectF QWaylandInputContext::keyboardRect() const
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return QPlatformInputContext::keyboardRect(); return QPlatformInputContext::keyboardRect();
return textInput()->keyboardRect(); return inputInterface->keyboardRect();
} }
QLocale QWaylandInputContext::locale() const QLocale QWaylandInputContext::locale() const
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return QPlatformInputContext::locale(); return QPlatformInputContext::locale();
return textInput()->locale(); return inputInterface->locale();
} }
Qt::LayoutDirection QWaylandInputContext::inputDirection() const Qt::LayoutDirection QWaylandInputContext::inputDirection() const
{ {
qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO; qCDebug(qLcQpaInputMethods) << Q_FUNC_INFO;
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return QPlatformInputContext::inputDirection(); return QPlatformInputContext::inputDirection();
return textInput()->inputDirection(); return inputInterface->inputDirection();
} }
void QWaylandInputContext::setFocusObject(QObject *object) void QWaylandInputContext::setFocusObject(QObject *object)
@ -174,7 +184,8 @@ void QWaylandInputContext::setFocusObject(QObject *object)
Q_UNUSED(object); Q_UNUSED(object);
#endif #endif
if (!textInput()) QWaylandTextInputInterface *inputInterface = textInput();
if (!inputInterface)
return; return;
QWindow *window = QGuiApplication::focusWindow(); QWindow *window = QGuiApplication::focusWindow();
@ -183,7 +194,7 @@ void QWaylandInputContext::setFocusObject(QObject *object)
if (mCurrentWindow.data() != window || !inputMethodAccepted()) { if (mCurrentWindow.data() != window || !inputMethodAccepted()) {
auto *surface = static_cast<QWaylandWindow *>(mCurrentWindow->handle())->wlSurface(); auto *surface = static_cast<QWaylandWindow *>(mCurrentWindow->handle())->wlSurface();
if (surface) if (surface)
textInput()->disableSurface(surface); inputInterface->disableSurface(surface);
mCurrentWindow.clear(); mCurrentWindow.clear();
} }
} }
@ -192,11 +203,11 @@ void QWaylandInputContext::setFocusObject(QObject *object)
if (mCurrentWindow.data() != window) { if (mCurrentWindow.data() != window) {
auto *surface = static_cast<QWaylandWindow *>(window->handle())->wlSurface(); auto *surface = static_cast<QWaylandWindow *>(window->handle())->wlSurface();
if (surface) { if (surface) {
textInput()->enableSurface(surface); inputInterface->enableSurface(surface);
mCurrentWindow = window; mCurrentWindow = window;
} }
} }
textInput()->updateState(Qt::ImQueryAll, QWaylandTextInputInterface::update_state_enter); inputInterface->updateState(Qt::ImQueryAll, QWaylandTextInputInterface::update_state_enter);
} }
} }