mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:17:44 +00:00
Clipboard+LibGUI: Move clipboard service to anonymous files
This commit is contained in:
parent
1cb44ec5ee
commit
5522e8f59d
6 changed files with 21 additions and 60 deletions
|
@ -25,7 +25,6 @@
|
|||
*/
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/SharedBuffer.h>
|
||||
#include <Clipboard/ClipboardClientEndpoint.h>
|
||||
#include <Clipboard/ClipboardServerEndpoint.h>
|
||||
#include <LibGUI/Clipboard.h>
|
||||
|
@ -79,18 +78,9 @@ Clipboard::Clipboard()
|
|||
Clipboard::DataAndType Clipboard::data_and_type() const
|
||||
{
|
||||
auto response = connection().send_sync<Messages::ClipboardServer::GetClipboardData>();
|
||||
if (response->shbuf_id() < 0)
|
||||
if (!response->data().is_valid())
|
||||
return {};
|
||||
auto shared_buffer = SharedBuffer::create_from_shbuf_id(response->shbuf_id());
|
||||
if (!shared_buffer) {
|
||||
dbgln("GUI::Clipboard::data() failed to attach to the shared buffer");
|
||||
return {};
|
||||
}
|
||||
if (response->data_size() > shared_buffer->size()) {
|
||||
dbgln("GUI::Clipboard::data() clipping contents size is greater than shared buffer size");
|
||||
return {};
|
||||
}
|
||||
auto data = ByteBuffer::copy(shared_buffer->data<void>(), response->data_size());
|
||||
auto data = ByteBuffer::copy(response->data().data<void>(), response->data().size());
|
||||
auto type = response->mime_type();
|
||||
auto metadata = response->metadata().entries();
|
||||
return { data, type, metadata };
|
||||
|
@ -98,17 +88,15 @@ Clipboard::DataAndType Clipboard::data_and_type() const
|
|||
|
||||
void Clipboard::set_data(ReadonlyBytes data, const String& type, const HashMap<String, String>& metadata)
|
||||
{
|
||||
auto shared_buffer = SharedBuffer::create_with_size(data.size());
|
||||
if (!shared_buffer) {
|
||||
dbgln("GUI::Clipboard::set_data() failed to create a shared buffer");
|
||||
auto buffer = Core::AnonymousBuffer::create_with_size(data.size());
|
||||
if (!buffer.is_valid()) {
|
||||
dbgln("GUI::Clipboard::set_data() failed to create a buffer");
|
||||
return;
|
||||
}
|
||||
if (!data.is_empty())
|
||||
memcpy(shared_buffer->data<void>(), data.data(), data.size());
|
||||
shared_buffer->seal();
|
||||
shared_buffer->share_with(connection().server_pid());
|
||||
memcpy(buffer.data<void>(), data.data(), data.size());
|
||||
|
||||
connection().send_sync<Messages::ClipboardServer::SetClipboardData>(shared_buffer->shbuf_id(), data.size(), type, metadata);
|
||||
connection().send_sync<Messages::ClipboardServer::SetClipboardData>(move(buffer), type, metadata);
|
||||
}
|
||||
|
||||
void ClipboardServerConnection::handle(const Messages::ClipboardClient::ClipboardDataChanged& message)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue