diff options
author | Tim Ledbetter <timledbetter@gmail.com> | 2023-02-09 20:20:45 +0000 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-19 01:35:29 +0100 |
commit | c63f70d0fd66ab2071305ac4f9d2c7737d39c11f (patch) | |
tree | 80c27186982ac2621725a76956d33fac31120757 /Userland/Libraries | |
parent | 76891ae45df15c411cba10b826ef11aa3608200c (diff) | |
download | serenity-c63f70d0fd66ab2071305ac4f9d2c7737d39c11f.zip |
LibGUI: Allow clipboard items to have no associated data
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibGUI/Clipboard.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Userland/Libraries/LibGUI/Clipboard.cpp b/Userland/Libraries/LibGUI/Clipboard.cpp index b2ed7cdd88..0c219bafbe 100644 --- a/Userland/Libraries/LibGUI/Clipboard.cpp +++ b/Userland/Libraries/LibGUI/Clipboard.cpp @@ -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); } |