| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
| 3 | |
| 4 | #include "qwaylandtextinputmanagerv3.h" |
| 5 | #include "qwaylandtextinputmanagerv3_p.h" |
| 6 | |
| 7 | #include <QtWaylandCompositor/QWaylandCompositor> |
| 8 | #include <QtWaylandCompositor/QWaylandSeat> |
| 9 | |
| 10 | #include "qwaylandtextinputv3.h" |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | QWaylandTextInputManagerV3Private::QWaylandTextInputManagerV3Private() |
| 15 | { |
| 16 | } |
| 17 | |
| 18 | void QWaylandTextInputManagerV3Private::zwp_text_input_manager_v3_get_text_input(Resource *resource, uint32_t id, struct ::wl_resource *seatResource) |
| 19 | { |
| 20 | qCDebug(qLcWaylandCompositorTextInput) << Q_FUNC_INFO; |
| 21 | |
| 22 | Q_Q(QWaylandTextInputManagerV3); |
| 23 | QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(q->extensionContainer()); |
| 24 | QWaylandSeat *seat = QWaylandSeat::fromSeatResource(resource: seatResource); |
| 25 | QWaylandTextInputV3 *textInput = QWaylandTextInputV3::findIn(container: seat); |
| 26 | if (!textInput) { |
| 27 | textInput = new QWaylandTextInputV3(seat, compositor); |
| 28 | } |
| 29 | textInput->add(client: resource->client(), id, version: wl_resource_get_version(resource->handle)); |
| 30 | QWaylandClient *client = QWaylandClient::fromWlClient(compositor, wlClient: resource->client()); |
| 31 | QWaylandClient::TextInputProtocols p = client->textInputProtocols(); |
| 32 | client->setTextInputProtocols(p.setFlag(flag: QWaylandClient::TextInputProtocol::TextInputV3)); |
| 33 | if (!textInput->isInitialized()) |
| 34 | textInput->initialize(); |
| 35 | } |
| 36 | |
| 37 | /*! |
| 38 | \internal |
| 39 | \preliminary |
| 40 | |
| 41 | \qmltype TextInputManagerV3 |
| 42 | \nativetype QWaylandTextInputManagerV3 |
| 43 | \inqmlmodule QtWayland.Compositor |
| 44 | \brief Provides access to input methods in the compositor. |
| 45 | |
| 46 | The \c TextInputManagerV3 corresponds to the \c zwp_text_input_manager_v3 interface |
| 47 | in the \c text_input_unstable_v3 extension protocol. |
| 48 | |
| 49 | Instantiating this as child of a \l WaylandCompositor adds it to the list of interfaces available |
| 50 | to the client. If a client binds to it, then it will be used to communciate text input to |
| 51 | that client. |
| 52 | |
| 53 | \note This protocol is currently a work-in-progress and only exists in Qt for validation purposes. It may change at any time. |
| 54 | */ |
| 55 | |
| 56 | /*! |
| 57 | \internal |
| 58 | \preliminary |
| 59 | \class QWaylandTextInputManagerV3 |
| 60 | \inmodule QtWaylandCompositor |
| 61 | \brief Provides access to input methods in the compositor. |
| 62 | |
| 63 | The \c QWaylandTextInputManagerV3 corresponds to the \c zwp_text_input_manager_v3 interface |
| 64 | in the \c text_input_unstable_v3 extension protocol. |
| 65 | |
| 66 | Instantiating this as child of a \l WaylandCompositor adds it to the list of interfaces available |
| 67 | to the client. If a client binds to it, then it will be used to communciate text input to |
| 68 | that client. |
| 69 | \note This protocol is currently a work-in-progress and only exists in Qt for validation purposes. It may change at any time. |
| 70 | */ |
| 71 | |
| 72 | QWaylandTextInputManagerV3::QWaylandTextInputManagerV3() |
| 73 | : QWaylandCompositorExtensionTemplate<QWaylandTextInputManagerV3>(*new QWaylandTextInputManagerV3Private) |
| 74 | { |
| 75 | } |
| 76 | |
| 77 | QWaylandTextInputManagerV3::QWaylandTextInputManagerV3(QWaylandCompositor *compositor) |
| 78 | : QWaylandCompositorExtensionTemplate<QWaylandTextInputManagerV3>(compositor, *new QWaylandTextInputManagerV3Private) |
| 79 | { |
| 80 | } |
| 81 | |
| 82 | QWaylandTextInputManagerV3::~QWaylandTextInputManagerV3() |
| 83 | { |
| 84 | } |
| 85 | |
| 86 | void QWaylandTextInputManagerV3::initialize() |
| 87 | { |
| 88 | qCDebug(qLcWaylandCompositorTextInput) << Q_FUNC_INFO; |
| 89 | |
| 90 | Q_D(QWaylandTextInputManagerV3); |
| 91 | |
| 92 | QWaylandCompositorExtensionTemplate::initialize(); |
| 93 | QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); |
| 94 | if (!compositor) { |
| 95 | qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandTextInputManagerV3" ; |
| 96 | return; |
| 97 | } |
| 98 | d->init(compositor->display(), 1); |
| 99 | } |
| 100 | |
| 101 | const wl_interface *QWaylandTextInputManagerV3::interface() |
| 102 | { |
| 103 | return QWaylandTextInputManagerV3Private::interface(); |
| 104 | } |
| 105 | |
| 106 | QByteArray QWaylandTextInputManagerV3::interfaceName() |
| 107 | { |
| 108 | return QWaylandTextInputManagerV3Private::interfaceName(); |
| 109 | } |
| 110 | |
| 111 | QT_END_NAMESPACE |
| 112 | |