@@ -34,9 +34,11 @@ class KeyboardDirectionKey: public QObject {
3434 static Enum fromDirection (impl::DirectionKey direction);
3535};
3636
37+ // / Provides keyboard handling logic for an @@InputMethod$'s grab protocol.
38+ // / Use @@KeyboardTextEdit$ for a higher level and easier to use version.
3739class Keyboard : public QObject {
3840 Q_OBJECT;
39- // / The surface that will be created for the keyboard. Must create a @@KeyboardSurface$.
41+ // / TODO The surface that will be created for the keyboard. Must create a @@KeyboardSurface$.
4042 // Q_PROPERTY(QQmlComponent* surface READ surfaceComponent WRITE setSurfaceComponent NOTIFY surfaceComponentChanged);
4143 // Q_CLASSINFO("DefaultProperty", "surface");
4244 QML_ELEMENT;
@@ -49,6 +51,7 @@ class Keyboard: public QObject {
4951signals:
5052 void keyPress (QChar character);
5153 void returnPress ();
54+ // / Note that internally Quickshell will release the keyboard when escape is pressed.
5255 void escapePress ();
5356 void directionPress (KeyboardDirectionKey::Enum);
5457 void backspacePress ();
@@ -62,16 +65,36 @@ private slots:
6265 // QQmlComponent* mSurfaceComponent = nullptr;
6366};
6467
68+ // / Provides the ability to send text input to the compositor
69+ // /
70+ // / A simple example that sends text to the currently focused input method:
71+ // / ```
72+ // / QSInputMethod {
73+ // / id: input_method
74+ // / }
75+ // / IpcHandler {
76+ // / target: "input_method"
77+ // / function hi(): void { input_method.sendString("hi"); }
78+ // / }
79+ // / ```
80+ // / We can now call the ipc handler and see that `hi` is printed to the terminal input.
81+ // / `$ qs ipc call input_method hi`
6582class InputMethod : public QObject {
6683 Q_OBJECT;
84+ // / If a text input is focused
6785 Q_PROPERTY (bool active READ isActive NOTIFY activeChanged);
86+ // / Is false if another input method is already registered to the compositor, otherwise is true
6887 Q_PROPERTY (bool hasInput READ hasInput NOTIFY hasInputChanged);
88+ // / If the input method has grabbed the keyboard
6989 Q_PROPERTY (bool hasKeyboard READ hasKeyboard NOTIFY hasKeyboardChanged);
90+ // / TODO(cmurtagh-lgtm)
7091 Q_PROPERTY (
7192 bool clearPreeditOnKeyboardRelease MEMBER mClearPreeditOnKeyboardRelease NOTIFY
7293 clearPreeditOnKeyboardReleaseChanged
7394 );
7495 // Q_PROPERTY(QString preedit)
96+ // / The @@Keyboard$ that will handle the grabbed keyboard.
97+ // / Use @@KeyboardTextEdit$ for most cases.
7598 Q_PROPERTY (
7699 QQmlComponent* keyboard READ keyboardComponent WRITE setKeyboardComponent NOTIFY
77100 keyboardComponentChanged
@@ -82,22 +105,39 @@ class InputMethod: public QObject {
82105public:
83106 explicit InputMethod (QObject* parent = nullptr );
84107
108+ // / Sends a string to the text input currently focused
85109 Q_INVOKABLE void sendString (const QString& text);
110+ // / Provides virtual text in the text input so the user can visualise what they write
111+ // / This will override any previous preedit text
112+ // / If `cursorBegin == cursorEnd == -1` the text input will not show a cursor
113+ // / If `cursorBegin == cursorEnd == n` the text input will show a cursor at n
114+ // / If `cursorBegin == n` and `cursorEnd == m` the text from n to m will be highlighted
86115 Q_INVOKABLE void
87116 sendPreeditString (const QString& text, int32_t cursorBegin = -1 , int32_t cursorEnd = -1 );
117+ // / Removes text before the cursor by `before` and after by `after`.
118+ // / If preedit text is present, then text will be deleted before the preedit text and after the preedit text instead of the cursor.
88119 Q_INVOKABLE void deleteText (int before = 1 , int after = 0 );
89120
121+ // / If there is a focused text input that we can write to
90122 Q_INVOKABLE [[nodiscard]] bool isActive () const ;
91123
124+ // / @@keyboard$
92125 Q_INVOKABLE [[nodiscard]] QQmlComponent* keyboardComponent () const ;
126+ // / @@keyboard$
93127 Q_INVOKABLE void setKeyboardComponent (QQmlComponent* keyboardComponent);
94128
129+ // / @@hasInput$
95130 Q_INVOKABLE [[nodiscard]] bool hasInput () const ;
131+ // / Retries getting the input method.
96132 Q_INVOKABLE void getInput ();
133+ // / Releases the input method so another program can use it.
97134 Q_INVOKABLE void releaseInput ();
98135
136+ // / @@hasKeyboard$
99137 Q_INVOKABLE [[nodiscard]] bool hasKeyboard () const ;
138+ // / Grabs the current keyboard so the input can be intercepted by the @@keyboard$ object
100139 Q_INVOKABLE void grabKeyboard ();
140+ // / Releases the grabbed keyboard so it can be used normally.
101141 Q_INVOKABLE void releaseKeyboard ();
102142
103143signals:
0 commit comments