commit 83e8afdb77695686a6b61dda2a5013d991232ddb
parent c6c6900b8743550da7eb4f0f61a28ee85ac80966
Author: falkTX <falktx@falktx.com>
Date: Thu, 9 Dec 2021 21:08:32 +0000
Expose clipboard functions from pugl, tested to work in Cardinal
Diffstat:
4 files changed, 43 insertions(+), 0 deletions(-)
diff --git a/dgl/TopLevelWidget.hpp b/dgl/TopLevelWidget.hpp
@@ -101,6 +101,8 @@ public:
void repaint(const Rectangle<uint>& rect) noexcept;
// TODO group stuff after here, convenience functions present in Window class
+ bool setClipboard(const char* mimeType, const void* data, size_t dataSize);
+ const void* getClipboard(const char*& mimeType, size_t& dataSize);
bool addIdleCallback(IdleCallback* callback, uint timerFrequencyInMs = 0);
bool removeIdleCallback(IdleCallback* callback);
double getScaleFactor() const noexcept;
diff --git a/dgl/Window.hpp b/dgl/Window.hpp
@@ -264,6 +264,27 @@ public:
void setIgnoringKeyRepeat(bool ignore) noexcept;
/**
+ Set the clipboard contents.
+
+ This sets the system clipboard contents,
+ which can be retrieved with getClipboard() or pasted into other applications.
+
+ If using a string, the use of a null terminator is required (and must be part of dataSize).@n
+ The MIME type of the data "text/plain" is assumed if null is used.
+ */
+ bool setClipboard(const char* mimeType, const void* data, size_t dataSize);
+
+ /**
+ Get the clipboard contents.
+
+ This gets the system clipboard contents,
+ which may have been set with setClipboard() or copied from another application.
+
+ returns the clipboard contents, or null.
+ */
+ const void* getClipboard(const char*& mimeType, size_t& dataSize);
+
+ /**
Add a callback function to be triggered on every idle cycle or on a specific timer frequency.
You can add more than one, and remove them at anytime with removeIdleCallback().
This can be used to perform some action at a regular interval with relatively low frequency.
diff --git a/dgl/src/TopLevelWidget.cpp b/dgl/src/TopLevelWidget.cpp
@@ -60,6 +60,16 @@ void TopLevelWidget::setSize(const Size<uint>& size)
pData->window.setSize(size);
}
+bool TopLevelWidget::setClipboard(const char* mimeType, const void* data, size_t dataSize)
+{
+ return pData->window.setClipboard(mimeType, data, dataSize);
+}
+
+const void* TopLevelWidget::getClipboard(const char*& mimeType, size_t& dataSize)
+{
+ return pData->window.getClipboard(mimeType, dataSize);
+}
+
bool TopLevelWidget::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs)
{
return pData->window.addIdleCallback(callback, timerFrequencyInMs);
diff --git a/dgl/src/Window.cpp b/dgl/src/Window.cpp
@@ -257,6 +257,16 @@ void Window::setIgnoringKeyRepeat(const bool ignore) noexcept
puglSetViewHint(pData->view, PUGL_IGNORE_KEY_REPEAT, ignore);
}
+bool Window::setClipboard(const char* const mimeType, const void* const data, const size_t dataSize)
+{
+ return puglSetClipboard(pData->view, mimeType, data, dataSize) == PUGL_SUCCESS;
+}
+
+const void* Window::getClipboard(const char*& mimeType, size_t& dataSize)
+{
+ return puglGetClipboard(pData->view, &mimeType, &dataSize);
+}
+
bool Window::addIdleCallback(IdleCallback* const callback, const uint timerFrequencyInMs)
{
DISTRHO_SAFE_ASSERT_RETURN(callback != nullptr, false)