File indexing completed on 2025-01-19 13:54:33
0001 /* 0002 SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@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 <QObject> 0009 #include <memory> 0010 0011 #include "textinput.h" 0012 0013 struct wl_resource; 0014 namespace KWaylandServer 0015 { 0016 class ClientConnection; 0017 class Display; 0018 class SeatInterface; 0019 class SurfaceInterface; 0020 class TextInputV2Interface; 0021 class TextInputV2InterfacePrivate; 0022 class TextInputManagerV2InterfacePrivate; 0023 0024 /** 0025 * @brief Represent the Global for the interface. 0026 * 0027 * The class can represent different interfaces. Which concrete interface is represented 0028 * can be determined through {@link interfaceVersion}. 0029 * 0030 * To create a TextInputManagerV2Interface use {@link Display::createTextInputManager} 0031 */ 0032 class KWIN_EXPORT TextInputManagerV2Interface : public QObject 0033 { 0034 Q_OBJECT 0035 public: 0036 explicit TextInputManagerV2Interface(Display *display, QObject *parent = nullptr); 0037 ~TextInputManagerV2Interface() override; 0038 0039 private: 0040 std::unique_ptr<TextInputManagerV2InterfacePrivate> d; 0041 }; 0042 0043 /** 0044 * @brief Represents a generic Resource for a text input object. 0045 * 0046 * This class does not directly correspond to a Wayland resource, but is a generic contract 0047 * for any interface which implements a text input, e.g. the unstable wl_text_input interface. 0048 * 0049 * It does not expose the actual interface to cover up the fact that the interface is unstable 0050 * and might change. If one needs to know the actual used protocol, use the method {@link interfaceVersion}. 0051 * 0052 * A TextInputV2Interface gets created by the {@link TextInputManagerV2Interface}. The individual 0053 * instances are not exposed directly. The SeatInterface provides access to the currently active 0054 * TextInputV2Interface. This is evaluated automatically based on which SurfaceInterface has 0055 * keyboard focus. 0056 * 0057 * @see TextInputManagerV2Interface 0058 * @see SeatInterface 0059 */ 0060 class KWIN_EXPORT TextInputV2Interface : public QObject 0061 { 0062 Q_OBJECT 0063 public: 0064 ~TextInputV2Interface() override; 0065 0066 enum class UpdateReason : uint32_t { 0067 StateChange = 0, // updated state because it changed 0068 StateFull = 1, // full state after enter or input_method_changed event 0069 StateReset = 2, // full state after reset 0070 StateEnter = 3, // full state after switching focus to a different widget on client side 0071 }; 0072 Q_ENUM(UpdateReason) 0073 /** 0074 * The preferred language as a RFC-3066 format language tag. 0075 * 0076 * This can be used by the server to show a language specific virtual keyboard layout. 0077 * @see preferredLanguageChanged 0078 */ 0079 QString preferredLanguage() const; 0080 0081 /** 0082 * @see cursorRectangleChanged 0083 */ 0084 QRect cursorRectangle() const; 0085 0086 /** 0087 * @see contentTypeChanged 0088 */ 0089 TextInputContentPurpose contentPurpose() const; 0090 0091 /** 0092 *@see contentTypeChanged 0093 */ 0094 TextInputContentHints contentHints() const; 0095 0096 /** 0097 * @returns The plain surrounding text around the input position. 0098 * @see surroundingTextChanged 0099 * @see surroundingTextCursorPosition 0100 * @see surroundingTextSelectionAnchor 0101 */ 0102 QString surroundingText() const; 0103 /** 0104 * @returns The byte offset of current cursor position within the {@link surroundingText} 0105 * @see surroundingText 0106 * @see surroundingTextChanged 0107 */ 0108 qint32 surroundingTextCursorPosition() const; 0109 /** 0110 * The byte offset of the selection anchor within the {@link surroundingText}. 0111 * 0112 * If there is no selected text this is the same as cursor. 0113 * @return The byte offset of the selection anchor 0114 * @see surroundingText 0115 * @see surroundingTextChanged 0116 */ 0117 qint32 surroundingTextSelectionAnchor() const; 0118 0119 /** 0120 * @return The surface the TextInputV2Interface is enabled on 0121 * @see isEnabled 0122 * @see enabledChanged 0123 */ 0124 QPointer<SurfaceInterface> surface() const; 0125 0126 /** 0127 * @return whether @p client supports text-input-v2 0128 */ 0129 bool clientSupportsTextInput(ClientConnection *client) const; 0130 0131 /** 0132 * @return Whether the TextInputV2Interface is currently enabled for a SurfaceInterface. 0133 * @see surface 0134 * @see enabledChanged 0135 */ 0136 bool isEnabled() const; 0137 0138 /** 0139 * Notify when a new composing @p text (pre-edit) should be set around the 0140 * current cursor position. Any previously set composing text should 0141 * be removed. 0142 * 0143 * The @p commitText can be used to replace the preedit text on reset 0144 * (for example on unfocus). 0145 * 0146 * @param text The new utf8-encoded pre-edit text 0147 * @param commitText Utf8-encoded text to replace preedit text on reset 0148 * @see commit 0149 * @see preEditCursor 0150 */ 0151 void preEdit(const QString &text, const QString &commitText); 0152 0153 /** 0154 * Notify when @p text should be inserted into the editor widget. 0155 * The text to commit could be either just a single character after a key press or the 0156 * result of some composing ({@link preEdit}). It could be also an empty text 0157 * when some text should be removed (see {@link deleteSurroundingText}) or when 0158 * the input cursor should be moved (see {@link cursorPosition}). 0159 * 0160 * Any previously set composing text should be removed. 0161 * @param text The utf8-encoded text to be inserted into the editor widget 0162 * @see preEdit 0163 * @see deleteSurroundingText 0164 */ 0165 void commitString(const QString &text); 0166 0167 /** 0168 * Sets the cursor position inside the composing text (as byte offset) relative to the 0169 * start of the composing text. When @p index is a negative number no cursor is shown. 0170 * 0171 * The Client applies the @p index together with {@link preEdit}. 0172 * @param index The cursor position relative to the start of the composing text 0173 * @see preEdit 0174 */ 0175 void setPreEditCursor(qint32 index); 0176 0177 /** 0178 * Sets the style for a range of text for the composing text (as byte offset). 0179 * 0180 * The Client applies the @p index together with {@link preEdit}. 0181 * @param index The position relative to the start of the composing text 0182 * @param length The length of the style to apply on 0183 * @param style style flag 0184 * @see preEdit 0185 */ 0186 void preEditStyling(uint32_t index, uint32_t length, uint32_t style); 0187 0188 /** 0189 * Notify when the text around the current cursor position should be deleted. 0190 * 0191 * The Client processes this event together with the commit string 0192 * 0193 * @param beforeLength length of text before current cursor position. 0194 * @param afterLength length of text after current cursor position. 0195 * @see commit 0196 */ 0197 void deleteSurroundingText(quint32 beforeLength, quint32 afterLength); 0198 0199 /** 0200 * Notify when the cursor @p index or @p anchor position should be modified. 0201 * 0202 * The Client applies this together with the commit string. 0203 */ 0204 void setCursorPosition(qint32 index, qint32 anchor); 0205 0206 /** 0207 * Sets the text @p direction of input text. 0208 */ 0209 void setTextDirection(Qt::LayoutDirection direction); 0210 0211 void keysymPressed(quint32 keysym, quint32 modifiers = 0); 0212 void keysymReleased(quint32 keysym, quint32 modifiers = 0); 0213 0214 /** 0215 * Informs the client about changes in the visibility of the input panel (virtual keyboard). 0216 * 0217 * The @p overlappedSurfaceArea defines the area overlapped by the input panel (virtual keyboard) 0218 * on the SurfaceInterface having the text focus in surface local coordinates. 0219 * 0220 * @param visible Whether the input panel is currently visible 0221 * @param overlappedSurfaceArea The overlapping area in surface local coordinates 0222 */ 0223 void setInputPanelState(bool visible, const QRect &overlappedSurfaceArea); 0224 0225 /** 0226 * Sets the language of the input text. The @p languageTag is a RFC-3066 format language tag. 0227 */ 0228 void setLanguage(const QString &languageTag); 0229 0230 /** 0231 * Sets the modifiers map to use when modifiers are included in a key event. 0232 */ 0233 void setModifiersMap(const QByteArray &modifiersMap); 0234 0235 Q_SIGNALS: 0236 /** 0237 * Requests input panels (virtual keyboard) to show. 0238 * @see requestHideInputPanel 0239 */ 0240 void requestShowInputPanel(); 0241 /** 0242 * Requests input panels (virtual keyboard) to hide. 0243 * @see requestShowInputPanel 0244 */ 0245 void requestHideInputPanel(); 0246 /** 0247 * Emitted whenever the preferred @p language changes. 0248 * @see preferredLanguage 0249 */ 0250 void preferredLanguageChanged(const QString &language); 0251 /** 0252 * @see cursorRectangle 0253 */ 0254 void cursorRectangleChanged(const QRect &rect); 0255 /** 0256 * Emitted when the {@link contentPurpose} and/or {@link contentHints} changes. 0257 * @see contentPurpose 0258 * @see contentHints 0259 */ 0260 void contentTypeChanged(); 0261 /** 0262 * Emitted when the {@link surroundingText}, {@link surroundingTextCursorPosition} 0263 * and/or {@link surroundingTextSelectionAnchor} changed. 0264 * @see surroundingText 0265 * @see surroundingTextCursorPosition 0266 * @see surroundingTextSelectionAnchor 0267 */ 0268 void surroundingTextChanged(); 0269 /** 0270 * Emitted whenever this TextInputV2Interface gets enabled or disabled for a SurfaceInterface. 0271 * @see isEnabled 0272 * @see surface 0273 */ 0274 void enabledChanged(); 0275 /** 0276 * Emitted whenever TextInputInterface should update the current state. 0277 */ 0278 void stateUpdated(uint32_t serial, UpdateReason reason); 0279 0280 private: 0281 friend class TextInputManagerV2InterfacePrivate; 0282 friend class SeatInterface; 0283 friend class SeatInterfacePrivate; 0284 friend class TextInputV2InterfacePrivate; 0285 explicit TextInputV2Interface(SeatInterface *seat); 0286 0287 std::unique_ptr<TextInputV2InterfacePrivate> d; 0288 }; 0289 0290 } 0291 0292 Q_DECLARE_METATYPE(KWaylandServer::TextInputV2Interface *) 0293 Q_DECLARE_METATYPE(KWaylandServer::TextInputV2Interface::UpdateReason)