16const quint32 s_version = 1;
19TextInputContentHints convertContentHint(uint32_t hint)
21 const auto hints = QtWaylandServer::zwp_text_input_v2::content_hint(hint);
24 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_auto_completion) {
27 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_auto_correction) {
30 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_auto_capitalization) {
33 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_lowercase) {
36 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_uppercase) {
39 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_titlecase) {
42 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_hidden_text) {
45 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_sensitive_data) {
48 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_latin) {
51 if (hints & QtWaylandServer::zwp_text_input_v2::content_hint_multiline) {
59 const auto wlPurpose = QtWaylandServer::zwp_text_input_v2::content_purpose(purpose);
62 case QtWaylandServer::zwp_text_input_v2::content_purpose_alpha:
64 case QtWaylandServer::zwp_text_input_v2::content_purpose_digits:
66 case QtWaylandServer::zwp_text_input_v2::content_purpose_number:
68 case QtWaylandServer::zwp_text_input_v2::content_purpose_phone:
70 case QtWaylandServer::zwp_text_input_v2::content_purpose_url:
72 case QtWaylandServer::zwp_text_input_v2::content_purpose_email:
74 case QtWaylandServer::zwp_text_input_v2::content_purpose_name:
76 case QtWaylandServer::zwp_text_input_v2::content_purpose_password:
78 case QtWaylandServer::zwp_text_input_v2::content_purpose_date:
80 case QtWaylandServer::zwp_text_input_v2::content_purpose_time:
82 case QtWaylandServer::zwp_text_input_v2::content_purpose_datetime:
84 case QtWaylandServer::zwp_text_input_v2::content_purpose_terminal:
86 case QtWaylandServer::zwp_text_input_v2::content_purpose_normal:
96 EnabledEmitter(TextInputV2Interface *q)
98 , m_wasEnabled(q->isEnabled())
103 if (m_wasEnabled != q->isEnabled()) {
104 Q_EMIT q->enabledChanged();
109 TextInputV2Interface *q;
110 const bool m_wasEnabled;
116 : QtWaylandServer::zwp_text_input_manager_v2(*display, s_version)
123 wl_resource_destroy(resource->handle);
130 wl_resource_post_error(resource->handle, 0,
"Invalid seat");
135 auto *textInputResource = textInputPrivate->add(resource->client(),
id, resource->version());
138 if (textInputPrivate->
surface && textInputPrivate->
surface->client()->client() == resource->client()) {
139 textInputPrivate->send_enter(textInputResource->handle, serial, textInputPrivate->
surface->resource());
153 EnabledEmitter emitter(
q);
155 Q_ASSERT(!
surface && newSurface);
158 for (
auto resource : clientResources) {
159 send_enter(resource->handle, serial, newSurface->
resource());
166 Q_ASSERT(leavingSurface &&
surface == leavingSurface);
167 EnabledEmitter emitter(
q);
170 for (
auto resource : clientResources) {
171 send_leave(resource->handle, serial, leavingSurface->
resource());
182 for (
auto resource : clientResources) {
183 send_preedit_string(resource->handle, text, commit);
194 for (
auto resource : clientResources) {
195 send_preedit_styling(resource->handle, index, length, style);
205 for (
auto resource : textInputs) {
206 send_commit_string(resource->handle, text);
217 for (
auto resource : textInputs) {
218 send_keysym(resource->handle,
seat ?
seat->
timestamp().count() : 0, keysym, WL_KEYBOARD_KEY_STATE_PRESSED, modifiers);
229 for (
auto resource : textInputs) {
230 send_keysym(resource->handle,
seat ?
seat->
timestamp().count() : 0, keysym, WL_KEYBOARD_KEY_STATE_RELEASED, modifiers);
240 for (
auto resource : textInputs) {
241 send_delete_surrounding_text(resource->handle, beforeLength, afterLength);
251 for (
auto resource : textInputs) {
252 send_cursor_position(resource->handle, index, anchor);
261 text_direction wlDirection;
263 case Qt::LeftToRight:
264 wlDirection = text_direction::text_direction_ltr;
266 case Qt::RightToLeft:
267 wlDirection = text_direction::text_direction_rtl;
269 case Qt::LayoutDirectionAuto:
270 wlDirection = text_direction::text_direction_auto;
277 for (
auto resource : textInputs) {
278 send_text_direction(resource->handle, wlDirection);
288 for (
auto resource : textInputs) {
289 send_preedit_cursor(resource->handle, index);
299 for (
auto resource : textInputs) {
300 send_input_panel_state(resource->handle,
301 inputPanelVisible ? ZWP_TEXT_INPUT_V2_INPUT_PANEL_VISIBILITY_VISIBLE : ZWP_TEXT_INPUT_V2_INPUT_PANEL_VISIBILITY_HIDDEN,
315 for (
auto resource : textInputs) {
316 send_language(resource->handle,
language);
326 for (
auto resource : textInputs) {
339 EnabledEmitter emitter(
q);
346 EnabledEmitter emitter(
q);
353 EnabledEmitter emitter(
q);
357 if (disabledSurface ==
surface) {
393 const QRect rect = QRect(x, y, width, height);
415 return resourceMap().values(client->
client());
418TextInputV2Interface::TextInputV2Interface(
SeatInterface *seat)
428 return d->preferredLanguage;
433 return d->contentHints;
438 return d->contentPurpose;
443 return d->surroundingText;
448 return d->surroundingTextCursorPosition;
453 return d->surroundingTextSelectionAnchor;
458 d->preEdit(text, commit);
463 d->preEditStyling(index, length, style);
468 d->commitString(text);
473 d->keysymPressed(keysym, modifiers);
478 d->keysymReleased(keysym, modifiers);
483 d->deleteSurroundingText(beforeLength, afterLength);
488 d->setCursorPosition(index, anchor);
493 d->setTextDirection(direction);
498 d->setPreEditCursor(index);
503 if (d->inputPanelVisible == visible && d->overlappedSurfaceArea == overlappedSurfaceArea) {
507 d->inputPanelVisible = visible;
508 d->overlappedSurfaceArea = overlappedSurfaceArea;
509 d->sendInputPanelState();
514 if (d->language == languageTag) {
518 d->language = languageTag;
524 if (d->modifiersMap == modifiersMap) {
528 d->modifiersMap = modifiersMap;
529 d->sendModifiersMap();
538 if (!d->resourceMap().contains(d->surface->client()->client())) {
547 return d->cursorRectangle;
552 return d->surface && d->m_enabledSurfaces.contains(d->surface);
557 return client && d->resourceMap().contains(*client);
561#include "moc_textinput_v2.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.
Display * display() const
static SeatInterface * get(wl_resource *native)
TextInputV2Interface * textInputV2() const
std::chrono::milliseconds timestamp() const
Resource representing a wl_surface.
ClientConnection * client() const
static SurfaceInterface * get(wl_resource *native)
void aboutToBeDestroyed()
wl_resource * resource() const
Represent the Global for the interface.
~TextInputManagerV2Interface() override
TextInputManagerV2Interface(Display *display, QObject *parent=nullptr)
void zwp_text_input_manager_v2_destroy(Resource *resource) override
TextInputManagerV2InterfacePrivate(TextInputManagerV2Interface *_q, Display *display)
void zwp_text_input_manager_v2_get_text_input(Resource *resource, uint32_t id, wl_resource *seat) override
Represents a generic Resource for a text input object.
void preEdit(const QString &text, const QString &commitText)
void setPreEditCursor(qint32 index)
void deleteSurroundingText(quint32 beforeLength, quint32 afterLength)
void setInputPanelState(bool visible, const QRect &overlappedSurfaceArea)
bool clientSupportsTextInput(ClientConnection *client) const
TextInputContentHints contentHints() const
qint32 surroundingTextCursorPosition() const
QRect cursorRectangle() const
void keysymPressed(quint32 keysym, quint32 modifiers=0)
~TextInputV2Interface() override
QString surroundingText() const
void setTextDirection(Qt::LayoutDirection direction)
void requestShowInputPanel()
void preEditStyling(uint32_t index, uint32_t length, uint32_t style)
void setCursorPosition(qint32 index, qint32 anchor)
QString preferredLanguage() const
void stateUpdated(uint32_t serial, UpdateReason reason)
void preferredLanguageChanged(const QString &language)
QPointer< SurfaceInterface > surface() const
TextInputContentPurpose contentPurpose() const
void commitString(const QString &text)
void requestHideInputPanel()
void setModifiersMap(const QByteArray &modifiersMap)
void cursorRectangleChanged(const QRect &rect)
void keysymReleased(quint32 keysym, quint32 modifiers=0)
void surroundingTextChanged()
void contentTypeChanged()
qint32 surroundingTextSelectionAnchor() const
void setLanguage(const QString &languageTag)
void sendEnter(SurfaceInterface *surface, quint32 serial)
void zwp_text_input_v2_show_input_panel(Resource *resource) override
QString preferredLanguage
qint32 surroundingTextCursorPosition
void keysymReleased(quint32 keysym, quint32 modifiers)
void zwp_text_input_v2_disable(Resource *resource, wl_resource *surface) override
QSet< SurfaceInterface * > m_enabledSurfaces
QPointer< SurfaceInterface > surface
void sendInputPanelState()
void deleteSurroundingText(quint32 beforeLength, quint32 afterLength)
void preEditStyling(uint32_t index, uint32_t length, uint32_t style)
void setTextDirection(Qt::LayoutDirection direction)
void zwp_text_input_v2_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override
void zwp_text_input_v2_enable(Resource *resource, wl_resource *surface) override
QRect overlappedSurfaceArea
TextInputContentPurpose contentPurpose
void setPreEditCursor(qint32 index)
void preEdit(const QString &text, const QString &commit)
void zwp_text_input_v2_set_preferred_language(Resource *resource, const QString &language) override
void zwp_text_input_v2_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) override
void zwp_text_input_v2_update_state(Resource *resource, uint32_t serial, uint32_t reason) override
static TextInputV2InterfacePrivate * get(TextInputV2Interface *inputInterface)
void sendLeave(quint32 serial, SurfaceInterface *surface)
void keysymPressed(quint32 keysym, quint32 modifiers)
void setCursorPosition(qint32 index, qint32 anchor)
TextInputV2InterfacePrivate(SeatInterface *seat, TextInputV2Interface *_q)
QList< Resource * > textInputsForClient(ClientConnection *client) const
qint32 surroundingTextSelectionAnchor
void commitString(const QString &text)
void zwp_text_input_v2_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override
TextInputContentHints contentHints
void zwp_text_input_v2_hide_input_panel(Resource *resource) override