mirror of
https://github.com/kunkundi/crossdesk.git
synced 2026-11-04 13:02:39 +08:00
[feat] add iOS system keyboard input and improve computer keyboard
This commit is contained in:
@@ -31,6 +31,7 @@ enum ControlType {
|
||||
privacy_status = 10,
|
||||
video_settings = 11,
|
||||
video_settings_status = 12,
|
||||
text_input = 13,
|
||||
};
|
||||
|
||||
enum MouseFlag {
|
||||
@@ -137,6 +138,7 @@ struct HostInfo {
|
||||
// Optional capability; absent in legacy desktop and web host information.
|
||||
bool supports_privacy_screen;
|
||||
bool supports_video_settings;
|
||||
bool supports_text_input;
|
||||
bool supports_deskhub_preview;
|
||||
bool supports_deskhub_resolution;
|
||||
bool supports_deskhub_fps15;
|
||||
@@ -183,6 +185,8 @@ inline bool ValidVideoSettings(const VideoSettings& settings) {
|
||||
settings.preference >= 0 && settings.preference <= 2;
|
||||
}
|
||||
|
||||
inline constexpr std::size_t kMaxTextInputBytes = 16 * 1024;
|
||||
|
||||
struct RemoteAction {
|
||||
ControlType type = ControlType::invalid;
|
||||
union {
|
||||
@@ -200,6 +204,9 @@ struct RemoteAction {
|
||||
VideoSettings vs;
|
||||
};
|
||||
|
||||
// Committed UTF-8 text. Kept outside the POD union for automatic ownership.
|
||||
std::string text;
|
||||
|
||||
std::string to_json() const;
|
||||
bool from_json(const std::string& json_string);
|
||||
|
||||
@@ -208,7 +215,7 @@ struct RemoteAction {
|
||||
};
|
||||
|
||||
// Releases the dynamically allocated display arrays held by host information.
|
||||
// Other RemoteAction variants do not own memory and are left unchanged.
|
||||
// Other RemoteAction variants require no explicit cleanup and are left unchanged.
|
||||
void FreeRemoteAction(RemoteAction& action);
|
||||
|
||||
// One display as advertised in host information; bounds are virtual-desktop
|
||||
|
||||
@@ -26,6 +26,7 @@ void ResetHostInfo(HostInfo& info) {
|
||||
info.bottom = nullptr;
|
||||
info.supports_privacy_screen = false;
|
||||
info.supports_video_settings = false;
|
||||
info.supports_text_input = false;
|
||||
info.supports_deskhub_preview = false;
|
||||
info.supports_deskhub_resolution = false;
|
||||
info.supports_deskhub_fps15 = false;
|
||||
@@ -136,6 +137,11 @@ std::string RemoteAction::ToJson(const RemoteAction& action) {
|
||||
{"s", action.m.s},
|
||||
{"flag", action.m.flag}};
|
||||
break;
|
||||
case ControlType::text_input:
|
||||
if (action.text.empty() || action.text.size() > kMaxTextInputBytes ||
|
||||
action.text.find('\0') != std::string::npos) return {};
|
||||
object["text"] = action.text;
|
||||
break;
|
||||
case ControlType::keyboard:
|
||||
object["keyboard"] = {{"key_value", action.k.key_value},
|
||||
{"scan_code", action.k.scan_code},
|
||||
@@ -226,6 +232,7 @@ std::string RemoteAction::ToJson(const RemoteAction& action) {
|
||||
{"displays", displays},
|
||||
{"supports_privacy_screen", action.i.supports_privacy_screen},
|
||||
{"supports_video_settings", action.i.supports_video_settings},
|
||||
{"supports_text_input", action.i.supports_text_input},
|
||||
{"supports_deskhub_preview", action.i.supports_deskhub_preview},
|
||||
{"supports_deskhub_resolution", action.i.supports_deskhub_resolution},
|
||||
{"supports_deskhub_fps15", action.i.supports_deskhub_fps15},
|
||||
@@ -253,6 +260,11 @@ bool RemoteAction::FromJson(const std::string& json_string,
|
||||
output.m.flag = static_cast<MouseFlag>(
|
||||
object.at("mouse").at("flag").get<int>());
|
||||
break;
|
||||
case ControlType::text_input:
|
||||
output.text = object.at("text").get<std::string>();
|
||||
if (output.text.empty() || output.text.size() > kMaxTextInputBytes ||
|
||||
output.text.find('\0') != std::string::npos) return false;
|
||||
break;
|
||||
case ControlType::keyboard:
|
||||
output.k.key_value =
|
||||
object.at("keyboard").at("key_value").get<std::size_t>();
|
||||
@@ -420,6 +432,8 @@ bool RemoteAction::FromJson(const std::string& json_string,
|
||||
output.i.supports_privacy_screen =
|
||||
privacy_support != host_info_object.end() &&
|
||||
privacy_support->is_boolean() && privacy_support->get<bool>();
|
||||
output.i.supports_text_input =
|
||||
host_info_object.value("supports_text_input", false);
|
||||
output.i.supports_video_settings =
|
||||
host_info_object.value("supports_video_settings", false);
|
||||
output.i.supports_deskhub_preview =
|
||||
|
||||
Reference in New Issue
Block a user