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

KDE's Doxygen guidelines are available online.