1// Copyright (C) 2017-2016 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#include "qwaylandtextinputmanager.h"
5#include "qwaylandtextinputmanager_p.h"
6
7#include <QtWaylandCompositor/QWaylandCompositor>
8#include <QtWaylandCompositor/QWaylandSeat>
9
10#include "qwaylandtextinput.h"
11
12QT_BEGIN_NAMESPACE
13
14QWaylandTextInputManagerPrivate::QWaylandTextInputManagerPrivate()
15{
16}
17
18void QWaylandTextInputManagerPrivate::zwp_text_input_manager_v2_get_text_input(Resource *resource, uint32_t id, struct ::wl_resource *seatResource)
19{
20 Q_Q(QWaylandTextInputManager);
21 QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(q->extensionContainer());
22 QWaylandSeat *seat = QWaylandSeat::fromSeatResource(resource: seatResource);
23 QWaylandTextInput *textInput = QWaylandTextInput::findIn(container: seat);
24 if (!textInput)
25 textInput = new QWaylandTextInput(seat, compositor);
26 textInput->add(client: resource->client(), id, version: wl_resource_get_version(resource->handle));
27 QWaylandClient *client = QWaylandClient::fromWlClient(compositor, wlClient: resource->client());
28 QWaylandClient::TextInputProtocols p = client->textInputProtocols();
29 client->setTextInputProtocols(p.setFlag(flag: QWaylandClient::TextInputProtocol::TextInputV2));
30 if (!textInput->isInitialized())
31 textInput->initialize();
32}
33
34/*!
35 \qmltype TextInputManager
36 \instantiates QWaylandTextInputManager
37 \inqmlmodule QtWayland.Compositor
38 \brief Provides access to input methods in the compositor.
39
40 The \c TextInputManager corresponds to the \c zwp_text_input_manager_v2 interface
41 in the \c text_input_unstable_v2 extension protocol.
42
43 Instantiating this as child of a \l WaylandCompositor adds it to the list of interfaces available
44 to the client. If a client binds to it, then it will be used to communciate text input to
45 that client.
46*/
47
48/*!
49 \class QWaylandTextInputManager
50 \inmodule QtWaylandCompositor
51 \brief Provides access to input methods in the compositor.
52
53 The \c QWaylandTextInputManager corresponds to the \c zwp_text_input_manager_v2 interface
54 in the \c text_input_unstable_v2 extension protocol.
55
56 Instantiating this as child of a \l WaylandCompositor adds it to the list of interfaces available
57 to the client. If a client binds to it, then it will be used to communciate text input to
58 that client.
59*/
60
61QWaylandTextInputManager::QWaylandTextInputManager()
62 : QWaylandCompositorExtensionTemplate<QWaylandTextInputManager>(*new QWaylandTextInputManagerPrivate)
63{
64}
65
66QWaylandTextInputManager::QWaylandTextInputManager(QWaylandCompositor *compositor)
67 : QWaylandCompositorExtensionTemplate<QWaylandTextInputManager>(compositor, *new QWaylandTextInputManagerPrivate)
68{
69}
70
71void QWaylandTextInputManager::initialize()
72{
73 Q_D(QWaylandTextInputManager);
74
75 QWaylandCompositorExtensionTemplate::initialize();
76 QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer());
77 if (!compositor) {
78 qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandTextInputManager";
79 return;
80 }
81 d->init(compositor->display(), 1);
82}
83
84const wl_interface *QWaylandTextInputManager::interface()
85{
86 return QWaylandTextInputManagerPrivate::interface();
87}
88
89QByteArray QWaylandTextInputManager::interfaceName()
90{
91 return QWaylandTextInputManagerPrivate::interfaceName();
92}
93
94QT_END_NAMESPACE
95
96#include "moc_qwaylandtextinputmanager.cpp"
97

source code of qtwayland/src/compositor/extensions/qwaylandtextinputmanager.cpp