mirror of
https://github.com/aphrody-labs/cygwin.git
synced 2026-10-13 22:03:45 +00:00
Cygwin: clipboard: Add workaround for ERROR_CLIPBOARD_NOT_OPEN
SetClipboardData() and GetClipboardData() occasionally fail with ERROR_CLIPBOARD_NOT_OPEN, even though OpenClipboard() succeeded if NULL HWND is used. Retry until GetClipboardData() does not return ERROR_CLIPBOARD_NOT_OPEN. Addresses: https://cygwin.com/pipermail/cygwin/2026-February/259438.html Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp> Reviewed-by: Mark Geisert <mark@maxrnd.com>
This commit is contained in:
1 parent
950abe2600
commit
7fd670a36b
2 files changed
+22
-2
No files matched your search
@@ -25,11 +25,28 @@ details. */
|
||||
static inline bool
|
||||
open_clipboard ()
|
||||
{
|
||||
const int max_retry = 10;
|
||||
const int max_retry = 20;
|
||||
for (int i = 0; i < max_retry; i++)
|
||||
{
|
||||
/* No appropriate HWND exists here. */
|
||||
if (OpenClipboard (NULL))
|
||||
return true;
|
||||
{
|
||||
/* SetClipboardData() and GetClipboardData() occasionally
|
||||
fail with ERROR_CLIPBOARD_NOT_OPEN, even though
|
||||
OpenClipboard() succeeded if NULL HWND is used.
|
||||
Retry until GetClipboardData() does not return
|
||||
ERROR_CLIPBOARD_NOT_OPEN. */
|
||||
if (GetClipboardData (CF_UNICODETEXT))
|
||||
return true;
|
||||
DWORD err = GetLastError ();
|
||||
/* Here, ERROR_NOT_FOUND means the clipboard does not contains
|
||||
valid CF_UNICODETEXT. OpenClipboard() must have succeeded. */
|
||||
if (err == ERROR_NOT_FOUND)
|
||||
return true;
|
||||
CloseClipboard ();
|
||||
if (err != ERROR_CLIPBOARD_NOT_OPEN)
|
||||
return false;
|
||||
}
|
||||
Sleep (1);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -8,3 +8,6 @@ Fixes:
|
||||
|
||||
- Fix behaviour with OPEN_MAX files open
|
||||
Addresses: https://cygwin.com/pipermail/cygwin/2026-May/259664.html
|
||||
|
||||
- Add workaround for clipboard access error.
|
||||
Addresses: https://cygwin.com/pipermail/cygwin/2026-February/259438.html
|
||||
Reference in new issue
Block a user