✨ Add Windows native lazy file clipboard write via JNA delayed rendering#3931
Merged
guiyanakuang merged 3 commits intomainfrom Feb 23, 2026
Merged
✨ Add Windows native lazy file clipboard write via JNA delayed rendering#3931guiyanakuang merged 3 commits intomainfrom
guiyanakuang merged 3 commits intomainfrom
Conversation
Use native API (OpenClipboard/EmptyClipboard/CloseClipboard) for inter-test
cleanup instead of JVM's setContents(StringSelection("")) which makes the
JVM the clipboard owner. Add awaitClipboardReady() to flush the AWT event
queue after native writes so WM_DESTROYCLIPBOARD is processed before reads.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WindowsLazyClipboardclass implementing Windows delayed rendering for file-type clipboard data via JNA, mirroring the macOSNSPasteboardItemDataProviderapproach (PR Add macOS native lazy file pasteboard write via NSPasteboardItemDataProvider #3930)WM_RENDERFORMAT/WM_RENDERALLFORMATSconstants andRegisterClipboardFormatAtoUser32interfaceWindowsNativePasteboardTestwith 7 tests covering write, read, marker detection, and laziness verificationDesign
Uses Windows delayed rendering:
SetClipboardData(CF_HDROP, NULL)registers the format without providing data. When a consumer readsCF_HDROP, Windows sendsWM_RENDERFORMATto the clipboard owner window, which builds aDROPFILESstructure with resolved file paths.Key implementation details:
newSingleThreadContext(Windows requires clipboard owner and message pump on same thread)CompletableDeferredfor write results,PostMessage(WM_USER+1)to dispatch work to window threadFunction.getFunction("user32", "GetMessageW")withIntreturn to handle tri-state (>0/0/-1) properly, avoiding JNA's boolean mapping issueTest plan
writeFilesToClipboard returns valid sequence number for single filewriteFilesToClipboard returns valid sequence number for multiple fileswriteFilesToClipboard returns -1 for zero countnative clipboard single file is readable from JVM clipboardnative clipboard multiple files are readable from JVM clipboardwriteFilesToClipboard sets CrossPaste markerdata provider is NOT called during write - only on read(laziness proof)Tests are
@EnabledOnOs(OS.WINDOWS)— run with./gradlew app:desktopTest --tests "com.crosspaste.paste.WindowsNativePasteboardTest"on Windows.