Conversation
Make the CLIPBOARD selection two-way: when an X client claims ownership, mirror its text out to SDL's clipboard so external host apps can paste it. A hidden InputOnly requestor window fires an async SelectionRequest for UTF8_STRING at the new owner; convertEvent routes replies destined for that window into clipboardConsumeInternalEvent, which pushes the text via SDL_SetClipboardText. Large payloads arrive via INCR: an INCR-typed reply acks by deleting the property and accumulates PropertyNotify chunks into a 128 MiB-capped buffer, pushing on the zero-length terminator. When an owner declines UTF8_STRING, retry legacy XA_STRING once for the current owner. Stale-reply defense: each fetch draws its receiving property from a small rotating pool, so a superseded fetch's late reply lands on a different slot and is ignored; declines are discriminated by target. Ownership expiry rides the native SDL_CLIPBOARDUPDATE event: an external host clipboard change (distinguished from our own echo via the last pushed text) revokes the X owner. A clipboard update during the first fetch, before anything has been pushed, does not expire the owner it is fetching from. Image and other non-text targets are text-only by design (SDL2 has no image clipboard and the SDL2-spelled shim does not wrap SDL3 SDL_SetClipboardData); the dropped target is logged by name.
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.
Make the CLIPBOARD selection two-way: when an X client claims ownership, mirror its text out to SDL's clipboard so external host apps can paste it.
A hidden InputOnly requestor window fires an async SelectionRequest for UTF8_STRING at the new owner; convertEvent routes replies destined for that window into clipboardConsumeInternalEvent, which pushes the text via SDL_SetClipboardText. Large payloads arrive via INCR: an INCR-typed reply acks by deleting the property and accumulates PropertyNotify chunks into a 128 MiB-capped buffer, pushing on the zero-length terminator. When an owner declines UTF8_STRING, retry legacy XA_STRING once for the current owner.
Stale-reply defense: each fetch draws its receiving property from a small rotating pool, so a superseded fetch's late reply lands on a different slot and is ignored; declines are discriminated by target. Ownership expiry rides the native SDL_CLIPBOARDUPDATE event: an external host clipboard change (distinguished from our own echo via the last pushed text) revokes the X owner. A clipboard update during the first fetch, before anything has been pushed, does not expire the owner it is fetching from.
Image and other non-text targets are text-only by design (SDL2 has no image clipboard and the SDL2-spelled shim does not wrap SDL3 SDL_SetClipboardData); the dropped target is logged by name.
Summary by cubic
Mirror X11 CLIPBOARD to the host: when an X client claims CLIPBOARD, we fetch its text and push it to SDL so external apps can paste. Supports
UTF8_STRING,XA_STRINGfallback with Latin‑1→UTF‑8, andINCRstreaming with a 128 MiB cap, with safeguards against stale replies, non‑text data, and echo loops.New Features
InputOnlyinternal requestor; asyncSelectionRequestforUTF8_STRING, retryXA_STRINGonce if declined (Latin‑1 transcoded to UTF‑8).INCRsupport with chunk acks (property deletes), reassembly, and a 128 MiB cap; also caps single‑shot replies; zero‑length terminator triggers push; malformedINCRhints are dropped.SDL_CLIPBOARDUPDATE) revoke the X owner unless it’s our own echo; the first‑fetch update doesn’t abort the fetch.Refactors
createInternalWindowand aWindow.internalflag; internal windows don’t emit Create/DestroyNotify and are hidden fromXQueryTreeand state snapshots.convertEventnow callsclipboardConsumeInternalEventfor the requestor window andclipboardHandleExternalUpdateonSDL_CLIPBOARDUPDATE.Written for commit f84b8f1. Summary will update on new commits.