commit fdbc69f0ba38c212ee160e70c61cce710959e4f9
parent 114031ee99257b7c02cfc66cf01d56bef3c6d315
Author: falkTX <falktx@falktx.com>
Date: Sat, 28 May 2022 03:49:18 +0100
Make the default onClipboardDataOffer more friendly
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
5 files changed, 24 insertions(+), 7 deletions(-)
diff --git a/dgl/Window.hpp b/dgl/Window.hpp
@@ -306,7 +306,10 @@ public:
This gets the system clipboard contents,
which may have been set with setClipboard() or copied from another application.
- returns the clipboard contents, or null.
+ Returns the clipboard contents, or null.
+
+ @note By default only "text/plain" mimetype is supported and returned.
+ Override onClipboardDataOffer for supporting other types.
*/
const void* getClipboard(size_t& dataSize);
@@ -465,7 +468,7 @@ protected:
Reimplement and return a non-zero id to accept the clipboard data offer for a particular type.
Applications must ignore any type they do not recognize.
- The default implementation does nothing.
+ The default implementation accepts the "text/plain" mimetype.
*/
virtual uint32_t onClipboardDataOffer();
diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp
@@ -485,6 +485,15 @@ std::vector<ClipboardDataOffer> Window::getClipboardDataOfferTypes()
uint32_t Window::onClipboardDataOffer()
{
+ std::vector<ClipboardDataOffer> offers(getClipboardDataOfferTypes());
+
+ for (std::vector<ClipboardDataOffer>::iterator it=offers.begin(), end=offers.end(); it != end;++it)
+ {
+ const ClipboardDataOffer offer = *it;
+ if (std::strcmp(offer.type, "text/plain") == 0)
+ return offer.id;
+ }
+
return 0;
}
diff --git a/distrho/DistrhoUI.hpp b/distrho/DistrhoUI.hpp
@@ -309,7 +309,7 @@ protected:
Reimplement and return a non-zero id to accept the clipboard data offer for a particular type.
UIs must ignore any type they do not recognize.
- The default implementation does nothing.
+ The default implementation accepts the "text/plain" mimetype.
*/
virtual uint32_t uiClipboardDataOffer();
diff --git a/distrho/src/DistrhoUI.cpp b/distrho/src/DistrhoUI.cpp
@@ -345,6 +345,15 @@ std::vector<DGL_NAMESPACE::ClipboardDataOffer> UI::getClipboardDataOfferTypes()
uint32_t UI::uiClipboardDataOffer()
{
+ std::vector<ClipboardDataOffer> offers(uiData->window->getClipboardDataOfferTypes());
+
+ for (std::vector<ClipboardDataOffer>::iterator it=offers.begin(), end=offers.end(); it != end;++it)
+ {
+ const ClipboardDataOffer offer = *it;
+ if (std::strcmp(offer.type, "text/plain") == 0)
+ return offer.id;
+ }
+
return 0;
}
diff --git a/pugl-updates-notes.txt b/pugl-updates-notes.txt
@@ -4,7 +4,3 @@ puglSetWindowSize was used on first show, still needed?
transientParentView needed? remove from WindowPrivateData
update distrhoui.cpp get scale factor to match new parent request setup and pugl
-
-clipboard todo
-
-pugl namespace details finalized