From 2501218801437ea413091007b535d7c097801713 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 22 May 2022 12:24:59 -0400 Subject: 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. --- bindings/cpp/include/pugl/pugl.hpp | 44 +++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'bindings/cpp/include/pugl') 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 +// Copyright 2012-2022 David Robillard // SPDX-License-Identifier: ISC #ifndef PUGL_PUGL_HPP @@ -6,6 +6,7 @@ #include "pugl/pugl.h" +#include // IWYU pragma: keep #include // IWYU pragma: keep #if defined(PUGL_HPP_THROW_FAILED_CONSTRUCTION) @@ -176,6 +177,12 @@ using LoopEnterEvent = Event; /// @copydoc PuglLoopLeaveEvent using LoopLeaveEvent = Event; +/// @copydoc PuglDataOfferEvent +using DataOfferEvent = Event; + +/// @copydoc PuglDataEvent +using DataEvent = Event; + /** @} @defgroup statuspp Status @@ -560,6 +567,37 @@ public: puglSetCursor(cobj(), static_cast(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(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; -- cgit v1.2.1