1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 20:28:11 +00:00

LibGUI: Allow clipboard items to have no associated data

This commit is contained in:
Tim Ledbetter 2023-02-09 20:20:45 +00:00 committed by Linus Groh
parent 76891ae45d
commit c63f70d0fd

View file

@ -57,14 +57,14 @@ Clipboard& Clipboard::the()
Clipboard::DataAndType Clipboard::fetch_data_and_type() const
{
auto response = connection().get_clipboard_data();
auto type = response.mime_type();
auto metadata = response.metadata().entries();
if (!response.data().is_valid())
return {};
return { {}, type, metadata };
auto data = ByteBuffer::copy(response.data().data<void>(), response.data().size());
if (data.is_error())
return {};
auto type = response.mime_type();
auto metadata = response.metadata().entries();
return { data.release_value(), type, metadata };
}
@ -125,15 +125,18 @@ RefPtr<Gfx::Bitmap> Clipboard::DataAndType::as_bitmap() const
void Clipboard::set_data(ReadonlyBytes data, DeprecatedString const& type, HashMap<DeprecatedString, DeprecatedString> const& metadata)
{
if (data.is_empty()) {
connection().async_set_clipboard_data({}, type, metadata);
return;
}
auto buffer_or_error = Core::AnonymousBuffer::create_with_size(data.size());
if (buffer_or_error.is_error()) {
dbgln("GUI::Clipboard::set_data() failed to create a buffer");
return;
}
auto buffer = buffer_or_error.release_value();
if (!data.is_empty())
memcpy(buffer.data<void>(), data.data(), data.size());
memcpy(buffer.data<void>(), data.data(), data.size());
connection().async_set_clipboard_data(move(buffer), type, metadata);
}