From 7563a3e17d281cb176415278892533a3dc5922ea Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 22 Sep 2025 09:06:42 -0700 Subject: [PATCH] Fixed clipboard tests on iOS --- src/video/uikit/SDL_uikitclipboard.m | 18 ++++++++++++++---- src/video/uikit/SDL_uikitvideo.h | 2 ++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/video/uikit/SDL_uikitclipboard.m b/src/video/uikit/SDL_uikitclipboard.m index 8ed4eb04c2..4952b95577 100644 --- a/src/video/uikit/SDL_uikitclipboard.m +++ b/src/video/uikit/SDL_uikitclipboard.m @@ -33,7 +33,14 @@ bool UIKit_SetClipboardText(SDL_VideoDevice *_this, const char *text) return SDL_SetError("The clipboard is not available on tvOS"); #else @autoreleasepool { - [UIPasteboard generalPasteboard].string = @(text); + SDL_UIKitVideoData *data = (__bridge SDL_UIKitVideoData *)_this->internal; + data.setting_clipboard = true; + if (text && *text) { + [UIPasteboard generalPasteboard].string = @(text); + } else { + [UIPasteboard generalPasteboard].items = nil; + } + data.setting_clipboard = false; return true; } #endif @@ -61,7 +68,7 @@ bool UIKit_HasClipboardText(SDL_VideoDevice *_this) { @autoreleasepool { #ifndef SDL_PLATFORM_TVOS - if ([UIPasteboard generalPasteboard].string != nil) { + if ([UIPasteboard generalPasteboard].hasStrings) { return true; } #endif @@ -80,11 +87,14 @@ void UIKit_InitClipboard(SDL_VideoDevice *_this) object:nil queue:nil usingBlock:^(NSNotification *note) { - // TODO: compute mime types - SDL_SendClipboardUpdate(false, NULL, 0); + if (!data.setting_clipboard) { + // TODO: compute mime types + SDL_SendClipboardUpdate(false, NULL, 0); + } }]; data.pasteboardObserver = observer; + data.setting_clipboard = false; } #endif } diff --git a/src/video/uikit/SDL_uikitvideo.h b/src/video/uikit/SDL_uikitvideo.h index 927e646883..0f69503b2c 100644 --- a/src/video/uikit/SDL_uikitvideo.h +++ b/src/video/uikit/SDL_uikitvideo.h @@ -31,6 +31,8 @@ @property(nonatomic, assign) id pasteboardObserver; +@property(nonatomic, assign) bool setting_clipboard; + @end #ifdef SDL_PLATFORM_VISIONOS