1 /*
2     SPDX-FileCopyrightText: 2020 Aleix Pol Gonzalez <aleixpol@kde.org>
3     SPDX-FileCopyrightText: 2021 Dorota Czaplejewicz <gihuac.dcz@porcupinefactory.org>
4     SPDX-FileCopyrightText: 2021 Roman Glig <subdiff@gmail.com>
5 
6     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only
7 */
8 #pragma once
9 
10 #include "text_input_v3.h"
11 
12 #include <Wrapland/Server/wraplandserver_export.h>
13 
14 #include <QObject>
15 #include <memory>
16 
17 namespace Wrapland::Server
18 {
19 class Client;
20 class Display;
21 class input_method_keyboard_grab_v2;
22 class input_method_popup_surface_v2;
23 
24 class WRAPLANDSERVER_EXPORT input_method_manager_v2 : public QObject
25 {
26     Q_OBJECT
27 public:
28     explicit input_method_manager_v2(Display* d, QObject* parent = nullptr);
29     ~input_method_manager_v2() override;
30 
31 private:
32     class Private;
33     std::unique_ptr<Private> d_ptr;
34 };
35 
36 struct input_method_v2_state {
37     struct {
38         bool update{false};
39         std::string data;
40         uint32_t cursor_begin{0};
41         uint32_t cursor_end{0};
42     } preedit_string;
43 
44     struct {
45         bool update{false};
46         std::string data;
47     } commit_string;
48 
49     struct {
50         bool update{false};
51         uint32_t before_length{0};
52         uint32_t after_length{0};
53     } delete_surrounding_text;
54 };
55 
56 class WRAPLANDSERVER_EXPORT input_method_v2 : public QObject
57 {
58     Q_OBJECT
59 public:
60     input_method_v2_state const& state() const;
61 
62     void set_active(bool active);
63     void set_surrounding_text(std::string const& text,
64                               uint32_t cursor,
65                               uint32_t anchor,
66                               text_input_v3_change_cause change_cause);
67     void set_content_type(text_input_v3_content_hints hints, text_input_v3_content_purpose purpose);
68     void done();
69 
70 Q_SIGNALS:
71     void state_committed();
72     void keyboard_grabbed(Wrapland::Server::input_method_keyboard_grab_v2*);
73     void popup_surface_created(Wrapland::Server::input_method_popup_surface_v2*);
74     void resourceDestroyed();
75 
76 private:
77     explicit input_method_v2(Client* client, uint32_t version, uint32_t id);
78     friend class input_method_manager_v2;
79 
80     class Private;
81     Private* d_ptr;
82 };
83 
84 class WRAPLANDSERVER_EXPORT input_method_keyboard_grab_v2 : public QObject
85 {
86     Q_OBJECT
87 public:
88     void set_keymap(std::string const& content);
89 
90     void press_key(uint32_t time, uint32_t key);
91     void release_key(uint32_t time, uint32_t key);
92 
93     void update_modifiers(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group);
94     void set_repeat_info(int32_t rate, int32_t delay);
95 
96 Q_SIGNALS:
97     void resourceDestroyed();
98 
99 private:
100     explicit input_method_keyboard_grab_v2(Client* client,
101                                            uint32_t version,
102                                            uint32_t id,
103                                            Seat* seat);
104     friend class input_method_v2;
105 
106     class Private;
107     Private* d_ptr;
108 };
109 
110 class WRAPLANDSERVER_EXPORT input_method_popup_surface_v2 : public QObject
111 {
112     Q_OBJECT
113 public:
114     Surface* surface() const;
115     void set_text_input_rectangle(QRect const& rect);
116 
117 Q_SIGNALS:
118     void resourceDestroyed();
119 
120 private:
121     explicit input_method_popup_surface_v2(Client* client,
122                                            uint32_t version,
123                                            uint32_t id,
124                                            Surface* surface);
125     friend class input_method_v2;
126 
127     class Private;
128     Private* d_ptr;
129 };
130 
131 }
132 
133 Q_DECLARE_METATYPE(Wrapland::Server::input_method_v2*)
134 Q_DECLARE_METATYPE(Wrapland::Server::input_method_keyboard_grab_v2*)
135 Q_DECLARE_METATYPE(Wrapland::Server::input_method_popup_surface_v2*)
136