1 /* 2 SPDX-FileCopyrightText: 2018 Roman Glig <subdiff@gmail.com> 3 SPDX-FileCopyrightText: 2020 Bhushan Shah <bshah@kde.org> 4 SPDX-FileCopyrightText: 2021 dcz <gihuac.dcz@porcupinefactory.org> 5 SPDX-FileCopyrightText: 2021 Roman Glig <subdiff@gmail.com> 6 7 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only 8 */ 9 #pragma once 10 11 #include <Wrapland/Server/wraplandserver_export.h> 12 13 #include <QObject> 14 #include <QRect> 15 16 #include <memory> 17 18 namespace Wrapland::Server 19 { 20 class Client; 21 class Display; 22 class Seat; 23 class Surface; 24 25 enum class text_input_v3_content_hint : uint32_t { 26 none = 0, 27 completion = 1 << 0, 28 spellcheck = 1 << 1, 29 auto_capitalization = 1 << 2, 30 lowercase = 1 << 3, 31 uppercase = 1 << 4, 32 titlecase = 1 << 5, 33 hidden_text = 1 << 6, 34 sensitive_data = 1 << 7, 35 latin = 1 << 8, 36 multiline = 1 << 9, 37 }; 38 Q_DECLARE_FLAGS(text_input_v3_content_hints, text_input_v3_content_hint) 39 40 enum class text_input_v3_content_purpose : uint32_t { 41 normal, 42 alpha, 43 digits, 44 number, 45 phone, 46 url, 47 email, 48 name, 49 password, 50 date, 51 time, 52 datetime, 53 terminal, 54 }; 55 56 enum class text_input_v3_change_cause { 57 input_method, 58 other, 59 }; 60 61 struct text_input_v3_state { 62 bool enabled{false}; 63 QRect cursor_rectangle; 64 struct { 65 text_input_v3_content_hints hints{text_input_v3_content_hint::none}; 66 text_input_v3_content_purpose purpose{text_input_v3_content_purpose::normal}; 67 } content; 68 69 struct { 70 bool update{false}; 71 std::string data; 72 int32_t cursor_position{0}; 73 int32_t selection_anchor{0}; 74 text_input_v3_change_cause change_cause{text_input_v3_change_cause::other}; 75 } surrounding_text; 76 }; 77 78 class WRAPLANDSERVER_EXPORT text_input_manager_v3 : public QObject 79 { 80 Q_OBJECT 81 public: 82 explicit text_input_manager_v3(Display* display, QObject* parent = nullptr); 83 ~text_input_manager_v3() override; 84 85 private: 86 class Private; 87 std::unique_ptr<Private> d_ptr; 88 }; 89 90 class WRAPLANDSERVER_EXPORT text_input_v3 : public QObject 91 { 92 Q_OBJECT 93 public: 94 text_input_v3_state const& state() const; 95 Surface* entered_surface() const; 96 Client* client() const; 97 98 void delete_surrounding_text(uint32_t before_length, uint32_t after_length); 99 void set_preedit_string(std::string const& text, uint32_t cursor_begin, uint32_t cursor_end); 100 void commit_string(std::string const& text); 101 102 void done(); 103 104 Q_SIGNALS: 105 void state_committed(); 106 void resourceDestroyed(); 107 108 private: 109 explicit text_input_v3(Client* client, uint32_t version, uint32_t id); 110 friend class text_input_manager_v3; 111 friend class Seat; 112 friend class text_input_pool; 113 114 class Private; 115 Private* d_ptr; 116 }; 117 118 } 119 120 Q_DECLARE_METATYPE(Wrapland::Server::text_input_v3*) 121 Q_DECLARE_METATYPE(Wrapland::Server::text_input_v3_content_hint) 122 Q_DECLARE_METATYPE(Wrapland::Server::text_input_v3_content_hints) 123 Q_DECLARE_OPERATORS_FOR_FLAGS(Wrapland::Server::text_input_v3_content_hints) 124 Q_DECLARE_METATYPE(Wrapland::Server::text_input_v3_content_purpose) 125 Q_DECLARE_METATYPE(Wrapland::Server::text_input_v3_change_cause) 126