17const quint32 s_version = 1;
19TextInputContentHints convertContentHint(uint32_t hint)
21 const auto hints = QtWaylandServer::zwp_text_input_v3::content_hint(hint);
24 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_completion) {
27 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_auto_capitalization) {
30 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_lowercase) {
33 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_uppercase) {
36 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_titlecase) {
39 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_hidden_text) {
42 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_sensitive_data) {
45 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_latin) {
48 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_multiline) {
51 if (hints & QtWaylandServer::zwp_text_input_v3::content_hint_spellcheck) {
59 const auto wlPurpose = QtWaylandServer::zwp_text_input_v3::content_purpose(purpose);
62 case QtWaylandServer::zwp_text_input_v3::content_purpose_alpha:
64 case QtWaylandServer::zwp_text_input_v3::content_purpose_digits:
66 case QtWaylandServer::zwp_text_input_v3::content_purpose_number:
68 case QtWaylandServer::zwp_text_input_v3::content_purpose_phone:
70 case QtWaylandServer::zwp_text_input_v3::content_purpose_url:
72 case QtWaylandServer::zwp_text_input_v3::content_purpose_email:
74 case QtWaylandServer::zwp_text_input_v3::content_purpose_name:
76 case QtWaylandServer::zwp_text_input_v3::content_purpose_password:
78 case QtWaylandServer::zwp_text_input_v3::content_purpose_pin:
80 case QtWaylandServer::zwp_text_input_v3::content_purpose_date:
82 case QtWaylandServer::zwp_text_input_v3::content_purpose_time:
84 case QtWaylandServer::zwp_text_input_v3::content_purpose_datetime:
86 case QtWaylandServer::zwp_text_input_v3::content_purpose_terminal:
88 case QtWaylandServer::zwp_text_input_v3::content_purpose_normal:
97 const auto wlCause = QtWaylandServer::zwp_text_input_v3::change_cause(cause);
99 case QtWaylandServer::zwp_text_input_v3::change_cause_input_method:
101 case QtWaylandServer::zwp_text_input_v3::change_cause_other:
109 : QtWaylandServer::zwp_text_input_manager_v3(*display, s_version)
116 wl_resource_destroy(resource->handle);
123 wl_resource_post_error(resource->handle, 0,
"Invalid seat");
127 auto *textInputResource = textInputPrivate->add(resource->client(),
id, resource->version());
129 if (textInputPrivate->
surface && textInputPrivate->
surface->client()->client() == resource->client()) {
130 textInputPrivate->send_enter(textInputResource->handle, textInputPrivate->
surface->resource());
165 wl_resource_destroy(resource->handle);
171 Q_ASSERT(!
surface && newSurface);
174 for (
auto resource : clientResources) {
175 send_enter(resource->handle, newSurface->
resource());
183 Q_ASSERT(leavingSurface &&
surface == leavingSurface);
186 for (
auto resource : clientResources) {
187 send_leave(resource->handle, leavingSurface->
resource());
199 pending.preeditCursorBegin = cursorBegin;
200 pending.preeditCursorEnd = cursorEnd;
203 for (
auto resource : textInputs) {
204 send_preedit_string(resource->handle, text, cursorBegin, cursorEnd);
214 for (
auto resource : textInputs) {
215 send_commit_string(resource->handle, text);
225 for (
auto resource : textInputs) {
226 send_delete_surrounding_text(resource->handle, before, after);
242 for (
auto resource : textInputs) {
244 send_done(resource->handle,
serialHash[resource]);
250 return resourceMap().values(client->
client());
255 QList<TextInputV3InterfacePrivate::Resource *> result;
256 const auto [start, end] = resourceMap().equal_range(client->
client());
257 for (
auto it = start; it != end; ++it) {
267 bool newEnabled =
false;
270 newEnabled = std::any_of(clientResources.begin(), clientResources.end(), [
this](Resource *resource) {
271 return enabledHash[resource];
303 pending.surroundingText = text;
304 pending.surroundingTextCursorPosition = cursor;
305 pending.surroundingTextSelectionAnchor = anchor;
314 pending.contentHints = convertContentHint(hint);
315 pending.contentPurpose = convertContentPurpose(purpose);
324 pending.cursorRectangle = QRect(x, y, width, height);
333 pending.surroundingTextChangeCause = convertChangeCause(cause);
341 const auto oldResourceEnabled = resourceEnabled;
342 if (resourceEnabled !=
pending.enabled) {
343 resourceEnabled =
pending.enabled;
354 if (resourceEnabled) {
361 if (resourceEnabled) {
371 if (resourceEnabled) {
384 send_done(resource->handle,
serialHash[resource]);
386 if (resourceEnabled && oldResourceEnabled) {
395 pending.cursorRectangle = QRect();
400 pending.surroundingText = QString();
401 pending.surroundingTextCursorPosition = 0;
402 pending.surroundingTextSelectionAnchor = 0;
408 pending.preeditText = QString();
409 pending.preeditCursorBegin = 0;
413TextInputV3Interface::TextInputV3Interface(
SeatInterface *seat)
423 return d->contentHints;
428 return d->contentPurpose;
433 return d->surroundingText;
438 return d->surroundingTextCursorPosition;
443 return d->surroundingTextSelectionAnchor;
448 d->deleteSurroundingText(beforeLength, afterLength);
453 d->sendPreEdit(text, cursorBegin, cursorEnd);
458 d->commitString(text);
472 if (!d->resourceMap().contains(d->surface->client()->client())) {
481 return d->cursorRectangle;
491 return client && d->resourceMap().contains(*client);
495#include "moc_textinput_v3.cpp"
Convenient Class which represents a wl_client.
wl_client * client() const
Class holding the Wayland server display loop.
Represents a Seat on the Wayland Display.
static SeatInterface * get(wl_resource *native)
TextInputV3Interface * textInputV3() const
Resource representing a wl_surface.
ClientConnection * client() const
wl_resource * resource() const
Represent the Global for the interface.
~TextInputManagerV3Interface() override
TextInputManagerV3Interface(Display *display, QObject *parent=nullptr)
void zwp_text_input_manager_v3_get_text_input(Resource *resource, uint32_t id, wl_resource *seat) override
TextInputManagerV3InterfacePrivate(TextInputManagerV3Interface *_q, Display *display)
void zwp_text_input_manager_v3_destroy(Resource *resource) override
Represents a generic Resource for a text input object.A TextInputV3Interface gets created by the Text...
void stateCommitted(quint32 serial)
~TextInputV3Interface() override
void deleteSurroundingText(quint32 beforeLength, quint32 afterLength)
QRect cursorRectangle() const
void cursorRectangleChanged(const QRect &rect)
TextInputContentPurpose contentPurpose() const
void surroundingTextChanged()
bool clientSupportsTextInput(ClientConnection *client) const
QPointer< SurfaceInterface > surface() const
qint32 surroundingTextSelectionAnchor() const
void commitString(const QString &text)
QString surroundingText() const
qint32 surroundingTextCursorPosition() const
TextInputContentHints contentHints() const
void contentTypeChanged()
void sendPreEditString(const QString &text, quint32 cursorBegin, quint32 cursorEnd)
QList< TextInputV3InterfacePrivate::Resource * > enabledTextInputsForClient(ClientConnection *client) const
QList< TextInputV3InterfacePrivate::Resource * > textInputsForClient(ClientConnection *client) const
void zwp_text_input_v3_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) override
void deleteSurroundingText(quint32 beforeLength, quint32 afterLength)
void zwp_text_input_v3_commit(Resource *resource) override
TextInputContentPurpose contentPurpose
QHash< Resource *, bool > enabledHash
void zwp_text_input_v3_disable(Resource *resource) override
void commitString(const QString &text)
void sendLeave(SurfaceInterface *surface)
quint32 preeditCursorBegin
TextInputV3InterfacePrivate(SeatInterface *seat, TextInputV3Interface *_q)
void zwp_text_input_v3_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override
void zwp_text_input_v3_destroy_resource(Resource *resource) override
void sendPreEdit(const QString &text, const quint32 cursorBegin, const quint32 cursorEnd)
void sendEnter(SurfaceInterface *surface)
void defaultPendingPreedit()
void zwp_text_input_v3_enable(Resource *resource) override
static TextInputV3InterfacePrivate * get(TextInputV3Interface *inputInterface)
QHash< Resource *, quint32 > serialHash
struct KWin::TextInputV3InterfacePrivate::@31 pending
qint32 surroundingTextCursorPosition
void zwp_text_input_v3_destroy(Resource *resource) override
TextInputContentHints contentHints
void zwp_text_input_v3_set_text_change_cause(Resource *resource, uint32_t cause) override
QPointer< SurfaceInterface > surface
qint32 surroundingTextSelectionAnchor
void zwp_text_input_v3_bind_resource(Resource *resource) override
void zwp_text_input_v3_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override
TextInputChangeCause surroundingTextChangeCause