Retry to open the clipboard in case another application has it open

This fixes 'testautomation --filter clipboard_testClipboardTextFunctions' on Windows
main
Sam Lantinga 2023-07-03 16:06:59 -07:00
parent 3bd5e5ca3c
commit b6645bb255
1 changed files with 22 additions and 14 deletions

View File

@ -102,11 +102,15 @@ int WIN_SetClipboardText(SDL_VideoDevice *_this, const char *text)
char *WIN_GetClipboardText(SDL_VideoDevice *_this)
{
char *text;
char *text = NULL;
text = NULL;
if (IsClipboardFormatAvailable(TEXT_FORMAT) &&
OpenClipboard(GetWindowHandle(_this))) {
if (IsClipboardFormatAvailable(TEXT_FORMAT)) {
/* Retry to open the clipboard in case another application has it open */
const int MAX_ATTEMPTS = 3;
int attempt;
for (attempt = 0; attempt < MAX_ATTEMPTS; ++attempt) {
if (OpenClipboard(GetWindowHandle(_this))) {
HANDLE hMem;
LPTSTR tstr;
@ -119,6 +123,10 @@ char *WIN_GetClipboardText(SDL_VideoDevice *_this)
WIN_SetError("Couldn't get clipboard data");
}
CloseClipboard();
break;
}
SDL_Delay(10);
}
}
if (text == NULL) {
text = SDL_strdup("");