aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_remote_copy_paste.c
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 /test/test_remote_copy_paste.c
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 'test/test_remote_copy_paste.c')
-rw-r--r--test/test_remote_copy_paste.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/test/test_remote_copy_paste.c b/test/test_remote_copy_paste.c
index 2ee90f7..07e75d9 100644
--- a/test/test_remote_copy_paste.c
+++ b/test/test_remote_copy_paste.c
@@ -1,4 +1,4 @@
-// Copyright 2020-2021 David Robillard <d@drobilla.net>
+// Copyright 2020-2022 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
// Tests copy and paste from one view to another
@@ -23,6 +23,8 @@ typedef enum {
START,
EXPOSED,
COPIED,
+ PASTED,
+ RECEIVED_OFFER,
FINISHED,
} State;
@@ -60,6 +62,7 @@ onCopierEvent(PuglView* const view, const PuglEvent* const event)
if (test->state < COPIED) {
puglSetClipboard(
view, "text/plain", "Copied Text", strlen("Copied Text") + 1);
+
test->state = COPIED;
}
@@ -92,18 +95,31 @@ onPasterEvent(PuglView* const view, const PuglEvent* const event)
case PUGL_TIMER:
assert(event->timer.id == pasterTimerId);
-
if (test->state == COPIED) {
- const char* type = NULL;
+ test->state = PASTED;
+ assert(!puglPaste(view));
+ }
+ break;
+
+ case PUGL_DATA_OFFER:
+ if (test->state == PASTED) {
+ test->state = RECEIVED_OFFER;
+
+ assert(!puglAcceptOffer(view, &event->offer, 0));
+ }
+ break;
+
+ case PUGL_DATA:
+ if (test->state == RECEIVED_OFFER) {
size_t len = 0;
- const char* text = (const char*)puglGetClipboard(view, &type, &len);
+ const char* text = (const char*)puglGetClipboard(view, 0, &len);
- assert(!strcmp(type, "text/plain"));
+ // Check that the offered data is what we copied earlier
+ assert(text);
assert(!strcmp(text, "Copied Text"));
test->state = FINISHED;
}
-
break;
default: