1 | // Copyright (C) 2020 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qwaylandqttextinputmethodmanager.h" |
5 | #include "qwaylandqttextinputmethodmanager_p.h" |
6 | |
7 | #include <QtWaylandCompositor/QWaylandCompositor> |
8 | #include <QtWaylandCompositor/QWaylandSeat> |
9 | |
10 | #include "qwaylandqttextinputmethod.h" |
11 | |
12 | QT_BEGIN_NAMESPACE |
13 | |
14 | QWaylandQtTextInputMethodManagerPrivate::QWaylandQtTextInputMethodManagerPrivate() |
15 | { |
16 | } |
17 | |
18 | void QWaylandQtTextInputMethodManagerPrivate::text_input_method_manager_v1_get_text_input_method(Resource *resource, uint32_t id, struct ::wl_resource *seatResource) |
19 | { |
20 | Q_Q(QWaylandQtTextInputMethodManager); |
21 | QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(q->extensionContainer()); |
22 | QWaylandSeat *seat = QWaylandSeat::fromSeatResource(resource: seatResource); |
23 | QWaylandQtTextInputMethod *textInput = QWaylandQtTextInputMethod::findIn(container: seat); |
24 | if (textInput == nullptr) |
25 | textInput = new QWaylandQtTextInputMethod(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::QtTextInputMethodV1)); |
30 | |
31 | if (!textInput->isInitialized()) |
32 | textInput->initialize(); |
33 | } |
34 | |
35 | /*! |
36 | \qmltype QtTextInputMethodManager |
37 | \instantiates QWaylandQtTextInputMethodManager |
38 | \inqmlmodule QtWayland.Compositor |
39 | \since 6.0 |
40 | \brief Provides access to input methods in the compositor. |
41 | |
42 | The \c QtTextInputMethodManager corresponds to the \c qt-text-input-method-manager interface |
43 | in the \c qt-text-input-method-unstable-v1 extension protocol. It is specifically designed |
44 | to be used with a Qt-based input method, such as Qt Virtual Keyboard. |
45 | |
46 | Instantiating this as child of a \l WaylandCompositor adds it to the list of interfaces available |
47 | to the client. If a client binds to it, then it will be used to communciate text input to |
48 | that client. |
49 | */ |
50 | |
51 | /*! |
52 | \class QWaylandQtTextInputMethodManager |
53 | \inmodule QtWaylandCompositor |
54 | \since 6.0 |
55 | \brief Provides access to input methods in the compositor. |
56 | |
57 | The \c QWaylandQtTextInputMethodManager class corresponds to the \c qt-text-input-method-manager interface |
58 | in the \c qt-text-input-method-unstable-v1 extension protocol. It is specifically designed |
59 | to be used with a Qt-based input method, such as Qt Virtual Keyboard. |
60 | |
61 | Instantiating this as child of a \l WaylandCompositor adds it to the list of interfaces available |
62 | to the client. If a client binds to it, then it will be used to communciate text input to |
63 | that client. |
64 | */ |
65 | |
66 | QWaylandQtTextInputMethodManager::QWaylandQtTextInputMethodManager() |
67 | : QWaylandCompositorExtensionTemplate<QWaylandQtTextInputMethodManager>(*new QWaylandQtTextInputMethodManagerPrivate) |
68 | { |
69 | } |
70 | |
71 | QWaylandQtTextInputMethodManager::QWaylandQtTextInputMethodManager(QWaylandCompositor *compositor) |
72 | : QWaylandCompositorExtensionTemplate<QWaylandQtTextInputMethodManager>(compositor, *new QWaylandQtTextInputMethodManagerPrivate) |
73 | { |
74 | } |
75 | |
76 | void QWaylandQtTextInputMethodManager::initialize() |
77 | { |
78 | Q_D(QWaylandQtTextInputMethodManager); |
79 | |
80 | QWaylandCompositorExtensionTemplate::initialize(); |
81 | QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); |
82 | if (compositor == nullptr) { |
83 | qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandQtTextInputMethodManager" ; |
84 | return; |
85 | } |
86 | |
87 | d->init(compositor->display(), 1); |
88 | } |
89 | |
90 | const wl_interface *QWaylandQtTextInputMethodManager::interface() |
91 | { |
92 | return QWaylandQtTextInputMethodManagerPrivate::interface(); |
93 | } |
94 | |
95 | QByteArray QWaylandQtTextInputMethodManager::interfaceName() |
96 | { |
97 | return QWaylandQtTextInputMethodManagerPrivate::interfaceName(); |
98 | } |
99 | |
100 | QT_END_NAMESPACE |
101 | |
102 | #include "moc_qwaylandqttextinputmethodmanager.cpp" |
103 | |