Changeset View
Changeset View
Standalone View
Standalone View
src/server/textinput_interface.cpp
1 | /**************************************************************************** | 1 | /**************************************************************************** | ||
---|---|---|---|---|---|
2 | Copyright 2016 Martin Gräßlin <mgraesslin@kde.org> | 2 | Copyright 2016 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | Copyright 2018 Roman Gilg <subdiff@gmail.com> | ||||
3 | 4 | | |||
4 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | 6 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) version 3, or any | 8 | version 2.1 of the License, or (at your option) version 3, or any | ||
8 | later version accepted by the membership of KDE e.V. (or its | 9 | later version accepted by the membership of KDE e.V. (or its | ||
9 | successor approved by the membership of KDE e.V.), which shall | 10 | successor approved by the membership of KDE e.V.), which shall | ||
10 | act as a proxy defined in Section 6 of version 3 of the license. | 11 | act as a proxy defined in Section 6 of version 3 of the license. | ||
Show All 12 Lines | |||||
23 | #include "resource_p.h" | 24 | #include "resource_p.h" | ||
24 | #include "seat_interface_p.h" | 25 | #include "seat_interface_p.h" | ||
25 | #include "surface_interface.h" | 26 | #include "surface_interface.h" | ||
26 | 27 | | |||
27 | #include <QVector> | 28 | #include <QVector> | ||
28 | 29 | | |||
29 | #include <wayland-text-server-protocol.h> | 30 | #include <wayland-text-server-protocol.h> | ||
30 | #include <wayland-text-input-unstable-v2-server-protocol.h> | 31 | #include <wayland-text-input-unstable-v2-server-protocol.h> | ||
32 | #include <wayland-text-input-unstable-v3-server-protocol.h> | ||||
31 | 33 | | |||
32 | namespace KWayland | 34 | namespace KWayland | ||
33 | { | 35 | { | ||
34 | namespace Server | 36 | namespace Server | ||
35 | { | 37 | { | ||
36 | 38 | | |||
37 | void TextInputInterface::Private::showInputPanelCallback(wl_client *client, wl_resource *resource) | 39 | void TextInputInterface::Private::showInputPanelCallback(wl_client *client, wl_resource *resource) | ||
38 | { | 40 | { | ||
39 | auto p = cast<Private>(resource); | 41 | auto p = cast<Private>(resource); | ||
40 | Q_ASSERT(*p->client == client); | 42 | Q_ASSERT(*p->client == client); | ||
41 | emit p->q_func()->requestShowInputPanel(); | 43 | emit p->q_func()->requestShowInputPanel(); | ||
42 | } | 44 | } | ||
43 | 45 | | |||
44 | void TextInputInterface::Private::hideInputPanelCallback(wl_client *client, wl_resource *resource) | 46 | void TextInputInterface::Private::hideInputPanelCallback(wl_client *client, wl_resource *resource) | ||
45 | { | 47 | { | ||
46 | auto p = cast<Private>(resource); | 48 | auto p = cast<Private>(resource); | ||
47 | Q_ASSERT(*p->client == client); | 49 | Q_ASSERT(*p->client == client); | ||
48 | emit p->q_func()->requestHideInputPanel(); | 50 | emit p->q_func()->requestHideInputPanel(); | ||
49 | } | 51 | } | ||
50 | 52 | | |||
51 | void TextInputInterface::Private::setSurroundingTextCallback(wl_client *client, wl_resource *resource, const char * text, int32_t cursor, int32_t anchor) | 53 | void TextInputInterface::Private::setSurroundingTextCallback(wl_client *client, wl_resource *resource, const char *text, int32_t cursor, int32_t anchor) | ||
52 | { | 54 | { | ||
53 | auto p = cast<Private>(resource); | 55 | auto p = cast<Private>(resource); | ||
54 | Q_ASSERT(*p->client == client); | 56 | Q_ASSERT(*p->client == client); | ||
55 | p->surroundingText = QByteArray(text); | 57 | p->setSurroundingText(text, cursor, anchor); | ||
56 | // TODO: make qint32 | | |||
57 | p->surroundingTextCursorPosition = cursor; | | |||
58 | p->surroundingTextSelectionAnchor = anchor; | | |||
59 | emit p->q_func()->surroundingTextChanged(); | | |||
60 | } | 58 | } | ||
61 | 59 | | |||
62 | void TextInputInterface::Private::setContentTypeCallback(wl_client *client, wl_resource *resource, uint32_t hint, uint32_t purpose) | 60 | void TextInputInterface::Private::setContentTypeCallback(wl_client *client, wl_resource *resource, uint32_t hint, uint32_t purpose) | ||
63 | { | 61 | { | ||
64 | auto p = cast<Private>(resource); | 62 | auto p = cast<Private>(resource); | ||
65 | Q_ASSERT(*p->client == client); | 63 | Q_ASSERT(*p->client == client); | ||
66 | const auto contentHints = p->convertContentHint(hint); | 64 | const auto contentHints = p->convertContentHint(hint); | ||
67 | const auto contentPurpose = p->convertContentPurpose(purpose); | 65 | const auto contentPurpose = p->convertContentPurpose(purpose); | ||
68 | if (contentHints != p->contentHints || contentPurpose != p->contentPurpose) { | 66 | p->setContentType(contentHints, contentPurpose); | ||
69 | p->contentHints = contentHints; | | |||
70 | p->contentPurpose = contentPurpose; | | |||
71 | emit p->q_func()->contentTypeChanged(); | | |||
72 | } | | |||
73 | } | 67 | } | ||
74 | 68 | | |||
75 | void TextInputInterface::Private::setCursorRectangleCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) | 69 | void TextInputInterface::Private::setCursorRectangleCallback(wl_client *client, wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) | ||
76 | { | 70 | { | ||
77 | auto p = cast<Private>(resource); | 71 | auto p = cast<Private>(resource); | ||
78 | Q_ASSERT(*p->client == client); | 72 | Q_ASSERT(*p->client == client); | ||
79 | const QRect rect = QRect(x, y, width, height); | 73 | p->setCursorRectangle(QRect(x, y, width, height)); | ||
80 | if (p->cursorRectangle != rect) { | | |||
81 | p->cursorRectangle = rect; | | |||
82 | emit p->q_func()->cursorRectangleChanged(p->cursorRectangle); | | |||
83 | } | | |||
84 | } | 74 | } | ||
85 | 75 | | |||
86 | void TextInputInterface::Private::setPreferredLanguageCallback(wl_client *client, wl_resource *resource, const char * language) | 76 | void TextInputInterface::Private::setPreferredLanguageCallback(wl_client *client, wl_resource *resource, const char * language) | ||
87 | { | 77 | { | ||
88 | auto p = cast<Private>(resource); | 78 | auto p = cast<Private>(resource); | ||
89 | Q_ASSERT(*p->client == client); | 79 | Q_ASSERT(*p->client == client); | ||
90 | const QByteArray preferredLanguage = QByteArray(language); | 80 | const QByteArray preferredLanguage = QByteArray(language); | ||
91 | if (p->preferredLanguage != preferredLanguage) { | 81 | if (p->preferredLanguage != preferredLanguage) { | ||
Show All 10 Lines | |||||
102 | TextInputInterface::Private::~Private() | 92 | TextInputInterface::Private::~Private() | ||
103 | { | 93 | { | ||
104 | if (resource) { | 94 | if (resource) { | ||
105 | wl_resource_destroy(resource); | 95 | wl_resource_destroy(resource); | ||
106 | resource = nullptr; | 96 | resource = nullptr; | ||
107 | } | 97 | } | ||
108 | } | 98 | } | ||
109 | 99 | | |||
100 | void TextInputInterface::Private::setSurroundingText(const char *text, int32_t cursor, int32_t anchor) | ||||
101 | { | ||||
102 | surroundingText = QByteArray(text); | ||||
103 | // TODO: make qint32 | ||||
104 | surroundingTextCursorPosition = cursor; | ||||
105 | surroundingTextSelectionAnchor = anchor; | ||||
106 | emit q_func()->surroundingTextChanged(); | ||||
107 | } | ||||
108 | | ||||
109 | void TextInputInterface::Private::setContentType(TextInputInterface::ContentHints hints, TextInputInterface::ContentPurpose purpose) | ||||
110 | { | ||||
111 | if (hints == contentHints && purpose == contentPurpose) { | ||||
112 | return; | ||||
113 | } | ||||
114 | contentHints = hints; | ||||
115 | contentPurpose = purpose; | ||||
116 | emit q_func()->contentTypeChanged(); | ||||
117 | } | ||||
118 | | ||||
119 | void TextInputInterface::Private::setCursorRectangle(const QRect &rect) | ||||
120 | { | ||||
121 | if (cursorRectangle == rect) { | ||||
122 | return; | ||||
123 | } | ||||
124 | cursorRectangle = rect; | ||||
125 | emit q_func()->cursorRectangleChanged(cursorRectangle); | ||||
126 | } | ||||
127 | | ||||
128 | void TextInputInterface::Private::done() | ||||
129 | { | ||||
130 | // child classes with implementation need to override | ||||
131 | } | ||||
132 | | ||||
110 | QByteArray TextInputInterface::preferredLanguage() const | 133 | QByteArray TextInputInterface::preferredLanguage() const | ||
111 | { | 134 | { | ||
112 | Q_D(); | 135 | Q_D(); | ||
113 | return d->preferredLanguage; | 136 | return d->preferredLanguage; | ||
114 | } | 137 | } | ||
115 | 138 | | |||
116 | TextInputInterface::ContentHints TextInputInterface::contentHints() const | 139 | TextInputInterface::ContentHints TextInputInterface::contentHints() const | ||
117 | { | 140 | { | ||
Show All 20 Lines | |||||
138 | } | 161 | } | ||
139 | 162 | | |||
140 | qint32 TextInputInterface::surroundingTextSelectionAnchor() const | 163 | qint32 TextInputInterface::surroundingTextSelectionAnchor() const | ||
141 | { | 164 | { | ||
142 | Q_D(); | 165 | Q_D(); | ||
143 | return d->surroundingTextSelectionAnchor; | 166 | return d->surroundingTextSelectionAnchor; | ||
144 | } | 167 | } | ||
145 | 168 | | |||
169 | TextInputInterface::ChangeCause TextInputInterface::surroundingTextChangeCause() const | ||||
170 | { | ||||
171 | Q_D(); | ||||
172 | return d->surroundingTextChangeCause; | ||||
173 | } | ||||
174 | | ||||
146 | void TextInputInterface::preEdit(const QByteArray &text, const QByteArray &commit) | 175 | void TextInputInterface::preEdit(const QByteArray &text, const QByteArray &commit) | ||
147 | { | 176 | { | ||
148 | Q_D(); | 177 | Q_D(); | ||
149 | d->preEdit(text, commit); | 178 | d->preEdit(text, commit); | ||
150 | } | 179 | } | ||
151 | 180 | | |||
181 | void TextInputInterface::preEdit(const QByteArray &text) | ||||
182 | { | ||||
183 | preEdit(text, QByteArray()); | ||||
184 | } | ||||
185 | | ||||
152 | void TextInputInterface::commit(const QByteArray &text) | 186 | void TextInputInterface::commit(const QByteArray &text) | ||
153 | { | 187 | { | ||
154 | Q_D(); | 188 | Q_D(); | ||
155 | d->commit(text); | 189 | d->commit(text); | ||
156 | } | 190 | } | ||
157 | 191 | | |||
158 | void TextInputInterface::keysymPressed(quint32 keysym, Qt::KeyboardModifiers modifiers) | 192 | void TextInputInterface::keysymPressed(quint32 keysym, Qt::KeyboardModifiers modifiers) | ||
159 | { | 193 | { | ||
Show All 23 Lines | |||||
183 | void TextInputInterface::setTextDirection(Qt::LayoutDirection direction) | 217 | void TextInputInterface::setTextDirection(Qt::LayoutDirection direction) | ||
184 | { | 218 | { | ||
185 | Q_D(); | 219 | Q_D(); | ||
186 | d->setTextDirection(direction); | 220 | d->setTextDirection(direction); | ||
187 | } | 221 | } | ||
188 | 222 | | |||
189 | void TextInputInterface::setPreEditCursor(qint32 index) | 223 | void TextInputInterface::setPreEditCursor(qint32 index) | ||
190 | { | 224 | { | ||
225 | setPreEditCursor(index, index); | ||||
226 | } | ||||
227 | | ||||
228 | void TextInputInterface::setPreEditCursor(qint32 begin, qint32 end) | ||||
229 | { | ||||
191 | Q_D(); | 230 | Q_D(); | ||
192 | d->setPreEditCursor(index); | 231 | d->setPreEditCursor(begin, end); | ||
193 | } | 232 | } | ||
194 | 233 | | |||
195 | void TextInputInterface::setInputPanelState(bool visible, const QRect &overlappedSurfaceArea) | 234 | void TextInputInterface::setInputPanelState(bool visible, const QRect &overlappedSurfaceArea) | ||
196 | { | 235 | { | ||
197 | Q_D(); | 236 | Q_D(); | ||
198 | if (d->inputPanelVisible == visible && d->overlappedSurfaceArea == overlappedSurfaceArea) { | 237 | if (d->inputPanelVisible == visible && d->overlappedSurfaceArea == overlappedSurfaceArea) { | ||
199 | // not changed | 238 | // not changed | ||
200 | return; | 239 | return; | ||
Show All 9 Lines | 247 | { | |||
210 | if (d->language == languageTag) { | 249 | if (d->language == languageTag) { | ||
211 | // not changed | 250 | // not changed | ||
212 | return; | 251 | return; | ||
213 | } | 252 | } | ||
214 | d->language = languageTag; | 253 | d->language = languageTag; | ||
215 | d->sendLanguage(); | 254 | d->sendLanguage(); | ||
216 | } | 255 | } | ||
217 | 256 | | |||
257 | void TextInputInterface::done() | ||||
258 | { | ||||
259 | Q_D(); | ||||
260 | d->done(); | ||||
261 | } | ||||
262 | | ||||
218 | TextInputInterfaceVersion TextInputInterface::interfaceVersion() const | 263 | TextInputInterfaceVersion TextInputInterface::interfaceVersion() const | ||
219 | { | 264 | { | ||
220 | Q_D(); | 265 | Q_D(); | ||
221 | return d->interfaceVersion(); | 266 | return d->interfaceVersion(); | ||
222 | } | 267 | } | ||
223 | 268 | | |||
224 | QPointer<SurfaceInterface> TextInputInterface::surface() const | 269 | QPointer<SurfaceInterface> TextInputInterface::surface() const | ||
225 | { | 270 | { | ||
▲ Show 20 Lines • Show All 48 Lines • Show Last 20 Lines |