KWayland

textinput_interface.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Martin Gräßlin <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5 */
6 #include "display.h"
7 #include "global_p.h"
8 #include "resource_p.h"
9 #include "seat_interface_p.h"
10 #include "surface_interface.h"
11 #include "textinput_interface_p.h"
12 
13 #include <QVector>
14 
15 #include <wayland-text-input-unstable-v2-server-protocol.h>
16 #include <wayland-text-server-protocol.h>
17 
18 namespace KWayland
19 {
20 namespace Server
21 {
22 void TextInputInterface::Private::showInputPanelCallback(wl_client *client, wl_resource *resource)
23 {
24  auto p = cast<Private>(resource);
25  Q_ASSERT(*p->client == client);
26  Q_EMIT p->q_func()->requestShowInputPanel();
27 }
28 
29 void TextInputInterface::Private::hideInputPanelCallback(wl_client *client, wl_resource *resource)
30 {
31  auto p = cast<Private>(resource);
32  Q_ASSERT(*p->client == client);
33  Q_EMIT p->q_func()->requestHideInputPanel();
34 }
35 
36 void TextInputInterface::Private::setSurroundingTextCallback(wl_client *client, wl_resource *resource, const char *text, int32_t cursor, int32_t anchor)
37 {
38  auto p = cast<Private>(resource);
39  Q_ASSERT(*p->client == client);
40  p->surroundingText = QByteArray(text);
41  // TODO: make qint32
42  p->surroundingTextCursorPosition = cursor;
43  p->surroundingTextSelectionAnchor = anchor;
44  Q_EMIT p->q_func()->surroundingTextChanged();
45 }
46 
47 void TextInputInterface::Private::setContentTypeCallback(wl_client *client, wl_resource *resource, uint32_t hint, uint32_t purpose)
48 {
49  auto p = cast<Private>(resource);
50  Q_ASSERT(*p->client == client);
51  const auto contentHints = p->convertContentHint(hint);
52  const auto contentPurpose = p->convertContentPurpose(purpose);
53  if (contentHints != p->contentHints || contentPurpose != p->contentPurpose) {
54  p->contentHints = contentHints;
55  p->contentPurpose = contentPurpose;
56  Q_EMIT p->q_func()->contentTypeChanged();
57  }
58 }
59 
60 void TextInputInterface::Private::setCursorRectangleCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height)
61 {
62  auto p = cast<Private>(resource);
63  Q_ASSERT(*p->client == client);
64  const QRect rect = QRect(x, y, width, height);
65  if (p->cursorRectangle != rect) {
66  p->cursorRectangle = rect;
67  Q_EMIT p->q_func()->cursorRectangleChanged(p->cursorRectangle);
68  }
69 }
70 
71 void TextInputInterface::Private::setPreferredLanguageCallback(wl_client *client, wl_resource *resource, const char *language)
72 {
73  auto p = cast<Private>(resource);
74  Q_ASSERT(*p->client == client);
75  const QByteArray preferredLanguage = QByteArray(language);
76  if (p->preferredLanguage != preferredLanguage) {
77  p->preferredLanguage = preferredLanguage;
78  Q_EMIT p->q_func()->preferredLanguageChanged(p->preferredLanguage);
79  }
80 }
81 
82 TextInputInterface::Private::Private(TextInputInterface *q, Global *c, wl_resource *parentResource, const wl_interface *interface, const void *implementation)
83  : Resource::Private(q, c, parentResource, interface, implementation)
84 {
85 }
86 
87 TextInputInterface::Private::~Private()
88 {
89  if (resource) {
90  wl_resource_destroy(resource);
91  resource = nullptr;
92  }
93 }
94 
95 QByteArray TextInputInterface::preferredLanguage() const
96 {
97  Q_D();
98  return d->preferredLanguage;
99 }
100 
101 TextInputInterface::ContentHints TextInputInterface::contentHints() const
102 {
103  Q_D();
104  return d->contentHints;
105 }
106 
107 TextInputInterface::ContentPurpose TextInputInterface::contentPurpose() const
108 {
109  Q_D();
110  return d->contentPurpose;
111 }
112 
113 QByteArray TextInputInterface::surroundingText() const
114 {
115  Q_D();
116  return d->surroundingText;
117 }
118 
119 qint32 TextInputInterface::surroundingTextCursorPosition() const
120 {
121  Q_D();
122  return d->surroundingTextCursorPosition;
123 }
124 
125 qint32 TextInputInterface::surroundingTextSelectionAnchor() const
126 {
127  Q_D();
128  return d->surroundingTextSelectionAnchor;
129 }
130 
131 void TextInputInterface::preEdit(const QByteArray &text, const QByteArray &commit)
132 {
133  Q_D();
134  d->preEdit(text, commit);
135 }
136 
137 void TextInputInterface::commit(const QByteArray &text)
138 {
139  Q_D();
140  d->commit(text);
141 }
142 
143 void TextInputInterface::keysymPressed(quint32 keysym, Qt::KeyboardModifiers modifiers)
144 {
145  Q_UNUSED(modifiers)
146  Q_D();
147  d->keysymPressed(keysym, modifiers);
148 }
149 
150 void TextInputInterface::keysymReleased(quint32 keysym, Qt::KeyboardModifiers modifiers)
151 {
152  Q_D();
153  d->keysymReleased(keysym, modifiers);
154 }
155 
156 void TextInputInterface::deleteSurroundingText(quint32 beforeLength, quint32 afterLength)
157 {
158  Q_D();
159  d->deleteSurroundingText(beforeLength, afterLength);
160 }
161 
162 void TextInputInterface::setCursorPosition(qint32 index, qint32 anchor)
163 {
164  Q_D();
165  d->setCursorPosition(index, anchor);
166 }
167 
168 void TextInputInterface::setTextDirection(Qt::LayoutDirection direction)
169 {
170  Q_D();
171  d->setTextDirection(direction);
172 }
173 
174 void TextInputInterface::setPreEditCursor(qint32 index)
175 {
176  Q_D();
177  d->setPreEditCursor(index);
178 }
179 
180 void TextInputInterface::setInputPanelState(bool visible, const QRect &overlappedSurfaceArea)
181 {
182  Q_D();
183  if (d->inputPanelVisible == visible && d->overlappedSurfaceArea == overlappedSurfaceArea) {
184  // not changed
185  return;
186  }
187  d->inputPanelVisible = visible;
188  d->overlappedSurfaceArea = overlappedSurfaceArea;
189  d->sendInputPanelState();
190 }
191 
192 void TextInputInterface::setLanguage(const QByteArray &languageTag)
193 {
194  Q_D();
195  if (d->language == languageTag) {
196  // not changed
197  return;
198  }
199  d->language = languageTag;
200  d->sendLanguage();
201 }
202 
203 TextInputInterfaceVersion TextInputInterface::interfaceVersion() const
204 {
205  Q_D();
206  return d->interfaceVersion();
207 }
208 
209 QPointer<SurfaceInterface> TextInputInterface::surface() const
210 {
211  Q_D();
212  return d->surface;
213 }
214 
215 QRect TextInputInterface::cursorRectangle() const
216 {
217  Q_D();
218  return d->cursorRectangle;
219 }
220 
221 bool TextInputInterface::isEnabled() const
222 {
223  Q_D();
224  return d->enabled;
225 }
226 
227 TextInputInterface::Private *TextInputInterface::d_func() const
228 {
229  return reinterpret_cast<Private *>(d.data());
230 }
231 
232 TextInputInterface::TextInputInterface(Private *p, QObject *parent)
233  : Resource(p, parent)
234 {
235 }
236 
237 TextInputInterface::~TextInputInterface() = default;
238 
239 TextInputManagerInterface::TextInputManagerInterface(Private *d, QObject *parent)
240  : Global(d, parent)
241 {
242 }
243 
244 TextInputManagerInterface::~TextInputManagerInterface() = default;
245 
247 {
248  Q_D();
249  return d->interfaceVersion;
250 }
251 
252 TextInputManagerInterface::Private *TextInputManagerInterface::d_func() const
253 {
254  return reinterpret_cast<Private *>(d.data());
255 }
256 
257 }
258 }
T * data() const const
ContentPurpose
The ContentPurpose allows to specify the primary purpose of a text input.
LayoutDirection
TextInputInterfaceVersion
Enum describing the different InterfaceVersion encapsulated in this implementation.
typedef KeyboardModifiers
TextInputInterfaceVersion interfaceVersion() const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 03:56:22 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.