1 | // Copyright (C) 2021 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef QWAYLANDTEXTINPUTV3_P_H |
5 | #define QWAYLANDTEXTINPUTV3_P_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include "qwaylandtextinputinterface_p.h" |
19 | #include <QtWaylandClient/private/qwayland-text-input-unstable-v3.h> |
20 | #include <QLoggingCategory> |
21 | |
22 | struct wl_callback; |
23 | struct wl_callback_listener; |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | Q_DECLARE_LOGGING_CATEGORY(qLcQpaWaylandTextInput) |
28 | |
29 | namespace QtWaylandClient { |
30 | |
31 | class QWaylandDisplay; |
32 | |
33 | class QWaylandTextInputv3 : public QtWayland::zwp_text_input_v3, public QWaylandTextInputInterface |
34 | { |
35 | public: |
36 | QWaylandTextInputv3(QWaylandDisplay *display, struct ::zwp_text_input_v3 *text_input); |
37 | ~QWaylandTextInputv3() override; |
38 | |
39 | void reset() override; |
40 | void commit() override; |
41 | void updateState(Qt::InputMethodQueries queries, uint32_t flags) override; |
42 | // TODO: not supported yet |
43 | void setCursorInsidePreedit(int cursor) override; |
44 | |
45 | bool isInputPanelVisible() const override; |
46 | QRectF keyboardRect() const override; |
47 | |
48 | QLocale locale() const override; |
49 | Qt::LayoutDirection inputDirection() const override; |
50 | |
51 | // doing nothing in zwp_text_input_v3. |
52 | // enter() and leave() takes the role to enable/disable the surface |
53 | void enableSurface(::wl_surface *) override {}; |
54 | void disableSurface(::wl_surface *) override {}; |
55 | |
56 | protected: |
57 | void zwp_text_input_v3_enter(struct ::wl_surface *surface) override; |
58 | void zwp_text_input_v3_leave(struct ::wl_surface *surface) override; |
59 | void zwp_text_input_v3_preedit_string(const QString &text, int32_t cursor_begin, int32_t cursor_end) override; |
60 | void zwp_text_input_v3_commit_string(const QString &text) override; |
61 | void zwp_text_input_v3_delete_surrounding_text(uint32_t before_length, uint32_t after_length) override; |
62 | void zwp_text_input_v3_done(uint32_t serial) override; |
63 | |
64 | private: |
65 | ::wl_surface *m_surface = nullptr; // ### Here for debugging purposes |
66 | |
67 | struct PreeditInfo { |
68 | QString text; |
69 | int cursorBegin = 0; |
70 | int cursorEnd = 0; |
71 | |
72 | void clear() { |
73 | text.clear(); |
74 | cursorBegin = 0; |
75 | cursorEnd = 0; |
76 | } |
77 | friend bool operator==(const PreeditInfo& lhs, const PreeditInfo& rhs) { |
78 | return (lhs.text == rhs.text) |
79 | && (lhs.cursorBegin == rhs.cursorBegin) |
80 | && (lhs.cursorEnd == rhs.cursorEnd); |
81 | } |
82 | }; |
83 | |
84 | PreeditInfo m_pendingPreeditString; |
85 | PreeditInfo m_currentPreeditString; |
86 | QString m_pendingCommitString; |
87 | uint m_pendingDeleteBeforeText = 0; // byte length |
88 | uint m_pendingDeleteAfterText = 0; // byte length |
89 | |
90 | QString m_surroundingText; |
91 | int m_cursor; // cursor position in QString |
92 | int m_cursorPos; // cursor position in wayland index |
93 | int m_anchorPos; // anchor position in wayland index |
94 | uint32_t m_contentHint = 0; |
95 | uint32_t m_contentPurpose = 0; |
96 | QRect m_cursorRect; |
97 | |
98 | uint m_currentSerial = 0; |
99 | |
100 | bool m_condReselection = false; |
101 | }; |
102 | |
103 | } |
104 | |
105 | QT_END_NAMESPACE |
106 | |
107 | #endif // QWAYLANDTEXTINPUTV3_P_H |
108 | |