From 2626136749a8f389b2971f949dd39bb8843581e1 Mon Sep 17 00:00:00 2001 From: Daniel Bertalan Date: Sat, 13 May 2023 08:51:05 +0200 Subject: [PATCH] SpiceAgent: Gracefully handle the host clearing the clipboard When the host clears the clipboard (e.g. by running `pbcopy (), data_buffer.data(), data_buffer.size()); - m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {}); + if (data_buffer.is_empty()) { + m_clipboard_connection.async_set_clipboard_data({}, "text/plain", {}); + } else { + auto anon_buffer_or_error = Core::AnonymousBuffer::create_with_size(data_buffer.size()); + VERIFY(!anon_buffer_or_error.is_error()); + auto anon_buffer = anon_buffer_or_error.release_value(); + memcpy(anon_buffer.data(), data_buffer.data(), data_buffer.size()); + m_clipboard_connection.async_set_clipboard_data(anon_buffer, "text/plain", {}); + } return; } else { ErrorOr frame_or_error = Gfx::ImageFrameDescriptor {};