File indexing completed on 2024-05-19 16:35:32
0001 /* 0002 SPDX-FileCopyrightText: 2020 Bhushan Shah <bshah@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 #pragma once 0007 0008 #include "clientconnection.h" 0009 #include "textinput_v3_interface.h" 0010 0011 #include <QHash> 0012 #include <QPointer> 0013 #include <QRect> 0014 #include <QVector> 0015 0016 #include <qwayland-server-text-input-unstable-v3.h> 0017 0018 namespace KWaylandServer 0019 { 0020 class TextInputManagerV3InterfacePrivate : public QtWaylandServer::zwp_text_input_manager_v3 0021 { 0022 public: 0023 TextInputManagerV3InterfacePrivate(TextInputManagerV3Interface *_q, Display *display); 0024 0025 TextInputManagerV3Interface *q; 0026 0027 protected: 0028 void zwp_text_input_manager_v3_destroy(Resource *resource) override; 0029 void zwp_text_input_manager_v3_get_text_input(Resource *resource, uint32_t id, wl_resource *seat) override; 0030 }; 0031 0032 class TextInputV3InterfacePrivate : public QtWaylandServer::zwp_text_input_v3 0033 { 0034 public: 0035 TextInputV3InterfacePrivate(SeatInterface *seat, TextInputV3Interface *_q); 0036 0037 // events 0038 void sendEnter(SurfaceInterface *surface); 0039 void sendLeave(SurfaceInterface *surface); 0040 void sendPreEdit(const QString &text, const quint32 cursorBegin, const quint32 cursorEnd); 0041 void commitString(const QString &text); 0042 void deleteSurroundingText(quint32 beforeLength, quint32 afterLength); 0043 void done(); 0044 0045 bool isEnabled() const; 0046 QList<TextInputV3InterfacePrivate::Resource *> textInputsForClient(ClientConnection *client) const; 0047 QList<TextInputV3InterfacePrivate::Resource *> enabledTextInputsForClient(ClientConnection *client) const; 0048 0049 static TextInputV3InterfacePrivate *get(TextInputV3Interface *inputInterface) 0050 { 0051 return inputInterface->d.get(); 0052 } 0053 0054 QRect cursorRectangle; 0055 TextInputContentHints contentHints = TextInputContentHint::None; 0056 TextInputContentPurpose contentPurpose = TextInputContentPurpose::Normal; 0057 0058 SeatInterface *seat = nullptr; 0059 QPointer<SurfaceInterface> surface; 0060 0061 QString surroundingText; 0062 qint32 surroundingTextCursorPosition = 0; 0063 qint32 surroundingTextSelectionAnchor = 0; 0064 TextInputChangeCause surroundingTextChangeCause = TextInputChangeCause::InputMethod; 0065 0066 QString preeditText; 0067 quint32 preeditCursorBegin = 0; 0068 quint32 preeditCursorEnd = 0; 0069 0070 struct 0071 { 0072 QRect cursorRectangle; 0073 TextInputChangeCause surroundingTextChangeCause = TextInputChangeCause::InputMethod; 0074 TextInputContentHints contentHints = TextInputContentHint::None; 0075 TextInputContentPurpose contentPurpose = TextInputContentPurpose::Normal; 0076 bool enabled = false; 0077 QString surroundingText; 0078 qint32 surroundingTextCursorPosition = 0; 0079 qint32 surroundingTextSelectionAnchor = 0; 0080 QString preeditText; 0081 quint32 preeditCursorBegin = 0; 0082 quint32 preeditCursorEnd = 0; 0083 } pending; 0084 0085 QHash<Resource *, quint32> serialHash; 0086 QHash<Resource *, bool> enabled; 0087 0088 void defaultPending(); 0089 void defaultPendingPreedit(); 0090 0091 TextInputV3Interface *q; 0092 0093 protected: 0094 void zwp_text_input_v3_bind_resource(Resource *resource) override; 0095 void zwp_text_input_v3_destroy(Resource *resource) override; 0096 // requests 0097 void zwp_text_input_v3_enable(Resource *resource) override; 0098 void zwp_text_input_v3_disable(Resource *resource) override; 0099 void zwp_text_input_v3_set_surrounding_text(Resource *resource, const QString &text, int32_t cursor, int32_t anchor) override; 0100 void zwp_text_input_v3_set_content_type(Resource *resource, uint32_t hint, uint32_t purpose) override; 0101 void zwp_text_input_v3_set_text_change_cause(Resource *resource, uint32_t cause) override; 0102 void zwp_text_input_v3_set_cursor_rectangle(Resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) override; 0103 void zwp_text_input_v3_commit(Resource *resource) override; 0104 }; 0105 0106 }