aboutsummaryrefslogtreecommitdiffstats
path: root/bindings/cpp/include/pugl
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-22 12:24:59 -0400
committerDavid Robillard <d@drobilla.net>2022-05-23 16:50:43 -0400
commit2501218801437ea413091007b535d7c097801713 (patch)
treecf938dd335f8aa9b547b458f97f05e7e18d8b9d3 /bindings/cpp/include/pugl
parent0093196a4c624da6d7f78a909a442f2e784c37aa (diff)
downloadpugl-2501218801437ea413091007b535d7c097801713.tar.gz
pugl-2501218801437ea413091007b535d7c097801713.tar.bz2
pugl-2501218801437ea413091007b535d7c097801713.zip
Add rich clipboard support
This implements a more powerful protocol for working with clipboards, which supports datatype negotiation, and fixes various issues by mapping more directly to how things work on X11.
Diffstat (limited to 'bindings/cpp/include/pugl')
-rw-r--r--bindings/cpp/include/pugl/pugl.hpp44
1 files changed, 43 insertions, 1 deletions
diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp
index 5b47fe6..8e74278 100644
--- a/bindings/cpp/include/pugl/pugl.hpp
+++ b/bindings/cpp/include/pugl/pugl.hpp
@@ -1,4 +1,4 @@
-// Copyright 2012-2020 David Robillard <d@drobilla.net>
+// Copyright 2012-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#ifndef PUGL_PUGL_HPP
@@ -6,6 +6,7 @@
#include "pugl/pugl.h"
+#include <cstddef> // IWYU pragma: keep
#include <cstdint> // IWYU pragma: keep
#if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION)
@@ -176,6 +177,12 @@ using LoopEnterEvent = Event<PUGL_LOOP_ENTER, PuglLoopEnterEvent>;
/// @copydoc PuglLoopLeaveEvent
using LoopLeaveEvent = Event<PUGL_LOOP_LEAVE, PuglLoopLeaveEvent>;
+/// @copydoc PuglDataOfferEvent
+using DataOfferEvent = Event<PUGL_DATA_OFFER, PuglDataOfferEvent>;
+
+/// @copydoc PuglDataEvent
+using DataEvent = Event<PUGL_DATA, PuglDataEvent>;
+
/**
@}
@defgroup statuspp Status
@@ -560,6 +567,37 @@ public:
puglSetCursor(cobj(), static_cast<PuglCursor>(cursor)));
}
+ /// @copydoc puglGetNumClipboardTypes
+ uint32_t numClipboardTypes() const
+ {
+ return puglGetNumClipboardTypes(cobj());
+ }
+
+ /// @copydoc puglGetClipboardType
+ const char* clipboardType(const uint32_t typeIndex) const
+ {
+ return puglGetClipboardType(cobj(), typeIndex);
+ }
+
+ /**
+ Accept data offered from a clipboard.
+
+ To accept data, this must be called while handling a #PUGL_DATA_OFFER
+ event. Doing so will request the data from the source as the specified
+ type. When the data is available, a #PUGL_DATA event will be sent to the
+ view which can then retrieve the data with puglGetClipboard().
+
+ @param offer The data offer event.
+
+ @param typeIndex The index of the type that the view will accept. This is
+ the `typeIndex` argument to the call of puglGetClipboardType() that
+ returned the accepted type.
+ */
+ Status acceptOffer(const DataOfferEvent& offer, const size_t typeIndex)
+ {
+ return static_cast<Status>(puglAcceptOffer(cobj(), &offer, typeIndex));
+ }
+
/// @copydoc puglRequestAttention
Status requestAttention() noexcept
{
@@ -678,6 +716,10 @@ private:
return target.onEvent(LoopEnterEvent{event->any});
case PUGL_LOOP_LEAVE:
return target.onEvent(LoopLeaveEvent{event->any});
+ case PUGL_DATA_OFFER:
+ return target.onEvent(DataOfferEvent{event->offer});
+ case PUGL_DATA:
+ return target.onEvent(DataEvent{event->data});
}
return Status::failure;