Skip to content

Commit 945eb6d

Browse files
stephomislouken
authored andcommitted
MacOS: fix cocoa clipboard text
Adjust Cocoa_SetClipboardData so that SetClipboardText text can be pasted outside SDL
1 parent b08d79b commit 945eb6d

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/video/cocoa/SDL_cocoaclipboard.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ bool Cocoa_SetClipboardData(SDL_VideoDevice *_this)
158158
@autoreleasepool {
159159
SDL_CocoaVideoData *data = (__bridge SDL_CocoaVideoData *)_this->internal;
160160
NSPasteboard *pasteboard = [NSPasteboard generalPasteboard];
161+
162+
// SetClipboardText specialization so text is available after the app quits
163+
if (_this->clipboard_callback && _this->num_clipboard_mime_types == 1) {
164+
if (SDL_strncmp(_this->clipboard_mime_types[0], "text/plain;charset=utf-8", 24) == 0) {
165+
[pasteboard declareTypes:@[ NSPasteboardTypeString ] owner:nil];
166+
[pasteboard setString:@((char *)_this->clipboard_userdata) forType:NSPasteboardTypeString];
167+
data.clipboard_count = [pasteboard changeCount];
168+
return true;
169+
}
170+
}
171+
161172
NSPasteboardItem *newItem = [NSPasteboardItem new];
162173
NSMutableArray *utiTypes = [NSMutableArray new];
163174
Cocoa_PasteboardDataProvider *provider = [[Cocoa_PasteboardDataProvider alloc] initWith: _this->clipboard_callback userData: _this->clipboard_userdata];

0 commit comments

Comments
 (0)