aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-22 20:24:05 -0400
committerDavid Robillard <d@drobilla.net>2023-11-11 09:47:23 -0500
commit32733abab8546b708cab59a4df09f92eb3214f73 (patch)
treeb6bed60281f9dd3b71006b7cb7aa7ab056d6a70c
parent61980dbb9e6968f9d99df9cbd4bbe2f46f0c5050 (diff)
downloadpugl-32733abab8546b708cab59a4df09f92eb3214f73.tar.gz
pugl-32733abab8546b708cab59a4df09f92eb3214f73.tar.bz2
pugl-32733abab8546b708cab59a4df09f92eb3214f73.zip
Add region parameter to puglAcceptOffer()
-rw-r--r--bindings/cpp/include/pugl/pugl.hpp10
-rw-r--r--doc/c/clipboards.rst8
-rw-r--r--examples/pugl_clipboard_demo.c2
-rw-r--r--include/pugl/pugl.h10
-rw-r--r--src/mac.m13
-rw-r--r--src/win.c7
-rw-r--r--src/x11.c14
-rw-r--r--test/test_local_copy_paste.c2
-rw-r--r--test/test_remote_copy_paste.c2
-rw-r--r--test/test_utils.h3
10 files changed, 54 insertions, 17 deletions
diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp
index e374efc..b7f9fcf 100644
--- a/bindings/cpp/include/pugl/pugl.hpp
+++ b/bindings/cpp/include/pugl/pugl.hpp
@@ -660,10 +660,16 @@ public:
@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.
+
+ @param region The region of the view that will accept the data. This may
+ be used by the system to avoid sending redundant events.
*/
- Status acceptOffer(const DataOfferEvent& offer, const uint32_t typeIndex)
+ Status acceptOffer(const DataOfferEvent& offer,
+ const uint32_t typeIndex,
+ const Rect& region)
{
- return static_cast<Status>(puglAcceptOffer(cobj(), &offer, typeIndex));
+ return static_cast<Status>(
+ puglAcceptOffer(cobj(), &offer, typeIndex, region));
}
/// @copydoc puglSetViewStyle
diff --git a/doc/c/clipboards.rst b/doc/c/clipboards.rst
index ec66bd5..44f2960 100644
--- a/doc/c/clipboards.rst
+++ b/doc/c/clipboards.rst
@@ -82,10 +82,16 @@ it can accept the offer with :func:`puglAcceptOffer`:
for (uint32_t t = 0; t < numTypes; ++t) {
const char* type = puglGetClipboardType(view, t);
if (!strcmp(type, "text/uri-list")) {
- puglAcceptOffer(view, event, t);
+ puglAcceptOffer(view,
+ event,
+ t,
+ puglGetFrame(view));
}
}
+A view region must be given,
+which the window system may use to optimize the process and/or provide user feedback.
+
When an offer is accepted,
the data will be transferred and converted if necessary,
then the view will be sent a :enumerator:`PUGL_DATA` event.
diff --git a/examples/pugl_clipboard_demo.c b/examples/pugl_clipboard_demo.c
index efeb1eb..f43d729 100644
--- a/examples/pugl_clipboard_demo.c
+++ b/examples/pugl_clipboard_demo.c
@@ -89,7 +89,7 @@ onDataOffer(PuglView* view, const PuglDataOfferEvent* event)
for (uint32_t t = 0; t < numTypes; ++t) {
const char* type = puglGetClipboardType(view, t);
if (!strncmp(type, "text/", 5)) {
- puglAcceptOffer(view, event, t);
+ puglAcceptOffer(view, event, t, puglGetFrame(view));
return;
}
}
diff --git a/include/pugl/pugl.h b/include/pugl/pugl.h
index 39c051e..329acba 100644
--- a/include/pugl/pugl.h
+++ b/include/pugl/pugl.h
@@ -652,6 +652,8 @@ typedef struct {
PuglEventType type; ///< #PUGL_DATA_OFFER
PuglEventFlags flags; ///< Bitwise OR of #PuglEventFlag values
double time; ///< Time in seconds
+ double x; ///< View-relative X coordinate
+ double y; ///< View-relative Y coordinate
} PuglDataOfferEvent;
/**
@@ -665,6 +667,8 @@ typedef struct {
PuglEventType type; ///< #PUGL_DATA
PuglEventFlags flags; ///< Bitwise OR of #PuglEventFlag values
double time; ///< Time in seconds
+ double x; ///< View-relative X coordinate
+ double y; ///< View-relative Y coordinate
uint32_t typeIndex; ///< Index of datatype
} PuglDataEvent;
@@ -1521,12 +1525,16 @@ puglGetClipboardType(const PuglView* view, uint32_t typeIndex);
@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.
+
+ @param region The region of the view that will accept the data. This may be
+ used by the system to avoid sending redundant events.
*/
PUGL_API
PuglStatus
puglAcceptOffer(PuglView* view,
const PuglDataOfferEvent* offer,
- uint32_t typeIndex);
+ uint32_t typeIndex,
+ PuglRect region);
/**
Set the clipboard contents.
diff --git a/src/mac.m b/src/mac.m
index dcc2ee3..2d492a9 100644
--- a/src/mac.m
+++ b/src/mac.m
@@ -1913,8 +1913,9 @@ puglGetClipboardType(const PuglView* PUGL_UNUSED(view),
PuglStatus
puglAcceptOffer(PuglView* const view,
- const PuglDataOfferEvent* const PUGL_UNUSED(offer),
- const uint32_t typeIndex)
+ const PuglDataOfferEvent* const offer,
+ const uint32_t typeIndex,
+ const PuglRect region)
{
PuglWrapperView* const wrapper = view->impl->wrapperView;
NSPasteboard* const pasteboard = [NSPasteboard generalPasteboard];
@@ -1930,8 +1931,12 @@ puglAcceptOffer(PuglView* const view,
wrapper->dragOperation = NSDragOperationCopy;
wrapper->dragTypeIndex = typeIndex;
- const PuglDataEvent data = {
- PUGL_DATA, 0U, puglGetTime(view->world), (uint32_t)typeIndex};
+ const PuglDataEvent data = {PUGL_DATA,
+ 0U,
+ puglGetTime(view->world),
+ (double)region.x,
+ (double)region.y,
+ (uint32_t)typeIndex};
PuglEvent dataEvent;
dataEvent.data = data;
diff --git a/src/win.c b/src/win.c
index 3d245f2..2562d5f 100644
--- a/src/win.c
+++ b/src/win.c
@@ -1365,7 +1365,8 @@ puglGetClipboardType(const PuglView* const PUGL_UNUSED(view),
PuglStatus
puglAcceptOffer(PuglView* const view,
const PuglDataOfferEvent* const PUGL_UNUSED(offer),
- const uint32_t typeIndex)
+ const uint32_t typeIndex,
+ const PuglRect region)
{
if (typeIndex != 0) {
return PUGL_UNSUPPORTED;
@@ -1375,6 +1376,8 @@ puglAcceptOffer(PuglView* const view,
PUGL_DATA,
0,
GetMessageTime() / 1e3,
+ (double)region.x,
+ (double)region.y,
0,
};
@@ -1469,6 +1472,8 @@ puglPaste(PuglView* const view)
PUGL_DATA_OFFER,
0,
GetMessageTime() / 1e3,
+ 0.0,
+ 0.0,
};
PuglEvent offerEvent;
diff --git a/src/x11.c b/src/x11.c
index 19633e3..6306efd 100644
--- a/src/x11.c
+++ b/src/x11.c
@@ -1618,7 +1618,7 @@ handleSelectionNotify(const PuglWorld* const world,
view, event->requestor, event->property, &numFormats, &formats) &&
!setClipboardFormats(view, board, numFormats, formats)) {
const PuglDataOfferEvent offer = {
- PUGL_DATA_OFFER, 0, (double)event->time / 1e3};
+ PUGL_DATA_OFFER, 0, (double)event->time / 1e3, 0.0, 0.0};
puglEvent.offer = offer;
board->acceptedFormatIndex = UINT32_MAX;
@@ -1635,8 +1635,12 @@ handleSelectionNotify(const PuglWorld* const world,
world, view, event->property, event->target, &board->data)) {
board->source = XGetSelectionOwner(display, board->selection);
- const PuglDataEvent data = {
- PUGL_DATA, 0U, (double)event->time / 1e3, board->acceptedFormatIndex};
+ const PuglDataEvent data = {PUGL_DATA,
+ 0U,
+ (double)event->time / 1e3,
+ 0.0,
+ 0.0,
+ board->acceptedFormatIndex};
puglEvent.data = data;
}
@@ -2092,9 +2096,11 @@ puglGetClipboard(PuglView* const view,
PuglStatus
puglAcceptOffer(PuglView* const view,
const PuglDataOfferEvent* const offer,
- const uint32_t typeIndex)
+ const uint32_t typeIndex,
+ const PuglRect region)
{
(void)offer;
+ (void)region;
PuglInternals* const impl = view->impl;
Display* const display = view->world->impl->display;
diff --git a/test/test_local_copy_paste.c b/test/test_local_copy_paste.c
index 737f193..1d0d3fc 100644
--- a/test/test_local_copy_paste.c
+++ b/test/test_local_copy_paste.c
@@ -92,7 +92,7 @@ onEvent(PuglView* view, const PuglEvent* event)
if (test->state == PASTED) {
test->state = RECEIVED_OFFER;
- assert(!puglAcceptOffer(view, &event->offer, 0));
+ assert(!puglAcceptOffer(view, &event->offer, 0, puglGetFrame(view)));
}
break;
diff --git a/test/test_remote_copy_paste.c b/test/test_remote_copy_paste.c
index a9f079e..8e2b752 100644
--- a/test/test_remote_copy_paste.c
+++ b/test/test_remote_copy_paste.c
@@ -105,7 +105,7 @@ onPasterEvent(PuglView* const view, const PuglEvent* const event)
if (test->state == PASTED) {
test->state = RECEIVED_OFFER;
- assert(!puglAcceptOffer(view, &event->offer, 0));
+ assert(!puglAcceptOffer(view, &event->offer, 0, puglGetFrame(view)));
}
break;
diff --git a/test/test_utils.h b/test/test_utils.h
index 80f28a0..92b2c58 100644
--- a/test/test_utils.h
+++ b/test/test_utils.h
@@ -358,7 +358,8 @@ printEvent(const PuglEvent* event, const char* prefix, const bool verbose)
case PUGL_LOOP_LEAVE:
return PRINT("%sLoop leave\n", prefix);
case PUGL_DATA_OFFER:
- return PRINT("%sData offer\n", prefix);
+ return PRINT(
+ "%sData offer at " PFFMT "\n", prefix, event->offer.x, event->offer.y);
case PUGL_DATA:
return PRINT("%sData\n", prefix);
default: