1 /****************************************************************************
2 Copyright © 2020 Adrien Faveraux <ad1rie3@hotmail.fr>
3 
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), which shall
10 act as a proxy defined in Section 6 of version 3 of the license.
11 
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library.  If not, see <http://www.gnu.org/licenses/>.
19 ****************************************************************************/
20 #pragma once
21 
22 #include <QObject>
23 
24 #include <Wrapland/Server/wraplandserver_export.h>
25 
26 #include <memory>
27 
28 namespace Wrapland::Server
29 {
30 class Display;
31 class Client;
32 class Seat;
33 class Surface;
34 
35 class WRAPLANDSERVER_EXPORT TextInputV2 : public QObject
36 {
37     Q_OBJECT
38 public:
39     enum class ContentHint : uint32_t {
40         None = 0,
41         AutoCompletion = 1 << 0,
42         AutoCorrection = 1 << 1,
43         AutoCapitalization = 1 << 2,
44         LowerCase = 1 << 3,
45         UpperCase = 1 << 4,
46         TitleCase = 1 << 5,
47         HiddenText = 1 << 6,
48         SensitiveData = 1 << 7,
49         Latin = 1 << 8,
50         MultiLine = 1 << 9,
51     };
52     Q_DECLARE_FLAGS(ContentHints, ContentHint)
53 
54     enum class ContentPurpose : uint32_t {
55         Normal,
56         Alpha,
57         Digits,
58         Number,
59         Phone,
60         Url,
61         Email,
62         Name,
63         Password,
64         Date,
65         Time,
66         DateTime,
67         Terminal,
68     };
69 
70     Client* client() const;
71     QByteArray preferredLanguage() const;
72     QRect cursorRectangle() const;
73     ContentPurpose contentPurpose() const;
74     ContentHints contentHints() const;
75     QByteArray surroundingText() const;
76     qint32 surroundingTextCursorPosition() const;
77     qint32 surroundingTextSelectionAnchor() const;
78     QPointer<Surface> surface() const;
79     bool isEnabled() const;
80 
81     void preEdit(const QByteArray& text, const QByteArray& commitText);
82     void commit(const QByteArray& text);
83     void setPreEditCursor(qint32 index);
84     void deleteSurroundingText(quint32 beforeLength, quint32 afterLength);
85     void setCursorPosition(qint32 index, qint32 anchor);
86     void setTextDirection(Qt::LayoutDirection direction);
87 
88     void keysymPressed(quint32 keysym, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
89     void keysymReleased(quint32 keysym, Qt::KeyboardModifiers modifiers = Qt::NoModifier);
90     void setInputPanelState(bool visible, const QRect& overlappedSurfaceArea);
91     void setLanguage(const QByteArray& languageTag);
92 
93 Q_SIGNALS:
94     void requestShowInputPanel();
95     void requestHideInputPanel();
96     void requestReset();
97     void preferredLanguageChanged(const QByteArray& language);
98     void cursorRectangleChanged(const QRect& rect);
99     void contentTypeChanged();
100     void surroundingTextChanged();
101     void enabledChanged();
102     void resourceDestroyed();
103 
104 private:
105     explicit TextInputV2(Client* client, uint32_t version, uint32_t id);
106     friend class TextInputManagerV2;
107     friend class Seat;
108     friend class text_input_pool;
109 
110     class Private;
111     Private* d_ptr;
112 };
113 
114 class WRAPLANDSERVER_EXPORT TextInputManagerV2 : public QObject
115 {
116     Q_OBJECT
117 public:
118     explicit TextInputManagerV2(Display* display, QObject* parent = nullptr);
119     ~TextInputManagerV2() override;
120 
121 private:
122     class Private;
123     std::unique_ptr<Private> d_ptr;
124 };
125 
126 }
127 
128 Q_DECLARE_METATYPE(Wrapland::Server::TextInputV2*)
129 Q_DECLARE_METATYPE(Wrapland::Server::TextInputV2::ContentHint)
130 Q_DECLARE_METATYPE(Wrapland::Server::TextInputV2::ContentHints)
131 Q_DECLARE_OPERATORS_FOR_FLAGS(Wrapland::Server::TextInputV2::ContentHints)
132 Q_DECLARE_METATYPE(Wrapland::Server::TextInputV2::ContentPurpose)
133