summaryrefslogtreecommitdiff
path: root/Userland/Services
diff options
context:
space:
mode:
authorCaoimhe <caoimhebyrne06@gmail.com>2023-05-13 13:44:10 +0100
committerAndreas Kling <kling@serenityos.org>2023-05-21 18:45:53 +0200
commit9c4538a9a803abba76e6d7c8357756078a33a2fb (patch)
treeca02d45280e865b98b858fd0b61a4830486fff5c /Userland/Services
parent8202f131690185371b83b601615d378496c4e6a5 (diff)
downloadserenity-9c4538a9a803abba76e6d7c8357756078a33a2fb.zip
SpiceAgent: Implement `ClipboardRequest` messages
Diffstat (limited to 'Userland/Services')
-rw-r--r--Userland/Services/SpiceAgent/Message.cpp26
-rw-r--r--Userland/Services/SpiceAgent/Message.h20
-rw-r--r--Userland/Services/SpiceAgent/SpiceAgent.cpp4
3 files changed, 50 insertions, 0 deletions
diff --git a/Userland/Services/SpiceAgent/Message.cpp b/Userland/Services/SpiceAgent/Message.cpp
index ecf399030e..fa2706c359 100644
--- a/Userland/Services/SpiceAgent/Message.cpp
+++ b/Userland/Services/SpiceAgent/Message.cpp
@@ -85,4 +85,30 @@ ErrorOr<String> ClipboardGrabMessage::debug_description()
return builder.to_string();
}
+ErrorOr<ClipboardRequestMessage> ClipboardRequestMessage::read_from_stream(AK::Stream& stream)
+{
+ auto value = TRY(stream.read_value<u32>());
+ if (value >= to_underlying(ClipboardDataType::__End)) {
+ return Error::from_string_literal("Unsupported clipboard type");
+ }
+
+ auto type = static_cast<ClipboardDataType>(value);
+ return ClipboardRequestMessage(type);
+}
+
+ErrorOr<void> ClipboardRequestMessage::write_to_stream(AK::Stream& stream)
+{
+ TRY(stream.write_value(data_type()));
+ return {};
+}
+
+ErrorOr<String> ClipboardRequestMessage::debug_description()
+{
+ StringBuilder builder;
+ TRY(builder.try_append("ClipboardRequest { "sv));
+ TRY(builder.try_appendff("data_type = {}", data_type()));
+ TRY(builder.try_append(" }"sv));
+ return builder.to_string();
+}
+
}
diff --git a/Userland/Services/SpiceAgent/Message.h b/Userland/Services/SpiceAgent/Message.h
index dc0a0725ba..8c70b1a205 100644
--- a/Userland/Services/SpiceAgent/Message.h
+++ b/Userland/Services/SpiceAgent/Message.h
@@ -130,6 +130,26 @@ private:
Vector<ClipboardDataType> m_types;
};
+// Request clipboard data with the specified type.
+class ClipboardRequestMessage : public Message {
+public:
+ ClipboardRequestMessage(ClipboardDataType data_type)
+ : Message(Type::ClipboardRequest)
+ , m_data_type(data_type)
+ {
+ }
+
+ static ErrorOr<ClipboardRequestMessage> read_from_stream(AK::Stream& stream);
+
+ ErrorOr<void> write_to_stream(AK::Stream& stream);
+ ErrorOr<String> debug_description() override;
+
+ ClipboardDataType data_type() { return m_data_type; }
+
+private:
+ ClipboardDataType m_data_type;
+};
+
}
namespace AK {
diff --git a/Userland/Services/SpiceAgent/SpiceAgent.cpp b/Userland/Services/SpiceAgent/SpiceAgent.cpp
index 5350ba8c1e..bb96d634be 100644
--- a/Userland/Services/SpiceAgent/SpiceAgent.cpp
+++ b/Userland/Services/SpiceAgent/SpiceAgent.cpp
@@ -74,6 +74,10 @@ ErrorOr<void> SpiceAgent::on_message_received()
break;
dbgln_if(SPICE_AGENT_DEBUG, "The spice server has notified us of new clipboard data of type: {}", data_type);
+ dbgln_if(SPICE_AGENT_DEBUG, "Sending a request for data of type: {}", data_type);
+
+ auto request_message = ClipboardRequestMessage(data_type);
+ TRY(this->send_message(request_message));
break;
}