Cocoa: avoid atomic-mode problems in clipboard

Get data from a clipboard client before going into atomic mode. This
correction can avoid an "about to suspend in atomic mode" failure,
particularly if a snip fails to copy correctly.
This commit is contained in:
Matthew Flatt 2015-02-05 10:33:47 +01:00
parent 7a3c102d1c
commit ff6b409f28

View File

@ -52,6 +52,9 @@
#f))))) #f)))))
(define/public (set-client c types) (define/public (set-client c types)
(define bstrs
(for/list ([type (in-list types)])
(send c get-data type)))
(atomically (atomically
(with-autorelease (with-autorelease
(let ([pb (tell NSPasteboard generalPasteboard)] (let ([pb (tell NSPasteboard generalPasteboard)]
@ -62,8 +65,8 @@
declareTypes: a declareTypes: a
owner: #f)) owner: #f))
(set! client c) (set! client c)
(for ([type (in-list types)]) (for ([type (in-list types)]
(let ([bstr (send c get-data type)]) [bstr (in-list bstrs)])
(when bstr (when bstr
(let* ([bstr (if (string? bstr) (let* ([bstr (if (string? bstr)
(string->bytes/utf-8 bstr) (string->bytes/utf-8 bstr)
@ -73,7 +76,7 @@
length: #:type _NSUInteger (bytes-length bstr))]) length: #:type _NSUInteger (bytes-length bstr))])
(tellv (tell NSPasteboard generalPasteboard) (tellv (tell NSPasteboard generalPasteboard)
setData: data setData: data
forType: #:type _NSString (map-type type)))))))))) forType: #:type _NSString (map-type type)))))))))
(define/public (get-data-for-type type) (define/public (get-data-for-type type)
(log-error "didn't expect clipboard data request")) (log-error "didn't expect clipboard data request"))