mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 09:47:34 +00:00
SpiceAgent: Add a new spice agent service :^)
A SPICE agent communicates with the host OS to provide nifty features like clipboard sharing :^) This patch implements only plain-text clipboard sharing. See: github.com/freedesktop/spice-protocol/blob/master/spice/vd_agent.h
This commit is contained in:
parent
42c5df7256
commit
d4bb6a1a1e
8 changed files with 432 additions and 0 deletions
127
Userland/Services/SpiceAgent/SpiceAgent.h
Normal file
127
Userland/Services/SpiceAgent/SpiceAgent.h
Normal file
|
@ -0,0 +1,127 @@
|
|||
/*
|
||||
* Copyright (c) 2021, Kyle Pereira <kyle@xylepereira.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "ClipboardServerConnection.h"
|
||||
#include <AK/ByteBuffer.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibCore/Notifier.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
class SpiceAgent {
|
||||
public:
|
||||
SpiceAgent(int fd, ClipboardServerConnection&);
|
||||
|
||||
static constexpr u32 AGENT_PROTOCOL = 1;
|
||||
enum class Port {
|
||||
Client = 1,
|
||||
Server
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] ChunkHeader {
|
||||
u32 port {};
|
||||
u32 size {};
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] Message {
|
||||
u32 protocol;
|
||||
u32 type;
|
||||
u64 opaque;
|
||||
u32 size;
|
||||
u8 data[];
|
||||
};
|
||||
|
||||
enum class MessageType {
|
||||
MouseState = 1, // server -> client
|
||||
MonitorsConfig, // client -> agent|server
|
||||
Reply, // agent -> client
|
||||
Clipboard, // both directions
|
||||
DisplayConfig, // client -> agent
|
||||
AnnounceCapabilities, // both directions
|
||||
ClipboardGrab, // both directions
|
||||
ClipboardRequest, // both directions
|
||||
ClipboardRelease, // both directions
|
||||
FileTransferStart,
|
||||
FileTransferStatus,
|
||||
FileTransferData,
|
||||
Disconnected,
|
||||
MaxClipboard,
|
||||
VolumeSync,
|
||||
GraphicsDeviceInfo,
|
||||
};
|
||||
|
||||
enum class Capability {
|
||||
MouseState = 0,
|
||||
MonitorsConfig,
|
||||
Reply,
|
||||
Clipboard,
|
||||
DisplayConfig,
|
||||
ClipboardByDemand,
|
||||
ClipboardSelection,
|
||||
SparseMonitorsConfig,
|
||||
GuestLineEndLF,
|
||||
GuestLineEndCRLF,
|
||||
MaxClipboard,
|
||||
AudioVolumeSync,
|
||||
MonitorsConfigPosition,
|
||||
FileTransferDisabled,
|
||||
FileTransferDetailedErrors,
|
||||
GraphicsCardInfo,
|
||||
ClipboardNoReleaseOnRegrab,
|
||||
ClipboardGrabSerial,
|
||||
__End,
|
||||
};
|
||||
|
||||
enum class ClipboardType {
|
||||
None = 0,
|
||||
Text,
|
||||
PNG,
|
||||
BMP,
|
||||
TIFF,
|
||||
JPG,
|
||||
FileList,
|
||||
__Count
|
||||
};
|
||||
|
||||
constexpr static size_t CAPABILITIES_SIZE = ((size_t)Capability::__End + 31) / 32;
|
||||
|
||||
struct [[gnu::packed]] AnnounceCapabilities {
|
||||
u32 request;
|
||||
u32 caps[CAPABILITIES_SIZE];
|
||||
|
||||
static ByteBuffer make_buffer(bool request, const Vector<Capability>& capabilities);
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] ClipboardGrab {
|
||||
u32 types[0];
|
||||
|
||||
static ByteBuffer make_buffer(Vector<ClipboardType> const&);
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] Clipboard {
|
||||
u32 type;
|
||||
u8 data[];
|
||||
|
||||
static ByteBuffer make_buffer(ClipboardType, ReadonlyBytes);
|
||||
};
|
||||
|
||||
struct [[gnu::packed]] ClipboardRequest {
|
||||
u32 type;
|
||||
|
||||
static ByteBuffer make_buffer(ClipboardType);
|
||||
};
|
||||
|
||||
private:
|
||||
int m_fd { -1 };
|
||||
RefPtr<Core::Notifier> m_notifier;
|
||||
ClipboardServerConnection& m_clipboard_connection;
|
||||
|
||||
void on_message_received();
|
||||
void send_message(const ByteBuffer& buffer);
|
||||
bool m_just_set_clip { false };
|
||||
void read_n(void* dest, size_t n);
|
||||
static Message* initialize_headers(u8* data, size_t additional_data_size, MessageType type);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue