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 ClipboardGrabMessage::debug_description() return builder.to_string(); } +ErrorOr ClipboardRequestMessage::read_from_stream(AK::Stream& stream) +{ + auto value = TRY(stream.read_value()); + if (value >= to_underlying(ClipboardDataType::__End)) { + return Error::from_string_literal("Unsupported clipboard type"); + } + + auto type = static_cast(value); + return ClipboardRequestMessage(type); +} + +ErrorOr ClipboardRequestMessage::write_to_stream(AK::Stream& stream) +{ + TRY(stream.write_value(data_type())); + return {}; +} + +ErrorOr 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 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 read_from_stream(AK::Stream& stream); + + ErrorOr write_to_stream(AK::Stream& stream); + ErrorOr 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 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; }