diff options
author | David Robillard <d@drobilla.net> | 2022-05-22 17:48:16 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-11-11 09:49:51 -0500 |
commit | c59e88aa6fa60c6f7424da737fcaf0496a0bf3d6 (patch) | |
tree | ca5e6f85207f3f51bd3015a67c23d9dd0c917846 /examples | |
parent | 32733abab8546b708cab59a4df09f92eb3214f73 (diff) | |
download | pugl-c59e88aa6fa60c6f7424da737fcaf0496a0bf3d6.tar.gz pugl-c59e88aa6fa60c6f7424da737fcaf0496a0bf3d6.tar.bz2 pugl-c59e88aa6fa60c6f7424da737fcaf0496a0bf3d6.zip |
Add API support for multiple clipboards
Adds a PuglClipboard enum, and uses it everywhere necessary to "structurally"
support multiple clipboards. Towards re-using this API to support DnD.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/pugl_clipboard_demo.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/examples/pugl_clipboard_demo.c b/examples/pugl_clipboard_demo.c index f43d729..ba691cf 100644 --- a/examples/pugl_clipboard_demo.c +++ b/examples/pugl_clipboard_demo.c @@ -65,7 +65,11 @@ onKeyPress(PuglView* const view, const PuglKeyEvent* const event) if (event->key == 'q' || event->key == PUGL_KEY_ESCAPE) { app->quit = 1; } else if ((event->state & PUGL_MOD_CTRL) && event->key == 'c') { - puglSetClipboard(view, "text/plain", copyString, strlen(copyString)); + puglSetClipboard(view, + PUGL_CLIPBOARD_GENERAL, + "text/plain", + copyString, + strlen(copyString)); fprintf(stderr, "Copy \"%s\"\n", copyString); } else if ((event->state & PUGL_MOD_CTRL) && event->key == 'v') { @@ -76,18 +80,19 @@ onKeyPress(PuglView* const view, const PuglKeyEvent* const event) static void onDataOffer(PuglView* view, const PuglDataOfferEvent* event) { - const uint32_t numTypes = puglGetNumClipboardTypes(view); + const PuglClipboard clipboard = event->clipboard; + const uint32_t numTypes = puglGetNumClipboardTypes(view, clipboard); // Print all offered types to be useful as a testing program fprintf(stderr, "Offered %u types:\n", numTypes); for (uint32_t t = 0; t < numTypes; ++t) { - const char* type = puglGetClipboardType(view, t); + const char* type = puglGetClipboardType(view, clipboard, t); fprintf(stderr, "\t%s\n", type); } // Accept the first type found that we support (namely text) for (uint32_t t = 0; t < numTypes; ++t) { - const char* type = puglGetClipboardType(view, t); + const char* type = puglGetClipboardType(view, clipboard, t); if (!strncmp(type, "text/", 5)) { puglAcceptOffer(view, event, t, puglGetFrame(view)); return; @@ -98,15 +103,16 @@ onDataOffer(PuglView* view, const PuglDataOfferEvent* event) static void onData(PuglView* view, const PuglDataEvent* event) { - const uint32_t typeIndex = event->typeIndex; + const PuglClipboard clipboard = event->clipboard; + const uint32_t typeIndex = event->typeIndex; - const char* const type = puglGetClipboardType(view, typeIndex); + const char* const type = puglGetClipboardType(view, clipboard, typeIndex); fprintf(stderr, "Received data type: %s\n", type); if (!strncmp(type, "text/", 5)) { // Accept any text type size_t len = 0; - const void* data = puglGetClipboard(view, typeIndex, &len); + const void* data = puglGetClipboard(view, clipboard, typeIndex, &len); fprintf(stderr, "Data:\n%s\n", (const char*)data); } |