aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2025-01-31 22:11:03 -0500
committerDavid Robillard <d@drobilla.net>2025-01-31 22:24:31 -0500
commite266f484e231bbad5399323cde97199e2a3d2da3 (patch)
tree2b9ffc55e5f716cf59b1554c53113901de6adfaa
parentd2ed87a00e39a800f03e63d3ded8ef0302cd8b5e (diff)
downloadpugl-e266f484e231bbad5399323cde97199e2a3d2da3.tar.gz
pugl-e266f484e231bbad5399323cde97199e2a3d2da3.tar.bz2
pugl-e266f484e231bbad5399323cde97199e2a3d2da3.zip
Windows: Improve clipboard reliability
-rw-r--r--src/win.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/win.c b/src/win.c
index dd736ff..129c780 100644
--- a/src/win.c
+++ b/src/win.c
@@ -1410,8 +1410,21 @@ puglGetClipboard(PuglView* const view,
{
PuglInternals* const impl = view->impl;
- if (typeIndex > 0U || !IsClipboardFormatAvailable(CF_UNICODETEXT) ||
- !OpenClipboard(impl->hwnd)) {
+ if (typeIndex > 0U || !IsClipboardFormatAvailable(CF_UNICODETEXT)) {
+ return NULL;
+ }
+
+ // Try to open the clipboard several times since others may have locked it
+ BOOL opened = FALSE;
+ static const unsigned max_tries = 16U;
+ for (unsigned i = 0U; !opened && i < max_tries; ++i) {
+ opened = OpenClipboard(impl->hwnd);
+ if (!opened) {
+ Sleep(0);
+ }
+ }
+
+ if (!opened) {
return NULL;
}