File indexing completed on 2025-01-19 13:54:33
0001 /* 0002 SPDX-FileCopyrightText: 2018 Roman Glig <subdiff@gmail.com> 0003 SPDX-FileCopyrightText: 2020 Bhushan Shah <bshah@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0006 */ 0007 #pragma once 0008 0009 #include <QObject> 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 TextInputV3Interface; 0021 class TextInputV3InterfacePrivate; 0022 class TextInputManagerV3InterfacePrivate; 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 TextInputManagerV3Interface use {@link Display::createTextInputManager} 0031 */ 0032 class KWIN_EXPORT TextInputManagerV3Interface : public QObject 0033 { 0034 Q_OBJECT 0035 public: 0036 explicit TextInputManagerV3Interface(Display *display, QObject *parent = nullptr); 0037 ~TextInputManagerV3Interface() override; 0038 0039 private: 0040 std::unique_ptr<TextInputManagerV3InterfacePrivate> d; 0041 }; 0042 0043 /** 0044 * @brief Represents a generic Resource for a text input object. 0045 * * 0046 * A TextInputV3Interface gets created by the {@link TextInputManagerV3Interface}. The individual 0047 * instances are not exposed directly. The SeatInterface provides access to the currently active 0048 * TextInputV3Interface. This is evaluated automatically based on which SurfaceInterface has 0049 * keyboard focus. 0050 * 0051 * @see TextInputManagerV3Interface 0052 * @see SeatInterface 0053 */ 0054 class KWIN_EXPORT TextInputV3Interface : public QObject 0055 { 0056 Q_OBJECT 0057 public: 0058 ~TextInputV3Interface() override; 0059 0060 /** 0061 * @see cursorRectangleChanged 0062 */ 0063 QRect cursorRectangle() const; 0064 0065 /** 0066 * @see contentTypeChanged 0067 */ 0068 TextInputContentPurpose contentPurpose() const; 0069 0070 /** 0071 *@see contentTypeChanged 0072 */ 0073 TextInputContentHints contentHints() const; 0074 0075 /** 0076 * @returns The plain surrounding text around the input position. 0077 * @see surroundingTextChanged 0078 * @see surroundingTextCursorPosition 0079 * @see surroundingTextSelectionAnchor 0080 */ 0081 QString surroundingText() const; 0082 /** 0083 * @returns The byte offset of current cursor position within the {@link surroundingText} 0084 * @see surroundingText 0085 * @see surroundingTextChanged 0086 */ 0087 qint32 surroundingTextCursorPosition() const; 0088 /** 0089 * The byte offset of the selection anchor within the {@link surroundingText}. 0090 * 0091 * If there is no selected text this is the same as cursor. 0092 * @return The byte offset of the selection anchor 0093 * @see surroundingText 0094 * @see surroundingTextChanged 0095 */ 0096 qint32 surroundingTextSelectionAnchor() const; 0097 0098 /** 0099 * @return The surface the TextInputV3Interface is enabled on 0100 * @see isEnabled 0101 * @see enabledChanged 0102 */ 0103 QPointer<SurfaceInterface> surface() const; 0104 0105 /** 0106 * @return Whether the TextInputV3Interface is currently enabled for a SurfaceInterface. 0107 * @see surface 0108 * @see enabledChanged 0109 */ 0110 bool isEnabled() const; 0111 0112 /** 0113 * Notify when the text around the current cursor position should be deleted. 0114 * 0115 * The Client processes this event together with the commit string 0116 * 0117 * @param beforeLength length of text before current cursor position. 0118 * @param afterLength length of text after current cursor position. 0119 * @see commit 0120 */ 0121 void deleteSurroundingText(quint32 beforeLength, quint32 afterLength); 0122 0123 /** 0124 * Send preEditString to the client 0125 * 0126 * @param text pre-edit string 0127 * @param cursorBegin 0128 * @param cursorEnd 0129 */ 0130 void sendPreEditString(const QString &text, quint32 cursorBegin, quint32 cursorEnd); 0131 0132 /** 0133 * Notify when @p text should be inserted into the editor widget. 0134 * The text to commit could be either just a single character after a key press or the 0135 * result of some composing ({@link preEdit}). It could be also an empty text 0136 * when some text should be removed (see {@link deleteSurroundingText}) or when 0137 * the input cursor should be moved (see {@link cursorPosition}). 0138 * 0139 * Any previously set composing text should be removed. 0140 * @param text The utf8-encoded text to be inserted into the editor widget 0141 * @see preEdit 0142 * @see deleteSurroundingText 0143 */ 0144 void commitString(const QString &text); 0145 0146 /** 0147 * Notify when changes and state requested by sendPreEditString, commitString and deleteSurroundingText 0148 * should be applied. 0149 */ 0150 void done(); 0151 0152 /** 0153 * @return whether @p client supports text-input-v3 0154 */ 0155 bool clientSupportsTextInput(ClientConnection *client) const; 0156 0157 Q_SIGNALS: 0158 0159 /** 0160 * @see cursorRectangle 0161 */ 0162 void cursorRectangleChanged(const QRect &rect); 0163 /** 0164 * Emitted when the {@link contentPurpose} and/or {@link contentHints} changes. 0165 * @see contentPurpose 0166 * @see contentHints 0167 */ 0168 void contentTypeChanged(); 0169 0170 /** 0171 * Emitted when the {@link surroundingText}, {@link surroundingTextCursorPosition} 0172 * and/or {@link surroundingTextSelectionAnchor} changed. 0173 * @see surroundingText 0174 * @see surroundingTextCursorPosition 0175 * @see surroundingTextSelectionAnchor 0176 */ 0177 void surroundingTextChanged(); 0178 0179 /** 0180 * Emitted whenever this TextInputV3Interface gets enabled or disabled for a SurfaceInterface. 0181 * @see isEnabled 0182 * @see surface 0183 */ 0184 void enabledChanged(); 0185 0186 /** 0187 * Emitted when state should be committed 0188 */ 0189 void stateCommitted(quint32 serial); 0190 0191 /** 0192 * Emitted whenever this TextInputV3Interface is already enabled, but received another enable from client. 0193 * @see isEnabled 0194 * @see surface 0195 */ 0196 void enableRequested(); 0197 0198 private: 0199 friend class TextInputManagerV3InterfacePrivate; 0200 friend class SeatInterface; 0201 friend class SeatInterfacePrivate; 0202 friend class TextInputV3InterfacePrivate; 0203 explicit TextInputV3Interface(SeatInterface *seat); 0204 0205 std::unique_ptr<TextInputV3InterfacePrivate> d; 0206 }; 0207 0208 } 0209 0210 Q_DECLARE_METATYPE(KWaylandServer::TextInputV3Interface *)