Skip to content

Commit 402093b

Browse files
committed
some documentation
1 parent d92ced5 commit 402093b

File tree

7 files changed

+83
-5
lines changed

7 files changed

+83
-5
lines changed

src/wayland/input_method/c_helpers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct FreeDeleter {
1313
using uniqueCString = std::unique_ptr<const char, FreeDeleter>;
1414

1515
// this is a bit half baked but works for what I need it for
16+
/// Handles the lifetime of a memory mapped shm
1617
class SharedMemory {
1718
public:
1819
SharedMemory(const char* shmName, int oFlag, size_t size);

src/wayland/input_method/input_method.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace qs::wayland::input_method::impl {
99

1010
class InputMethodKeyboardGrab;
1111

12+
/// A lightweight handle for the wayland input_method protocol
1213
class InputMethodHandle
1314
: public QObject
1415
, private QtWayland::zwp_input_method_v2 {

src/wayland/input_method/key_map_state.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace qs::wayland::input_method::impl {
1313

14+
/// A wrapper that handles xkb_keymap and xkb_state lifetime with some convenience functions
1415
class KeyMapState {
1516
public:
1617
KeyMapState() = default;

src/wayland/input_method/keyboard_grab.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ namespace qs::wayland::input_method::impl {
1111

1212
class VirtualKeyboardHandle;
1313

14+
// TODO(cmurtagh-lgtm) Implement the popup-surface part of the protocol
1415
class InputMethodPopupSurface: QObject {
1516
Q_OBJECT;
1617
};
1718

19+
/// A wrapper around the input_method_keyboard_grab protocol
20+
/// Only some control keys and keys that are representable by utf32 are captured,
21+
/// other keys are passed back to the compositor via virtual keyboard.
1822
class InputMethodKeyboardGrab
1923
: public QObject
2024
, private QtWayland::zwp_input_method_keyboard_grab_v2 {

src/wayland/input_method/manager.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ InputMethodManager::InputMethodManager(): QWaylandClientExtensionTemplate(1) { t
1515
InputMethodManager::~InputMethodManager() { this->destroy(); }
1616

1717
InputMethodManager* InputMethodManager::instance() {
18-
static auto instance = std::unique_ptr<InputMethodManager>(new InputMethodManager());
19-
return instance.get();
18+
// The OS should free this memory when we exit
19+
static auto* instance = new InputMethodManager();
20+
return instance;
2021
}
2122

2223
namespace {
@@ -45,8 +46,9 @@ VirtualKeyboardManager::VirtualKeyboardManager(): QWaylandClientExtensionTemplat
4546
}
4647

4748
VirtualKeyboardManager* VirtualKeyboardManager::instance() {
48-
static auto instance = std::unique_ptr<VirtualKeyboardManager>(new VirtualKeyboardManager());
49-
return instance.get();
49+
// The OS should free this memory when we exit
50+
static auto* instance = new VirtualKeyboardManager();
51+
return instance;
5052
}
5153

5254
std::unique_ptr<VirtualKeyboardHandle>

src/wayland/input_method/qml.hpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
3739
class 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 {
4951
signals:
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`
6582
class 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 {
82105
public:
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

103143
signals:

src/wayland/input_method/qml_helpers.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,39 @@
88

99
namespace qs::wayland::input_method {
1010

11+
/// A keyboard handler for @@InputMethod$'s keyboard grab protocol.
12+
///
13+
/// As text is typed on the keyboard this will be displayed in the input method as virtual/preedit text.
14+
/// A cursor enables some control over the composition of the text.
15+
/// When return is pressed the transform function is called and the returned string is sent to the input text
16+
/// and the keyboard is released.
17+
///
18+
/// ```
19+
/// QSInputMethod {
20+
/// id: input_method
21+
/// KeyboardTextEdit {
22+
/// transform: function (text: string): string {
23+
/// return {
24+
/// "cool": "😎"
25+
/// // etc.
26+
/// }[text];
27+
/// }
28+
/// }
29+
/// }
30+
/// IpcHandler {
31+
/// target: "emoji"
32+
/// function get(): void { input_method.grabKeyboard(); }
33+
/// }
34+
/// ```
35+
///
36+
/// If you need a lower level view of the key events use @@Keyboard$.
1137
class KeyboardTextEdit: public Keyboard {
1238
Q_OBJECT;
39+
/// A function that has a string parameter and returns a string.
1340
Q_PROPERTY(QJSValue transform READ transform WRITE setTransform NOTIFY transformChanged FINAL)
41+
/// The position of the cursor within the @@editText$.
1442
Q_PROPERTY(int cursor MEMBER mCursor READ cursor WRITE setCursor NOTIFY cursorChanged);
43+
/// The text that is currently being edited and displayed.
1544
Q_PROPERTY(
1645
QString editText MEMBER mEditText READ editText WRITE setEditText NOTIFY editTextChanged
1746
);

0 commit comments

Comments
 (0)