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