diff options
author | David Robillard <d@drobilla.net> | 2025-01-31 22:11:03 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-01-31 22:24:31 -0500 |
commit | e266f484e231bbad5399323cde97199e2a3d2da3 (patch) | |
tree | 2b9ffc55e5f716cf59b1554c53113901de6adfaa | |
parent | d2ed87a00e39a800f03e63d3ded8ef0302cd8b5e (diff) | |
download | pugl-e266f484e231bbad5399323cde97199e2a3d2da3.tar.gz pugl-e266f484e231bbad5399323cde97199e2a3d2da3.tar.bz2 pugl-e266f484e231bbad5399323cde97199e2a3d2da3.zip |
Windows: Improve clipboard reliability
-rw-r--r-- | src/win.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -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; } |