diff options
Diffstat (limited to 'src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp')
-rw-r--r-- | src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp | 138 |
1 files changed, 86 insertions, 52 deletions
diff --git a/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp b/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp index a443502fa..e9a962d28 100644 --- a/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp +++ b/src/compositor/compositor_api/qwaylandinputmethodcontrol.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtWaylandCompositor module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2017 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "qwaylandinputmethodcontrol.h" #include "qwaylandinputmethodcontrol_p.h" @@ -45,6 +9,8 @@ #include "qwaylandsurface.h" #include "qwaylandview.h" #include "qwaylandtextinput.h" +#include "qwaylandtextinputv3.h" +#include "qwaylandqttextinputmethod.h" #include <QtGui/QInputMethodEvent> @@ -53,11 +19,21 @@ QWaylandInputMethodControl::QWaylandInputMethodControl(QWaylandSurface *surface) { connect(d_func()->compositor, &QWaylandCompositor::defaultSeatChanged, this, &QWaylandInputMethodControl::defaultSeatChanged); - QWaylandTextInput *textInput = d_func()->textInput(); - if (textInput) { - connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); - connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); - connect(textInput, &QWaylandTextInput::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod); + + updateTextInput(); + + QWaylandTextInputV3 *textInputV3 = d_func()->textInputV3(); + if (textInputV3) { + connect(textInputV3, &QWaylandTextInputV3::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputV3, &QWaylandTextInputV3::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + connect(textInputV3, &QWaylandTextInputV3::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod); + } + + QWaylandQtTextInputMethod *textInputMethod = d_func()->textInputMethod(); + if (textInputMethod) { + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + connect(textInputMethod, &QWaylandQtTextInputMethod::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod); } } @@ -66,10 +42,16 @@ QVariant QWaylandInputMethodControl::inputMethodQuery(Qt::InputMethodQuery query Q_D(const QWaylandInputMethodControl); QWaylandTextInput *textInput = d->textInput(); - - if (textInput && textInput->focus() == d->surface) { + if (textInput != nullptr && textInput->focus() == d->surface) return textInput->inputMethodQuery(query, argument); - } + + QWaylandTextInputV3 *textInputV3 = d->textInputV3(); + if (textInputV3 != nullptr && textInputV3->focus() == d->surface) + return textInputV3->inputMethodQuery(query, argument); + + QWaylandQtTextInputMethod *textInputMethod = d_func()->textInputMethod(); + if (textInputMethod && textInputMethod->focusedSurface() == d->surface) + return textInputMethod->inputMethodQuery(query, argument); return QVariant(); } @@ -78,9 +60,12 @@ void QWaylandInputMethodControl::inputMethodEvent(QInputMethodEvent *event) { Q_D(QWaylandInputMethodControl); - QWaylandTextInput *textInput = d->textInput(); - if (textInput) { + if (QWaylandTextInput *textInput = d->textInput()) { textInput->sendInputMethodEvent(event); + } else if (QWaylandTextInputV3 *textInputV3 = d->textInputV3()) { + textInputV3->sendInputMethodEvent(event); + } else if (QWaylandQtTextInputMethod *textInputMethod = d->textInputMethod()) { + textInputMethod->sendInputMethodEvent(event); } else { event->ignore(); } @@ -131,7 +116,22 @@ void QWaylandInputMethodControl::setSurface(QWaylandSurface *surface) d->surface = surface; QWaylandTextInput *textInput = d->textInput(); - setEnabled(textInput && textInput->isSurfaceEnabled(d->surface)); + QWaylandTextInputV3 *textInputV3 = d->textInputV3(); + QWaylandQtTextInputMethod *textInputMethod = d->textInputMethod(); + setEnabled((textInput && textInput->isSurfaceEnabled(d->surface)) + || (textInputV3 && textInputV3->isSurfaceEnabled(d->surface)) + || (textInputMethod && textInputMethod->isSurfaceEnabled(d->surface))); +} + +void QWaylandInputMethodControl::updateTextInput() +{ + QWaylandTextInput *textInput = d_func()->textInput(); + + if (textInput) { + connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled, Qt::UniqueConnection); + connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled, Qt::UniqueConnection); + connect(textInput, &QWaylandTextInput::updateInputMethod, this, &QWaylandInputMethodControl::updateInputMethod, Qt::UniqueConnection); + } } void QWaylandInputMethodControl::defaultSeatChanged() @@ -139,14 +139,32 @@ void QWaylandInputMethodControl::defaultSeatChanged() Q_D(QWaylandInputMethodControl); disconnect(d->textInput(), nullptr, this, nullptr); + disconnect(d->textInputV3(), nullptr, this, nullptr); + disconnect(d->textInputMethod(), nullptr, this, nullptr); d->seat = d->compositor->defaultSeat(); QWaylandTextInput *textInput = d->textInput(); + QWaylandTextInputV3 *textInputV3 = d->textInputV3(); + QWaylandQtTextInputMethod *textInputMethod = d->textInputMethod(); + + if (textInput) { + connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + } + + if (textInputV3) { + connect(textInputV3, &QWaylandTextInputV3::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputV3, &QWaylandTextInputV3::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + } - connect(textInput, &QWaylandTextInput::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); - connect(textInput, &QWaylandTextInput::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + if (textInputMethod) { + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceEnabled, this, &QWaylandInputMethodControl::surfaceEnabled); + connect(textInputMethod, &QWaylandQtTextInputMethod::surfaceDisabled, this, &QWaylandInputMethodControl::surfaceDisabled); + } - setEnabled(textInput && textInput->isSurfaceEnabled(d->surface)); + setEnabled((textInput && textInput->isSurfaceEnabled(d->surface)) + || (textInputV3 && textInputV3->isSurfaceEnabled(d->surface)) + || (textInputMethod && textInputMethod->isSurfaceEnabled(d->surface))); } QWaylandInputMethodControlPrivate::QWaylandInputMethodControlPrivate(QWaylandSurface *surface) @@ -156,7 +174,23 @@ QWaylandInputMethodControlPrivate::QWaylandInputMethodControlPrivate(QWaylandSur { } +QWaylandQtTextInputMethod *QWaylandInputMethodControlPrivate::textInputMethod() const +{ + if (!surface->client() || !surface->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::QtTextInputMethodV1)) + return nullptr; + return QWaylandQtTextInputMethod::findIn(seat); +} + QWaylandTextInput *QWaylandInputMethodControlPrivate::textInput() const { + if (!surface->client() || !surface->client()->textInputProtocols().testFlag(QWaylandClient::TextInputProtocol::TextInputV2)) + return nullptr; return QWaylandTextInput::findIn(seat); } + +QWaylandTextInputV3 *QWaylandInputMethodControlPrivate::textInputV3() const +{ + return QWaylandTextInputV3::findIn(seat); +} + +#include "moc_qwaylandinputmethodcontrol.cpp" |