mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:07:45 +00:00
SpiceAgent: Gracefully handle the host clearing the clipboard
When the host clears the clipboard (e.g. by running `pbcopy </dev/null`) the Spice server sends an empty string to us. Previously, we would crash as `AnonymousBuffer::create_with_size` doesn't accept a size of 0. Fix this by passing `{}` to `async_set_clipboard_data` in this case.
This commit is contained in:
parent
9d78619b59
commit
2626136749
1 changed files with 9 additions and 5 deletions
|
@ -132,11 +132,15 @@ void SpiceAgent::on_message_received()
|
||||||
|
|
||||||
m_just_set_clip = true;
|
m_just_set_clip = true;
|
||||||
if (type == ClipboardType::Text) {
|
if (type == ClipboardType::Text) {
|
||||||
auto anon_buffer_or_error = Core::AnonymousBuffer::create_with_size(data_buffer.size());
|
if (data_buffer.is_empty()) {
|
||||||
VERIFY(!anon_buffer_or_error.is_error());
|
m_clipboard_connection.async_set_clipboard_data({}, "text/plain", {});
|
||||||
auto anon_buffer = anon_buffer_or_error.release_value();
|
} else {
|
||||||
memcpy(anon_buffer.data<void>(), data_buffer.data(), data_buffer.size());
|
auto anon_buffer_or_error = Core::AnonymousBuffer::create_with_size(data_buffer.size());
|
||||||
m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {});
|
VERIFY(!anon_buffer_or_error.is_error());
|
||||||
|
auto anon_buffer = anon_buffer_or_error.release_value();
|
||||||
|
memcpy(anon_buffer.data<void>(), data_buffer.data(), data_buffer.size());
|
||||||
|
m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {});
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
ErrorOr<Gfx::ImageFrameDescriptor> frame_or_error = Gfx::ImageFrameDescriptor {};
|
ErrorOr<Gfx::ImageFrameDescriptor> frame_or_error = Gfx::ImageFrameDescriptor {};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue