| 1 | /* |
| 2 | SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org> |
| 3 | |
| 4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 5 | */ |
| 6 | #ifndef KWAYLAND_CLIENT_TEXTINPUT_P_H |
| 7 | #define KWAYLAND_CLIENT_TEXTINPUT_P_H |
| 8 | #include "textinput.h" |
| 9 | |
| 10 | #include <QObject> |
| 11 | |
| 12 | struct wl_text_input; |
| 13 | struct wl_text_input_manager; |
| 14 | struct zwp_text_input_v2; |
| 15 | |
| 16 | namespace KWayland |
| 17 | { |
| 18 | namespace Client |
| 19 | { |
| 20 | class EventQueue; |
| 21 | class TextInputUnstableV0; |
| 22 | class Surface; |
| 23 | class Seat; |
| 24 | |
| 25 | class TextInputManagerUnstableV0 : public TextInputManager |
| 26 | { |
| 27 | Q_OBJECT |
| 28 | public: |
| 29 | /** |
| 30 | * Creates a new TextInputManagerUnstableV0. |
| 31 | * Note: after constructing the TextInputManagerUnstableV0 it is not yet valid and one needs |
| 32 | * to call setup. In order to get a ready to use TextInputManagerUnstableV0 prefer using |
| 33 | * Registry::createTextInputManagerUnstableV0. |
| 34 | **/ |
| 35 | explicit TextInputManagerUnstableV0(QObject *parent = nullptr); |
| 36 | ~TextInputManagerUnstableV0() override; |
| 37 | |
| 38 | private: |
| 39 | class Private; |
| 40 | Private *d_func() const; |
| 41 | }; |
| 42 | |
| 43 | class TextInputManagerUnstableV2 : public TextInputManager |
| 44 | { |
| 45 | Q_OBJECT |
| 46 | public: |
| 47 | /** |
| 48 | * Creates a new TextInputManagerUnstableV0. |
| 49 | * Note: after constructing the TextInputManagerUnstableV0 it is not yet valid and one needs |
| 50 | * to call setup. In order to get a ready to use TextInputManagerUnstableV0 prefer using |
| 51 | * Registry::createTextInputManagerUnstableV0. |
| 52 | **/ |
| 53 | explicit TextInputManagerUnstableV2(QObject *parent = nullptr); |
| 54 | ~TextInputManagerUnstableV2() override; |
| 55 | |
| 56 | private: |
| 57 | class Private; |
| 58 | QScopedPointer<Private> d; |
| 59 | }; |
| 60 | |
| 61 | class Q_DECL_HIDDEN TextInputManager::Private |
| 62 | { |
| 63 | public: |
| 64 | Private() = default; |
| 65 | virtual ~Private() = default; |
| 66 | |
| 67 | virtual void release() = 0; |
| 68 | virtual void destroy() = 0; |
| 69 | virtual bool isValid() = 0; |
| 70 | virtual void setupV0(wl_text_input_manager *textinputmanagerunstablev0) |
| 71 | { |
| 72 | Q_UNUSED(textinputmanagerunstablev0) |
| 73 | } |
| 74 | virtual void setupV2(zwp_text_input_manager_v2 *textinputmanagerunstablev2) |
| 75 | { |
| 76 | Q_UNUSED(textinputmanagerunstablev2) |
| 77 | } |
| 78 | virtual TextInput *createTextInput(Seat *seat, QObject *parent = nullptr) = 0; |
| 79 | virtual operator wl_text_input_manager *() |
| 80 | { |
| 81 | return nullptr; |
| 82 | } |
| 83 | virtual operator wl_text_input_manager *() const |
| 84 | { |
| 85 | return nullptr; |
| 86 | } |
| 87 | virtual operator zwp_text_input_manager_v2 *() |
| 88 | { |
| 89 | return nullptr; |
| 90 | } |
| 91 | virtual operator zwp_text_input_manager_v2 *() const |
| 92 | { |
| 93 | return nullptr; |
| 94 | } |
| 95 | |
| 96 | EventQueue *queue = nullptr; |
| 97 | }; |
| 98 | |
| 99 | class Q_DECL_HIDDEN TextInput::Private |
| 100 | { |
| 101 | public: |
| 102 | Private(Seat *seat); |
| 103 | virtual ~Private() = default; |
| 104 | |
| 105 | virtual bool isValid() const = 0; |
| 106 | virtual void enable(Surface *surface) = 0; |
| 107 | virtual void disable(Surface *surface) = 0; |
| 108 | virtual void showInputPanel() = 0; |
| 109 | virtual void hideInputPanel() = 0; |
| 110 | virtual void setCursorRectangle(const QRect &rect) = 0; |
| 111 | virtual void setPreferredLanguage(const QString &lang) = 0; |
| 112 | virtual void setSurroundingText(const QString &text, quint32 cursor, quint32 anchor) = 0; |
| 113 | virtual void reset() = 0; |
| 114 | virtual void setContentType(ContentHints hint, ContentPurpose purpose) = 0; |
| 115 | |
| 116 | EventQueue *queue = nullptr; |
| 117 | Seat *seat; |
| 118 | Surface *enteredSurface = nullptr; |
| 119 | quint32 latestSerial = 0; |
| 120 | bool inputPanelVisible = false; |
| 121 | Qt::LayoutDirection textDirection = Qt::LayoutDirectionAuto; |
| 122 | QByteArray language; |
| 123 | |
| 124 | struct PreEdit { |
| 125 | QByteArray text; |
| 126 | QByteArray commitText; |
| 127 | qint32 cursor = 0; |
| 128 | bool cursorSet = false; |
| 129 | }; |
| 130 | PreEdit currentPreEdit; |
| 131 | PreEdit pendingPreEdit; |
| 132 | |
| 133 | struct Commit { |
| 134 | QByteArray text; |
| 135 | qint32 cursor = 0; |
| 136 | qint32 anchor = 0; |
| 137 | DeleteSurroundingText deleteSurrounding; |
| 138 | }; |
| 139 | Commit currentCommit; |
| 140 | Commit pendingCommit; |
| 141 | }; |
| 142 | |
| 143 | class TextInputUnstableV0 : public TextInput |
| 144 | { |
| 145 | Q_OBJECT |
| 146 | public: |
| 147 | explicit TextInputUnstableV0(Seat *seat, QObject *parent = nullptr); |
| 148 | ~TextInputUnstableV0() override; |
| 149 | |
| 150 | /** |
| 151 | * Setup this TextInputUnstableV0 to manage the @p textinputunstablev0. |
| 152 | * When using TextInputManagerUnstableV0::createTextInputUnstableV0 there is no need to call this |
| 153 | * method. |
| 154 | **/ |
| 155 | void setup(wl_text_input *textinputunstablev0); |
| 156 | /** |
| 157 | * Releases the wl_text_input interface. |
| 158 | * After the interface has been released the TextInputUnstableV0 instance is no |
| 159 | * longer valid and can be setup with another wl_text_input interface. |
| 160 | **/ |
| 161 | void release(); |
| 162 | /** |
| 163 | * Destroys the data held by this TextInputUnstableV0. |
| 164 | * This method is supposed to be used when the connection to the Wayland |
| 165 | * server goes away. If the connection is not valid anymore, it's not |
| 166 | * possible to call release anymore as that calls into the Wayland |
| 167 | * connection and the call would fail. This method cleans up the data, so |
| 168 | * that the instance can be deleted or set up to a new wl_text_input interface |
| 169 | * once there is a new connection available. |
| 170 | * |
| 171 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 172 | * @code |
| 173 | * connect(connection, &ConnectionThread::connectionDied, textinputunstablev0, &TextInputUnstableV0::destroy); |
| 174 | * @endcode |
| 175 | * |
| 176 | * @see release |
| 177 | **/ |
| 178 | void destroy(); |
| 179 | |
| 180 | operator wl_text_input *(); |
| 181 | operator wl_text_input *() const; |
| 182 | |
| 183 | private: |
| 184 | class Private; |
| 185 | Private *d_func() const; |
| 186 | }; |
| 187 | |
| 188 | class TextInputUnstableV2 : public TextInput |
| 189 | { |
| 190 | Q_OBJECT |
| 191 | public: |
| 192 | explicit TextInputUnstableV2(Seat *seat, QObject *parent = nullptr); |
| 193 | ~TextInputUnstableV2() override; |
| 194 | |
| 195 | /** |
| 196 | * Setup this TextInputUnstableV2 to manage the @p textinputunstablev2. |
| 197 | * When using TextInputManagerUnstableV2::createTextInputUnstableV2 there is no need to call this |
| 198 | * method. |
| 199 | **/ |
| 200 | void setup(zwp_text_input_v2 *textinputunstablev2); |
| 201 | /** |
| 202 | * Releases the zwp_text_input_v2 interface. |
| 203 | * After the interface has been released the TextInputUnstableV2 instance is no |
| 204 | * longer valid and can be setup with another zwp_text_input_v2 interface. |
| 205 | **/ |
| 206 | void release(); |
| 207 | /** |
| 208 | * Destroys the data held by this TextInputUnstableV2. |
| 209 | * This method is supposed to be used when the connection to the Wayland |
| 210 | * server goes away. If the connection is not valid anymore, it's not |
| 211 | * possible to call release anymore as that calls into the Wayland |
| 212 | * connection and the call would fail. This method cleans up the data, so |
| 213 | * that the instance can be deleted or set up to a new zwp_text_input_v2 interface |
| 214 | * once there is a new connection available. |
| 215 | * |
| 216 | * It is suggested to connect this method to ConnectionThread::connectionDied: |
| 217 | * @code |
| 218 | * connect(connection, &ConnectionThread::connectionDied, textinputunstablev2, &TextInputUnstableV2::destroy); |
| 219 | * @endcode |
| 220 | * |
| 221 | * @see release |
| 222 | **/ |
| 223 | void destroy(); |
| 224 | |
| 225 | operator zwp_text_input_v2 *(); |
| 226 | operator zwp_text_input_v2 *() const; |
| 227 | |
| 228 | private: |
| 229 | class Private; |
| 230 | Private *d_func() const; |
| 231 | }; |
| 232 | |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | #endif |
| 237 | |